// JavaScript Document
function compareOptionText2(a, b){ 
	var  i = 0; 
	aString = a.text.toLowerCase(); 
	bString = b.text.toLowerCase(); 
	if (aString < bString) return -1; 
	else if (aString > bString) return 1; 
	return 0; 
} 			
function trans(completeAreaCity,areaCity,moveAll){
	var obj1 = document.all[completeAreaCity] ;
	var obj2 = document.all[areaCity];
	if(( obj1.selectedIndex == -1) && ( moveAll == false)){
		return;
	}
	newobj2 = new Array( obj2.options.length );			

	var len = 0;
	for( len = 0; len < obj2.options.length; len++ ){
		if ( obj2.options[ len ] != null ){
			newobj2[ len ] = new Option( obj2.options[ len ].text, obj2.options[ len ].value, obj2.options[ len ].defaultSelected, obj2.options[ len ].selected );
		}
	}
	for( var i = 0; i < obj1.options.length; i++ ){ 
		if ( obj1.options[i] != null && ( obj1.options[i].selected == true || moveAll)){
			newobj2[ len ] = new Option( obj1.options[i].text, obj1.options[i].value, obj1.options[i].defaultSelected, obj1.options[i].selected );
			len++;
		}
	}
	newobj2.sort( compareOptionText2 );   // BY TEXT
	for ( var j = 0; j < newobj2.length; j++ ){
		if ( newobj2[ j ] != null ){
			obj2.options[ j ] = newobj2[ j ];
		}
	}
	for( var i = obj1.options.length - 1; i >= 0; i-- ){ 
		if ( obj1.options[i] != null && ( obj1.options[i].selected == true || moveAll )){
			obj1.options[i] = null;
		}
	}
}

function isNotAlphabets(str){
	var valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
	var temp;
	for (var i=0; i<str.length; i++) {
		temp = "" + str.substring(i, i+1);
		if (valid.indexOf(temp) == -1) return true;
	}
	return false;
}



function IsNumeric(str){
	r1=new RegExp("^[$]?[0-9]+([.]{1}[0-9]{2})?$"); 
	r2=new RegExp("^[$]?[0-9]+([,][0-9]{3})+([.]{1}[0-9]{2})?$"); 
	return(r1.test(str)||r2.test(str));
} 

function IsFloat(str){
	r1=new RegExp("^[0-9]+([.]{1}([0-9]*))?$"); 
	r2=new RegExp("^[0-9]+([,][0-9]{3})+([.]{1}([0-9]*))?$"); 
	return(r1.test(str)||r2.test(str));
}

function validemail(mailStr){
	var matchStr=mailStr;
	var isValid = (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(matchStr));	
	
	if(isValid){
		return true;
	}
	else{
		return false;
	}
}

function formatDollar(obj)
{
	//alert(obj.value);
	var num = obj.value
	num = num.toString().replace(/\$|\,/g,'');
	
	if(isNaN(num))
	return false;

	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num;
	var temp=((sign)?'':'-') + '$' + num + '.' + cents;
	if(temp!="$0.00")
	{
		obj.value=num;
		return true;
	}
	else
	{
		obj.value="";
		//obj.focus();
		return false;
	}
}

function tabvalidatePhone(phfield1,phfield2){
	if(document.getElementById(phfield1).value.length==3) 
		document.getElementById(phfield2).focus();
}

function tabvalidatemultiPhone(phfield1,phfield2){
	if(document.getElementById(phfield1).value.length==4) 
	 document.getElementById(phfield2).focus();
}


function validnumber1()
{
	if(event.keyCode==47 || event.keyCode==126 || event.keyCode==46) 
		event.returnValue = false;
	if ((event.keyCode <= 45 || event.keyCode > 57) && event.keyCode !=13) 
		event.returnValue = false; 
}
function checkValidNumber(obj) {
	var num = "0123456789";
	var i;
	if(obj.value!="") {
		var objVal = obj.value;
		var objLen = obj.value.length;
		for(i=0;i<objLen;i++) {
			var check = objVal.substring(i,i+1);
			if(num.indexOf(check) == -1) {
				alert("Please enter numerics");
				obj.value = "";
				obj.focus();
				return false;
			}
		}
	}
	return true;
}

function checkValidData(obj) {
	var num = "!@#$%^&*()_+|';?><0123456789";
	var i;
	if(obj.value!="") {
		var phval = obj.value;
		var phlen = obj.value.length;
		for(i=0;i<phlen;i++) {
			var check = phval.substring(i,i+1);
			if(num.indexOf(check) > 0) {
				return false;
			}
		}
	}
	return true;
}

function checkValidContactName(obj) {
	//var cName = "!@#$%^&*()><?/;:'-+{}[]\",.\\~`0123456789";
	var cName = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
	var i;
	if(obj.value!="") {
		var objval = obj.value;
		var objlen = obj.value.length;
		for(i=0;i<objlen;i++) {
			var check = objval.substring(i,i+1);
			if(cName.indexOf(check) == -1) {
				alert("Please enter only alphabets");
				obj.value = "";
				obj.focus();
				return false;
			}
		}
	}
	return true;
}

function checkValidContactNameNew(obj) {
	var cName = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 ";
	var i;
	if(obj.value!="") {
		var objval = obj.value;
		var objlen = obj.value.length;
		for(i=0;i<objlen;i++) {
			var check = objval.substring(i,i+1);
			if(cName.indexOf(check) == -1) {
				alert("Please enter only alphanumerics.");
				obj.value = "";
				obj.focus();
				var status = true;
			}
		}
		
		/*if(status)
		{
			var objval = obj.value;
			var objlen = obj.value.length;
			for(i=0;i<objlen;i++) {
				var check = objval.substring(i,i+1);
				if(cName.indexOf(check) == -1) {
					alert(objval.indexOf(check));
					objval = objval.replace(check, "");
					alert(objval);
				}
			}
		}
		objval = Trim(objval);*/
	}
	return true;
}

