// JavaScript Document

// used in all job details pages to record when mailto, website or more details links are clicked on
function jobContact(linkType, jobId)
{
// the if below is useful for the admin stats which link to want_job_details.aspx to view which job
// was viewed, it helps stop our viewing of the jobs add more stats
	if (window.location.href.indexOf("stats=off") == -1)
	{
		new Ajax.Request("/stats/", {method:"get", parameters:"link_type=" + linkType + "&job_id=" + jobId});
	}
}


/*
	function name : stripSpaces
	purpose : To remove any spaces from the beginning and end of a string, like the trim function in vbscript
*/
function strip_spaces(tempString) {
    while (tempString.substring(0,1) == ' ')
		{
			tempString = tempString.substring(1);
		}
    while (tempString.substring(tempString.length-1,tempString.length) == ' ')
		{
			tempString = tempString.substring(0,tempString.length-1);
		}
    return tempString;
}

function focusField(theForm, theField)
{	
	eval("document." + theForm + "." + theField + ".focus();");
}

/*
	This function is used to set a field called is_javascript_enabled in the form name that is passed to this function. The purpose of this function is to make it possible to establish if the user has a javascript enabled brower	
*/
function set_javascript_enabled_field(theFormField)
{
	eval("document." + theFormField + ".is_javascript_enabled.value = \"true\";")
}


function isValidEmail(str)
{
/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    return false
	 }
		
	 if (str.indexOf(" ")!=-1){
	    return false
	 }

	 return true					
}

function isCookiesEnabled()
{

	document.cookie = "JavascriptAndCookiesEnabled=Y";
	
	if (document.cookie.indexOf("JavascriptAndCookiesEnabled") == -1)
	{
		return false;
	}
	
	return true;	
}

// removes leading and trailing spaces from a string
function trimString(str)
{
	str = this != window? this : str;
  	return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}


// this function is replace function that takes the source string, the substring in the source string
// you wish to replace and the substring you wish to replace the other substring with
function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}



/***********************************************
* Disable "Enter" key in Form script- By Nurul Fadilah(nurul@REMOVETHISvolmedia.com)
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
// this function is used in text fields in forms to prevent the user being able to submit the
// form by pressing enter in the text field. It checks on every keypress to see if return has been
// pressed and if so return false preventing the form from being submitted, other wise it returns true
// allowing the character to be entered into the text field           
function handleEnter (field, event) {
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) 
		{
			return false;
		} 
		else
		{
			return true;
		}
	}      


