
//SETTING UP OUR POPUP  
//0 means disabled; 1 means enabled;  
 var popupStatus = 0;  

//loading popup with jQuery magic!  

function loadPopup(id){  
  //loads popup only if it is disabled  
 // alert(id);
  if(popupStatus==0){ 

 $(".backgroundPopup").css({   
"opacity":"0.5"  
 }); 
  
$(".backgroundPopup").fadeIn("slow"); 
  $(id).fadeIn("slow");  
 popupStatus = 1;  
//  alert($(".backgroundPopup"));
 }  
 }  
 
//disabling popup with jQuery magic!  
 function disablePopup(id){  
 //disables popup only if it is enabled  
 //alert(id);
  if(popupStatus==1){  
$(".backgroundPopup").fadeOut("slow");  
$(".popupContact").fadeOut("slow");  
 popupStatus = 0;  
  }  
 }  
 
//centering popup  
  function centerPopup(id){  
  //request data for centering  
  var windowWidth = document.documentElement.clientWidth;  
  var windowHeight = document.documentElement.clientHeight;  
  var popupHeight = $(id).height();  
  var popupWidth = $(id).width();  
  //alert(popupHeight);
  //centering  
  $(".popupContact").css({  
  "position": "absolute",  
  "top": windowHeight/2-popupHeight/2,  
  "left": windowWidth/2-popupWidth/2  
  });  
  //only need force for IE6  
    
  //$(".backgroundPopup").css({  
 // "height": windowHeight  
 // });  
}  

function validalphabet(e) 
	{
	var mykey = window.event ? e.keyCode : e.which; 
	
		if (mykey==46 || mykey==126) 
		{ 
			return false; 
		}
		
		if (((mykey > 32 && mykey < 48) || (mykey > 57 && mykey < 65) || (mykey > 90 && mykey < 97) || (mykey > 45 && mykey <= 57)))
		{ 
			return false; 
		}
	return true;
}

function myvalidnumber(e)
{
var mykey = window.event ? e.keyCode : e.which;
		if ((mykey <= 47 || mykey > 57) && mykey !=13 && mykey !=0 && mykey != 8) 
			{
//			alert ("Enter number only");
		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 isValidFirstName(FirstName)
{
	FirstName.value=removeLeadingAndTrailingChar(FirstName.value);
	if ((FirstName.value==""))
		{
			alert("Enter First Name ");
			FirstName.focus();
			return false;
		}
return true;
}
  // Last Name Validation
function isValidLastName(LastName)
{
	LastName.value=removeLeadingAndTrailingChar(LastName.value);
	if ((LastName.value==""))
		{
			alert("Enter Last Name ");
			LastName.focus();
			return false;

		}
return true;
}

// Email Validation

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 isValidEmail(Email)
{
	if (Email.value=="")
	{
		alert("Enter E-mail Id");
		Email.focus();
		return false;
	}

	if (Email.value!="" && !validemail(Email.value))
	{ 
		alert("Enter Valid E-mail Id");
		Email.focus();
		return false;		
	}
return true;
}

function isValidMPhone(ph1,phtype)
 {
	if (phtype == undefined)  { phtype =' Phone '  ; }
	ph1.value=removeLeadingAndTrailingChar(ph1.value);	


	if(isNaN(ph1.value))
		{
			alert(phtype +" should be Numeric");	
			ph1.select();
			return false;
		}
	
	if (ph1.value.length<10)
	{
		alert("Enter " + phtype);
		ph1.focus();
		return false;
	}
	
	var p1 = /\d{3}/g;
	var p2 = /\d{4}$/g;	
	var resultPhone="(" +p1.exec(ph1.value)+") "
	p1.lastIndex;
	var resultPhone = resultPhone+p1.exec(ph1.value)+" - "+p2.exec(ph1.value);	
	document.getElementById('OffPhone').value= resultPhone;
return true;
 }

function isValidModel(Model)
{
		if ((Model.value==""))
		{
			alert("Please select Model");
			Model.focus();
			return false;

		}
return true;
}


function validateMoreInfoNewFormat(thisForm, id)
{	
	if(!(isValidFirstName(thisForm.FirstName))) return false;
	if(!(isValidLastName(thisForm.LastName))) return false;
	if(!(isValidEmail(thisForm.Email))) return false;
	if(!(isValidMPhone(thisForm.Phone,' Phone '))) return false;
	if(!(isValidModel(thisForm.Model))) return false;
	return true;
}

