///////////////////////// COMMON JAVASCRIPT FILE ////////////////////////////
//																		   //
// 	  COMMON JAVASCRIPT FILE FOR ALL THE SCRIPTS USED ALLOVER THE SITE     //
//																		   //
/////////////////////////////////////////////////////////////////////////////

//for Home Page

///////////////////////////////////////Setting Position of layers//////////////////

function setPosition(){
	iWidth = (!navigator.appName=="Netscape")?window.innerWidth:document.body.clientWidth; 
	iHeight = (!navigator.appName=="Netscape")?window.innerHeight:document.body.clientHeight; 
	 
	if((iWidth-1000) % 2 == 0){
	x=1000;
	}else
	{
	x=1000;
	}
	 
	if(iWidth>1000){
	 if(!navigator.appName=="Netscape"){
	  pos= (iWidth-x) / 2;
	 }else{
	  pos= (iWidth-x) / 2;
	 }
	}else
	{
	 pos= 0;
	}
		
		///////////////////////////////////////

		document.getElementById('newcars').style.left=pos+0;
		document.getElementById('preownedcars').style.left=pos+142;
		document.getElementById('onlinespecials').style.left=pos+250;
		document.getElementById('partsservice').style.left=pos+382;
		document.getElementById('research').style.left=pos+503;
		document.getElementById('finance').style.left=pos+598;
		document.getElementById('aboutus').style.left=pos+683;
		document.getElementById('flash_file1').style.left=pos+698;
}

function setPositionHome(){
	iWidth = (!navigator.appName=="Netscape")?window.innerWidth:document.body.clientWidth; 
	iHeight = (!navigator.appName=="Netscape")?window.innerHeight:document.body.clientHeight; 
	
	 
	if((iWidth-1000) % 2 == 0){
	x=1000;
	}else
	{
	x=1000;
	}
	 
	if(iWidth>1000){
	 if(!navigator.appName=="Netscape"){
	  pos= (iWidth-x) / 2;
	 }else{
	  pos= (iWidth-x) / 2;
	 }
	}else
	{
	 pos= 0;
	}
		
		///////////////////////////////////////

		document.getElementById('newcars').style.left=pos+0;
		document.getElementById('preownedcars').style.left=pos+173;
		document.getElementById('onlinespecials').style.left=pos+284;
		document.getElementById('partsservice').style.left=pos+423;
		document.getElementById('research').style.left=pos+545;
		document.getElementById('finance').style.left=pos+643;
		document.getElementById('aboutus').style.left=pos+735;
		document.getElementById('TNails').style.left=pos+38;
		document.getElementById('TNails1').style.left=pos+38;

}

function validnumber1()
	{
		if ((event.keyCode <= 47 || event.keyCode > 57) && event.keyCode !=13) 
			event.returnValue = false;
	}
function validnumber()
	{
			if ((event.keyCode <= 47 || event.keyCode > 57) && event.keyCode !=13) 
			event.returnValue = false;
	}

function alphanumeric1()
	{
	
	if (event.keyCode==46 || event.keyCode==126) 
			event.returnValue = false; 
		if ((event.keyCode >=33 && event.keyCode <=47) || (event.keyCode >=58  &&  event.keyCode <=64) || (event.keyCode >=91 && event.keyCode <=96 ) ||(event.keyCode >=123 && event.keyCode <=127 ) ) 
			event.returnValue = false; 
	}
function hideMe(obj){
	obj.style.visibility='hidden';
	return true;
}

function showMe(obj){
	obj.style.visibility='visible';
	return true;
}

/////////////////////////////////////////////////////////////////////////////////

var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
			// Handle all the the FSCommand messages in a Flash movie
			function fscommand_DoFSCommand(command, args) 
			{
				document.DetailedInfo.ExtColor.value=args;
				document.DetailedInfo.ExtColor1.value=args;
				document.DetailedInfo.IntColor.value=command;
			}

// Hook for Internet Explorer 
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<SCRIPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('Sub fscommand_FSCommand(ByVal command, ByVal args)\n');
	document.write('  call fscommand_DoFSCommand(command, args)\n');
	document.write('end sub\n');
	document.write('</SCRIPT\> \n');
}

