/*** Start: Job search RHC functions ***/

$(document).ready(function() {
	$("#frm_js").show();
	$("#frm_nojs").hide();
	$("#frm_job_salary").hide();
	$("#frm_job_daily").hide();
	$(".profile_more").hide();
	$('form.rate_calc_form').submit(function() {
		calculator_sidebar();
		return false;
	});
	$('form.rate_calc_form_main').submit(function() {
		calculator_main();
		return false;
	});
	
	// global assignments slide panels
	$(".slide_panel").hide();
	$(".slide_button").click(function(){
			$(this).siblings(".slide_panel").toggle('blind',250);
			if($(this).html() == 'more') {
				$(this).html('hide');
			} else {
				$(this).html('more');
			}
			return false;
		});
});

// Show/hide dropdown
function toggleLayer(oLayer)
{
	if($(oLayer).is(":hidden"))
	{
		$(oLayer).show();
		$(oLayer).parent().bind({
			mouseleave: function(){
				$(oLayer).hide();
			}
		});
	} else if($(oLayer).is(":visible")) {
		$(oLayer).hide();
	}
}

// Hide other layers
function hideLayer(oLayer)
{
	var arrLayers = oLayer.split(",");
	for(i=0;i<arrLayers.length;i++)
	{
		if($(arrLayers[i]).is(":visible"))
			$(arrLayers[i]).hide();
	}
}


// Ensure clicked value from custom dropdown is applied to relevant select element
function assignDropdownValue(strList,strLbl)
{
	strLbl = strLbl.replace("&amp;", "&");  //added due to &amp; causing the function to fail
	$("#" + strList + "_lbl").html(strLbl);
	$(".frm_dropdown").hide();
	$("#" + strList).val(strLbl);
}

/*** End: Job search RHC functions ***/

/*** Switch search dropdown lists ***/
function switchlists()
{
	var job_type = $("#sjm_job_period").val();
	if (job_type == 'Permanent')
	{
		$("#frm_job_daily").hide();
		$("#frm_job_salary").slideDown('slow');
		
	}
	if (job_type == 'Interim')
	{
		$("#frm_job_salary").hide();
		$("#frm_job_daily").slideDown('slow');
	}
	if (job_type == 'Job Type')
	{
		$("#frm_job_salary").hide();
		$("#frm_job_daily").hide();
	}
}

/*** scroll down to the calculated rate ***/
function scrolltodiv(id){
      $('html,body').animate({scrollTop: $("#"+id).offset().top},'slow');
}


/** Our People - show more paragraph **/
function showMoreLayer(oLayer,oClass)
{
	$(oLayer).toggle('blind',500);
	if($(oClass).html() == 'more') {
		$(oClass).html('hide');
	} else {
		$(oClass).html('more');
	}
}

/**  Sidebar calculator **/
function calculator_sidebar()
{
	/* get the values */
	var salary = $('#salary').val();
	var benefits = $('#benefits').val();
	
	/* validation */
	if (benefits == "Benefits") { benefits = ""; }
	
	if (salary == 'Salary') {
		alert('Please enter a salary figure');
		return false;
	}
	
	/* remove commas and £ signs from values*/
	var salary = salary.replace(",","");
	var salary = salary.replace("£","");
	var benefits = benefits.replace(",","");
	var benefits = benefits.replace("£","");
	
	/* calculate the rate */
	var total = salary/1 + benefits/1;
	var rate = (total * 1.128) / 220;
	
	/* round it up */
	rate = Math.ceil(rate);
	
	/* output the result */
	$('#calculated').html('<h2 class="calculated">The Calculated Rate is :</h2><h2 class="sidebar">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&pound;' + rate + ' per day</h2><p>This is based on a salary and benefits total of : &pound;' + total + '</p>');
}

/**  Main calculator **/
function calculator_main()
{
	/* get the values */
	var salary = $('#salary_main').val();
	var benefits = $('#benefits_main').val();
	
	/* validation */
	if (benefits == "Benefits") { benefits = ""; }
	
	if (salary == 'Salary') {
		alert('Please enter a salary figure');
		return false;
	}
	
	/* remove commas and £ signs from values*/
	var salary = salary.replace(",","");
	var salary = salary.replace("£","");
	var benefits = benefits.replace(",","");
	var benefits = benefits.replace("£","");
	
	/* calculate the rate */
	var total = salary/1 + benefits/1;
	var rate = (total * 1.128) / 220;
	
	/* round it up */
	rate = Math.ceil(rate);
	
	/* output the result */
	$('#calculated_main').slideUp();
	$('#calculated_main').html('<h2 class="calculated"><br>The Calculated Rate is :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&pound;' + rate + ' per day</h2><p>This is based on a salary and benefits total of : &pound;' + total + '</p>');
	$('#calculated_main').slideDown('slow');
}

// Slide in videos
function showVideo(intLayerID)
{
	$("." + intLayerID).toggle('blind',500);
}


