/*
	Validate a form's elements according to varius attributes
*/

function nofollow(n, isNewWindow) {

	n = n.replace(/\^/, '@');
	n = n.replace(/\~/, 'mailto:');
	n = n.replace(/\`/, '.');
	n = n.replace(/\!/, 'http://');
	n = n.replace(/\++/, '.asp');

	if (isNewWindow == "false") {
		document.location.href = n;
	}
	else {
		window.open(n);
	}
}

function NoFollowOnMouseHover(menuRow) {
	if ((navigator.userAgent.indexOf("IE") != -1) && (menuRow.nodeName.toLowerCase() == "span")) {
		menuRow.style.color = "#FD5B0B";
	}	
	
}
function openPopupWindow(url, width, height) {
	win = window.open(url, 'Jobniton', 'menubar=1,resizable=0,scrollbars=1,status=1,width=' + width + ',height=' + height);
}

function NoFollowOnMouserOut(menuRow) {
	if ((navigator.userAgent.indexOf("IE") != -1) && (menuRow.nodeName.toLowerCase() == "span")
		 && (menuRow.style.fontFamily != "Arial,Verdana, Geneva, Arial, Helvetica, sans-serif")) {
		menuRow.style.color = "#037EAF";
	}
}

function validateForm(form, title, submit)
{
	var i, j, u, sum;
	var input;
	var valid;
	var sErrorMsg = "";

	//if (!title)
	//	title = "Please correct the following(s):";

	for (i=0; i<form.elements.length; i++)
	{
		input = form.elements[i];
		// skip input when it's not rendered (ie. parent display:none)
		if (input.offsetHeight == 0) continue;
		valid = true;

		// Validate value according to element type and validation type
		switch (input.type.toLowerCase())
		{
		case "text":
		case "password":
		case "textarea":
		case "file":
			if (!input.getAttribute("validation")) continue;
			if (input.getAttribute("mandatory"))
			{
				if (input.getAttribute("mandatory").toLowerCase() == "false" && input.value.length == 0) continue;
			}
			else
				continue;
			switch (input.getAttribute("validation").toLowerCase())
			{
			case "string":
				if (input.value.length == 0)
					valid = false;
				break;
			case "password":
				if (input.value.length == 0)
					valid = false;
				break;
			case "integer":
				if (!/\d+/.test(input.value))
					valid = false;
				break;
			case "email":
				if (!/^[\w\.\-]+@[\w\-]+(\.\w+)+$/.test(input.value))
					valid = false;
				break;
			case "phone":
				if (!/^\+?\d+(-\d+)*$/.test(input.value))
					valid = false;
				break;
			case "id":
				j = input.value.toString();
				input.value = j.replace(/\D/g, "");
				if (/\d+/.test(input.value))
				{
					sum = 0;
					for (j=0; j<input.value.length; j++)
					{
						u = (j % 2 ? 2 : 1) * parseInt(input.value.charAt(input.value.length - j - 1));
						sum += u > 9 ? Math.floor(u / 10) + u % 10 : u;
					}
					if (sum % 10) valid = false;
				}
				else
					valid = false;
				break;
			case "compare":
				// Check the compareInput attribute
				if (input.getAttribute("compareInput"))
					if (input.value != form.elements[input.getAttribute("compareInput")].value)
						valid = false;
			}

			// Validate max and min according to validation type
			if (valid == true)
			{
				switch (input.getAttribute("validation").toLowerCase())
				{
				case "integer":
					if (input.getAttribute("validmax"))
					{
						if (parseInt(input.value) > parseInt(input.getAttribute("validmax")))
							valid = false;
					}
					if (input.getAttribute("validmin"))
					{
						if (parseInt(input.value) < parseInt(input.getAttribute("validmin")))
							valid = false;
					}
					break;
				default:
					if (input.getAttribute("validmax"))
					{
						if (input.value.length > input.getAttribute("validmax")) valid = false;
					}
					if (input.getAttribute("validmin"))
					{
						if (input.value.length < input.getAttribute("validmin")) valid = false;
					}
					break;
				}
			}
			break;
		case "select-one":
			if (input.getAttribute("mandatory"))
				if (input.selectedIndex == 0)
					valid = false;
			break;
		case "select-multiple":
			if (input.getAttribute("mandatory"))
			{
				sum = 0;
				for (j=0; j<input.options.length; j++)
				{
					if (input.options[j].selected) sum++;
				}
				if ((!input.getAttribute("validmax")) && (!input.getAttribute("validmin")))
				{
					if (sum == 0) valid = false;
				}
				else
				{
					if (input.getAttribute("validmax"))
					{
						if (sum > input.getAttribute("validmax")) valid = false;
					}
					if (input.getAttribute("validmin"))
					{
						if (sum < input.getAttribute("validmin")) valid = false;
					}
				}
			}
			break;
		case "checkbox":
			if (input.getAttribute("mandatory"))
				if (!input.checked)
					valid = false;
			break;
		}

		if (!valid)
		{
			if (input.getAttribute("validationError"))
				sErrorMsg += input.getAttribute("validationError") + "\n";
			else
				sErrorMsg += "Error in field " + input.name + "\n";
		}
	}
	if (sErrorMsg.length)
	{
		alert((title ? title + "\n" : "") + sErrorMsg);
		return false;
	}
	else
	{
		if (submit)
			form.submit();
		return true;
	}
}

function chng_pic(pic_location,pic)
{
	document[pic_location].src=pic
}

function swapImage(img)
{
	var src = img.getAttribute("overSrc");
	img.setAttribute("overSrc", img.src);
	img.src = src;
}

Date.prototype.toLongString = function()
{
	return this.getDate().toString().pad("0", 2) + "/" + (this.getMonth()+1).toString().pad("0", 2) + "/" + this.getFullYear() + " " + this.getHours().toString().pad("0", 2) + ":" + this.getMinutes().toString().pad("0", 2) + ":" + this.getSeconds().toString().pad("0", 2);
}

Date.prototype.toShortString = function()
{
	return this.getDate().toString().pad("0", 2) + "/" + (this.getMonth()+1).toString().pad("0", 2) + "/" + this.getFullYear();
}

Date.prototype.toShortStringUTC = function()
{
	return this.getUTCDate().toString().pad("0", 2) + "/" + (this.getUTCMonth()+1).toString().pad("0", 2) + "/" + this.getUTCFullYear();
}

Date.prototype.toLongStringUTC = function()
{
	return this.getUTCDate().toString().pad("0", 2) + "/" + (this.getUTCMonth()+1).toString().pad("0", 2) + "/" + this.getUTCFullYear() + " " + this.getUTCHours().toString().pad("0", 2) + ":" + this.getUTCMinutes().toString().pad("0", 2) + ":" + this.getUTCSeconds().toString().pad("0", 2);
}


String.prototype.pad = function(char, length)
{
	var i = length - this.length;
	var ret = "";
	for (j=0; j<i; j++)
		ret += char;
	return ret + this;
}


//Cookies Functions////////////////
function setCookie(name, value, years) { 

	if (!years) years = 10; // default to 1 day if empty 

	var expdate = new Date(); 
	expdate.setTime(expdate.getTime() + years*365*24*60*60*1000); 

	document.cookie = name + "=" + value + "; expires=" + expdate.toGMTString(); 
} 

function getCookie(name)
{//alert(document.cookie);
	var cname = name + "=";
	var startOfCookie = document.cookie.indexOf(cname)
	var endOfCookie;
	if (startOfCookie != -1){
		startOfCookie += cname.length; // skip past cookie name
		endOfCookie = document.cookie.indexOf(";", startOfCookie);
		if(endOfCookie != -1)
			return document.cookie.substring(startOfCookie, endOfCookie);
		else
			return document.cookie.substring(startOfCookie, document.cookie.length);
	}
	return null;
	
}


function getCookieDate(name)
{//alert(document.cookie);
	var cname = name + "=";
	var startOfCookie = document.cookie.indexOf(cname)
	var endOfCookie;
	if (startOfCookie != -1){
		startOfCookie += cname.length; // skip past cookie name
		endOfCookie = document.cookie.indexOf(";", startOfCookie);
		if(endOfCookie != -1)
			return document.cookie.substring(startOfCookie, document.cookie.length);
		else
			return document.cookie.substring(startOfCookie, document.cookie.length);
	}
	return null;
	
}




function eraseCookie(name)
{
	setCookie(name,"",-1);
}


function IsDate(P_Date)
{
  var maxDaysInMonth;

  // ---------------------------------------- //
  // 1. Parse and validate date-part strings, //
  //    and get their numeric values.         //
  // ---------------------------------------- //
 
  // if no slash in string, or if only one slash in string,
  // or if first character is a slash, or if last character is a slash,
  // date is bigger then ten charecters return false
  
  if((P_Date.indexOf('/') == -1) || (P_Date.indexOf('/') == P_Date.lastIndexOf('/')) || 
	(P_Date.indexOf('/') == 0) || (P_Date.indexOf('/') == (P_Date.length - 1)) || (P_Date.length > 10))
	return false;


 //--- Get day value ---

  // get day string (the charcters before the first slash)
  var dayString = P_Date.substring(0 ,P_Date.indexOf("/"));

  var numberOfDigitsInDay = dayString.length;
  
  //Check if day is 1 or 2 digit
  if((numberOfDigitsInDay > 2) || (numberOfDigitsInDay == 0))
	return false;
	
  //Check if day is not numeric or the day is 0 or 00.
  if ((isNaN(dayString) == true) || (dayString == "0") || (dayString == "00"))
	return false;
	
 // parse day string to get day number
  var dayNumber = dayString*1;
  

   // --- Get month value ---

  // get month string (the charcters after the first slash and before the second slash)
  var monthString = P_Date.substring(P_Date.indexOf("/") + 1, P_Date.lastIndexOf("/"));

 var numberOfDigitsInMonth = dayString.length;
  
  //Check if month is 1 or 2 digit
  if((numberOfDigitsInMonth > 2) || (numberOfDigitsInMonth == 0))
	return false;
	
  //Check if day is not numeric or the month is 0 or 00.
  if ((isNaN(monthString) == true) || (monthString == "0") || (monthString == "00"))
	return false;
	
  // parse month string to get month number
  var monthNumber = monthString*1;
  

  
  // --- Get year value ---

  // get year string (the charcters after the second slash)
  var yearString = P_Date.substring(P_Date.lastIndexOf("/") + 1, P_Date.length);

  var numberOfDigitsInYear = yearString.length

  
  //Check if the year in date is 4 digits. 
  if(numberOfDigitsInYear != 4) 
	  return false;

//if the first digit is 0.
  if((numberOfDigitsInYear == 4) &&(yearString.substring(0,1)=="0"))
	return false;


 //Check if year is not numeric or the year is 0000.
  if ((isNaN(yearString) == true)|| yearString == "0000")
	return false;
	
  var yearNumber = yearString*1;




  // --------------------------------------- //
  // 2. Validate date-part values according  //
  //    to calendar rules.                   //
  // --------------------------------------- //

  
  // validate month (should be between 1 - 12)
  if((monthNumber > 12) || (monthNumber < 1))
	return false;
					

  // validate day according to month and year
  switch(monthNumber)
  {
	case 1:
	case 3:
	case 5:
	case 7:
	case 8:
	case 10:
	case 12:
	maxDaysInMonth = 31;
	break;
 
	case 4:
	case 6:
	case 9:
	case 11:
	maxDaysInMonth = 30;
	break;
									
	case 2:
	// check if year can be divided by 4
	if((yearNumber / 4) == (parseInt(yearNumber / 4)))
	  maxDaysInMonth = 29;
	else
	  maxDaysInMonth = 28;


	// check if year can be divided by 100
	if((yearNumber / 100) == (parseInt(yearNumber / 100)))
	  maxDaysInMonth = 28;
											   

	// check if year can be divided by 400
	if((yearNumber / 400) == (parseInt(yearNumber / 400)))
	  maxDaysInMonth = 29;                                   

	break;
  }


  // day should be between 1 - maxDaysInMonth
  if((dayNumber > maxDaysInMonth) || (dayNumber < 1))
	return false;


  // ------------------------------------------
  // if we got here than string represents a valid date, return true
  return true;

}
															
/////////////////////////////////////

function GeatherPositionsToViewAndSend()
{
 
  window.open("PositionResults.aspx?type=JobBasketNew");

}

// add or remove position from basket in a page of SearchIndex.aspx
function addRemovePositionArrays(chk, BasketType)
{
  try{
				if (document.cookie != "") 
				{
					var positionsCookieName = "BasketQNew";
					var positionsCookie = getCookie(positionsCookieName);
					if(!positionsCookie)
						setCookie(positionsCookieName, chk.value, 10)
					else
					{
					
						if(chk.checked)
							addPositionArrays(chk.value, positionsCookie, positionsCookieName);
						else
							removePositionArrays(chk.value, positionsCookie, positionsCookieName);
					}
					
					var choicesCookieName = "BasketRememberChoices";
					var choicesCookie = getCookie(choicesCookieName);
					if(!choicesCookie)
						setCookie(choicesCookieName, chk.value, 10)
					else
					{
						if(chk.checked)
							addPositionArrays(chk.value, choicesCookie, choicesCookieName);
						else
							removePositionArrays(chk.value, choicesCookie, choicesCookieName);
					}
				}
			}
			catch (ex)
			{
				alert(ex.message);
			}
}

		function addPositionArrays(value, positionsCookie, BasketType)
		{
			var positions=null;
			var arrPositions = positionsCookie.split(',');
			for(var i=0; i<arrPositions.length; i++)
				if(parseInt(arrPositions[i]) == parseInt(value))
					return;
			
			setCookie(BasketType , value + "," + positionsCookie, 10)
		}
		
		function removePositionArrays(value, positionsCookie, BasketType)
		{
			var flag=false;
			var positions="";
			
			var arrPositions = positionsCookie.split(',');
			var arrPositionFordelete=value.split(',');
			//alert(arrPositions.length);
			
			for(var i=0; i<arrPositions.length; i++)
			{
				  flag=false;
			  for( j=0; j<arrPositionFordelete.length; j++)
			  {
				if(parseInt(arrPositions[i]) == parseInt(arrPositionFordelete[j]))
				{
				   flag=true;
					
				}
			  }
			  if(flag==false)
				 positions += parseInt(arrPositions[i]) + ",";
			  
			}
		   // alert(positions);
					
			if(positions)
			{
			   // eraseCookie("BasketQNew");
				setCookie(BasketType, positions.substring(0, positions.length-1), 10)
			}
			else
				eraseCookie(BasketType);
					
		}
		//===================end of add or remove position from basket in a page of SearchIndex.aspx
		
		
		function addRemovePosition(chk,BasketType)
		{
		   var Basket="";
			 switch(BasketType)
			{
			case "JobBasket":
				Basket="BasketQ";
				break;
			case "JobBasketNew":
				Basket="BasketQ";
				break;
			case "JobBasketSentCV":
				Basket="BasketSentCV";
				break;
			default:
				Basket="BasketQ";
				
			}
		  // alert(Basket);
		   
			 
			try{
			
				if (document.cookie != "") {
					var positionsCookie = getCookie(Basket);
					
					if(!positionsCookie)
						setCookie(Basket, chk.value, 10)
					else
					{	
					
						if(chk.checked)
							addPosition(chk.value, positionsCookie,Basket);
						else
							removePosition(chk.value, positionsCookie,Basket);
					}
				}
			}
			catch (ex)
			{
				alert(ex.message);
			}
			//alert(getCookie("BasketQ"));
		}
		function addPositionBasketSentCV(obj,id,RedirectStringWithParam)
		{
			var Basket="BasketSentCV";
			var PositionObj= document.getElementById("Input"+id);
			try{
				if (document.cookie != "") 
				{
				   var positionsCookie = getCookie(Basket);
						if(!positionsCookie)
							setCookie(Basket, PositionObj.value, 10)
						else
						{	
						
							  if(isPositionAlreadyinList(Basket,PositionObj.value)!=true)
								  {
								  
									   addPosition(PositionObj.value, positionsCookie,Basket);
									   
								  }
						}
				}
			}
			catch (ex)
			{
				alert(ex.message);
			}
			
			if(obj)
			obj.style.color = '#800080';

						window.open(RedirectStringWithParam,'cvWindow','top=50,left=200,height=480,width=700,resize=yes,scrollbars=yes,toolbar=no,location=no,menubar=no,status=no');
			return false;
			//parent.location.refresh();
			
		}
		function  isPositionAlreadyinList(Basket,PositionID)
		{
			var positionsCookie = getCookie(Basket);
		  
			var Positins = positionsCookie.split(',');
		
			for (i = 0; i < Positins.Length; i++)
			{
				if (Positins[i] == PositionID)
					return true;
			}
			return false;

		}
		function addPosition(value, positionsCookie,BasketType)
		{
		
			var positions=null;
			var arrPositions = positionsCookie.split(',');
			for(var i=0; i<arrPositions.length; i++)
				if(parseInt(arrPositions[i]) == parseInt(value))
					return;
			
			setCookie(BasketType, value + "," + positionsCookie, 10)
		}
		
		function removePosition(value, positionsCookie,BasketType)
		{
			//alert("removePosition "+BasketType);
			var positions="";
			var arrPositions = positionsCookie.split(',');
			for(var i=0; i<arrPositions.length; i++)
				if(parseInt(arrPositions[i]) != parseInt(value))
					positions += parseInt(arrPositions[i]) + ",";
					
			if(positions)
				setCookie(BasketType, positions.substring(0, positions.length-1), 10)
			else
			{
				eraseCookie(BasketType);
				//alert("after eraseCookie");
			}
					
		}
		//delete all positions from the basket and refreshed the page
		function RemoveAllBasketPositions(BasketType) 
		{
			switch(BasketType)
			{
			case "JobBasket":
				eraseCookie("BasketQ");
				//alert(getCookie("BasketQ") );
				break;
			case "JobBasketNew":
				eraseCookie("BasketQNew");
			   // alert(getCookie("BasketQNew") );
				break;
			case "JobBasketSentCV":
				eraseCookie("BasketSentCV");
			   // alert( getCookie("BasketSentCV"));
				break;
				
				default:
				;
			}
			document.location = document.location.href;
		
		}
		function PositionsSelected()
		{
		
		  var inputArray=document.getElementsByTagName("input");
		  //alert(inputArray.length);
		  for( i=0; i<inputArray.length; i++)
		  {
			if(inputArray[i].id=="positions")
			{
			   if(inputArray[i].checked ==true)
			   {
			   //alert("true");
				  return true;
			   }
			}
		  }
		  return false;
		}

function GetMultiplySavechoiceCookies()
{               					 
var Obj= document.getElementById("tip");
var GetMultiplySavechoiceCounter=0;
GetMultiplySavechoiceCounter = getCookie("MultiplySavechoiceCounter");      					            
var tip=0; 
if(GetMultiplySavechoiceCounter==null || GetMultiplySavechoiceCounter=="50")       
{
 tip=2;           
 GetMultiplySavechoiceCounter=0;
}
 GetMultiplySavechoiceCounter=parseInt(GetMultiplySavechoiceCounter) + 1 ;                		                                                                     					               
 setCookie("MultiplySavechoiceCounter",GetMultiplySavechoiceCounter , 10);      				          
 GetMultiplySavechoiceCounter = getCookie("MultiplySavechoiceCounter");      					             
  if (tip==2)
 displayTip("")
 else
 displayTip("none") 
}

function displayTip(action)
{
var Obj= document.getElementById("tip");
if(Obj)
Obj.style.display=action;    
}
//==================================================================================================================
function checkposition()
{
	if (getCookie("BasketRememberChoices")==null)
		return;
	var ifCheck=false;            
	var ChoicesCookie= getCookie("BasketRememberChoices").split(",");
	var positionsCb = document.getElementsByName("positions");
	var cookieHash = makeCookieHash(ChoicesCookie);
	for(i = 0 ; i < positionsCb.length && i < 100; i++)
	{
	    ifCheck = checkIfSelect(cookieHash, positionsCb[i].value);      
	   positionsCb[i].checked=ifCheck;
	   if(ifCheck)
	   {
			var positionsCookie = getCookie("BasketQNew");
			if(!positionsCookie)
				setCookie("BasketQNew", positionsCb[i].value, 10)
			else
			{	
				addPositionArrays(positionsCb[i].value, positionsCookie, "BasketQNew");
			}
	   }                      
	 }
  }
//================================================================================================================== 
   function checkIfSelect(cookieHash, cboxPositions)
   {
       var cboxArray = cboxPositions.split(',');

		for(var i = 0; i < cboxArray.length && i < 100; i++)
		{
			if(cookieHash[cboxArray[i]] != true)
			{
				return false;
			}
		}
		
		return true;
   }
//==================================================================================================================         
function makeCookieHash(ChoicesArray)
{
	var hash = new Object();
	for (var i = 0; i < ChoicesArray.length; i++)
	{    
		hash[ChoicesArray[i]] = true;
	}
	return hash;
}

function trim(str) 
{
	return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}
function setTitle() {
	if ((!(typeof (autoSendCV) == 'undefined')) && autoSendCV) {
		var elem = document.getElementById('linkr' + posID);
		if (elem) {
			elem.onclick();
		}
		else {
			elem = document.getElementById('linkEmail');
			if (elem) {
				elem.onclick();
			}
		}
	}
}
function ParenHistory() {
	window.history.back();
}
//The function clears all the checked checkbox on the page.
function ClearCheckBox() {

	for (var i = 0; i < document.getElementsByTagName("INPUT").length; i++) {
		if (document.getElementsByTagName("INPUT")[i].checked) {
			document.getElementsByTagName("INPUT")[i].checked = false;
		}
	}
}

//changes the cursor's style when mouseover and restore to regular when mouseout.
function SetCursor(obj, flag) {

	if (flag) {
		obj.style.cursor = "hand";
	}
	else {
		obj.style.cursor = "";
	}
}
//checks the selection of atleast one area.
//if atleast one was selected it returns true.
//if none was selected it returns false;
function ValidateAreaSection() {

    var bChecked = false;
	for (var i = 0; i < document.getElementsByName("checkArea").length; i++) {
	    if (document.getElementsByName("checkArea")[i].checked == true) {
			bChecked = true;
		}

	}
	return bChecked;

}

// does some funky things (just like areasection)
function ValidateExtentSection() {
    var bChecked = false;
	for (var i = 0; i < document.getElementsByName("checkExtent").length; i++) {
	    if (document.getElementsByName("checkExtent")[i].checked == true) {
			bChecked = true;
		}

	}
	return bChecked;
}

//checks the selection of atleast one professional field.
//return true if atleast on pro. field was selected, otherwise return false.
function validateProfessionalFieldSelection() {

	var bChecked = false;

	for (var i = 0; i < document.getElementsByName("checkProfessionals").length; i++) {
	    if (document.getElementsByName("checkProfessionals")[i].checked == true) {
			bChecked = true;
		}
	}
	return bChecked;

}
function trimAll(sString) {

	while (sString.substring(0, 1) == ' ') {
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length - 1, sString.length) == ' ') {
		sString = sString.substring(0, sString.length - 1);
	}
	return sString;
}

function SetExtentCookie() {
	var strExtents = "";
	for (var i = 0; i < document.getElementsByName("checkExtent").length; i++) {
	    var element = document.getElementsByName("checkExtent")[i];
		if (element.checked)
			strExtents += element.value + ",";
	}
	// delete the last comma
	strExtents = strExtents.substring(0, strExtents.length - 1);
	setCookie("ExtentsList", strExtents, 10);
	return strExtents;
}
function AreAllExtentsChecked() {
	var bChecked = true;
	for (var i = 0; i < document.getElementsByName("checkExtent").length; i++) {
	    if (document.getElementsByName("checkExtent")[i].checked == false) {
			bChecked = false
		}
	}
	return bChecked;
}


//the function check if a professional field has sub categories and check/uncheck them
function CheckSubCategories(sId) {

	var iCounter;
	var bFlag;
	var sTempId;
	if (document.getElementById("checkProfessionals" + sId).checked) // get on/off status of operation
	{
		bFlag = true;
	}
	else {
		bFlag = false;
	}

	var cbTemp;
	var arrCheckProfessionals = document.getElementsByName("checkProfessionals");
	for (iCounter = 0; iCounter < arrCheckProfessionals.length; iCounter++) {
		cbTemp = arrCheckProfessionals[iCounter]; //document.all["checkProfessionals"][iCounter];
		sTempId = cbTemp.id;

		var ar = sTempId.split('_');
		if (ar[0] + "_" + ar[1] == "checkProfessionals_" + sId) {
			if (bFlag) {
				cbTemp.checked = true;
			}
			else {
				cbTemp.checked = false;
			}
		}

	}
}

//check/uncheck the parent checkbox according to his sun(a sub category of professional field) value.
function CheckParent(sIDSun, sIDParent) {
	//alert("sIDSun "+sIDSun);
	//alert("sIDParent "+sIDParent);

	var iCounter;
	var bFlagAllChecked = true;
	var sTempId;

	//uncheck
	if (document.getElementById("checkProfessionals_" + sIDParent + "_" + sIDSun).checked == false) {
	    document.getElementById("checkProfessionals" + sIDParent).checked = false;
	}
	else {//if all subcategories are checked , then check the father
		var cbTemp;
		var arrCheckProfessionals = document.getElementsByName("checkProfessionals"); // all elements
		for (iCounter = 0; iCounter < arrCheckProfessionals.length; iCounter++) {
			cbTemp = arrCheckProfessionals[iCounter];
			sTempId = cbTemp.id;
			var ar = sTempId.split('_');
			if (ar[0] + "_" + ar[1] == "checkProfessionals_" + sIDParent) {//found a sun
				if (cbTemp.checked == false) {
					bFlagAllChecked = false;
				}
			}
		}
		if (bFlagAllChecked == true) {
		    document.getElementById("checkProfessionals" + sIDParent).checked = true;
		}
		else {
		    document.getElementById("checkProfessionals" + sIDParent).checked = false;
		}

	}

}

//the function set the color of a link to purple
function ChangeLinkColor(oLink) {

	if (oLink != null) {
		oLink.style.color = "purple";
	}
}


//=====================================================================================================			
function SetMultiplSaveychoice(oBj) {


	if (oBj.checked)
		document.getElementById("MultiplySavechoice").disabled = false;
	else {
		document.getElementById("MultiplySavechoice").disabled = true;
		document.getElementById("MultiplySavechoice").checked = false;
	}
}
function hideDatePicker() {
	$("#datepicker").hide('slow');
	$("#CalandarSpan")[0].disabled = false;
}


//checks the selection of atleast one area.
//if atleast one was selected it returns true.
//if none was selected it returns false;
function ValidateAreaSelection() {

    var bChecked = false;
	for (var i = 0; i < document.getElementsByName("checkArea").length; i++) {
	    if (document.getElementsByName("checkArea")[i].checked == true) {
			bChecked = true;
		}

	}
	return bChecked;

}
function getDisplayMode() {
	var answer = "";
	for (i = 0; i < document.getElementsByName("displayRad").length; i++)
		if (document.getElementsByName("displayRad")[i].checked == true)
			answer = document.getElementsByName("displayRad")[i].value;

	return answer;
}

function SearchByCompany(CompanyID) {
	document.location.href = 'CompanyResults.aspx?CompanyID=" + CompanyID + "'
}

function openPositionsForProf(NumberOfProfField, TotlalNumberOfSubProfFields, siteURL) {
    var ProfStr = "";
    if (isNaN(NumberOfProfField - 0)) {
        //NumberOfProfField = (NumberOfProfField + "").substring(0, NumberOfProfField.length - 1);
        var arr = NumberOfProfField.split(",");
        for (var i = 0; i < TotlalNumberOfSubProfFields; i++) {
            if ($.inArray(i.toString(), arr) != -1) { ProfStr += "1"; }
            else { ProfStr += "0"; }
            //if (arr.indexOf(i.toString())) ProfStr = +"1";
            //else ProfStr += "0";
        }
    }
    else {
        for (var i = 0; i < TotlalNumberOfSubProfFields; i++) {
            if (i == NumberOfProfField) ProfStr += "1";
            else ProfStr += "0";
        }
    }
    var URL = siteURL + "/PositionResults.aspx?searchPage=SearchIndex.aspx&checkProfessionals=" + ProfStr + "&PositionType=0&displayRad=fullView&savechoice=false#BackToTop";
    window.open(URL, '_self');
}

