
if (document.images) 
	cpbrowser = true;
else 
	cpbrowser = false;

emailValidateStr = "validateEmail(document.Request.email)";




function checkForm()
{
	if(! document.Request.name.type)
		document.Request.name.type = "text";
	if(! document.Request.mail1.type)
		document.Request.mail1.type = "text";
	if(! document.Request.mail2.type)
		document.Request.mail2.type = "text";
	if(! document.Request.city.type)
		document.Request.city.type = "text";
	if(! document.Request.state.type)
		document.Request.state.type = "text";
	if(! document.Request.zip.type)
		document.Request.zip.type = "text";
	if(! document.Request.phone.type)
		document.Request.phone.type = "text";
	
	
	
	if (!checkField(document.Request.name,''))
	{
		alert("Name is a required field");
		selectObj(document.Request.name);
		return false;
	}

	if (document.Request.country.value == "Other")
	{
		if (!checkField(document.Request.countryText,''))
		{
			alert("Country is a required field");
			selectObj(document.Request.countryText);
			return false;
		}
		
	}
	if (!checkField(document.Request.mail1,''))
	{
		alert("Mailing address is a required field");
		selectObj(document.Request.mail1);
		return false;
	}
	
	
	if (!checkField(document.Request.city,''))
	{
		alert("City is a required field");
		selectObj(document.Request.city);
		return false;
	}
	
	if (document.Request.country.value == "United States")
	{
		if (document.Request.state.value == "")
		{
			alert("State is a required field");
			selectObj(document.Request.state);
			return false;
		}
	
	}
	if (document.Request.country.value == "Canada")
	{
		if (document.Request.province.value == "")
		{
			alert("Province is a required field");
			selectObj(document.Request.province);
			return false;
		}
		
	}
	
	if (document.Request.country.value == "United States" )
	{
		if (!checkField(document.Request.zip,''))
		{
			alert("Zip code is a required field");
			selectObj(document.Request.zip);
			return false;
		}
		if (!IsNumeric(document.Request.zip))
		{
			alert("Zip code must be numeric");
			selectObj(document.Request.zip);
			return false;
		}
		if (!checkZip(document.Request.zip,''))
		{
			alert("The zip code must have the correct number of characters");
			selectObj(document.Request.zip);
			return false;
		}
	}
	
	if (document.Request.country.value == "Canada" )
	{
		if (!checkField(document.Request.zip,''))
		{
			alert("Postal code is a required field");
			selectObj(document.Request.zip);
			return false;
		}
		if (!IsNumeric(document.Request.zip))
		{
			alert("The postal code must be numeric");
			selectObj(document.Request.zip);
			return false;
		}
	}
	
	if (document.Request.country.value == "Other" )
	{
		if (!IsNumeric(document.Request.zip))
		{
			alert("The postal code must be numeric");
			selectObj(document.Request.zip);
			return false;
		}
	}
		
	if (!checkField(document.Request.phone,''))
	{
		alert("Phone number is a required field");
		selectObj(document.Request.phone);
		return false;
	}
	
	if (!IsNumeric(document.Request.phone))
	{
		alert("The phone number must be numeric");
		selectObj(document.Request.phone);
		return false;
	}
	
	if (document.Request.country.value == "United States")
	{
		if (!checkPhone(document.Request.phone,''))
		{
			alert("The phone number must have the correct number of characters");
			selectObj(document.Request.phone);
		
			return false;
		}
	}
	
	if (!checkSPD())
	{
		alert("At least one SPD must be selected");
		return false;
	}  
	
	if (document.Request.country.value == "United States" || document.Request.country.value == "Canada")
	{
		if (document.Request.mail2.value == "")
		{
			document.Request.FormID.value = "F499";
		}
		if (document.Request.mail2.value != "")
		{
			document.Request.FormID.value = "F499";
		}	
	}
	
	if (document.Request.country.value == "Other")
	{
		if (document.Request.mail2.value == "")
		{
			document.Request.FormID.value = "F500";
		}
		if (document.Request.mail2.value != "")
		{
			document.Request.FormID.value = "F500";
		}	
	}
	
	var count = document.Request.interests.length;
	var interests = "";
	for(var i = 0; i < count; i++)
	{
		if (document.Request.interests[i].checked)
		{
			interests = interests == "" ? document.Request.interests[i].value : interests + "\n" + document.Request.interests[i].value;
			
			
		}
		
	}
	document.Request.spds.value = interests;
	
	return true;
}


function removeBlanks(obj)
{
	for(var i = 0; i < obj.value.length - 1; i++)

	{
		obj.value = obj.value.replace(" ", "");
	}
	return obj;
}


function checkSPD()
{

	var count = document.Request.interests.length;

	var status = false;
	
		
	for(var i = 0; i < count && !status ; i++)
	{
		status = document.Request.interests[i].checked;
	}
	
	return status;
	
	
	
}

