jQuery.fn.hint = function (blurClass) {if (!blurClass) { blurClass = 'blur';}
  return this.each(function () {
    var $input = jQuery(this), title = $input.attr('title'), $form = jQuery(this.form), $win = jQuery(window);
    function remove() {
      if ($input.val() === title && $input.hasClass(blurClass)) {$input.val('').removeClass(blurClass);}
    }
    if (title) { $input.blur(function () {if (this.value === '') {$input.val(title).addClass(blurClass);}}).focus(remove).blur();
      $form.submit(remove); $win.unload(remove); 
    }
  });
};

 function closeComments(cid){ var cntc = 0;
    var cntc= $.ajax({ type: "GET", url: "index.php?s=aj&do=cmnt&ac=count&cid="+cid, async: false }).responseText;
    $('#comments'+cid).hide(); $('#cmLbl'+cid).html('<a href="#" onclick="getComments(\''+cid+'\'); return false;" class="comments_count">Comments ('+cntc+')</a>&nbsp;&nbsp;');
  }
  function getComments(cid){ 
    $.get("index.php?s=aj&do=cmnt&ac=get&cid="+cid,
    function(data){ //alert(cid);
        $('#comments'+cid).html(data);
        $('#cmLbl'+cid).html('<a href="#" onclick="jQuery.facebox({ajax: \'index.php?postComment='+cid+'\'}); return false;" class="btn"><b>Add new comment</b></a>&nbsp;&nbsp;<a class="comments_count" onclick="closeComments(\''+cid+'\'); return false;" href="#">Hide Comments</a>&nbsp;&nbsp;');
        $('#comments'+cid).slideDown();      
    });
  } 
  
   function postNewComment(cid,need){ 
  if($('#comment').val()=='Share your thoughts here')
  {
	  show_message('Please enter your comment!',1,"Warning","alert");
	  $('#comment').focus();
	  return false;
  }
  var comment = $('#comment').val();
  if(comment.length<3)
  {
	  show_message('Your comment is too short!',1,"Warning","alert");
	  $('#comment').focus();
	  return false;
  }
  if(need==1)
  {
  	if (!validateCaptcha())
  	{
	   alert("Captcha is wrong!");
	   return false;
  	}
  if($('#comment').val()=='')
  {
	   alert("Please enter your comment!");
	   return false;
   }
    $.post("index.php?s=aj&do=cmntAdd&action=get&cid="+cid, { commentUname: $('#commentUname').val(), commentUid: $('#commentUid').val(), comment: $('#comment').val(), recaptcha_challenge_field: $('#recaptcha_challenge_field').val(), recaptcha_response_field: $('#recaptcha_response_field').val() ,need:1},
    function(data){
		if(data !="wait")
		{
        	$('#comments'+cid).append(data);
        	$('#comments'+cid).show();
			$('#comment').val('');
		}
		else if(data=="wait")
		{
			show_message("Your comments is being reviewed and will be published soon.");
			$('#comment').val('');
		}
		else
		{
			alert("Failed to submit comment!");
		}
    }); 
	return true;
  }
  else
  {
	
  if($('#comment').val()=='')
  {
	   alert("Please enter your comment!");
	   return false;
   }
    $.post("index.php?s=aj&do=cmntAdd&action=get&cid="+cid, { commentUname: $('#commentUname').val(), commentUid: $('#commentUid').val(), comment: $('#comment').val(), need:0 },
    function(data){
		if(data !="wait")
		{
        	$('#comments'+cid).append(data);
        	$('#comments'+cid).show();
			$('#comment').val('');
		}
		else if(data=="wait")
		{
			show_message("Your comment is being reviewed and will be published soon.");
			$('#comment').val('');
		}
		else
		{
			alert("Failed to submit comment!");
		}
    }); 
	return true;   
   }
   //jQuery(document).trigger('close.facebox');
}
  function contactUs(){ 
    $.post("index.php?s=aj&do=contactUs&action=get&cid="+cid, { commentUname: $('#commentUname').val(), commentUid: $('#commentUid').val(), comment: $('#comment').val()  },
    function(data){
        $('#comments'+cid).html(data);
        $('#comments'+cid).show();      
    });
  }
  function postNewCoupon(cid){ 
    $.post("index.php?s=aj&do=cpnAdd&action=get&cid="+cid, { commentUname: $('#commentUname').val(), commentUid: $('#commentUid').val(), comment: $('#comment').val()  },
    function(data){
             
    });
  }
  
