var __ZSVAL_JS__ = 1;

//// form validation scripts 
// Thanks H!
var alpha = /[^a-z]/ig;
var alphaNum =/[^a-z\-0-9]/ig;
var alphaNumPunc =/[^\w \- \. , \']/ig;
var num = /[^\d]/ig;
var _float = /[^\d*][\.\d*]?$/i;
var notNull = /[^\s]/ig;
var email = /^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z0-9]{2,}$/ig;
var URL = /(http:\/\/)?[a-zA-Z0-9\.-]+\.[A-Z0-9a-z\.]{2,}/ig;
var dte = /\d{1,2}\/\d{1,2}\/[20]?[\d{2}][ ]?[\d:ampm ]?/ig;
var img = /\.(gif|jp[e]?g)$/ig;
var nospace = /\s/g;

function charCheck(f,ty,m,doIt)
{
	var e = (doIt || !doIt) ? doIt : true;
	var f_type = null;
	var f_val = null;
	
	if (!e)
	{
		return e;
	}

	f_type = f.type;
	f_val = (f_type == "checkbox" || f_type == "select" || f_type == "radio") ? f[f.selectedIndex].value : f.value;

	switch (ty.toLowerCase())
	{
		case "alpha":
			e = (f_val.search(alpha) == -1) ? true : false;
			break;
			
		case "alphanum":
			e = (f_val.search(alphaNum) == -1) ? true : false;
			break;
		
		case "alphanumpunc":
			e = (f_val.search(alphaNumPunc) == -1) ? true : false;
			break;
			
		case "num":
			e = (f_val.search(num) == -1) ? true : false;
			break;
			
		case "float":
			e = (f_val.search(_float) == -1) ? true : false;
			break;
			
		case "notnull":
			e = (f_val.search(notNull) == -1) ? false : true;
			break;
			
		case "url":
			e = (f_val.match(URL) == null) ? false : true;
			break;
			
		case "email":
			e = (f_val.match(email) == null) ? false : true;
			break;
			
		case "date":
			e = (f_val.match(dte) == null) ? false : true;
			break;
			
		case "nospace":
			e = (f_val.match(nospace) == null) ? true : false;
			break;
			
		default:
			if (__DEBUG__)
			{
				alert ("charCheck was provided with a bogus type.");
			}
		
			return false;
	};

	if (!e)
	{
		if (ty == "date")
		{
			alert("The "+m+" you've entered is invalid.  \nPlease enter dates using the following format:\n\n\tMM/DD/YYYY");
		}
		else if (ty == "nospace")
		{
			alert ("Sorry, there are no spaces allowed in " + m + ".  Please remove all spaces and try again.");
		}
		else if (m != "" && m != "no")
		{
			var msg = (ty.toLowerCase() != "notnull") ? "The value you have entered for " + m + " is invalid.  Please re-enter this information." : "The " + m + " field is required.  Please correct this and resubmit.";
			alert(msg);
		}
		if (f_type != "hidden")
		{
			f.focus();
		}
	}

	return e;
}

function zipAuth (zip, country)
{
	var z = zip.value;
	var c = country;
	var zFit, zCountry, zMask;
	var procZip = "";

	if (c == 1) // USA
	{
		zFit = /\d{5}[\s-]?(\d{4})?/i;
		zCountry = "USA";
		zMask = "\t- #####\n\t- #####-####";
	}
	else if (c == 32) // canada
	{
		zFit = /\w\d\w([\s-]?)[0-9][a-zA-Z][0-9]/i;
		zCountry = "Canada";
		zMask = "\t- !#!-#!#";
	}
	else if (c == 60 || c == 143 || c == 218) // england, n.ireland, wales
	{
		zFit = /[\d\w]{3}[\s-]?[\d\w]{3}/i;
		zCountry = "England, Northern Ireland or Wales";
		zMask = "\t- XXX-XXX";
	}
	else if (c == 170) // scotland
	{
		zFit = /[\d\w]{2}[\s-]?[\d\w]{3}/i;
		zCountry = "Scotland";
		zMask = "\t- XX-XXX";
	}
	else if (c == 227) // australia
	{
		zFit = /[\d]{4,}/i;
		zCountry = "Australia";
		zMask = "\t- ####";
	}
	else
	{
		zFit = /[\d\w]+/i;
		zMask = "";
	}
	procZip = String(z.match(zFit));
	//alert(procZip);
	if (procZip == "" || procZip == "null")
	{
		msg = (zMask != "") ? "The postal code you have entered is incorrectly formatted\nfor "+zCountry+"  \n\nPlease enter your postal code in the following format:\n\n"+zMask+"\n\n where " : "The Postal Code field is required.\nPlease enter your postal code";
		if (zMask != "")
		{
			if (zMask.indexOf("X") > -1)
			{
				msg += "X can be either a letter or a number.";
			}
			else if (zMask.indexOf("!") > -1)
			{
				msg += "! represents a letter and # represents a number.";
			}
			else if (zMask.indexOf("!") == -1 && zMask.indexOf("X") == -1)
			{
				msg += "# represents a number.";
			}
		}
		alert(msg);
		zip.focus();
		return false;
	}

	zip.value = z.replace(/[^\w]/ig,"");

	return true;
}

function dateCheck(mm,dd,yyyy) {
  try {
    var test = new Date(yyyy,mm-1,dd);
    
    if (test.getMonth() != (mm-1) ||
        test.getFullYear() != yyyy ||
        test.getDate() != dd) {
      throw 1;
    }
  } catch (e) {
    return false;
  }
  
  return true;
}