var isDOM = document.getElementById?1:0;
var isIE = document.all?1:0;
var isNS4 = (navigator.appName=='Netscape' && !isDOM)?1:0;
var isIE4 = (isIE && !isDOM)?1:0;
var isDyn = (isDOM||isIE4||isNS4);

// Determine the popup window properties
// options include:  top, left, toolbars, scrollbars,
// menubar, location, statusbar, and resizable

function openWindow(url, w, h, rs, sb) {
var windowprops = "width=" + w + ",height=" + h + ",resizable=" + rs + ",scrollbars=" + sb;
//windowprops += "center=yes;border=thin;help=no;status=no;locationbar=no;statusbar=no;locationbar=no;menubar=no;toolbar=no";

popup = window.open(url,'remote',windowprops);
}

//CountryNav auto Submit script
function countryNavChange() {
  country = document.countrynav.country[document.countrynav.country.selectedIndex].value;
  window.location.href = document.countrynav.action + "?country=" + country;
}

function checkCheckBox(f) {
  if (f.agreement.checked == false )
  {
    alert('You must agree with the agreement to continue.');
    return false;
  } else
return true;
}

function fullscreen(theURL,theTarget) {
var varwidth = screen.availWidth;
var varheight = screen.availHeight;
if (isIE) {
var varwidth = varwidth-10;
var varheight = varheight-150;
} else {
var varwidth = varwidth-10;
var varheight = varheight-100;
}
//alert(varwidth + "x" + varheight);

var windowprops = "height=" + varheight + ",width=" + varwidth + ",innerheight=" + varheight + ",innerwidth=" + varwidth + ",left=0,screenX=0,top=0,screenY=0,toolbar,menubar,scrollbars,resizable,status,location";
//alert(windowprops);
if (isIE){
//alert('Internet Explorer!');
window.open(theURL,theTarget,windowprops);
//theTarget.window.focus();
//window.open("page.html","","height=200,width=200,left=80,top=80");
//theTarget.resizeTo(screen.availwidth,screen.availheight);
//theTarget.moveto(0,0);} //The javascript error in this line in some IE.
} else {
//alert('Non Internet Explorer detected');
window.open(theURL,theTarget,windowprops);
}
//alert(varwidth + 'x' + varheight);
//var windowprops = "height=" + varheight + ",width=" + varwidth +  ",top=0,left=0,toolbar,menubar,scrollbars,resizable,status,location";
//var windowprops = 'width=' + varwidth + ',height=' + varheight + ',top=0,left=0';
//alert(windowprops);
//window.open(theURL,theTarget,windowprops);
//window.open("page.html","","height=200,width=200,left=80,top=80");
//myWin.resizeTo(screen.availwidth,screen.availheight);
//myWin.moveto(0,0);
//var windowprops = "toolbar=yes, scrollbars=yes, menubar=no, location=yes, statusbar=no, resizable=no, fullscreen=no"
//window.open(theURL, '', windowprops);
}

function screensize() {
var screenW = screen.width;
var screenH = screen.height;
return screenW;
}

// QueryString
function PageQuery(q) {
if(q.length > 1) this.q = q.substring(1, q.length);
else this.q = null;
this.keyValuePairs = new Array();
if(q) {
for(var i=0; i < this.q.split("&").length; i++) {
this.keyValuePairs[i] = this.q.split("&")[i];
}
}
this.getKeyValuePairs = function() { return this.keyValuePairs; }
this.getValue = function(s) {
for(var j=0; j < this.keyValuePairs.length; j++) {
if(this.keyValuePairs[j].split("=")[0] == s)
return this.keyValuePairs[j].split("=")[1];
}
return false;
}
this.getParameters = function() {
var a = new Array(this.getLength());
for(var j=0; j < this.keyValuePairs.length; j++) {
a[j] = this.keyValuePairs[j].split("=")[0];
}
return a;
}
this.getLength = function() { return this.keyValuePairs.length; } 
}
function queryString(key){
var page = new PageQuery(window.location.search); 
return unescape(page.getValue(key)); 
}