function voteDeal(cid, userID, vote){ 
    $.post("index.php?s=aj&do=vote&cid="+cid, { cid: cid, userID: userID, vote:vote  },
    function(data){ 
	returned = data.split("||"); 
	var rate; 
	rate =  returned[3]; 
	rate =  rate+'%';
        $('#sukRt'+cid).html(rate);    
       // $('#vote_deal'+cid).html('<em class="good_x"><span class="votes_count">'+returned[0]+'</span></em><em class="bad_x"><span class="votes_count">'+returned[1]+'</span></em>');
		$('#vote_deal'+cid).html('<p class="cp_ms_wz1">&nbsp;</p>');
            
    }); 
	return false;
  }
/**
  function plusDeal(cid, userID, vote){ 
    $.post("index.php?s=aj&do=vote&cid="+cid, { cid: cid, userID: userID, vote:vote  },
    function(data){ returned = data.split("||"); var rate; rate =  returned[3]; rate =  rate+'%';
        $('#sukRt'+cid).html(returned[0]);    
        $('#vote_deal'+cid).html('<em class="good_x"><span class="votes_count">Voted</span></em>');
            
    }); return false;
  }
  **/
function plusDeal(did, userID, vote){ 
    $.post("index.php?s=aj&do=plus&did="+did, { did:did, userID: userID, vote:vote  },
    function(data){ 
	returned = data.split("||"); 
	var vote; 
	vote =  returned[0];
        $('#vote'+did).html(vote);    
        $('#voted'+did).html('<strong >voted</strong>');
            
    }); return false;
  }
