﻿function ajax() {
    var xmlHttp;
    var objSelf = this;
    this.callBack = function(xmlObj) {return;}//回发函数
    this.method = "POST"; //处理方式
    this.url = ""; //请求地址
    this.async = true; //同步异步
    this.content = ""; //传输数据
    this.send = function() {
        if (window.XMLHttpRequest) {
            xmlHttp = new XMLHttpRequest();
        }
        else if (window.ActiveXObject) {
            xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
        }
        if (xmlHttp != null) {
            xmlHttp.open(this.method, this.url, this.async);
			xmlHttp.setRequestHeader("Content-Type","text/xml");
            xmlHttp.onreadystatechange = function() {
                if (xmlHttp.readyState == 4) {
                   // if (xmlHttp.status == 200) {//如果是本地打开，不能判断status的状态,直接判断readyState
						objSelf.callBack(xmlHttp);
                   // }
                }
            }

			xmlHttp.send();

        }
        else {
            alert('Your browser does not support XMLHTTP.');
        }
    }
}


function getCheckState(CbBox) {
    if (CbBox.checked == true) return '1';
    else return '0';
    return 0;
}

String.prototype.trim=trim;
function trim() {
  return this.replace(/^\s+|\s+$/g, "");
}

String.prototype.clear=clear;
function clear()
{
    return this.replace(/\'|\"|\*|\s+|\&|\=|\+|\<|\>/g,"");
}
function setNull(ctlName,ctlTel,ctlqq,edCuty,ctlemail,Province,City,cbjsj,cbyy,cbjz,cbjj)
{
	ctlName.value='';
	ctlTel.value='';	
	ctlqq.value='';
	ctlemail.value='';
	edCuty.value='';
	Province.options[0].selected = true;
	City.options.length = 0;
   var oOption = document.createElement("OPTION");
   oOption.value="0";
   oOption.text="请选择";              
   City.options.add(oOption);
   City.options[0].selected = true;
	cbjsj.checked=false;
	cbyy.checked=false;
	cbjz.checked=false;
	cbjj.checked=false;
}
function servicePost(edName,edTel,edCuty,edQQ,edEmail,hdstate,Province,City,cbjsj,cbyy,cbjz,cbjj)
{
		if(edName.value=="")
		{
			alert('请输入您的姓名！');
			edName.focus();
			return;
		}	
		if(edCuty.value=="")
		{
			alert('请输入您的单位！');
			edCuty.focus();
			return;
		}
		
		if(edTel.value=='')
		{
			alert('请输入您的电话！');
			edTel.focus();
			return;
		}
		else
		{  
	            var st="0123456789."; 
	            if (edTel.value.length >6)
	            {
	                var str = edTel.value;	    		
	                var j;
		            for (i=0;i<str.length;i++)
		            {
			            j=st.indexOf(str.charAt(i)); 
			            if (j==-1)
			            {
				            alert("请输入7-11位的纯数字电话号码！");		
				            edTel.focus();
				            return;
	                     }	      
	                }
	            }
	            else
	            {
	                alert("请输入7-11位的纯数字电话号码！");		
				            edTel.focus();
				            return;
	            }	    
		}		
			
			if(edQQ.value!="")
			{
			    var st="0123456789."; 
	            if (edQQ.value.length >4)
	            {
	                var str = edQQ.value;	    		
	                var j;
		            for (i=0;i<str.length;i++)
		            {
			            j=st.indexOf(str.charAt(i)); 
			            if (j==-1)
			            {
				            alert("请输入5-11位的纯数字QQ号码！");		
				            edQQ.focus();
				            return;
	                     }	      
	                }
	            }
	            else
	            {
	                alert("请输入5-11位的纯数字QQ号码！");		
				            edQQ.focus();
				            return;
	            }	  
			}			
		if(edEmail.value!="")
		{			
		    var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;  
　　　　　　if(!pattern.test(edEmail.value))
　　　　　　{
　　　　　　   alert('请输入正确的邮箱地址！');
			    edEmail.focus();
		        return ;
　　　　　　}

		}
		var cit=City.options[City.selectedIndex].value;
		if(cit==""||cit=="0")
		{
		    alert('请选择您的地区！');
		    Province.focus();
		     return ;
		}	
		var jsj="";
		var yy="";
		var jz="";
		var jj="";
		if(cbjsj.checked==true)
		     jsj=cbjsj.value;		
		if(cbyy.checked==true)
		     yy=cbyy.value;		
		if(cbjz.checked==true)
		     jz=cbjz.value;		
		if(cbjj.checked==true)
		     jj=cbjj.value;	
		     
		if(hdstate.value=="0")
		{
		   ymPrompt.alert("您的信息已经提交，谢谢！", null,null, '提示', handler);function handler(tp){};
		     return;
		}
               
          ymPrompt.alert('正在处理请求，请稍候...', null,null, '提示', handler);function handler(tp){};              
          var ajaxObject = new ajax();

		ajaxObject.url="ToSave.aspx?Name="+edName.value.clear()+"&Tel=" +edTel.value.clear() +"&QQ=" + edQQ.value.clear()+"&Email=" + edEmail.value.clear()+"&Cuty="+edCuty.value.clear()+"&AreaId="+cit+"&jsj="+jsj+"&yy="+yy+"&jz="+jz+"&jj="+jj;
		ajaxObject.content="";
		ajaxObject.send();  
		
		   
        ajaxObject.callBack = function(xmlObj) 
        {
               if(xmlObj.responseText.trim()=='success')
                {                         
                          hdstate.value="0";
                          ymPrompt.close();
                            ymPrompt.alert('您的信息已经提交，谢谢使用，再见。', null,null, '提示', handler);
                           function handler(tp){};    
                                                 
                }
                else
                {
                    if(xmlObj.responseText.trim()=="IsHave")
                    {
                        ymPrompt.close();
                         ymPrompt.alert('您的信息已经提交，谢谢。', null,null, '提示', handler);
                        function handler(tp){};
                        
                    }
                    else
                    {
                        ymPrompt.close();
                        ymPrompt.errorInfo('提交失败，请检查网络，谢谢。', null,null, '提示', handler);
                        function handler(tp){};
                    }       
               } 
        }       
	  
}
