// JavaScript Document

 //End Function
function validsearch()
{	
	if(document.getElementById('sel-year').value == "" )
			  {
				  alert("please select the year");
					return false;
				}
				else if(document.getElementById('sel-make').value == "" )
				{
				 alert("please select the make");
				 return false;
				 }
				//else if(document.getElementById('sel-model').value == "" )
				//{
				 //alert("please select the model");
				 //return false;
				 //}
				 else
				{
				  				
				var selObj1 = document.getElementById('sel-year');
				var selIndex1 = selObj1.selectedIndex;
				var year=selObj1.options[selIndex1].value;
				var selObj2 = document.getElementById('sel-make');
				var selIndex2 = selObj2.selectedIndex;
				var make=selObj2.options[selIndex2].value;
				
				var make=selObj2.options[selIndex2].value;
				MakeOne = make.replace(/\s/g,"-");
				URL = 'http://www.navigationpros.com/selectmodel/'+year+'_'+MakeOne+'.html';
				window.location.replace(URL);
				return false;
	
	
	
	}
}
function test()
{
 if(document.getElementById('sel-year').value == "" )
			  {
				  alert("please select the year");
					return false;
				}
				else if(document.getElementById('sel-make').value == "" )
				{
				 alert("please select the make");
				 return false;
				 }
				else if(document.getElementById('sel-model').value == "" )
				{
				 alert("please select the model");
				 return false;
				 }
				 else
				 {
				    return true;
					}
}

function FnEvents()
	{
	var eve;
	eve = document.parts.descriptform.value;
	if (eve == 1)
	{
	alert("Please Select a Part");
	document.parts.descriptform.focus();
	}
	else
	document.location.href=eve;
	}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function discountvalidation()
	{
		if(document.discount.promocode.value=="")
		 {
		 	alert("Please enter the Coupon Code");
			document.discount.promocode.select();
			return false;
		}
		var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
		for(var i=0;i<document.discount.promocode.value.length;i++)
		{
			if(iChars.indexOf(document.discount.promocode.value.charAt(i)) != -1)
			{
				alert("Coupon Code Has Special Characters. \nThese Are Not Allowed.\n Please Remove Them And Try Again.");
				document.discount.promocode.select();
				return false;
			}
		}
	  return true;		
	}


/*Login scripts*/

function formvalidate()
	{
		if (document.loginform.username.value=="")
			{
		    alert("Please Enter User Name");
		    document.loginform.username.select();
		    document.loginform.username.focus();
		    return false;
			}
		if (document.loginform.password.value=="")
			{
		    alert("Please Enter Password");
		    document.loginform.password.select();
		    document.loginform.password.focus();
		    return false;
			}
	}

/*User account script	*/


	function shipSameAsBill()
{
	
	if (document.custdetails.shipsameasbill.checked == true)
	{
		document.custdetails.sfirstname.value=document.custdetails.bfirstname.value;
		document.custdetails.slastname.value=document.custdetails.blastname.value;
		document.custdetails.saddress1.value=document.custdetails.baddress1.value;
		document.custdetails.saddress2.value=document.custdetails.baddress2.value;
		document.custdetails.scity.value=document.custdetails.bcity.value;
		document.custdetails.sstate.value=  document.custdetails.bstate.value;
		document.custdetails.sphone.value=  document.custdetails.bphone.value;
		document.custdetails.szip.value = document.custdetails.bzip.value;
		document.custdetails.scountry.value=  document.custdetails.bcountry.value;
	}
	else
	{
		document.custdetails.sfirstname.value="";
		document.custdetails.slastname.value="";
		document.custdetails.saddress1.value="";
		document.custdetails.saddress2.value="";
		document.custdetails.scity.value="";
		document.custdetails.sstate.value =  "";
		document.custdetails.sphone.value="";
		document.custdetails.szip.value = "";
		document.custdetails.scountry.value =  "";
	}	
	
}

/*change pasword*/

function passwordchk()
{
	if (document.pwdform.oldpwd.value=="")
	{
		alert("Please Enter Your Old Password!");
		document.pwdform.oldpwd.select();
		document.pwdform.oldpwd.focus();
		return false;
	}
	if (document.pwdform.newpwd.value=="")
	{
		alert("Please Enter A New Password!");
		document.pwdform.newpwd.select();
		document.pwdform.newpwd.focus();
		return false;
	}
	if (document.pwdform.confpwd.value=="")
	{
		alert("Please Enter Confirm Your New Password!");
		document.pwdform.confpwd.select();
		document.pwdform.confpwd.focus();
		return false;
	}
	if (document.pwdform.newpwd.value!=document.pwdform.confpwd.value)
	{
		alert("The New Password and Confirmation Mismatch!");
		document.pwdform.confpwd.select();
		document.pwdform.confpwd.focus();
		return false;
	}
}
	
	
function chkdiv()
	{
		if (document.getElementById('forgotpass').style.display == "none")
			document.getElementById('forgotpass').style.display='block';
		else
			document.getElementById('forgotpass').style.display='none';
	}
	

	
	
	
	
/* 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.navigationpros.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;
																		
																		
                                 		}
															 }
				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;
}
}
	

/*ajax function for viewcart page*/



function showtrolley(val,stat)
	{
	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.navigationpros.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;
}
}	

/* Ajax function for Contact us page*/


function concheckit()
	{
	 //alert("test1");
	if(conmakAx())
		{
		var selObj1 = document.getElementById('cmake');
        var selIndex1 = selObj1.selectedIndex;
				//alert(selIndex)
        var make=selObj1.options[selIndex1].value;
				//alert(make)
				var selObj2 = document.getElementById('cyear');
        var selIndex2 = selObj2.selectedIndex;
				//alert(selIndex)
        var year=selObj2.options[selIndex2].value;
				//alert(year)
		url = "http://www.dieselpartspros.com/makemodel.asp?make="+make+"&year="+year
		//alert(url);
		document.getElementById("result").innerHTML="";
		document.getElementById("result").innerHTML='<img src="http://dieselpartspros.com/images/load.gif" alt="loading">'
			concallCpass()
		}
}
function concallCpass()
{
	xm.open("GET",url,true);
	xm.onreadystatechange = concpass
	xm.send(null)
}

//This is gives response from server
function concpass()
{
	if(xm.readyState == 4)
	{
		var response = xm.responseText
		str = document.getElementById("models")
		//alert(response)
		str.innerHTML = response
	}
}

function conmakAx(){
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;
}
}


