﻿var DIVpositions;
var onNow = null;
var onNowState = false;
var sLastBackground = "BG_MatchBox_Row";
var somethingChanged = false;
var HotPositions = '0'
		
function ChooseRow(RowID)
{
	
	if ( getObj( onNow ) != null )
	   {
		 if ( RowID != onNow )
			{
				getObj( onNow ).className = sLastBackground
				sLastBackground = getObj( RowID ).className
				onNow = RowID;
				getObj( onNow ).className = "BG_Search_Row_HighLight";
				onNowState = true;
			}
		}
	else
	   {
		    sLastBackground = getObj( RowID ).className
			getObj( RowID ).className = "BG_Search_Row_HighLight";
			onNow = RowID;
			onNowState = true;
		}
				
}	

function JobDescription( PositionId , AlreadyMatched, withImage, CompanyId, JobDescJavascriptStr )
{
	setScrollPos();
	appendDatatToCookie(PositionId);
	//parent.window.scrollTo(0,0);
	var objTheForm = ''
	if (typeof(parent.document.theForm)=='object')
		objTheForm = parent.document.theForm
	else 
		objTheForm = document.theForm
		
	 document.hiddenForm.param.value = PositionId;
	 document.hiddenForm.JobDescJavascriptStr.value = JobDescJavascriptStr;

	 var windowName;
	 if(parent.NoBackground=='')
	 {
		win = window.open( "blank.html","JobDescription","toolbars=0,menubar=0,scrollbars=" +((isExplorer=true)?1:0) + ",directories=0,location=0,resizable=1,width=" + parent.popupJobsJobDescriptionWidth + ",height=450,left=30,top=30" );	 
		windowName = "'JobDescription'";
	 }
	 else
		windowName = "'_self'";
	
	 goToPage( "employee.jobDescription.init&NoBackground=" + parent.NoBackground + "&userId=" + objTheForm.userId.value + "&AlreadyMatched=" + AlreadyMatched + '&withImage=' + withImage + "&AffiliateID=" + objTheForm.AffiliateID.value + "&isValidSubscription=" + objTheForm.isValidSubscription.value + ((typeof(CompanyId)!='undefined')?"&CompanyId=" + CompanyId:""), windowName );
}

function CompanyDescription( CompanyID, PositionId )
{
	setScrollPos();
	win = window.open( "blank.html","CompanyDescription","toolbars=0,menubar=0,scrollbars=1,directories=0,location=0,resizable=1,width=" + parent.popupJobsJobDescriptionWidth + "px,height=530,left=30,top=1" );
	goToPage( "employee.companyDescription.init&param=" + CompanyID + "&compPositionId=" + PositionId , 'win.name' );
}

function ApplyToPos(PositionId,AnchorId,CompanyTypeId,isSendApply,IsOnlineUser)
{
	
	setScrollPos();
	Apply(PositionId,AnchorId,CompanyTypeId,isSendApply,IsOnlineUser);
}
function Apply(PositionId,AnchorId,CompanyTypeId,isSendApply,IsOnlineUser)
{
	
		if(getObj(AnchorId) != null)
			if(getObj(AnchorId).getAttribute('isApplied') == '1')
			{
				alert('You have already applied for this job.')
				return
			}

		
		document.hiddenForm.Managerial.value =document.theForm.Managerial.value
		document.hiddenForm.City.value = document.theForm.City.value
		document.hiddenForm.Field.value =document.theForm.Field.value
		document.hiddenForm.keyword.value = document.theForm.keyword.value

		var tmpNoBackground = null;
		var tmpPersSubscriptionInstallation = null;
		try
		{
			tmpNoBackground = parent.document.theForm.NoBackground.value;
			tmpPersSubscriptionInstallation = document.theForm.PersSubscriptionInstallation.value;
		}
		catch(e)
		{
			tmpNoBackground = NoBackground;
			tmpPersSubscriptionInstallation = PersSubscriptionInstallation;
		}

		if(tmpNoBackground==1)
			{
				document.hiddenForm.compPosId.value = PositionId
				if( tmpPersSubscriptionInstallation==1 || HotPositions=='1')

					if (document.theForm.ClientID.value == '' && HotPositions=='0')

						goToPage( 'employee.myCareer.init&isApply=1&isExternalApply=1&positionId=' + PositionId, "'_parent'" );				
					else					
						{
							var objTheFromTarget = "'_parent'"
							if(HotPositions=='1') objTheFromTarget = "'_self'"
							goToPage( 'employee.RMApplyLogin.createUser&isApply=1&isExternalApply=1&positionId=' + PositionId, objTheFromTarget );				
						}

				else
					goToPage( 'employee.communicate.init&isApply=1&isExternalApply=1&positionId=' + PositionId, "'_parent'" );				
			}
			else
			{				
								
				if( document.theForm.PersSubscriptionInstallation.value==1 && document.theForm.isValidSubscription.value!=1) // open subscription payment window
				{
					var params= 'isApply=1&positionId=' + PositionId + '&UserId=' + parent.document.hiddenForm.userId.value +  '&password=' + parent.document.hiddenForm.password.value + '&WhereToGoAfterTran=employee.communicate.init'
					win = window.open("blank.html","Subscribe","toolbars=0,menubar=0,scrollbars=1,directories=0,location=0,width=650,height=400");
					winName = win.name
					goToPage( 'employee.Subscribe.init&' + params , 'win.name' );
				}	
				else
				{
					if (CheckOnLineCompany(parent.document.theForm.userId.value,isSendApply,CompanyTypeId,IsOnlineUser) == false) return
					document.hiddenForm.compPosId.value = PositionId
					win = window.open( "blank.html","Popup","toolbars=0,menubar=0,scrollbars=1,directories=0,location=0,resizable=1,width=580,height=590,left=30,top=70" );
					goToPage( 'employee.communicate.init&isApply=1&positionId=' + PositionId + '&UserId=' + parent.document.hiddenForm.userId.value +  '&password=' + parent.document.hiddenForm.password.value, 'win.name' );
				}
			}	
}

