var AjaxPageName;
var AjaxServerPageName;
AjaxPageName="AJAXRequest.aspx";
AjaxServerPageName="AjaxModelList.aspx";
function billshipsame(isbillshipsame,regForm)
{
regForm = document.forms[0];
var ischecked = window.document.getElementById(isbillshipsame).checked;
    if(ischecked==true)
    { 
    regForm.txtFirstname.value = regForm.txtBillFirstName.value;
    regForm.txtLastname.value = regForm.txtBillLastName.value;
    regForm.txtAddress1.value = regForm.txtBillAddress1.value;
    regForm.txtAddress2.value = regForm.txtBillAddress2.value;
    regForm.txtState.value = regForm.txtBillState.value;
    regForm.Shipping_Country.value = regForm.Billing_Country.value;
    regForm.txtZip.value = regForm.txtBillZip.value;
    regForm.txtEmail.value = regForm.txtBillEmail.value;
    regForm.txtTelephone.value = regForm.txtBillTelephone.value;    
    }
}
function ModelListOnChange(Brand,Model)
{
    var cboModel = window.document.getElementById(Model);
	var cboBrand =  window.document.getElementById(Brand);	
	
        optionItem = new Option( "Select Model Name", "-1",  false, false);
	    cboModel.options[cboModel.length] = optionItem;	
	if(cboBrand.selectedIndex > 0)
	{	
	    var selectedBrand = cboBrand.options[cboBrand.selectedIndex].value;	
	    var requestUrl = AjaxServerPageName + "?selectedBrand=" + encodeURIComponent(selectedBrand) + "&ModelCombo=" + cboModel.id + "" ;
	
	    CreateXmlHttp();
	
	    if(XmlHttp)
	    {
		    XmlHttp.onreadystatechange = HandleResponseModel;
		    XmlHttp.open("GET", requestUrl,true);
		    XmlHttp.send(null);
	    }
	    else
        {
		    for (var count = Model.options.length-1; count >=0; count--)
		    {
			    Model.options[count] = null;
		    }   
        }
	}
    
}
function HandleResponseModel()
{
	if(XmlHttp.readyState == 4)
	{
		if(XmlHttp.status == 200)
		{	
			
			ClearAndSetModelListItems(XmlHttp.responseText);
			
		}
		else
		{		
			alert("There was a problem retrieving data from the server.");
		}
	}
}

function ClearAndSetModelListItems(brandNode)
{
	var mystring= brandNode.split("\t");	
	var modelList = document.getElementById(mystring[0]);	

	//Clears the state combo box contents.
	for (var count = modelList.options.length-1; count >0; count--)
	{
		modelList.options[count] = null;
	}
//	alert(stateList.options.length);
	//var stateNodes = countryNode.getElementsByTagName('NewDataSet');
	//var textValue; 
	//var optionItem;
	//Add new states list to the state combo box.
	if(mystring.length > 0)
    {
        modelList.disabled = false;
    }
	for (var count = 1; count < mystring.length-1; count++)
	{
		var idvalue = mystring[count].split(":");
   		optionItem = new Option( idvalue[1], idvalue[0],  false, false);
		modelList.options[modelList.length] = optionItem;		
		
	}
}

