/******** 函数名: trim
********* 参数：str
********* 说明：去首尾空格
*******************************************************************************************************/
function trim(str)
{
	str = str.replace(/(^\s*)|(\s*$)/g, "");
	return str;
}

/******** 函数名: checkdata
********* 参数：obj,mode,name
********* 说明：去首尾空格
*******************************************************************************************************/
function checkdata(obj_id,mode,alertword){
	var obj = $(obj_id);
	var value = trim(obj.value);
	if (mode == "isnull"){
		if (value == ""){
			alert ("You must enter the "+alertword+".");
			obj.focus();
			return false;
		}
	}
	else if (mode == "iszero"){
		if (value == "0"){
			alert ("The "+alertword+" can't be null.");
			obj.focus();
			return false;
		}
	}
	else if (mode == "int"){
		var tt = /^[1-9]\d*$/;
		if (!(tt.exec(value))){
			alert ("The "+alertword+" can only be integer.");
			obj.focus();
			return false;
		}
	}
	else if (mode == "email"){
		var tt = /^[a-zA-Z0-9]([a-zA-Z0-9]*[-_.]?[a-zA-Z0-9]+)+@([\w-]+\.)+[a-zA-Z]{2,}$/;
		if (!(tt.exec(value))){
			alert ("The "+alertword+" isn't a valid email address.");
			obj.focus();
			return false;
		}
	}
	else if (mode == "account"){
		var tt = /^[a-zA-Z][a-zA-Z0-9_]{1,15}$/;
		if (!(tt.exec(value))){
			alert ("The "+alertword+" is not a valid value. It must be start with english letter, number and '_' is allowed, 2-16 chars.");
			obj.focus();
			return false;
		}
	}
	return true;
}

/******** 函数名: search
********* 参数：search_form
********* 说明：检查search_form中是否全为空
*******************************************************************************************************/
function search(search_form){
	var s_form = $(search_form);
	var len = s_form.elements.length;
	var flag = 0;
	for (var i=0;i<len;i++){
		if (s_form.elements[i].type!="reset" && s_form.elements[i].type!="submit" && s_form.elements[i].type!="button" && trim(s_form.elements[i].value)!="" && trim(s_form.elements[i].value)!='0'){
			flag=1;
		}
	}
	if (flag==1){
		s_form.submit();
		return true;
	}else{
		alert ("You need to enter at least one keyword.");
		return false;
	}
}


function AutoIframe(frmid,miniheight)
{
	var obj=$(frmid);
	var contentheight = obj.contentWindow.document.body.scrollHeight;
	if (contentheight < miniheight){
		contentheight = miniheight;
	}
	obj.height= contentheight;
}

function logout(url){
	if (confirm("Are you sure to logout?")){
		window.location.href = url;
	}else{
		return false;
	}
}