function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_swapImgRestore() { //v3.0
  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() { //v3.0
  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_findObj(n, d) { //v4.01
  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_swapImage() { //v3.0
  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 clearform(which){
	if (which.value=="email")
	which.value='' 
	if (which.value=="zip")
	which.value='' 
}

function openPopup(width, height, url)
{
	var options = "toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=1, resizable=0, width=" + width + ", height=" + height;
	var newWin = open(url, "", options);
}

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;
	
function DoValidation(form, validatePhone)
{	
	var frmemail = form;

	if (frmemail.first_name.value == "")
	{
		alert("Please enter your first name");
		frmemail.first_name.select();
		frmemail.first_name.focus();
		return false;
	} 
	if (frmemail.last_name.value == "")
	{
		alert("Please enter your last name");
		frmemail.last_name.select();
		frmemail.last_name.focus();
		return false;
	}
	if (frmemail.company.value == "")
	{
		alert("Please enter your company name");
		frmemail.company.select();
		frmemail.company.focus();
		return false;
	}
	if (!(checkemail(frmemail.email.value)))
	{		
		alert("Please enter a valid email");
		frmemail.email.select();
		frmemail.email.focus();
		return false;	
	} 
	if (validatePhone)
	{
		if (frmemail.phone.value == "")
		{
			alert("Please enter your phone");
			frmemail.phone.select();
			frmemail.phone.focus();
			return false;
		}
		if (!(checkInternationalPhone(frmemail.phone.value))){
			alert("Please Enter a Valid Phone Number")
			frmemail.phone.value=""
			frmemail.phone.focus()
			return false
		}
	}
	if (frmemail.city.value == "")
	{
		alert("Please enter your city");
		frmemail.city.select();
		frmemail.city.focus();
		return false;
	}
	if (frmemail.state.value == "")
	{
		alert("Please enter your state");
		frmemail.state.select();
		frmemail.state.focus();
		return false;
	}
	return true;
}	

function checkemail(strMail)
{
	var str=strMail;
	var filter=/^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(str))
		testresults=true
	else
		testresults=false
	return (testresults)
}

function ValidZipCode(ZipCode)
{
	var stringValue = new String(ZipCode);
	var stringLength = stringValue.length;
	testresults=true;
	
	if (stringLength!=5) {
		testresults=false
	}
	for (var i = 0; i < stringLength; i++)
	{			
		value = stringValue.charAt(i);
		if (!((value >= 0) && (value <=9)))
		{
			testresults=false
		}
	}
	return (testresults);
}

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    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 checkInternationalPhone(strPhone){
	var s = stripCharsInBag(strPhone, validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}
