function isNumeric(sText){
	var ValidChars = "0123456789";
	var IsNumber=true;
	var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++) { 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
		}
	}
	return IsNumber;   
}

function getElementsByClassName(className) { 
	var arr = new Array(); 
	var elems = document.getElementsByTagName("*");
	for(var i = 0; i < elems.length; i++){
		var elem = elems[i];
		var id = elem.getAttribute("id");
		var cls = elem.getAttribute("class");
		if(cls == className){
			arr[arr.length] = id;
		}
	}
	return arr;
}

function isDollar(sText){
	var ValidChars = "0123456789.";
	var isDollar=true;
	var Char;

	for (i = 0; i < sText.length && isDollar == true; i++) { 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) {
			isDollar = false;
		}
	}
	return isDollar;   
}

function isWhitespace(str){
	for(var i=0; i<str.length; i++) {
		var c = str.charAt(i);
		if( c!=' ' && c!='\n' && c!='\t' )
		  return false;
		}
	return true;
}

function isPhone(inputPhone,type){
	var strPhone = replaceAll(inputPhone," ","");
	/*
	strPhone = replaceAll(strPhone,"-","");
	strPhone = replaceAll(strPhone,"*","");
	strPhone = replaceAll(strPhone,"&lt;","");
	strPhone = replaceAll(strPhone,"&gt;","");
	strPhone=replaceAll(strPhone,"(","");
	strPhone=replaceAll(strPhone,")","");
	strPhone=replaceAll(strPhone,"+","");
	strPhone = replaceAll(strPhone,"\&","");
	strPhone = replaceAll(strPhone,"#","");
	strPhone=replaceAll(strPhone,"$","");
	strPhone=replaceAll(strPhone,"@","");
	strPhone=replaceAll(strPhone,":","");
	strPhone=replaceAll(strPhone,";","");
	strPhone=replaceAll(strPhone,",","");
	strPhone=replaceAll(strPhone,".","");
	strPhone=replaceAll(strPhone,"[","");
	strPhone=replaceAll(strPhone,"]","");
	strPhone=replaceAll(strPhone,"{","");
	strPhone=replaceAll(strPhone,"}","");
	strPhone=replaceAll(strPhone,"=","");
	strPhone=replaceAll(strPhone,"_","");
	strPhone=replaceAll(strPhone,"^","");
	strPhone=replaceAll(strPhone,"%","");
	strPhone=replaceAll(strPhone,"!","");
	strPhone=replaceAll(strPhone,"`","");
	strPhone=replaceAll(strPhone,"~","");
	strPhone=replaceAll(strPhone,"/","");
	strPhone=replaceAll(strPhone,"\\","");
	strPhone=replaceAll(strPhone,"|","");
	strPhone=replaceAll(strPhone,"\"","");
	strPhone=replaceAll(strPhone,"\'","");
	strPhone=replaceAll(strPhone,"?","");
	
	if(strPhone.length==14){
		if (strPhone.substring(0,1) =="+" && strPhone.substring(1,2) =="(" && strPhone.substring(5,6) ==")" && isNumeric(strPhone.substring(2,5)) && isNumeric(strPhone.substring(7,strPhone.length))){
			return true;
		}else{
			return false;
		}
	}else if(strPhone.length==13){
		if (strPhone.substring(0,1) =="(" && strPhone.substring(4,5) ==")" && isNumeric(strPhone.substring(1,4)) && isNumeric(strPhone.substring(6,strPhone.length))){
			return true;
		}else{
			return false;
		}
	}else if(strPhone.length==12){
		//if ((strPhone.substring(0,5) =="+8526" || strPhone.substring(0,5) =="+8529" || strPhone.substring(0,5) =="+8525" || strPhone.substring(0,5) =="+8536" || strPhone.substring(0,5) =="+8539") && isNumeric(strPhone.substring(1,strPhone.length))){
		if ((strPhone.substring(0,5) =="+8526" || strPhone.substring(0,5) =="+8529" || strPhone.substring(0,5) =="+8525") && isNumeric(strPhone.substring(1,strPhone.length))){
			return true;
		}else{
			return false;
		}
	}else if(isNumeric(strPhone)==false){
		return false;
	}else if(strPhone.length==11){
		if (strPhone.substring(0,4) =="8526" || strPhone.substring(0,4) =="8529" || strPhone.substring(0,4) =="8525" || strPhone.substring(0,4) =="8522" || strPhone.substring(0,4) =="8523"){
			return true;
		}else{
			return false;
		}
	}else */if(strPhone.length==8){
		if(type==852){
			if (strPhone.substring(0,1) =="6" || strPhone.substring(0,1) =="9" || strPhone.substring(0,1) =="5" || strPhone.substring(0,1) =="2" || strPhone.substring(0,1) =="3"){
				return true;
			}else{
				return false;
			}
		}else{
			if (strPhone.substring(0,1) =="6" || strPhone.substring(0,1) =="9" || strPhone.substring(0,1) =="5" || strPhone.substring(0,1) =="2" || strPhone.substring(0,1) =="3"){
				return true;
			}else{
				return false;
			}
		}
	}else {
		return false;
	}
}

