//alert('got script');

/* Browser Tester Code */
var whichBrowser

function browserDetection(){
        if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
         var ieversion=new Number(RegExp.$1) 
         /*capture x.x portion and store as a number*/
         if (ieversion>=8)
          {whichBrowser='ie8';}
         else if (ieversion>=7)
          {whichBrowser='ie7';}
         else if (ieversion>=6)
          {whichBrowser='ie6';}
         else if (ieversion>=5)
          {whichBrowser='ie5';}
        }
        else
         {whichBrowser='notIE';//alert('testing -- not ie');
	}
}
browserDetection();


var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
// exactly Internet Explorer 7
var IE7 = false /*@cc_on || @_jscript_version == 5.7 @*/;
// at least Internet Explorer 7
var gteIE7 = false /*@cc_on || @_jscript_version >= 5.7 @*/;
// any Internet Explorer (thanks to Dean)
var isMSIE = /*@cc_on!@*/false;


var bSaf     = (navigator.userAgent.toLowerCase().indexOf('safari') != -1);
var bSaf12   = (bSaf && (navigator.productSub > 20030107));
if(bSaf||bSaf12){}
if(bSaf){
	//alert('yes bsaf');
}

/* Browser tester done */


/* Espanol English Button Code */


var changeLanguage
var whichURL
//changeLanguage='English'
var searchString
searchString = document.location.href;

var english = new Array();
english[0]  = "genericsection.do?categoryId=82915461&contentId=6003531";//Products & Services
english[1]  = "genericsection.do?categoryId=82915462&contentId=6007275";//For You
english[2]  = "subsection.do?categoryId=82915463&contentId=6005246";//Cars, Vans, Trucks, SUV
english[3]  = "genericsection.do?categoryId=82915601&contentId=6006728";//Racing & Sponsorship landing
english[4]  = "extendedsectiongenericarticle.do?categoryId=9029398&contentId=7053818";//GTX HM PRODUCT INFO
english[5]  = "extendedsectiongenericarticle.do?categoryId=82915476&contentId=7053315"//GTX HM MAIN PAGE
english[6]  = "genericsection.do?categoryId=9031983&contentId=7058412";//Soccer landing
english[7]  = "genericsection.do?categoryId=9031999&contentId=7058472";//Racing 'Sponsorship' landing page
english[8]  = "genericsection.do?categoryId=9032000&contentId=7058475";//Racing 'Embassador'
english[9]  = "genericsection.do?categoryId=9032001&contentId=7058538";//Racing 'Hot Tips'
english[10] = "sectiongenericarticle.do?categoryId=9032096&contentId=7058533";//Racing 'ESA'
english[11] = "sectiongenericarticle.do?categoryId=9032099&contentId=7058537";//Ronaldo vs Messi
english[12] = "sectiongenericarticle.do?categoryId=9032097&contentId=7058535";//Embassador 'Wenger'
english[13] = "sectiongenericarticle.do?categoryId=9032098&contentId=7058536";//Embassador 'Ronaldo'
english[14] = "sectiongenericarticle.do?categoryId=9032095&contentId=7058528";//Sponsorship FIFA World Cup
english[15] = "extendedsectiongenericarticle.do?categoryId=9034075&contentId=7063001";//Predictor
english[16] = "extendedsectiongenericarticle.do?categoryId=9034079&contentId=7063022";//Predictor Winner
english[17] = "extendedsectiongenericarticle.do?categoryId=9034080&contentId=7063024";//Predictor success
english[18] = "extendedsectiongenericarticle.do?categoryId=9034081&contentId=7063025";//Predictor group
english[19] = "extendedsectiongenericarticle.do?categoryId=9034082&contentId=7063026";//Predictor opponent
english[20] = "extendedsectiongenericarticle.do?categoryId=9034083&contentId=7063027";//Predictor match
english[21] = "extendedsectiongenericarticle.do?categoryId=9034084&contentId=7063028";//Predictor tournament


