if(!String.trim)
{
 String.prototype.trim = function ()
 { 
 return this.replace(/(^\s*)|(\s*$)/g,""); 
 }
}

if(!String.equal)
{
 String.prototype.equal = function(str)
 {
 var x = this.trim().toUpperCase();
 var y = str.trim().toUpperCase();
 return x == y; 
 }
}

var VAL_CSS_LINE = "FormValLine";
var VAL_CSS_TITLE = "FormValTitle";
var VAL_CSS_INPUT = "FormValInput";
var VAL_CSS_NOTE = "FormValNote";
var VAL_CSS_NOTE_FOCUS = "FormValNoteFocus";
var VAL_CSS_NOTE_ERROR = "FormValNoteError";
var VAL_CSS_NOTE_RIGHT = "FormValNoteRight";
var VAL_CSS_NOTE_ANSY_WAIT = "FormValNoteAnsyWait";
var VAL_CSS_NOTE_ANSY_ERROR = "FormValNoteAnsyError";

var VAL_PRE_LINE = "ValPreLine_";
var VAL_PRE_TITLE = "ValPreTitle_";
var VAL_PRE_INPUT = "ValPreInput_";
var VAL_PRE_NOTE = "ValPreNote_";
var VAL_PRE_TITLE_VALID = "ValPreTitleValid_";
var VAL_PRE_NOTE_ERROR = "ValPreNoteError_";
var VAL_PRE_NOTE_RIGHT = "ValPreNoteRight_";
var VAL_PRE_NOTE_ANSY_WAIT = "ValPreNoteAnsyWait_";
var VAL_PRE_NOTE_ANSY_ERROR = "ValPreNoteAnsyError_";

var LineCount = 0;
var ValTags = new Array( VAL_PRE_LINE,VAL_PRE_TITLE,VAL_PRE_INPUT,VAL_PRE_NOTE,VAL_PRE_TITLE_VALID,
 VAL_PRE_NOTE_ERROR,VAL_PRE_NOTE_RIGHT,VAL_PRE_NOTE_ANSY_WAIT,VAL_PRE_NOTE_ANSY_ERROR );
var ValLastValue = new Array(); 
 

//得到字节长度，区分单双字符 
function GetByteLength(str)
{ 
 var length = 0;
 var tmp = str.trim();
 for(var i=0;i<str.length;i++)
 {
 length++;
 if(tmp.charCodeAt(i) > 128)
 {
 length++;
 } 
 }
 return length;
} 


function GetEvent(evnt)
{
 return evnt ? evnt : window.event; 
}


function ValGetIndex(evnt)
{
 var source = evnt.srcElement ? evnt.srcElement : evnt.currentTarget;
 
 if(!source.tagName.equal("div"))
 {
 if(source.valid)
 return source.valid;
 return -1;
 }
 
 if(!source || !source.id) return -1;
 
 for(i=0;i<ValTags.length;i++)
 {
 if(source.id.length < ValTags[i].length) 
 continue;
 if(source.id.substr(0,ValTags[i].length) == ValTags[i])
 {
 return source.id.substr(ValTags[i].length);
 }
 }
 return -1; 
}


function ValSetValid(index,valid)
{
 var el = document.getElementById(VAL_PRE_TITLE_VALID + index); 
 if(el)
 {
 if(valid)
 {
 el.style.display = "";
 } 
 else
 {
 el.style.display = "none";
 }
 } 
}

