/* USAGE
function checkForm(wForm) {
	if (!(checkText(wForm.fname, 	"First Name"))) 		{ return false; } 
	if (!(checkText(wForm.textAreaField, "TEXTAREA"))) 			{ return false; } 		
	*/ /*
	wForm.Submit.disabled = true;
	return true;
}
</script>				
<form name="amForm" method="post" action="<%=request.ServerVariables("URL")%>" 
	onSubmit="return checkForm(this);"> 
*/

function gotosite(site) {
	if (site != "") {
	self.location=site; } 
}

function clearcombo(wCombo){
  for (var i=wCombo.options.length-1; i>=0; i--){
    wCombo.options[i] = null;
  }
  wCombo.selectedIndex = -1;
}

// Clears the combo box, then fills with array
function fillcombo(wCombo, wFillArray){
  clearcombo(wCombo);
  for (var i = 0; i < wFillArray[0].length; i++){
    wCombo.options[wCombo.options.length]=
      new Option(wFillArray[0][i],wFillArray[1][i]);
  }

}

function checkOptions(wField, rText) {		// Works for both radio and checkboxes
	if (rText == null) {
		rText = "one of the options";
	}		
	var selected = false;
	if (wField.length == null) {
		selected = wField.checked;
		focusfield = wField;
	}
	else {
		for (var i = 0; i < wField.length; i++) {
			selected = selected || wField[i].checked;
		}
		focusfield = wField[0];
	}
	if (!selected) {
		alert('Please make a selection for '  + rText);
		focusfield.focus();
		return false;
	}
	return(selected)
}
function unCheckRadio(oRadio) {
	var or = document.getElementsByName(oRadio);
	for (var i = 0; i < or.length; i++) {
		 or[i].checked = false;
	 }
}
function optionsSelected(wField) {		// Works for both radio and checkboxes
	var selected = false;
	if (wField.length == null) { selected = wField.checked; focusfield = wField; }
	else {
		for (var i = 0; i < wField.length; i++) {
			selected = selected || wField[i].checked;
		}
		focusfield = wField[0];
	}
	if (!selected) { focusfield.focus(); return false; }
	return(selected);
}
function checkPulldown(wField, rText) {
	if (rText == null) {
		rText = "this";
	}	
	if (wField[wField.selectedIndex].value == "" | wField[wField.selectedIndex].value == null) {
		 alert('Please make a selection for ' + rText);
		 wField.focus();
		 return false;
	}
	else {
		return true;
	}
}	  

function checkText(wField) {
	/*if (rText == null) {
		rText = "This";
	}*/
	if (isEmpty(wField.value)) {
		//alert(rText + " is a required field");
		wField.focus();
		return false;
	}
	else {
		return true;
	}
}

function checkTextClear(wField, rText) {
	if (rText == null) {
		rText = "This";
	}
	if (isEmpty(wField.value) | isStartText(wField)) {
		alert(rText + " is a required field");
		wField.focus();
		return false;
	}
	else {
		return true;
	}
}

function checkEmail(wField) {
	if (!isEmail(wField.value)) {
		wField.focus();
		return false;
	}
	else {
		return true;
	}
}

var whitespace = " \t\n\r";
function isEmpty (s){
	var i;
    if (isNull(s)) return true;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) return false;
    }
    // All characters are whitespace.
    return true;
}

function isNull(s) {	// used by isEmpty
   return ((s == null) || (s.length == 0))
}

function isEmail(emailStr) {
	if (isEmpty(emailStr)) return false;
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		//alert("This Email address seems incorrect (check @ and .'s)")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	
	if (user.match(userPat)==null) {
		//alert("This E-Mail address doesn't seem to be valid.")
		return false
	}
	
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		  for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				//alert("Destination IP address is invalid!")
			return false
			}
		}
		return true
	}
	
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		//alert("This E-Mail address domain name doesn't seem to be valid.")
		return false
	}
	
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
		domArr[domArr.length-1].length>3) {
	  // alert("This E-Mail address must end in a three-letter domain, or two letter country.")
	   return false
	}
	
	if (len<2) {
	   var errStr="This E-Mail address is missing a hostname."
	  // alert(errStr)
	   return false
	}
	
	return true;
}