function validURL(obj)
{
	var num = "!@#$%^&*()_+=?><,{}][';|\\";
	var i;
	if(obj.value!="") {
		var objval = obj.value;
		var objlen = obj.value.length;
		for(i=0;i<objlen;i++) {
			var check = objval.substring(i,i+1);
			if(num.indexOf(check) != -1) {
				obj.value = "http://";
				return false;
			}
		}
	}
	return true;
}

function checkValidStaffId(obj) {
	//var cName = "!@#$%^&*()><?/;:'-+{}[]\",.\\~`0123456789";
	var cName = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	var i;
	if(obj.value!="") {
		var objval = obj.value;
		var objlen = obj.value.length;
		for(i=0;i<objlen;i++) {
			var check = objval.substring(i,i+1);
			if(cName.indexOf(check) == -1) {
				alert("Please enter valid staff id");
				obj.value = "";
				obj.focus();
				return false;
			}
		}
	}
	return true;
}

function excludeSpecialChar(obj) {
	var spChars = "!@#$%^&*()><?/;:'-+{}[]\",.\\~`";
	var i;
	if(obj.value!="") {
		var objval = obj.value;
		var objlen = obj.value.length;
		for(i=0;i<objlen;i++) {
			var check = objval.substring(i,i+1);
			if(spChars.indexOf(check) > 0) {
				alert("Special characters not allowed");
				obj.value = "";
				obj.focus();
				return false;
			}
		}
	}
	return true;
}

/* Login Username Validation */
function validUserName(_f){
	var matchStr=_f;
	var isValid = (/[^0-9a-zA-Z_ ]/.test(matchStr));
	if(isValid){
		return false;
	}
	else{	
		return true;
	}
}

function  validateUserId( strValue ) {
	var objRegExp  =  /^[\w]+$/; 
	var flag = objRegExp.test(strValue.value);
	
	if(strValue.value != "" && !flag)
	{
		alert("Enter Valid User ID");
		var len = strValue.value.length;
		strValue.value = "";
		strValue.focus();
		return flag;
	}
	else {
		return true;
	}
}

function  validateSearchFields(strValue) 
{
	var objRegExp  =  /^[\w]+$/; 
	var flag = objRegExp.test(strValue.value);
	
	if(strValue.value != "" && !flag)
	{
		alert("Enter Valid Data");
		var len = strValue.value.length;
		strValue.value = "";
		strValue.focus();
		return flag;
	}
	else {
		return true;
	}
}

function  validateNumeric( strValue ) {
	var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/; 
	var flag = objRegExp.test(strValue.value);
	
	if(strValue.value != "" && !flag)
	{
		alert("Enter numerics");
		var len = strValue.value.length;
		strValue.value = "";
		strValue.focus();
		return flag;
	}
	else {
		return true;
	}
}

/// Calculator Calculations:

function validates()
 {
	 if (document.getElementById('NameA').value=="")
		{
			alert("Please enter the number of leads bought");
			document.getElementById('NameA').focus();
			 return false;
		}
		if (document.getElementById('NameA').value!="")
		{
			  document.getElementById('NameA').value=removeLeadingAndTrailingChar(document.getElementById('NameA').value);
			  if(document.getElementById('NameA').value.length=="0")
			     { 
					alert("Please enter the number of leads bought");
					document.getElementById('NameA').focus();
					return false;	
				 }
		}
		
		if (document.getElementById('NameB').value=="")
		{
			alert("Please enter total spend for leads");
			document.getElementById('NameB').focus();
			 return false;
		}
		if (document.getElementById('NameB').value!="")
		{
			  document.getElementById('NameB').value=removeLeadingAndTrailingChar(document.getElementById('NameB').value);
			  if(document.getElementById('NameB').value.length=="0")
			     { 
					alert("Please enter total spend for leads");
					document.getElementById('NameB').focus();
					return false;	
				 }
		}
		if (document.getElementById('NameD').value=="")
		{
			alert("Please enter vehicles sold from leads");
			document.getElementById('NameD').focus();
			 return false;
		}
		if (document.getElementById('NameD').value!="")
		{
			  document.getElementById('NameD').value=removeLeadingAndTrailingChar(document.getElementById('NameD').value);
			  if(document.getElementById('NameD').value.length=="0")
			     { 
					alert("Please enter vehicles sold from leads");
					document.getElementById('NameD').focus();
					return false;	
				 }
		}
		if (document.getElementById('NameF').value=="")
		{
			alert("Please enter gross margin from sales");
			document.getElementById('NameF').focus();
			 return false;
		}
		if (document.getElementById('NameF').value!="")
		{
			  document.getElementById('NameF').value=removeLeadingAndTrailingChar(document.getElementById('NameF').value);
			  if(document.getElementById('NameF').value.length=="0")
			     { 
					alert("Please enter gross margin from sales");
					document.getElementById('NameF').focus();
					return false;	
				 }
		}
		
	   var a,b,d,f;
       a=document.getElementById('NameA').value;
	   b=document.getElementById('NameB').value;
	   d=document.getElementById('NameD').value;
	   f=document.getElementById('NameF').value;
       var c=parseInt(b)/parseInt(a);
	   document.getElementById('NameC').value=Math.floor(c);
	   var e=parseInt(b)/parseInt(d);
	    document.getElementById('NameE').value=Math.floor(e);
		var g=parseInt(f)/parseInt(d);
	   document.getElementById('NameG').value=Math.floor(g);
	   var h=parseInt(d)/parseInt(a) * 100;
	   document.getElementById('NameH').value=Math.floor(h);
	   return true;
}
 
 function calc(){
	 if (document.getElementById('NameH').value=="")
		{
			alert("Please enter first four values");
			document.getElementById('NameA').focus();
			 return false;
		}
	var a,b,d,f;
       a=document.getElementById('NameA').value;
	   b=document.getElementById('NameB').value;
	   d=document.getElementById('NameD').value;
	   f=document.getElementById('NameF').value;
       var c=parseInt(b)/parseInt(a);
	   var e=parseInt(b)/parseInt(d);
	   var g=parseInt(f)/parseInt(d);
	   var h=parseInt(a)/100 * parseInt(d);
	   var a1=document.getElementById('NameA').value;
	   var b1=document.getElementById('NameB').value;
	   document.getElementById('NameA1').value=Math.floor(a1);
	   document.getElementById('NameB1').value=Math.floor(b1);
	   var d1=parseInt(a)*0.15;
	   document.getElementById('NameD1').value=Math.floor(d1);
	    var c1=parseInt(b)/parseInt(a);
	   document.getElementById('NameC1').value=Math.floor(c1);
	   var e1=parseInt(b1)/parseInt(d1);
	    document.getElementById('NameE1').value=Math.floor(e1);
		var g1=(parseInt(g)+(parseInt(e)-parseInt(e1)));
	    document.getElementById('NameG1').value=Math.floor(g1);
		 var f1=parseInt(g1)*parseInt(d1);
	   document.getElementById('NameF1').value=Math.floor(f1);
		var h1=parseInt(d1)/ parseInt(a1) * 100;
	    document.getElementById('NameH1').value=Math.floor(h1);
		var ann1=parseInt(f1)-parseInt(f);
		var annual=parseInt(ann1)*12;
		document.getElementById('Month').value="$"+annual;
		document.getElementById('Annual').value="$"+ann1;
		 
//		document.getElementById('Month').value=
		return true;
 }

