﻿/*===================================================================================================================
Part Purchase Steps
=====================================================================================================================*/
function ShowStep(pmStep)
{
    
      try
		{		    
	        var iCurStep = GetCurrentStep();		
            if (pmStep > iCurStep)
			{
				//document.PartRequest.hid_count.value = 1			

				if (pmStep == "2" || pmStep == "3" || pmStep == "4" || pmStep == "5") 
				//#--Vehicle Information
				//#--Checks whether all mandatory fields are filled or not
				{				
                    if (part1() == false) //Checks Vehicle Information
					    {
						    //#--Show tab 1
						    //ShowMe(1)
                
						    //#--Returns error msg while any mandatory field is empty
						    checkpart1()
                
						    return false
					    }              
				 }
				    
				    if (pmStep == "3" || pmStep == "4" || pmStep == "5")
				    //#--Part Informtaion
				    //#--Checks whether all mandatory fields are filled or not
				    {  
					    if (part2() == false)
					    {
						    //#--Show tab 2
						    //ShowMe(2)
						    //#--Returns error msg while any mandatory field is empty
						    checkpart2()
						    
						    return false
					    }
				    }
	
			
				    if (pmStep == "4" || pmStep == "5") 
				    //#--Contact Information
				    //#--Checks whether all mandatory fields are filled or not
				    {
					    if (part3() == false)
					    {//#--Returns error msg while any mandatory field is empty
						    //#--Show tab 3
						    //ShowMe(3)
						    //#--Returns error msg while any mandatory field is empty
						    checkpart3(); 					
						    return false;
					    }
				    }
				   
				    if (pmStep == "5") 
				    //#--Shipping Information
				    //#--Checks whether all mandatory fields are filled or not
				    { 	part4();	
				 	    if (checkpart4()==true)
					    {//#--Returns error msg while any mandatory field is empty
						     //#--Show tab 4
						    //ShowMe(5)
						    //#--Returns error msg while any mandatory field is empty
						    document.getElementById('errormsg').innerHTML = "";
			                document.getElementById('errormsg').style.visibility = "hidden";
						    return true;
					    } else
					    { 
						    //ShowMe(3);
						    return false;
					    }
				    }
				   
			}
			    //ShowMe(pmStep);
			    document.getElementById('errormsg').innerHTML = "";
			    document.getElementById('errormsg').style.visibility = "hidden";
			    return true;
			    
			  /*  
				switch (pmStep){
				case 1:
					document.getElementById("int_C_Year").focus()
				case 2:
					document.getElementById("int_C_PartID8").focus()
				case 3:
					document.getElementById("txt_C_Name").focus()
				case 4:
					document.getElementById("txt_C_Name").focus()
				}
		    */
			
		}
		catch(Exception){}
}