function checkZip(obj)
{
	var strZip = obj.value;
	var first
	var last
	strZip = strZip.replace(" ", "")
	strZip = strZip.replace("-", "")
	if (strZip.length == 5)
	{
	return true;
	}
	if(strZip.length == 9)
	{
		first = strZip.substring(0, 5)
		last = strZip.substring(5, 9)
		strZip = first .concat("-") .concat(last)
		obj.value = strZip
		return true
	}
	
	return false;
}

function checkPhone(obj)
{
	var strPhone = obj.value;
	var first
	var last
	var middle
	var one
	strPhone = strPhone.replace(" ", "")
	strPhone = strPhone.replace(" ", "")
	strPhone = strPhone.replace("-", "")
	strPhone = strPhone.replace("-", "")
	strPhone = strPhone.replace("-", "")
	strPhone = strPhone.replace(".", "")
	strPhone = strPhone.replace(".", "")
	strPhone = strPhone.replace(".", "")
	strPhone = strPhone.replace("(", "")
	strPhone = strPhone.replace(")", "")
	strPhone = strPhone.replace("+", "")
	if (strPhone.length == 10)
	{
		first = strPhone.substring(0, 3)
		middle = strPhone.substring(3, 6)
		last = strPhone.substring(6, 10)
		strPhone = first .concat("-") .concat(middle) .concat("-") .concat(last)
		obj.value = strPhone
		return true;
	}
	if (strPhone.length == 11)
	{
		one = strPhone.substring(0, 1)
		first = strPhone.substring(1, 4)
		middle = strPhone.substring(4, 7)
		last = strPhone.substring(7, 11)
		strPhone = one .concat("-") .concat(first) .concat("-") .concat(middle) .concat("-") .concat(last)
		obj.value = strPhone
		return true;
	}
	
	
	return false;
}

function checkLength (obj)
{
	var strNum = obj.value;
	if (strNum.length == 19) {
	return false;
	}
	return true;
}


function isDigit (c)
{
   var strAllowed = "1234567890";
   return (strAllowed.indexOf (c) != -1);
}

function IsNumeric(obj)
{
   var sText = obj.value;
   var ValidChars = "0123456789-()+ .";
   var IsNumber=true;
   var Char;

 
	for (i = 0; i < sText.length && IsNumber == true; i++) 
   	{ 
      	Char = sText.charAt(i); 
      	
      	if (ValidChars.indexOf(Char) == -1) 
        {
        	IsNumber = false;
        }
   	}
   return IsNumber;
   
}


function stripBlanks(aString)
{
	var newString =aString;
	var blank = " ";

	if(newString.indexOf(blank) != -1)
	{
		var i = 0;
		var j = newString.length - 1;

		for(i = 0; i < newString.length; i++)
		{
			if(newString.charAt(i) != blank)
				break;
		}

		if(i != newString.length)
		{
			for(j = newString.length - 1;j > -1; j--)
			{
				if(newString.charAt(j) != blank)
					break;
			}

			newString = newString.substring(i,j);
		}
		else
		{
			// all blanks
			newString = "";
		}
	}
	return newString;
}

function checkForBlank(obj)
{
	if(! obj.value || stripBlanks(obj.value) == " ")
		return true;
	else
		return false;
}

function checkField(element,validateStr)
{
	if(validateStr && validateStr != null && validateStr != "")
	{
		return eval(validateStr);
	}
	else if(element.type == "text")
	{
		if(checkForBlank(element))
			return false;
		else
			return true;
	}
}	

function switchEm(obj,img,validateStr)
{
	if(! checkField(obj,validateStr))
		img.src = "/images/asterisk_wht.gif";
	else
		img.src = "/images/noasterisk_wht.gif";
}

if(cpbrowser)
{
	theImgSrcs = new Array(3);
	theImgSrcs["img1"] = new Image();
	theImgSrcs["img1"].src = '/images/asterisk_ylw.gif';
	theImgSrcs["img2"] = new Image();
	theImgSrcs["img2"].src = '/images/noasterisk_ylw.gif';
}

function switchImage(theImage)
{
	if(cpbrowser)
		{
		// mouse moving in
		var tmp;
		tmp = theImgSrcs[theImage.name].src;
		theImgSrcs[theImage.name].src = theImage.src;
		return tmp;
		}
}

function isNumberString (InString)  {
	if(InString.length==0) 
		return (false);
	RefString="1234567890";
	for (Count=0; Count < InString.length; Count++)  {
		TempChar= InString.substring (Count, Count+1);
		if (RefString.indexOf (TempChar, 0)==-1)  
			return (false);
	}
	return (true);
}

function selectObj(obj)
{
	if(window.focus)
		obj.focus();
}