function fb(url){
	jQuery.facebox({ajax: url});
}  

  
function validateCaptcha(){ challengeField = $("input#recaptcha_challenge_field").val(); responseField = $("input#recaptcha_response_field").val();
  var html = $.ajax({ type: "POST", url: "index.php", data: "tst=tst&recaptcha_challenge_field=" + challengeField + "&recaptcha_response_field=" + responseField,
        async: false }).responseText; 
  if(html == "OK") { return true; } else {
    $("#captchaStatus").html("The security code you entered did not match. Please try again."); Recaptcha.reload(); return false;
  }
} 
<!-- 删除alert -->
function delete_user_alert(cid){
    $.post("index.php?s=aj&do=deleteUserAlert&action=get&cid="+cid,
    function(data){
    	location.reload();
    }); return true;
}
<!-- 编辑alert -->
function edit_user_alert(cid){
	var value = $("#user_alert_"+cid).html();
	$("#user_alert_"+cid).html('<input type="text" value="'+value+'" id="user_new_alert_'+cid+'" class="submit_inp2" style="width:130px;" />&nbsp;&nbsp;&nbsp;<a href="javascript:void(0)" onclick="update_user_alert('+cid+');" style="color:#5F615C;">Update</a>&nbsp;&nbsp;&nbsp;<a href="javascript:void(0)" onclick="cancel_user_alert('+cid+',\''+value+'\');" style="color:#5F615C;">Cancel</a>');
	$("#user_alert_edit_"+cid).hide();
}
<!-- 取消编辑 -->
function cancel_user_alert(cid,value){
	$("#user_alert_"+cid).html(value);
	$("#user_alert_edit_"+cid).show();
}
<!-- 更新alert -->
function update_user_alert(cid){
	var value = $("#user_new_alert_"+cid).val();
	$.post("index.php?s=aj&do=updateUserAlert&action=get&cid="+cid+"&keyword="+value,
    function(data){
		if (data == 'ok') {
			$("#user_alert_"+cid).html(value);
		    $("#user_alert_edit_"+cid).show();
			return true;
		} else {
			alert('You\'ve already added this keyword alert!');
			return false;	
		}
    }); 
}
<!-- 查询下一级菜单 -->
function show_next_categorie(cid){
    $.post("index.php?s=aj&do=cateNext&action=get&cid="+cid,
    function(data){
        $('#cate_next').html(data);     
    }); return true;
}
<!-- 标题联动 -->
function ajax_input_title(){
	var value = $("#deal_url_title").val();
	$("#previow_url_title").html(value);
}
<!-- 价格联动 -->
function ajax_input_price_pay(){
	var value = $("#deal_pay_price").val();
	$("#previow_url_price").html(value);
	$("#previow_url_price_2").html(value); 
}
function ajax_input_original_price(){
	var value = $("#original_price").val();
	$("#previow_list_price").html(value);
}
<!-- 所属商店联动 -->
function ajax_input_store_name(){
	var value = $("#deal_store_name").val();
	$("#deal_input_store_name").html(value);
}
<!-- deal非空选项检查 -->
function deal_check_submit(form){
	if (form.url_title.value == '') {
		form.url_title.focus(); return false;
	}
	if ($("#selectStoreName").val() == '0') {
		if (form.store_name.value == 'Enter the store name') {
			form.store_name.focus(); return false;
		}
	}
	if (form.url_image.value == '' && form.upload_image.value == '') {
		alert('Please Add a URL Or Upload an Image!'); return false;
	} 
	if (form.url_image.value != '' && form.upload_image.value != '') {
		alert('You can either add an image  URL or upload an image!'); return false;
	}
	if ($("input[name='radio5']:checked").val() == 'HotDeals') {
		if (form.pay_price.value == '') {
			form.pay_price.focus(); return false;
		} 
		if ($("#ShippingPrice").val() == '0') {
			alert('Please select a shipping method'); return false;
		} else if ($("#ShippingPrice").val() == '4') {
				   if ($("#ship_price").val() == '' || $("#ship_price").val() == 'e.g: $15.00') {
					   alert('Please enter shipping charge'); return false;	
				   }
		}
	}
	if ($("#ExpiringDate").val() == '2') {
		if ($("#inputDatepicker").val() == '') {
			alert('Please change the expiring date'); return false;	
		}
	}
	for(i=0; i<form.categories.length; i++) {
    	if(form.categories[i].checked == true) return true;
	}
    alert('Please select a category!');
	return false;
}
<!-- coupon非空选项检查 -->
function coupon_check_submit(form){
	if (form.store_name.value == '') {
		form.store_name.focus(); return false;
	} 
}
<!-- coupon_share 检查 -->
function check_coupon_share(value) {
	$.post("index.php?s=aj&do=coupon_check&action=get&store_name="+value,
    function(data){
    	if (data == '0') {
			$("#coupon_check_allowed").html('Sorry! This Store is not allowed to share coupon ');
			$("#couponSubmit").attr("disabled",true);
		} else {
			$("#coupon_check_allowed").html('');
			$("#couponSubmit").attr("disabled",false);
		}
    });
}
<!-- 输入框有默认值 -->
function inputAutoClear(ipt){
    ipt.onfocus=function()
    {this.style.color='#000000';if(this.value==this.defaultValue){this.value='';}};
    ipt.onblur=function()
    {this.style.color='#999999';if(this.value==''){this.value=this.defaultValue;}};
    ipt.onfocus();
}
/*
 function closeComments(cid){ var cntc = 0;
    var cntc= $.ajax({ type: "GET", url: "index.php?s=aj&do=cmnt&ac=count&cid="+cid, async: false }).responseText;
    $('#comments'+cid).hide(); $('#cmLbl'+cid).html('<a href="#" onclick="getComments(\''+cid+'\'); return false;">Comments ('+cntc+')</a>&nbsp;&nbsp;');
  }
  function getComments(cid){ 
    $.get("index.php?s=aj&do=cmnt&ac=get&cid="+cid,
    function(data){ //alert(cid);
        $('#comments'+cid).html(data);
        $('#cmLbl'+cid).html('<a href="#" onclick="jQuery.facebox({ajax: \'index.php?postComment='+cid+'\'}); return false;" class="btn"><b>Add new comment</b></a>&nbsp;&nbsp;<a class="comments_count" onclick="closeComments(\''+cid+'\'); return false;" href="#">Hide Comments</a>&nbsp;&nbsp;');
        $('#comments'+cid).show();      
    });
  } 
  
  function contactUs(){ 
    $.post("index.php?s=aj&do=contactUs&action=get&cid="+cid, { commentUname: $('#commentUname').val(), commentUid: $('#commentUid').val(), comment: $('#comment').val()  },
    function(data){
        $('#comments'+cid).html(data);
        $('#comments'+cid).show();      
    });
  }
  function postNewCoupon(cid){ 
    $.post("index.php?s=aj&do=cpnAdd&action=get&cid="+cid, { commentUname: $('#commentUname').val(), commentUid: $('#commentUid').val(), comment: $('#comment').val()  },
    function(data){
             
    });
  }
  function showRecaptcha(element) { Recaptcha.create("{/literal}{$settings.publickey}{literal}", element, {
    theme: "red", callback: Recaptcha.focus_response_field});
  }
  function voteDeal(cid, userID, vote){ 
    $.post("index.php?s=aj&do=vote&cid="+cid, { cid: cid, userID: userID, vote:vote  },
    function(data){ returned = data.split("||"); var rate; rate =  returned[3]; rate =  rate+'%';
        $('#sukRt'+cid).html(rate);    
        $('#vote_deal'+cid).html('<em class="good_x"><span class="votes_count">'+returned[0]+'</span></em><em class="bad_x"><span class="votes_count">'+returned[1]+'</span></em>');
            
    }); return false;
  }
  function fb(url){
    jQuery.facebox({ajax: url});
  }
	
*/	
/***replay comments****/
function replayComments(cid,did,uid)
{
	if(uid>0)
	{
	var str='';
	str  = '<textarea id="replay'+cid+'" name="replay" style="width:500px; height:75px; padding:10px;" class=" italic hui"></textarea>';
	str += '<br />';
	str += '<input type="button" name="postReplay" onclick="postReplay('+cid+','+did+','+uid+')" class="btnMainSearch"  value="Replay" style="border:1px solid #ccc;" />';
	$('#commentdesc'+cid).html(str);
	}
  else
  {
  	fb('signin');
  }
	
}
/****post Comments*****/
function postReplay(cid,did,uid)
{
	var replayContent = $('#replay'+cid).val();
  {
	if(replayContent.length>1)
	{
	$.post("index.php?s=aj&do=replay&action=get&cid="+cid, { uid: uid, replay: replayContent,deal_id:did },
    function(data){
		if(data !=0)
		{
       		$('#commentdesc'+cid).html('');
	   		$('#comReplayDiv'+cid).append(data);
		}
		else
		{
		    alert("Failed to reply comment!");	
		}
    });
	}
	else
	{
		alert("Reply cannot be empty!");
		return false;
	}
  }
 
	
}
/**comment vote***/
function doComVote(cid,uid,vote)
{
	
    $.post("index.php?s=aj&do=doComVote&action=get&cid="+cid, { uid: uid, vote: vote},
    function(data){
		if(data !=-1)
		{
       		$('#dovVoteDiv'+cid).html('<img src="templates/dealdigs/img/+0.jpg" /><span>'+data+'</span><img src="templates/dealdigs/img/-0.jpg" />');
		}
		else
		{
		    alert("Vote failed!");	
		}
    });	
	
}
     