function part1()
	{
		try
		{
			vIsSubModel = false
			if (document.getElementById("int_O_SubModel8") != null)
			{
				vIsSubModel = (document.getElementById("int_O_SubModel8").value == "")
			}
			///#--Checks whether Body Style div tag is visible
			vIsBodyStyle = false
			if (document.getElementById("int_O_BodyStyleID8") != null)
			{
				vIsBodyStyle = (document.getElementById("int_O_BodyStyleID8").value == "")
			}
	
			vYear = (document.getElementById("int_C_Year").value == "")
			vMake = (document.getElementById("int_C_Make8").value == "") //|| (document.getElementById("int_C_Make8") == null && document.getElementById("txt_O_OtherMake").value == ""))			
			var vModel = false;
			if (document.getElementById("int_C_Model8") != null){
			    vModel = (document.getElementById("int_C_Model8").value == "")    
			} else {
			    vModel = (document.getElementById("txt_O_OtherModel").value == "")
			}
			vTransmission = (document.getElementById("int_C_TransmissionID8").value == "")
			if (vYear || vMake || vModel || vTransmission || vIsSubModel || vIsBodyStyle)
			{
				return false;
			}
			else
			{
			    return true;
			}
		}
		catch(exception){}
	}
	
	function checkpart1()
	{
	    document.getElementById('errormsg').innerHTML = "";
		if (document.getElementById("int_C_Year").value == "")
		{
			//alert("Please select a Year")
			showwarning('waryear')
			showerror("Year is required")
			document.getElementById("int_C_Year").focus()
			//return 
		}

		if (document.getElementById("int_C_Make8").value == "")
		{
			//alert("Please select a Make")
			showwarning('warmake')
			showerror("Make is required")
			document.getElementById("int_C_Make8").focus()
			//return
		}
        if (document.getElementById("int_C_Model8") != null)
		{
		    if (document.getElementById("int_C_Model8").value ==""){
		        //alert("Please select a Model")
		        showwarning('warmodel')
		        showerror("Model is required")
			    document.getElementById("int_C_Model8").focus()
			    //return
			}
		} else {
		    if (document.getElementById("txt_O_OtherModel").value ==""){
		        //alert("Please enter Other Model")
		        showwarning('warmodel')
		        showerror("Model is required")
			    document.getElementById("txt_O_OtherModel").focus()
			    //return
		    }	    
		}
		
		//#--Check Sub Model
		var vIsSubModel = false
		if (document.getElementById("int_O_SubModel8") != null)
			vIsSubModel = (document.getElementById("int_O_SubModel8").value == "" )

		///#--Checks whether Body Style div tag is visible
		var vIsBodyStyle = false
		if (document.getElementById("int_O_BodyStyleID8") != null)
			vIsBodyStyle = (document.getElementById("int_O_BodyStyleID8").value == "")

		if (vIsSubModel)
		{
			//alert("Please select a Sub Model")
			showwarning('warsubmodel')
			showerror("Sub Model is required")
			document.getElementById("int_O_SubModel8").focus()
			//return
		}
			
		if (vIsBodyStyle)
		{
			//alert("Please select a Body Style")
			showwarning('warbody')
			showerror("Body Style is required")
			document.getElementById("int_O_BodyStyleID8").focus()
			//return
		}

		if (document.getElementById("int_C_TransmissionID8").value == "")
		{
			//alert("Please enter Transmission")
			showwarning('wartrans')
			showerror("Transmission is required")
			document.getElementById("int_C_TransmissionID8").focus()
			//return
		}
        return

	}

    function part2()
	{
		var vRetValue = true;
		try
		{
    
			if (document.getElementById("int_C_PartID8").value == "" || 
				(document.getElementById("int_C_PartID8").options[document.getElementById("int_C_PartID8").selectedIndex].text == 'Other - Not Listed' && document.getElementById("txt_O_PartDesc").value == ""))
			{
				
				vRetValue = false;
			}
			else if (document.getElementById("PnlSubPart") != null)
			{
				if (document.getElementById("int_C_SubPartID").value == "")
				{	
					vRetValue = false;
				}
			}
			else if (document.getElementById("PnlPartDetails") != null)
			{
				if (document.getElementById("PartDetailsId").value == "")
				{	
					vRetValue = false;
				}
			}
			
			return vRetValue;
			
		}
		catch(exception){}
	}
	
	function checkpart2()
	{
	    var valid = true;
	    document.getElementById('errormsg').innerHTML = "";
		if (document.getElementById("int_C_PartID8").value == "")
		{
			 //alert('Please select a part');
			 showwarning('warparttype')
			 showerror("Part Type is required")
			 document.getElementById("int_C_PartID8").focus()
			 valid = false;			
		}

		if (document.getElementById("int_C_PartID8").options[document.getElementById("int_C_PartID8").selectedIndex].text == 'Other - Not Listed' && document.getElementById("txt_O_PartDesc").value == "")
		{
			//alert('Please enter Part Description')
			showwarning('warpartdesc')
			showerror("Part Description is required")
			document.getElementById("txt_O_PartDesc").focus()
			valid = false;
		}
		
		if (document.getElementById("PnlSubPart") != null)
		{
			if (document.getElementById("int_C_SubPartID").value == "")
			{	
			    //alert('Please enter Part Side')
			    showwarning('warpartside')
			    showerror("Part Side is required")
		        document.getElementById("int_C_SubPartID").focus()
		        valid = false;
			}
		}
		
		if (document.getElementById("PnlPartDetails") != null)
		{
			if (document.getElementById("PartDetailsId").value == "")
			{	
			    //alert('Please enter Part Details')
			    showwarning('warpartd')
			    showerror("Part Detail is required")
		        document.getElementById("PartDetailsId").focus()
		        valid = false;					
			}
		}
		return valid;
}

