if ((parseInt(navigator.appVersion) <= 4) && (navigator.appName.indexOf("Microsoft") == -1)) {
	window.location.href = "upgrade.htm";
}

function popup(page,w,h){
	popwin = window.open(page,'pwin','width=' + w + ',height=' + h + ',scrollbars=yes,resizable=yes')
	popwin.focus()
}

function getExam(page,w,h){
	popwin = window.open(page,'pwin','width=' + w + ',height=' + h + ',scrollbars=yes,resizable=yes')
	popwin.focus()
}

function checkRadio(){
		for ( grp=0; grp<required_radio.length; grp++){
			c = 0
			radioGrp= eval("document.questions." + required_radio[grp])
	  		for (i=0; i<radioGrp.length; i++){
	     		if (radioGrp[i].checked == 1){   
		  		 c = 1;
		 		} 
	  		}
			if (c == 0){
				return false;
			}	
	  	}
	return true;	
}

function checkText(){	
		for ( i=0; i<required_text.length; i++){
		   q = eval("document.questions." + required_text[i])
		   if (q.value == ""){
				return false;
			}
		}
	return true;
}

function check(){
	 if (!checkText() || !checkRadio()){	
		 alert("All fields with an asterisk must be completed.");
		 return false;	
	 }
	 else{	 		
		return true;
	}
}

function markLink(linkName){
	if(document.getElementById){
		document.getElementById('nav' + num).style.color="#009966";
		document.getElementById('nav' + num).style.textDecoration="underline";		
	 }
	 else if(document.all){
		document.all.item('nav' + num).style.color="#009966";
		document.all.item('nav' + num).style.textDecoration="underline";
	}
} 	

function unmarkLink(linkName){
	if(document.getElementById){
		document.getElementById('nav' + num).style.color="#003399";
		document.getElementById('nav' + num).style.textDecoration="none";		
	 }
	 else if(document.all){
		document.all.item('nav' + num).style.color="#003399";
		document.all.item('nav' + num).style.textDecoration="none";
	}
} 

//--------- 

// is number
function isNum(passedVal){
	if (passedVal == ""){return false}
	
	for (i=0; i<passedVal.length;i++){
	   if (passedVal.charAt(i) < "0"){return false}
	   if (passedVal.charAt(i) > "9"){return false}
	}	
	return true
	}
// initial cap	
function changeCase(val) {
var index;
var tmpStr;
var tmpChar;
var preString;
var postString;
var strlen;
//tmpStr = val.toLowerCase();
tmpStr = val
strLen = tmpStr.length;
if (strLen > 0)  {
for (index = 0; index < strLen; index++)  {
if (index == 0)  {
tmpChar = tmpStr.substring(0,1).toUpperCase();
postString = tmpStr.substring(1,strLen);
tmpStr = tmpChar + postString;
}
else {
tmpChar = tmpStr.substring(index, index+1);
if (tmpChar == " " && index < (strLen-1))  {
tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
preString = tmpStr.substring(0, index+1);
postString = tmpStr.substring(index+2,strLen);
tmpStr = preString + tmpChar + postString;
         }
      }
   }
}
return tmpStr;
}	
	
	
//CAPlOCK
function checkCapsLock( e,msg ) {
  //if the browser did not pass event information to the handler,
  //check in window.event
  var myMsg = msg
  if( !e ) { e = window.event; } if( !e ) { return; }
  //what (case sensitive in good browsers) key was pressed
  //this uses all three techniques for checking, just in case
  var theKey = 0;
  if( e.which ) { theKey = e.which; } //Netscape 4+, etc.
  else if( e.keyCode ) { theKey = e.keyCode; } //Internet Explorer, etc.
  else if( e.charCode ) { theKey = e.charCode } //Gecko - probably not needed
  //was the shift key was pressed
  var theShift = false;
  if( e.shiftKey ) { theShift = e.shiftKey; } //Internet Explorer, etc.
  else if( e.modifiers ) { //Netscape 4
    //check the third bit of the modifiers value (says if SHIFT is pressed)
    if( e.modifiers & 4 ) { //bitwise AND
      theShift = true;
    }
  }
  //if upper case, check if shift is not pressed
  if( theKey > 64 && theKey < 91 && !theShift ) {
    alert( myMsg );
  }
  //if lower case, check if shift is pressed
  else if( theKey > 96 && theKey < 123 && theShift ) {
    alert( myMsg );
  }
} 
	
	 
// check cap doesn't work with firefox 
function checkCapsLock_old( e,msg ) {
	var myKeyCode=0;
	var myShiftKey=false;
	var myMsg = msg

	// Internet Explorer 4+
	if ( document.all ) {
	   myKeyCode=e.keyCode;
	   myShiftKey=e.shiftKey;
	
	// Netscape 4
	} else if ( document.layers ) {
	   myKeyCode=e.which;
	   myShiftKey=( myKeyCode == 16 ) ? true : false;
	
	// Netscape 6
	} else if ( document.getElementById ) {
	   myKeyCode=e.which;
	   myShiftKey=( myKeyCode == 16 ) ? true : false;
	}
	//Gecko format
	else if( e.charCode ) 
	//{ theKey = e.charCode } 
	{
	   myKeyCode=e.charCode;  
	   myShiftKey=( myKeyCode == 16 ) ? true : false;
	} 
	 
	
	// Upper case letters are seen without depressing the Shift key, therefore Caps Lock is on
	if ( ( myKeyCode >= 65 && myKeyCode <= 90 ) && !myShiftKey ) {
	   alert( myMsg );
	
	// Lower case letters are seen while depressing the Shift key, therefore Caps Lock is on
	} else if ( ( myKeyCode >= 97 && myKeyCode <= 122 ) && myShiftKey ) {
	   alert( myMsg );
	
	}
}

