
	function sfHover() {
		var sfEls = document.getElementById("nav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
	if (window.attachEvent) window.attachEvent("onload", sfHover);

	var xmlHttp
	
	function createXMLHttpRequest(){ //v1.0 3Thinker Technologies Inc. AJAX library
		if (window.XMLHttpRequest){ // if Mozilla, Safari etc
			xmlHttp = new XMLHttpRequest(); 
		} else if (window.ActiveXObject) { // if IE
			try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");} 
			catch (e){
				try{xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}
				catch (e){}
			}
		}
	}
	
function submitForm2(iScript,iForm,iTarget){
	
 	$(iTarget).innerHTML='<img src="images/ajax-loader.gif">';
	var url='scripts/'+iScript;
	var rand=Math.random(9999);
	var pars=$(iForm).serialize()+'&rand='+rand;
	var myAjax=new Ajax.Updater(iTarget,url,{method: 'post', parameters: pars,evalScripts: true});
}
	
	
	
	function submitForm(iForm,iProcess){ //v1.0 3Thinker Technologies Inc. AJAX library
		document.getElementById('results').innerHTML="<img src='images/ajax-loader.gif' border='0'>";
		createXMLHttpRequest();
		var postStr=createQueryString(iForm);
		xmlHttp.onreadystatechange=getFormResults;
		xmlHttp.open("POST","scripts/"+iProcess,true);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlHttp.send(postStr);
	}

	function getFormResults(){ //v1.0 3Thinker Technologies Inc. AJAX library
		
		if (xmlHttp.readyState == 4){
			if (xmlHttp.status==200){
				var varredirect=xmlHttp.responseText.indexOf('Successful login.');
				var varredirect2=xmlHttp.responseText.indexOf('Successful first time login.');
				var varredirect3=xmlHttp.responseText.indexOf('Password Updated.');
				if (varredirect!= -1 ) {window.location = "dealerHome.php"}
				if (varredirect2!= -1 ) {window.location = "dealerFirstTime.php"}
				if (varredirect3!= -1 ) {window.location = "dealerHome.php"}
				document.getElementById('results').innerHTML=(xmlHttp.responseText);
			}
		}
	}
	
	function createQueryString(iForm){
		var qStr='';
		if (document.getElementById(iForm)){
			var iFormElements = document.getElementById(iForm).elements;
			for (var i = 0; i < iFormElements.length; i++){
				var ele = iFormElements[i];
				// check for a name, skip not named
				if (!ele.name){continue;}
				// Skip the ele if its type radio or checkbox and is not "checked"
				if ((ele.type == "radio" || ele.type == "checkbox") && ele.checked==false){continue;}
				// Add in a seperator if needed.
				if (qStr!=''){qStr += "&";}
				// Use the JS escape function to escape the var name and value
				qStr += encodeURIComponent(ele.name) + "=" + encodeURIComponent(ele.value);
			}
		}	
		return qStr;	
	}
	
	function validateBecomeDealerForm(){//v1.0 3Thinker Technologies Inc.
		var errors='';
		if(document.getElementById('Name').value==''){errors+='Name is required.\n';}
		if(document.getElementById('Address').value==''){errors+='Address is required.\n';}
		if(document.getElementById('City').value==''){errors+='City is required.\n';}
		if(document.getElementById('ProvState').value==''){errors+='Province is required.\n';}
		if(document.getElementById('PostalZip').value==''){errors+='Postal Code is required.\n';}
		if(document.getElementById('Phone').value==''){errors+='Phone is required.\n';}
		if(document.getElementById('Email').value==''){errors+='Email address is required.\n';}
		
		if (errors) {alert('The following problem(s) occurred:\n\n'+errors +'\n\nPlease check and try again.');
		} else {
			submitForm('form1','becomedealerScript.php');
		}
				
	}
	
	function validateAskForm(){//v1.0 3Thinker Technologies Inc.
		var errors='';
		if(document.getElementById('Name').value==''){errors+='Name is required.\n';}
		if(document.getElementById('Email').value==''){errors+='Email address is required.\n';}
		
		if (errors) {alert('The following problem(s) occurred:\n\n'+errors +'\n\nPlease check and try again.');
		} else {
			submitForm('form1','askScript.php');
		}
				
	}

	function validateCreateDealerForm(){//v1.0 3Thinker Technologies Inc.
		var errors='';
		if(document.getElementById('Name').value==''){errors+='Name is required.\n';}
		if(document.getElementById('Address').value==''){errors+='Address is required.\n';}
		if(document.getElementById('Phone').value==''){errors+='Phone is required.\n';}
		if(document.getElementById('Email').value==''){errors+='Email address is required.\n';}
		if(document.getElementById('username').value==''){errors+='Username is required.\n';}
		
		if (errors) {alert('The following problem(s) occurred:\n\n'+errors +'\n\nPlease check and try again.');
		} else {
			submitForm('form1','createdealerscript.php');
		}
				
	}
	
	function validatePasswordDealerForm(){//v1.0 3Thinker Technologies Inc.
		var errors='';
		if(document.getElementById('pwd').value=='' || document.getElementById('pwd2').value=='' ){errors+='Passwords are required.\n';}
		if(document.getElementById('pwd').value!=document.getElementById('pwd2').value){errors+='Passwords do not match.\n';}
		if(document.getElementById('pwd').value.length<8){errors+='Password should be at least 8 characters.\n';}
		if (errors) {alert('The following problem(s) occurred:\n\n'+errors +'\n\nPlease check and try again.');
		} else {
			submitForm('form1','passworddealerscript.php');
		}
				
	}
