﻿var g_defaultRangeHalf = 2000;

function UrlEncode(str){ 
  if(str == null || str.length == 0) {
	  return str;
  }
  
  var ret=""; 
  var strSpecial="!\"#$%&'()*+,/:;<=>?[]^`{|}~%"; 
  var tt= "";

  for(var i=0;i<str.length;i++){ 
   var chr = str.charAt(i); 
    var c=str2asc(chr); 
    tt += chr+":"+c+"n"; 
    if(parseInt("0x"+c) > 0x7f){ 
      ret+="%"+c.slice(0,2)+"%"+c.slice(-2); 
    }else{ 
      if(chr==" ") 
        ret+="+"; 
      else if(strSpecial.indexOf(chr)!=-1) 
        ret+="%"+c.toString(16); 
      else 
        ret+=chr; 
    } 
  } 
  return ret; 
} 

function UrlDecode(str){ 
  var ret=""; 
  for(var i=0;i<str.length;i++){ 
   var chr = str.charAt(i); 
    if(chr == "+"){ 
      ret+=" "; 
    }else if(chr=="%"){ 
     var asc = str.substring(i+1,i+3); 
     if(parseInt("0x"+asc)>0x7f){ 
      ret+=asc2str(parseInt("0x"+asc+str.substring(i+4,i+6))); 
      i+=5; 
     }else{ 
      ret+=asc2str(parseInt("0x"+asc)); 
      i+=2; 
     } 
    }else{ 
      ret+= chr; 
    } 
  } 
  return ret; 
} 

function validateField(fieldName, canEmpty, maxLen, theObj) {
	var theValue = theObj.value;
	if(!canEmpty && (theValue == null || theValue.length == 0)) {
		alert("对不起，\"" + fieldName + "\"不能为空");
		theObj.focus();
		return false;
	}
	if(theValue != null) {
		if(theValue.length > maxLen) {
			alert("对不起，\"" + fieldName + "\"的长度不能大于" + maxLen + "个中文字符");
			theObj.focus();
			return false;
		}
	}
	
	return true;
}
