// JavaScript Document
var ajax = new Array();

function getInfo(psel,file,vars,elmnt,addvars,size,stclass)
{
	var make = psel.options[psel.selectedIndex].value;
	if(make == "nl")
	{
		//
		var sPath = window.location.pathname;
		//var sPage = sPath.substring(sPath.lastIndexOf('\\') + 1);
		var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
		//alert(sPage);
		//alert();//
		location.href = sPage+'?showAll=1';
	}
	else
	{
		if(make.length>0){
			var index = ajax.length;
			ajax[index] = new sack();		
			ajax[index].requestFile = file + '?' + vars + '=' + make + '&size=' + size + '&styleclass=' +stclass + '&' + addvars;	// Specifying which file to get and variables to pass to the file
			ajax[index].element = elmnt;
			ajax[index].onLoading = function(){ whenLoading(elmnt) }; 
			ajax[index].onLoaded = function(){ whenLoaded(elmnt) };		
			ajax[index].onCompletion = function(){ createInformation(index,elmnt) };	// Specify function that will be executed after file has been found
			ajax[index].runAJAX();		// Execute AJAX function
		}
	}
}

function getInfoF(file,vars,elmnt,addvars,size,stclass)
{
	var make = document.getElementById('make').options[document.getElementById('make').selectedIndex].value;
	if(make == "nl")
	{
		//
		var sPath = window.location.pathname;
		//var sPage = sPath.substring(sPath.lastIndexOf('\\') + 1);
		var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
		//alert(sPage);
		//alert();//
		location.href = sPage+'?showAll=1';
	}
	else
	{
		if(make.length>0){
			var index = ajax.length;
			ajax[index] = new sack();		
			ajax[index].requestFile = file + '?' + vars + '=' + make + '&size=' + size + '&styleclass=' +stclass + '&' + addvars;	// Specifying which file to get and variables to pass to the file
			ajax[index].element = elmnt;
			ajax[index].onLoading = function(){ whenLoading(elmnt) }; 
			ajax[index].onLoaded = function(){ whenLoaded(elmnt) };		
			ajax[index].onCompletion = function(){ createInformation(index,elmnt) };	// Specify function that will be executed after file has been found
			ajax[index].runAJAX();		// Execute AJAX function
		}
	}
}

function getValueInfo(psel,file,vars,elmnt,addvars,size,stclass)
{
	var make = psel;
	if(make.length>0){
		var index = ajax.length;
		ajax[index] = new sack();		
		ajax[index].requestFile = file + '?' + vars + '=' + make + '&size=' + size + '&styleclass=' +stclass + '&' + addvars;	// Specifying which file to get and variables to pass to the file
		ajax[index].element = elmnt;
		ajax[index].onLoading = function(){ whenLoading(elmnt) }; 
		ajax[index].onLoaded = function(){ whenLoaded(elmnt) };		
		ajax[index].onCompletion = function(){ createInformation(index,elmnt) };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function
	}
}

function submitLogin(elmnt)
{
		var user = document.lform.email.value;
		var pass = document.lform.password.value;
		if((user.length>0) && (pass.length>0))
		{
			var index = ajax.length;
			ajax[index] = new sack();
			ajax[index].requestFile = 'loginpopup.asp?user='+user+'&password='+pass;
			ajax[index].element = elmnt;
			ajax[index].onLoading = function(){ whenLoading(elmnt) }; 
			ajax[index].onLoaded = function(){ whenLoaded(elmnt) };
			ajax[index].onCompletion = function(){ createInformation(index,elmnt) };	// Specify function that will be executed after file has been found
			ajax[index].runAJAX();
		}
}
function doLogout(elmnt)
{
	var index = ajax.length;
	ajax[index] = new sack();
	ajax[index].requestFile = 'loginer.asp?action=logout';
	ajax[index].element = elmnt;
	ajax[index].onLoading = function(){ whenLoading(elmnt) }; 
	ajax[index].onLoaded = function(){ whenLoaded(elmnt) };
	ajax[index].onCompletion = function(){ createInformation(index,elmnt) };	// Specify function that will be executed after file has been found
	ajax[index].runAJAX();
		
}