// Radio Button
function checkRadioButton(element){
   var selected 
   selected = -1 
   for (i=0; i < element.length; i++){
       if (element[i].checked){
	   selected = i}
   }
   if (selected == -1) {return false}
   else {return true}
}
// Agency ID
function validateAgencyID(ID){
	var tempX;
	var tempY;
	var trim;
	var i;
	if ((ID.length != 8)||(!(isNum(ID)))){
	   return false
	}
	else
	{
	tempX = ID.substring(0,7)
	i = 0;
	trim = true;
	while (tempX.charAt(0) == 0){
	 {tempX = tempX.substring(1,tempX.length)}
	}
	tempX = parseInt(tempX) % 7
	tempY = parseInt(ID.substring(7))
	if (tempX != tempY) {return false;}
	}
	return true
	}
//check email	
function checkeMail(email)
{
	var x = email.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) {return true}
	else {return false}
}

//match password
function matchPassword(x,y){
    var pass1
    var pass2
	pass1=x.toString()
	pass2=y.toString()
	pass1=pass1.toUpperCase();
	pass2=pass2.toUpperCase();
	if (pass1 != pass2)
	{ return false}
	else
	{ return true}
}

//check password
function checkPassword(password){
   var pass
   pass = password.value
   if ((pass.length < 5) || (pass.length > 12))
      {return false} 
   else
      {return true}	  
   }