function dot(obj)
{
//	if (event.keyCode!=9 && event.keyCode!=16)
//	{
//		alert(event.keyCode);
//	}
	
	if (event.keyCode==190 || event.keyCode==110)
	{

var i=0;j=0;text="";total="";
var len=obj.value.length;
for(i=0;i<len;i++)
{
	text=obj.value.charAt(i);
	if(text==".")
	{
		j=j+1;
	}
	if(j>1){text='';}
	total=total+text;
}
obj.value=total;
	}
}




function  validateName( strValue ) {
	var objRegExp  =  /^[a-zA-Z]+$/; 
	var flag = objRegExp.test(strValue.value);

	if(strValue.value != "" && !flag)
	{
		alert("Enter Alphabets");
		var len = strValue.value.length;
		var str = strValue.value.substr(0,(strValue.value.length-1));
		strValue.value = str;
		strValue.focus();
		return flag;
	}
	else {
		return true;
	}
}

function validateurl(url) {
	if(url.indexOf("http://")==-1)
		return false;
	
	var afterhttp = url.substr(7,url.indexOf("."));
	if(afterhttp.length <= 1) 
		return false;
	
	if(url.indexOf(".")>0) {
		var afterDot = url.substr(url.indexOf("."), url.length-1);
		if(afterDot.length<=1) 
			return false;
	}
	else {
		return false; 
	}
	return true;
}

function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(0)) != -1) 
   {
      // We have a string with leading blank(s)...
      var j = 0, i = s.length;
      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;
      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}


function RTrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to RTrim

*/
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) 
   {
      // We have a string with trailing blank(s)...
      var i = s.length - 1;       // Get length of string
      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
    }
   return s;
}


function Trim(str)
/*
   PURPOSE: Remove trailing and leading blanks from our string.
   IN: str - the string we want to Trim
   RETVAL: A Trimmed string!
*/
{
   return RTrim(LTrim(str));
}





// Script for AJAX
function FillData (url,state, dateWeek)
{
	
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
  		http_request = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE
		http_request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	if (!http_request) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}

	if (http_request){	
			if(state == "designation_td") {				
				url = url + "&department="+document.getElementById('department').value;
				if(document.getElementById('desgSel').value!="") {
				url = url + "&desgSel=" + document.getElementById('desgSel').value;
				}
				http_request.onreadystatechange = function() { processStateChangeDesignation(http_request); } ;
			}
			if(state == "user_td") {				
				url = url + "&userType="+document.getElementById('userType').value;
				/*if(document.getElementById('desgSel').value!="") {
				url = url + "&desgSel=" + document.getElementById('desgSel').value;
				}*/
				http_request.onreadystatechange = function() { processStateChangeUser(http_request); } ;
			}
			if(state == "dealer_td") {				
				url = url + "&dealerGroup="+document.getElementById('dealerGroup').value;
				http_request.onreadystatechange = function() { processStateChangeDealer(http_request); } ;
			}
			if(state == "weekListTd") {				
				url = url + "&year="+document.getElementById('year').value + "&month="+document.getElementById('month').value+ "&dateWeek="+dateWeek;
				http_request.onreadystatechange = function() { processStateChangeWeekList(http_request); } ;
			}
			http_request.open ("GET", url, true);
			http_request.send(null);
	}
} 


function processStateChangeDesignation (http_request)
{
  if (http_request.readyState == 4){ // Complete 
     document.getElementById("designation_td").innerHTML = http_request.responseText;
  }
} 
function processStateChangeUser (http_request)
{
  if (http_request.readyState == 4){ // Complete 
     document.getElementById("user_td").innerHTML = http_request.responseText;
  }
}
function processStateChangeDealer (http_request)
{
  if (http_request.readyState == 4){ // Complete 
     document.getElementById("dealer_td").innerHTML = http_request.responseText;
  }
}
function processStateChangeWeekList (http_request)
{
  if (http_request.readyState == 4){ // Complete 
     document.getElementById("weekListTd").innerHTML = http_request.responseText;
  }
}

