function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if ( oldonload ) {
				oldonload();
			}
			func();
		}
	}
}

////////////////
//
//	COMPATIBILITY FIXES
//
////////////////

//THIS STOPS INTERNET EXPLORER MAKING SILLY FLICKERS WITH MOUSEOVERS
try {
	document.execCommand ( "BackgroundImageCache", false, true );
} catch ( err ) {}






var stored_redirect_url = "";

function please_redirect_now ( ) {
	window.location = stored_redirect_url;
}


function please_redirect_shortly ( param_timeout ) {
	setTimeout ( "please_redirect_now()", param_timeout );
}

function highlight_obj( object_id, color_value ) {
	if( color_value == null ) color_value = 'red';
	obj = document.getElementById( object_id );
	obj.style.color = color_value;
}

function form_submit_do(param_form_id) {
	document.getElementById( param_form_id ).submit();
}

function form_submit_call(param_form_id) {
	// IE6 hack
	setTimeout(function(){form_submit_do(param_form_id)}, 50);
}

function check_select( object_id, msg, hl_object_id ) {
	sel = document.getElementById( object_id );
	if( ( hl_object_id != null ) && ( sel.selectedIndex == -1 ) ) highlight_obj( hl_object_id );
	return ( sel.selectedIndex > -1 ) ? '' : msg;
}

function showLoginForm() {
	document.getElementById('login_form').style.display='none';
	document.getElementById('login_form2').style.display='inline';
}

function hideLoginForm() {
	document.getElementById('login_form').style.display='inline';
	document.getElementById('login_form2').style.display='none';
}

function checkSearchForm() {
	var retval = false;
	var box, k=-1;
	industries = document.getElementsByName('sectors[]');
	while( box=industries[++k] ) {
		if( box.checked ) retval = true;
	}
	k=-1;
	languages = document.getElementsByName('languages[]');
	while( box=languages[++k] ) {
		if( box.checked ) retval = true;
	}
	locations = document.getElementById('location');
	if( locations.selectedIndex > -1 ) retval = true;  //multiple select
	emptype = document.getElementById('emptype');
	if( emptype.selectedIndex > -1 ) retval = true;		//multiple select
	salary_band = document.getElementById('salary_band');
	if( salary_band.selectedIndex > 0 ) retval = true;	//single select
	search_string = document.getElementById('strongtextinput');
	if( search_string.value != "" ) retval = true;
	if( !retval ) alert('Please enter a specific search');
	return retval;
}

$(document).ready(function() {
	if ( $('#sidebox')[0] ) {
		$('#sidebox').corner({
		tl: { radius: 25 },
		tr: { radius: 25 },
		bl: { radius: 25 },
		br: { radius: 25 }});
		$('#sidebox2').corner({
		tl: { radius: 25 },
		tr: { radius: 25 },
		bl: { radius: 25 },
		br: { radius: 25 }});
		$('#sidebox3').corner({
		tl: { radius: 25 },
		tr: { radius: 25 },
		bl: { radius: 25 },
		br: { radius: 25 }});
		$('#sidebox4').corner({
		tl: { radius: 25 },
		tr: { radius: 25 },
		bl: { radius: 25 },
		br: { radius: 25 }});
		$('#sidebox5').corner({
		tl: { radius: 25 },
		tr: { radius: 25 },
		bl: { radius: 25 },
		br: { radius: 25 }});
		$('#sidebox6').corner({
		tl: { radius: 25 },
		tr: { radius: 25 },
		bl: { radius: 25 },
		br: { radius: 25 }});
		$('#sidebox7').corner({
		tl: { radius: 25 },
		tr: { radius: 25 },
		bl: { radius: 25 },
		br: { radius: 25 }});
		$('#sidebox8').corner({
		tl: { radius: 25 },
		tr: { radius: 25 },
		bl: { radius: 25 },
		br: { radius: 25 }});
		$('#sidebox9').corner({
		tl: { radius: 25 },
		tr: { radius: 25 },
		bl: { radius: 25 },
		br: { radius: 25 }});
		$('#sidebox10').corner({
		tl: { radius: 25 },
		tr: { radius: 25 },
		bl: { radius: 25 },
		br: { radius: 25 }});
		$('#sidebox11').corner({
		tl: { radius: 25 },
		tr: { radius: 25 },
		bl: { radius: 25 },
		br: { radius: 25 }});
		$('#sidebox12').corner({
		tl: { radius: 25 },
		tr: { radius: 25 },
		bl: { radius: 25 },
		br: { radius: 25 }});
		$('#sidebox13').corner({
		tl: { radius: 25 },
		tr: { radius: 25 },
		bl: { radius: 25 },
		br: { radius: 25 }});
		$('#sidebox14').corner({
		tl: { radius: 25 },
		tr: { radius: 25 },
		bl: { radius: 25 },
		br: { radius: 25 }});
		$('#sidebox15').corner({
		tl: { radius: 25 },
		tr: { radius: 25 },
		bl: { radius: 25 },
		br: { radius: 25 }});
		$('#sidebox16').corner({
		tl: { radius: 25 },
		tr: { radius: 25 },
		bl: { radius: 25 },
		br: { radius: 25 }});
		$('#sidebox17').corner({
		tl: { radius: 25 },
		tr: { radius: 25 },
		bl: { radius: 25 },
		br: { radius: 25 }});
		$('#sidebox18').corner({
		tl: { radius: 25 },
		tr: { radius: 25 },
		bl: { radius: 25 },
		br: { radius: 25 }});
		$('#sidebox19').corner({
		tl: { radius: 25 },
		tr: { radius: 25 },
		bl: { radius: 25 },
		br: { radius: 25 }});
		$('#sidebox20').corner({
		tl: { radius: 25 },
		tr: { radius: 25 },
		bl: { radius: 25 },
		br: { radius: 25 }});
	}
	if ( $.ifixpng ) {
        	$.ifixpng('/templates/merrow/images/pixel.gif');
        	$('#header h1').ifixpng();
	}
});


