function check_jobsearch_form () {

	var searchform = document.forms["searchform"].elements;

	if (searchform["locationtext"].value == "" || searchform["locationtext"].value == locationDefault) {

		searchform["locationid"] = "";	// Set the variable for now
		document.forms["searchform"].elements["locationid"].value = "";	// Set the actual form
	}

	if ((searchform["jobtitle"].value.length < 1 || searchform["jobtitle"].value == keywordDefault)	&& (searchform["locationtext"].value.length < 1 || searchform["locationtext"].value == locationDefault) && searchform["locationid"].value.length < 1) {

		alert("Please choose a jobtitle/keyword or a location");

		return false;

	} else {

		return true;
	}
}

//--------------------------------------------------------------------------------------------------------------------------------

function toggle_login_form (toggle) {	
	
	if (toggle == 'show') {

		$('#tab-login').fadeOut('fast');
		$('#login-form').slideDown('fast');

	} else {

		$('#login-form').slideUp('fast');
		$('#tab-login').fadeIn('fast');
	}
}

//--------------------------------------------------------------------------------------------------------------------------------

function toggleClass (objectName, fromVal, toVal) {
	
	var tmpObject = document.getElementById(objectName);

	if (tmpObject.className == fromVal) {
		tmpObject.className = toVal;
	} else {
		tmpObject.className = fromVal;
	}
}

//--------------------------------------------------------------------------------------------------------------------------------

function check_all_job_terms (objectName) {

	toggleClass(objectName+'-caption', 'normal', 'checked'); 

	var tmpChecked = false;

	for (i in jobterms) {
           //.css ('background-color', '#f4f4f4')
		if (document.getElementById(jobterms[i]+'-jobtype').checked) {
			tmpChecked = true;
			break;
		}
	}

	if (!tmpChecked) {
		for (i in jobterms) {
			document.getElementById(jobterms[i]+'-jobtype').checked = true;
 			document.getElementById(jobterms[i]+'-caption').className = 'checked';
		}
	}
}

//--------------------------------------------------------------------------------------------------------------------------------

function hide_more_roles () {

	$("#hide-more-roles").hide();
	$("#show-more-roles").show();
	$("#search-options-extra").slideUp();
}

//--------------------------------------------------------------------------------------------------------------------------------

function show_more_roles (masterRoleID) {

	$("#show-more-roles").hide();
	$("#search-options-extra").slideDown();

	if (!moreRolesShow) {

		moreRolesShow = true;
		
		var tmpStr = '';
		for (i in extraRoles) {
			tmpStr = tmpStr + extraRoles[i]+'-';
		}

		tmpStr = tmpStr.substring(0, tmpStr.length-1);

		var url = '/index.php?section=logmoreroles&masterRoleID='+masterRoleID+'&roles='+tmpStr;

		jQuery.ajax(url);
	}
	
	$("#hide-more-roles").show();
}

//--------------------------------------------------------------------------------------------------------------------------------

function do_search (masterRoleID, inNumber) {

	var filters = $("#filteroptionsform").serialize();
	if (filters.length < 1) {
		alert("Please note: At least one filter must be set");
		return false;
	}

	var params = $("#searchform").serialize() + '&' + filters;
	var url = '/index.php?section=searchajax&'+params;

	if (document.getElementById("add_job_"+masterRoleID).checked) {
		url = url + '&clickRoleID='+inNumber;
	}

	document.getElementById('numJobResults').style.display = 'none';
	document.getElementById('numResultsWaiting').style.display = 'inline-block';

	$('#search-results').fadeTo('fast', 0.25, function() {
		$("#search-results").load(url);
    });

	return true;
}

//--------------------------------------------------------------------------------------------------------------------------------

function swap (elementID, imageUrl) {

	document.getElementById(elementID).style.backgroundImage = "url('"+imageUrl+"')";
}

//--------------------------------------------------------------------------------------------------------------------------------

function swapSrc (elementID, imageUrl) {

	document.getElementById(elementID).src = imageUrl;
}

//--------------------------------------------------------------------------------------------------------------------------------

function swapLoaded (imageName, imageFile) {

    if (!document.images) {
        return;
    } else {
        eval('document.images[imageName].src = '+ imageFile +'.src');
    }
}

//--------------------------------------------------------------------------------------------------------------------------------

function toggleOptions (tmpVal) {

	if (tmpVal != 0) {
		document.getElementById("unsubchoice").style.display = "none";
	} else {
		document.getElementById("unsubchoice").style.display = "block";
	}
}