function MM_reloadPage(init) {  // reloads the window if Nav4 resized.
	if (init==true) with (navigator) {
	  	if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    		document.MM_pgW=innerWidth; 
			document.MM_pgH=innerHeight; 
			onresize=MM_reloadPage; 
		}
	}
  	else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) 
		location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { // gets the object by its id.
	var p,i,x;  
	if(!d) 
		d=document; 
	if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; 
		n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all) 
		x=d.all[n]; 
	for (i=0;!x&&i<d.forms.length;i++) 
		x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
		x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) 
		x=d.getElementById(n); 
	return x;
}

function MM_showHideLayers() { // hides or shows layers.
  	var i,p,v,obj,args=MM_showHideLayers.arguments;
  	for (i=0; i<(args.length-2); i+=3) 
		if ((obj=MM_findObj(args[i]))!=null) { 
			v=args[i+2];
    		if (obj.style) { 
				obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
			}
    		obj.visibility=v;
		}
}

function MM_swapImgRestore() { // restores the mouseover images.
  	var i,x,a=document.MM_sr; 
	for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) 
		x.src=x.oSrc;
}

function MM_preloadImages() { // preloads the mouseover images.
  	var d=document; 
	if(d.images) { 
		if(!d.MM_p) 
			d.MM_p=new Array();
    	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; 
		for(i=0; i<a.length; i++)
    		if (a[i].indexOf("#")!=0) { 
				d.MM_p[j]=new Image; 
				d.MM_p[j++].src=a[i];
			}
	}
}

function MM_swapImage() { // swaps the images for mouse over effect.
  	var i,j=0,x,a=MM_swapImage.arguments; 
	document.MM_sr=new Array; 
	for(i=0;i<(a.length-2);i+=3)
   		if ((x=MM_findObj(a[i]))!=null)	{
			document.MM_sr[j++]=x; 
			if(!x.oSrc) 
				x.oSrc=x.src; 
			x.src=a[i+2];
		}
}

function MM_openBrWindow(theURL,winName,features) { // pop opens a browser window
  	window.open(theURL,winName,features);
}

function dot(obj)
{
	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;
	}
}

//////////////////////////// Data Entry Validation /////////////////////////////////

function alphanumeric(obj)
{

if (event.keyCode==46 || event.keyCode==126 || event.keyCode==32) 
		event.returnValue = false; 
	if ((event.keyCode >=33 && event.keyCode <=47) || (event.keyCode >=58  &&  event.keyCode <=64) || (event.keyCode >=91 && event.keyCode <=96 ) ||(event.keyCode >=123 && event.keyCode <=127 ) ) 
		event.returnValue = false; 

}

function a()
{
alert(event.keyCode);	
}

function a(x,z)
{
var y=document.getElementById(z).value
	if (x==46 || x==126) 
		event.returnValue = false; 
	if (((x > 32 && x < 48) || (x > 57 && x < 65) || (x > 90 && x < 97) || (x > 45 && x <= 57)))
		document.getElementById(z).value=y.substring(0,y.length -1);
		
}

