var track; //Sets Global Variable for alrt and galert function to allow for keeping focus on fake alert screen

//var ff=0;//This is to check if any fields are flagged, if one is then the no other alert messages will show
/*//Older reqs
var req_edt="The selected field must be filled in.";
var req_edt1="The selected field ";
var req_edt2=" must be filled in.";
var req_sel="A selection from the list must be made.";
var req_gen="All required fields must be completed before moving to the next page.";
var req_num_only="The selected field accepts numbers only.";
var req_min_size="The selected field requires at least ";
var req_min_is_max="The selected field must be completely filled in.";
var req_valid_email="A valid e-mail address is required. Example: myname@myaccount.com";
var ZIP_5_long = "The ZIP code must be 5 numbers long.";
var ZIP_num_only = "The ZIP code must contain numbers only.";
var POSTAL_6_long = "The postal code must be 6 characters long, with a space in the middle.  Example: K1Z 8R7";
var POSTAL_valid = "Please input a valid postal code. Example: K1Z 8R7";
*/
function galert(stri,gen) {  //old way of doing Kanji alerts with Graphics (graphic name, 1 for show req_gen or 0 for don't show req_gen)
 var langcode = "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\">";
 if(gen==1){ gen="<br><img src='req_gen.gif'>"; } else { gen=""; }
 if (document.all){
         var xMax = screen.width, yMax = screen.height;
        } else {
        if (document.layers){
            var xMax = window.outerWidth, yMax = window.outerHeight;
         } else {
           var xMax = 640, yMax=480;
	 }
 }
 stri="<img src=\""+stri+".gif\">";
 var xOffset = (xMax - 600)/2, yOffset = (yMax - 150)/2;
 if (track){
 	if (track.close){window.track.close();}
 }
 var alrt = window.open('','alert','width=600,height=150,resizable=false,screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+'');
 alrt.document.write('<html><title>Javascript Alert</title><body bgcolor=#CCCCCC onBlur="window.focus()" link=#CCCCCC vlink=#CCCCCC alink=#CCCCCC>' + langcode + '<table><tr><td><table><tr><td><img src=alert.gif></td><td>'+stri+gen+'</td></tr></table></td></tr><tr><td><center><a href="javascript://" onClick="window.close();"><img src="button.gif" onClick="window.close();"></a></td></tr></table>');
 track=alrt;
 alrt.focus();
 setTimeout('track.focus()', 100);
 return false;
}

function alrt(stri) {  //Makes an alert popup with the message created in UTF 8 instead of the old way with graphics
 var langcode = "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\">";
 gen="";
 if (document.all){
         var xMax = screen.width, yMax = screen.height;
        } else {
        if (document.layers){
            var xMax = window.outerWidth, yMax = window.outerHeight;
         } else {
           var xMax = 640, yMax=480;
         }
 }

 var xOffset = (xMax - 600)/2, yOffset = (yMax - 150)/2;
 if (track&&track.open&&!track.closed){
        if (window.track.close){window.track.close();}
 }
 var alrt = window.open('','alert','width=630,height=150,resizable=false,screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+'');
 alrt.document.write('<html><title>Javascript Alert</title><body bgcolor=#CCCCCC onBlur="window.focus()" link=#CCCCCC vlink=#CCCCCC alink=#CCCCCC>' + langcode + '<table><tr><td><table><tr><td><img src=/art/<TMPL_VAR NAME=LANG>/ALERT/alert.gif></td><td>'+stri+gen+'</td></tr></table></td></tr><tr><td><center><a href="javascript://" onClick="window.close();"><img src="/art/<TMPL_VAR NAME=LANG>/ALERT/button.gif" onClick="window.close();"></a></td></tr></table>');
 track=alrt;
 alrt.focus();
 setTimeout('track.focus()', 100);
 return false;
}



function MM_preloadImages() { 

  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();

    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length;

i++)

    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}

}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function num_check (field_to_check){  //if field filled in, then check to see if a number
  if (isNaN(document.forms[0].field_to_check.value)&&document.forms[0].field_to_check.length!=0&&ff==0) { ff=1; alert(req_num_only); window.scroll(0,0); document.forms[0].field_to_check.focus();}
  return ff;
}