//--------------------------------------------------------------------------------------------------------------------------------

function toggleUnsubOtherBox (show) {

	if (show) {
		document.getElementById("otherBox").style.display = "block";
	} else {
		document.getElementById("otherBox").style.display = "none";
	}
}

//--------------------------------------------------------------------------------------------------------------------------------

function doFormVerify () {

	var form = document.forms["contactForm"];

	var newVar = document.createElement("input");
	newVar.type = "hidden";
	newVar.name = "verify";
	newVar.value = "Z3TrRA";

	form.appendChild(newVar);

	return true;	
}

//--------------------------------------------------------------------------------------------------------------------------------

function showLoginForm () {

	document.getElementById("loginFormDiv").style.display = "block";
	document.getElementById("regBannerSmallDiv").style.display = "none";
}

//--------------------------------------------------------------------------------------------------------------------------------

function switchSearchForm() {

	if (document.searchform.searchType.value == "advanced") {	// Showing basic

		// Submit the form to get a new summary with a new target and within a new frame
		document.searchform.action = "/searchsummary.php";
		document.searchform.target = "searchRollupFrame";
		document.searchform.submit();

		// Set the parameters back so the search button works again
 		document.searchform.action = "/jobsearch.php";
 		document.searchform.target = "";
 		document.searchform.searchType.value = "basic";

	} else {
	
		document.getElementById("searchButtonImage").src="/images/new/button_searchCollapse.png";
		document.getElementById("searchButtonImage").style.display = "block";
		document.searchform.searchType.value = "advanced";
		slideup("basicFormDiv");
		slidedown("advancedFormDiv");
	}
}

//--------------------------------------------------------------------------------------------------------------------------------

function switchSearchFormSmall() {

	if (document.searchform.searchType.value == "advanced") {	// Showing basic

		// Submit the form to get a new summary with a new target and within a new frame
		document.searchform.action = "/searchsummary.php";
		document.searchform.target = "searchRollupFrame";
		document.searchform.submit();

		// Set the parameters back so the search button works again
 		document.searchform.action = "/jobsearch.php";
 		document.searchform.target = "";
 		document.searchform.searchType.value = "basic";

	} else {

		document.getElementById("searchButtonImage").src="/images/new/button_searchSmallCollapse.png";
		document.searchform.searchType.value = "advanced";
		slideup("basicFormDiv");
		slidedown("advancedFormDiv");
	}
}

//--------------------------------------------------------------------------------------------------------------------------------

/* Functions for placeholder support */

function addPlaceHolders () {
	
    // If not webkit/opera, probably doesn't support placeholder attribute right now
    if (!$.browser.webkit && !$.browser.opera) {

        // Set up the inputs with placeholder attributes
        $("input[placeholder]").attr("hasFocus", "false").focus(function (event) { // when clicked/tabbed in:

            // Hide our own label
            hideLabel(event.target.id);
            // Defend against label reprisals by whoever might have just blurred
            $(event.target).attr("hasFocus", "true");

        }).blur(function (event) { // when clicked/tabbed out of:

            // Allow a label for ourselves again
            $(event.target).attr("hasFocus", "false");
            // Re-draw all the labels (including ours)
            checkPlaceholderLabels();

        });

        // draw our very first labels!
        checkPlaceholderLabels();
    }
}

//--------------------------------------------------------------------------------------------------------------------------------

/**
 * Hides/removes a placeholder label to reveal text-box contents
 *
 * @param string boxID to search for labels about
 *
 * @author David G Jan 2011
 */
function hideLabel(boxID) {

    // Just remove it entirely from the DOM
    $("label[for="+boxID+"]").remove();

} // function hideLabel

//--------------------------------------------------------------------------------------------------------------------------------

/**
 * Ensures there is a placeholder over a text-box.
 * Retrieves the label's contents from the specified input's "placeholder"
 * attribute.
 * Doesn't bother if a placeholder label already exists, just falls back
 * through.
 *
 * @param string boxID to attach the label to (highly recommended to be a <input>)
 *
 * @author David G Jan 2011
 */

