﻿
//将表里面的数据提出来，提交到服务器里。
function hballsUpdateCustomFormAjax(formName){
var allRight=0;
   if (checkName('companyName'))
    allRight= allRight+1;

    if (checkName('customName'))
    allRight= allRight+1;
    
  if (checkNum('phone'))
    allRight= allRight+1;
    
      if (checkNum('mobilePhone'))
    allRight= allRight+1;
    
      if (checkEmail('email'))
    allRight= allRight+1;
    
      if (checkQq('qq'))
    allRight= allRight+1;
    
          if (checkEmail('msn'))
    allRight= allRight+1;
    
    
	if(allRight==7){
	
	var pars2=Form.serialize(formName);//使用propertype.js把表的字段取出来。

	var checkUser = new Ajax.Request('../order/addCustom.do',{method:'post',parameters:pars2 ,onSuccess:setOk,onFailure:errMain});
	}
}

//如果用户信息成功输入数据库，关闭用户信息提交，打开订单信息提交
function setOk(originalRequest)
{
    
	var sText = originalRequest.responseText;
	var aText = sText.split('\n');
	var aNewText =[];
	aText.each(function(tmp){
		if(tmp!=''&& tmp!='\r'){aNewText.push(tmp);}
	});
	aText = aNewText;
	
	if(parseInt(aText[0])==0){
	error_info=$F('userCheckCode_error');
$('userCheckCode_errorInfo').innerHTML=error_info+'<br/>';
	}
	
	if(parseInt(aText[0])==5){
	$('userCheckCode_errorInfo').innerHTML='';
	$('customupdate').disabled='true';
	$('refreshRandomNo').disabled='true';
	$('orderInfoSubmit').disabled='';
	if(aText.length==2)
	alert(aText[1]);
	}
	
	
	
}

function errMain(originalRequest){
		alert('请重新提交');
		return false;
}

//这个函数检查，用户名的是否为空，及格式是否正确。针对公司名与用户名。
function checkName(Name){
var needCheck=$F(Name);
var error_info='';
if (needCheck.length===0){
error_info=$F(Name+'_error');
$(Name+'_errorInfo').innerHTML=error_info;
return false;
}
else{
$(Name+'_errorInfo').innerHTML='';
//checkFormOfCustomForm(Name);
return true;
}
}

//这个函数检查电话与手机，数据形式的号码，
function checkNum(NumFieldInput){
var needCheck=$F(NumFieldInput);
var error_info='';
//下面的定义电话号码必须为数字，且长度介于5至20位
var regex=/^\d{5,20}$/;
if (needCheck.length===0){
error_info=$F(NumFieldInput+'_error');
$(NumFieldInput+'_errorInfo').innerHTML=error_info;
return false;
}
else if (regex.test(needCheck)===false){
error_info=$F(NumFieldInput+'_error2');
$(NumFieldInput+'_errorInfo').innerHTML=error_info;
return false;
}
else{
$(NumFieldInput+'_errorInfo').innerHTML='';
//checkFormOfCustomForm(Name);
return true;
}
}

function checkQq(NumFieldInput){
var needCheck=$F(NumFieldInput);
var error_info='';
//下面的定义号码必须为数字，且长度介于3至20位
var regex=/^\d{4,20}$/;
if (needCheck.length===0){
$(NumFieldInput+'_errorInfo').innerHTML='';
return true;
}
else if (regex.test(needCheck)===false){
error_info=$F(NumFieldInput+'_error');
$(NumFieldInput+'_errorInfo').innerHTML=error_info;
return false;
}
else{
$(NumFieldInput+'_errorInfo').innerHTML='';
//checkFormOfCustomForm(Name);
return true;
}
}


//这个方法检查EMAIL与MSN
function checkEmail(email){
//下面定义email的正则表达式
var regex=/^(([\-\w]+)\.?)+@(([\-\w]+)\.?)+\.[a-zA-Z]{2,4}$/; 
//取输入被测试对象的值
var needCheck=$F(email);
var error_info='';
//如果取值为空，如果是MSN返回真，
if(needCheck.length===0){
if(email==='msn'){
$(email+'_errorInfo').innerHTML='';
return true;
}
else //如果不是msn，是EMAIL，显示必填，返回假
{
error_info=$F(email+'_error');
$(email+'_errorInfo').innerHTML=error_info;
return false;
}
}//为空的判断结束
//如果有值，测试是否为EMAIL
else if (regex.test(needCheck)===false){
error_info=$F(email+'_error2');
$(email+'_errorInfo').innerHTML=error_info;
return false;
}
else{
$(email+'_errorInfo').innerHTML='';
return true;
}
}


//这个方法是检查订单信息里的表项，如果全部为空，报提示信息。
function checkOrederInfoForm(){
var NotNull=false;
var oInputs= new Array("dtp","facilitiesRent","writtenTranslation","interpreter","localization","otherService","orderDescription" );
for(var i=0 ; i< oInputs.length-1 ; i++){
var tmp = oInputs[i];
if($(tmp).status==true){
NotNull=true;
}
}
if($F('orderDescription').length>0){
NotNull=true;
}
if(NotNull===false){
error_info=$F('OrederInfo_error');
$('OrederInfo_errorInfo').innerHTML=error_info;
return false;
}
else{
$('OrederInfo_errorInfo').innerHTML='';
return true;
}}


//国家地点选择
function redirect(siteLange) { 
var UrlStr='addCustom.do?'+'siteLanguage='+siteLange;
location = UrlStr; }

//功能函数 end======================================================================================

//用户验证码，相关

function fRefreshRandomNoClick(){
	
		var oImg = $('randomNoImg');
		if ( !oImg ){
			oImg = document.createElement('IMG');
			oImg.setAttribute('alt','将图中的文字填到左边输入框中');
			oImg.setAttribute('width','106');
			oImg.setAttribute('height','28');
			oImg.setAttribute('id','randomNoImg');
			var oSpan = document.createElement('SPAN');
			$('checkcode').appendChild(oImg);
			$('checkcode').appendChild(oSpan);
		}
		dt=new Date();
		$('randomNoImg').src ='getImg.do?t='+dt+Math.random();
	    
}




//测试公司名称：
function testName(theId){
//var temp=$F(theId);//取Id为theId 标签的值，放入temp中进行处理。
if( $(theId).value.length === 0 && theId =='companyName'){
$('companyErrors').innerHTML='<fmt:message key="companyName" />';
}
}