

var myWind = "";
function quickContactValidate()
{ 
	if(!document.cookie) 
	{
		alert("For security/anti spam reasons, this form requires cookies.");
		return false;
	}	
	if(window.document.quickContactForm.v_personName.value.length < 2)
	{	alert("Please enter a valid name (at least 2 letters).");
		window.document.quickContactForm.v_personName.focus(); return false;
	}
	
	if(window.document.quickContactForm.v_email.value == '')
	{	alert("Please enter a valid email address.");
		window.document.quickContactForm.v_email.focus(); return false;
	}
	if (!(isValidMail(window.document.quickContactForm.v_email.value)))
	{	alert("Please enter a valid email address");
		window.document.quickContactForm.v_email.focus(); return false;
	}
	if(window.document.quickContactForm.v_phone.value == '')
	{	alert("Please enter a valid phone number (xxx-xxx-xxxx)");
		window.document.quickContactForm.v_phone.focus(); return false;
	}
//	if(!isUSPhoneNumber(window.document.quickContactForm.v_phone.value))
	if(!checkPhone(window.document.quickContactForm.v_phone.value))
	{	alert("Please enter a valid phone number (xxx-xxx-xxxx).");
		window.document.quickContactForm.v_phone.focus(); return false;
	}
	/*
	if(window.document.quickContactForm.v_code.value == '')
	{	alert("Please enter the correct anti spam security code.");
		window.document.quickContactForm.v_code.focus(); return false;
	}
	*/
	if(window.document.quickContactForm.t_message.value == '')
	{	alert("Please Enter Message in the Message Box.");
		window.document.quickContactForm.t_message.focus(); return false;
	}
	
	
	if(document.quickContactForm.windowCheck.value=='Open')
	{	
		//alert(myWind.name+'check');
		alert("Please enter the anti spam security code.");
		myWind.focus();
		myWind.document.quickContactForm.txtActivation.focus();
		//alert(myWind);
		 return false;
	}	
	if (myWind == "" || myWind.closed || myWind.name == undefined) 
	{
		//alert(myWind.name+'checktrue');
		var activationcode=document.quickContactForm.activationcode.value;
		var sessionid=document.quickContactForm.sessionid.value;
		document.quickContactForm.windowCheck.value='Open';
	myWind = window.open('buttonFinal.php?activationcode='+activationcode+'&sessionid='+sessionid,'_blank','height=210, width=550, left=350, top=300, menubar=no');
		return false;
	} 
	else
	{
		//alert(myWind.name+'checkfalse');
		alert("Please enter the anti spam security code.");
		myWind.focus();
		//alert(myWind);
		return false;
		
	}
	
	return true;


	
}

function confirmEmailForSubscription()
{	with(window.document.newsletterSubsForm)
	{	if (v_email.value == "")	
		{	alert("Enter your Email to subscribe to our Mailing List");
			v_email.focus(); return false;
		}
		
		return true;
	}
}


function trim( instr ) {
    	var reFirst = /\S/;		// regular expression for first non-white char
    	var reLast = /\s+$/;	// regular expression for first white char after last non-white char
    	var firstChar = instr.search(reFirst);
    	var lastChar = instr.search(reLast);
    	
    	if( lastChar == -1 ) 
			lastChar = instr.length;    	
    	outstr = instr.substring( firstChar, lastChar );
    	return outstr;
}
function checkBlank(field,name)
{
	if(trim(field.value) == "")
	{	
		field.focus();
		if(name != null)
			alert(name);//+" can not be left blank.");
		else
			alert("This field can not be left blank.");

		field.value = "";
		field.focus();
		return false;
	}
	return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
	
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkPhone(strPhone){
var validWorldPhoneChars = "0123456789-+ ";
if (strPhone.length < 10)
return false;

s=stripCharsInBag(strPhone,validWorldPhoneChars);
if (s.length == 0)
	return true;
else 
	return false;
}