//验证表单是否为空

function is_empty (input) {
	var val=input.value;
	var id=input.id;
	var spanId="msg"+id;
	$.post("index.php?s=aj&do=is_empty&action=get&value="+val,
    function(data){
    	if (data == 'true') {
			$("#font"+id).attr("color","#FF0000");
			$("#"+spanId).html('Please enter all required information!');
			$("#submit").attr("disabled",true);
		} else if(data == 'false') {
			$("#"+spanId).html('');
			$("#submit").attr("disabled",false);
			
		}
    });
	
	
}

//验证美国邮编
function validateZipCode(input){
	var val=input.value;
	var id=input.id;
	var spanId="msg"+id;
    //var zipCodePattern = /^\d{5}$|^\d{5}-\d{4}$/;
	
	$.post("index.php?s=aj&do=validateZipCode&action=get&value="+val,
    function(data){
    	if (data == 'false') {
			$("#font"+id).attr("color","#FF0000");
			$("#"+spanId).html('wrong zip code!');
			$("#submit").attr("disabled",true);
		} else if(data == 'true') {
			$("#"+spanId).html('');
			$("#submit").attr("disabled",false);
		}
    });
	
    
}



//ajax邮箱验证

function check_email(email) {
	
    $.post("index.php?s=aj&do=check_email&action=get&email="+email,
    function(data){
		if (data == 'used')  {
			$("#font1").attr("color","#FF0000");
			$("#warnning1").html('Email used!');
			$("#submit").attr("disabled",true);
		} else if (data == 'false') {
			$("#font1").attr("color","#FF0000");
			$("#warnning1").html('Malformed!');
			$("#submit").attr("disabled",true);
		} else if(data == 'true') {
			$("#font1").attr("color","#006600");
			$("#warnning1").html('Available!');
			$("#submit").attr("disabled",false);
			
		}
    });
}






