/*main application js*/
function GetObj(objName){
	var obj = null;
	if(document.getElementById){
		 obj = eval('document.getElementById("' + objName + '")');
		
	}
	if(obj == null){
		if(window.navigator.userAgent.indexOf("Firefox")>=1) { 
			obj = document.getElementsByName(objName);
			if(obj.length>0)obj=obj[0];
		}else{
			if(document.layers){
				obj = eval("document.layers['" + objName +"']");
		
			}else{
				obj = eval('document.all.' + objName);
				
			}
		}
	}
	return obj;
}

/**
 * 去两边的空格
 **/
String.prototype.trim = function() {
  return this.replace(/(^\s*)|(\s*$)/g, "");
}

String.prototype.replaceAll  = function(s1,s2){    
	return this.replace(new RegExp(s1,"gm"),s2);    
}  

function validateEmail(email) {
	if (email.charAt(0) == "." || email.charAt(0) == "@" || email.indexOf("@.") != -1 ||
	 	email.indexOf(".@") != -1 || email.indexOf('@', 0) == -1 ||  email.indexOf('.', 0) == -1 || 
	 	email.lastIndexOf("@")==email.length-1 || email.lastIndexOf(".")==email.length-1) {
	 	return false;
	} else {
		return true;
	}
}

function validateEmailForReg(email){
	var testResult = /^\w+([-+.]\w+)*@\w+([-.]\\w+)*\.\w+([-.]\w+)*$/.test(email);
	return testResult;
}

/**
 * 所在城市用到。当选择省时，显示省下的城市
 **/
function selectCity(objName){
	var obj = GetObj(objName);
 	var cityCallProxy = new CityCallProxy();
 	var value = obj.options[obj.selectedIndex].value;
 	removeSelect("city");
 	if(value=="") return;
 	cityCallProxy.getCitys(value,_getCitysCallback);
 	function _getCitysCallback(reply){ 
		var returnList=reply.getResult();
		
		var oOption = document.createElement("OPTION");
		var obj = GetObj("city");
		obj.options.add(oOption);
		oOption.innerHTML = "";
		if(returnList.length>0){
			//remove existed option
			for(var i=0;i<returnList.length;i++){
				var category = returnList[i];
				var oOption = document.createElement("OPTION");
				var obj =GetObj("city");
				obj.options.add(oOption);
				oOption.innerHTML = category.label;
				oOption.value = category.value;
	
			}
		}
	}
}

/*telephone validate*/
String.prototype.isTel = function() {
	var phoneRegWithArea = /^[0][0-9]{2,3}[ ]?[-]?[0-9]{5,8}$/; 
	var phoneRegNoArea = /^[1-9]{1}[0-9]{5,8}$/; 
	if( this.length > 9 ) {
	    if(phoneRegWithArea.test(this)){
	    	return true; 
	    } else {
	    	return false;
	    }
	}else{
	    if(phoneRegNoArea.test(this)) {
	    	return true; 
	    } else {
	    	return false;
	    }
	}
	/*
	//return (/^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/.test(this.trim()));
	var patrn=/^(\d){3,4}[ ]?[-]?(\d){7,8}$/;   
	if (!patrn.exec(this))
	    return false;  
	return true;  
	 */
}

/*Mobile validate*/
String.prototype.isMobile = function() { 
	return (/^(((13[0-9]{1})|15[0189])+\d{8})$/.test(this.trim())); 
}

function validateEmail(email) {
	if (email.charAt == "." || email.charAt == "@" ||       
	 	email.indexOf('@', 0) == -1 ||  email.indexOf('.', 0) == -1 || 
	 	email.lastIndexOf("@")==email.length-1 || 
	 	email.lastIndexOf(".")==email.length-1) {
	 	return false;
	} else {
		return true;
	}
}