//Added by tahir
function validateForm(formobj, fieldRequired, fieldDescription){
		// dialog message
		var alertMsg = "Please complete the following fields:\n";
		var l_Msg = alertMsg.length;
		var tempstr = 	"";

		for (var i = 0; i < fieldRequired.length; i++){
			var obj = formobj.elements[fieldRequired[i]];
			if (obj){
				switch(obj.type){
				case "select-one":
					if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
						alertMsg += " - " + fieldDescription[i] + "\n";
					}
					break;
				case "select-multiple":
					if (obj.selectedIndex == -1){
						alertMsg += " - " + fieldDescription[i] + "\n";
					}
					break;
				case "text":
				case "hidden":
				case "textarea":
					tempstr = obj.value.replace(/^\s+|\s+$/g, '').replace(/(<([^>]+)>)/ig,"").replace(/^(\s|&nbsp;)+|(\s|&nbsp;)+$/g,"");
					if (tempstr == "" || obj.value == null){
						alertMsg += " - " + fieldDescription[i] + "\n";
					}
					break;
				default:
				}
				if (obj.type == undefined){
					var blnchecked = false;
					for (var j = 0; j < obj.length; j++){
						if (obj[j].checked){
							blnchecked = true;
						}
					}
					if (!blnchecked){
						alertMsg += " - " + fieldDescription[i] + "\n";
					}
				}
			}
		}
	
		if (alertMsg.length == l_Msg){
			return true;
		}else{
			alert(alertMsg);
			return false;
		}
	}


	function stripHTML(HTMLstring){
		return HTMLstring.replace(/(<([^>]+)>)/ig,"");
	}

	function removeConfirm(){
		if (confirm('This action will remove this record from the system !')){
			return true;
		}else{
			return false;
		}
	}
//End of Added by tahir



	function changeSaleForm() {
		sel = document.getElementById( 'saletype' );
		dperm = document.getElementById( 'dperm' );
		dtemp = document.getElementById( 'dtemp' );
		if( sel.options[sel.selectedIndex].value == 'temp' )
		{
			dperm.style.display = 'none';
			dtemp.style.display ='';
		}
		else {
			dperm.style.display = '';
			dtemp.style.display ='none';
		}
	}
	
	function calculateSale() {
		sale = document.getElementById( 'sale' );
		perc = document.getElementById( 'perc' ).value;
		salary = document.getElementById( 'salary' ).value;
		sale.value = (salary*perc)/100;
	}
	
	function calculateMargin() {
		hourly = document.getElementById( 'hourly' ).value;
		charge = document.getElementById( 'charge' ).value;
		margin = document.getElementById( 'margin' );
		margin.value = charge-hourly;
	}