

//确定数值的范围
function isBetween(val,lo,hi){
	if (val <lo){

		return false;
	}

	if (val >hi){ 

		return(false);
	}
	
	return(true);

}

//獲得
// srcDate > destDate
// [1 true] [0 false] [-1 data format error]
function isBigDate(srcDate,destDate){

	//not date format
	if((!isDate(srcDate))||(!isDate(destDate))){
		return -1 
	}

	var the1st = srcDate.indexOf('-');
	var the2nd = srcDate.lastIndexOf('-');
	var srcy = srcDate.substring(0,the1st);
	var srcm = srcDate.substring(the1st+1,the2nd);
	var srcd = srcDate.substring(the2nd+1,srcDate.length);			

	the1st = destDate.indexOf('-');
	the2nd = destDate.lastIndexOf('-');
	var desty = destDate.substring(0,the1st);
	var destm = destDate.substring(the1st+1,the2nd);
	var destd = destDate.substring(the2nd+1,destDate.length);			
	if(srcy<desty){
		return 0;
	}

	if(srcm<destm){
		return 0 ;
	}

	if(srcd>destd){
			return 1 ;
	}
	
	return 0 ;

}

//判断是否日期
//格式：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 if(y<1900){return false;}
		else{return(true);}
	}

}




//判断是否时间
//格式：hh:mm
function isTime(theStr){
	var colonDex = theStr.indexOf(':');
	if((colonDex<1)||(colonDex>2)){return(false);}
	else{
		var hh = theStr.substring(0,colonDex);
		var ss = theStr.substring(colonDex+1,theStr.length);
		if((hh.length<1)||(hh.length>2)||(!isInt(hh))){return (false);}
		else if((ss.length<1)||(ss.length>2)||(!isInt(ss))){return (false);}
		else if((!isBetween(hh,0,23))||(!isBetween(ss,0,59))){return(false);}
		else{ return(true);}
	}
}


//判断是否数字(单一字符)
function isDigit(theNum){
	var theMask = '0123456789';
	if(isEmpty(theNum)) return (false);
	else if(theMask.indexOf(theNum) == -1) return(false);
	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);
}

//判断是否浮点数值
function isReal(theStr){
	var dot1st = theStr.indexOf('.');
	var dot2nd = theStr.lastIndexOf('.');
	var OK = true ;
	if (isEmpty(theStr)) return false ;
	if (dot1st == -1){
		if(!isInt(theStr)) return (false);
		else return(true);
	}
	else if(dot1st != dot2nd) return (false);
	else if(dot1st == 0 ) return(false);
	else{
		var intPart = theStr.substring(0,dot1st);
		var decPart = theStr.substring(dot2nd+1);
//		if(decPart.length >decLen) return(false);
		if(!isInt(intPart) || !isInt(decPart)) return(false);
		else if(isEmpty(decPart)) return(false);
		else return(true);
	}
}

//
function isUReal(theStr){
	if(!isReal(theStr)){return false;}
	if(theStr<=0){return false;}
	return true;
}


function isQuot(str){
	var slen = str.length ;
	var i,s ;
	for (i=0;i<slen;i++)
	{
		 s = str.substring(i,i+1) ;
		if(s=="'"||s=="\""){
			return true ;
		}
	}
	return false;
}

function isDateTime(str){

  var n = str.indexOf(' ');
  if (n<0){
	  return false;
  }

  var datestr = str.substring(0,n);
  var timestr = str.substring(n+1);
  if(!(isDate(datestr)&&isTime(timestr))){
		return false ;
  }
  
  return true;
}

//email check
function isEmail(strEmail) { 
  var myReg = /^[_a-zA-Z0-9]+@([_a-zA-Z0-9]+\.)+[A-Za-z0-9]{2,3}$/; 
  if(myReg.test(strEmail)) return true; 
  return false; 
}

function isCharsInBag (s, bag){ 
	var i,c;
	for (i = 0; i < s.length; i++){ 
		c = s.charAt(i);//字符串s中的字符
		if (bag.indexOf(c)<= -1) {
			return "";
		}
	}
	return "find";
}

function isKeyStr(s){
	var errorChar;
	var theChar = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
	errorChar = isCharsInBag(s, theChar)
	if (errorChar != "" ){
		return true;
	} 
	return false;
}
/* String Functions
 */
function getDateStr(){
	var cDate = new Date();
	var DateStr = ""+cDate.getYear()+""+cDate.getMonth()+""+cDate.getDay()+cDate.getHours()+cDate.getMinutes()+cDate.getSeconds();
	return DateStr ;
}


function goURL(url){
	if(url.indexOf('?')>=0){
		url += "&mark="+getDateStr() ;
	}else{
		url += "?mark="+getDateStr() ;
	}
	top.location.href = url;
}



function goURL2(url,obj){
	if(url.indexOf('?')>=0){
		url += "&mark="+getDateStr() ;
	}else{
		url += "?mark="+getDateStr() ;
	}
	obj.location = url ;
}

function centerWindow(url,width,height) {
	if (document.all)
		var xMax = screen.width, yMax = screen.height;
	else
		if (document.layers)
		var xMax = window.outerWidth, yMax = window.outerHeight;
	else
		var xMax = 640, yMax=480;
		var xOffset = (xMax - width)/2, yOffset = (yMax - height)/2;

	var newwin = window.open(url,'', 'toolbar=0,resizable=1,scrollbars=1,dependent=0,width='+width+',height='+height+',screenX='+xOffset+',screenY='+yOffset+', top='+yOffset+',left='+xOffset+'');
	newwin.focus();
}

function queryString( key ) {
	var href = window.location.search;
	var lhref = href.toLowerCase();

	var pos = lhref.indexOf( key + "=" );
	if (pos==-1) return null;

	var next = lhref.indexOf( "&", pos );
	var value = href.substring( pos + key.length + 1, (next==-1) ? 999 : next );

	return value;
}