var basicQuhao=new Array('010','021','022','023','0471','0474','04813','0472','0478','0473','0477','0470','04812','04801','0476','0479','04814','0475','04857','04802','0351','0354','0350','0352','0357','03651','0359','0353','0355','0356','0311','03278','03215','0318','0319','03286','0310','0317','03439','03426','0315','0335','0335','0314','0316','0313','0312','03234','03244','　','　','　','024','0419','0410','0410','0413','0412','04221','0417','0411','0411','0414','0415','0416','04261','04262','04284','04285','0418','04271','　','　','　','0431','0438','0432','04423','0433','04436','04438','04435','0435','0435','0439','0448','0434','0434','0437','0436','0436','　','　','　','0451','0450','04616','0455','0458','0454','0454','04640','04619','0454','0453','04638','0453','0452','0459','04661','0456','04678','025','05291','0511','05211','0519','0510','05218','05217','0512','05221','0516','0518','0517','0517','05274','0515','05251','0514','05241','05245','0513','0551','0554','0552','0557','05600','0558','0558','0564','0565','0550','0553','0559','0555','0562','0559','0559','0556','0531','05411','05412','0534','0533','05431','05461','0536','05465','05469','0535','0896','0532','0538','05481','05482','0537','05437','0530','05400','05471','05472','0580','0570','0571','0574','0571','0574','0571','0574','0571','0574','0571','0574','0571','0574','0571','0574','0571','0574','0575','0574','0575','0580','0575','0577','0579','0577','0579','0577','0579','0577','0578','0577','0579','0577','0579','0577','0578','0577','0579','0580','0575','0580','0575','0576','0575','0580','0572','0576','0572','0576','0572','0576','0572','0576','0573','0576','0573','0576','0573','0579','0573','0579','0573','0578','0573','0578','0578','0578','0578','0578','0578','0570','0578','0570','0570','0577','0570','0577','0570','　','　','　','0791','0792','0798','0793','07032','0795','0790','0799','0797','0796','07060','0794','0794','　','　','　','0591','0594','0599','0599','0592','0595','0595','0596','0597','0598','0598','　','　','　','0731','0732','0732','0733','0737','0730','0730','0736','0736','07481','07483','0738','0738','0738','0745','07429','0734','0734','0739','0735','0746','0746','027','07232','0728','0712','07223','07225','07214','07213','0716','07264','07267','0714','0711','07239','0715','0710','07255','07202','07207','07292','0719','0717','07275','0718','07287','　','　','　','0371','0373','0391','0372','03812','0393','0374','03813','03011','0376','03851','0375','0379','03891','03887','0377','0378','0370','020','0763','0769','0751','0753','0754','0768','0752','0660','0762','0755','0759','0668','0758','0757','0760','0750','0662','0898','0898','0899','08001','0771','07815','0776','0777','0779','0775','0773','0774','0772','0772','0778','　','　','　','0851','0858','0856','0855','0854','0853','0859','0852','0852','　','　','　','028','0833','0834','0812','0838','0816','0835','0839','08252','0837','0831','0818','0817','08260','0832','0813','0830','　','　','　','0871','08811','0874','0870','08844','0873','0872','0878','0875','0877','029','0910','0913','09238','0911','0917','0916','0919','0931','09430','0930','0935','0936','0937','09477','09471','09455','0938','0933','0934','0951','0953','0953','0952','0971','0974','0979','0977','0991','0994','0993','0992','09093','0990','09003','0999','09009','0995','09022','0996','0997','0998','09081','09032','0891','0892')
var name=""
var mobile=""
var quhao=""
var phone=""
var tel=""
var content=""
var stockId="";
//验证手机
function checkMobile(mobile,id){

	var msg;
	var flag = true;
	if(mobile == null || mobile ==""){
		msg = "手机号码不能为空";
		flag = false;
	}else{
		if(mobile.search(/\D/g)!=-1){
			msg = "手机号必须为数字";
			flag = false;
		}else if(mobile.search(/^0/g)==-1&&mobile.search(/^13/g)==-1&&mobile.search(/^15/g)==-1&&mobile.search(/^18/g)){
			msg = "手机号必须以0,13,15或18开头";
			flag = false;
		}else if (mobile.search(/^0/g)==-1 ){
			if(mobile.length!=11){
				msg = "对不起，非0开头的手机号码必须为11位";
				flag = false;
			}
		}else if(mobile.search(/^0/g)!=-1 ){
			if(mobile.length<8||mobile.length>12){
				msg = "对不起，手机号码长度不对";
				flag = false;
			}
		}
	}
	if(!flag){
		alert(msg);
		$(id).value = "";
		$(id).focus();
	}
	return flag;
}
//验证用户名
function checkName(name,id){
	//alert(name+" :"+id);
	var msg;
	var flag = true;
	if(name == null || name==""){
		msg = "姓名不能为空";
		flag = false;
	}else if(name.length>8){
		msg = "对不起,用户名长度不能大于8";
		flag = false;
	}
	if(name.search(/\d/g)!=-1||name.search(/[_]/g)!=-1){
		msg = "对不起,用户名不能有数值和下划线";
		flag =  false;
	}
	if(!flag){
		alert(msg);
		$(id).value = "";
		$(id).focus();
	}
	return flag;
}
//验证区号
function checkQuhao(quhao,phone,quhaoId,phoneId){
	var msg;
	var flag = true;
	var id;
	if(quhao == null || quhao ==""){
		msg = "区号不能为空";
		flag =  false;
		id = quhaoId;
	} else {
		var right = false;
		for(var i=0;i<basicQuhao.length;i++){
			if(quhao==basicQuhao[i]){
				right = true;
				break;
			}
		}
		if(!right){
			msg = "对不起，请输入正确的区号";
			flag =  false;
			id = quhaoId;
		}else{
			if(phone.length>8||phone.length<6||phone.search(/\D/g)!=-1){
				msg = "对不起，电话号码必须为6到8位的数字";
				flag =  false;
				id = phoneId;
			}
		}
	}
	if(!flag){
		alert(msg);
		$(id).value = "";
		$(id).focus();
	}
	return flag;
}
//验证股票代码
function checkStockId(stockId,id){
	var msg;
	var flag = true;
	if(stockId == null || stockId==""){
		msg = "股票代码不能为空";
		flag = false;
	}else if(stockId.length >=7||stockId.length<5){
		msg = "股票代码长度只能为5或6";
		flag =  false;
	}
	if(!flag){
		alert(msg);
		$(id).value = "";
		$(id).focus();
	}
	return flag;
}
function go(){
	//alert("go");
 	name = document.getElementById("name1").value;
 	mobile = document.getElementById("mobile1").value;
 	quhao = document.getElementById("quhao1").value;
 	phone = document.getElementById("phone1").value;
 	tel = quhao+"-"+phone;

	if(!checkName(name,"name1")){
		return false;
	}
	if(!checkMobile(mobile,"mobile1")){
		return false;
	}
	if(quhao == null || quhao == ""){
		tel = "";
	}else{
		if(!checkQuhao(quhao,phone,"quhao1","phone1")){
			return false;
		}
	}
	sendRequest("qdsz");
}


