$(document).ready(function(){
	$("#login_popup1 a.link_shadow,#login_popup a.link_shadow1,#login_popup2 a.link_shadow2,#login_popup3 a.link_shadow3,a.login_popup_show,a.aly_login_popup_show").click(function(a){
		$.modal.close(); 
		$('#saved_jobs_popup_wrapper').addClass("savedjobs_hidden");
		a.preventDefault();
		$("#login_popup_wrapper").removeClass("loginpopup_hidden");
		$("#login_popup_wrapper").modal();
		$("#login_popup_email").focus();
	});
	$("a.show_edit_notes").click(function(a){
		a.preventDefault();
		$("#notes").removeClass("");
		$("#notes").modal();
	});
	$("a.hide_source1,a.hide_source2,a.hide_source3,a.hide_source4,a.hide_source5").click(function(e){
		e.preventDefault();
		if(language=='en'){ 
				var vj_title = "View Source Site";var vj_desc = "To view the source, your Meijob credits will be reduced by 1 credit.";
		}else{
			var vj_title = "查看来源网站";var vj_desc = "要查看来源网站，您需要使用1个Meijob求职积分(M值)。";
		}
		$("#PTitle").html(vj_title);$("#credits_desc").html(vj_desc);
		$("input[name=action]").val('view_source');
		$("#credits_popup").modal({
			containerCss:{
			width:500}
		});
		$("#credits_popup").removeClass("");
	});
	//apply jobs
	$("a.aly_btn").click(function(e){
		e.preventDefault();
		if(language=='en'){ 
			var vj_title = "Apply Job";var vj_desc = "To apply or view the source of this job, your Meijob credits will be reduced by 1 credit.";
		}else{
			var vj_title = "申请工作";var vj_desc = "要申请此工作，您需要使用1个Meijob求职积分(M值)。";
		}
		$("#PTitle").html(vj_title);$("#credits_desc").html(vj_desc);
		$("input[name=action]").val('apply');
		$("#credits_popup").modal({
			containerCss:{
			width:500}
		});
		$("#credits_popup").removeClass("");
	});
	
	$("a.show_login1").click(function(e){
		$.modal.close(); 
		e.preventDefault();
		$("#login_popup_wrapper").removeClass("loginpopup_hidden");
		$("#login_popup_wrapper").modal();
		$("#login_popup_email").focus();
	});
	
	
	// Register Partner Job site
	var seconds = 5;
	var intval = 0;
	var str_landing_page ="";
	
	function UpdateSecondsTimer(){
		
		document.getElementById('seconds').innerHTML = (seconds - 1);
		seconds = seconds - 1;
		
		if(seconds == 0)
		{
			window.clearInterval(intval);	
			window.open(str_landing_page);
		}
	}
	
	function ShowPartnerSiteRegistrationPopUp()
	{
		seconds = 5;
		intval = window.setInterval(UpdateSecondsTimer, 1000);
	}
	
	// Job Button
	$("a.show_partner_registration_button").click(function(e){
		$.modal.close(); 
		e.preventDefault();
		$("#partner_site_popup_wrapper").removeClass("partner_site_popup_hidden");
		$("#partner_site_popup_wrapper").modal();
		$("#username").focus();
		
		str_landing_page = document.getElementById('job_board_landing_page_url_apply_button').value;
		
		ShowPartnerSiteRegistrationPopUp();
	});
	
	// Job Apply Text
	$("a.show_partner_registration_apply_text").click(function(e){
		$.modal.close(); 
		e.preventDefault();
		$("#partner_site_popup_wrapper").removeClass("partner_site_popup_hidden");
		$("#partner_site_popup_wrapper").modal();
		$("#username").focus();
		
		str_landing_page = document.getElementById('job_board_landing_page_url_apply_text').value;
		
		ShowPartnerSiteRegistrationPopUp();
	});
	
	// Job View Source
	$("a.show_partner_registration_view_source").click(function(e){
		$.modal.close(); 
		e.preventDefault();
		$("#partner_site_popup_wrapper").removeClass("partner_site_popup_hidden");
		$("#partner_site_popup_wrapper").modal();
		$("#username").focus();
		
		str_landing_page = document.getElementById('job_board_landing_page_url_view_source').value;
		
		ShowPartnerSiteRegistrationPopUp();
	});
	//--------------------------------------------------------------------------------------------------------
	
	
	
	$('#credits_help_jobStatic').click(function(e){
		$('#credits_tips').slideToggle();
	});
	$('#cancel_action').click(function(e){
		$.modal.close(); 
	});
	$('#continue_action_jobStatic').click(function(e){
		 var url="/Ajax/job_ajax.php";
		 var job_id = $("input[name=jid]").val();
		 var left_credits = $("input[name=left_credits]").val();
		 var have_e = $("input[name=have_e]").val();
		 var action = $("input[name=action]").val();
		  $.post(url, {job_id: job_id,left_credits:left_credits,action:action,have_e:have_e}, function(data){
				if(data.length>2){
					window.location.reload();
					window.open(data);
					//common.popup_blank(data,'600','600'); // open the source url in new window
				}else if(data=='-1'){
				 	$('#zero_credits_tips').show();
				}
		 	});
	});

	$("a.show_job_introfriend").click(function(a){
		a.preventDefault();
		$("#introduce_to_friend").modal();
	});
});
var hex=0;var php_uri_myjobs='/Ajax/myjobs_ajax.php';
function clickSaveNote(job_id,note,type){
	$("#saveNoteBtn_"+job_id).attr("disabled","true");
	$.post(php_uri_myjobs,{job_id:job_id,note:note,type:type},function(data){
		alert|(data);
		$("#li_template_"+job_id).parents("div.dlist_body").append(data);
		$(".add_note_miniform").css({display:"none"});
	});
}
function clickDelNote(note_id){$.post(php_uri_myjobs,{note_id:note_id,action:'del'},function(data){alert(data);$("#"+note_id).parents("div.dlist_item li_template").remove();});}
function checkConfirm(){
	var b=document.getElementById("friend_email").value;
	var a=document.getElementById("friend_name").value;
	if(b==""||a==""){
		if(language=='en'){alert("The email address or your friend's name can't be blank！") }
		else{alert("您朋友的email地址或者名称不能为空！")}
		if(b==""){document.getElementById("friend_email").select();}
		if(a==""){document.getElementById("friend_name").select();}
		return false;
	}
	if(b.indexOf("@")<0||b.indexOf(".")<0){
		if(language=='en'){alert("Please input the valid format email address.") }
		else{alert("请填写正确的email地址.")}
		document.getElementById("friend_email").select();
		return false;
	}
	return true;
}
function do_send_to_friend(job_id,friend_email,friend_name){
  var url="/Ajax/job_ajax.php";
	  $.post(url, {job_id: job_id,friend_email:friend_email,friend_name:friend_name,action:'save'}, function(data){
       $.modal.close(); 
    });
}