var bookmarkurl="http://www.irishjobs.ie"
var bookmarktitle="IrishJobs.ie Putting power in your hands?"
var strgLoc="";

function addbookmark(){
if (document.all)
window.external.AddFavorite(bookmarkurl,bookmarktitle)
}

function MM_openBrWindow(theURL,winName,features) 
{
  window.open(theURL,winName,features);
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function CheckJobCategories(IDCategory)
{
	if(IDCategory.options[0].selected == true)
	{
		for (var i = 1 ; i < IDCategory.options.length;i++)
		{
			IDCategory.options[i].selected=false;
		}
	}
	return false;
}

function CheckLocation(IDcboLocation,IDLocation,IDIsProvince)
{
	if (IDcboLocation.selectedIndex>0)
    {
		var tempArr
		var k=IDcboLocation.selectedIndex;
			
        tempArr=IDcboLocation.options[k].value.split(",") ;  //split the values
	
		IDLocation.value=tempArr[0]; //set the Location
		 
		if (tempArr[1]==0) 
		{IDIsProvince.value=0; } //set the province
		else
		{IDIsProvince.value=1;}
	}
}

function doValidation(IDRecruiter,IDCategory,IDLocation)
{
	if ( IDRecruiter.value=="none" )
	{
		//IDRecruiter.value="Company"
		alert("You must select a Recruiter Type.");
		return false;
	}
	if ( IDCategory.value=='' )
	{
		alert("You must select a Job Category.");
		return false;
	}	
	if ( IDLocation.value=="-1" )
	{
		IDLocation.value=0;
	}
}

function CheckJobCategoriesAdv()
{
	if(document.MAIN.Category.options[0].selected == true)
	{
		for (var i = 1 ; i < document.MAIN.Category.options.length;i++)
		{
			document.MAIN.Category.options[i].selected=false;
		}
	}
	return false;
}

function CheckLocationAdv()
{
     var r = document.MAIN.cboLocation.selectedIndex;
     var eSrc= window.event.srcElement;

      if (eSrc.value=="-999")
       {
        alert(" Please select any location[s] under it ");      
        document.MAIN.cboLocation.options[r].selected=false;
        return false;
       }  
       
	if(document.MAIN.cboLocation.options[0].selected == true)
	{
		for (var i = 1 ; i < document.MAIN.cboLocation.options.length;i++)
		{
			document.MAIN.cboLocation.options[i].selected=false;
		}
	}
 
 return false; 	
}

function ProcessLocation()
{
var tempArr ; 

         for (var i = 1 ; i < document.MAIN.cboLocation.options.length;i++)
  	   {
  	      	if (document.MAIN.cboLocation.options[i].selected)
		   { 
		     tempArr=document.MAIN.cboLocation.options[i].value.split("_") ;  //split the values
		     
		     if (tempArr[0]==0) // if  province then don't allow the other locations to be selected.
		     {
		       if (ValidateLocation(i)==false) //chk if non 0 value exist..
		         { 
 		           alert("You cannot choose Province and a County or Country..");
		           return false;
		           break;
		         }
		      }
		   }	   
	   }

	   //***** to check if the user has selected more than 3 locations
    
	var p=0;
    for (var k = 1 ; k < document.MAIN.cboLocation.options.length;k++)
  	    {
  	      	if (document.MAIN.cboLocation.options[k].selected)
		   { 
		      p=p+1;
		   }
		 }

      if (p>3)
	   {
          alert("You cannot choose more than 3 locations.");
		  return false;		           
	   }

 return true;   
}

function ValidateLocation(indexID) //chk if non 0 value exist..if province selected
{
var myArr ;

  for (var p = 1; p < document.MAIN.cboLocation.options.length;p++)
   {
   	if (document.MAIN.cboLocation.options[p].selected)
   	{

           if (indexID!=p)
            {
              myArr=document.MAIN.cboLocation.options[p].value.split("_");
              
              if (0!=myArr[0])
               { 
                 // alert("You cannot choose province and a location..");
                 return false;
                 break;
               }
            }
        }
  }

  return true;   
}

function SerializeLocation()
{
var q;
var myArr;

 for ( q = 1; q < document.MAIN.cboLocation.options.length;q++)
   {
   	if (document.MAIN.cboLocation.options[q].selected)
   	{
     
          myArr=document.MAIN.cboLocation.options[q].value.split("_");
              
           if (0==myArr[0])  //chk province..
           {
             document.MAIN.IsProvince.value=1; //make province =1 if prov selected
             AddLoc(myArr[1],q);
           }
           else
           {
             document.MAIN.IsProvince.value=0;
             AddLoc(myArr[0],q);
           }          
	 }	 
     }

     //remove the first comma if present..
     if (strgLoc.substr(0,1)==",")
     {
       strgLoc = strgLoc.substr(1,strgLoc.length);
     }
    document.MAIN.Location.value=strgLoc; //put the location into a hidden filed.
      
}

function AddLoc(pID,pSno)
{

      if (pSno==1)
     	   {
	     strgLoc =pID;
  	   }
          else
	   {
	    strgLoc=  strgLoc + "," + pID;
	   }
	   
}

function doValidationAdv()
{
	if ( document.MAIN.Recruiter.value=="none" )
	{
		document.MAIN.Recruiter.value="Company"
		//alert("You must select a Recruiter Type.");
		//return false;
	}
	if ( document.MAIN.Category.value=='' || document.MAIN.Category.value == 0 )
	{
		alert("You must select a Job Category.");
		return false;
	}
		if ( document.MAIN.employment.value=="99" )
	{
		document.MAIN.employment.value="0";
	}
	
	if ( document.MAIN.cboLocation.value=="-1" )
	{
		document.MAIN.Location.value=0;
	}


        if (ProcessLocation()==true)
        {        
           SerializeLocation();
        }
        else
        {
          return false;
        }
}

function setLangImageUrl() 
{
	var sHref = window.location.href;
	var host = window.location.host;
	var dir = sHref.substring(sHref.lastIndexOf(host));
	
	dir = dir.replace(host,"");

	if(sHref.indexOf("/irish/") != -1)
	{
		src = dir;
		src = src.replace("/irish","");
	}else{
		src = '/irish' + dir;
	}
	
	var pos = 9999;
	var num;

	for(num=0; num<document.links.length; num++) 
	{
		if (document.links[num].href.indexOf("irishlink") != -1) 
		{
			pos = num;
			num = 5000;
		}
	}

	if (pos!=9999) 
	{
		document.links[pos].href = src;
	}
}