function part3()
	{
		/*
		if (document.PartRequest.hidPageSt.value=="Vendor")
		{
			lflgSt=part3Vendor();
		}
		else if (document.PartRequest.hidPageSt.value=="PartRequest")
		{
			lflgSt=part3PartRequest();
		}*/
		lflgSt=part3PartRequest();
		return lflgSt;
	}
	function trim(str)
    {    
	    return str.replace( /^ +/, "" ).replace( / +$/, "" );
    }
    
	function part3PartRequest()
	{
	    try
		{	
	        var sPhone = document.getElementById("txt_C_Phone").value;	        
	        if (sPhone == "___-___-____") { sPhone = (sPhone.replace(/_/gi,"")).replace(/-/gi,""); }
	       
			if (document.getElementById("txt_C_Name").value == "" || !isEmail(trim(document.getElementById("txt_C_Email").value)) || sPhone == ""  )
			{	
				return false;
			}
			else
			{	
				return true;
			}
		}
		catch(exception){}
	}



    function checkpart3()
	{	    
	    document.getElementById('errormsg').innerHTML = "";
		if (document.getElementById("txt_C_Name").value == "")
		{
			//alert("Please enter Name")
			showwarning('warname')
			showerror("Name is required")
			document.getElementById("txt_C_Name").focus()
			//return
		}
 
		if (!isEmail(trim(document.getElementById("txt_C_Email").value)))
		{
			//alert("Please enter correct email address")
			showwarning('waremail')
			showerror("Enter Your Correct Email Address (ie. your@email.com)")
			document.getElementById("txt_C_Email").focus()
			//return
		}
		if (trim(document.getElementById("txt_C_ShipCountries8").value) == "")
		{
				//alert( "Select a Country" );
				showwarning('warcountry')
			    showerror("Country is required")
				document.getElementById("txt_C_ShipCountries8").focus();
				//return
		}
		
			if (trim(document.getElementById("txt_C_ShipZipCode").value) == "" && (document.getElementById("txt_C_ShipCountries8").value =="3" || document.getElementById("txt_C_ShipCountries8").value =="2"))
			{
				//alert( "Enter a Zip/Postal Code" );
				 showwarning('warzip')
			     showerror("Zip/Postal code is required")
				 document.getElementById("txt_C_ShipZipCode").focus();
				//return
			}
			else if ((isNaN(document.getElementById("txt_C_ShipZipCode").value)) && document.getElementById("txt_C_ShipCountries8").value =="2" )
			{				
				showwarning('warzip')
			    showerror("Enter a Valid US Zip Code (ie. 90210)")
				vObject	=document.getElementById("txt_C_ShipZipCode");
			}
			else if ((document.getElementById("txt_C_ShipZipCode").value.length <5 || document.getElementById("txt_C_ShipZipCode").value.length >5) && document.getElementById("txt_C_ShipCountries8").value =="2" )
			{
				
				showwarning('warzip');
			    showerror("Enter a Valid US Zip Code (ie. 90210)");
				vObject	= document.getElementById("txt_C_ShipZipCode");
			}
			else if ((document.getElementById("txt_C_ShipZipCode").value.length <6 || document.getElementById("txt_C_ShipZipCode").value.length >7) && document.getElementById("txt_C_ShipCountries8").value =="3" )
			{
				//alert( "Enter a Valid Canadian Post Code (ie. K7R 2G9)");
				showwarning('warzip')
			    showerror("Enter a Valid Canadian Post Code (ie. K7R 2G9)")
				vObject	= document.getElementById("txt_C_ShipZipCode");
			}
			
		var sPhone = document.getElementById("txt_C_Phone").value;		
	    if (sPhone == "___-___-____") { sPhone = (sPhone.replace(/_/gi,"")).replace(/-/gi,""); }
	    	    
		if (trim(sPhone) == "")
		{
			//alert("Please enter phone number")
			showwarning('warphone')
			showerror("Phone is required")
			document.getElementById("txt_C_Phone").focus()
			//return
		}
		return;
		
	}