function isTel(str){   
       var reg=/^([0-9]|[\-])+$/g ;   
       if(str.length<8 || str.length>18){   
        return false;   
       }   
       else{   
         return reg.exec(str);   
       }   
}  

function isMobilephone(str) {  
  return (/^(?:13\d|15[89])-?\d{5}(\d{3}|\*{3})$/.test(str));  
} 

function isTelephone(str)
{
    return (/^(([0\+]\d{2,3}-)?(\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/.test(str));
}

function isTel2(str){   
	if (isMobilephone(str)||isTelephone(str) || isPhone(str)){
		return true;
	}else{
		return false;
	}
}

function isEmail(strEmail){
	var invalidChars ="/:,?#;";
	if (strEmail==null || isWhitespace(strEmail)){
		return false;
	}
	for (ai=0;ai<invalidChars.length;ai++) {
		var badChar = invalidChars.charAt(ai);
		if (strEmail.indexOf(badChar,0) > -1){
			return false;
		}
	}
	var atPos = strEmail.indexOf("@",1);
	if (atPos ==-1){
		return false;
	}
	if (strEmail.indexOf("@",atPos+1) > -1){
		return false;
	}
	var periodPos = strEmail.indexOf(".",atPos);
	if (periodPos == -1){
		return false;
	}
	if (periodPos+3 > strEmail.length){
		return false;
	}
	return true;
}

function trim(stringToTrim){
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function checkLength(sText){
	if(sText.length < 8) {
		return false;
	}
	return true;
	
}

function replaceAll(strOrg,strFind,strReplace){
	var index = 0;
	while(strOrg.indexOf(strFind,index) != -1){
		strOrg = strOrg.replace(strFind,strReplace);
		index = strOrg.indexOf(strFind,index);
	}
	return strOrg
} 

function changeColor(td){
	if(td.className=='highlight')
		td.className = 'normal_blue';
	else
		td.className='normal_blue';
	var tdtag = document.getElementsByTagName("td");
	for(var i = 0; i < tdtag.length; i++){
		if(tdtag[i].className=='highlight'){
			tdtag[i].className = 'normal_blue';
		}
	}
	td.className='highlight';
}

function MM_openBrWindow(theURL,winName,features){ //v2.0
  var fea_split = new Array()
  var popW, popH, new_features
      fea_split = features.split(",")

  for (i=0; i<fea_split.length; i++) {
    if (fea_split[i].match("width"))
      popW = fea_split[i].slice(6)
    else if (fea_split[i].match("height"))
      popH = fea_split[i].slice(7)
  }

  if (document.all) {
    /* the following is only available after onLoad */
    w = document.body.clientWidth;
    h = document.body.clientHeight;
    x = window.screenTop;
    y = window.screenLeft;
  }
  else if (document.getElementById) {
    w = window.innerWidth;
    h = window.innerHeight;
    x = window.screenX;
    y = window.screenY;
  }
  //var leftPos = ((w-popW)/2)+y, topPos = ((h-popH)/2)+x;
  var leftPos = 20, topPos = 20;
  new_features = features + ',left=' + leftPos + ',top=' + topPos
  window.open(theURL,winName,new_features).focus();
}

function checkStr(msgContent) {
	var escapeMsg = escape(msgContent);
	if(escapeMsg.indexOf("%u")!=-1){
		return false;
	} else {
		return isValidStr(msgContent);
	}
}

function isValidStr(str){
	var invalidChars ="/:,?#;!'\"$@%^&*()_+-.[]{}|~`<>=\\";
	for (ai=0;ai<invalidChars.length;ai++) {
		var badChar = invalidChars.charAt(ai);
		if (str.indexOf(badChar,0) > -1){
			return false;
		}
	}
	return true;
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
