
// History:
// 02-Jul-2002 JR  - portal version written by John Roden, KINSA
// 10-Jul-2002 JR  - moved this script into file /static/scripts/home_main.js
// 22-Jul-2002 JR - if language choice is rejected, set the language menu back again

// Purpose:
// Various service functions for the kompass.com home page.

   // define the addresses of the kompass.com servers
   url_kiserver = "/kinl/";
   url_adserver = "/kinl/";

   gs=0; 	// prevent multiple searches being started by "roller" button mice
		// being used to select the country.


function ki_eid(id) {
   // returns the DOM local element id for various browsers. It assumes
   // that browser detection code (browser_detect.js) has been included.
   // NB only elements with the id attribute set to id="id" can be found
   // with this function. Elements with only name="id" will be found in
   // Netscape V4 versions!

   // alert ("ki_eid:id="+id+"  browser: "+navigator.family);

   var eid;

   switch (navigator.family ) {

      case "ie3":
	  case "ie4":  // includes ie5 and ie6
      	 eid = eval("document.all."+id);    // node id in IE 5, 6
         break;

	  case "aol":
	  case "nn3":
	  case "nn4":
	     // element must have name="īd" in Netscape V4
	     eid = eval("document."+id);
		 if (!eid) {
            // search the forms for this value
		    var i = -1;
		    while (!eid && document.forms[++i] ) {
		       eid = eval("document.forms["+i+"]."+id);
			   }
			}
         break;
      case "opera":
	  case "gecko": // Mozilla, Netscape V6, V7  etc
	     eid = document.getElementById(id); // node id in W3C DOM (NS 6)
         if (!eid) {
   	         eid = document.getElementsByName(id);
 			 if (eid) 
 			    eid = eid.item(0);  // assume only one item with this name 
			} 
         break;

	  case "hotjava":
	  default:
	     alert ("Browser type not recognized: "+navigator.family);
		 break;
    } // switch

  // alert ("ki_eid:eid="+eid);

   if (eid)
      return eid;
   else
      // this is usually a developer error (it really is not there!)
      alert ("Element "+id+" not found in this document");
} // ki_eid()


function valid_keypress(e) {
	if  (e.keyCode == 13) {
		top.resize(3);
		ki_eid("Formulaire").submit();
		return(false);
	}
}

function valid_netscape(evnt) {
	if (evnt.which == 13) {
		top.resize(3);
		ki_eid("Formulaire").submit();
		return(false);
	}
}

function setLanguage (f) {

   var language, country, temp;
   // tell the control panel which language to set (it will change the page if necessary)

   temp  = f._Language.options[f._Language.selectedIndex].value;
   language = temp.substr(0,2);
   country  = "";	// Default value
   if (temp.substr(2,1) == "-")
       country  = temp.substr(3,2);
   //alert ("setLanguage():"+language + "-" + country);
   window.top.kiTopFrame.setPortal(language,country);

}

function setGuidedSearch (f) {

   var temp;
   temp  = "";	// Default value
   // tell the control panel which country to set (it will load the guided search)

   temp  = f._Zone.options[f._Zone.selectedIndex].value;
   //alert ("setGuidedSearch():"+ temp + " gs=" + gs);
   if (temp != "" && gs==0){
   	   gs=1;
	   f.submit();
	}
}

function initialise()
{
  setTimeout("window.top.kiTopFrame.MajPub('','')", 1000);

  if (navigator.appName == 'Netscape') {
        // these calls only work after the page is loaded
        ki_eid('_Username').onkeypress=valid_netscape;
        ki_eid('_Passwd').onkeypress=valid_netscape;
  }
}