function part4()
	{ 
		try
		{
 			if (trim(document.getElementById("txt_C_Name").value) == "" ||	document.getElementById("txt_C_Email").value == "" ||
			document.getElementById("txt_C_Phone").value == "" ||	document.getElementById("txt_C_ShipCountries8").value == "" ||
			(   (document.getElementById("txt_C_ShipCountries8").value==2 ||	document.getElementById("txt_C_ShipCountries8").value==3)
				&& (document.getElementById("txt_C_ShipZipCode").value == ""))) 		 
			{	
				return false;
			}
			else
			{	
				return true;
			}
		}
		catch(Exception){}
	}
	
	function checkpart4()
	{
		var valid = true;
		document.getElementById('errormsg').innerHTML = "";
		
		if (document.getElementById("txt_C_Name").value == "")
		{
			//alert("Please enter Name")
			showwarning('warname')
			showerror("Name is required")
			document.getElementById("txt_C_Name").focus()
			valid = false;
		}
		
	    if (!isEmail(trim(document.getElementById("txt_C_Email").value)))
		{
		    
			//alert("Enter Your Correct Email Address (ie. your@email.com)")
			showwarning('waremail')
		    showerror("Enter Your Correct Email Address (ie. your@email.com)")
			document.getElementById("txt_C_Email").focus();	
			valid = false;
		}
		
		if (document.getElementById("txt_C_Phone").value =='') 
		{
			//alert("Please enter the Phone no")
			showwarning('warphone')
			showerror("Phone no is required")
			document.getElementById("txt_C_Phone").focus()
			valid = false;
		}
		if (document.getElementById("txt_C_ShipCountries8").value == "")
		{
			//alert("Please select a Country")
			showwarning('warcountry')
			showerror("Country is required")
			document.getElementById("txt_C_ShipCountries8").focus()
			valid = false;
		}
		if (document.getElementById("txt_C_ShipZipCode").value == "" && (document.getElementById("txt_C_ShipCountries8").value =="2"))
		{
			
			showwarning('warzip')
			showerror("Enter a Valid US Zip Code (ie. 90210)")
			document.getElementById("txt_C_ShipZipCode").focus()
			valid = false;
		}
		if (document.getElementById("txt_C_ShipZipCode").value == "" && (document.getElementById("txt_C_ShipCountries8").value =="3"))
		{
			//alert("Enter a Valid Canadian Post Code (ie. K7R 2G9)");			
			showwarning('warzip')
			showerror("Enter a Valid Canadian Zip Code (ie. K7R 2G9)")
			document.getElementById("txt_C_ShipZipCode").focus();
			valid = false;
		}
		else if ((isNaN(document.getElementById("txt_C_ShipZipCode").value)) && document.getElementById("txt_C_ShipCountries8").value =="2" )
		{
			//alert( "Enter a Valid US Zip Code (ie. 90210)");			
			showwarning('warzip')
			showerror("Enter a Valid US Zip Code (ie. 90210)")
			document.getElementById("txt_C_ShipZipCode").focus();
			valid = false;
		}
		else if ((document.getElementById("txt_C_ShipZipCode").value.length <5 || document.getElementById("txt_C_ShipZipCode").value.length >5) && document.getElementById("txt_C_ShipCountries8").value =="2" )
		{		    
			showwarning('warzip')
			showerror("Enter a Valid US Zip Code (ie. 90210)")
			document.getElementById("txt_C_ShipZipCode").focus();
			valid = false;
		}
		else if ((document.getElementById("txt_C_ShipZipCode").value.length <6 || document.getElementById("txt_C_ShipZipCode").value.length >7) && document.getElementById("txt_C_ShipCountries8").value =="3" )
		{
			//alert( "Enter a Valid Canadian Post Code (ie. K7R 2G9)" );			
			showwarning('warzip')
			showerror("Enter a Valid Canadian Zip Code (ie. K7R 2G9))")
			document.getElementById("txt_C_ShipZipCode").focus();
			valid = false;
		}
		if (document.getElementById("ddlCity").value == "Select City")
		{
			//alert("Please select City");			
			showwarning('warddlcity')
			showerror("City is require")
			document.getElementById("ddlCity").focus()
			valid = false;
		}
		return valid;
	}
	
function ShowMe(pmStep)
{
		try
		{
			
			/*--This part should execute only for vendores*/
			if (document.getElementById("hid_isVendor"))
			{
				if (document.getElementById("hid_isVendor").value == 'yes')
					pmStep = 1
			}
			/*--End of part*/
		
		    //Hide Current Step Tab
		    
		    var iCurStep = GetCurrentStep();
		    
		    //Show Request Step Tab
		   
		        
			    switch (iCurStep){
                    case 1:
                        document.getElementById("tabStepI").style.display = "none";
				        //document.getElementById("PnlStepI").style.display = "none";
                        break;
                    case 2:
                        document.getElementById("tabStepII").style.display = "none";
				        //document.getElementById("PnlStepII").style.display = "none";
                        break;
                    case 3:
                        document.getElementById("tabStepIII").style.display = "none";
				        //document.getElementById("PnlStepIII").style.display = "none";
                        break;            
                }
    		
		        //Show Request Step Tab
			    switch (pmStep){
                    case 1:
                        document.getElementById("tabStepI").style.display = "";
				        //document.getElementById("PnlStepI").style.display = "";
				        //document.getElementById("txtCurStep").value = 1;
                        break;
                    case 2:
                        document.getElementById("tabStepII").style.display = "";
				       // document.getElementById("PnlStepII").style.display = "";
				        //document.getElementById("txtCurStep").value = 2;
                        break;
                    case 3:
                        document.getElementById("tabStepIII").style.display = "";
				        //document.getElementById("PnlStepIII").style.display = "";
				        //document.getElementById("txtCurStep").value = 3;
                        break;            
                }
            
	    }
		catch(Exception){}
}

function GetCurrentStep(){
    var iCurStep = document.getElementById("txtCurStep").value;
    if (iCurStep != ""){
        return parseInt(iCurStep);
    } else {return 1;}    
}

function getZipcode(pmVal)
{
    if(parseInt(document.getElementById("txt_C_ShipCountries8").value)==2 || parseInt(document.getElementById("txt_C_ShipCountries8").value)==3)
    {
	    document.getElementById("zip").innerHTML = '<img src="../Sell/images/Required.png"/>';
    }
    else
    {
	    document.getElementById("zip").innerHTML='';
    }
}