function whenLoading(elmnt){
	var e = document.getElementById(elmnt); 
	e.innerHTML = "";
	e.innerHTML = "<img src='images/ajax-loader.gif' border='0'>";
}
function whenLoaded(elmnt){
	var e = document.getElementById(elmnt); 
	e.innerHTML = "";
}
function createInformation(index,elmnt)
{
	var obj = document.getElementById(elmnt);
	obj.innerHTML = ajax[index].response
}

function submitForm(action)
{
	window.location = action;
}

function subForm()
{
	index0 = document.getElementById('fuel').selectedIndex;
	index1 = document.getElementById('bodytype').selectedIndex;
	index2 = document.getElementById('cc').selectedIndex;
	if(document.getElementById('make').selectedIndex == 0 )
	{
		alert('Please select your vehicle make');
	}
	else if(document.getElementById('model').selectedIndex == 0 )
	{
		alert('Please select your vehicle model');
	}
	else if(document.getElementById('year').selectedIndex == 0 )
	{
		alert('Please select your vehicle registration year');
	}	
//	document.form1.select1.
	else if(document.getElementById('fuel').options[index0].value == "nk")
	{
		alert('Please select fuel type for your vehicle');
	}
	else if(document.getElementById('cc').options[index2].value == "nk")
	{	
		alert('Please select CC for your vehicle');
	}
	else if(document.getElementById('cc').options[index2].value == "")
	{	
		alert('Please select CC for your vehicle');
	}
	else if(document.getElementById('bodytype').options[index1].value == "nk")
	{	
		alert('Please select body type for your vehicle');
	}
	else if(document.getElementById('bodytype').options[index1].value == "")
	{	
		alert('Please select body type for your vehicle');
	}
	
	else if(document.getElementById('gboxtype').selectedIndex == 0)
	{
		alert('Please select Gearbox type for your vehicle');
	}
	else
	{
		document.form.submit();
	}
}

function showhide(sel)
{
	var partsList = new Array();
	partsList[0] = 'engine';
	partsList[1] = 'gbmt';
	partsList[2] = 'gbat';
	partsList[3] = 'cylhead';
	partsList[4] = 'dist';
	partsList[5] = 'starter';
	partsList[6] = 'turbo';
	partsList[7] = 'inject';
	partsList[8] = 'alt';
	partsList[9] = 'other';
	for (x=0; x<=9; x= x+1)
	{ 
		if(partsList[x].length > 2)
		{
			if(document.getElementById(partsList[x]).style.display == 'block')
			{
				document.getElementById(partsList[x]).style.display = 'none';
			}
		}
	}
	if(document.getElementById(sel).style.display == 'none')
	{
		document.getElementById(sel).style.display = 'block';
	}
	else
	{
		document.getElementById(sel).style.display = 'none';
	}
}


function flipImages(i)
{	
//alert('Incomming value = '+i);
	var j =1;
	if (j == i)
	{
		//alert('J=I showing first pic');
		i = i + 1;
		document.getElementById('imgchanger').src = 'images/o'+i+'.jpg';
		var name = "flipImages("+i+")";
		setTimeout(name,1500);
	}
	if ((j < i) && (i<7))
	{
		//alert('J<I showing '+i);
		i = i + 1;
		document.getElementById('imgchanger').src = 'images/o'+i+'.jpg';
		var name = "flipImages("+i+")";
		setTimeout(name,1500);
	}
	else
	{
		var name = "flipImages(1)";
		setTimeout(name,1500);
	}
}
function toggle(sl)
{
	//alert(document.getElementById(elemnt).style.display);
	//slidedown(elemnt);
	if(ShoppingWindow.getElementById(sl).style.display != 'none')
	{
		ShoppingWindow.getElementById(sl).style.display != 'block';
		//new Effect.SlideUp(document.getElementById(sl));
		//document.getElementById(sl+'icon').src = 'images/show.jpg';
	}
	else
	{
		ShoppingWindow.getElementById(sl).style.display != 'none';
		//new Effect.SlideDown(document.getElementById(sl));
		//document.getElementById(sl+'icon').src = 'images/hide.jpg';
	}
}
function MM_CheckFlashVersion(reqVerStr,msg){
  with(navigator){
    var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
    var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
    if (!isIE || !isWin){  
      var flashVer = -1;
      if (plugins && plugins.length > 0){
        var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
        desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
        if (desc == "") flashVer = -1;
        else{
          var descArr = desc.split(" ");
          var tempArrMajor = descArr[2].split(".");
          var verMajor = tempArrMajor[0];
          var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
          var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
          flashVer =  parseFloat(verMajor + "." + verMinor);
        }
      }
      // WebTV has Flash Player 4 or lower -- too low for video
      else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

      var verArr = reqVerStr.split(",");
      var reqVer = parseFloat(verArr[0] + "." + verArr[2]);
  
      if (flashVer < reqVer){
        if (confirm(msg))
          window.location = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
      }
    }
  } 
}