function ApplyFromPosDesc(PositionId,AlreadyMatched,winName)
{	 
	if(AlreadyMatched == 1)
	{
		alert('You have already applied for this job')
		return
	}
	
	document.hiddenForm.Managerial.value =document.theForm.Managerial.value;
	document.hiddenForm.City.value = document.theForm.City.value;
	document.hiddenForm.Field.value =document.theForm.Field.value;
	document.hiddenForm.keyword.value = document.theForm.keyword.value;
			
	var objTheForm = '';
	var objTheFromTarget = "'_parent'";
			
	if (typeof(parent.document.theForm)=='object')
		objTheForm = parent.document.theForm;
	else 
	{
		objTheForm = document.theForm;
		objTheFromTarget = "'_self'";
	}
				
	if(parent.document.theForm.NoBackground.value==1)
	{			
		document.hiddenForm.compPosId.value = PositionId;
		if (document.theForm.ClientID.value == '' && HotPositions=='0')
		{
			document.hiddenForm.compPosId.value = PositionId;						
			goToPage( 'employee.communicate.init&isApply=1&isExternalApply=1&positionId=' + PositionId, objTheFromTarget );
		}
		else
		{
			document.hiddenForm.compPosId.value = PositionId;
			goToPage( 'employee.RMApplyLogin.createUser&isApply=1&isExternalApply=1&positionId=' + PositionId, objTheFromTarget );				
		}
						
	}
	else
	{								
		parent.document.hiddenForm.compPosId.value = PositionId;
		var page;
				
		if( document.theForm.PersSubscriptionInstallation.value==1 && document.theForm.isValidSubscription.value!=1) // open subscription payment window
		{
			page='employee.Subscribe.init&isApply=1&positionId=' + PositionId + '&WhereToGoAfterTran=employee.communicate.init';
			parent.document.forms['hiddenForm'].action = "c.asp?action=" + page + "";
		}	
		else
		{
			page='employee.communicate.init&isApply=1&positionId=' + PositionId;
			checkIfRematch( page );
			parent.document.forms['hiddenForm'].action = "c.asp?action=" + page + "";
		}	
		
		parent.document.hiddenForm.target=winName;
		parent.document.forms['hiddenForm'].submit();				
	}
}

function nextChunck()
{
	eraseCookie("scrollPos");
	var ChkNumber = new Number(document.theForm.ChunckNumber.value) + 1;
	parent.checkValidation(ChkNumber)
	createCookie("pagerPosition", ChkNumber, 0);
	document.theForm.submit();
}

function prevChunck()
{
	eraseCookie("scrollPos");
	var ChkNumber = new Number(document.theForm.ChunckNumber.value) - 1;
	if(ChkNumber == 0)
		ChkNumber = 1
	createCookie("pagerPosition", ChkNumber, 0);
	parent.checkValidation(ChkNumber)
}