var Espanol = new Array();
Espanol[0]  = "genericsection.do?categoryId=3341&contentId=7061326";//Products & Services -- X
Espanol[1]  = "genericsection.do?categoryId=9033393&contentId=7061493";//For You -- X
Espanol[2]  = "subsection.do?categoryId=9033405&contentId=7061331";//Cars, Vans, Trucks, SUV -- X
Espanol[3]  = "genericsection.do?categoryId=3342&contentId=7061278";//Racing & Sponsorship landing -- X
Espanol[4]  = "extendedsectiongenericarticle.do?categoryId=9033496&contentId=7061513";//GTX HM PRODUCT INFO -- X
Espanol[5]  = "extendedsectiongenericarticle.do?categoryId=9033491&contentId=7061512";//GTX HM MAIN PAGE	-- X
Espanol[6]  = "genericsection.do?categoryId=9033279&contentId=7061243";//Soccer landing -- X
Espanol[7]  = "genericsection.do?categoryId=9033280&contentId=7061279";//Racing 'Sponsorship' landing page -- X
Espanol[8]  = "genericsection.do?categoryId=9033281&contentId=7061290";//Racing 'Embassador' -- X
Espanol[9]  = "genericsection.do?categoryId=9033282&contentId=7061291";//Racing 'Hot Tips' -- X
Espanol[10] = "sectiongenericarticle.do?categoryId=9033295&contentId=7061295";//Racing 'ESA' -- X
Espanol[11] = "sectiongenericarticle.do?categoryId=9033296&contentId=7061303";//Ronaldo vs Messi -- X
Espanol[12] = "sectiongenericarticle.do?categoryId=9033367&contentId=7061304";//Embassador 'Wenger' -- X
Espanol[13] = "sectiongenericarticle.do?categoryId=9033368&contentId=7061307";//Embassador 'Ronaldo' -- X
Espanol[14] = "sectiongenericarticle.do?categoryId=9033294&contentId=7061178";//Sponsorship FIFA World Cup -- X
Espanol[15] = "extendedsectiongenericarticle.do?categoryId=9034153&contentId=7063081";//Predictor
Espanol[16] = "extendedsectiongenericarticle.do?categoryId=9034154&contentId=7063082";//Predictor Winner
Espanol[17] = "extendedsectiongenericarticle.do?categoryId=9034155&contentId=7063087";//Predictor success
Espanol[18] = "extendedsectiongenericarticle.do?categoryId=9034156&contentId=7063084";//Predictor group
Espanol[19] = "extendedsectiongenericarticle.do?categoryId=9034157&contentId=7063086";//Predictor opponent
Espanol[20] = "extendedsectiongenericarticle.do?categoryId=9034158&contentId=7063088";//Predictor match
Espanol[21] = "extendedsectiongenericarticle.do?categoryId=9034159&contentId=7063085";//Predictor tournament





