// JavaScript Document

function myPass() {
		document.getElementById('password_fake').style.display='none';
		document.getElementById('password').style.display='inline';
		document.getElementById('password').focus();
}


// start navigation js

function myNav()
{
	var list = document.getElementsByTagName('a');
	for (i = 0; i < list.length; i++)
	{
		if ((list[i].className == 'nav1') && (location.pathname.length <= 1))
		{
			list[i].className = 'redLink';
		}
		if ((list[i].className == 'nav2') && (location.href.indexOf("about-us") != -1))
		{
			list[i].className = 'redLink';
		}
		if ((list[i].className == 'nav3') && (location.href.indexOf("divisions") != -1))
		{
			list[i].className = 'redLink';
		}
		if ((list[i].className == 'nav4') && (location.href.indexOf("job-search") != -1))
		{
			list[i].className = 'redLink';
		}
		if ((list[i].className == 'nav5') && (location.href.indexOf("for-candidates") != -1))
		{
			list[i].className = 'redLink';
		}
		if ((list[i].className == 'nav6') && (location.href.indexOf("for-employers") != -1))
		{
			list[i].className = 'redLink';
		}
		if ((list[i].className == 'nav7') && (location.href.indexOf("work") != -1))
		{
			list[i].className = 'redLink';
		}
		if ((list[i].className == 'nav8') && (location.href.indexOf("contact-us") != -1))
		{
			list[i].className = 'redLink';
		}
	}
}

// end navigation js


// check username & password for my account log in

function checkUserPass()
{
	var themessage = "Please enter:\n";
	
	if (document.form1.username.value=="")
	{
		themessage = themessage + " - Your username\n";
	}
	
	if (document.form1.password.value=="")
	{
		themessage = themessage + " - Your password\n";
	}

	//alert if fields are empty and cancel form submit
	
	if (themessage == "Please enter:\n")
	{
		return true;
	}
	else
	{
		alert(themessage);
		return false;
	}
}

function checkUserPass2()
{
	var themessage = "Please enter:\n";
	
	if (document.formsignin.username.value=="")
	{
		themessage = themessage + " - Your username\n";
	}
	
	if (document.formsignin.password.value=="")
	{
		themessage = themessage + " - Your password\n";
	}

	//alert if fields are empty and cancel form submit
	
	if (themessage == "Please enter:\n")
	{
		return true;
	}
	else
	{
		alert(themessage);
		return false;
	}
}

// end check


// check email a friend form

function checkFriend()
{
	var themessage = "Please enter:\n";
		
	if (document.emailafriend.friends_name.value=="")
	{
		themessage = themessage + " - Your friend\'s name\n";
	}
	
	if ((document.emailafriend.friends_email.value.indexOf('@') < 1) || (document.emailafriend.friends_email.value.length < (document.emailafriend.friendsemail.value.indexOf('@') + 5)) )
	{
		themessage = themessage + " - Your friend\'s email address\n";
	}

	//alert if fields are empty and cancel form submit
	
	if (themessage == "Please enter:\n")
	{
		return true;
	}
	else
	{
		alert(themessage);
		return false;
	}
}

// end check


// check apply for a job form

function checkApply()
{
	var themessage = "Please enter:\n";
		
	if (document.applyforajob.name.value=="")
	{
		themessage = themessage + " - Your name\n";
	}
	
	if ((document.applyforajob.email.value.indexOf('@') < 1) || (document.applyforajob.email.value.length < (document.applyforajob.email.value.indexOf('@') + 5)) )
	{
		themessage = themessage + " - Your email address\n";
	}
	
	if ((document.applyforajob.email2.value.indexOf('@') < 1) || (document.applyforajob.email2.value.length < (document.applyforajob.email2.value.indexOf('@') + 5)) )
	{
		themessage = themessage + " - Your email address (again)\n";
	}
	
	if ((document.applyforajob.email.value) != (document.applyforajob.email2.value))
	{
		themessage = themessage + " - Your email addresses don't match!\n";
	}
	
	if (document.applyforajob.message.value=="")
	{
		themessage = themessage + " - Your covering letter\n";
	}

	//alert if fields are empty and cancel form submit
	
	if (themessage == "Please enter:\n")
	{
		return true;
	}
	else
	{
		alert(themessage);
		return false;
	}
}

// end check



// check already applied form