function checkRegistrationData(regForm)
{
regForm = document.forms[0];
        strres="";
		if(isTextExist(regForm.txtEmailAddress)==false)
		{
			strres="false";
			
		}		
		else
		{
			 exp = new RegExp("^(.+)@(.+)$");
			 if(isValidEmail(regForm.txtEmailAddress)==false)
			 {		
				strres="false";
			 }	
		}		
        if(isTextExist(regForm.txtPassword)==false)
		{
			strres="false";
		}
		if(isTextExist(regForm.txtConfirmPassword)==false)
		{
			strres="false";
		}
		if(isTextExist(regForm.txtFirstname)==false)
		{
			strres="false";
		}
		if(isTextExist(regForm.txtLastname)==false)
		{
			strres="false";
		}
		if(isTextExist(regForm.txtAddress1)==false)
		{
			strres="false";
		}		
		if(isTextExist(regForm.txtState)==false)
		{
			strres="false";
		}		
		
		if(regForm.Shipping_Country.value=="00")//
		{		
			strres="false";
		}
		if(isTextExist(regForm.txtZip)==false)
		{
		strres="false";
		}
		if(isTextExist(regForm.txtEmail)==false)
		{
			strres="false";
		}
		else
		{
			 exp = new RegExp("^(.+)@(.+)$");
			 if(isValidEmail(regForm.txtEmail)==false)
			 {
				strres="false";
			 }	
		}		
        if(isTextExist(regForm.txtTelephone)==false)
		{
			strres="false";
		}
		if(isTextExist(regForm.txtBillFirstName)==false)
		{
			strres="false";
		}
		if(isTextExist(regForm.txtBillLastName)==false)
		{
			strres="false";
		}
		if(isTextExist(regForm.txtBillAddress1)==false)
		{
			strres="false";
		}
		if(isTextExist(regForm.txtBillState)==false)
		{
			strres="false";
		}
		if(regForm.Billing_Country.value=="00")//		
		{
            strres="false";
		}
		if(isTextExist(regForm.txtBillZip)==false)
		{
strres="false";
		}
		if(isTextExist(regForm.txtBillEmail)==false)
		{
			strres="false";
		}
		else
		{
			 exp = new RegExp("^(.+)@(.+)$");
			 if(isValidEmail(regForm.txtBillEmail)==false)
			 {
				strres="false";
			 }	
		}		
        
		if(isTextExist(regForm.txtBillTelephone)==false)
		{
			strres="false";
		}
		if(strres=="false")		    
		{
		    alert("Some Of Necessory Detail(s) are Still Blank, Please Fill up All Compulsary Detail(s)");
		    return false;
		}		
		else
		    return true;
}
function checkShippingInfo(regForm)
{
regForm = document.forms[0];
strres="";
		
		if(isTextExist(regForm.txtFirstname)==false)
		{
			strres="false";
		}
		if(isTextExist(regForm.txtLastname)==false)
		{
			strres="false";
		}
		if(isTextExist(regForm.txtAddress1)==false)
		{
			strres="false";
		}		
		if(isTextExist(regForm.txtState)==false)
		{
			strres="false";
		}		
		
		if(regForm.Shipping_Country.value=="00")//
		{		
			strres="false";
		}
		if(isTextExist(regForm.txtZip)==false)
		{
		strres="false";
		}
		if(isTextExist(regForm.txtEmail)==false)
		{
			strres="false";
		}
		else
		{
			 exp = new RegExp("^(.+)@(.+)$");
			 if(isValidEmail(regForm.txtEmail)==false)
			 {
				strres="false";
			 }	
		}		
        if(isTextExist(regForm.txtTelephone)==false)
		{
			strres="false";
		}		
		if(strres=="false")		    
		{
		    alert("Some Of Necessory Detail(s) are Still Blank or not , Please Fill up All Compulsary Detail(s)");
		    return false;
		}		
		else
		    return true;
}
function checkEditProfile(regForm)
{
regForm = document.forms[0];
        strres="";
		
		if(isTextExist(regForm.txtFirstname)==false)
		{
			strres="false";
		}
		if(isTextExist(regForm.txtLastname)==false)
		{
			strres="false";
		}
		if(isTextExist(regForm.txtAddress1)==false)
		{
			strres="false";
		}		
		if(isTextExist(regForm.txtState)==false)
		{
			strres="false";
		}		
		
		if(regForm.Shipping_Country.value=="00")//
		{		
			strres="false";
		}
		if(isTextExist(regForm.txtZip)==false)
		{
		strres="false";
		}
		if(isTextExist(regForm.txtEmail)==false)
		{
			strres="false";
		}
		else
		{
			 exp = new RegExp("^(.+)@(.+)$");
			 if(isValidEmail(regForm.txtEmail)==false)
			 {
				strres="false";
			 }	
		}		
        if(isTextExist(regForm.txtTelephone)==false)
		{
			strres="false";
		}
		if(isTextExist(regForm.txtBillFirstName)==false)
		{
			strres="false";
		}
		if(isTextExist(regForm.txtBillLastName)==false)
		{
			strres="false";
		}
		if(isTextExist(regForm.txtBillAddress1)==false)
		{
			strres="false";
		}
		if(isTextExist(regForm.txtBillState)==false)
		{
			strres="false";
		}
		if(regForm.Billing_Country.value=="00")//		
		{
            strres="false";
		}
		if(isTextExist(regForm.txtBillZip)==false)
		{
strres="false";
		}
		if(isTextExist(regForm.txtBillEmail)==false)
		{
			strres="false";
		}
		else
		{
			 exp = new RegExp("^(.+)@(.+)$");
			 if(isValidEmail(regForm.txtBillEmail)==false)
			 {
				strres="false";
			 }	
		}		
        
		if(isTextExist(regForm.txtBillTelephone)==false)
		{
			strres="false";
		}
		if(strres=="false")		    
		{
		    alert("Some Of Necessory Detail(s) are Still Blank, Please Fill up All Compulsary Detail(s)");
		    return false;
		}		
		else
		    return true;
}
function EnsureNumeric()
{	
	if (event.keyCode>=48 && event.keyCode<=57)
	{
	}
	else
	{
		event.keyCode=null;
	}
}