function addElement() {
	//if (whichBrowser != 'notIE');alert('testing -- not ie');
	//alert('adding element now');
  var ni = document.getElementById('mastHeadTopNav');
  var newdiv = document.createElement('div');
  var divIdName = 'SpanDiv';
  newdiv.setAttribute('id',divIdName);
  



  for (var i=0;i<english.length;i++)
      {
	//alert('String to search is ' + searchString + ' and english i is ' + english[i]);
	
	/* THIS JUST CHANGES THE LANGUAGE TO SPANISH Espanol right nav text */
        if (searchString.indexOf(english[i])!= -1){
	   whichURL = Espanol[i];
	   //alert(whichURL);
	   changeLanguage = 'Espanol';
	   //if (whichBrowser != 'notIE');alert('testing -- not ie in English');
           break;
        }
	
	/* ELSE THIS CHANGES THE LANGUAGE TO ENGLISH right nav text */
	else if(searchString.indexOf(Espanol[i])!= -1){
	   whichURL = english[i];
	   changeLanguage = 'English';
	   document.getElementById('breadCrumbContainer').style.visibility='hidden';
	   var ulArray = document.getElementsByTagName('ul');

	   /* ~~~~~~~~~~~~~ ulArray[0] is the right top nav in header ~~~~~~~~~~~~~ */
	   /* ~~~~~~~~~~~~~ ulArray[1] is the top nav in the shaded bar ~~~~~~~~~~~~~ */
	   var shadedNav
	   
	   /* GTX HM urls */
	   if((searchString.indexOf('7061512')!= -1) || (searchString.indexOf('7061513')!= -1)){
	    shadedNav='<li><div><div class="button1"><span class="nowrap">Castrol GTX High Mileage</span></div></div><div class="padding"></div></li><li><div><a href="http://www.castrol.com/castrol/genericsection.do?categoryId=9033279&contentId=7061243" class="button"><span class="nowrap">F&uacute;tbol</span></a></div><div class="padding"></div></li>'
	   }
	   //if(searchString.indexOf('7061243')!= -1){
	   /* NOT GTX HM urls */
	   else {
	    shadedNav='<li><div><a href="http://www.castrol.com/castrol/extendedsectiongenericarticle.do?categoryId=9033491&contentId=7061512" class="button"><span class="nowrap">Castrol GTX High Mileage</span></a></div><div class="padding"></div></li><li><div><div class="button1" onclick="self.location.href=\'http://www.castrol.com/castrol/genericsection.do?categoryId=9033279&contentId=7061243\'" style="cursor:pointer;"><span class="nowrap">F&uacute;tbol</span></div></div><div class="padding"></div></li>'
	   }

	   ulArray[0].innerHTML='';
	   ulArray[1].innerHTML=shadedNav;

	   /* THIS CHANGES THE TOP LOGO URL TO GO TO THE ENGLISH HOMEPAGE */
	   /* ROB CHANGED MIND, DOES NOT WANT LOGO TO GO ANYWHERE, THIS FIXES */
	   var anchorTags = document.getElementsByTagName("a");
	   for (var i = 0; i < anchorTags.length ; i++)
	     {   
		if (anchorTags[i].innerHTML.search('logo') != -1)
		   {
		     anchorTags[i].style.cursor='text';
		     //alert(anchorTags[i].innerHTML);
		     anchorTags[i].href='#';
                     break;

		   }
	       //alert("Href of this a element is : " + anchorTags[i].href + "\n");
	     }
           /* END */

	   var divArray = document.getElementsByTagName('div');
	  
	  /* GTX HM url */
	  if (searchString.indexOf('7061512') != -1){
		/* ~~~~~~~~~~~~ THIS HIDES PART OF THE LEFT NAV (cars vans trucks suv) AS REQUESTED ~~~~~~~~~~~~~~~ */
	  	for (var i = 0; i < divArray.length ; i++)
	     	{   
			if (divArray[i].className=='navContainerBNew')
		   	{
		     		//alert(divArray[i].className);
		     		//alert(divArray[i].style.display);
	             		divArray[i].style.display='none';
		    		 //divArray[i].innerHTML='';
                     		break;

		   	}
	       	//alert("Href of this a element is : " + anchorTags[i].href + "\n");
	     	}
	        /* END */
	   }	

	     
	     var fieldsetArray = document.getElementsByTagName('fieldset');
	  
	  /* ~~~~~~~~~~~~ hides fieldset including the search button at top ~~~~~~~~~~~~~~ */ 
	  for (var i = 0; i < fieldsetArray.length ; i++)
	     {   
		if (fieldsetArray[i].className=='fldBorder')
		   {
		     //alert(divArray[i].className);
		     //alert(divArray[i].style.display);
	             fieldsetArray[i].style.display='none';
		     //divArray[i].innerHTML='';
                     break;

		   }
	       //alert("Href of this a element is : " + anchorTags[i].href + "\n");
	     }
		
           
           break;
        }

	else{}
      }

 
  //alert(whichURL);
  newdiv.innerHTML = '<a href="http://www.castrol.com/castrol/' + whichURL + '" style="font-weight:bold;curser:pointer;text-decoration:none;">' + changeLanguage + ' \> </a>';
  ni.appendChild(newdiv);

  if (whichBrowser == 'notIE')
	{
		//alert('not ie');
		if (changeLanguage == 'English'){
			document.getElementById('SpanDiv').style.position='absolute';
  			document.getElementById('SpanDiv').style.top='118px';
  			document.getElementById('SpanDiv').style.left='-80px';  
			
  		}
		else 
		{
			document.getElementById('SpanDiv').style.position='absolute';
  			document.getElementById('SpanDiv').style.top='125px';
  			document.getElementById('SpanDiv').style.left='150px';  
  			document.getElementById('SpanDiv').style.zIndex='2000';
			if (searchString.indexOf('903') != -1)
			{
				document.getElementById('SpanDiv').style.top='116px';
			}
	        	if (searchString.indexOf('7058528') != -1)
			{
				document.getElementById('SpanDiv').style.left='170px';
                        	document.getElementById('SpanDiv').style.fontSize='13px';
                        
			}
		
	        }
       	}
  else
       {
	//alert('is ie');
  	document.getElementById('SpanDiv').style.position='absolute';
  	document.getElementById('SpanDiv').style.top='118px';
  	document.getElementById('SpanDiv').style.left='710px';  
  	document.getElementById('SpanDiv').style.zIndex='2000';
	if (changeLanguage == 'English'){
		document.getElementById('SpanDiv').style.left='-100px';
		document.getElementById('SpanDiv').style.width='400px';
	        
	}
	if (searchString.indexOf('903349')!= -1){
		document.getElementById('SpanDiv').style.left='-900px';
		document.getElementById('SpanDiv').style.width='400px';
	}
      }

/*
  if ((searchString.search('7058537') != -1) || (searchString.search('7061303') != -1) || (searchString.search('7061178') != -1) || (searchString.search('7058528') != -1))
	{
		document.getElementById('SpanDiv').style.top='130px';
	}
*/
}

