<!--
// POP UP
var newWin = null;
function popUp(strURL, strType, strHeight, strWidth) {
if (newWin != null && !newWin.closed)
	newWin.close();
var strOptions="";
if (strType=="all"){
	strOptions="resizable,status,menubar,scrollbars,resizable,location,"+"height="+strHeight+",width="+strWidth;
	 }
else if (strType=="menu"){
	strOptions="toolbar,scrollbars,resizable,height="+strHeight+",width="+strWidth;
	 }
else if (strType=="coupon"){
	strOptions="resizable,height="+strHeight+",width="+strWidth;
	 }

newWin = window.open(strURL, 'newWin', strOptions);
newWin.focus();
}

// PHONE VALIDATION
// 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 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){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function ValidatePhone(){
	var Phone=document.frm.phone;
	var checkphone = true;
	if ((Phone.value==null)||(Phone.value=="")){
		Phone.focus()
		checkphone = false;
	}
	if (checkInternationalPhone(Phone.value)==false){
		Phone.focus()
		checkphone = false;
	}
	return checkphone
}

// EMAIL VALIDATION - VALIDATE
function validateEmail(email, msg, optional) {
if (!email.value && optional) {
	return true;
}

var emailPat = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/;

var matchArray=email.match(emailPat); 
if (matchArray==null) {
	return false; 
	email.focus();
	email.select();
} 
	return true;
}

//CLOSE PAGE
function closePage() {
	window.close();  
}

//PRINT PAGE
function printPage() {
	window.print();  
}

//EMAIL VALIDATION - SUBMIT
function emailSubmit(obj) {
submitflag = true;
	if (!validateEmail(obj.email.value)){
		notice = "> To sign up for the mailing list, you must enter a valid email address.\n";
		submitflag = false;
	}

	if (submitflag) {
		obj.submit();
	} else {
		alert(notice);
	}
}

// -->
<!--

// below modified from http://www.js-examples.com/
// ^ a great site for JS stuff
function fncSubmit(obj) {
	var req = obj.req_fields;
	var email_check = obj.email.value;
	var submitflag = true;
	var notice = "There was an error with your form:\n\n";
	if (req) {	
		//Means the required fields are present, let's check for values
		var arrFields = obj.req_fields.value.split("|");
		for(var x=0; x<=arrFields.length-1; x++) {
			var arrName = arrFields[x].split(",");
			// Now we create (or add to) the string that outputs the specific errors 
			// also set submitflag to false so that it doesn't get submitted
			var str = "if (obj."+arrName[0]+".value == '') { notice += '> "+arrName[1]+"\\n'; submitflag = false;}";
			eval(str);
		}
		if (submitflag) {
		// Means that there are no required fields missing
		// Now, if they want to be on the email list, let's make sure they included their valid email
			if (obj.nletter[0].checked && !validateEmail(email_check)){
				notice += "> To sign up for the mailing list you must enter a valid email address.\n";
				submitflag = false;
			}
		// Even if they don't want to be on the email list,
			else if (email_check.length>2 && !validateEmail(email_check)){
				notice += "> The email address you entered is invalid.\n";
				submitflag = false;
			} 
		//Now validate phone number
			if (ValidatePhone()==false) {
				notice += "> The phone number you entered is invalid or incomplete. Please use the format ###-###-####. Other valid characters are: ' + ( ) - '\n";
				submitflag=false;

			}
		}
		notice += "\nPlease check these errors and resubmit."
	} else {
		//Means there isn't a required fields parameter; keep going
	}
	if (submitflag) {
		obj.submit();
	} else {
		alert(notice);
	}
}
//-->