function isEmail(fstrEmail) 
{

        var re = new RegExp("^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$");
	    fstrEmail=trim(fstrEmail);
	    lintPos=fstrEmail.indexOf("@")
	    lstrwww=(fstrEmail.substr(0, 3).toUpperCase());
	    lstrhttp=(fstrEmail.substr(0, 4).toUpperCase());
	    lstrDot=fstrEmail.substr(lintPos);
	    lintpos=lstrDot.indexOf(".");
	    if (fstrEmail.indexOf(",")!=-1 || fstrEmail.indexOf(".")==-1 || lintpos==-1 || lstrwww =="FTP" || lstrwww =="WWW" || lstrhttp=="HTTP" )
	    {
		    return false
	    }
	    else if (fstrEmail.match(re)) {
        return true;
  } else {
        return false;
  }
}	


function showMsgDataLoad(sDisplayMsg){ 

   
    if (sDisplayMsg != '') {
        document.getElementById('lblMsgDataLoad').style.display = ''; 
        document.getElementById('lblMsgDataLoad').innerText = 'Loading ' + sDisplayMsg + '...';    
    } else {
        document.getElementById('lblMsgDataLoad').innerText = '';
        document.getElementById('lblMsgDataLoad').style.display = 'none'; 
    }     
}

/*===================================================================================================================
Part Billing
=====================================================================================================================*/

function validatePartBilling()
	{
	
		with(document.Subscription)
		{
			for (i=0; i < elements.length; i++)
			{
				vname=(elements[i].name);
				vpre=vname.substring(0,5);
				if (elements[i].value == "" && (vpre =="txt_C"))
				{
					if((elements[i].name!="All_Country"))
					{	
						alert(elements[i].id + " Cannot Be Empty.")
						elements[i].focus();
						return false
						break;
					}
				}
			}
			
     		//#--Checking for valide Credit Card Number
			if(!CheckAllCC(document.getElementById('txt_C_CCNo').value))
			{
				alert("Please enter a valid Credit Card Number")
				document.getElementById('txt_C_CCNo').focus();
				return false
			}
			
			//#--Checking for valide Expiry Date
			if(CheckExpiryDate(document.getElementById('cmb_O_CrdExpiryMonth').value, document.getElementById('cmb_O_CrdExpiryYear').value) == false)
			{
				document.getElementById('cmb_O_CrdExpiryMonth').focus();
				return false
			}
			
		}
		
			if(document.getElementById('txt_O_FirstName').value =='')
			{
				alert('Please enter the First Name');
				document.getElementById('txt_O_FirstName').focus();
				return false;
			}	
			
			if(document.getElementById('txt_O_LastName').value =='')
			{
				alert('Please enter the Last Name');
				document.getElementById('txt_O_LastName').focus();
				return false;
			}
		
			//vIsLNameEmpty = (document.getElementById('txt_O_LastName.value == '')
			//vIsCNameEmpty = (document.getElementById('txt_O_Company.value == '')
			if(document.getElementById('txt_O_Address').value =='')
			{
				alert('Please enter the Street address')
				document.getElementById('txt_O_Address').focus()
				return false;
			}	

			if(document.getElementById('txt_O_City').value =='')
			{
				alert('Please enter the City')
				document.getElementById('txt_O_City').focus()
				return false;
			}	
			
			if(document.getElementById('All_Country').value == 1 &&  document.getElementById('All_Country_Other').value =='')
			{
				alert('Enter a Country')
				if(document.getElementById('All_Country_Other').disabled==false)
				{
					document.getElementById('All_Country_Other').focus()
				}
				return false;
			}
	
			if(document.getElementById('All_Country').value != 2 && document.getElementById('All_Country').value != 3 && document.getElementById('US_state_Other').value =='')
			{
				alert('Enter a State/Province/Territory')
				if (document.getElementById('US_state').value == '1')
				{
					if(document.getElementById('US_state_Other').disabled==false)
					{
						document.getElementById('US_state_Other').focus()
					}
				}
				else
				{
					if(document.getElementById('US_state').disabled==false)
					{
						document.getElementById('US_state').focus()
					}
				}
				return false;
			}
		
	
			if((document.getElementById('All_Country').value == 2 || document.getElementById('All_Country').value == 3) && document.getElementById('US_state').value == '')
			{
				alert('Select a State')
				if (document.getElementById('US_state').disabled == false)
				{
					document.getElementById('US_state').focus()
				}
				return false;
			}
		
		
			if(document.getElementById('US_state').value == 1 &&  document.getElementById('US_state_Other').value =='')
			{
				alert('Please enter State/Province/Territory')
				if(document.getElementById('US_state').disabled==false)
				{
					document.getElementById('US_state').focus()
				}
				return false;
			}	

			if(document.getElementById('txt_O_ZipCode').value =='')
			{
				alert('Please enter the Zip Code')
				document.getElementById('txt_O_ZipCode').focus()
				return false;
			}			
			
		return true;
			
		document.getElementById('txt_O_FirstName').disabled = false	
		document.getElementById('txt_O_LastName').disabled = false
		//document.getElementById('txt_O_Company.disabled = false
		//document.getElementById('txt_O_Phone.disabled = false
		document.getElementById('txt_O_Address').disabled = false
		document.getElementById('txt_O_City').disabled = false
		document.getElementById('All_Country').disabled = false
		document.getElementById('All_Country_Other').disabled = false

		document.getElementById('US_state').disabled = false
		document.getElementById('US_state_Other').disabled = false	
		document.getElementById('txt_O_ZipCode').disabled = false
		
		
	}


	function fun_country()
	{

		if (document.getElementById('All_Country').value==1)
		{
			document.getElementById('US_state').selectedIndex = 1;
			document.getElementById('showtd1').style.display= "";
			document.getElementById('showtd2').style.display= "";
			document.getElementById('All_Country_Other').disabled = false;
			document.getElementById('All_Country_Other').value = "";
		}
		else if (document.getElementById('All_Country').value == 2 || document.getElementById('All_Country').value == 3)
		{
			document.getElementById('US_state').selectedIndex=0;
			document.getElementById('All_Country_Other').value='';
			document.getElementById('US_state_Other').value='';
			document.getElementById('showtd1').style.display= "none";
			document.getElementById('showtd2').style.display= "none";
		}
		else
		{
			document.getElementById('US_state').selectedIndex = 1;
			document.getElementById('showtd1').style.display= "none";
			document.getElementById('showtd2').style.display= "";
			document.getElementById('All_Country_Other').value='';
		}
		
		fun_state();
	}

	function fun_state()
	{
		if (document.getElementById('US_state').value==1)
		{
			document.getElementById('showtd2').style.display= "";
		}
		else
		{
            document.getElementById('US_state_Other').value='';
			document.getElementById('showtd2').style.display= "none";
		}
	}
	
	function validateCCNum(cardType,cardNum)
{

	var result = false;
	cardType = cardType.toUpperCase();
	
	var cardLen = cardNum.length;
	var firstdig = cardNum.substring(0,1);
	var seconddig = cardNum.substring(1,2);
	var first4digs = cardNum.substring(0,4);

	switch (cardType)
	{
		case "VISA":
			result = ((cardLen == 16) || (cardLen == 13)) && (firstdig == "4");
			break;
		case "AMEX":
			var validNums = "47";
			result = (cardLen == 15) && (firstdig == "3") && (validNums.indexOf(seconddig)>=0);
			break;
		case "MASTERCARD":
			var validNums = "12345";
			result = (cardLen == 16) && (firstdig == "5") && (validNums.indexOf(seconddig)>=0);
			break;
		case "DISCOVER":
			result = (cardLen == 16) && (first4digs == "6011");
			break;
		case "DINERS":
			var validNums = "068";
			result = (cardLen == 14) && (firstdig == "3") && (validNums.indexOf(seconddig)>=0);
			break;
	}
	return result;
}


