var req=null;
var READY_STATE_UNINITIALIZED=0;
var READY_STATE_LOADING=1;
var READY_STATE_LOADED=2;
var READY_STATE_INTERACTIVE=3;
var READY_STATE_COMPLETE=4;
function sendRequest ( url, params, HttpMethod ) {		
	if ( !HttpMethod ){
		HttpMethod="GET";
	}		
	req=initXMLHTTPRequest();
	if ( req ) {
		 var btype=getOs();
		req.onreadystatechange= (btype!="Firefox")?(onReadyState):(onReadyState());
		
		req.open(HttpMethod, url, false );
		req.setRequestHeader ( "Content-Type", "application/x-www-form-urlencoded");
		req.send (params);
		req.onreadystatechange= (btype!="Firefox")?(onReadyState):(onReadyState());
	}
}
function initXMLHTTPRequest(){
	var xRequest=null;
	if (window.XMLHttpRequest) {
		xRequest=new XMLHttpRequest();
	} else if ( window.ActiveXObject ){
		xRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return xRequest;
}
function onReadyState() {
	
	var ready=req.readyState;
	var jsonObject=null;
	
	if ( ready == READY_STATE_COMPLETE ){
		  jsonObject=eval( "("+ req.responseText +")" );
		  if(jsonObject.isError==true){
			  alert('\u4F1A\u8BDD\u5931\u6548\uFF0C\u8BF7\u5237\u65B0\u9875\u9762\u3002');
			  getCookie();
		  }
		  callback ( jsonObject );
	}
}
function removeAllChildren( node ){
	var childCount = node.childNodes.length;
	for ( var count = 1; count <= childCount; count++) {
		node.removeChild ( node.childNodes[0] );
	}
}
function replaceText(objId, text){
	var objObj = document.getElementById(objId);
	if(objObj!=null){
		removeAllChildren ( objObj );
		objObj.appendChild(document.createTextNode(text));
	}else{
		alert(objId + 'not exist');
	}
}
function replaceImg(objId, src, alt){
	var objObj = document.getElementById(objId);
	if(objObj!=null){
		removeAllChildren ( objObj );
		var imgObj = document.createElement("img");
		imgObj.setAttribute("alt",alt);
		imgObj.setAttribute("src",src);
		objObj.appendChild(imgObj);
	}else{
		alert(objId + 'not exist');
	}
}
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

function isCmccNo(code){
  var re=/^(134|135|136|137|138|139|147|150|151|152|157|158|159|187|188)(\d){8}$/; 
  if(!re.test(code)){
    return false;
  } 
  return true;
}

function isInteger(string ,sign) 
{  
	var integer; 
	if ((sign!=null) && (sign!='-') && (sign!='+')) { 
		alert('IsInter(string,sign) param error: sign must be null , "-" or "+"'); 
		return false; 
	} 
	integer = parseInt(string); 
	if (isNaN(integer)){ 
		return false; 
	} else if (integer.toString().length==string.length) {  
		if ((sign==null) || (sign=='-' && integer<0) || (sign=='+' && integer>0)) { 
			return true; 
		}else {
			return false;  
		} 
	}else {
		return false; 
	}
} 
function getOs()
{
    var OsObject = "";
   if(navigator.userAgent.indexOf("MSIE")>0) {
        return "MSIE";
   }
   if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){
        return "Firefox";
   }
   if(isSafari=navigator.userAgent.indexOf("Safari")>0) {
        return "Safari";
   } 
   if(isCamino=navigator.userAgent.indexOf("Camino")>0){
        return "Camino";
   }
   if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){
        return "Gecko";
   }
} 
function getCookie(){
	var strCookie = document.cookie;
	var arrCookie = strCookie.split("; ");
		for(var i=0;i<arrCookie.length;i++){
			if(arrCookie[i].indexOf('homeQryStr')!=-1){
			var att=arrCookie[i].substring(11);
			window.location.href = att;
			}
		}
	}