function ensureLabel(boxID) {
    // Make sure there isn't one already
    if ($("label[for="+boxID+"]").length == 0) {

        // Find the actual element we're talking about here
        inputBox = $("#"+boxID)[0];
        // Where is it on the page?
        inputBoxOffset = $(inputBox).offset();

        // Okay, create a <label> element to hover over the specified element
        label = $("<label for=\""+inputBox.id+"\">&nbsp;"+$(inputBox).attr("placeholder")+"</label>").mouseup(function (el) { // On mouse-up:

            forID = $(el.target).attr("for");
            $("#"+forID)[0].focus();

        }).css({ // Set the css/style as:

            position: "absolute",                        // Absolute so we can position it
            top: inputBoxOffset["top"]+"px",             // Same as box
            left: inputBoxOffset["left"]+"px",           // Same as box
            width: $(inputBox).innerWidth()+"px",        // Same as box
            height: $(inputBox).innerHeight()+"px",      // Same as box
            lineHeight: $(inputBox).innerHeight()+"px",  // Vertically aligns the text
            zIndex: "100",                               // Places at front of page
            color: "grey"                                // To match the default look of a placeholder value

        }); // NOTE: @PK You can just put styles in in the ".css" bit just above (notice "line-height" becomes "lineHeight" to avoid using a hyphen) although these will not be used in browsers with native placeholder support (Safari,Chrome,Opera)

        // Finally, add it to the body (absolute positioning will put it where it needs to be)
        $("body").append(label);
    }
}

//--------------------------------------------------------------------------------------------------------------------------------

/**
 * Ensures all inactive inputs with placeholder attributes have their
 * placeholder labels displayed
 *
 * @author David G Jan 2011
 */
function checkPlaceholderLabels() {

    $("input[placeholder][hasFocus=false]").each(function (i, el) { // For all the placeholders that aren't currently focused/active..

        if ($("#"+el.id)[0].value == "") { // If their value is empty..

            // Show label
            ensureLabel(el.id);

        } // No value

    }); // all placeholderables
}

//--------------------------------------------------------------------------------------------------------------------------------

function switch_divs (div1, div2, div3) {

	document.unsubscribe.subsection.value = div1;

	document.getElementById(div1+"choice").style.display = "block";
	if (frequency != 0 || div1 != "unsub") {
		document.getElementById(div1+"image").style.display = "block";
	}

	if (frequency != 0) {

		document.getElementById(div2+"choice").style.display = "none";
		if (frequency != 0 || div2 != "unsub") {
			document.getElementById(div2+"image").style.display = "none";
		}

		document.getElementById(div3+"choice").style.display = "none";
		if (frequency != 0 || div3 != "unsub") {
			document.getElementById(div3+"image").style.display = "none";
		}
	}

	document.getElementById("makeChangeButton").style.display = "block";
}

//--------------------------------------------------------------------------------------------------------------------------------

function redirect_search (sectorStr) {

	var outStr = "&"+sectorStr;

	if (document.searchform.keywords.value) {
		outStr = outStr + "&keywords=" + document.searchform.keywords.value.replace(/ /g,"+");
	}

	if (document.searchform.locationid.value) {
		outStr = outStr + "&locationid="+document.searchform.locationid.value;
	}

	if (document.searchform.minpay.value) {
		outStr = outStr + "&minpay="+document.searchform.minpay.value; 
	}

	if (document.searchform.maxpay.value) {
		outStr = outStr + "&maxpay="+document.searchform.maxpay.value; 
	}

	document.location = "/jobsearch.php?search=1&searchType=advanced"+outStr; 
}

//--------------------------------------------------------------------------------------------------------------------------------

function show_hide_full_search () {

	if (document.getElementById('advanced-options-container').style.display == 'none') {

		$("#advanced-options-container").slideDown();
		document.getElementById('full-search-toggle').innerHTML = 'Less Options';
		document.searchform.searchType.value = 'advanced';
		
	} else {

		$("#advanced-options-container").slideUp();
		document.getElementById('full-search-toggle').innerHTML = 'More Options';
		document.searchform.searchType.value = 'basic';
	}
}

//--------------------------------------------------------------------------------------------------------------------------------

function change_input_value (boxObj, runType) {
	
	if (runType == 'focus' && boxObj.value == defaultText[boxObj.name]) {
		boxObj.className = "text-box";
		boxObj.value = "";
	}

	if (runType == 'blur' && boxObj.value == "") {
		boxObj.className = "text-box-empty";
		boxObj.value = defaultText[boxObj.name];
	}
}

//================================================================================================================================

var moreRolesShow = false;

var jobterms = new Array('permanent', 'contract', 'temporary', 'voluntary', 'casual', 'student_gap_year', 'interim_management');

var defaultText = new Array;
defaultText["jobtitle"] = "Job Title or Keyword";
defaultText["locationtext"] = "Town or Postcode";

