/*
*去空格
*/
function trim(value){
		return value.replace(/(^\s*)|(\s*$)/g,"");
}
/*
*IN NULL OR EMPTY
*/
function isNullOrEmpty(value){
	
	var result = false;
	if (value == null || 
		value == undefined || 
		value == "null" || 
		value == ""){
		result = true;
	}
	return result;
}
function addProductnotify(){
	
	var productId=document.getElementById("productId").value;
	
	var customerId=document.getElementById("customerId").value;
	
	var email=document.getElementById("email").value;
	
	var phone=document.getElementById("phone").value;
	
	var comment=document.getElementById("comment").value;
	
	var Parameter={"productId":productId,"customerId":customerId,"email":email,"phone":phone,"comment":comment};
	//alert(json);
	//var Parameter = eval("(" + json + ")");
	//alert(Parameter);
	if(!isNullOrEmpty(trim(phone))){
		 //手机号码
    var patternss = /^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/;
      var ss = /^(?:13\d|15\d|18\d)-?\d{5}(\d{3}|\*{3})$/;
      	if (!(ss.test(phone))){
      		if(!patternss.exec(phone)){
      		alert('请输入正确的固定电话,如010-63458858或010-63458858-025或者正确的手机号码,如13501284888或15811445345');
      		return;
      	}
        }
	}
	if(isNullOrEmpty(trim(email))){
		alert('请您填写有效的E-mail的地址！');
		return;
	}else{
		//电子邮件
      var pattern =/(\S)+[@]{1}(\S)+[.]{1}(\w)+/;
      if(!pattern.exec(email)){
        	alert('请输入正确的邮箱地址。如wojiuxihuan@163.com或cn.ryan@sina.com');
        	return;
		}
	}
	if(isNullOrEmpty(trim(comment))){
		alert("请填写附言内容！");
		return;
	}
	productnotifyService.insertRecord("productnotify_sqlMap.addProductnotify",Parameter,{callback:function(returnValue){
		if(returnValue==0){
			return;
		}else{
			alert('添加成功！');
			window.close();
		}
	}});
}
function toProductnotify(id,name,uid){
	if(isNullOrEmpty(uid)){
		alert("请先登陆！");
		return;
	}
	window.open(jsCtx+'/jsp/shop/productNotify.jsp?productId='+id+'&productName='+encodeURI(encodeURI(name)),'','height=504px,width=450px,menubar=no, scrollbars=no, resizable=no,location=no, status=no');
}
function toShowProductnotify(id,name){
	window.open(jsCtx+'/product/productnotifyMessage.do?method=viewProductnotify&productId='+id+'&name='+encodeURI(name),'','height=504px,width=450px,menubar=no, scrollbars=no, resizable=no,location=no, status=no');
}
//后台删除到货通知
function deleteNotify(id,evnt){
	//alert(1);
	productnotifyService.removeRecord("productnotify_sqlMap.deleteNotify",id,{callback:function(returnValue){
		if(returnValue==0){
			alert('删除失败！');
			return;
		}else{
			var table=document.getElementById("notifyTable");
			var i=evnt.parentNode.parentNode.rowIndex;
			table.deleteRow(i);
			alert('删除成功！');
		}
	}});
}