function checkText(el, ruleName, fshow) {
    var err = '';
    var alertMsg =getDefaultMessage(el, fshow, ruleName, '')
    el.value = trim(el.value);
	
    if (ruleName=='required') {
        if ( el.value==null || el.value=='' ) {
            err = alertMsg;
        }
    } else if (ruleName=='equal') {
        err = yav.checkEqual(el, myRule);
    } else if (ruleName=='notequal') {
        err = yav.checkNotEqual(el, myRule);
    } else if (ruleName=='numeric') {
        reg = new RegExp("^[0-9]*$");
        if ( !reg.test(el.value) ) {
            yav.highlight(el, ajax_config.inputclasserror);
            err = alertMsg;
        }
    } else if (ruleName=='alphabetic') {
        reg = new RegExp(ajax_config.alphabetic_regex);
        if ( !reg.test(el.value) ) {
            yav.highlight(el, ajax_config.inputclasserror);
            err = alertMsg;
        }
    } else if (ruleName=='alphanumeric') {
        reg = new RegExp(ajax_config.alphanumeric_regex);
        if ( !reg.test(el.value) ) {
            yav.highlight(el, ajax_config.inputclasserror);
            err = alertMsg;
        }
    } else if (ruleName=='alnumhyphen') {
        reg = new RegExp(ajax_config.alnumhyphen_regex);
        if ( !reg.test(el.value) ) {
            yav.highlight(el, ajax_config.inputclasserror);
           err = alertMsg;
        }
    } else if (ruleName=='alnumhyphenat') {
        reg = new RegExp(ajax_config.alnumhyphenat_regex);
        if ( !reg.test(el.value) ) {
            yav.highlight(el, ajax_config.inputclasserror);
            err = alertMsg;
        }
    } else if (ruleName=='alphaspace') {
        reg = new RegExp(ajax_config.alphaspace_regex);
        if ( !reg.test(el.value) ) {
            yav.highlight(el, ajax_config.inputclasserror);
            err = alertMsg;
        }
    } else if (ruleName=='email') {
    	if(el.value!=null && el.value!=''){
	        reg = new RegExp(ajax_config.email_regex);
	        if ( !reg.test(el.value) ) {
	           err = alertMsg;
	        }
        }
    }else if (ruleName=='mobile') {
    	if(el.value!=null && el.value!=''){
	        reg = new RegExp(ajax_config.mobile_regex);
	        if ( !reg.test(el.value) ) {
	            err = alertMsg;
	        }
        }
    } else if (ruleName=='zipcode') {
    	if(el.value!=null && el.value!=''){
	        reg = new RegExp(ajax_config.zipcode_regex);
	        if ( !reg.test(el.value) ) {
	            err = alertMsg;
	        }
        }
    } else if (ruleName=='phone') {
    	if(el.value!=null && el.value!=''){
	        reg = new RegExp(ajax_config.phone_regex);
	        if ( !reg.test(el.value) ) {
	            err = alertMsg;
	        }
        }
    }else if (ruleName=='password') {
    	if(el.value!=null && el.value!=''){
	        reg = new RegExp(ajax_config.password_regex);
	        if ( !reg.test(el.value) ) {
	            err = alertMsg;
	        }
        }
    } else if (ruleName=='maxlength') {
        if ( isNaN(myRule.comparisonValue) ) {
            yav.debug('DEBUG: comparisonValue for rule ' + myRule.ruleName + ' not a number');
        }else if ( el.value.length > myRule.comparisonValue ) {
            yav.highlight(el, ajax_config.inputclasserror);
            err = alertMsg;
        }
    } else if (ruleName=='minlength') {
        if ( isNaN(myRule.comparisonValue) ) {
            yav.debug('DEBUG: comparisonValue for rule ' + myRule.ruleName + ' not a number');
        } else if ( el.value.length < myRule.comparisonValue ) {
            yav.highlight(el, ajax_config.inputclasserror);
            err = alertMsg;
        }
    } else if (ruleName=='numrange') {
        reg = new RegExp("^[-+]{0,1}[0-9]*[.]{0,1}[0-9]*$");
        if ( !reg.test(yav.unformatNumber(el.value)) ) {
            yav.highlight(el, ajax_config.inputclasserror);
            err = alertMsg;
        } else {
            regRange = new RegExp("^[0-9]+-[0-9]+$"); 
            if ( !regRange.test(myRule.comparisonValue) ) {
                yav.debug('DEBUG: comparisonValue for rule ' + myRule.ruleName + ' not in format number1-number2');
            } else {
                rangeVal = myRule.comparisonValue.split('-');
                if (eval(yav.unformatNumber(el.value))<eval(rangeVal[0]) || eval(yav.unformatNumber(el.value))>eval(rangeVal[1])) {
                    yav.highlight(el, ajax_config.inputclasserror); 
                   err = alertMsg;
                }
            }
        }
    } else if (ruleName=='regexp') {
        reg = new RegExp(myRule.comparisonValue);
        if ( !reg.test(el.value) ) {
            yav.highlight(el, ajax_config.inputclasserror);
            err = alertMsg;
        }
    } else if (ruleName=='integer') {
        err = yav.checkInteger(el, myRule);
    } else if (ruleName=='double') {
        err = yav.checkDouble(el, myRule);
    } else if (ruleName=='date') {
        err = yav.checkDate(el, myRule);
    } else if (ruleName=='date_lt') {
        err = yav.checkDateLessThan(el, myRule, false);
    } else if (ruleName=='date_le') {
        err = yav.checkDateLessThan(el, myRule, true);
    } else {
        alert('DEBUG: rule ' + ruleName + ' not supported for ' + el.type);
    }
    return err;
}