if (document.images) {

	tabBut0a = new Image(56, 28); tabBut0a.src = "/images/tabs/tab_home.png";
	tabBut0b = new Image(56, 28); tabBut0b.src = "/images/tabs/tab_home_over.png";
	tabBut1a = new Image(93, 28); tabBut1a.src = "/images/tabs/tab_myprofile.png";
	tabBut1b = new Image(93, 28); tabBut1b.src = "/images/tabs/tab_myprofile_over.png";
	tabBut2a = new Image(99, 28); tabBut2a.src = "/images/tabs/tab_jobsearch.png";
	tabBut2b = new Image(99, 28); tabBut2b.src = "/images/tabs/tab_jobsearch_over.png";
	tabBut3a = new Image(126, 28); tabBut3a.src = "/images/tabs/tab_careersadvice.png";
	tabBut3b = new Image(126, 28); tabBut3b.src = "/images/tabs/tab_careersadvice_over.png";
	tabBut4a = new Image(57, 28); tabBut4a.src = "/images/tabs/tab_help.png";
	tabBut4b = new Image(57, 28); tabBut4b.src = "/images/tabs/tab_help_over.png";
	tabBut5a = new Image(192, 28); tabBut5a.src = "/images/tabs/tab_recruiters.png";
	tabBut5b = new Image(192, 28); tabBut5b.src = "/images/tabs/tab_recruiters_over.png";
	tabBut6a = new Image(120, 28); tabBut6a.src = "/images/tabs/tab_myaccount.png";
	tabBut6b = new Image(120, 28); tabBut6b.src = "/images/tabs/tab_myaccount_over.png";
	tabBut7a = new Image(80, 28); tabBut7a.src = "/images/tabs/tab_logout.png";
	tabBut7b = new Image(80, 28); tabBut7b.src = "/images/tabs/tab_logout_over.png";
	tabBut8a = new Image(70, 28); tabBut8a.src = "/images/tabs/tab_login.png";
	tabBut8b = new Image(70, 28); tabBut8b.src = "/images/tabs/tab_login_over.png";
	tabBut9a = new Image(80, 28); tabBut9a.src = "/images/tabs/tab_register.png";
	tabBut9b = new Image(80, 28); tabBut9b.src = "/images/tabs/tab_register_over.png";
	
	loginBut1a = new Image(103, 33); loginBut1a.src = "/images/new/button_signin.png";
	loginBut1b = new Image(103, 33); loginBut1b.src = "/images/new/button_signin_over.png";
	
	recruitNowButa = new Image(192, 26); recruitNowButa.src = "/images/new/recruitNowButton.png";
	recruitNowButb = new Image(192, 26); recruitNowButb.src = "/images/new/recruitNowButtonOver.png";

	// Directory Buttons
	butBackToResultsA = new Image(151, 22); butBackToResultsA.src = "/images/new/button_backToResults.png";
	butBackToResultsB = new Image(151, 22); butBackToResultsB.src = "/images/new/button_backToResults_over.png";

    butModifySearchA = new Image(107, 22); butModifySearchA.src = "/images/new/button_modifySearch.png";
    butModifySearchB = new Image(107, 22); butModifySearchB.src = "/images/new/button_modifySearch_over.png";
    butViewShortlistA = new Image(99, 22); butViewShortlistA.src = "/images/new/button_viewShortlist.png";
    butViewShortlistB = new Image(99, 22); butViewShortlistB.src = "/images/new/button_viewShortlist_over.png";
    butAddToShortListA = new Image(130, 23); butAddToShortListA.src = "/images/new/button_addToShortlist.png";
    butAddToShortListB = new Image(130, 23); butAddToShortListB.src = "/images/new/button_addToShortlist_over.png";
    butAddToShortListFeaturedA = new Image(130, 23); butAddToShortListFeaturedA.src = "/images/new/button_addToShortlistFeatured.png";
    butAddToShortListFeaturedB = new Image(130, 23); butAddToShortListFeaturedB.src = "/images/new/button_addToShortlistFeatured_over.png";
    butViewJobDetailsA = new Image(130, 23); butViewJobDetailsA.src = "/images/new/button_viewJobDetails.png";
    butViewJobDetailsB = new Image(130, 23); butViewJobDetailsB.src = "/images/new/button_viewJobDetails_over.png";
    butViewJobDetailsFeaturedA = new Image(130, 23); butViewJobDetailsFeaturedA.src = "/images/new/button_viewJobDetailsFeatured.png";
    butViewJobDetailsFeaturedB = new Image(130, 23); butViewJobDetailsFeaturedB.src = "/images/new/button_viewJobDetailsFeatured_over.png";
}