// Function to fill states
var states="Select|AK|AL|AR|AZ|CA|CO|CT|DC|DE|FL|GA|HI|IA|ID|IN|KS|KY|LA|MA|ME|MD|MI|MN|MO|MS|MT|NC|ND|NE|NH|NJ|NM|NV|NY|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VT|VA|WA|WI|WV|WY";

function fillStates(beanState) {
var allStates = states.split("|");
	for(var i=0; i <allStates.length; i++)
	{ 													
			document.getElementById('state').options[i] = new Option(allStates[i],allStates[i]);		
			if(allStates[i] == beanState) document.getElementById('state').options[i].selected = true;
	}
}



// Function to convert to uppercase
function convertToUpper(obj) {
	obj.value = obj.value.toUpperCase();
}

// Function to convert to lowercase
function convertToLower(obj) {
	obj.value = obj.value.toLowerCase();
}


function openWindow(url) {
	var winOpen = window.open(url, 'popup', 'width=1000, height=620, scrollbars=no, top=40, left=5');
	winOpen.focus();
}

function closeWindow(divId) {
	document.getElementById(divId).style.visibility = "hidden";
	//document.getElementById('userName').focus();
}

// Additional Scripts

function validate(){
	if (document.contactus.Name.value=="")
		{alert("Please Enter Name");
			document.contactus.Name.focus();
			 return false;
		}
		if (document.contactus.Name.value!="")
		{
			  document.contactus.Name.value=removeLeadingAndTrailingChar(document.contactus.Name.value);
			  if(document.contactus.Name.value.length=="0")
			     { 
					alert("Please Enter Name");
					document.contactus.Name.focus();
					return false;	
				 }
		}
		if (document.contactus.Store.value=="")
		{alert("Please Enter Store");
			document.contactus.Store.focus();
			 return false;
		}
			if (document.contactus.Store.value!="")
		{
			  document.contactus.Store.value=removeLeadingAndTrailingChar(document.contactus.Store.value);
			  if(document.contactus.Store.value.length=="0")
			     { 
					alert("Please Enter Store");
					document.contactus.Store.focus();
					return false;	
				 }
		}
		
		if (document.contactus.Phone.value=="")
		{alert("Please Enter Phone No.");
			document.contactus.Phone.focus();
			 return false;
		}
		if (document.contactus.Phone.value.length <10 )
		{alert("Please Enter Valid Phone No.");
			document.contactus.Phone.focus();
			 return false;
		}
			if (document.contactus.Phone.value!="")
		{
			  document.contactus.Phone.value=removeLeadingAndTrailingChar(document.contactus.Phone.value);
			  if(document.contactus.Phone.value.length=="0")
			     { 
					alert("Enter Phone No.");
					document.contactus.Phone.focus();
					return false;	
				 }
		}
	if (document.contactus.Email.value=="")
		{alert("Please Enter E-mail");
			document.contactus.Email.focus();
			 return false;
		}
	if (document.contactus.Email.value!="" && !validemail(document.contactus.Email.value))
		{ 
			alert("Please Enter Valid E-mail");
			document.contactus.Email.focus();
			return false;		
		}
	if (document.contactus.City.value=="")
		{alert("Please Enter City");
			document.contactus.City.focus();
			 return false;
		}
				if (document.contactus.City.value!="")
		{
			  document.contactus.City.value=removeLeadingAndTrailingChar(document.contactus.City.value);
			  if(document.contactus.City.value.length=="0")
			     { 
					alert("Please Enter City");
					document.contactus.City.focus();
					return false;	
				 }
		}
	if (document.contactus.State.selectedIndex=="0")
		{alert("Please Select State");
			document.contactus.State.focus();
			 return false;
		}
		if (document.contactus.Zip.value=="" || isNaN(document.contactus.Zip.value))
		{alert("Please Enter Zip");
			document.contactus.Zip.focus();
			 return false;
		}
		if (document.contactus.Zip.value.length <5)
		{alert("Please Enter Valid Zip");
			document.contactus.Zip.focus();
			 return false;
		}
				if (document.contactus.Zip.value!="")
		{
			  document.contactus.Zip.value=removeLeadingAndTrailingChar(document.contactus.Zip.value);
			  if(document.contactus.Zip.value.length=="0")
			     { 
					alert("Enter Zip");
					document.contactus.Zip.focus();
					return false;	
				 }
		}
 
	
	document.contactus.submit();
}
	
	
	function validate1(){
	 
	if (document.contactus1.Name.value=="")
		{alert("Please Enter Name");
			document.contactus1.Name.focus();
			 return false;
		}
		if (document.contactus1.Name.value!="")
		{
			  document.contactus1.Name.value=removeLeadingAndTrailingChar(document.contactus1.Name.value);
			  if(document.contactus1.Name.value.length=="0")
			     { 
					alert("Please Enter Name");
					document.contactus1.Name.focus();
					return false;	
				 }
		}
		if (document.contactus1.Store.value=="")
		{alert("Please Enter Store");
			document.contactus1.Store.focus();
			 return false;
		}
			if (document.contactus1.Store.value!="")
		{
			  document.contactus1.Store.value=removeLeadingAndTrailingChar(document.contactus1.Store.value);
			  if(document.contactus1.Store.value.length=="0")
			     { 
					alert("Please Enter Store");
					document.contactus1.Store.focus();
					return false;	
				 }
		}
		
		if (document.contactus1.Phone.value=="")
		{alert("Please Enter Phone No.");
			document.contactus1.Phone.focus();
			 return false;
		}
		if (document.contactus1.Phone.value.length <10 )
		{alert("Please Enter Valid Phone No.");
			document.contactus1.Phone.focus();
			 return false;
		}
			if (document.contactus1.Phone.value!="")
		{
			  document.contactus1.Phone.value=removeLeadingAndTrailingChar(document.contactus1.Phone.value);
			  if(document.contactus1.Phone.value.length=="0")
			     { 
					alert("Enter Phone No.");
					document.contactus1.Phone.focus();
					return false;	
				 }
		}
	if (document.contactus1.Email.value=="")
		{alert("Please Enter E-mail");
			document.contactus1.Email.focus();
			 return false;
		}
	if (document.contactus1.Email.value!="" && !validemail(document.contactus1.Email.value))
		{ 
			alert("Please Enter Valid E-mail");
			document.contactus1.Email.focus();
			return false;		
		}
	if (document.contactus1.City.value=="")
		{alert("Please Enter City");
			document.contactus1.City.focus();
			 return false;
		}
				if (document.contactus1.City.value!="")
		{
			  document.contactus1.City.value=removeLeadingAndTrailingChar(document.contactus1.City.value);
			  if(document.contactus1.City.value.length=="0")
			     { 
					alert("Please Enter City");
					document.contactus1.City.focus();
					return false;	
				 }
		}
	if (document.contactus1.State.selectedIndex=="0")
		{alert("Please Select State");
			document.contactus1.State.focus();
			 return false;
		}
		if (document.contactus1.Zip.value=="" || isNaN(document.contactus1.Zip.value))
		{alert("Please Enter Zip");
			document.contactus1.Zip.focus();
			 return false;
		}
		if (document.contactus1.Zip.value.length <5)
		{alert("Please Enter Valid Zip");
			document.contactus1.Zip.focus();
			 return false;
		}
				if (document.contactus1.Zip.value!="")
		{
			  document.contactus1.Zip.value=removeLeadingAndTrailingChar(document.contactus1.Zip.value);
			  if(document.contactus1.Zip.value.length=="0")
			     { 
					alert("Enter Zip");
					document.contactus1.Zip.focus();
					return false;	
				 }
		}
 
	
	document.contactus1.submit();
	}
	
	
	function validate2(){
	 
	if (document.contactus2.Name.value=="")
		{alert("Please Enter Name");
			document.contactus2.Name.focus();
			 return false;
		}
		if (document.contactus2.Name.value!="")
		{
			  document.contactus2.Name.value=removeLeadingAndTrailingChar(document.contactus2.Name.value);
			  if(document.contactus2.Name.value.length=="0")
			     { 
					alert("Please Enter Name");
					document.contactus2.Name.focus();
					return false;	
				 }
		}
		if (document.contactus2.Store.value=="")
		{alert("Please Enter Store");
			document.contactus2.Store.focus();
			 return false;
		}
			if (document.contactus2.Store.value!="")
		{
			  document.contactus2.Store.value=removeLeadingAndTrailingChar(document.contactus2.Store.value);
			  if(document.contactus2.Store.value.length=="0")
			     { 
					alert("Please Enter Store");
					document.contactus2.Store.focus();
					return false;	
				 }
		}
		
		if (document.contactus2.Phone.value=="")
		{alert("Please Enter Phone No.");
			document.contactus2.Phone.focus();
			 return false;
		}
		if (document.contactus2.Phone.value.length <10 )
		{alert("Please Enter Valid Phone No.");
			document.contactus2.Phone.focus();
			 return false;
		}
			if (document.contactus2.Phone.value!="")
		{
			  document.contactus2.Phone.value=removeLeadingAndTrailingChar(document.contactus2.Phone.value);
			  if(document.contactus2.Phone.value.length=="0")
			     { 
					alert("Enter Phone No.");
					document.contactus2.Phone.focus();
					return false;	
				 }
		}
	if (document.contactus2.Email.value=="")
		{alert("Please Enter E-mail");
			document.contactus2.Email.focus();
			 return false;
		}
	if (document.contactus2.Email.value!="" && !validemail(document.contactus2.Email.value))
		{ 
			alert("Please Enter Valid E-mail");
			document.contactus2.Email.focus();
			return false;		
		}
	if (document.contactus2.City.value=="")
		{alert("Please Enter City");
			document.contactus2.City.focus();
			 return false;
		}
				if (document.contactus2.City.value!="")
		{
			  document.contactus2.City.value=removeLeadingAndTrailingChar(document.contactus2.City.value);
			  if(document.contactus2.City.value.length=="0")
			     { 
					alert("Please Enter City");
					document.contactus2.City.focus();
					return false;	
				 }
		}
	if (document.contactus2.State.selectedIndex=="0")
		{alert("Please Select State");
			document.contactus2.State.focus();
			 return false;
		}
		if (document.contactus2.Zip.value=="" || isNaN(document.contactus2.Zip.value))
		{alert("Please Enter Zip");
			document.contactus2.Zip.focus();
			 return false;
		}
		if (document.contactus2.Zip.value.length <5)
		{alert("Please Enter Valid Zip");
			document.contactus2.Zip.focus();
			 return false;
		}
				if (document.contactus2.Zip.value!="")
		{
			  document.contactus2.Zip.value=removeLeadingAndTrailingChar(document.contactus2.Zip.value);
			  if(document.contactus2.Zip.value.length=="0")
			     { 
					alert("Enter Zip");
					document.contactus2.Zip.focus();
					return false;	
				 }
		}	
	 document.contactus2.submit();
	}
	
	
	function validalphabet()
{

		
	if (event.keyCode==46 || event.keyCode==126) 
		event.returnValue = false; 
	if (((event.keyCode > 32 && event.keyCode < 48) || (event.keyCode > 57 && event.keyCode < 65) || (event.keyCode > 90 && event.keyCode < 97) || (event.keyCode > 45 && event.keyCode <= 57)))
		event.returnValue = false; 
}