function checkSelOne(el, ruleName, fshow) {
	var err = '';
    var alertMsg =getDefaultMessage(el, fshow, ruleName, '')
    if (ruleName=='required') {
        var found = false;
        var inx = el.selectedIndex;
        if(inx>=0 && el.options[inx].value) {
            found = true;
        }
        if ( !found ) {
            return alertMsg;
        }
    }  else {
        return 'DEBUG: rule ' + ruleName + ' not supported for ' + el.type;
    }
}

function checkRadio(el, ruleName, fshow) {
	var alertMsg =getDefaultMessage(el, fshow, ruleName, '')
    if (ruleName=='required') {
        var radios = el;
	    var found=false;
	    if (isNaN(radios.length) && radios.checked) {
	    	found=true;
	    } else {
		    for(var j=0; j < radios.length; j++) {
		        if(radios[j].checked) {
		            found=true;
		            break;
		        }
		    }
		}
        if( !found ) {
        	
            return alertMsg;
        }
    }  else {
        return 'DEBUG: rule ' + ruleName + ' not supported for radio';
    }
    return '';
}

function checkCheckbox(el, ruleName, fshow) {	
    if (ruleName=='required') {
    	var alertMsg =getDefaultMessage(el, fshow, ruleName, '')
        if ( !el.checked ) {
            return alertMsg;
        }
    } if (ruleName=='requiredCheck') {
        if ( !el.checked ) {
            return fshow;
        }
    }  else {
        return 'DEBUG: rule ' + ruleName + ' not supported for ' + el.type;
    }
}

function checkBeforeSub(formName, rules, errortip){
	var formObj = document.forms[formName];
	for(var i=0; i<rules.length; i=i+1){
		var r = rules[i];			
		var tmp = r.split('|');
		var err = '';
		if(tmp.length==2){
	        var fs = tmp[0];
	        var ruleName = tmp[1];
	        var tm2 = fs.split(':');
	        var fieldName=tm2[0];
	        var fshow=tm2[1];
	        var el = getField(formObj,fieldName);
	        if (el == null) {
	            err = 'DEBUG: could not find element ' + fieldName;
			
	        }else{
		 if(el.type) {	        	
	             if(el.type=='hidden'||el.type=='text'||el.type=='password'||el.type=='textarea') {
					err = checkText(el, ruleName, fshow);
	             } else if(el.type=='checkbox') {
	                err = checkCheckbox(el, ruleName, fshow);
	             } else if(el.type=='select-one') {
	                 err = checkSelOne(el, ruleName, fshow);
	             } else if(el.type=='select-multiple') {
	                 err = checkSelMul(el, ruleName, fshow);
	             } else if(el.type=='radio') {
	                 err = checkRadio(el, ruleName, fshow);
	             } else {
	                 err = 'DEBUG: type '+ el.type +' not supported';
	             }
	         } else {
	             err = checkRadio(el, ruleName, fshow);
	         }
		}	         
         }
         if(tmp.length==3){
         	var fs1 = tmp[0];
	        var ruleName = tmp[1];
	        var fs2 = tmp[2];
	        var fs1t = fs1.split(":");
	        var fs2t = fs2.split(":");
	        if(ruleName == 'same'){
	        	var el1 = getField(formObj,fs1t[0]);
	        	var el2 = getField(formObj,fs2t[0]);
	        	if(trim(el1.value)!==trim(el2.value)){
	        		err =  ajax_config.EQUAL_MSG.replace('{1}', fs2t[1]).replace('{2}', fs1t[1]);
	        	}
	        }else {
	                 err = 'DEBUG: ruleName '+ ruleName +' not supported';
	        }
         }
         if ( err!=null && err!='' ) {
	         	replaceText(errortip,err);
	         	document.getElementById(errortip).style.display='block';
	         	return false;
	      }
	}
	return true;
}

