String.prototype.trim=function(){return this.replace(/(^[\s]*)|([\s]*$)/g,"");}
String.prototype.lTrim=function(){return this.replace(/(^[\s]*)/g, "");}
String.prototype.rTrim=function(){return this.replace(/([\s]*$)/g, "");}
function CopyText(obj) {
	ie = (document.all)? true:false
	if (ie){
		var rng = document.body.createTextRange();
		rng.moveToElementText(obj);
		rng.scrollIntoView();
		rng.select();
		rng.execCommand("Copy");
		rng.collapse(false);
	}
}
function addFav()
{
 window.external.AddFavorite(window.location,document.title);
	
}
function submitSearch()
	{
		var obj=$("keyword")
		var objVal=obj.value.trim();
		if(objVal=="" ||objVal=="请输入关键字")
		{		
			alert("请输入关键字");
			obj.value="";
			obj.focus();
			return;
		}
		$("frmSearch").submit();
	}
function openWin(url){ 
var   width   =   screen.availWidth;   
var   height   =   screen.availHeight; 
window.open(url,"","top=0,left=0,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
}

function copyToClipBoard(){
    var clipBoardContent="";
    clipBoardContent+=document.title;
    clipBoardContent+="\n";
    clipBoardContent+=this.location.href;
    window.clipboardData.setData("Text",clipBoardContent);
    alert("复制成功，请粘贴到你的QQ/MSN上推荐给你的好友");
  }
function $(obj)
{
	return document.getElementById(obj)
}
function selectPicture(curPicPath,objPic)
{
	var curDir="",fileName='';
	if(curPicPath.trim()=="")curPicPath=$(objPic).value;
	curDir=curPicPath.substring(0,curPicPath.lastIndexOf("/"));
	fileName=curPicPath.substring(curPicPath.lastIndexOf("/"),curPicPath.length);
	var reVal="";
	reVal=OpenWindow('../lib/dir/SelectPic.asp?CurrPath='+curDir+"&fileName="+fileName,500,300,window);
	if(reVal.trim()!="")
	{
		$(objPic).value=reVal;
	}
}

function OpenWindowPicture(Url,Width,Height,WindowObj,SetObj)
{
	var ReturnStr=showModalDialog(Url,WindowObj,'dialogWidth:'+Width+'pt;dialogHeight:'+Height+'pt;status:yes;help:no;scroll:yes;');
	alert(ReturnStr)
	if (ReturnStr!='') $(SetObj).value=ReturnStr;
	return ReturnStr;
}

function OpenWindowAndSetValue(Url,Width,Height,WindowObj,SetObj)
{
	var ReturnStr=showModalDialog(Url,WindowObj,'dialogWidth:'+Width+'pt;dialogHeight:'+Height+'pt;status:yes;help:no;scroll:yes;');
	alert(ReturnStr)
	if (ReturnStr!='') $(SetObj).value=ReturnStr;
	return ReturnStr;
}
function OpenWindow(Url,Width,Height,WindowObj)
{
	var ReturnStr=showModalDialog(Url,WindowObj,'dialogWidth:'+Width+'pt;dialogHeight:'+Height+'pt;status:no;help:no;scroll:yes;');
	return ReturnStr;
}

function OpenEditerWindow(Url,WindowName,Width,Height)
{
	window.open(Url,WindowName,'toolbar=0,location=0,maximize=1,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,top=50,left=50,width='+Width+',height='+Height);
}
function OpeniFrameWindow(objName,hiddenObj,typeFlag)
{
	var reVal="";
	reVal=window.showModalDialog('../lib/menuFrame.asp?typeFlag='+typeFlag,'','dialogWidth:500px;dialogHeight:400px;center:1;resizable:no;scroll:1;help:0;status:0');
	return reVal;
}
function selectType(objName,hiddenObj,type)
{
	var reVal=OpeniFrameWindow(objName,hiddenObj,type)
	if(typeof(reVal)=="undefined"||reVal.trim()=="")return;
	if(reVal!="")
	 {
	 	var reVal=reVal.split("|");
		var objHidden=document.getElementById(hiddenObj);
		objHidden.value=reVal[0];
		var obj=document.getElementById(objName);
		obj.value=(reVal[1].trim()==""||reVal[1]=="undefined")?"无父栏目":reVal[1].trim();
	 }
}
function selectInfoType(objName,hiddenObj,type)
{
	var reVal=OpeniFrameWindow(objName,hiddenObj,type)
	if(typeof(reVal)=="undefined"||reVal.trim()=="")return;
	if(reVal!="")
	 {
	 	var reVal=reVal.split("|");
		var objHidden=document.getElementById(hiddenObj);
		objHidden.value=reVal[0];
		var obj=document.getElementById(objName);
		obj.value=(reVal[1].trim()==""||reVal[1]=="undefined")?"无父栏目":reVal[1].trim();
	 }
}
function pageSearchType(objName,hiddenObj)
{
	var reVal=OpeniFrameWindow(objName,hiddenObj)
	if(typeof(reVal)=="undefined"||reVal.trim()=="")return;
	if(reVal!="")
	 {
	 	var reVal=reVal.split("|");
		var objHidden=document.getElementById(hiddenObj);
		objHidden.value=reVal[0];
		var obj=document.getElementById(objName);
		obj.value=(reVal[1].trim()==""||reVal[1]=="undefined")?"类别不限":reVal[1].trim();
	 }
}


function IsAge(n){
	if (isNaN(n)) return false;
	if (n>15 && n<100) return true;
}
function IsHeight(n){
	if (isNaN(n)) return false;
	if (n>99 && n<251) return true;
}
function IsWeight(n){
	if (isNaN(n)) return false;
	if (n>29 && n<201) return true;
}
function IsSalary(n){
	if (n=='') return false;
	if (isNaN(n)) return false;
	if (n>=0 && n<1000000) return true;
}
function IsEmail(s){
	var patrn = /[_a-zA-Z\d\-\.]+@[_a-zA-Z\d\-]+(\.[_a-zA-Z\d\-]+)+$/;
	if (patrn.test(s)) return true;
}
function IsQQ(s){
	var patrn=/^[1-9]{1}[0-9]{4,9}$/;
	if (patrn.exec(s)) return true;
}
function IsPoPo(s){
	var patrn=/^([a-zA-Z0-9.\-_@]){5,16}$/;
	if (patrn.exec(s)) return true;
}
function isBetween (val, lo, hi) {
	if ((val < lo) || (val > hi)) { return(false); }
	else { return(true); }
}
function isEmpty (str) {
    if ((str==null)||(str.length==0)) return true;
    else return(false);
}
function isInt (theStr) {
	var flag = true;
	if (isEmpty(theStr)) { flag=false; }
	else
	{	for (var i=0; i<theStr.length; i++) {
			if (isDigit(theStr.substring(i,i+1)) == false) {
				flag = false; break;
			}
		}
	}
	return(flag);
}
//校验数字：0-9数字的组合
function isDigit(s)
{
	var patrn=/^[0-9]{1,20}$/;
	if (!patrn.exec(s)) return false
	return true
}
//检验日期：YYYY-MM-DD
function IsDate (theStr) {
	var the1st = theStr.indexOf('-');
	var the2nd = theStr.lastIndexOf('-');
	
	if (the1st == the2nd) { return(false); }
	else {
		var y = theStr.substring(0,the1st);
		var m = theStr.substring(the1st+1,the2nd);
		var d = theStr.substring(the2nd+1,theStr.length);
		var maxDays = 31;
		
		if (isInt(m)==false || isInt(d)==false || isInt(y)==false) {
			return(false); }
		else if (y.length < 4) { return(false); }
		else if (!isBetween (m, 1, 12)) { return(false); }
		else if (m==4 || m==6 || m==9 || m==11) maxDays = 30;
		else if (m==2) {
			if (y % 4 > 0) maxDays = 28;
			else if (y % 100 == 0 && y % 400 > 0) maxDays = 28;
           	else maxDays = 29;
		}
		if (isBetween(d, 1, maxDays) == false) { return(false); }
		else { return(true); }
	}
}

//判断单选
function chkRadio(o){
	for (i=0;i<o.length;i++){
		if (o[i].checked) return true;
	}
	return false;
}

//验证后一个日期不能小于前一个日期
function checkTwoTime(fromObj,toObj){
		var fromTime = fromObj.value;
		var toTime = toObj.value;
		if(fromTime==""||toTime==""||fromTime==toTime){
			return true;
		}else{
			var fromYear = fromTime.substr(0,4);
			var toYear = toTime.substr(0,4);
			if(parseInt(fromYear)<parseInt(toYear)){
				return true;
			}else if(parseInt(fromYear)>parseInt(toYear)){
				alert("后一个时间不能小于前一个时间！");
				toObj.value="";
				return false;
			}else{
				var fromMon = fromTime.substr(5,2);
				var toMon = toTime.substr(5,2);
				if(parseInt(fromMon)<parseInt(toMon)){
					return true;
				}else if(parseInt(fromMon)>parseInt(toMon)){
					alert("后一个时间不能小于前一个时间！");
					toObj.value="";
					return false;
				}else{
					var fromDay = fromTime.substr(8,2);
					var toDay = toTime.substr(8,2);
					if(parseInt(fromDay)<=parseInt(toDay)){
						return true;
					}else{
						alert("后一个时间不能小于前一个时间！");
						toObj.value="";
						return false;
					}
				}
			}
		}
	}
	function getCookieVal(offset) {
	try{
		var endstr = document.cookie.indexOf (";", offset);
		if (endstr == -1)
		endstr = document.cookie.length;
		//return unescape(document.cookie.substring(offset, endstr));
		return document.cookie.substring(offset, endstr);
	}catch(e){
		return "";
	}
}

function GetCookie (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
	var j = i + alen;    
	if (document.cookie.substring(i, j) == arg)      
	return getCookieVal (j);    
	i = document.cookie.indexOf(" ", i) + 1;    
	if (i == 0) break;   
	}  
	return "";
}
function SetCookie (name, value) { 
	var exp1 = new Date(); 
	exp1.setTime(exp1.getTime() + (30*24*60*60*1000));
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : exp1;  
	var path = (argc > 3) ? argv[3] : '/';  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) +  
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	var cval = GetCookie (name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