/*
function getcountry(strformname)
{
//alert (queryString('countrycode'));
    var cval = document.forms[strformname].Region.options[document.forms[strformname].Region.selectedIndex].value;
    if (cval != '')
    {
         document.forms[strformname].country.disabled = false;
         document.forms[strformname].country.length = 0;
         
         var counter = 0
         document.forms[strformname].country.options[counter] = new Option('All Countries in selected region', '');
         document.forms[strformname].country.options[counter].selected = true;
         counter++
         document.forms[strformname].country.options[counter] = new Option('--------------------------------', '');
         counter++ 
         for(i=0;i<countryRegion.length;i++)
         {
             if (cval == countryRegion[i]) {
               document.forms[strformname].country.options[counter] = new Option(countryDisplay[i],countryValue[i]);
               var strTemp
               //alert(countryValue[i].toLowerCase());
               //alert (strTemp.toLowerCase());
               if (queryString('countrycode').toLowerCase() == countryValue[i].toLowerCase()) {
                 document.forms[strformname].country.options[i].selected = true;
                 //alert (queryString('countrycode').toLowerCase());
              }
               counter++;
             }
             //document.frm.country.options[i] = new Option(eval(""+cval+"option["+i+"]"),eval(""+cval+"id["+i+"]"));
              
         }
    }
    else
    {
         document.forms[strformname].country.length = 0;
         document.forms[strformname].country.options[0] = new Option('All Countries in selected region','');
         document.forms[strformname].country.disabled = true;     
    }
    
}
*/
  function getcountry(strformname, strSelection)
{
    var cval = document.forms[strformname].Region.options[document.forms[strformname].Region.selectedIndex].value;
    if (cval != '')
    {
         document.forms[strformname].country.disabled = false;
         document.forms[strformname].country.length = 0;
         
         var counter = 0
         document.forms[strformname].country.options[counter] = new Option('All Countries in selected region', '');
         document.forms[strformname].country.options[counter].selected = true;
         counter++
         document.forms[strformname].country.options[counter] = new Option('--------------------------------', '');
         counter++ 
         
         //If Global selected...
         if (cval == '0')
         {
           for(i=0;i<countryRegion.length;i++)
           {
             //Polulate the drop down list
             document.forms[strformname].country.options[counter] = new Option(countryDisplay[i],countryValue[i]);
             if (strSelection.toLowerCase() == countryValue[i].toLowerCase())
             {
                 document.forms[strformname].country.options[counter].selected = true;
             }
           counter++  
           }
         } else if (cval < 9) {//if main region selected
           for(i=0;i<countryRegion.length;i++) {
             //Populate the drop down list
             if (cval*10 <= countryRegion[i] && (cval*10)+10 > countryRegion[i]) {
               document.forms[strformname].country.options[counter] = new Option(countryDisplay[i],countryValue[i]);
               if (strSelection.toLowerCase() == countryValue[i].toLowerCase()) {
                 document.forms[strformname].country.options[counter].selected = true;
               }
               counter++;
             }
           }
         } else if (cval > 9) { //if region selected
           for(i=0;i<countryRegion.length;i++) {
             //Polulate the drop down list
             if (cval == countryRegion[i]) {
             document.forms[strformname].country.options[counter] = new Option(countryDisplay[i],countryValue[i]);
               if (strSelection.toLowerCase() == countryValue[i].toLowerCase()) {
                 document.forms[strformname].country.options[counter].selected = true;
               }
             counter++;
             }
           }
         }
         
    }
    else
    {
         document.forms[strformname].country.length = 0;
         document.forms[strformname].country.options[0] = new Option('All Countries in selected region','');
         document.forms[strformname].country.disabled = true;     
    }
    
}

function changeregion()
{
    var rval = document.frm.country.options[document.frm.country.selectedIndex].value;
    document.frm.country.options[0] = new Option("Select Region","0");
    for(j=0;j<document.frm.Region.length;j++)
    if(rval.indexOf(',') != -1)
    {
         rval = rval.split(',');
         for(j=0;j<document.frm.Region.length;j++)
         {
              if(document.frm.Region.options[j].value == rval[1])
              {
                   document.frm.Region.options[j].selected = true;
                   break;
              }               
         }
    }
}
