$(document).ready(function(){
	Cufon.replace('.cufon_this');
	
	$("#tbl_seach_results").dataTable({
		"sPaginationType": "full_numbers",
		"aaSorting": [ ],
		"sDom": "<'top'pi>rt<'bottom'pi<'clear'>"
	});
	
	$("#tbl_news_listing").dataTable({
		"sPaginationType": "full_numbers",
		"aaSorting": [ ],
		"sDom": "<'top'p>rt<'bottom'p<'clear'>"
	});
	
	if($("#jobs_salary_type2").is(":checked")){
		$("#jobs_hourly_rate").removeAttr("disabled");	
	}else{
		$("#jobs_hourly_rate").attr("disabled", true);
	}
	
	$(function(){
		$(".checkall").click(function(){
			$(this).parents("fieldset:eq(0)").find(":checkbox").attr("checked", this.checked);
		});
	});
	
	$(function(){
		$("#jobs_salary_type2").click(function() { 
			if($(this).is(":checked")){
				$("#jobs_hourly_rate").removeAttr("disabled");	
			}else{
				$("#jobs_hourly_rate").attr("disabled", true);
			}
		}); 
	});
	
	$(function(){
		$("#jobs_salary_type3").click(function() { 
			if($(this).is(":checked")){
				$(".jobs_salary_range").removeAttr("disabled");	
			}else{
				$(".jobs_salary_range").attr("disabled", true);
			}
		}); 
	});
	
	if($("input[name=can_local]:radio:checked").val() == "0"){
		$("#can_nationality").removeAttr("disabled");	
	}else{
		$("#can_nationality").attr("disabled", true);
	}

	if($("#company1_cur").is(":checked")){
		$("#company1_til").attr("disabled", true);
		$("#company1_til").val("current");
	}else{
		$("#company1_til").attr("disabled", false);
	}

	if($("#no_work_exp").is(":checked")){
		$("#can_exp").attr("readonly", "readonly");
		$("#can_exp").val("0");
		$("#company1_name, #company1_pos, #company1_from, #company1_til, #company1_cur").attr("disabled", true);
		$("#company2_name, #company2_pos, #company2_from, #company2_til").attr("disabled", true);
		$("#company3_name, #company3_pos, #company3_from, #company3_til").attr("disabled", true);
		$("#company1_name, #company1_pos, #company1_from, #company1_til").val("");
		$("#company2_name, #company2_pos, #company2_from, #company2_til").val("");
		$("#company3_name, #company3_pos, #company3_from, #company3_til").val("");

	}else{
		$("#can_exp").removeAttr("readonly");
		$("#company1_name, #company1_pos, #company1_from, #company1_til").attr("disabled", false);
		$("#company2_name, #company2_pos, #company2_from, #company2_til").attr("disabled", false);
		$("#company3_name, #company3_pos, #company3_from, #company3_til").attr("disabled", false);
	}
	
	$(function(){
		$("#can_dob").datepicker({ dateFormat: "dd-mm-yy", changeYear: true, changeMonth: true, yearRange: '-65:-16', defaultDate: '-65y'});
		$("#company1_from").datepicker({ dateFormat: "dd-mm-yy", changeYear: true, changeMonth: true, yearRange: '-60:-0' });
		$("#company1_til").datepicker({ dateFormat: "dd-mm-yy", changeYear: true, changeMonth: true, yearRange: '-60:-0' });
		$("#company2_from").datepicker({ dateFormat: "dd-mm-yy", changeYear: true, changeMonth: true, yearRange: '-60:-0' });
		$("#company2_til").datepicker({ dateFormat: "dd-mm-yy", changeYear: true, changeMonth: true, yearRange: '-60:-0' });
		$("#company3_from").datepicker({ dateFormat: "dd-mm-yy", changeYear: true, changeMonth: true, yearRange: '-60:-0' });
		$("#company3_til").datepicker({ dateFormat: "dd-mm-yy", changeYear: true, changeMonth: true, yearRange: '-60:-0' });
	});

	$("#company1_cur").click(function(){
		if($("#company1_cur").is(":checked")){
			$("#company1_til").attr("disabled", true);
			$("#company1_til").val("current");
		}else{
			$("#company1_til").attr("disabled", false);
			$("#company1_til").val("");
		}
	});

	$("#no_work_exp").click(function(){
		if($("#no_work_exp").is(":checked")){
			$("#can_exp").attr("readonly", "readonly");
			$("#can_exp").val("0");
			$("#company1_name, #company1_pos, #company1_from, #company1_til, #company1_cur").attr("disabled", true);
			$("#company2_name, #company2_pos, #company2_from, #company2_til").attr("disabled", true);
			$("#company3_name, #company3_pos, #company3_from, #company3_til").attr("disabled", true);
			$("#company1_name, #company1_pos, #company1_from, #company1_til").val("");
			$("#company2_name, #company2_pos, #company2_from, #company2_til").val("");
			$("#company3_name, #company3_pos, #company3_from, #company3_til").val("");

		}else{
			$("#can_exp").removeAttr("readonly");
			$("#company1_name, #company1_pos, #company1_from, #company1_til").attr("disabled", false);
			$("#company2_name, #company2_pos, #company2_from, #company2_til").attr("disabled", false);
			$("#company3_name, #company3_pos, #company3_from, #company3_til").attr("disabled", false);
		}
	});
	
	$("#can_fresh").click(function(){
		if($("#can_fresh").is(":checked")){
			$("#can_fresh").val("1");
		}else{
			$("#can_fresh").val("0");
		}
	});
				
	$("input[name=can_local]:radio").click(function(){
		if($("input[name=can_local]:radio:checked").val() == "0"){
			$("#can_nationality").removeAttr("disabled");	
		}else{
			$("#can_nationality option[selected]").removeAttr("selected");
			$("#can_nationality option[value='0']").attr("selected", "selected");
			$("#can_nationality").attr("disabled", true);
		}
	});		
	
});

ddaccordion.init({
	headerclass: "handcursor", //Shared CSS class name of headers group
	contentclass: "switchgroup1", //Shared CSS class name of contents group
	revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover"
	mouseoverdelay: 0, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
	collapseprev: false, //Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [0], //index of content(s) open by default [index1, index2, etc]. [] denotes no content.
	onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: true, //persist state of opened contents within browser session?
	toggleclass: ["", ""], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["none", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
	oninit:function(expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
		//do nothing
	}
});
