validZIP = /^\d{5}(-\d{4})?$/
function validate1(e) {
	var keynum;
	if(window.event) {
		keynum = e.keyCode;
	} else if(e.which) {
		keynum = e.which;
	}
	if (e.ctrlKey || keynum == null || keynum < 32) {
		return true;
	}
	var validchars =  /^[\w\s;.\[\]\-'@]*$/i;
	var keychar = String.fromCharCode(keynum);
	return validchars.test(keychar);
}
function validate2(form, wait, contID) {
	var res= (/^(((((\w+ )+|(\((\w+( \w+)?)+\) ?)|(\'(\w+( \w+)?)+\' ?))?([\w-]+(?:\.[\w-]+)*))((@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?))|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?)))( *\; *\b|( *;?$)))+$/i).test(form['email'].value)
	if (!res) alert("Invalid email format!")
	if (res && wait)
		ShowWaitIcon(form, contID);
	return res;
}
function validate_form(form)
{
	var error=""
	if (!form['firstName'].value)
		error += "First Name is required.<br/>"
	if (!form['lastName'].value)
		error += "Last Name is required.<br/>"
	if (!validZIP.test(form['zip'].value))
		error += "Please enter a valid ZIP code (Example: 12345 or 12345-1234).<br/>"
	if (error)
	{
		var er = document.getElementById("error");
		er.innerHTML = error;
		er.style.display="block";
	}
	return !error
}
ShowWaitIcon = function(form, aContainerID)
{
	var container = typeof(aContainerID)=="Object" ? aContainerID : ((aContainerID && document.getElementById(aContainerID)) || form.parentNode.parentNode);
	var chld=container.childNodes, chldStyle
	for (var i=0; i < chld.length; ++i)
		if ((chldStyle=chld[i].style) &&typeof(chldStyle.visibility)!="undefined")
			chldStyle.visibility="hidden"
	container.style.backgroundColor="#ffffff"
	container.style.position="relative"
	var newDiv=document.createElement("div");
		newDiv.style.cssText="top: 0px; left: 0px; text-align: center; padding-top: " + (container.offsetHeight-32)/2 + "px; padding-left: "+ (container.offsetWidth-32)/2+"px;"
	var img =document.getElementById("waitImage")
	img.width=32;
	img.height=32;
	img.style.display="block"
	newDiv.appendChild(img)
	container.appendChild(newDiv)
	newDiv.style.position = "absolute";
}
addEvent = function(aObj, aEvent, aFunction)
{
	if (typeof(aFunction)!="function")
		aFunction = new Function(aFunction);
	if ( aObj.addEventListener )
		aObj.addEventListener(aEvent, aFunction, false);
	else if ( aObj.attachEvent )
		aObj.attachEvent("on"+aEvent, aFunction );
}

function loadImage(aPath) {
	var img=document.createElement("IMG")
	with (img)
	{
		src = aPath
		style.display="none"
	}
	document.body.appendChild(img)
}

preloadImage = function()
{
	var img=document.createElement("IMG")
	with (img)
	{
		id="waitImage"
		alt="Processing..."
		src = "Images/loading.gif"
		style.display="none"
	}
	document.body.appendChild(img)
}
addEvent(window, "load", preloadImage)
selectItem=function(aId, aIndex)
{
	var o=document.getElementById(aId)
	if (o) o.selectedIndex = aIndex
}
/* DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/) */

// 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);
	if (isInteger(s) && s.length >= minDigitsInIPhoneNumber) {
		if (s <= 19999999999) // US phone numbers starting with 1
			return true;
		else
			return false;

	}

	return false;

}

function ValidatePhone(p_id, p_name, p_value) 
{
	return /^[^\d]*1?([-\.\+]?|\s*)\(?\d{3}\)?([\-\.\+]?|\s*)\d{3}([\-\.\+]?|\s*)\d{4}[\s]*$/.test(p_value.toString());
}