function Cart(vars,elmnt)
{
	var index = ajax.length;
	ajax[index] = new sack();		
	ajax[index].requestFile = 'getCart.asp?' + vars ;	// Specifying which file to get and variables to pass to the file
	ajax[index].element = elmnt;
	ajax[index].onLoading = function(){ whenLoading(elmnt) }; 
	ajax[index].onLoaded = function(){ whenLoaded(elmnt) };		
	ajax[index].onCompletion = function(){ createInformation(index,elmnt) };	// Specify function that will be executed after file has been found
	ajax[index].runAJAX();		// Execute AJAX function
}
function toggleDisplay(e,hide){
imgX="icon"+e;
tableX="model"+e;
element = document.getElementById(tableX).style;
	
	if (element.display=='none') 
		{
			element.display='block';
			if (hide == 'Yes')
			{
			document.getElementById(imgX).src='images/hide.jpg';
			}
		}
	else 
		{
			element.display='none';
			if (hide == 'Yes')
			{
			document.getElementById(imgX).src='images/show.jpg';
			}
		}
}
function toggleDisplay2(e,hide){
imgX="icon"+e;
tableX="model"+e;
element = document.getElementById(tableX).style;
	
	if (element.display=='none') 
		{
			element.display='block';
			if (hide == 'Yes')
			{
			document.getElementById(imgX).src='images/hide1.jpg';
			}
		}
	else 
		{
			element.display='none';
			if (hide == 'Yes')
			{
			document.getElementById(imgX).src='images/show1.jpg';
			}
		}
}
window.name = "ShoppingWindow";

function savencontinue()
{
	var poscode;
	poscode = prompt("Please enter your Shipping address post code so that the system can know you are eligible for free shipping","Enter your post code here");
	if (poscode != null)
	{
		if (poscode.length > 10 )
		{
			alert('Please enter a valid Post Code');
			savencontinue();
		}
		else if (poscode.length < 5)
		{
			alert('Please enter a valid Post Code');
			savencontinue();
		}
		else
		{
			//document.getElementById('pcode').value = poscode;
			alert('Please wait while the postcode is verified and you are being redirected to order confirmation...');
			postit(poscode);
			//window.location = "confirmOrder.asp?postcode="+poscode;
		}
	}
}

