var subWindow = null;

function closeSub() {
  if (subWindow != null && subWindow.open) subWindow.close();
}
window.onfocus=closeSub;

//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
function LoadPage(strFormName, strCurrentField, strAnchor)
{
        var i;
        var j;
        var strURL;
        var strElement;
        var is_major = parseInt(navigator.appVersion);
        // convert all characters to lowercase to simplify testing
        var agt=navigator.userAgent.toLowerCase();
        var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)  && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)&& (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
    

//      alert('start of the LoadPage function');
//      Have assumed that there is ONLY 1 form in the page
//      NEW -- We now have assumed that the <FORM> tag in the header will
//             be the first FORM tag in the page -->ALWAYS!
//             The for loop below will be processing the 2nd form tag
//             in the page. 
//             If any pages are added without the header.asp then this
//             will NOT work!
        
       
        
//      Netscape does not recognize 2 form tags. IE does.
//      document.all only returns true for IE.

      
        if (document.all)
        {
                //the surfer is using IE 4+
                
                i=1;
        }
        else
        {
                if (is_nav && is_major >= 5) { 
                        i=1;
                }
                else {
                        i=0;
                }
               
        }
        
     
        //  alert('length = ' + document.forms.length);
        
        strURL = strFormName ;
        
        strSeparator = '?';
        
        
       
//      for (i=0; i<document.forms.length; i++)
//      {
                for (j=0; j<document.forms[i].elements.length; j++)
                
                {
                         

                        strElement = '';

                        switch (document.forms[i].elements[j].type)
                        {
                        case 'text':
                        case 'hidden':
                                {
                                strElement = strSeparator + document.forms[i].elements[j].name + '=' + escape(document.forms[i].elements[j].value);
                                break;
                                }
                        case 'select-one':      
                                {
                                var lngSelected
                                var strValue
                                
                                lngSelected = document.forms[i].elements[j].selectedIndex;
                                //alert('strValue = ' + document.forms[i].elements[j].options[lngSelected].value);
                                //alert('lngSelected =' +  document.forms[i].elements[j].selectedIndex);
                                if (lngSelected >= 0) 
                                        {
                                        strValue = document.forms[i].elements[j].options[lngSelected].value;
                                        strElement = strSeparator + document.forms[i].elements[j].name + '=' + escape(strValue);
                                        }
                                else
                                        {
                                        strElement = strSeparator + document.forms[i].elements[j].name + '='
                                        }
                                break;
                                }                               
                        case 'radio':
                                {
                                if (document.forms[i].elements[j].checked)
                                {
                                        strElement = strSeparator + document.forms[i].elements[j].name + '=' + escape(document.forms[i].elements[j].value);
                                }
                                break;
                                }
                        case 'button':
                                {
                                //What should we do so we know which button was pushed
                                //strElement = strSeparator + document.forms[i].elements[j].name + '=' + escape(document.forms[i].elements[j].value);
                                break;
                                }
                        default:
                                {
                                strElement = strSeparator + document.forms[i].elements[j].name + '=' + escape(document.forms[i].elements[j].value);
                                break;
                                }
                        }
                        
                        
                        //alert ('strElement=:' + strElement + ':')
                        if (strElement != "") 
                        {
                                // once a field has been addedd to the url, change the separator from ? to &
                                // Needed because if an unchecked radio button is the first element of the form, no element 
                                // is added to the URL

                                strURL = strURL + strElement;
                                strSeparator = '&';
                        }
                }
                strURL = strURL + '&CurrField=' + strCurrentField;
//      }

        //alert(strURL);
        
        if (strAnchor != '') 
        {
                //alert(strURL);
                strURL = strURL + '&#' + strAnchor;
                //alert(strURL);
        }
        location.replace(strURL);

}


function openHelp(url, h, w){
        //var w = 500;
        //var h = 400;

        if (window.screen) {
                var chasm = screen.availWidth;
                var mount = screen.availHeight;
                subWindow = window.open(url,'_help','width=' + w + ',height=' + h + ',left=' + ((chasm - w - 10) * .5) + ',scrollbars=1,resizable=yes,top=' + ((mount - h - 30) * .5));
        }
}

function openFS(url){
	var windowProperties;
	var newWindow;
	var w;
	var h;

	h=(screen.height);
	w=(screen.width);
	windowProperties = "top=0, left=0, resizable=1, scrollbars=1, width=" + w + ",height=" + h;

	newWindow=window.open(url,"",windowProperties);
	newWindow.focus();
}