//说明
function ValTitle(el,mustInput)
{ 
 function SetValid(valid)
 {
 if(valid)
 {
 this.objValid.style.display = "";
 } 
 else
 {
 this.objValid.style.display = "none";
 }
 }
 
 el.id = VAL_PRE_TITLE + LineCount; 
 
 var objText = el.childNodes[0];
 
 el.removeChild(objText);
 
 var objvalid = document.createElement("IMG");
 objvalid.src = "http://files.mainone.com/images/valid.gif";
 objvalid.align = "absmiddle"; 
 objvalid.style.marginRight = "5px"; 
 objvalid.id = VAL_PRE_TITLE_VALID + LineCount; 
 objvalid.style.display = "none";
 el.appendChild(objvalid); 
 
 el.appendChild(objText);
 
 var objmust = document.createElement("SPAN"); 
 objmust.innerHTML = "*"; 
 objmust.style.color = "red";
 objmust.style.visibility = mustInput ? "visible" : "hidden"; 
 el.appendChild(objmust); 
}


//输入
function ValInput(el)
{ 
 function OnFocus(evnt)
 { 
 var MyEvent = GetEvent(evnt); 
 var index = ValGetIndex(MyEvent); 
 ValOnFocus(index);
 }
 function OnBlur(evnt)
 {
 var MyEvent = GetEvent(evnt);
 var index = ValGetIndex(MyEvent);
 ValOnBlur(index); 
 } 
 
 el.id = VAL_PRE_INPUT + LineCount; 
 
 var inputs = el.getElementsByTagName("input"); 
 for(i=0;i<inputs.length;i++)
 {
 inputs[i].onfocus = OnFocus; 
 inputs[i].onblur = OnBlur; 
 inputs[i].valid = LineCount;
 } 
 
 var selects = el.getElementsByTagName("select");
 for(i=0;i<selects.length;i++)
 {
 selects[i].onfocus = OnFocus; 
 selects[i].onblur = OnBlur; 
 selects[i].valid = LineCount;
 }
 
 var areas = el.getElementsByTagName("textarea"); 
 for(i=0;i<areas.length;i++)
 {
 areas[i].onfocus = OnFocus; 
 areas[i].onblur = OnBlur; 
 areas[i].valid = LineCount;
 } 
} 

function ValOnFocus(index)
{
 var note = document.getElementById( VAL_PRE_NOTE + index);
 if(note)
 {
 note.className = VAL_CSS_NOTE_FOCUS; 
 note.style.display = "";
 } 
 
 var elNoteError = document.getElementById(VAL_PRE_NOTE_ERROR + index); 
 var elNoteRight = document.getElementById(VAL_PRE_NOTE_RIGHT + index); 
 
 var elNoteAnsyError = document.getElementById(VAL_PRE_NOTE_ANSY_ERROR + index); 
 var elNoteAnsyWait = document.getElementById(VAL_PRE_NOTE_ANSY_WAIT + index); 
 
 if(elNoteAnsyError)
 elNoteAnsyError.style.display = "none";
 if(elNoteAnsyWait)
 elNoteAnsyWait.style.display = "none"; 
 if(elNoteRight)
 elNoteRight.style.display = "none";
 if(elNoteError)
 elNoteError.style.display = "none";
}


function ValOnBlur(index)
{ 
 var note = document.getElementById( VAL_PRE_NOTE + index);
 if(note)
 note.className = VAL_CSS_NOTE; 
 ValValidation(index);

} 