function validnumber()
{
	

	if(event.keyCode==47 || event.keyCode==126) 
		event.returnValue = false;
	if ((event.keyCode <= 45 || event.keyCode > 57) && event.keyCode !=13) 
		event.returnValue = false; 
}

function layer_submit()
{
	if(event.keyCode==13)
	{
		validate();	
	}
}
function layer_submit1()
{
	if(event.keyCode==13)
	{
		validate2();	
	}
}

function layer_submit2()
{
	if(event.keyCode==13)
	{
		validate1();	
	}
}
 

  

function removeLeadingAndTrailingChar(inputString)
{
	var removeChar = " ";
	var returnString = inputString;
	if (removeChar.length)
   		{
		  while(''+returnString.charAt(0)==removeChar)
			{
			  returnString=returnString.substring(1,returnString.length);
			}
    	  while(''+returnString.charAt(returnString.length-1)==removeChar)
	 	    {
	  	      returnString=returnString.substring(0,returnString.length-1);
			} 
		}
		return returnString;
}

 
	
	
	function validate4(){
	if (document.contactus_signup.Name.value=="")
		{alert("Please Enter Name");
			document.contactus_signup.Name.focus();
			 return false;
		}
		if (document.contactus_signup.Name.value!="")
		{
			  document.contactus_signup.Name.value=removeLeadingAndTrailingChar(document.contactus_signup.Name.value);
			  if(document.contactus_signup.Name.value.length=="0")
			     { 
					alert("Please Enter Name");
					document.contactus_signup.Name.focus();
					return false;	
				 }
		}
		if (document.contactus_signup.Store.value=="")
		{alert("Please Enter Store");
			document.contactus_signup.Store.focus();
			 return false;
		}
			if (document.contactus_signup.Store.value!="")
		{
			  document.contactus_signup.Store.value=removeLeadingAndTrailingChar(document.contactus_signup.Store.value);
			  if(document.contactus_signup.Store.value.length=="0")
			     { 
					alert("Please Enter Store");
					document.contactus_signup.Store.focus();
					return false;	
				 }
		}
		
		if (document.contactus_signup.Phone.value=="")
		{
			alert("Please Enter Phone No.");
			document.contactus_signup.Phone.focus();
			return false;
		}
		if(! phoneFormatCheck(document.contactus_signup.Phone,'Phone Number')) return false;
		
		if (document.contactus_signup.Email.value=="")
		{alert("Please Enter E-mail");
			document.contactus_signup.Email.focus();
			 return false;
		}
		if (document.contactus_signup.Email.value!="" && !validemail(document.contactus_signup.Email.value))
		{ 
			alert("Please Enter Valid E-mail");
			document.contactus_signup.Email.focus();
			return false;		
		}
		
		if (document.contactus_signup.Street.value=="")
		{alert("Please Enter Street");
			document.contactus_signup.Street.focus();
			 return false;
		}
				if (document.contactus_signup.Street.value!="")
		{
			  document.contactus_signup.Street.value=removeLeadingAndTrailingChar(document.contactus_signup.Street.value);
			  if(document.contactus_signup.Street.value.length=="0")
			     { 
					alert("Please Enter Street");
					document.contactus_signup.Street.focus();
					return false;	
				 }
		}
	if (document.contactus_signup.City.value=="")
		{alert("Please Enter City");
			document.contactus_signup.City.focus();
			 return false;
		}
				if (document.contactus_signup.City.value!="")
		{
			  document.contactus_signup.City.value=removeLeadingAndTrailingChar(document.contactus_signup.City.value);
			  if(document.contactus_signup.City.value.length=="0")
			     { 
					alert("Please Enter City");
					document.contactus_signup.City.focus();
					return false;	
				 }
		}
	if (document.contactus_signup.State.selectedIndex=="0")
		{alert("Please Select State");
			document.contactus_signup.State.focus();
			 return false;
		}
		if (document.contactus_signup.Zip.value=="" || isNaN(document.contactus_signup.Zip.value))
		{alert("Please Enter Zip");
			document.contactus_signup.Zip.focus();
			 return false;
		}
		if (document.contactus_signup.Zip.value.length <5)
		{
			alert("Please Enter Valid Zip");
			document.contactus_signup.Zip.focus();
			return false;
		}
		if(! zipFormatCheck(document.contactus_signup.Zip)) return false;
 
	
	return true;
	}
	
	
	
	
	function validate3(){
	if (document.contactus_new.Name.value=="")
		{alert("Please Enter Name");
			document.contactus_new.Name.focus();
			 return false;
		}
		if (document.contactus_new.Name.value!="")
		{
			  document.contactus_new.Name.value=removeLeadingAndTrailingChar(document.contactus_new.Name.value);
			  if(document.contactus_new.Name.value.length=="0")
			     { 
					alert("Please Enter Name");
					document.contactus_new.Name.focus();
					return false;	
				 }
		}
		if (document.contactus_new.Store.value=="")
		{alert("Please Enter Store");
			document.contactus_new.Store.focus();
			 return false;
		}
			if (document.contactus_new.Store.value!="")
		{
			  document.contactus_new.Store.value=removeLeadingAndTrailingChar(document.contactus_new.Store.value);
			  if(document.contactus_new.Store.value.length=="0")
			     { 
					alert("Please Enter Store");
					document.contactus_new.Store.focus();
					return false;	
				 }
		}
		
		document.contactus_new.Phone.value=removeLeadingAndTrailingChar(document.contactus_new.Phone.value);
		if (document.contactus_new.Phone.value=="")
		{
			alert("Please Enter Phone No.");
			document.contactus_new.Phone.focus();
			return false;
		}
		if(! phoneFormatCheck(document.contactus_new.Phone,'Phone Number')) return false;
		
		/*if (document.contactus_new.Phone.value.length <10 )
		{alert("Please Enter Valid Phone No.");
			document.contactus_new.Phone.focus();
			 return false;
		}
			if (document.contactus_new.Phone.value!="")
		{
			  document.contactus_new.Phone.value=removeLeadingAndTrailingChar(document.contactus_new.Phone.value);
			  if(document.contactus_new.Phone.value.length=="0")
			     { 
					alert("Enter Phone No.");
					document.contactus_new.Phone.focus();
					return false;	
				 }
		}*/
	if (document.contactus_new.Email.value=="")
		{alert("Please Enter E-mail");
			document.contactus_new.Email.focus();
			 return false;
		}
	if (document.contactus_new.Email.value!="" && !validemail(document.contactus_new.Email.value))
		{ 
			alert("Please Enter Valid E-mail");
			document.contactus_new.Email.focus();
			return false;		
		}
		if (document.contactus_new.Street.value=="")
		{alert("Please Enter Street");
			document.contactus_new.Street.focus();
			 return false;
		}
				if (document.contactus_new.Street.value!="")
		{
			  document.contactus_new.Street.value=removeLeadingAndTrailingChar(document.contactus_new.Street.value);
			  if(document.contactus_new.Street.value.length=="0")
			     { 
					alert("Please Enter Street");
					document.contactus_new.Street.focus();
					return false;	
				 }
		}
	if (document.contactus_new.City.value=="")
		{alert("Please Enter City");
			document.contactus_new.City.focus();
			 return false;
		}
				if (document.contactus_new.City.value!="")
		{
			  document.contactus_new.City.value=removeLeadingAndTrailingChar(document.contactus_new.City.value);
			  if(document.contactus_new.City.value.length=="0")
			     { 
					alert("Please Enter City");
					document.contactus_new.City.focus();
					return false;	
				 }
		}
		if (document.contactus_new.State.selectedIndex=="0")
		{
			alert("Please Select State");
			document.contactus_new.State.focus();
			 return false;
		}
		if (document.contactus_new.Zip.value=="" || isNaN(document.contactus_new.Zip.value))
		{
			alert("Please Enter Zip");
			document.contactus_new.Zip.focus();
			return false;
		}
		document.contactus_new.Zip.value=removeLeadingAndTrailingChar(document.contactus_new.Zip.value);
		if (document.contactus_new.Zip.value.length <5)
		{
			alert("Please Enter Valid Zip");
			document.contactus_new.Zip.focus();
			 return false;
		}
		if(! zipFormatCheck(document.contactus_new.Zip)) return false;
		/*if (document.contactus_new.Zip.value!="")
		{
			  document.contactus_new.Zip.value=removeLeadingAndTrailingChar(document.contactus_new.Zip.value);
			  if(document.contactus_new.Zip.value.length=="0")
			     { 
					alert("Enter Zip");
					document.contactus_new.Zip.focus();
					return false;	
				 }
		}
 */
	
	return true;
	}
	
	
	
	function validate5(){
	
		if (document.contactus_contact.first_name.value=="")
		{alert("Please Enter First Name");
			document.contactus_contact.first_name.focus();
			 return false;
		}
		if (document.contactus_contact.first_name.value!="")
		{
			  document.contactus_contact.first_name.value=removeLeadingAndTrailingChar(document.contactus_contact.first_name.value);
			  if(document.contactus_contact.first_name.value.length=="0")
			     { 
					alert("Please Enter First Name");
					document.contactus_contact.first_name.focus();
					return false;	
				 }
		}
		
		if (document.contactus_contact.last_name.value=="")
		{alert("Please Enter Last Name");
			document.contactus_contact.last_name.focus();
			 return false;
		}
		if (document.contactus_contact.last_name.value!="")
		{
			  document.contactus_contact.last_name.value=removeLeadingAndTrailingChar(document.contactus_contact.last_name.value);
			  if(document.contactus_contact.last_name.value.length=="0")
			     { 
					alert("Please Enter Last Name");
					document.contactus_contact.last_name.focus();
					return false;	
				 }
		}
		
		
		if (document.contactus_contact.company.value=="")
		{alert("Please Enter Dealership");
			document.contactus_contact.company.focus();
			 return false;
		}
			if (document.contactus_contact.company.value!="")
		{
			  document.contactus_contact.company.value=removeLeadingAndTrailingChar(document.contactus_contact.company.value);
			  if(document.contactus_contact.company.value.length=="0")
			     { 
					alert("Please Enter Dealership");
					document.contactus_contact.company.focus();
					return false;	
				 }
		}
		
		document.contactus_contact.Phone1.value=removeLeadingAndTrailingChar(document.contactus_contact.Phone1.value);	
	document.contactus_contact.Phone2.value=removeLeadingAndTrailingChar(document.contactus_contact.Phone2.value);	
	document.contactus_contact.Phone3.value=removeLeadingAndTrailingChar(document.contactus_contact.Phone3.value);	
	if(isNaN(document.contactus_contact.Phone1.value))
		{
			alert("Phone should be Numeric");	
			document.contactus_contact.Phone1.select();
			return false;
		}
	if(isNaN(document.contactus_contact.Phone2.value))
		{
			alert("Phone should be Numeric");	
			document.contactus_contact.Phone2.select();
			return false;
		}
	if(isNaN(document.contactus_contact.Phone3.value))
		{
			alert("Phone should be Numeric");	
			document.contactus_contact.Phone3.select();
			return false;
		}		


		if (document.contactus_contact.Phone1.value.length<3)
		{
			alert("Please Enter Phone");
			document.contactus_contact.Phone1.focus();
			return false;
		}
		if (document.contactus_contact.Phone2.value.length<3)
		{
			alert("Please Enter Phone");
			document.contactus_contact.Phone2.focus();
			return false;
		}
		if (document.contactus_contact.Phone3.value.length<4)
		{
			alert("Please Enter Phone");
			document.contactus_contact.Phone3.focus();
			return false;
		}	
		if(document.contactus_contact.Phone1.value.length==3 &&document.contactus_contact.Phone2.value.length==3 && document.contactus_contact.Phone3.value.length==4) {
			document.contactus_contact.phone.value=document.contactus_contact.Phone1.value+document.contactus_contact.Phone2.value+document.contactus_contact.Phone3.value;
			
		}
		
	if (document.contactus_contact.email.value=="")
		{alert("Please Enter E-mail");
			document.contactus_contact.email.focus();
			 return false;
		}
	if (document.contactus_contact.email.value!="" && !validemail(document.contactus_contact.email.value))
		{ 
			alert("Please Enter Valid E-mail");
			document.contactus_contact.email.focus();
			return false;		
		}
		
		if (document.contactus_contact.street.value=="")
		{alert("Please Enter Street");
			document.contactus_contact.street.focus();
			 return false;
		}
			if (document.contactus_contact.street.value!="")
		{
			  document.contactus_contact.street.value=removeLeadingAndTrailingChar(document.contactus_contact.street.value);
			  if(document.contactus_contact.street.value.length=="0")
			     { 
					alert("Please Enter Street");
					document.contactus_contact.street.focus();
					return false;	
				 }
		}
	if (document.contactus_contact.city.value=="")
		{alert("Please Enter City");
			document.contactus_contact.city.focus();
			 return false;
		}
				if (document.contactus_contact.city.value!="")
		{
			  document.contactus_contact.city.value=removeLeadingAndTrailingChar(document.contactus_contact.city.value);
			  if(document.contactus_contact.city.value.length=="0")
			     { 
					alert("Please Enter City");
					document.contactus_contact.city.focus();
					return false;	
				 }
		}
	if (document.contactus_contact.state.selectedIndex=="0")
		{alert("Please Select State");
			document.contactus_contact.state.focus();
			 return false;
		}
		if (document.contactus_contact.zip.value=="" || isNaN(document.contactus_contact.zip.value))
		{alert("Please Enter Zip");
			document.contactus_contact.zip.focus();
			 return false;
		}
		if (document.contactus_contact.zip.value.length <5)
		{alert("Please Enter Valid Zip");
			document.contactus_contact.zip.focus();
			 return false;
		}
				if (document.contactus_contact.zip.value!="")
		{
			  document.contactus_contact.zip.value=removeLeadingAndTrailingChar(document.contactus_contact.zip.value);
			  if(document.contactus_contact.zip.value.length=="0")
			     { 
					alert("Enter Zip");
					document.contactus_contact.zip.focus();
					return false;	
				 }
		}
 
	if (document.contactus_contact.description.value=="")
		{alert("Please Enter Comments");
			document.contactus_contact.description.focus();
			 return false;
		}
				if (document.contactus_contact.description.value!="")
		{
			  document.contactus_contact.description.value=removeLeadingAndTrailingChar(document.contactus_contact.description.value);
			  if(document.contactus_contact.description.value.length=="0")
			     { 
					alert("Please Enter Comments");
					document.contactus_contact.description.focus();
					return false;	
				 }
		}
	return true;
	}
	
