
if($('counter')!=undefined)
var pageId=$('counter').value;

function logoutProcess()
{
		logoutURI=base_url+'postajob/HuserLogoutPrcess/';
		var myAjax = new Ajax.Request(logoutURI, {method: 'post', 
				onComplete: function showResponse(response)
				{
					window.location.reload(true);
				}
		});
}

if(typeof($('userLogin'))!='undefined')
{
	Event.observe('userLogin', 'keypress', function(event) {
		if(event.keyCode==13)
		{
			var element = Event.element(event);
			if(element.tagName=='INPUT' || element.type=='button'  || element.type=='password')
			{
				huserHeaderLogin();
			}
		}
	});
}

function huserHeaderLogin()
{
	if(typeof($('huserHeaderLoginEmail'))!='undefined')
	{
		
		resetFormErrorBorderStyle("userLogin");
		loginEmail=$('huserHeaderLoginEmail').value;
		loginPassword=$('huserHeaderLoginPassword').value;
		
		str="";
		if(loginEmail=="")
		{str+=POSTAJOB.PROCESS142_LOGIN[0].ERROR;setErrorBoxBorder('huserHeaderLoginEmail');}
		else
		{
			if(validEmailAddress(loginEmail))
			{str+=POSTAJOB.PROCESS142_LOGIN[1].ERROR;setErrorBoxBorder('huserHeaderLoginEmail');}
		}
		
		if(loginPassword=="")
		{str+=POSTAJOB.PROCESS142_LOGIN[2].ERROR;setErrorBoxBorder('huserHeaderLoginPassword');}
		else if(loginPassword.length<6 || loginPassword.length>15)
		{str+=POSTAJOB.PROCESS142_LOGIN[3].ERROR;setErrorBoxBorder('huserHeaderLoginPassword');}
			
		if(str!="")
		{	
			showErrorPopup(DIVPOPUPWINDOW.TEXT[0].MSG,DIVPOPUPWINDOW.TEXT[1].MSG,str);
		}
		else
		{	
			headerLogin=base_url+'postajob/userHeaderLogin/'+varHexString('huserHeaderLoginEmail')+'/'+MD5(loginPassword)+'/'+pageId;
			var myAjax = new Ajax.Request(headerLogin, {method: 'post', 
					onComplete: function showResponse(response)
					{
						
						if(response.responseText=="loginerror")
						{
							strting=DIVPOPUPWINDOW.LOGIN_ERROR[2].MSG;
							str+=strting;
							showErrorPopup(DIVPOPUPWINDOW.LOGIN_ERROR[0].MSG, DIVPOPUPWINDOW.LOGIN_ERROR[1].MSG, str, DIVPOPUPWINDOW.LOGIN_ERROR[4].MSG, 'huserHeaderLoginEmail',  MD5(loginPassword), "loginerror");	
							str='';
						}
						else if(response.responseText=="account_disabled")
						{
							str+=DIVPOPUPWINDOW.ACCOUNT_DISABLED[2].MSG;
							showErrorPopup(DIVPOPUPWINDOW.ACCOUNT_DISABLED[0].MSG,DIVPOPUPWINDOW.ACCOUNT_DISABLED[1].MSG,str);
							str='';
						}
						else if(response.responseText=="loginfailed")
						{	
							if(typeof($('huserHeaderLoginEmail'))!='undefined')
							{	
								setErrorBoxBorder('huserHeaderLoginEmail');
								setErrorBoxBorder('huserHeaderLoginPassword');
								str+=POSTAJOB.PROCESS142_LOGIN[4].ERROR;
								showErrorPopup(DIVPOPUPWINDOW.TEXT[0].MSG,DIVPOPUPWINDOW.TEXT[1].MSG,str)
								str='';
							}
						}
						else 
						{	
							window.location.reload(true);
						}
					}
			});
			
		}
	}
}

// JavaScript Document
function userLogoutCounter(){
	var cookieTimer=0;
	var counterValue=0;
	var timerValue=0;
	var HfieldValue=parseInt($('counter').value);
	
	if(getCookie(pageId)!=null)
	{
		if(HfieldValue>=parseInt(getCookie(pageId)))
		{	counterValue=parseInt(getCookie(pageId));}
		else
		{	counterValue=HfieldValue+1;}
	}
	else
	{
		counterValue=parseInt(document.getElementById('counter').value);
	}
	
	setCookie(pageId,parseInt(counterValue+1));
	$('counter').value=parseInt(counterValue+1);

	
	timerValue=(parseInt(FILE.CONTENT[0].TIMER)*2);

	if($('counter').value>timerValue)
	{
		loginURI=base_url+'postajob/updateLoginStatus/'+pageId;
		var myAjax = new Ajax.Request(loginURI, {method: 'post', 
				onComplete: function showResponse(response)
				{
					//go to site main url when user is going to logout by the system timer
					window.location.href=SITE_URL;
				}
				
		});
	}
}

function updateLoginCurrentTime()
{
	if(typeof($('huserHeaderLoginEmail'))=='undefined')
	{
		loginURI=base_url+'postajob/updateLoginUserActiveTime/';
		var myAjax = new Ajax.Request(loginURI, {method: 'post', 
				onComplete: function showResponse(response)
				{	
					var logOutVariables=(response.responseText).split(' ----------------- ');
					if(logOutVariables[1]==0)
					{window.location.reload(true);}
				}
		});
	}
}
function accountDeactivationAlert(){
	showErrorPopup(POSTAJOB.HEADERLOGIN[0].ERROR,POSTAJOB.HEADERLOGIN[1].ERROR,POSTAJOB.HEADERLOGIN[2].ERROR);
}

function accountDeactivationAlertNewJob(){
	showErrorPopup(POSTAJOB.HEADERLOGIN[0].ERROR,POSTAJOB.HEADERLOGIN[1].ERROR," - Please activate your account before posting another job.");
}
