var stepvalidates = 1;

$(document).ready(function(){
	
	//round boxes
	$(".cornered").corner();
	
	/******************************************************** QUICK LOGIN */
	$("#loginlink").click(function(event){
		$("#loginsubmit").click();
		event.preventDefault();
	});
	if($(".input-username").val()!=""){
		$(".input-username").val("");
	}
	if($(".input-password").val()!=""){
		$(".input-password").val("");
	}
	//handle focus on pre filled forms:
	$(".input-username").focus(function(){
		$(this).css("background","none");
		
	});
	$(".input-password").focus(function(){
		$(this).css("background","none");
	});
	
	
	/******************************************************** ACCOUNT INTERACTION */
	$(".delete-job").click(function(event){
		if(!confirm("Are you sure you want to delete this job?")){
			event.preventDefault();
		}
	});
	
	
	/******************************************************** RETRIEVE PASSWORD */
	$("#forgot-pass").click(function(){
		$("#retrieve-pass-content").load("/ajaxpage/retrievepasswordform");
		$("#retrieve-pass-dialog").dialog("open");
	});
	
	$("#retrieve-pass-dialog").each(function(){
		$("#retrieve-pass-dialog").dialog({ modal: true,width:500,autoOpen:false,title:"Password Recovery"});
		$("#do-submit-recoverpassword").click(function(){
			$("#dosubmitpassword").click();
		});
	});
	
	
	/******************************************************** QUICK SEARCH */
	$("#searchregion").change(function(){
		$(".areas-dropdown").addClass("hidden");
		$(".areas-dropdown select").attr("disabled","disabled");
		
		if($(this).val() != 0){
			$("#areas-"+$(this).val()).removeClass("hidden");
			$("#areas-"+$(this).val() +" select").removeAttr("disabled");
		}
	});
	
	
	$("#do-quick-search").click(function(event){
		
		
		if( $("#searchjobs").attr("checked") ){
			searchtype = "jobs";
		}else if( $("#searchcandidates").attr("checked") ){
			searchtype = "candidates";
		}
		
//		searchtype = $("#searchtype").val();
		
		//gather data
		idcategory = $("#searchcategory").val();
		idposition = $("#searchposition").val();
		term = "negotiable";
		region = $("#searchregion").val();
		
		if(region!=0){
			idlocation = $("#areas-"+region+" select").val();
		}else{
			idlocation = 0;
		}

		published = $("#publishdate").val();
		
		//build URL
		var searchurl = "/search/"+searchtype+"";
		searchurl += "/"+idcategory;
		searchurl += "/"+idposition;
		searchurl += "/"+region;
		searchurl += "/"+idlocation;
		searchurl += "/"+term;
		searchurl += "/"+published;
		searchurl += "/1";
		
		//redirect
//		prompt("url",searchurl);
		
		
		$(location).attr('href',searchurl);
		
		event.preventDefault();
		
//		return;
		
	});
	
	
	/******************************************************** ALERTS SUBSCRIBE */
	$("#do-alerts-subscribe").click(function(event){
		$("#form-job-alerts #submit-alerts").click();
		event.preventDefault();
	});
	
	$("#do-submit-contact").click(function(event){
		$("#submit-contact").click();
		event.preventDefault();
	});
	
	
});