function checkOnSubmit(formName, rules, errortip) {
	if(checkBeforeSub(formName, rules, errortip)){
   		 document.forms[formName].submit();
   	 }
}
function getField(formObj, fieldName){
	var retval = null;
	if (formObj.elements[fieldName]){
		retval = formObj.elements[fieldName];
	}else {
		retval = document.getElementById(fieldName);
	}
	return retval;
}

function getDefaultMessage(el, nameDisplayed, ruleName, comparisonValue) {
    if (nameDisplayed.length == 0) {
        nameDisplayed = el;
    }
    var msg = ajax_config.DEFAULT_MSG;
    if (ruleName=='required') {
        msg = ajax_config.REQUIRED_MSG.replace('{1}', nameDisplayed);
    } else if (ruleName=='minlength') {
        msg = ajax_config.MINLENGTH_MSG.replace('{1}', nameDisplayed).replace('{2}', comparisonValue);
    } else if (ruleName=='maxlength') {
        msg = ajax_config.MAXLENGTH_MSG.replace('{1}', nameDisplayed).replace('{2}', comparisonValue);
    } else if (ruleName=='numrange') {
        msg = ajax_config.NUMRANGE_MSG.replace('{1}', nameDisplayed).replace('{2}', comparisonValue);
    } else if (ruleName=='date') {
        msg = ajax_config.DATE_MSG.replace('{1}', nameDisplayed);
    } else if (ruleName=='numeric') {
        msg = ajax_config.NUMERIC_MSG.replace('{1}', nameDisplayed);
    } else if (ruleName=='integer') {
        msg = ajax_config.INTEGER_MSG.replace('{1}', nameDisplayed);
    } else if (ruleName=='double') {
        msg = ajax_config.DOUBLE_MSG.replace('{1}', nameDisplayed);
    } else if (ruleName=='equal') {
        msg = ajax_config.EQUAL_MSG.replace('{1}', nameDisplayed).replace('{2}', yav.getComparisonDisplayed(comparisonValue));
    } else if (ruleName=='notequal') {
        msg = ajax_config.NOTEQUAL_MSG.replace('{1}', nameDisplayed).replace('{2}', yav.getComparisonDisplayed(comparisonValue));
    } else if (ruleName=='alphabetic') {
        msg = ajax_config.ALPHABETIC_MSG.replace('{1}', nameDisplayed);
    } else if (ruleName=='alphanumeric') {
        msg = ajax_config.ALPHANUMERIC_MSG.replace('{1}', nameDisplayed);
    } else if (ruleName=='alnumhyphen') {
        msg = ajax_config.ALNUMHYPHEN_MSG.replace('{1}', nameDisplayed);
    } else if (ruleName=='alnumhyphenat') {
        msg = ajax_config.ALNUMHYPHENAT_MSG.replace('{1}', nameDisplayed);
    } else if (ruleName=='alphaspace') {
        msg = ajax_config.ALPHASPACE_MSG.replace('{1}', nameDisplayed);
    } else if (ruleName=='email') {
        msg = ajax_config.EMAIL_MSG.replace('{1}', nameDisplayed);
    } else if (ruleName=='mobile') {
        msg = ajax_config.MOBILE_MSG.replace('{1}', nameDisplayed);
    } else if (ruleName=='zipcode') {
        msg = ajax_config.ZIPCODE_MSG.replace('{1}', nameDisplayed);
    } else if (ruleName=='phone') {
        msg = ajax_config.PHONE_MSG.replace('{1}', nameDisplayed);
    } else if (ruleName=='password') {
        msg = ajax_config.PASSWORD_MSG.replace('{1}', nameDisplayed);
    }  else if (ruleName=='regexp') {
        msg = ajax_config.REGEXP_MSG.replace('{1}', nameDisplayed).replace('{2}', comparisonValue);
    } else if (ruleName=='date_lt') {
        msg = ajax_config.DATE_LT_MSG.replace('{1}', nameDisplayed).replace('{2}', yav.getComparisonDisplayed(comparisonValue));
    } else if (ruleName=='date_le') {
        msg = ajax_config.DATE_LE_MSG.replace('{1}', nameDisplayed).replace('{2}', yav.getComparisonDisplayed(comparisonValue));
    } else if (ruleName=='empty') {
        msg = ajax_config.EMPTY_MSG.replace('{1}', nameDisplayed);
    }
    return msg;
}

 /* UTF8UrlEncode(input)*/  
 function UTF8UrlEncode(input){   
  
        var output = "";   
  
        var currentChar = '';   
  
        for(var counter = 0; counter < input.length; counter++){   
  
            currentChar = input.charCodeAt(counter);   
  
            if((0 <= currentChar) && (currentChar <= 127))   
  
                output = output + UTF8UrlEncodeChar(currentChar);   
  
            else  
  
                output = output + encodeURIComponent(input.charAt(counter));   
  
        }   
  
        var reslut = output.toUpperCase();   
        return reslut.replace(/%26/, "%2526");    
    }   
  
    
  
    function UTF8UrlEncodeChar(input){   
  
        if(input <= 0x7F) return "%" + input.toString(16);   
  
        var leadByte = 0xFF80;   
  
        var hexString = "";   
  
        var leadByteSpace = 5;   
  
        while(input > (Math.pow(2, leadByteSpace + 1) - 1)){   
  
            hexString = "%" + ((input & 0x3F) | 0x80).toString(16) + hexString;   
  
            leadByte = (leadByte >> 1);   
  
            leadByteSpace--;   
  
            input = input >> 6;   
  
        }   
  
        return ("%" + (input | (leadByte & 0xFF)).toString(16) + hexString).toUpperCase();   
  
    }   