function checkLimit(wField, wLimit) {
	StrLen = wField.value.length;
	if (StrLen > wLimit) {
		msgText = wField.value;
		newText = msgText.substr(0, wLimit);
		StrLen = wLimit;
		wField.value = newText;
	}
}

// clearText() thesecond parameter is allows this function to be used on password fields, the type of the password field should be set to "text"
function clearText(wField,isPassword) {			
	iValue = wField.defaultValue;
	cValue = wField.value;
	if (cValue == "") {
	    wField.value = iValue;
	}
	else if (cValue == iValue) {
	    wField.value = "";
		if (isPassword) fieldTypeToPassword(wField);		
	}	
}

function fieldTypeToPassword(oInput) {
	var newEl = document.createElement('input');
	newEl.setAttribute('type', 'password');
    newEl.setAttribute('name', oInput.name);
    newEl.onfocus = oInput.onfocus;
    newEl.onblur = oInput.onblur;	
    newEl.className = oInput.className;
	oInput.parentNode.replaceChild(newEl,oInput);
	fieldTypeToPassword.el = newEl;
	setTimeout('fieldTypeToPassword.el.focus()',100);
	return true;
}

function clearField(wField) {
	if (wField.value == wField.defaultValue) {
		wField.value = "";
	}
	else if (wField.value == "") {
		wField.value = wField.defaultValue;
	}	
}

function clearFieldSelect(wField) {
	if (wField.value == wField.defaultValue) {
		wField.value = "";
	}
	else if (wField.value == "") {
		wField.value = wField.defaultValue;
	}		
}

/** DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/) */
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

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++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
		// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function checkDate(wField){
	var dtStr = wField.value;
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

