var actionPage="/common/recommend.php";

function show_recommend_window(tb_id,tb_type,tb_is_products){
	window.open("/common/recommend.php?tb_id="+tb_id+"&tb_type="+tb_type+"&tb_is_products="+tb_is_products+"&recommend_url="+window.location.href,"wnd_recommend","menubar=no,location=no,resizable=no,width=600,height=600,scrollbars=yes,status=yes");
}

function check_mail_list(){
	var arr_email_list=$("txt_receiver_email").value.trim().split(",");
	if($("txt_receiver_email").value.trim().length==0){
		return "err_receiver_email";
	}
	for(var counter=0;counter<arr_email_list.length;counter++){
		var v_email_list=arr_email_list[counter].trim();
		if(!v_email_list.isEmail()){
			return "err_receiver_email";
		}

	}
	return "";
}

function check_name(){
	var v_name=$("txt_name").value.trim();
	if(v_name.length==0 || v_name.isChinese()){
		return "err_name";
	}
	return "";
}

function check_mail(){
	var v_mail=$("txt_email").value.trim();
	if(v_mail.length==0){
		return "";
	}
	if(!v_mail.isEmail()){
		return"err_email";
	}
	return "";
}

function check_content(){
	var v_content=$("txt_content").value.trim();
	if(v_content.length<1 || v_content.length>1000 || v_content.isChinese()){
		return "err_content";
	}
	return "";
}

function send_recommend(){
	var errs=new Array();
	errs.push(check_mail_list());
	errs.push(check_name());
	errs.push(check_mail());
	errs.push(check_content());

	errorCodes=implode(",",errs);

	if(errorCodes==""){
		var varObjs=new Array("txt_receiver_email","txt_name","txt_email","txt_content","tb_id","tb_type","tb_is_products");
		/* 开始提交数据 */
		new Ajax.Request(actionPage, {
			method: 'post',
			parameters:"action=send_recommend&"+assembleParam(varObjs),
			onSuccess: function(transport) {
				switch(parseInt(transport.responseText,10)){
					case 0:
						func=function(){window.close();};
						guide("recommend_success");
						window.close();
					break;
					case 1:
						guide("recommend_faile");
					break;
					default:
						guide("recommend_faile");
				}
//				return;
//				window.close();
			}
		});
		return true;
	}

	guide(errorCodes);
	return false;

}