function PrePopulateCountry(){   //This function pre populates the country field if the user selects USA or Canada from the Province/State list

	if(parent.STATi==0)
	{
		parent.CTRYi.selectedIndex=0;
		document.forms[0].CTRY.selectedIndex=0;
		parent.CTRY="";
	}

	if(parent.STATi>=2 && parent.STATi<=14) //These are the index values for Canadan provinces
	{
		selectCTRY("Canada");
	}

 	if(parent.STATi>=15 && parent.STATi<=65) //These are the index values for the 50 states
 	{
	 	selectCTRY("United States");
 	}
}//May need to include values instead of indexes for better accuracy

function selectDropDown(field_to_check, string, formName)  //Look through the Dropdown list, find a value, and set the DropDown on the form specified
{
        var i;
        var len = eval('document.'+formName+'.'+field_to_check+'.length');
        for(i=0; i < len; i++)
        {
                if(eval('document.'+formName+'.'+field_to_check+'.options[i].value') == string)
                {
                        eval('document.'+formName+'.'+field_to_check+'.selectedIndex=i');
                        break;
                }
        }
}

function returnDropDownvisible(field_to_check, string, formName){
        var i;
        var len = eval('document.'+formName+'.'+field_to_check+'.length');
        for(i=0; i < len; i++)
        {
                if(eval('document.'+formName+'.'+field_to_check+'.options[i].value') == string)
                {
                        return eval('document.'+formName+'.'+field_to_check+'.options[i].text');
                }
        }
}

function checkit (field_to_check, field_type){
 if (field_type =="edit"){
   if (document.forms[0].field_to_check.value==""&&ff==0) { ff=1; window.scroll(0,0); document.forms[0].field_to_check.focus(); alert(req_edt+"\n"+req_gen);}
 }
 if (field_type =="radio"){

 }
 if (field_type =="checkbox"){

 }
 if (field_type =="list"){
   if (document.forms[0].field_to_check.options[document.forms[0].field_to_check.selectedIndex].value==""&&ff==0) { ff=1; window.scroll(0,0); document.forms[0].field_to_check.focus(); alert(req_sel+"\n"+req_gen);} 	
 }
  
 return ff;
}

function Applic(){// included because of previous use.  Will have to examine how to handle such situations from now on.

  if (parent.PUSEi==0){
    document.forms[0].COMP.value='Not Applicable';
    parent.COMP='';
    document.forms[0].TITL.value='Not Applicable';
    parent.TITL='';
    document.forms[0].PHEX.value='N/A';
    parent.PHEX='';
    document.forms[0].FXNM.value='Not Applicable';
    parent.FXNM.value='';
    return false;
  }
  else{
    if (document.forms[0].COMP.value=='Not Applicable'){
      document.forms[0].COMP.value='';
      }else{parent.COMP.value=document.forms[0].COMP.value;}
    if (document.forms[0].TITL.value=='Not Applicable'){
      document.forms[0].TITL.value='';
      }else{parent.TITL.value=document.forms[0].TITL.value;}
    if (document.forms[0].PHEX.value=='N/A'){
      document.forms[0].PHEX.value='';
      }else{parent.PHEX.value=document.forms[0].PHEX.value;}
    if (document.forms[0].FXNM.value=='Not Applicable'){
      document.forms[0].FXNM.value='';
      }else{parent.FXNM.value=document.forms[0].FXNM.value;}
  }
  return true;
}

function BirthYear (){
// derive the applicant's birth year from the value of 
//the age attribute and the BirthMonth and Year
var BirthMonth = document.SendForm.MNTH.options[document.SendForm.MNTH.selectedIndex].value;
var BirthDay = document.SendForm.DAYS.options[document.SendForm.DAYS.selectedIndex].value;
var CurMonth = document.SendForm.SSMN.value;
var CurDay = document.SendForm.SSDY.value;
var CurYear = document.SendForm.SSYR.value;
var age =  document.SendForm.AGES.value;

// as a first approximation, set the age to the difference between the 
//current year and the birth year
age = CurYear - age;

// if the applicant's has not yet had a birthday in the current year, 
//reduce the age by 1
if (CurMonth < BirthMonth){
	age = age - 1;
}else{
	if (CurMonth == BirthMonth){
	    if (CurDay < BirthDay){
	    	age = age - 1;
	    }
	}
}

// return age to the calling method
//alert (age);
return age;
}//will require additional changes for universal use