//密码修改
function check_password_form(){
	   
	var strOldPassword = $("#oldPassword").val();
	//alert(strOldPassword);
	var strNewPassword=document.getElementById('newPassword').value;
	var strConfirmPassword=document.getElementById('confirmPassword').value;
	var warnningText1=document.getElementById('warnning1');
	var warnningText2=document.getElementById('warnning2');
	var warnningText3=document.getElementById('warnning3');
	
	if (strOldPassword=="") {
		 warnningText3.innerText="";
		 warnningText3.innerText="Please enter the old password!";
         document.getElementById('oldPassword').focus();
		 return false;
		} else if (strNewPassword.length<6) {
		 warnningText1.innerText="";
		 warnningText1.innerText="The minimum lenght is 6!";
		 document.getElementById('newPassword').value="";
		 document.getElementById('confirmPassword').value="";
         document.getElementById('newPassword').focus();
		 return false;
		} else if( strNewPassword !== strConfirmPassword ){
			  warnningText2.innerText="";
		      warnningText2.innerText="Password does not match!";
			  document.getElementById('confirmPassword').value="";
			  document.getElementById('newPassword').value="";
              document.getElementById('confirmPassword').focus();
			  return false;
		} else {
			return true;
		
		}

}




function check_pic_form(){
	   
	var strPic=document.getElementById('pho').value;
	var warnningText=document.getElementById('warnning');
	
	
	
	if (document.getElementById('pho').value != "")
   {
	  
       return true;
   } else {
	   
	   warnningText.innerText="";
	   warnningText.innerText="Please choose an image file!";
       strPic="./deal_pictures/user_img/defualt/sc_09.jpg";
       document.getElementById('pho').focus();
       return false;
    }

}


//发现bug，调查弹窗
function survey_window() {
	
	var screenwWidth=screen.width;var screenheight=screen.height;var cutWidth=screenwWidth/5;
	
     window.open('bug_report.html','_blank','height='+screenheight+',width='+cutWidth*3+',top=0,left='+cutWidth+',toolbar=no,menubar=no,scrollbars=yes, resizable=yea,location=no, status=no,alwaysRaised=yes,directories=no,titlebar=no');
	
}



//删除确认
function confirm_delete() {
	   
	    var bln = window.confirm("Are you sure? You acount will be permanently and completely deleted in 48 hours. If you do not want to delete you acount now, please click the cansel button.");   
        if(bln) {
			survey_window();
			window.location.href="logout";
		}
	   
}

//删除调查
function delete_survey() {
	alert("Your account will be completely and permanently within 48 hours!");
	if (top.location !== self.location) {top.location = 'logout';}
}

//添加payment address验证
function address_check() {
	
	var pal_email = $("#pal_email").val();
	var first_name = $("#first_name").val();
	var last_name = $("#last_name").val();
	var address_line1 = $("#address_line1").val();
	var city = $("#city").val();
	var zip = $("#zip").val();
	var phone = $("#phone").val();
	var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
	var zipTest = /^\d{5}(-\d{4})?$/;
	var phoneTest = /^[2-9]{1}[0-9]{2}-[0-9]{3}-[0-9]{4}$/;
	if(!myreg.test(pal_email))
          {
			  show_message('Please enter the correct PayPal account.',1,"Erro","erro");
			  $("#pal_email").focus();
			  return false;
		}
	if(first_name.length<1)
	{
		show_message('Please enter your first name.',1,"Erro","erro");
		$("#first_name").focus();
		return false;
	}
	if(last_name.length<1)
	{
		show_message('Please enter your last name.',1,"Erro","erro");
		$("#last_name").focus();
		return false;
	}
	if(address_line1.length<1)
	{
		show_message('Please enter your address.',1,"Erro","erro");
		$("#address_line1").focus();
		return false;
	}
	if(city.length<1)
	{
		show_message('Please enter city name.',1,"Erro","erro");
		$("#city").focus();
		return false;
	}
	if(!zipTest.test(zip))
    {
		show_message('Please enter correct  zip code.',1,"Erro","erro");
		$("#zip").focus();
		return false;
	}
	if(!phoneTest.test(phone))
	{
		show_message('Please enter your phone number.',1,"Erro","erro");
		$("#phone").focus();
		return false;
	}
	

}
//修改密码验证
function checkchangePwd()
{
	var oldPassword = $("#oldPassword").val();
	var newPassword = $("#newPassword").val();
	var confirmPassword = $("#confirmPassword").val();
	if(oldPassword.length<6)
	{
		show_message("Please input  correct old password!",1,"Erro","erro");
		$("#oldPassword").focus();
		return false;
	}
	if(newPassword.length<5)
	{
		show_message("The minimum length of password is 6!",1,"Erro","erro");
		$("#newPassword").focus();
		return false;
	}
	if(confirmPassword.length<5)
	{
		show_message("Invalid Confirm Password!",1,"Erro","erro");
		$("#confirmPassword").focus();
		return false;
	}
	else
	{
		if(confirmPassword!=newPassword)
		{
			show_message("New password do not match!",1,"Erro","erro");
			$("#confirmPassword").focus();
			return false;
		}
	}
}