function LuhnCheck(str) 
{
  var result = true;

  var sum = 0; 
  var mul = 1; 
  var strLen = str.length;
  
  for (i = 0; i < strLen; i++) 
  {
    var digit = str.substring(strLen-i-1,strLen-i);
    var tproduct = parseInt(digit ,10)*mul;
    if (tproduct >= 10)
      sum += (tproduct % 10) + 1;
    else
      sum += tproduct;
    if (mul == 1)
      mul++;
    else
      mul--;
  }
  if ((sum % 10) != 0)
    result = false;
    
  return result;
}


function CheckAllCC(pmCardNumber)
{

	//#--This function checks all kind of valid credit card number 

//	return (validateCCNum("3", pmCardNumber) || validateCCNum("5", pmCardNumber))
	return (LuhnCheck(pmCardNumber) && (validateCCNum("VISA",pmCardNumber) || validateCCNum("AMEX",pmCardNumber) || validateCCNum("MASTERCARD",pmCardNumber) || validateCCNum("DISCOVER",pmCardNumber) || validateCCNum("DINERS",pmCardNumber)))	
	
}

function CheckExpiryDate(pmMonth, pmYear)
{
		var now = new Date();
		var nowMonth = now.getMonth() + 2;
		var nowYear = (now.getYear())%100;
		if (pmYear==nowYear)
		{ 
			if(pmMonth < nowMonth)
			{
				alert("Your card expired date is incorrect");
				return false;
			}
		}
		return true;
}

