var downStrokeField;
function autojump(fieldName,nextFieldName,newMaxLength,resetMaxLength,zone) {
	//zone is "W' for work  or "H" for home
	//var myForm=document.forms[document.forms.length - 1];
	if (document.forms["appform"] != null) {
		var myForm=document.forms["appform"];
	} else {
		var myForm=document.forms["form"];
	}
	var myField=myForm.elements[fieldName];
	myField.nextField=myForm.elements[nextFieldName];
	
	//check selected Country first
	if (
		(zone=="W" && ( (myForm.WorkCountry.options[myForm.WorkCountry.selectedIndex].value == 'US') ||
						(myForm.WorkCountry.options[myForm.WorkCountry.selectedIndex].value == 'CA') ) ) ||
		(zone=="H" && ( (myForm.HomeCountry.options[myForm.HomeCountry.selectedIndex].value == 'US') ||
						(myForm.HomeCountry.options[myForm.HomeCountry.selectedIndex].value == 'CA') ) )
		) {
		myField.maxLength=newMaxLength;
		myField.onkeydown=autojump_keyDown;
		myField.onkeyup=autojump_keyUp;
	} else {
		myField.maxLength=resetMaxLength;
		myField.onkeydown= "";
		myField.onkeyup= "";
	}
	
}

function autojump_keyDown() {
	this.beforeLength=this.value.length;
	downStrokeField=this;
}

function autojump_keyUp() {
	if (
	   (this == downStrokeField) && 
	   (this.value.length >= this.beforeLength) && 
	   (this.value.length >= this.maxLength)
	   ) {
		   this.nextField.focus();
		   this.nextField.select();
		 }
	downStrokeField=null;
}

function insertHyphen(fieldName,zone,strPlace) {
	if (document.forms["appform"] != null) {
		var myForm=document.forms["appform"];
	} else {
		var myForm=document.forms["form"];
	}
	var myField=myForm.elements[fieldName];
	if (
		(zone=="W" && ( (myForm.WorkCountry.options[myForm.WorkCountry.selectedIndex].value == 'US') ||
						(myForm.WorkCountry.options[myForm.WorkCountry.selectedIndex].value == 'CA') ) ) ||
		(zone=="H" && ( (myForm.HomeCountry.options[myForm.HomeCountry.selectedIndex].value == 'US') ||
						(myForm.HomeCountry.options[myForm.HomeCountry.selectedIndex].value == 'CA') ) )
		) {  
		var output = '';
		for (var i=0; i<myField.value.length; i++) {
			if (i==strPlace && myField.value.charAt(strPlace) != '-' && myField.value.length > strPlace)
				output += '-';
			output += myField.value.charAt(i);
		}
		myField.value = output;
	}
}

function insertHyphen2(fieldName,zone,numType) {
	if (numType == 'P') {
		var strPlace = 3;	
	}
	if (numType == 'Z') {
		var strPlace = 5;	
	}
	if (document.forms["appform"] != null) {
		var myForm=document.forms["appform"];
	} else {
		var myForm=document.forms["form"];
	}
	var myField=myForm.elements[fieldName];
	if (
		(zone=="W" && ( (myForm.WorkCountry.options[myForm.WorkCountry.selectedIndex].value == 'US') ||
						(myForm.WorkCountry.options[myForm.WorkCountry.selectedIndex].value == 'CA' && numType=='P') ) ) ||
		(zone=="H" && ( (myForm.HomeCountry.options[myForm.HomeCountry.selectedIndex].value == 'US') ||
						(myForm.HomeCountry.options[myForm.HomeCountry.selectedIndex].value == 'CA' && numType=='P') ) )
		) {  
		var output = '';
		for (var i=0; i<myField.value.length; i++) {
			if (i==strPlace && myField.value.charAt(strPlace) != '-' && myField.value.length > strPlace)
				output += '-';
			output += myField.value.charAt(i);
		}
		myField.value = output;
	}
}