function EnterOnlyDouble()
{	
	if ((event.keyCode>=48 && event.keyCode<=57)||event.keyCode==46)
	{
		if (event.keyCode==46)
			{
				var text;
				text=document.activeElement.getAttribute("value");
				if(text.toString().indexOf(".")!=-1)
					event.keyCode=null;
			}
	}
	else
	{
		event.keyCode=null;
	}
}
function EnterOnlyChar(Length)
{	
	if ((event.keyCode>=65 && event.keyCode<=90) || (event.keyCode>=97 && event.keyCode<=122))
	{
		
	}
	else
	{
		event.keyCode=null;
	}
}
function EnterOnlyChar(Length)
{	
	alert(event.keyCode);
	if ((event.keyCode>=65 && event.keyCode<=90) || (event.keyCode>=97 && event.keyCode<=122))
	{
		
	}
	else
	{
		event.keyCode=null;
	}
}

function EnterMobileNo()
{
if ((event.keyCode==43 ||event.keyCode==45 ) || (event.keyCode>=48 && event.keyCode<=57) )
	{
	if (event.keyCode==43)
			{			
				var len=0;
				len=document.activeElement.getAttribute("value").toString().length;
				if(len != 0)
					event.keyCode=null;
			}	
		}
	else
	{
		event.keyCode=null;
	}
}

function isValidEmail(emailaddr)
{
		if(navigator.appName=="Netscape" || navigator.appName=="Opera")
			var semailaddr = emailaddr.value;
		else
			var semailaddr = emailaddr.getAttribute("value").toString();
		
		exp = new RegExp("^(.+)@(.+)$");
		if(semailaddr.match(exp)==null)
		{
		return false;
		}
		else
		{
		return true;
		}
			 
			
}
function ValidateEmail(emailaddr)
{
		if(navigator.appName=="Netscape" || navigator.appName=="Opera")
			var semailaddr = emailaddr.value;
		else
			var semailaddr = emailaddr.getAttribute("value").toString();
		
		
		
		exp = new RegExp("^(.+)@(.+)$");
		if(semailaddr.match(exp)==null)
		{
		alert("Invalid Email address");
		return false;
		}
		else
		{
		return true;
		}
			 
			
}


function isTextExist(txtControl)
{
	var txtControlValue;
	
	if(navigator.appName=="Netscape" || navigator.appName=="Opera")
	{
	
			var txtControlValue = txtControl.value;
	}
	else
	{
	
			var txtControlValue = txtControl.getAttribute("value").toString();
	}
	//var txtControlValue= txtControl.getAttribute("value").toString();
	
	if(txtControlValue.length==0)
	{
		return false;
	}
	else
	{
		return true;
	}
}
function EnterChars()
{	
	//alert(event.keyCode);
	if ((event.keyCode>=65 && event.keyCode<=90) || (event.keyCode>=97 && event.keyCode<=122) || (event.keyCode==32))
	{
		
	}
	else
	{
		event.keyCode=null;
	}
}

function fnMoveUp(strListID)
{
	var oList = window.document.getElementById(strListID);
	if(oList != null)
	{
		var intLen = oList.length;
		for(var intCtr=0; intCtr<intLen; intCtr++)
		{
			if(oList.options.selectedIndex == -1)
				break;
			var intSelectedIndex = oList.options[oList.options.selectedIndex].index;
			if(intSelectedIndex == 0)
				break;
			var strPrevValue = oList.options[intSelectedIndex - 1].value;
			var strPrevID = oList.options[intSelectedIndex - 1].id;
			var strPrevText = oList.options[intSelectedIndex - 1].text;
			oList.options[intSelectedIndex - 1].value = oList.options[intSelectedIndex].value;
			oList.options[intSelectedIndex - 1].id = oList.options[intSelectedIndex].id;
			oList.options[intSelectedIndex - 1].text = oList.options[intSelectedIndex].text;
			oList.options[intSelectedIndex].value = strPrevValue;
			oList.options[intSelectedIndex].id = strPrevID;
			oList.options[intSelectedIndex].text = strPrevText;
			oList.options[intSelectedIndex - 1].selected = true;
			break;
		}
	}
}

function fnMoveDown(strListID)
{
	var oList = window.document.getElementById(strListID);
	
	if(oList != null)
	{
		var intLen = oList.length;
		for(var intCtr=0; intCtr<intLen; intCtr++)
		{
			if(oList.options.selectedIndex == -1)
				break;
			var intSelectedIndex = oList.options[oList.options.selectedIndex].index;
			if(intSelectedIndex == intLen-1)
				break;
			var strNextValue = oList.options[intSelectedIndex + 1].value;
			var strNextID = oList.options[intSelectedIndex + 1].id;
			var strNextText = oList.options[intSelectedIndex + 1].text;
			oList.options[intSelectedIndex + 1].value = oList.options[intSelectedIndex].value;
			oList.options[intSelectedIndex + 1].id = oList.options[intSelectedIndex].id;
			oList.options[intSelectedIndex + 1].text = oList.options[intSelectedIndex].text;
			oList.options[intSelectedIndex].value = strNextValue;
			oList.options[intSelectedIndex].id = strNextID;
			oList.options[intSelectedIndex].text = strNextText;
			oList.options[intSelectedIndex + 1].selected = true;
			break;
		}
	}
}