function select_state(req_state)
{
	var dropDown;

	if (req_state == null)
	{
		req_state="";
	}
	
	if (document.forms[0] && document.forms[0].State)
	{
		dropDown = document.forms[0].State;
	}
	else if (document.forms[1] && document.forms[1].State)
	{
		dropDown = document.forms[1].State;
	}
	
	if (dropDown)
	{
		if (dropDown)
		{
			for (x=0; x<dropDown.length; x++)
			{
				mk=dropDown.options[x].value;
				
				if (mk == req_state)
				{
					if (dropDown.options[x].selected==false)
					{
						dropDown.options[x].selected=true;
					}
				}
			}
		}
	}
}


function get_states(ranges,rangesv,req_state)
{
    
	selectedIndex = 0;
	var dropDown = document.forms[0].US_state;
		
	if (dropDown)
	{
		dropDown.length = 0;

		if (ranges)
		{
			for(index=0; index<ranges.length; index++)
			{
				dropDown[index] = new Option(ranges[index],rangesv[index]);
				
				if(ranges[index] == req_state)
				{
					selectedIndex = index;
				}
				
				dropDown.options[selectedIndex].selected = true;
			}
		}
	
		select_state(req_state);
	}
}

/*===================================================================================================================
Animation Script
=====================================================================================================================*/
function onUpdating(){
    var sValue = document.getElementById("txtLoading").value;
    
    if (sValue != ''){   
                            
        disableForm();                      
        if (sValue != 'review') {        
            document.getElementById(sValue).style.display = '';            
            document.getElementById('rwProcessingRequest').style.display = 'none';
        } else if (sValue == 'review') {
            document.getElementById('rwProcessingRequest').style.display = '';
        }       
        
    } else {
        document.getElementById('rwProcessingRequest').style.display = 'none';
    } 
}

function onUpdated(){ 

        enableForm();                     
        document.getElementById(document.getElementById("txtLoading").value).style.display = 'none';
        document.getElementById('rwProcessingRequest').style.display = 'none';
        document.getElementById("txtLoading").value = '';        
}

function disableForm(){
    
    if (document.getElementById('int_C_Year')!= null){document.getElementById('int_C_Year').disabled = true; }
    if (document.getElementById('int_C_Make8')!= null){document.getElementById('int_C_Make8').disabled = true;}
    if (document.getElementById('int_C_Model8')!= null){document.getElementById('int_C_Model8').disabled = true;}
    if (document.getElementById('txt_O_OtherModel')!= null){document.getElementById('txt_O_OtherModel').disabled = true;}
    if (document.getElementById('btnFindYourPart')!= null){ document.getElementById('btnFindYourPart').disabled = true; }    
    if (document.getElementById('int_O_SubModel8')!= null){ document.getElementById('int_O_SubModel8').disabled = true; }
    if (document.getElementById('txt_O_OtherSubModel')!= null){ document.getElementById('txt_O_OtherSubModel').disabled = true; }
    if (document.getElementById('int_O_BodyStyleID8')!= null){ document.getElementById('int_O_BodyStyleID8').disabled = true; }
    if (document.getElementById('txt_O_VIN') != null){ document.getElementById('txt_O_VIN').disabled = true; }
    if (document.getElementById('int_O_EngineSize8')!= null){ document.getElementById('int_O_EngineSize8').disabled = true; }
    if (document.getElementById('txt_O_EngineSizeOther')!= null){ document.getElementById('txt_O_EngineSizeOther').disabled = true; }
    if (document.getElementById('int_O_AxleID8')!= null){ document.getElementById('int_O_AxleID8').disabled = true; }
    if (document.getElementById('int_C_TransmissionID8')!= null){ document.getElementById('int_C_TransmissionID8').disabled = true; }
    if (document.getElementById('int_O_FuelID8')!= null){ document.getElementById('int_O_FuelID8').disabled = true; }
    if (document.getElementById('btnNextStepI') != null){ document.getElementById('btnNextStepI').disabled = true; }     
    if (document.getElementById('int_C_PartID8') != null){document.getElementById('int_C_PartID8').disabled = true; }       
    if (document.getElementById('int_C_PartID8_Part_Status') != null){document.getElementById('int_C_PartID8_Part_Status').disabled = true;}    
    if (document.getElementById('int_C_SubPartID') != null){document.getElementById('int_C_SubPartID').disabled = true; }    
    if (document.getElementById('PnlPartDetails') != null){document.getElementById('PartDetailsId').disabled = true; }
    if (document.getElementById('txt_O_PartDesc') != null){document.getElementById('txt_O_PartDesc').disabled = true; }                
    if (document.getElementById('btnPreviousStepII') != null){document.getElementById('btnPreviousStepII').disabled = true; }
    if (document.getElementById('btnNextStepII') != null){document.getElementById('btnNextStepII').disabled = true; }  
    if (document.getElementById('btnSubmitFree') != null){document.getElementById('btnSubmitFree').disabled = true; }  
    if (document.getElementById('btnPreviousStepV') != null){document.getElementById('btnPreviousStepV').disabled = true; }  
    if (document.getElementById('btnSubmitRushRequest') != null){document.getElementById('btnSubmitRushRequest').disabled = true; }  
  }     
  