function ValValidation(index,isSubmit)
{
 var elInput = document.getElementById(VAL_PRE_INPUT + index); 
 if(!elInput)
 return;
 
 var isRight = false;
 
 var isMustInput = ValGetMustInput(index);

 var isInput = false;
 var isRight = false; 
 var isOtherError = false;
 
 var thisValue = ValGetValue(index); 
 var thisDefaultValue = ValGetDefaultValue(index);
 
 if(thisValue!="" && thisValue == ValLastValue[index])
 return; 
 
 if(thisValue.trim() == "")
 isInput = false;
 else
 if(thisDefaultValue == "") 
 isInput = thisValue != "";
 else
 isInput = !thisValue.equal(thisDefaultValue);

 var elNote = document.getElementById(VAL_PRE_NOTE + index); 
 var elNoteError = document.getElementById(VAL_PRE_NOTE_ERROR + index); 
 var elNoteRight = document.getElementById(VAL_PRE_NOTE_RIGHT + index); 
 
 var elNoteAnsyError = document.getElementById(VAL_PRE_NOTE_ANSY_ERROR + index); 
 var elNoteAnsyWait = document.getElementById(VAL_PRE_NOTE_ANSY_WAIT + index); 
 	   
 if(isSubmit)
 {
     if(isMustInput && !isInput) 
      {
          if(elNoteAnsyError)
          elNoteAnsyError.style.display = "none";
          if(elNoteAnsyWait)
          elNoteAnsyWait.style.display = "none";
          if(elNote)
          elNote.style.display = "none";
          if(elNoteRight)
          elNoteRight.style.display = "none";
           if(elNoteError)
          elNoteError.style.display = "";
          return false;
        }
     if(elNoteError && elNoteError.style.display == "") 
     return false;
 
     if(elNoteAnsyError && elNoteAnsyError.style.display == "") 
     return false; 
 
     return true; 
 }
 
 if(elNote)
 elNote.style.display = "none";
 if(elNoteError)
 elNoteError.style.display = "none";
 if(elNoteRight)
 elNoteRight.style.display = "none";
 
 if(isInput) 
 {
 isRight = true;
 
 if(isRight)
 {
 var custom = ValGetCustom(index);
 if(custom!="")
 {
 if(! eval(custom+"()"))
 isRight = false;
 } 
 } 
 if(isRight)
 {
   var reg = ValGetRegularExpress(index);
   if(reg != "")
   {
 //if(!thisValue.match(reg))
 // isRight = false; 
      var rx = new RegExp(reg);
      var matches = rx.exec(thisValue); 
      if(matches==null || matches[0] != thisValue) 
      isRight = false; 
     }
 } 
    if(isRight)
    {
      var compare = ValGetCompare(index);
      if(compare)
      {
         if(compare.type.equal("equal"))
         {
             var otherValue = ValGetValue(index + compare.to);
             if(thisValue != otherValue)
             isRight = false;
          } 
       }
     }
 	   
   if(isRight)
   {
      var ansy = ValGetAnsy(index)
      if(ansy!="")
      { 
           if(elNoteAnsyError)
           elNoteAnsyError.style.display = "none"; 
 
            if(elNoteAnsyWait)
            elNoteAnsyWait.style.display = "";
 
           var args = {"index":index};
 
            eval(ansy + "(args);");////////////////////////////////////////////////////////////////////////用户名重复验证
            return;
        }
   }
 
 } 

 if(!isInput)
 {
 if(elNote)
 elNote.style.display = "";
 ValSetValid(index,false);

 return isMustInput ? false : true; 
 } 
 if(isRight)
 {
 if(elNoteRight)
 elNoteRight.style.display = "";
 ValSetValid(index,true);
 return true;
 } 
 else
 {
 if(elNoteError)
 elNoteError.style.display = "";
 ValSetValid(index,false);
 return false;
 }
}