function fnOpenNewWindow(strPageName)
{
	var oNewWin = null;
	var strQuerystring = "PageName=" + strPageName;
	
	oNewWin = window.open("SetPriority.aspx?" + strQuerystring, "newwin", "toolbar=no,status=no,resizable=yes,width=200,height=200,top=200,left=350");
}

function fnOpenNew(strPageName)
{
	var oNewWin = null;
	
	oNewWin = window.open(strPageName, "newwin", "toolbar=no,status=no,resizable=yes,width=700,height=700,top=50,left=50");
}

function CreateXmlHttp()
{
//Creating object of XMLHTTP in IE</SPAN>
	try
	{
		XmlHttp =new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e)
		{
			XmlHttp=null;
		}
	}
	//Creating object of XMLHTTP in Mozilla and Safari
	if(!XmlHttp && typeof XMLHttpRequest != "undefined")
	{
		XmlHttp =new XMLHttpRequest();
	}
}



function SetHiddenField(State,Items)
{
	if(State.selectedIndex > 0)
	{
	var selectedState = State.options[State.selectedIndex].value;
	document.getElementById(Items.id).value = selectedState;	
	}
}



function checkRegForUpdate(name,email)
{
        strres="";
        name = document.getElementById(name);
        email = document.getElementById(email);
		if(isTextExist(email)==false)
		{
			strres="Email is Required";			
		}		
		else
		{
			 exp = new RegExp("^(.+)@(.+)$");
			 if(isValidEmail(email)==false)
			 {		
				strres="Invalid Email Address";			
			 }	
		}		        
		if(isTextExist(name)==false)
		{
			if(strres=="")
			{
			    strres="Name is Required";			
			}
			else
			{
			    strres+="\nName is Required";			
			}
		}
		if(strres=="")		    
        {
            var requestUrl = AjaxPageName + "?Email=" + email.value + "&Name=" + name.value + "" ;
	        CreateXmlHttp();
	        if(XmlHttp)
	        {
		        XmlHttp.onreadystatechange = HandleResponse;
		        XmlHttp.open("GET", requestUrl,true);
		        XmlHttp.send(null);
	        }   
        }		    
		else
		{
		    alert(strres);
		    return false;
		}
}
function HandleResponse()
{
	if(XmlHttp.readyState == 4)
	{
		if(XmlHttp.status == 200)
		{	
			
			alert(XmlHttp.responseText);			
		}
		else
		{
			alert("There was a problem Register for update, please try after some time.");
		}
	}
}


function checkInquiryData(regForm)
{
        var strres="";
        if(isTextExist(regForm.surname)==false)
		{
			strres="false";
		}
		if(isTextExist(regForm.forename)==false)
		{
			strres="false";
		}
		if(isTextExist(regForm.address1)==false)
		{
			strres="false";
		}
		if(isTextExist(regForm.town)==false)
		{
			strres="false";
		}		
		if(isTextExist(regForm.county)==false)
		{
			strres="false";
		}		
		if(isTextExist(regForm.email)==false)
		{
			strres="false";
		}		
		else
		{
			 exp = new RegExp("^(.+)@(.+)$");
			 if(isValidEmail(regForm.email)==false)
			 {		
				strres="false";			
			 }	
		}		        
		if(regForm.country.value=="00")//
		{		
			strres="false";
		}
		if(isTextExist(regForm.postcode)==false)
		{
		strres="false";
		}
		if(isTextExist(regForm.vehicle_make)==false)
		{
			strres="false";
		}
		if(isTextExist(regForm.vehicle_model)==false)
		{
			strres="false";
		}
		if(isTextExist(regForm.vehicle_year)==false)
		{
			strres="false";
		}
		if(isTextExist(regForm.vehicle_engine)==false)
		{
			strres="false";
		}
		if(isTextExist(regForm.vehicle_chassis)==false)
		{
			strres="false";
		}
		if(isTextExist(regForm.question)==false)
		{
			strres="false";
		}
		if(strres=="false")		    
		{
		    alert("Some Of Necessory Detail(s) are Still Blank, Please Fill up All Compulsary Detail(s)");
		    return false;
		}		
		else
		{
		    var requestUrl = AjaxPageName + "?Email=" + regForm.email.value + "&Name=" + regForm.surname.value + " " + regForm.forename.value + "";
	        CreateXmlHttp();
	        if(XmlHttp)
	        {
		        XmlHttp.open("GET", requestUrl,true);
		        XmlHttp.send(null);
	        }   
        
		    return true;
		}
}