//if (document.location.href.search('cms')!= -1)
//    {
	//alert('addElement');
	addElement();
 //   }

/* THIS CODE IS FOR EXTENDED PAGES ONLY */
//if (document.location.href.search('cms')!= -1)
   // {
	if (document.location.href.indexOf('extended') != -1){
		//alert('extended');
		
		if (changeLanguage == 'English'){
			
			if (whichBrowser=='ie7'){
				//alert(whichBrowser);
				//alert(document.getElementById('SpanDiv').style.left);
				document.getElementById('SpanDiv').style.left='-1300px';
			}
			if (whichBrowser=='ie8'){
				//alert(whichBrowser);
				//alert(document.getElementById('SpanDiv').style.left);
				document.getElementById('SpanDiv').style.left='-1300px';
			}
			if (whichBrowser=='notIE'){
			   if (document.location.href.indexOf('7063085') == -1){
				document.getElementById('SpanDiv').style.left='-140px';
				}
			   else{
				document.getElementById('SpanDiv').style.left='-290px';
				}
			}
			if ((searchString.indexOf('7061512')!= -1) && (whichBrowser=='ie7')){
				//alert(document.getElementById('SpanDiv').style.left);
				document.getElementById('SpanDiv').style.left='-800px';
			}
			
			
	    	}
		
	       

	}
		/* LOTS OF PROBLEMS WITH IE8, THESE ARE ALL #### TEMPORARY BANDAIDS ##### UNTIL TIME TO FIX */

		if (whichBrowser=='ie8'){
			if (document.location.href.indexOf('7053315') != -1)
				{
					document.getElementById('SpanDiv').style.left='70px';
					//alert('testing');
					//alert(document.getElementById('SpanDiv').style.left);
				}
			if (document.location.href.indexOf('7058412') != -1)
				{
					document.getElementById('SpanDiv').style.left='70px';
					//alert('testing');
					//alert(document.getElementById('SpanDiv').style.left);
				}
			if (document.location.href.indexOf('7062988') != -1)
				{
					document.getElementById('SpanDiv').style.left='-70px';
					//alert('testing');
					//alert(document.getElementById('SpanDiv').style.left);
				}
			if (document.location.href.indexOf('7058472') != -1)
				{
					document.getElementById('SpanDiv').style.left='70px';
					//alert('testing');
					//alert(document.getElementById('SpanDiv').style.left);
				}
			if (document.location.href.indexOf('7058528') != -1)
				{
					document.getElementById('SpanDiv').style.left='155px';
					document.getElementById('SpanDiv').style.top='130px';
					//alert('testing');
					//alert(document.getElementById('SpanDiv').style.left);
					//alert(document.getElementById('SpanDiv').style.top);
				}
			if (document.location.href.indexOf('7058533') != -1)
				{
					document.getElementById('SpanDiv').style.left='140px';
					//alert('testing');
					//alert(document.getElementById('SpanDiv').style.left);
				}
			if (document.location.href.indexOf('7062978') != -1)
				{
					document.getElementById('SpanDiv').style.left='70px';
					//alert('testing');
					//alert(document.getElementById('SpanDiv').style.left);
				}
			if (document.location.href.indexOf('7061512') != -1)
				{
					document.getElementById('SpanDiv').style.left='-70px';
					//alert('testing');
					//alert(document.getElementById('SpanDiv').style.left);
				}
			if (document.location.href.indexOf('7061513') != -1)
				{
					document.getElementById('SpanDiv').style.left='-70px';
					//alert('testing');
					//alert(document.getElementById('SpanDiv').style.left);
				}
			if (document.location.href.indexOf('7053818') != -1)
				{
					document.getElementById('SpanDiv').style.left='70px';
					//alert('testing');
					//alert(document.getElementById('SpanDiv').style.left);
				}
			if (document.location.href.indexOf('7058475') != -1)
				{
					document.getElementById('SpanDiv').style.left='70px';
					//alert('testing');
					//alert(document.getElementById('SpanDiv').style.left);
				}
			if (document.location.href.indexOf('7058535') != -1)
				{
					document.getElementById('SpanDiv').style.left='140px';
					//alert('testing');
					//alert(document.getElementById('SpanDiv').style.left);
				}
			if (document.location.href.indexOf('7058536') != -1)
				{
					document.getElementById('SpanDiv').style.left='140px';
					//alert('testing');
					//alert(document.getElementById('SpanDiv').style.left);
				}
		}

   // }