function ValOnAnsyChange(index,valid)
{
 var elNote = document.getElementById(VAL_PRE_NOTE + index); 
 var elNoteError = document.getElementById(VAL_PRE_NOTE_ERROR + index); 
 var elNoteRight = document.getElementById(VAL_PRE_NOTE_RIGHT + index); 
 var elNoteAnsyError = document.getElementById(VAL_PRE_NOTE_ANSY_ERROR + index); 
 var elNoteAnsyWait = document.getElementById(VAL_PRE_NOTE_ANSY_WAIT + index); 
 
 
 if(elNoteAnsyWait)
 elNoteAnsyWait.style.display = "none";
 if(elNote)
 elNote.style.display = "none";
 if(elNoteError)
 elNoteError.style.display = "none";
 if(elNoteRight)
 elNoteRight.style.display = "none";
 if(elNoteAnsyError)
 elNoteAnsyError.style.display = "none";
 
 if(valid)
 {
 if(elNoteRight)
 elNoteRight.style.display = "";
 }
 else
 { 
 if(elNoteAnsyError)
 {
 elNoteAnsyError.style.display = ""; 
 }
 else
 if(elNoteError)
 elNoteError.style.display = ""; 
 }
 ValSetValid(index,valid);
}
function ValGetValue(index)
{ 
 var elInput = document.getElementById(VAL_PRE_INPUT + index); 
 if(!elInput)
 return "";
 
 var ret = "";
 
 var inputs = elInput.getElementsByTagName("input"); 
 var selects = elInput.getElementsByTagName("select");
 var areas = elInput.getElementsByTagName("textarea");
 
 for(i=0;i<inputs.length;i++) 
 {
 if(inputs[i].style.display == "none")
 continue; 
 if(inputs[i].type.equal("text") || inputs[i].type.equal("password"))
 {
 if(ret!="")
 ret += "|";
 ret += inputs[i].value;
 }
 if(inputs[i].type.equal("radio") && inputs[i].checked)
 {
 if(ret!="")
 ret += "|";
 ret += inputs[i].value;
 }
 if(inputs[i].type.equal("check") && inputs[i].checked)
 {
 if(ret!="")
 ret += "|";
 ret += inputs[i].value;
 }
 }
 for(i=0;i<selects.length;i++)
 {
 if(selects[i].style.display == "none")
 continue; 
 if(selects[i].value.trim()!="") 
 {
 if(ret!="")
 ret += "|";
 ret += selects[i].value;
 }
 } 
 for(i=0;i<areas.length;i++)
 { 
 if(areas[i].style.display == "none")
 continue; 
 if(ret!="")
 ret += "|";
 ret += areas[i].value;
 }
 return ret;
}
function ValGetMustInput(index)
{
 var el = document.getElementById(VAL_PRE_LINE + index);
 if(el)
 return el.getAttributeNode("must") && el.getAttributeNode("must").value.equal("true");
 return false;
}
function ValGetRegularExpress(index)
{
 var el = document.getElementById(VAL_PRE_LINE + index);
 if(el && el.getAttributeNode("regular"))
 return el.getAttributeNode("regular").value.trim();
 return "";
}
function ValGetCompare(index)
{
 var el = document.getElementById(VAL_PRE_LINE + index);
 if(!el)
 return null;
 
 var type,to; 
 if(el.getAttributeNode("CompareType") && el.getAttributeNode("CompareType").value.trim() !="")
 type = el.getAttributeNode("CompareType").value.trim(); 
 
 if(el.getAttributeNode("CompareIndex") && el.getAttributeNode("CompareIndex").value.trim() !="")
 {
 to = el.getAttributeNode("CompareIndex").value.trim();
 to = parseInt(to,10);
 if(isNaN(to))
 to = null;
 }
 if(type && to)
 return {"type":type,"to":to}; 
 return null;
}
function ValGetAnsy(index)
{
    var el = document.getElementById(VAL_PRE_LINE + index);
    if(el && el.getAttributeNode("ansy"))
    return el.getAttributeNode("ansy").value.trim();
    return ""; 
}
  function ValGetCustom(index)
  {
     var el = document.getElementById(VAL_PRE_LINE + index);
     if(el && el.getAttributeNode("custom"))
     return el.getAttributeNode("custom").value.trim();
     return ""; 
  }
  
  function ValGetDefaultValue(index)
  {
    var el = document.getElementById(VAL_PRE_LINE + index);
    if(el && el.getAttributeNode("default"))
    return el.getAttributeNode("default").value.trim();
    return ""; 
   }
