function processselection(citem) 
{
   //alert(citem.checked);
    var l_value;
    l_value = citem.checked?"Y":"N";

     if (citem.value=="D")
  	 document.AdvancedSearch.p_display_short_desc.value=l_value;
     else
         if (citem.value=="J")
        	 document.AdvancedSearch.p_display_related_jobroles.value=l_value;
         else
	         if (citem.value=="C")
                    document.AdvancedSearch.p_display_course_desc.value=l_value;
				   //alert(citem.value);
}
//------------------------------------------------------------------------------
function showHint()
{
   xmlHttp=GetXmlHttpObject();
   if (xmlHttp==null)
   {
        alert ("Your browser does not support AJAX!");
        return;
   }
   var url="/pls/web_prod-plq-dad/WEBREG_COURSE_SEARCH.get_countries";
   var con = new Array();
   for (var i = 0; i < document.AdvancedSearch.p_country.options.length; i++)
      if (document.AdvancedSearch.p_country.options[i].selected)
	     con[con.length] = document.AdvancedSearch.p_country.options[i].value;

    if(document.AdvancedSearch.p_country.options.length!=0)
    {    
        url=url+"?p_countries="+con;
        xmlHttp.onreadystatechange=stateChanged;
        xmlHttp.open("GET",url,true);
        xmlHttp.send(null);
    }
    else
        return null;
}
//------------------------------------------------------------------------------
function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
  {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  }
  catch (e)
  {
    // Internet Explorer
    try
    {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
   catch (e)
   {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
   }
  }
 return xmlHttp;
}
//------------------------------------------------------------------------------
function stateChanged()
{
    if (xmlHttp.readyState==4)
    {
        fillLocationCombo(xmlHttp.responseText);
    }
}

//------------------------------------------------------------------------------

function fillLocationCombo(strLocations) 
{
 var strArray = new Array();
 var strValueArray=new Array();
 var first_split=new Array();
 //We tokenize the string passed by parameter, so we separate the locations and the "#"
 first_split=strLocations.split("@&");
 var strtext=first_split[0];
 var strvalue=first_split[1];
 strArray = strtext.split("#");
 strValueArray = strvalue.split(",");
 var comboBox = document.getElementById("p_search_location");
 //First, we clean up the combo box...
 for (var i = comboBox.length - 1; i >= 0 ; i=i-1){
 	 comboBox.remove(i);
 }
 //Then, we filled it out with new values.
 //We go until length array minus 1, because we discard the last empty value
 for (var i = 0; i<strArray.length-1; i++) 
 {
 	 var choice = document.createElement("option");
         choice.className = "multipleSelectText";
         choice.value = strValueArray[i];
  	 choice.appendChild(document.createTextNode(strArray[i]));
	 comboBox.appendChild(choice);
 }
}

//------------------------------------------------------------------------------

function loadCountriesFromRegion() 
{   
    var regionCombo = document.getElementById("p_region");   
    var regionsArray = new Array();    
    for(i=0; i<regionCombo.options.length; i++) 
    {
      if(regionCombo[i].selected)
        regionsArray[regionsArray.length] = regionCombo.options[i].value;     
    }
    
   xmlHttp=GetXmlHttpObject();
   if (xmlHttp==null)
   {
        alert ("Your browser does not support AJAX!");
        return;
   }
   var url="/pls/web_prod-plq-dad/WEBREG_COURSE_SEARCH.get_countriesFromRegion";   
    url=url+"?p_regions="+regionsArray;
    xmlHttp.onreadystatechange=loadCountriesFromRegionReturn;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
    
}
//-----------------------------------------------------------------------------
function loadCountriesFromRegionReturn() 
{
    if (xmlHttp.readyState==4) 
    { 	  
		if (xmlHttp.status == 200) 
		{
				if (xmlHttp.responseText) 
				{					   		   
				   var xmlRes= parseXml(xmlHttp.responseText);				                                    
                                   var countryCombo = document.AdvancedSearch.p_country;                                   
                                   getComboBoxEmpty(countryCombo); 
                                   getComboBoxEmpty(document.getElementById("p_search_location"));
                                   
                                   for(i=0 ; i<xmlRes.getElementsByTagName("COUNTRY").length;i++)
                                   {				   
                                            var cOrgId=xmlRes.getElementsByTagName("ORG_ID")[i].firstChild.nodeValue;	   
                                            var cCountryName=xmlRes.getElementsByTagName("COUNTRY_NAME")[i].firstChild.nodeValue;
                                            var cOpt = document.createElement('option');
                                            cOpt.text=cCountryName;
                                            cOpt.value=cOrgId;     
                                            cOpt.className="multipleSelectText";                                                                                                             
                                            countryCombo.options[countryCombo.length]=cOpt;
                                            
                                   }
                                   if(countryCombo.length==1)
                                   {
                                        countryCombo.options[0].selected=true;
                                        showHint();
                                   }
				}		
	       }
    }
}

//-----------------------------------------------------------------------------
function parseXml(xml)
{
	var xmlDoc =null;
	if(document.implementation && document.implementation.createDocument) 
	{
	  domParser = new DOMParser();
	  xmlDoc = domParser.parseFromString(xml, "text/xml");
	}
	else 
	{
	  xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	  xmlDoc.async="false";
	  xmlDoc.loadXML(xml);
	}	 
	 return xmlDoc;
}
//------------------------------------------------------------------------------
function getComboBoxEmpty(comboBoxObj) 
{
   for (i = comboBoxObj.length - 1; i>=0; i--) 
    {    
      comboBoxObj.remove(i);
    }
}
//------------------------------------------------------------------------------
function isEmptyOrNoSelected(comboBox) 
{
  var is = false;  
  if(comboBox.options.length==0)
    is = true; 
  else 
  {
      for(var i=0; i < comboBox.options.length; i++) 
      {
           if(comboBox.options[i].selected) 
           {
                is = false; 
                break;
           }
           else
            is = true;
      }
  }
  return is;
}
//-----------------------------------------------------------------------------
function selectAll(comboId)
{
    var comboBox = document.getElementById(comboId);
	for(var i=0; i < comboBox.options.length; i++) 
    {
           comboBox.options[i].selected = true;           
    }
}

//-----------------------------------------------------------------------------
function validateForm() 
{
       var pCountry = document.getElementById("p_country");
       if(isEmptyOrNoSelected(pCountry)) 
       {
           
          var option = document.createElement("option");
          option.value = orgid;
          option.selected = "selected";
          pCountry.options[pCountry.options.length] = option;           
       }       
       document.AdvancedSearch.submit();
}
