function validsearch()
{
  
  var selObj1 = document.getElementById('year');
	var selIndex1 = selObj1.selectedIndex;
	//alert(selIndex)
  var year=selObj1.options[selIndex1].value;
	var selObj2 = document.getElementById('make');
	var selIndex2 = selObj2.selectedIndex;
	//alert(selIndex)
	var make=selObj2.options[selIndex2].value;
	MakeOne = make.replace(/\s/g,"-");
	URL = 'http://www.buyautoparts.com/selectmodel/'+year+'_'+MakeOne+'.html';
	//alert(URL)
	window.location.replace(URL);
	return false;
}

/* Ajax function for addtoart page*/
function checkit(val)
	{
	
	if(makAx())
		{
		var originalpart="originalpart"+val		
		//alert(originalpart)
		var opartid = document.getElementById(originalpart).value;
    //alert(opartid)
		var code="code"+val
    var codeid = document.getElementById(code).value;
		//alert(codeid);
		var cartid="cartid"+val
		var cartid = document.getElementById(cartid).value;
    // alert(cartid)
		var dumpartid="dpartid"+val
		var dpartid = document.getElementById(dumpartid).value;
		//alert(dpartid)
		var price1="price"+val
		var price = document.getElementById(price1).value;
		//alert(price)
		var corepr="core"+val
		var core = document.getElementById(corepr).value;
		//alert(core)
		var desc1="desc"+val
		var desc=document.getElementById(desc1).value;
		//alert(desc)
		var mak="smake"+val
		var make=document.getElementById(mak).value;
		//alert(make)
		var mod="model"+val
		var model=document.getElementById(mod).value;
		//alert(model)
		var yr="myear"+val
		var year=document.getElementById(yr).value;
		//alert(year)
		var weigh="weight"+val
		var weight=document.getElementById(weigh).value;
		//alert(weight)
		//alert(document.location)
    var url = "http://www.buyautoparts.com/trolley.asp?opartid="+opartid+"&codeid="+codeid+"&cartid="+cartid+"&dpartid="+dpartid+"&price="+price+"&core="+core+"&desc="+desc+"&make="+make+"&model="+model+"&myear="+year+"&weight="+weight +"&random=" + Math.random();    
	//alert(url);
		callcpass(url,val)
		}
}

function callcpass(url,val)
				 {
				 xm.open("GET",url,true);
         xm.onreadystatechange = function()
				 											 {
															 if(xm.readyState == 4)
                        	         	{ 
                                 		var response = xm.responseText;
                                 		//alert(response);
																		var mySplitResult = response.split("|");
																		qty=mySplitResult[0];
																		noofrows=mySplitResult[1];
																		total=mySplitResult[2];
																		
                                 		res="result"+val;
																		//alert(qty)
																		str = document.getElementById(res);
                                 		//alert(str)
                                 		str.innerHTML = qty;
																		//tot="Shopping Cart <br> "+noofrows+": $"+total+"";
																		tot=noofrows+": $"+total+"";
																		str = document.getElementById("trolley");
    		 														str.value = tot;
																		runEffect('Fade', 'main', {duration: 100, from: 100, to: 0, toggle: true}, 'Makes an HTML element appear or fade away.');
																		
                                 		}
															 }
				xm.send(null)
		 		}
	
function makAx(){
try {
  xm = new ActiveXObject("Msxml2.XMLHTTP");
  return true;
} catch (e) {
  try {
    xm = new ActiveXObject("Microsoft.XMLHTTP");
	return true;
  } catch (e2) {
    xm = false;
  }
}

if (!xm && typeof XMLHttpRequest != 'undefined') {
  xm = new XMLHttpRequest();
  return true;
}
}

function FnEvents()
	{
	//alert("test")
	var eve;
	eve = document.parts.descriptform.value;
	if (eve == 1)
	{
	alert("Please Select a Part");
	document.parts.descriptform.focus();
	}
	else
	document.location.href=eve;
	}
	
	/*ajax function for viewcart page*/



function showtrolley(val,stat)
	{
	//alert("test")
	if(maknewAx())
		{
		var qty="qty"+val		
		var swqty = document.getElementById(qty).value;
		//alert(swqty)
		if (isNaN(swqty))
		 	 {
			 alert("Please Enter Numeric Value for Quantity");
			 document.getElementById(qty).select();
			 return false();
		 	 }
		var opart="originalpart"+val
		var swopart = document.getElementById(opart).value;
		var dpart="dummypart"+val
		var swdpart = document.getElementById(dpart).value;
		var code="code"+val
		var swcode = document.getElementById(code).value;
		var cartid="cartid"+val
		var swcartid = document.getElementById(cartid).value;
		var swdiscount = document.getElementById("discountdet").value;
		var action=stat;
		var url = "http://www.buyautoparts.com/showtrolley.asp?opartid="+swopart+"&cartid="+swcartid+"&codeid="+swcode+"&qty="+swqty+"&dpartid="+swdpart+"&discount="+swdiscount+"&action="+action+"&random=" + Math.random();
		//alert(url);
		callnewcpass(url,val)
		}
	}
	
	
		 
