// -------------------------------------------------------------------
// Madgex Limited
// Copyright (c) 2003 Madgex Limited. All Rights Reserved.
// Site Wide Code 
// 05 Jun 2003
// Version 1.0
// -------------------------------------------------------------------


 function checkEnter(event, action)
 { 
//	var code = 0; 
//	if (NS4) 
//	{
//		code = event.which;
//	} 
//	else 
//	{
//		code = event.keyCode; 
//	}
//	if (code==13)
//	{ 
//		eval(action) 
//	}
 } 


function gonext(lPage)
{
	document.location.search = AddQueryString(document.location.search, 'nPage', parseInt(lPage))
}

function EmailMe()
{
	document.form2.action = '../EmailAlerts/AddJobAlert.aspx'
	document.form2.method = 'get';
	document.form2.submit();
}

function ValidateJobForm()
{
	var sEmail = document.form2.sEmailAddress.value.Trim();
	var sRecipientEmail = document.form2.sRecipientEmail.value.Trim();
	
	if ( sRecipientEmail == '' )
	{
		alert( "You must enter a recipient email address" );
		document.form2.sRecipientEmail.focus();
		document.form2.sRecipientEmail.select();
		return false;	
	}
	if ( !CheckValidEmail(sRecipientEmail) )
	{
		alert( "Invalid email address" );
		document.form2.sRecipientEmail.focus();
		document.form2.sRecipientEmail.select();
		return false;	
	}
	if ( sEmail == '' )
	{
		alert( "You must enter your email address" );
		document.form2.sEmailAddress.focus();
		document.form2.sEmailAddress.select();
		return false;	
	}
	if ( !CheckValidEmail(sEmail) )
	{
		alert( "Invalid email address" );
		document.form2.sEmailAddress.focus();
		document.form2.sEmailAddress.select();
		return false;	
	}
	return true;
}

function CheckValidEmail( sText )
{
	// Assumes sText is not empty
	var d = sText.split('@')

	if ( d.length != 2 )
	{
		return false;
	}
	else
	{
		var dom = d[1].split('.') ;
		
		if ( dom.length < 2 )
			return false;
	}
	
	return true;
}

function validEmail(item)
{
	if(item.indexOf('@') > 0)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function AddQueryString( sQuery, sName, sValue )
{
	//alert( 'query=' + sQuery + 'name=' + sName + 'value=' + sValue )
	sRes = StripQuery( sQuery, sName )

	//alert( 'strip=' + sRes )
	
	if ( sRes =='' || sRes =='?' )
		return '?'+sName + '=' + sValue
	else
		return sRes + '&' + sName + '=' + sValue
}

function StripQuery( sIn, sName )
{
	// write your own because different browsers do different things with regular expressions...
	
	var sincopy = sIn
	if ( sIn.substr(0,1) == '?' )
		sincopy = sIn.substr(1)
	
	var itms = sincopy.split( '&' )
	var res = ''

	for( var i=0; i< itms.length; i++ )
	{
		if (itms[i].substr(0, sName.length ) != sName )
		{
			if ( res.length > 0 )
				res += '&'

			res = res + itms[i]
		}
	}
	return res
}

function OpenJob(nJobID) 
{		
	document.location.search = AddQueryString(document.location.search, 'liJobID', parseInt(nJobID))
}

function openPage(sPage)
{
	document.location.href=sPage
}

function SubmitForm()
{
	document.form1.submit()
}	

function OpenPrintWin() {
	var strLocation = document.location.href;
	var objPrintWindow
	if (strLocation.indexOf("?") > 0){
		strLocation += "&display=print"
	}else{
		strLocation += "?display=print"
	}
	objPrintWindow = window.open(strLocation,"PrintWindow")
}

function OpenContactWin(sJobID) {
	var objContactWindow
	w = 450
	h = 390
	if (is.ie4up) h = 400
	if (is.nav6up) h = 400
	winleft = (screen.width - w) / 2
	wintop = (screen.height - h) / 2
	winprops = 'height=' +h + ',width=' + w + ',top=' + wintop + ',left=' + winleft + ',status=no,toolbar=no,menubar=no,location=no,status=no,resizable=no'
	objContactWindow = window.open("jobDetailContact.aspx?liJobID=" + sJobID, objContactWindow, winprops)
}

function OpenEmailWin() {
	var strLocation = document.location.href;
	var objEmailWindow
	w = 450
	h = 350
	if (is.ie4up) h = 360
	if (is.nav6up) h = 360
	winleft = (screen.width - w) / 2
	wintop = (screen.height - h) / 2
	if (strLocation.indexOf("?") > 0){
		strLocation += "&display=email"
	}else{
		strLocation += "?display=email"
	}
	winprops = 'height=' +h + ',width=' + w + ',top=' + wintop + ',left=' + winleft + ',status=no,toolbar=no,menubar=no,location=no,status=no,resizable=no'
	objEmailWindow = window.open(strLocation,"EmailWindow",winprops)
}

function OpenCVWin(uiCandidateID) 
{
	var objCVWindow
	var strLocation
	w = 1000
	h = 500
	winleft = (screen.width - w) / 2
	wintop = (screen.height - h) / 2
	strLocation = '../MyAccount/CVPage.aspx?uiCandidateID=' + uiCandidateID
	winprops = 'height=' +h + ',width=' + w + ',top=' + wintop + ',left=' + winleft + ',toolbar=no,status=no,menubar=yes,scrollbars=yes,location=no,status=no,resizable=yes'
	objCVWindow = window.open(strLocation,"CVWindow",winprops)
}

function CloseWindow()
{
	window.close();
}

String.prototype.IsWhiteSpace = function()
{
	return this == ' ' || this == '\t';
}

String.prototype.TrimLeft = function()
{
	var i=0;
	
	while (this.charAt(i).IsWhiteSpace())
		i++;
		
	return this.substr(i)
}

String.prototype.TrimRight = function()
{
	var i=this.length;
	
	while (this.charAt(i).IsWhiteSpace())
		i--;
		
	return this.substr(0,i+1)
}

String.prototype.Trim = function()
{
	return this.TrimLeft().TrimRight();
}
