/**专为跨域的AJAX (速度测试)
 * Ajax类构造函数
 * @param {Object} url  请求URL,如Action路径或jsp等
 * @param {Object} params 请求的参数值
 * @param {Object} component  回调响应对象
 * @param {Object} method  回调方法，默认为ajaxUpdate
 * @author duncan
 * @lastEdit 2008-06-18
 * @version 1.0
 * @createTime 2008-06-18
 * @return 返回Ajax对象
 */
var Ajax = function(config){
	this.url = config.url;    //请求URL	
	this.params=config.params;     //请求参数	
	this.component = this;    //回调对象
	this.method='success'; //AJAX的回调方法,默认为success
	this.sendRequest();
};
Ajax.prototype = {	 	
	 /**
	 * 发送请求
	 * @author duncan
	 * @lastEdit 2008-06-18
	 */
	sendRequest : function(){	
		var scriptId=new Date().getTime();
		var script = document.createElement("script");
        script.setAttribute("src",this.url );
        script.method=this.method;
        script.component=this.component;
        script.onreadystatechange = function(){//IE用
                var state = script.readyState;
                if (state == "loaded") {
                     this.component[this.method]();
                }
        };
        document.body.appendChild(script);        
	}
};
var ZC={

     addZC:function(){
          var name=document.getElementById("name").value;
          if(name==null||name==""){
            alert("请输入姓名");
            document.getElementById("name").focus();
            return;
          }
          var productId=document.getElementById("productId").value;
          if(productId==null||productId==""){
            alert("请输入产品ID号");
            document.getElementById("productId").focus();
            return;
          }
          var phone=document.getElementById("phone").value;
          if(phone==null||phone==""){
            alert("请输入联系电话");
            document.getElementById("phone").focus();
            return;
          }
        var email=document.getElementById("email").value;
        if(email==""){
           alert("请输入email地址");
            document.getElementById("email").focus();
            return;
	   }
	  
	  //检测用户名
	  var userNameReg=/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/;
	  if(!userNameReg.exec(email)){
	      alert("请输入正确的email地址");
            document.getElementById("email").focus();
            return;
	  }
         var ajax=new Ajax({url:'http://zhsh.netfilm.cn/addZC.do?name='+name+"&productId="+productId+"&phone="+phone+"&email="+email});
         ajax.success=function(){
           if(success){
           document.getElementById("name").value="";
           document.getElementById("productId").value="";
           document.getElementById("phone").value="";
           document.getElementById("email").value="";
           alert("注册成功");
          }else{
           if(data==1){
            alert("对不起，请输入完整信息");
           }else if(data==2){
            alert("对不起，系统错误请稍候再试");
           }
          }
         }
     }
};