/*end*/  

function copyToClipboard(txt) {   
        if (window.clipboardData) {   
               window.clipboardData.clearData();   
               window.clipboardData.setData("Text", txt);   
           } else if (navigator.userAgent.indexOf("Opera") != -1) {   
               window.location = txt;   
           } else if (window.netscape) {   
               try {   
                   netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");   
               } catch (e) {                 
                   
               }   
               var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);   
               if (!clip) return;   
               var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);   
               if (!trans) return;   
               trans.addDataFlavor('text/unicode');   
               var str = new Object();   
               var len = new Object();   
               var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);   
               var copytext = txt;   
               str.data = copytext;   
               trans.setTransferData("text/unicode", str, copytext.length * 2);   
               var clipid = Components.interfaces.nsIClipboard;   
               if (!clip) return false;   
               clip.setData(trans, null, clipid.kGlobalClipboard);   
           }   
          
       return true;   
   } 


function stepcoclose()
{
 var item1=document.getElementById("mySitep")
 if (item1.style.display=="none")
 {
  item1.style.display="block";
  document.getElementById("sishowsitep").style.display="none";
 }
 else 
 {
  item1.style.display="none";
  document.getElementById("sishowsitep").style.display="block";
 }
 
}

function stepcoclose1()
{
 var item1=document.getElementById("mySitep")
  item1.style.display="block";
  document.getElementById("sishowsitep").style.display="none";
}