//This function will open the popup window containing the information for sorting the applications for
//particular job posting
function application_Sort_Help(obj) {	
   var mywindow = window.open ("application_sort_help.html",
  "ApplicationSortHelp","location=0,status=0,scrollbars=0,width=300,height=120,directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=0");
   	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}   
  mywindow.moveTo(curleft,curtop);
}

//This function will open the popup which cantain the information for efective search in case of advanced search.
function job_Search_Help(obj, lang) {

if ( lang != 'ar')
{	
   var mywindow = window.open ("job_Search_Help.html",
  "JobSearchHelp","location=0,status=0,scrollbars=0,width=350,height=200,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=0"); 
  mywindow.moveTo(300,300);
}
else
{
  var mywindow = window.open ("job_Search_Help_ar.html",
  "JobSearchHelp","location=0,status=0,scrollbars=0,width=550,height=200,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=0"); 
  mywindow.moveTo(300,300);

}
}

function resume_Search_Help(lang) {

if ( lang != 'ar')
{	
   var mywindow = window.open ("resume_Search_Help.html",
  "ResumeSearchHelp","location=0,status=0,scrollbars=0,width=350,height=200,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=0"); 
  mywindow.moveTo(300,300);
}
else
{
  var mywindow = window.open ("resume_Search_Help.html",
  "ResumeSearchHelp","location=0,status=0,scrollbars=0,width=550,height=200,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=0"); 
  mywindow.moveTo(300,300);

}
}


//This function will open the popup which conatin the information for job sorting.
function job_Sort_Help(obj) {	
   var mywindow = window.open ("job_Sort_Help.html",
  "JobSortHelp","location=0,status=0,scrollbars=0,width=300,height=120,directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=0");
   	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}   
  mywindow.moveTo(curleft,curtop);
}

//This function will open the popup to show complete company profile.
function more_Company_Profile(obj) {	
   var mywindow = window.open ("./jsp/moreCompanyProfile.jsp",
  "MoreCompanyProfile","location=0,status=0,scrollbars=0,width=500,height=350,directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=0"); 
  mywindow.moveTo(300,300);
}

//This function will open the popup which cantain the information for efective search in case of simple search.
function job_Simple_Search_Help(obj , lang) {
	if(lang != 'ar'	)
	{
   var mywindow = window.open ("job_Simple_Search_Help.html",
  "JobSearchHelp","location=0,status=0,scrollbars=0,width=350,height=200,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=0"); 
  mywindow.moveTo(300,300);
}
else
{
var mywindow = window.open ("job_Simple_Search_Help_ar.html",
  "JobSearchHelp","location=0,status=0,scrollbars=0,width=350,height=200,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=0"); 
  mywindow.moveTo(300,300);

}
}

//This function will open the popup to show complete company profile.
function view_More_Company_Profile(obj) {	
   var mywindow = window.open ("./moreCompanyProfile.jsp",
  "MoreCompanyProfile","location=0,status=0,scrollbars=0,width=500,height=350,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=0"); 
  mywindow.moveTo(300,300);
}



//This variable indicate the location from where the request came
var pageForResponse;
var suggestReq;
function changeValue(s) {
	  
	  //For simple search result page
      if(pageForResponse == 'sResult') {
      	document.getElementById("resultKeywords").value = s;
      }
       //For category search result page
      else if(pageForResponse == 'cSearch') {
      	document.getElementById("keywords").value = s;
      }
      //For index page ,simple search , advanced search , candidate home page 
      else {
      	document.getElementById("keyWords").value = s;
      }
      
      document.getElementById("suggestTD").style.display = "none";
}

function getXMLHttpRequest() {
     var xmlhttp=false;
     
     try {
     	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
     }
     catch (e) {
     	try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          }
          catch (E) {
            xmlhttp = false;
          }
     }
     
     if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
            xmlhttp = new XMLHttpRequest();
      }
      
     return xmlhttp;
}


function initRequest(pageName) {
return;
/*	  pageForResponse = pageName;
	  var s;
	  
	  //For simple search result 
	  if(pageName == 'sResult') {
	  s = document.getElementById("resultKeywords").value;
	  }
	  //For category search result page
	  else if(pageName == 'cSearch') {
	  s = document.getElementById("keywords").value;
	  }
	  //For index page ,simple search , advanced search , candidate home page 
	  else {
	  s = document.getElementById("keyWords").value;
	  }
	 
      if(s.length > 0)
      {
            var xmlhttp = getXMLHttpRequest();
            suggestReq = xmlhttp;
            xmlhttp.open("GET","searchSuggest.do?searchStr="+s,true);
            xmlhttp.onreadystatechange=handleSuggestions;
            xmlhttp.send(null);
      }
      else
      {
            document.getElementById("suggestTD").style.display = "none";
      }*/
}

function handleSuggestions() {
     if (suggestReq.readyState == 4) {
          var ss = document.getElementById('suggestTD')
          ss.innerHTML = "";
          var xml = suggestReq.responseXML;
          var root = xml.getElementsByTagName('suggestions').item(0);
          var suggestions = new Array();
          var cnt = 0;
          
          for (var i=0; i < root.childNodes.length; i++){
               var node = root.childNodes.item(i);
               if (node.childNodes.length > 0){
                    suggestions[cnt++] = node.childNodes.item(0).data;
               }
          }
          
          if(suggestions.length > 0) {
          	var list="<select id='sel' size='5' onclick='changeKeyWordValue()'>";
	          for(i=0; i < suggestions.length; i++) {
	                   var val = suggestions[i];
	                   if (val.length > 0) {
		 				   list+="<option value="+val+">"+val+"</option>";
	               }
	          }
	          list+="</select>";
	          ss.innerHTML = list;
          } else {
          	ss.innerHTML = "";
          }
          
     }
}


//This function will clear the value of division tag.
function clearSuggestion() {
	document.getElementById("suggestTD").innerHTML = "";
}


//This function will set the selected value from search suggest options
function changeKeyWordValue() {

	var selectedValue = document.getElementById("sel");
	var value = selectedValue.options[selectedValue.selectedIndex].text;
	
	//For simple search result page
      if(pageForResponse == 'sResult') {
      	document.getElementById("resultKeywords").value = value;
      }
       //For category search result page
      else if(pageForResponse == 'cSearch') {
      	document.getElementById("keywords").value = value;
      }
      //For index page ,simple search , advanced search , candidate home page 
      else {
      	document.getElementById("keyWords").value = value;
      }
}