function GoToChunck(ChkNumber)
{
	eraseCookie("scrollPos");
	eraseCookie("pagerPosition");
	createCookie("pagerPosition", ChkNumber, 0);
	
	parent.checkValidation(ChkNumber)
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function deleteCookies()
{
	eraseCookie("pagerPosition");
	eraseCookie("scrollPos");
}
		
function makePositionNoApplyable(PositionId)
{ 	
	getObj('Pos'+PositionId).isApplied = 1
}	

function setScrollPos()
{
	var scrollPosition;
	if (window.pageYOffset)
		scrollPosition = window.pageYOffset; 
	else if (parent.document.documentElement.scrollTop)
		scrollPosition = parent.document.documentElement.scrollTop; 
	else
		scrollPosition = parent.document.body.scrollTop;
	
	createCookie("scrollPos", scrollPosition, 0);
}

function scrollToPos()
{
	if(readCookie("scrollPos")!= null)
		parent.window.scrollTo(0,Number(readCookie("scrollPos")));
}

function appendDatatToCookie(posId)
{
	var posViewId = "";
	if(readCookie("ViewedPosition") != null)
	{
		posViewId = readCookie("ViewedPosition");
		posViewId = posViewId + "," + posId;
		createCookie("ViewedPosition", posViewId, 0);
	}
	else
	{
		posViewId += posId + ",";
		createCookie("ViewedPosition", posViewId, 0);
	}
}
function PaintPagesLink(CurrChunk,TotalCounter,TotalPageRow,Caller)
{						
			if(readCookie("pagerPosition")!=null)
				CurrChunk = readCookie("pagerPosition");
			var FC=1;
			var DefNumLink=5;
			var TC=5;
			var PC=1;
			var ChNum=1;
			var NeedNext=0;
			var NeedPrev=0;
			var NextChunk = parseInt(CurrChunk) + parseInt(PC);
			var PrevChunk = CurrChunk - PC
			var HTML="";			
					

			ChNum = parseInt(((CurrChunk -1) / DefNumLink)) +1;
			FC = ((ChNum - 1) * TC) + 1;			

							
			if(TotalCounter > (CurrChunk * TotalPageRow)) NeedNext=1;						

			if(CurrChunk > PC) NeedPrev=1;			
										    
		   	 TC=Math.ceil(((TotalCounter - (DefNumLink * TotalPageRow * (ChNum-1))) / TotalPageRow))		    
		   	 if (TC > DefNumLink) TC = DefNumLink;	    	 
		   	 
		   	 if (TC == 0){
		   	     return  HTML;
		   	 }		    		    	
			
		   	var ClassName = 'FNT_SearchHeader'
		   	if (Caller == 'Top') 
		   		ClassName = 'FNT_BlueSubBigTxt'

            var ClassName2 = 'FNT_SearchHeader'
		   	if (Caller == 'Top') 
		   		ClassName2 = 'FNT_WhiteUpperBigTxt'
			   			
			
			HTML += "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class='" + ClassName + "'>";
			HTML += "<tr>";						
			HTML += "<td><span class='" + ClassName2 + "'><b>Result Page:&nbsp;</b></span></td>"				
			if (NeedPrev==1)											
				HTML += "<td><a class='" + ClassName + "' href=\"javascript:GoToChunck(" + PrevChunk + ");\"><span class='FNT_WhiteUpperBigTxt'><b>&lt;&lt;&nbsp;Previous</b></span></a></td>"
			HTML += "<td><span class='" + ClassName2 + "'><b>&nbsp;[&nbsp;</b></span></td>"				
				for( var i = FC; i <=((ChNum -1)* DefNumLink)+ TC; i ++ )
				{	
					if (i == CurrChunk)
						TXD= 'none';
					else
						TXD = 'underline'; 						
					
					HTML += "<td><a href=\"javascript:GoToChunck('" + i + "')\" style=\"TEXT-DECORATION:" + TXD +  ";\" class='" + ClassName + "'><span class='" + ClassName2 + "'><b>" + i + "</b></span></a></td>"
					if (i < (((ChNum -1)* DefNumLink)+ TC)) HTML += "<td> &nbsp; </td>"
				}				       
			HTML += "<td><span class='" + ClassName2 + "'><b>&nbsp;]&nbsp;</b></span></td>"	
			if (NeedNext==1)							
				HTML += "<td><a class='" + ClassName + "' href=\"javascript:GoToChunck(" + NextChunk + ");\" class=\"FNT_BlackTxt10\"><span class='" + ClassName2 + "'><b>Next&nbsp;&gt;&gt;</b></span></a></td>"
			HTML += "</b></tr>";			
			HTML += "</table>";			
						

			return  HTML;
}