function postit(ukpostcode){ //check postcode format is valid
 test = ukpostcode; 
 size = test.length
 test = test.toUpperCase(); //Change to uppercase
 while (test.slice(0,1) == " ") //Strip leading spaces
  {
	test = test.substr(1,size-1);
	size = test.length
  }
 while(test.slice(size-1,size)== " ") //Strip trailing spaces
  {
	test = test.substr(0,size-1);
	size = test.length
  }
 document.postcodev.postcode.value = test; //write back to form field
 if (size < 6 || size > 8){ //Code length rule
  alert(test + " is not a valid postcode - wrong length");
  savencontinue();
  return false;
  }
 if (!(isNaN(test.charAt(0)))){ //leftmost character must be alpha character rule
   alert(test + " is not a valid postcode - cannot start with a number");
   savencontinue();
   return false;
  }
 if (isNaN(test.charAt(size-3))){ //first character of inward code must be numeric rule
   alert(test + " is not a valid postcode - alpha character in wrong position");
   savencontinue();
   return false;
  }
 if (!(isNaN(test.charAt(size-2)))){ //second character of inward code must be alpha rule
   alert(test + " is not a valid postcode - number in wrong position");
   savencontinue();
   return false;
  }
 if (!(isNaN(test.charAt(size-1)))){ //third character of inward code must be alpha rule
   alert(test + " is not a valid postcode - number in wrong position");
   savencontinue();
   return false;
  }
 if (!(test.charAt(size-4) == " ")){//space in position length-3 rule
   alert(test + " is not a valid postcode - no space or space in wrong position");
   savencontinue();
   return false;
   }
 count1 = test.indexOf(" ");count2 = test.lastIndexOf(" ");
 if (count1 != count2){//only one space rule
   alert(test + " is not a valid postcode - only one space allowed");
   savencontinue();
   return false;
  }
	//window.location = "confirmOrder.asp?postcode="+ukpostcode;
	document.postcodev.submit();
//return true;
}

function makeChangedReverse(){

	document.getElementById('year').selectedIndex = 0;	
	document.getElementById('year').disabled = true;
	document.getElementById('fuel').selectedIndex = 0;	
	document.getElementById('fuel').disabled = true;
	document.getElementById('cc').selectedIndex = 0;	
	document.getElementById('cc').disabled = true;
	//document.getElementById('etype').selectedIndex = 0;	
	//document.getElementById('etype').disabled = true;
	//document.getElementById('body').selectedIndex = 0;	
	//document.getElementById('body').disabled = true;
}
function letsGo(url,parameters)
{
	window.parent.location = url+'?'+parameters;
}
function checkCode(ukpostcode,nm)
{
 result = true;
 test = ukpostcode; 
 size = test.length
 test = test.toUpperCase(); //Change to uppercase
 while (test.slice(0,1) == " ") //Strip leading spaces
  {
	test = test.substr(1,size-1);
	size = test.length
  }
 while(test.slice(size-1,size)== " ") //Strip trailing spaces
  {
	test = test.substr(0,size-1);
	size = test.length
  }
 //document.postcodev.postcode.value = test; //write back to form field
 if (size == 0){ //Code length rule
  alert("Please enter a"+nm+"postcode");
  result = false;
  }
  if (result == true )
  {
 if (size < 6 || size > 8){ //Code length rule
  //alert(test + " is not a valid postcode - wrong length");
  alert(test + " is not a valid"+nm+"postcode");
  result = false;
  }
 if (!(isNaN(test.charAt(0))) && result == true){ //leftmost character must be alpha character rule
   //alert(test + " is not a valid postcode - cannot start with a number");
   alert(test + " is not a valid"+nm+"postcode");
   result = false;
  }
 if (isNaN(test.charAt(size-3)) && result == true){ //first character of inward code must be numeric rule
   //alert(test + " is not a valid postcode - alpha character in wrong position");
   alert(test + " is not a valid"+nm+"postcode");
   result = false;
  }
 if (!(isNaN(test.charAt(size-2))) && result == true){ //second character of inward code must be alpha rule
   //alert(test + " is not a valid postcode - number in wrong position");
   alert(test + " is not a valid"+nm+"postcode");
   result = false;
  }
 if (!(isNaN(test.charAt(size-1))) && result == true){ //third character of inward code must be alpha rule
   //alert(test + " is not a valid postcode - number in wrong position");
   alert(test + " is not a valid"+nm+"postcode");
   result = false;
  }
 if (!(test.charAt(size-4) == " ") && result == true){//space in position length-3 rule
   //alert(test + " is not a valid postcode - no space or space in wrong position");
   alert(test + " is not a valid"+nm+"postcode");
   result = false;
   }
 count1 = test.indexOf(" ");count2 = test.lastIndexOf(" ");
 if (count1 != count2 && result == true){//only one space rule
   //alert(test + " is not a valid postcode - only one space allowed");
   alert(test + " is not a valid"+nm+"postcode");
   result = false;
  }
  }
  return result;
}

window.name="ShoppingWindow"