//提示
function ValNote(el)
{
 el.id = VAL_PRE_NOTE + LineCount; 
} 
function ValNoteError(el)
{
 el.id = VAL_PRE_NOTE_ERROR + LineCount; 
 el.style.display = "none";
}
function ValNoteRight(el)
{
 el.id = VAL_PRE_NOTE_RIGHT + LineCount; 
 el.style.display = "none";
}
function ValNoteAnsyWait(el)
{
 el.id = VAL_PRE_NOTE_ANSY_WAIT + LineCount; 
 el.style.display = "none";
}
function ValNoteAnsyError(el)
{
 el.id = VAL_PRE_NOTE_ANSY_ERROR + LineCount; 
 el.style.display = "none";
}
//一行
function ValLine(el)
{ 
 el.id = VAL_PRE_LINE + LineCount;
// el.className = VAL_CSS_LINE;
 
 var mustInput = el.getAttributeNode("must") && el.getAttributeNode("must").value.equal("true");
 
 var divs = el.getElementsByTagName("DIV"); 
 var ShowErr;
 
 for(var i=0;i<divs.length;i++)
 { 
	 if(divs[i].className.equal(VAL_CSS_TITLE))
	 {
	     ValTitle(divs[i],mustInput); 
	 }
	 
	 if(divs[i].className.equal(VAL_CSS_INPUT))
	 {
	    ValInput(divs[i]); 
	 }
	 
	 if(divs[i].className.equal(VAL_CSS_NOTE))
	 {
		 ValNote(divs[i]); 
	 }
	 
	 if(divs[i].className.equal(VAL_CSS_NOTE_RIGHT))
	 {
			 ValNoteRight(divs[i]); 
	 }
 if(divs[i].className.equal(VAL_CSS_NOTE_ERROR))
 {
 if(divs[i].getAttributeNode("showerr") && divs[i].getAttributeNode("showerr").value.equal("true")) 
 ShowErr = divs[i];
 
 ValNoteError(divs[i]); 
 } 
 if(divs[i].className.equal(VAL_CSS_NOTE_ANSY_WAIT))
 {
 ValNoteAnsyWait(divs[i]); 
 }
 if(divs[i].className.equal(VAL_CSS_NOTE_ANSY_ERROR))
 {
 if(divs[i].getAttributeNode("showerr") && divs[i].getAttributeNode("showerr").value.equal("true")) 
 ShowErr = divs[i];
 
 ValNoteAnsyError(divs[i]); 
 }
 } 
 if(ShowErr)
 {
 var elNote = document.getElementById(VAL_PRE_NOTE + LineCount); 
 var elNoteError = document.getElementById(VAL_PRE_NOTE_ERROR + LineCount); 
 var elNoteRight = document.getElementById(VAL_PRE_NOTE_RIGHT + LineCount); 
 var elNoteAnsyError = document.getElementById(VAL_PRE_NOTE_ANSY_ERROR + LineCount); 
 var elNoteAnsyWait = document.getElementById(VAL_PRE_NOTE_ANSY_WAIT + LineCount); 
 
 
 if(elNoteAnsyWait)
     elNoteAnsyWait.style.display = "none";
 if(elNote)
     elNote.style.display = "none";
 if(elNoteError)
     elNoteError.style.display = "none";
 if(elNoteRight)
     elNoteRight.style.display = "none";
 if(elNoteAnsyError)
     elNoteAnsyError.style.display = "none";
     ShowErr.style.display = ""; 
 }
}
 