/* ---------- ---------- ---------- ---------- ---------- ---------- */
function applicationResidence(country) {
	document.getElementById("USoffice").style.display = "none";
	document.getElementById("AUoffice").style.display = "none";
	document.getElementById("ARoffice").style.display = "none";
	document.getElementById("AToffice").style.display = "none";
	document.getElementById("BEoffice").style.display = "none";
	document.getElementById("BRoffice").style.display = "none";
	document.getElementById("CAoffice").style.display = "none";
	document.getElementById("DKoffice").style.display = "none";
	document.getElementById("FRoffice").style.display = "none";
	document.getElementById("DEoffice").style.display = "none";
	document.getElementById("GRoffice").style.display = "none";
	document.getElementById("NLoffice").style.display = "none";
	document.getElementById("HKoffice").style.display = "none";
	document.getElementById("INoffice").style.display = "none";
	document.getElementById("IEoffice").style.display = "none";
	document.getElementById("IToffice").style.display = "none";
	document.getElementById("JPoffice").style.display = "none";
	document.getElementById("LUoffice").style.display = "none";
	document.getElementById("MXoffice").style.display = "none";
	document.getElementById("NOoffice").style.display = "none";
	document.getElementById("ESoffice").style.display = "none";
	document.getElementById("SEoffice").style.display = "none";
	document.getElementById("CHoffice").style.display = "none";
	document.getElementById("GBoffice").style.display = "none";
	document.getElementById("JPDEoffice").style.display = "none";
	document.getElementById("ZAoffice").style.display = "none";	
	document.getElementById("Nearestoffice").style.display = "none";

	if (country == "AR" || country == "BO" || country == "CL" || country == "CO" || country == "EC" || country == "PY" || country == "PE" || country == "UY" || country == "VE") {
		showoffice = document.getElementById("ARoffice");
	}
	else if (country == "AU" || country == "NZ" || country == "CK") {
		showoffice = document.getElementById("AUoffice")
	}
	else if (country == "RO" || country == "AT" || country == "CZ" || country == "HU" || country == "SK" || country == "SI") {
		showoffice = document.getElementById("AToffice");
	}
	else if (country == "BE") {
		showoffice = document.getElementById("BEoffice");
	}
	else if (country == "BR") {
		showoffice = document.getElementById("BRoffice");
	}
	else if (country == "CA") {
		showoffice = document.getElementById("CAoffice");
	}
	else if (country == "DK" || country == "GL") {
		showoffice = document.getElementById("DKoffice");
	}
	else if (country == "FR" || country == "GP" || country == "MQ" || country == "GF" || country == "AE") {
		showoffice = document.getElementById("FRoffice");
	}
	else if (country == "DE" || country == "EE" || country == "LV" || country == "LT" || country == "PL" || country == "UA") {
		showoffice = document.getElementById("DEoffice");
	}
	else if (country == "GR" || country == "CY" || country == "MK" || country == "CS" || country == "BG"  || country == "AL"  || country == "TR") {
		showoffice = document.getElementById("GRoffice");
	}
	else if (country == "NL" || country == "AW" || country == "AN") {
		showoffice = document.getElementById("NLoffice");
	}
	else if (country == "HK" || country == "BN" || country == "KH" || country == "CN" || country == "ID" || country == "LA" || country == "MO" || country == "MY" || country == "MM" || country == "PH" || country == "SG" || country == "TW" || country == "TH" || country == "TL" || country == "VN") {
		showoffice = document.getElementById("HKoffice");
	}
	else if (country == "IN" || country == "BD" || country == "BT" || country == "MV" || country == "NP" || country == "PK" || country == "LK") {
		showoffice = document.getElementById("INoffice");
	}
	else if (country == "IE") {
		showoffice = document.getElementById("IEoffice");
	}	
	else if (country == "IT" || country == "VA") {
		showoffice = document.getElementById("IToffice");
	}
	else if (country == "JP" || country == "KP" || country == "KR") {
		showoffice = document.getElementById("JPoffice");
	}
	else if (country == "LU") {
		showoffice = document.getElementById("LUoffice");
	}
	else if (country == "MX" || country == "BZ" || country == "CR" || country == "SV" || country == "GT" || country == "HN" || country == "NI" || country == "PA" || country == "CU") {
		showoffice = document.getElementById("MXoffice");
	}
	else if (country == "NO" || country == "SJ") {
		showoffice = document.getElementById("NOoffice");
	}
	else if (country == "ES" || country == "AD") {
		showoffice = document.getElementById("ESoffice");
	}
	else if (country == "SE" || country == "FI") {
		showoffice = document.getElementById("SEoffice");
	}
	else if (country == "CH") {
		showoffice = document.getElementById("CHoffice");
	}
	else if (country == "GB" || country == "AI" || country == "MS" || country == "FK" || country == "FO" || country == "VG") {
		showoffice = document.getElementById("GBoffice");
	}
	else if (country == "US" || country == "PR" || country == "VI" || country == "UM" || country == "AS" || country == "GU" || country =="MP") {
		showoffice = document.getElementById("USoffice");
	}
	
	else if (country == "AG" || country == "BS" || country == "BB" || country == "BM" || country == "KY" ||  country == "DM" || country == "DO" || country == "GD" || country == "GY" || country == "HT" || country == "JM" || country == "MH" || country == "KN" || country == "LC" || country == "VC" || country == "TT" || country == "TC" || country == "SR") {
		showoffice = document.getElementById("Nearestoffice");
	}
	
	
	else if (country == "RU") {
		showoffice = document.getElementById("JPDEoffice");
	}
	else if (country == "ZA" || country == "ZW" || country == "ZM" || country == "LS" || country == "MZ" || country == "NA" || country == "BW" || country == "MW" || country == "SZ" ) {
		showoffice = document.getElementById("ZAoffice");
	}
	
	
	else {
		showoffice = document.getElementById("Nearestoffice");
	}
	showoffice.style.display = "block";

}

/* ---------- ---------- ---------- ---------- ---------- ---------- */