//allow only number or alphabet  
function removeInvalid(string) {
    for (var i=0, output='', valid="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; i<string.length; i++)
       if (valid.indexOf(string.charAt(i)) != -1)
          output += string.charAt(i)
    return output;
} 

//allow only number  
function removeInvalidPhone(string) {
    for (var i=0, output='', valid="0123456789"; i<string.length; i++)
       if (valid.indexOf(string.charAt(i)) != -1)
          output += string.charAt(i)
    return output;
} 
//--------------------------------Country Zip/Postal code functions----------------------------------
// US Zip code	10001
function validateUSZip(ID){
	
	if ((ID.length != 5)||(!(isNum(ID)))){
	   return false
	}
	return true
	}
	
// Canada postal code A1A 1A1 or A1A1A1
function validateCanadaZip(entry){ // CANADIAN CODES ONLY
//entry=removeInvalid(entry)
//alert(entry)
strlen = entry.length; 
if ((strlen) < 6 || (strlen > 7)){return false;}
entry=entry.toUpperCase();        // in case of lowercase characters
// Check for legal characters in string - note index starts at zero

if (strlen == 6){
if ('ABCEHJKLMNPRSTVXY'.indexOf(entry.charAt(0)) < 0) {return false;}
if ('0123456789'.indexOf(entry.charAt(1)) < 0) {return false;}
if ('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(entry.charAt(2)) < 0) {return false;}
//if (' '.indexOf(entry.charAt(3)) < 0) {return false;}
if ('0123456789'.indexOf(entry.charAt(3)) < 0) {return false;}
if ('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(entry.charAt(4)) < 0) {return false;}
if ('0123456789'.indexOf(entry.charAt(5)) < 0) {return false;}}

if (strlen == 7){
if ('ABCEHJKLMNPRSTVXY'.indexOf(entry.charAt(0)) < 0) {return false;}
if ('0123456789'.indexOf(entry.charAt(1)) < 0) {return false;}
if ('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(entry.charAt(2)) < 0) {return false;}
if (' '.indexOf(entry.charAt(3)) < 0) {return false;}
if ('0123456789'.indexOf(entry.charAt(4)) < 0) {return false;}
if ('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(entry.charAt(5)) < 0) {return false;}
if ('0123456789'.indexOf(entry.charAt(6)) < 0) {return false;}}
return true; }

// Bermuda postal code 1A A1
function validateBermudaZip(entry){

strlen = entry.length; if (strlen != 5) {return false;}
entry=entry.toUpperCase();        // in case of lowercase characters
// Check for legal characters in string - note index starts at zero
if ('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(entry.charAt(0)) < 0) {return false;}
if ('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(entry.charAt(1)) < 0) {return false;}
if (' '.indexOf(entry.charAt(2)) < 0) {return false;}
if ('ABCDEFGHJKLMNPQRSTUVWXYZ0123456789'.indexOf(entry.charAt(3)) < 0) {return false;}
if ('ABCDEFGHJKLMNPQRSTUVWXYZ0123456789'.indexOf(entry.charAt(4)) < 0) {return false;}
return true; }


//UK postal code
function validateUKZip(entry){
  var validFormat = /^[A-Z]{1,2}\d[A-Z\d]? \d[A-Z]{2}$/i
  var isValid = validFormat.test(entry);
  return isValid;
}
// Australia & NewZealand Zip code	1234
function validateAustraliaZip(ID){
	
	if ((ID.length != 4)||(!(isNum(ID)))){
	   return false
	}
	return true
	}
//Itian postal code TI-12345 or I-12345 or 12345
function validateItalyZip(entry){
  var validFormat = /(^(TI-|I-)\d{5}$)|(^\d{5})$/i
  var isValid = validFormat.test(entry);
  return isValid;
}
//India postal code 123 456 or 123456
function validateIndiaZip(entry)
{
  var validFormat = /(^\d{3}\s\d{3}|^\d{6})$/i
  var isValid = validFormat.test(entry);
  return isValid;
}
//Czech Republic postal code 123 45
function validateCzechZip(entry)
{
  var validFormat = /^\d{3}\s\d{2}$/i
  var isValid = validFormat.test(entry);
  return isValid;
}
//Finland postal code FI-12345 or 12345
function validateFinlandZip(entry){
  var validFormat = /(^FI-\d{5})$|(^\d{5})$/i
  var isValid = validFormat.test(entry);
  return isValid;
}
//Hungary postal code 4 digits 1234
function validateHungaryZip(entry)
{
  var validFormat = /^\d{4}$/i
  var isValid = validFormat.test(entry);
  return isValid;
}
//Netherlands postal code 4 digits 1234
function validateNetherlandsZip(entry)
{
  var validFormat = /^\d{4}$/i
  var isValid = validFormat.test(entry);
  return isValid;
}
//Switzerland postal code 4 digits 1234
function validateSwitzerlandZip(entry)
{
  var validFormat = /^\d{4}$/i
  var isValid = validFormat.test(entry);
  return isValid;
}
//China postal code 6 digits 123456
function validateChinaZip(entry)
{
  var validFormat = /^\d{6}$/i
  var isValid = validFormat.test(entry);
  return isValid;
}
//Bahrain postal code 1XX or 12XX
function validateBahrainZip(entry)
{
  var validFormat = /^(1|12)\d{2}$/i
  var isValid = validFormat.test(entry);
  return isValid;
}
//Egypt postal code 5 digits 12345
function validateEgyptZip(entry)
{
  var validFormat = /^\d{5}$/i
  var isValid = validFormat.test(entry);
  return isValid;
}
//Morocco postal code 5 digits 12345
function validateMoroccoZip(entry)
{
  var validFormat = /^\d{5}$/i
  var isValid = validFormat.test(entry);
  return isValid;
}
//Oman postal code 3 digits 123
function validateOmanZip(entry)
{
  var validFormat = /^\d{3}$/i
  var isValid = validFormat.test(entry);
  return isValid;
}
//Saudi Arabia postal code 5 digits 12345
function validateSaudiZip(entry)
{
  var validFormat = /^\d{5}$/i
  var isValid = validFormat.test(entry);
  return isValid;
}
//Japan postal code 123-1234
function validateJapanZip(entry)
{
  var validFormat = /^\d{3}-\d{4}$/i
  var isValid = validFormat.test(entry);
  return isValid;
}
//Korea postal code 123-123
function validateKoreaZip(entry)
{
  var validFormat = /^\d{3}-\d{3}$/i
  var isValid = validFormat.test(entry);
  return isValid;
}
//Portugal postal code 1234-123
function validatePortugalZip(entry)
{
  var validFormat = /^\d{4}-\d{3}$/i
  var isValid = validFormat.test(entry);
  return isValid;
}
//Brazil postal code 12345-123
function validateBrazilZip(entry)
{
  var validFormat = /^\d{5}-\d{3}$/i
  var isValid = validFormat.test(entry);
  return isValid;
}
//Turkey postal code 5 digits 12345
function validateTurkeyZip(entry)
{
  var validFormat = /^\d{5}$/i
  var isValid = validFormat.test(entry);
  return isValid;
}
//-----------------------------------Country Phone number functions----------------------------------

// US phone number format 3,7
function validateUSPhone(ID1,ID2){
if (ID1.charAt(0)==1) {return false}
if ((ID1.length != 3)||(!(isNum(ID1)))){
	   return false
	}
if ((ID2.length != 7)||(!(isNum(ID2)))){
	   return false
	}
	return true	
}
//UK phone number format 2-6, 3-8
function validateUKPhone(ID1,ID2){
if (ID1.charAt(0)==0) {return false}
if ((ID1.length < 2)||(ID1.length > 6)||(!(isNum(ID1)))){
	   return false
	}
if ((ID2.length < 3)||(ID2.length > 8)||(!(isNum(ID2)))){
	   return false
	}
	return true	
}
//Ireland phone number format 1-3, 5-7
function validateIrelandPhone(ID1,ID2){
if (ID1.charAt(0)==0) {return false}
if ((ID1.length < 1)||(ID1.length > 3)||(!(isNum(ID1)))){
	   return false
	}
if ((ID2.length < 5)||(ID2.length > 7)||(!(isNum(ID2)))){
	   return false
	}
	return true	
}			
//Australia phone number format 1,9
function validateAustraliaPhone(ID1,ID2){
if (ID1.charAt(0)==0) {return false}
if ((ID1.length != 1)||(!(isNum(ID1)))){
	   return false
	}
if ((ID2.length != 8)||(!(isNum(ID2)))){
	   return false
	}
	return true	
}
//New Zealand Phone Number format 1-3, 5-7
function validateNewZealandPhone(ID1,ID2){
if (ID1.charAt(0)==0) {return false}
if ((ID1.length < 1)||(ID1.length > 3)||(!(isNum(ID1)))){
	   return false
	}
if ((ID2.length < 5)||(ID2.length > 7)||(!(isNum(ID2)))){
	   return false
	}
	return true	
}		
//Mexico Phone Number format 1-3,5-7
function validateMexicoPhone(ID1,ID2){
if (ID1.charAt(0)==0) {return false}
if ((ID1.length < 1)||(ID1.length > 3)||(!(isNum(ID1)))){
	   return false
	}
if ((ID2.length < 5)||(ID2.length > 7)||(!(isNum(ID2)))){
	   return false
	}
	return true	
}
//Germany Phone Number format 2-5,3-9
function validateGermanyPhone(ID1,ID2){
if (ID1.charAt(0)==0) {return false}
if ((ID1.length < 2)||(ID1.length > 5)||(!(isNum(ID1)))){
	   return false
	}
if ((ID2.length < 3)||(ID2.length > 9)||(!(isNum(ID2)))){
	   return false
	}
	return true	
}					
//Italy Phone Number format 1-3,5-8
function validateItalyPhone(ID1,ID2){
if ((ID1.length < 1)||(ID1.length > 3)||(!(isNum(ID1)))){
	   return false
	}
if ((ID2.length < 5)||(ID2.length > 8)||(!(isNum(ID2)))){
	   return false
	}
	return true	
}						
//Sweden Phone Number format 1-3,5-8
function validateSwedenPhone(ID1,ID2){
if (ID1.charAt(0)==0) {return false}
if ((ID1.length < 1)||(ID1.length > 3)||(!(isNum(ID1)))){
	   return false
	}
if ((ID2.length < 5)||(ID2.length > 8)||(!(isNum(ID2)))){
	   return false
	}
	return true	
}		
	
//India Phone Number format 2-7,4-8
function validateIndiaPhone(ID1,ID2){
if (ID1.charAt(0)==0) {return false}
if ((ID1.length < 2)||(ID1.length > 7)||(!(isNum(ID1)))){
	   return false
	}
if ((ID2.length < 4)||(ID2.length > 8)||(!(isNum(ID2)))){
	   return false
	}
	return true	
}		
//Indonesia Phone Number format 1-4,5-11
function validateIndonesiaPhone(ID1,ID2){
if (ID1.charAt(0)==0) {return false}
if ((ID1.length < 1)||(ID1.length > 4)||(!(isNum(ID1)))){
	   return false
	}
if ((ID2.length < 5)||(ID2.length > 11)||(!(isNum(ID2)))){
	   return false
	}
	return true	
}							
//Czech Republic Phone Number format 1-5,4-8
function validateCzechPhone(ID1,ID2){
if ((ID1.length < 1)||(ID1.length > 5)||(!(isNum(ID1)))){
	   return false
	}
if ((ID2.length < 4)||(ID2.length > 8)||(!(isNum(ID2)))){
	   return false
	}
	return true	
}					
//Finland Phone Number format 1-2,4-9
function validateFinlandPhone(ID1,ID2){
if ((ID1.length < 1)||(ID1.length > 2)||(!(isNum(ID1)))){
	   return false
	}
if ((ID2.length < 4)||(ID2.length > 9)||(!(isNum(ID2)))){
	   return false
	}
	return true	
}			