function callnewcpass(url,val)
				 {
				 xm.open("GET",url,true);
         xm.onreadystatechange = function()
				 											 {
															 if(xm.readyState == 4)
                        	         	{ 
                                 		var response = xm.responseText;
                                 		//alert(response);
																		var mySplitResult = response.split("|");
																		//alert(mySplitResult[2])
																		//alert("s")
																		qty=mySplitResult[0];
																		//alert("qty")
																		noofrows=mySplitResult[1];
																		//alert("noofrows")
																		var subtot=mySplitResult[2];
																		//alert("subtot")
																		pricetotal=mySplitResult[3];
																		//alert("pricetotal")
																		coretot=mySplitResult[4];
																		//alert("coretot")
																		fulltot=mySplitResult[5];
																		//alert("1")
																		tot=noofrows+": $"+subtot+"";
																		
																		var res="qty"+val;
																		str = document.getElementById(res);
																		str.value = qty;
																		str = document.getElementById("trolley");
																		str.value = tot;
																		//alert("3")
																		var pricerow="pricetot"+val;
																		str = document.getElementById(pricerow);
																		str.innerHTML = "$"+pricetotal;
																		//alert("4")
																		str = document.getElementById("coretotal");
																		str.innerHTML = "$"+coretot;
																		//alert("5")
																		str = document.getElementById("subtotal");
																		str.innerHTML = "$"+subtot;
																		//alert("6")
																		str = document.getElementById("total");
																		str.innerHTML = "$"+fulltot;
																		//alert("done")
																		runEffect('Fade', 'main', {duration: 100, from: 100, to: 0, toggle: true}, 'Makes an HTML element appear or fade away.');              		
                                 		}
															 }
				xm.send(null)
		 		}
	
function maknewAx(){
try {
  xm = new ActiveXObject("Msxml2.XMLHTTP");
  return true;
} catch (e) {
  try {
    xm = new ActiveXObject("Microsoft.XMLHTTP");
	return true;
  } catch (e2) {
    xm = false;
  }
}

if (!xm && typeof XMLHttpRequest != 'undefined') {
  xm = new XMLHttpRequest();
  return true;
}
}	

function contactvalid()
{
	if(document.contactus.custname.value == "")
	{
		alert("Please Enter the Name");
		document.contactus.custname.select();
		return false;
	}
id1=document.contactus.email.value.indexOf("@")
id2=document.contactus.email.value.indexOf(".")
if (document.contactus.email.value=="")
{
	alert("Please enter the Email ID");
	document.contactus.email.focus();
	return false;
}

 if(id1==-1)
		{
		alert("Invalid Email Id:");
		document.contactus.email.focus();
		return false;
		}	
	if(id2==-1)
		{
		alert("Please Enter Domain Name Also:");
		document.contactus.email.focus();
		return false;
		}
var iChars = "!#$%^&*()+=-[]\\\';,/{}|\":<>?";

  for (var i = 0; i < document.contactus.email.value.length; i++) {
  	if (iChars.indexOf(document.contactus.email.value.charAt(i)) != -1) {
  	alert ("Your username has special characters. \nThese are not allowed.\n Please remove them and try again.");
	document.contactus.email.focus();
  	return false;
  	}
  }
	if(document.contactus.city.value == "")
	{
		alert("Please Enter the City Name and State Name");
		document.contactus.city.select();
		return false;
	}
	if(document.contactus.phone.value == "")
	{
		alert("Please Enter the Phone Number");
		document.contactus.phone.select();
		return false;
	}
var num=document.contactus.phone.value;
	for(i=0;i<num.length;i++)
	{ 
		var number=num.substring(i,i+1);	
		if(!((((number>=0) && (number<=9)) || (number=='-'))))
		{
			alert("Enter only numbers in Phone Number");
			document.contactus.phone.focus();
			return false;
		}
	}
	if(document.contactus.year.value == "")
	{
		alert("Please Enter the Year");
		document.contactus.year.select();
		return false;
	}
var num=document.contactus.year.value;
	for(i=0;i<num.length;i++)
	{ 
		var number=num.substring(i,i+1);	
		if(!((((number>=0) && (number<=9)))))
		{
			alert("Enter only numbers in Year");
			document.contactus.year.focus();
			return false;
		}
	}
	if(document.contactus.make.value == "")
	{
		alert("Please Enter the Make Name");
		document.contactus.make.select();
		return false;
	}
	if(document.contactus.carinfo.value == "")
	{
		alert("Please Enter the Carinfo");
		document.contactus.carinfo.select();
		return false;
	}
	if(document.contactus.part.value == "")
	{
		alert("Please Enter the Part Name");
		document.contactus.part.select();
		return false;
	}
	/*var custname = document.contactus.custname.value;
	var email = document.contactus.email.value;
	var city = document.contactus.city.value;
	var phone = document.contactus.phone.value;
	var year = document.contactus.year.value;
	var make = document.contactus.make.value;
	var carinfo = document.contactus.carinfo.value;
	var part = document.contactus.part.value;
	var comments = document.contactus.comments.value;
	location.href = "http://www.onlineaccompressors.com/sendmail~custname~"+custname+"~email~"+email+"~city~"+city+"~phone~"+phone+"~year~"+year+"~make~"+make+"~carinfo~"+carinfo+"~part~"+part+"~comments~"+comments+".asp";*/
return true;		
}
	