function makePhoneFormat(obj) {
	if(obj.value!="") {	
		objVal = obj.value.replace(/[\s\(\)\-]/g , '');	
		obj.value = objVal;
		//alert(parseInt(objVal,10));
		if(parseInt(objVal,10) == 0) obj.value='';
		if(obj.value.length == 10) {
			str1 = objVal.substring(0,3);
			str2 = objVal.substring(3,6);
			str3 = objVal.substring(6,10);
//			var str = '('+ str1 +') '+ str2 + '-' + str3 ;
			var str = ''+str1+str2+str3 ;
			obj.value = str;
		}
		else {
			//alert('Invalid Phone Number');  
		}
	}
	return true;
}
function checkValidPhoneNumber(obj) {
	var num = "0123456789()- ";
	if(obj.value!="") {	
		var objVal = obj.value;
		var newVal=objVal;
		var objLen = obj.value.length;
		for(var i=objLen-1;i>=0;i--) {
			var check = objVal.substring(i,i+1);
			if(num.indexOf(check) == -1) {
				newVal = obj.value.substring(0,i);
			}
		}
		obj.value  = newVal;
	}
	return true;
}

function checkValidZip(obj) {
	var num = "0123456789 ";
	if(obj.value!="") {	
		var objVal = obj.value;
		var newVal=objVal;
		var objLen = obj.value.length;
		for(var i=objLen-1;i>=0;i--) {
			var check = objVal.substring(i,i+1);
			if(num.indexOf(check) == -1) {
				newVal = obj.value.substring(0,i);
			}
		}
		obj.value  = newVal;
	}
	return true;
}

function phoneFormatCheck(obj, dispName) {
	//regExp = /^\([0-9]{3,3}\)\s{1,1}[0-9]{3,3}\-[0-9]{4,4}$/;
	regExp = /^[0-9]{10,10}$/;
	if (regExp.test(obj.value)) return true;
	else 
	{
		alert('Enter Valid '+ dispName);
		obj.focus();
		return false;
	}
}

function zipFormatCheck(obj) {
//	alert(parseInt(obj.value));
	if(parseInt(obj.value)==0) obj.value='';
	regExp = /^[0-9]{5,5}$/;
	if (regExp.test(obj.value)) return true;
	else 
	{
		alert('Enter Valid Zip Code');
		obj.focus();
		return false;
	}
}