function ValForm(frm)    /////////////////////////////////////////////////////////////////////////////////
{ 
 var el; 

 function OnSubmit(evnt)
 { 
 var isRight = true;
 var ErrMsg = "";
 var temp = "";
 for(i=1;i<=LineCount;i++)
  {
   if(!ValValidation(i,true))
   {
      isRight = false;
      temp = ValGetErrorName(i);
      if(temp!="")
      ErrMsg += "\r\n\u2022 " + temp;
    }
   }

 var myEvent = evnt ? evnt : window.event;
 
if(isRight){
	if (frm=="aspnetForm"){
send('online_consultation_submit.aspx?name='+ escape(document.getElementById("nam").value) +'&qq='+ document.getElementById("qq").value +'&email='+ document.getElementById("emai").value +'&phone='+ document.getElementById("tel").value +'&content='+ escape(document.getElementById("textarea").value) +'&t='+ Math.random(),'loading');
}
    if (frm=="aspnet"){
send('online_sign_up_submit.aspx?name='+ escape(document.getElementById("nam").value) + '&qq='+ document.getElementById("qq").value +'&email='+ document.getElementById("emai").value +'&phone='+ document.getElementById("tel").value +'&content='+ escape(document.getElementById("textarea").value) +'&t='+ Math.random(),'loading');}
    if (frm=="aspnetq"){
send('come_down_on_courses_submit.aspx?name='+ escape(document.getElementById("nam").value) + '&qq='+ document.getElementById("qq").value +'&email='+ document.getElementById("emai").value +'&phone='+ document.getElementById("tel").value +'&content='+ escape(document.getElementById("textarea").value) +'&t='+ Math.random(),'loading');}
    if (frm=="aspnetf"){
send('come_down_on_fees_submit.aspx?name='+ escape(document.getElementById("nam").value) + '&qq='+ document.getElementById("qq").value +'&email='+ document.getElementById("emai").value +'&phone='+ document.getElementById("tel").value +'&textFee='+document.getElementById("textFees").value +'&content=' + escape(document.getElementById("textarea").value) +'&t='+ Math.random(),'loading');}
alert("添加信息成功，请继续关注...");

 }

 if(!isRight)
 {
     if(myEvent.preventDefault)
     { 
        
       myEvent.preventDefault(); 
     }
     else
     {
       myEvent.returnValue = 0;
     } 
     

 if(ErrMsg!="")
        {
          ErrMsg = "以下信息填写有误或未填写：\r\n" + ErrMsg + "\r\n\r\n请修改相应信息后再次提交注册信息。";
          alert(ErrMsg);
        }
 } 
 } 
 for(var i=0;i<document.forms.length;i++)
 {
	  
 if(document.forms[i].id.equal(frm))
 {
 this.el = document.forms[i];
 break;
 }
 } 
 if(!this.el)
 return; 
 

 
 var divs = this.el.getElementsByTagName("DIV"); 
 
 for(var i=0;i<divs.length;i++)
 { 
	 if(divs[i].className.equal(VAL_CSS_LINE))
	 {
	 LineCount ++; 
	 ValLastValue[LineCount] = ""; 
	 ValLine(divs[i]);   
	 }
 } 
 
  this.el.msg_submit.onclick = OnSubmit;
 
}

var vallastclsid = null;
if(!window.XMLHttpRequest) 
{
 function getXmlHttp(clsid) 
 {
 var xmlHttp = null;
 try 
 {
 xmlHttp = new ActiveXObject(clsid);
 vallastclsid = clsid;
 return xmlHttp;
 } catch(ex) {}
 }
 
 window.XMLHttpRequest = function() 
 {
 if(vallastclsid != null) {
 return getXmlHttp(vallastclsid);
 }
 
 var xmlHttp = null;
 var clsids = ["Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.5.0","Msxml2.XMLHTTP.4.0","Msxml2.XMLHTTP.3.0","Msxml2.XMLHTTP.2.6","Microsoft.XMLHTTP.1.0","Microsoft.XMLHTTP.1","Microsoft.XMLHTTP"];

 for(var i=0; i<clsids.length && xmlHttp == null; i++) {
 xmlHttp = getXmlHttp(clsids[i]);
 }
 
 if(xmlHttp == null) {
 return null;
 }

 return xmlHttp;
 }
}



function ValGetErrorName(index)
{
 var el = document.getElementById(VAL_PRE_LINE + index);
 if(el && el.getAttributeNode("errname"))
 return el.getAttributeNode("errname").value.trim();
 return "";
}