function enableForm(){
    if (document.getElementById('int_C_Year')!= null){
        document.getElementById('int_C_Year').disabled = false; 
        if (document.getElementById('int_C_Year').selectedIndex > 0){
            if (document.getElementById('int_C_Make8')!= null){document.getElementById('int_C_Make8').disabled = false;}
        }    
     }
        
    if (document.getElementById('int_C_Make8')!= null){
        if (document.getElementById('int_C_Make8').selectedIndex > 0){
            if (document.getElementById('int_C_Model8')!= null){document.getElementById('int_C_Model8').disabled = false;}
            if (document.getElementById('txt_O_OtherModel')!= null){document.getElementById('txt_O_OtherModel').disabled = false;}
        }    
    }    
    
    if (document.getElementById('int_C_Model8')!= null){
        if (document.getElementById('int_C_Model8').selectedIndex > 0){
            if (document.getElementById('int_O_SubModel8')!= null){ document.getElementById('int_O_SubModel8').disabled = false; }
            if (document.getElementById('txt_O_OtherSubModel')!= null){ document.getElementById('txt_O_OtherSubModel').disabled = false; }
            if (document.getElementById('int_O_BodyStyleID8')!= null){ document.getElementById('int_O_BodyStyleID8').disabled = false; }
        }
    } 

    if (document.getElementById('int_O_SubModel8')!= null){
        if (document.getElementById('int_O_SubModel8').selectedIndex > 0){
            if (document.getElementById('int_O_EngineSize8')!= null){ document.getElementById('int_O_EngineSize8').disabled = false; }
            if (document.getElementById('txt_O_EngineSizeOther')!= null){ document.getElementById('txt_O_EngineSizeOther').disabled = false; }
            if (document.getElementById('int_O_AxleID8')!= null){ document.getElementById('int_O_AxleID8').disabled = false; }
            if (document.getElementById('int_C_TransmissionID8')!= null){ document.getElementById('int_C_TransmissionID8').disabled = false; }
        }
    } else { 
            if (document.getElementById('int_O_EngineSize8')!= null){ document.getElementById('int_O_EngineSize8').disabled = false; }
            if (document.getElementById('txt_O_EngineSizeOther')!= null){ document.getElementById('txt_O_EngineSizeOther').disabled = false; }
            if (document.getElementById('int_O_AxleID8')!= null){ document.getElementById('int_O_AxleID8').disabled = false; }
            if (document.getElementById('int_C_TransmissionID8')!= null){ document.getElementById('int_C_TransmissionID8').disabled = false; }
    }  
    
    if (document.getElementById('int_C_PartID8') != null){
        document.getElementById('int_C_PartID8').disabled = false;
        if (document.getElementById('int_C_PartID8').selectedIndex > 0){         
            if (document.getElementById('int_C_SubPartID') != null){document.getElementById('int_C_SubPartID').disabled = false; }    
            if (document.getElementById('PnlPartDetails') != null){document.getElementById('PartDetailsId').disabled = false; }
            if (document.getElementById('txt_O_PartDesc') != null){document.getElementById('txt_O_PartDesc').disabled = false; } 
        }     
    }       
    
    if (document.getElementById('txt_O_VIN') != null){ document.getElementById('txt_O_VIN').disabled = false; }
    if (document.getElementById('int_O_FuelID8')!= null){ document.getElementById('int_O_FuelID8').disabled = false; }
    if (document.getElementById('btnFindYourPart') != null){document.getElementById('btnFindYourPart').disabled = false;}
    if (document.getElementById('btnNextStepI') != null){document.getElementById('btnNextStepI').disabled = false;}
    if (document.getElementById('btnPreviousStepII') != null){document.getElementById('btnPreviousStepII').disabled = false;}
    if (document.getElementById('btnNextStepII') != null){document.getElementById('btnNextStepII').disabled = false;}
    if (document.getElementById('btnSubmitFree') != null){document.getElementById('btnSubmitFree').disabled = false; }  
    if (document.getElementById('btnPreviousStepV') != null){document.getElementById('btnPreviousStepV').disabled = false; }  
    if (document.getElementById('btnSubmitRushRequest') != null){document.getElementById('btnSubmitRushRequest').disabled = false; }  
    
} 
   
/*=====================================================================================================================
Popup Window
===============================================================================================================*/
function popupVIN() {	
	window.open(sRoot + 'request/vin_help.aspx', 'popUp', 'width=700,height=430,scrollbars=1');
}