function checkApplied()
{
	var themessage = "Please enter:\n";
		
	if (document.alreadyapplied.name.value=="")
	{
		themessage = themessage + " - Your name\n";
	}
	
	if ((document.alreadyapplied.email.value.indexOf('@') < 1) || (document.alreadyapplied.email.value.length < (document.alreadyapplied.email.value.indexOf('@') + 5)) )
	{
		themessage = themessage + " - Your email address\n";
	}
	
	if (document.alreadyapplied.message.value=="")
	{
		themessage = themessage + " - Your message\n";
	}

	//alert if fields are empty and cancel form submit
	
	if (themessage == "Please enter:\n")
	{
		return true;
	}
	else
	{
		alert(themessage);
		return false;
	}
}

// end check



// check register form

function checkRegister()
{
	var themessage = "Please enter:\n";
		
	if (document.registerform.name.value=="")
	{
		themessage = themessage + " - Your name\n";
	}
	
	if ((document.registerform.email.value.indexOf('@') < 1) || (document.registerform.email.value.length < (document.registerform.email.value.indexOf('@') + 5)) )
	{
		themessage = themessage + " - Your email address\n";
	}
	
	if (document.registerform.passwordONE.value=="")
	{
		themessage = themessage + " - Your password\n";
	}
	
	if (document.registerform.passwordTWO.value=="")
	{
		themessage = themessage + " - Your password (again)\n";
	}
	
	if ((document.registerform.passwordONE.value) != (document.registerform.passwordTWO.value))
	{
		themessage = themessage + " - Your password's don't match!\n";
	}
	
	if (document.registerform.privacy.checked == false)
	{
		themessage = themessage + " - Please indicate that you accept our privacy policy\n";
	}
	

	//alert if fields are empty and cancel form submit
	
	if (themessage == "Please enter:\n")
	{
		return true;
	}
	else
	{
		alert(themessage);
		return false;
	}
}

// end check


// check account settings form

function checkRegister2()
{
	var themessage = "Please enter:\n";
		
	if (document.registerform.name.value=="")
	{
		themessage = themessage + " - Your name\n";
	}
	
	if ((document.registerform.email.value.indexOf('@') < 1) || (document.registerform.email.value.length < (document.registerform.email.value.indexOf('@') + 5)) )
	{
		themessage = themessage + " - Your email address\n";
	}
		
	if ((document.registerform.passwordONE.value) != (document.registerform.passwordTWO.value))
	{
		themessage = themessage + " - Your password's don't match!\n";
	}

	//alert if fields are empty and cancel form submit
	
	if (themessage == "Please enter:\n")
	{
		return true;
	}
	else
	{
		alert(themessage);
		return false;
	}
}

// end check


// check account settings form

function checkUnsubscribe()
{
	var themessage = "Please enter:\n";
		
	if (document.unsubscribeform.password.value=="")
	{
		themessage = themessage + " - Your password\n";
	}
	
	//alert if fields are empty and cancel form submit
	
	if (themessage == "Please enter:\n")
	{
		return true;
	}
	else
	{
		alert(themessage);
		return false;
	}
}

// end check


// check forgotten password form

function checkFP()
{
	var themessage = "Please enter:\n";
		
	if ((document.fpform.email.value.indexOf('@') < 1) || (document.fpform.email.value.length < (document.fpform.email.value.indexOf('@') + 5)) )
	{
		themessage = themessage + " - Your email address\n";
	}
	
	//alert if fields are empty and cancel form submit
	
	if (themessage == "Please enter:\n")
	{
		return true;
	}
	else
	{
		alert(themessage);
		return false;
	}
}

// end check


// check contact us form

function checkContact()
{
	var themessage = "Please enter:\n";
		
	if (document.contactform.name.value=="")
	{
		themessage = themessage + " - Your name\n";
	}
	
	if ((document.contactform.email.value.indexOf('@') < 1) || (document.contactform.email.value.length < (document.contactform.email.value.indexOf('@') + 5)) )
	{
		themessage = themessage + " - Your email address\n";
	}
	
	if (document.contactform.comments.value=="")
	{
		themessage = themessage + " - Your comments\n";
	}

	//alert if fields are empty and cancel form submit
	
	if (themessage == "Please enter:\n")
	{
		return true;
	}
	else
	{
		alert(themessage);
		return false;
	}
}

// end check




// disable right-clicking to save images
var message="© hr consultancy. all right reserved";
function clickIE4()
{
	if (event.button==2)
	{
		alert(message);
		return false;
	}
}

function clickNS4(e)
{
	if (document.layers||document.getElementById&&!document.all)
	{
		if (e.which==2||e.which==3)
		{
			alert(message);
			return false;
		}
	}
}