function validalphabet(FinanceForm)
{
	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(FinanceForm)
{	
	if(event.keyCode==47 || event.keyCode==126) 
		event.returnValue = false;
	if ((event.keyCode <= 45 || event.keyCode > 57) && event.keyCode !=13) 
		event.returnValue = false; 
}

function validPhoneCheck()
{
	if(event.keyCode == 46) 
		event.returnValue = false;
}

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 tabvalidatePhone(phfield1,phfield2)
{
	if(document.getElementById(phfield1).value.length==3) 
		document.getElementById(phfield2).focus();
}


//////////////////////////// Contact Us Validation /////////////////////////////////

function validatecontactus(Contactus)
{
	if(Contactus.FirstName.value=="")
		{
			alert("Enter First Name");
			Contactus.FirstName.focus();
			return false;
		}
		
	if (Contactus.FirstName.value!="")
	{
		  Contactus.FirstName.value=removeLeadingAndTrailingChar(Contactus.FirstName.value);
		  if(Contactus.FirstName.value.length=="0")
			 { 
				alert("Enter First Name");
				Contactus.FirstName.focus();
				return false;	
			 }
	}
		
	if(Contactus.LastName.value=="")
		{
			alert("Enter Last Name");
			Contactus.LastName.focus();
			return false;
		}
	
	if (Contactus.LastName.value!="")
		{
		  Contactus.LastName.value=removeLeadingAndTrailingChar(Contactus.LastName.value);
			  if(Contactus.LastName.value.length=="0")
				 { 
					alert("Enter Last Name");
					Contactus.LastName.focus();
					return false;	
				 }
	}
	if (Contactus.Designation.value!="")
	{
		  Contactus.Designation.value=removeLeadingAndTrailingChar(Contactus.Designation.value);
	}	
	if (Contactus.Company.value!="")
	{
		  Contactus.Company.value=removeLeadingAndTrailingChar(Contactus.Company.value);
	}
	if (Contactus.Street.value!="")
	{
		  Contactus.Street.value=removeLeadingAndTrailingChar(Contactus.Street.value);
	}		
	if (Contactus.City.value!="")
	{
		  Contactus.City.value=removeLeadingAndTrailingChar(Contactus.City.value);
	}	
	if (Contactus.State.value!="")
	{
		  Contactus.State.value=removeLeadingAndTrailingChar(Contactus.State.value);
	}
	Contactus.Zip.value=removeLeadingAndTrailingChar(Contactus.Zip.value);		
	
	if(Contactus.OffPhone.value=="")
		{
			alert("Enter Telephone Name");
			Contactus.OffPhone.focus();
			return false;
		}
	if(isNaN(Contactus.OffPhone.value))
		{
			alert("Telephone should be Numeric");	
			Contactus.OffPhone.select();
			return false;
		}
	if(isNaN(Contactus.Fax.value))
		{
			Contactus.Fax.value="";
		}
	if (Contactus.Email.value=="")
	{
		alert("Enter E-mail");
		Contactus.Email.focus();
		return false;
	}
	if (Contactus.Email.value!="" && !validemail(Contactus.Email.value))
		{ 
			alert("Enter Valid E-mail");
			Contactus.Email.focus();
			return false;		
		}
	if (Contactus.areaInterest.value!="")
	{
		  Contactus.areaInterest.value=removeLeadingAndTrailingChar(Contactus.areaInterest.value);
	}
	if (Contactus.Comments.value!="")
	{
		  Contactus.Comments.value=removeLeadingAndTrailingChar(Contactus.Comments.value);
	}
	return true;
}

function validateresumeUpload(resumeUpload)
{
	
	if (resumeUpload.mailTo.selectedIndex==0)
	{
		alert("Select Location");
		resumeUpload.mailTo.focus();
		return false;
	}
	if (resumeUpload.mailFrom.value=="")
	{
		alert("Enter E-mail");
		resumeUpload.mailFrom.focus();
		return false;
	}
	if (resumeUpload.mailFrom.value!="" && !validemail(resumeUpload.mailFrom.value))
		{ 
			alert("Enter Valid E-mail");
			resumeUpload.mailFrom.focus();
			return false;		
		}
	if(resumeUpload.uploadfile.value=="")
		{
			alert("Please Attach Resume");
			resumeUpload.uploadfile.focus();
			return false;
		}
return true;
}

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 checkNumber(Ttemp,objectname)
{ 
///Added by Amit to add percentage symbol

	var name="";
	var i;
	name=name+Ttemp.substring(i,i+1);
	if( !((Ttemp.substring(i,i+1) >= 0) && (Ttemp.substring(i,i+1) <= 9)) && !(Ttemp.substring(i,i+1)=='%') && !(Ttemp.substring(i,i+1)=='.'))
		{
		 no=name.length-1;
		}
	else if(objectname=="loaninterest" && !(Ttemp.substring(Ttemp.length-1)=='%') )
		{
			document.loan.loaninterest.value = Ttemp + '%' ;
		}
			
 	 return true;
}

/////The script for showing menu over input components//////

 function hideiframe(d3)
 {
 var d1=document.getElementById(d3);
 d1.style.display='none';
 }
function showiframe(d1,d2)
 {
 var div=document.getElementById(d1);
 var frame=document.getElementById(d2);
    
    frame.style.width = div.offsetWidth;
    frame.style.height = div.offsetHeight;
    frame.style.top = div.style.top;
    frame.style.left = div.style.left;
    var brow=navigator.appName;
	if(brow=="Netscape")
	{
		frame.style.display = 'none';
	} else if(brow=="Microsoft Internet Explorer") {
	frame.style.display = 'block';	
	}
 }
 
 /////////////the code ends here/////////////
 