function go1(){
 	name = document.getElementById("name2").value;
 	mobile = document.getElementById("mobile2").value;
 	quhao = document.getElementById("quhao2").value;
 	phone = document.getElementById("phone2").value;
 	tel = quhao+"-"+phone;

	if(!checkName(name,"name2")){
		return false;
	}
	if(!checkMobile(mobile,"mobile2")){
		return false;
	}
	if(quhao == null || quhao == ""){
		tel = "";
	}else{
		if(!checkQuhao(quhao,phone,"quhao2","phone2")){
			return false;
		}
	}
	sendRequest("zsxt");
}


function go2(){
 	name = document.getElementById("name3").value;
 	mobile = document.getElementById("mobile3").value;
 	quhao = document.getElementById("quhao3").value;
 	phone = document.getElementById("phone3").value;
 	tel = quhao+"-"+phone;
 	content = document.getElementById("textarea").value;
 	stockId = document.getElementById("stockId3").value;
	
	if(!checkName(name,"name3")){
		return false;
	}
	if(!checkMobile(mobile,"mobile3")){
		return false;
	}
	if(quhao == null || quhao == ""){
		tel = "";
	}else{
		if(!checkQuhao(quhao,phone,"quhao3","phone3")){
			return false;
		}
	}
	if(!checkStockId(stockId,"stockId3")){
		return false;
	}
	if(content.length<10){
		alert("对不起，你输入的问题太短了，请重新填写")
		$("textarea").value=""
		$("textarea").focus()
		return false;
	}
	
	sendRequest2();
}

function sendRequest2() {
			    var url = "/customerQuestion.do";  
			    var mailAjax = new Ajax.Request(    
			        url,    
			        {   
			        	parameters:"name="+encodeURIComponent(name)+"&mobile="+mobile+"&tel="+tel+"&question="+content+"&stockId="+stockId,
			            method: 'post',    
			            onComplete: showResponse2    
			        }    
			    );    
	}
	
	function sendRequest(type) {
    			
			    var url = "/chanceStock.do";  
			    
			    var mailAjax = new Ajax.Request(    
			        url,    
			        {   
			        	parameters:"name="+name+"&mobile="+mobile+"&tel="+tel+"&type="+type,
			            method: 'post',    
			            onComplete: showResponse   
			        }    
			    );    
	}
	function showResponse2(originalRequest) {  
			 
			    if(originalRequest.responseText == "success"){
			    	check();
			    }else{
			    	alert("对不起,您使用次数已经超过,不能再使用,如果新需求,请联系客服:021-52400078");
			    }
			
	}		    
	function showResponse(originalRequest) {  
			alert("恭喜保存成功,新利多将会关注您的需求");
			
	}		    
   
			
var xmlHttp;
var phoneNumber;
var isOk;
var rname;
var userName;
function createXMLHttpRequest(){
	if (window.XMLHttpRequest) {
	    xmlHttp = new XMLHttpRequest();
	  } else if (window.ActiveXObject) {
	    try {
	      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	    } catch (e1) {
	      try {
	        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	      } catch (e2) {
	        xmlHttp = false;
	      }
    	}
	}
}
function sendRequest111(type){//开始请求


	var url = "/lidoocom/chanceStock.do";  
	var parameters = "?name="+name+"&mobile="+mobile+"&tel="+tel+"&type="+type
	
	createXMLHttpRequest();//创建一个XMLHttpRequest对象
	xmlHttp.onreadystatechange=handleStateChange;//在状态改变时调用handStateChang方法
	
	xmlHttp.open("POST",url+parameters,true);
	alert(url+parameters)
	xmlHttp.send(null);
}
function handleStateChange(){
	if(xmlHttp.readyState==4){//请求状态是否完成

		if(xmlHttp.status==200){//服器是否OK
			alert("提交成功111")
		}
	}
}