if (document.layers)
{
	document.captureEvents(Event.MOUSEDOWN);
	document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById)
{
	document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("alert(message);return false")
// end disable right-clicking



// my account stuff
setUpPage = function(e)
{
	var mys1Cookie = new s1JS.SimpleCookie('mys1_eid', 1, '/');
	if(mys1Cookie.load())
	{
		s1JS.Dom.get('greeting').innerHTML = '';
		var eid = mys1Cookie.mys1_eid;

		if(eid)
		{
			var xmlhttp;

			if ( window.ActiveXObject ) // if it's ie
			{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); // xmlhttp is global
				xmlhttp.onreadystatechange = function ()
				{	
					if(xmlhttp.readyState == 4) write_signed_in_name(xmlhttp.responseText);
				};
			}
			else 
			{
				if (window.XMLHttpRequest) // if it's firefox etc.
				{
					xmlhttp        = new XMLHttpRequest() // xmlhttp is global
					xmlhttp.onload = function () { write_signed_in_name(xmlhttp.responseText) };
				}
				else return; // 
			}     

			var url = "http://" + document.location.hostname + "/login-check.cgi"

			xmlhttp.open("GET", url , true);
			xmlhttp.send(null); 
		}
	}
	return true;   
}

function write_signed_in_name (name)
{
	var content = '<div id="subRight1b"><div id="subL1"><div id="subL2">Welcome, ' + name +
		'</div></div><div id="subR1"><div id="subR2"><b>' +
		'<a href="/my-account/">my account</a></b>&nbsp;&nbsp;&nbsp;' +
		'<a href="/my-account/job-alerts.cgi">job alerts</a>&nbsp;&nbsp;&nbsp' +
		'<a href="/my-account/stored-jobs.cgi">stored jobs</a>&nbsp;&nbsp;&nbsp;' +
		'<a href="/my-account/jobs-applied-for.cgi">jobs applied for</a>&nbsp;&nbsp;&nbsp;' +
		'<a href="/my-account/documents.cgi">my CV</a>&nbsp;&nbsp;&nbsp;' +
		'<a href="/my-account/settings.cgi">settings</a>&nbsp;&nbsp;&nbsp;' +
		'<a href="/my-account/sign-out.cgi">sign out</a>&nbsp;&nbsp;&nbsp;' +
		'</div></div><div class="clear">&nbsp;</div></div>';

	s1JS.Dom.get('greeting').innerHTML = content;
}

s1JS.Event.addListener(window, 'load', setUpPage);

// job detail page, populate search results
function job_details_search_results ()
{
	var sr_cookie = new s1JS.Cookie('stored_search', 2, '/');
	if (sr_cookie.load())
	{
		var search_string = sr_cookie.search_string;
		if(search_string)
		{
			var xmlhttp;

			if ( window.ActiveXObject ) // if it's ie
			{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); // xmlhttp is global
				xmlhttp.onreadystatechange = function ()
				{
					if(xmlhttp.readyState == 4) { s1JS.Dom.get('searchresults').innerHTML = xmlhttp.responseText };
				};
			}
			else
				if (window.XMLHttpRequest) // if it's firefox etc.
				{
					xmlhttp        = new XMLHttpRequest(); // xmlhttp is global
					xmlhttp.onload = function () { s1JS.Dom.get('searchresults').innerHTML = xmlhttp.responseText };
				}
				else return; //
		}

		var url = "http://" + document.location.hostname + "/results-mini.cgi?" + search_string;

		xmlhttp.open("GET", url , true);
		xmlhttp.send(null);
	}
	else
	{
		var xmlhttp;

		if ( window.ActiveXObject ) // if it's ie
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); // xmlhttp is global
			xmlhttp.onreadystatechange = function ()
			{
				if(xmlhttp.readyState == 4) { s1JS.Dom.get('searchresults').innerHTML = xmlhttp.responseText };
			};
		}
		else
			if (window.XMLHttpRequest) // if it's firefox etc.
			{
				xmlhttp        = new XMLHttpRequest(); // xmlhttp is global
				xmlhttp.onload = function () { s1JS.Dom.get('searchresults').innerHTML = xmlhttp.responseText };
			}
			else return; //
			var url = "http://" + document.location.hostname + "/results-mini.cgi?location=Any+--+Anywhere+in+Scotland&x=13&y=18";

			xmlhttp.open("GET", url , true);
			xmlhttp.send(null);


	}
}
