

function trim(str) {
	return str.replace(/^\s*|\s*$/g, "");
}
function $(id) {
	return document.getElementById(id);
}
function $$(name) {
	return document.getElementsByName(name);
}
function isStrEmpty(value) {
	return value == "" || value == null;
}
function isFieldEmpty(obj) {
	obj.value = trim(obj.value);
	if (isStrEmpty(obj.value)) {
		obj.focus();
		return true;
	} else {
		return false;
	}
}


/**
check the redio or checkbox be selected one at least
*/
function isSelectedOne(tagName) {
	var radios = $$(tagName);
	for (var i = 0; i < radios.length; i++) {
		if (radios[i].checked == true) {
			return true;
		}
	}
	return false;
}
/**
check or uncheck all the checkbox
*/
function selectAll(selectBoxObj, tagName) {
	var radios = $$(tagName);
	var isChecked = selectBoxObj.checked;
	for (var i = 0; i < radios.length; i++) {
		radios[i].checked = isChecked;
	}
}
function reloadPage() {
	window.location.reload();
}
function goBack() {
	history.go(-1);
}
/*below check the form*/
function isEmail(str) {
	return /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(str);
}

/*
clear white space
*/
function trimAllInputTextValue()
	{
		var inputReturn = document.getElementsByTagName("input");
			for(var i=0;i<inputReturn.length;i++)
			{
				if(inputReturn[i].type=="text" )
				{
					inputReturn[i].value = trim(inputReturn[i].value);
				}
			}
	}


/*start with http or https */
function isUrl(str) {
	return /^http[s]?:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/.test(str);
}

function isUrlPath(str) {
	return /^http[s]?:\/\/*/.test(str);
}


function isNumAndChar(str) {
	return /^[0-9a-zA-Z]+$/.test(str);
}
function isQQ(str) {
	return /^[1-9]\d{4,10}$/.test(str);
}
function isEnglish(str) {
	return /^[A-Za-z]+$/.test(str);
}
function isChinese(str) {
	return /^[\u0391-\uFFE5]+$/.test(str);
}
function lenCH(str) {
	var t = str.replace(/[^\x00-\xff]/g, "**").length;
	return t;
}
//"[","]",
function containExceptChar(content)
{
	var tag_list = new Array("`","$","%","^","&","*","(",")","=","+","|","\\","{","}",";","'","\"",",","/","?");
	//var tag_list = new Array("~","`","!","@","#","$","%","^","&","*","_","=","+","\\",":",";","'","\"","<",",",">",".","/","?");
	//"#","(",")","-","|","[","]","{","}",
	for (var i=0;i<tag_list.length;i++) {
          if (content.indexOf(tag_list[i]) != -1) {
            	return true;
        }
    }
    return false;
}



function checkExceptCharPassed(form,checkExceptCharFields)
{
	for (var i=0;i<checkExceptCharFields.length;i++) 
	{
		var obj = eval("form."+checkExceptCharFields[i]);
		if( containExceptChar(obj.value) )
		{
			alert(EXCEPTION_CHAR_MESS);
			obj.focus();
			return false;
		}
	}
	
	return true;
}


/**
 * control the value length
 * @author jamesz
 */
function controlValueLen(obj,count)
{
	var max = count;
	var len = lenCH(obj.value); //obj.value.replace(/[^\x00-\xff]/gi,'xx').length;
	var n = max-len;
	
	if(n<0)
	{
	  obj.value = obj.value.substring(0, max);
	}
}

/* Just for tab show:
tabId: tab name
tabContId: tab content name
tabMax: tab child count
showId: show tab child index
*/
function showTag(tabId,tabContId,tabMax,showId)
	{
	 for(var i=1;i<=tabMax;i++)
	 {
	  if(i==showId) 
	  {
		   $(tabId+i).className="hLightOn";
		   $(tabContId+i).style.display="block";
	  }
	  else
	  {
		  $(tabContId+i).style.display="none";
		  $(tabId+i).className="hLightOff";
	   
	  }
	 }
	}


function goMenuURLinHeader(url)
	{
		window.top.location = url;
	}

	
function goMenuURLinFrame(url)
	{
		window.parent.frames['right'].location = url;
	}
	
function goPage(url, inputPage, totalPage)
{
	if(inputPage>totalPage)
	{
		inputPage = totalPage;
	}
	window.location = url+inputPage;
}
	

