﻿function getPara(paraName)
{ 
    var urlPara = location.search;
    var reg = new RegExp("[&|?]"+paraName+"=([^&$]*)", "gi"); 
    var a = reg.test(urlPara); 
    return a ? RegExp.$1 : ""; 
}
function checknumber(String) 
{ 
    var Letters = "1234567890";
    var i;
    var c;
    var f=1;
    for(i = 0; i < String.length; i++)
    {
        c = String.charAt(i);
        if (Letters.indexOf( c ) == -1)
        {
            f=0;
            break;
        }
    }
    if(i>0 && f>0)
    {
        return true;
    }
    else
    {
        return false;
    }
}
function pickDate(objOb,url)
{
	var	strURL = url;
	var	strIni = objOb.value;
	var	strFtr = "dialogHeight: 240px; dialogWidth: 320px; ";
	strFtr = strFtr + "dialogLeft: " + window.event.screenX + "px; ";
	strFtr = strFtr + "dialogTop: " + window.event.screenY + "px; ";
	strFtr = strFtr + "edge: Sunken; center: no; help: No; resizable: No; scroll: No; status: No;"

	var	strVal = window.showModalDialog (strURL, strIni,strFtr);		
	if (strVal != "")
	{
		objOb.value = strVal;
	}
}
//var df = new DateFormater('现在是: /m月/j日,/Y年  /D  /a  /0h:/0i:/0s');
//    df.AM('上午');
//    df.PM('下午');
//    var datestr  = df.format( new Date );
//    alert( datestr );
function DateFormater(expr){
	var wd = [ '星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六' ],
		M= [ '一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月' ],
		utc= false,
		am= 'AM',
		pm= 'PM',
		y,m,j,d,h,i,s,e;
	this.expr = expr;
	this.format = function(t){
		if(!t.getTime){ return false; }
		y 	= utc?t.getUTCFullYear():t.getFullYear();
		m	= utc?t.getUTCMonth():t.getMonth();
		j	= utc?t.getUTCDate():t.getDate();
		d	= utc?t.getUTCDay():t.getDay();
		h	= utc?t.getUTCHours():t.getHours();
		i	= utc?t.getUTCMinutes():t.getMinutes();
		s	= utc?t.getUTCSeconds():t.getSeconds();
		e	= utc?t.getUTCMilliseconds():t.getMilliseconds();
		a	= ((h==12 && (m+s+e>0))||h>12)?pm:am;
		return expr.replace(/\/0?[YyMmjDdHhisea\/]{1}/g, function(){
			for(var x=0,l=arguments.length; x<l; x++){
				switch(arguments[x]){
					case '/Y': 	return ''+y;
					case '/y': 	return (''+y).replace(/\d*(\d{2})/,'$1');
					case '/0m': return ''+((m<9?'0'+(m+1): (m+1)));
					case '/m': 	return ''+(m+1);
					case '/M':	return M[m];
					case '/0j':	return ''+(j<10?'0'+j: j);
					case '/j':	return ''+j;
					case '/d': 	return ''+d;
					case '/D':	return wd[d];
					case '/0H': return ''+(h<10?'0'+h: h);
					case '/H':	return ''+h;
					case '/0h': h=h>12?h-12:h; return ''+(h<10?'0'+h: h);
                                        case '/h':   return ''+h>12?h-12:h;
					case '/0i': return ''+(i<10?'0'+i: i);
					case '/i': 	return ''+i;
					case '/0s': return ''+(s<10?'0'+s: s);
					case '/s': 	return ''+s;
					case '/0e': return ''+(e<10?'00'+e: (e<100?'0'+e: e));
					case '/e': 	return ''+e;
					case '/a':	return ''+a;
					case '//': 	return '/';
					default: return arguments[x];
				}
			}
		});
	};
	this.isUTC	= function(u){ return typeof(u)=='boolean'? (utc=u): utc; };
	this.AM = function(a){ return am = typeof(a)=='string'? a: am; };
	this.PM = function(p){ return pm = typeof(p)=='string'? p: pm; };
	this.weekdays = function(){ return _confg(arguments, 'wd', 7); };
	this.months	= function(){ return _confg(arguments, 'M', 12); }
	function _confg(args, vrb, s){
		var a1 = args[0], a2 = args[1];
		if(args.length>2){ return false; }
		switch( typeof(a1) ){
			case 'undefined': return eval(vrb);
			case 'object':
				if( a1.length!=s || typeof(a1[0])=='undefined' ){ return false;}
				for(var i=0,l=a1.length; i<l; i++){
					eval(vrb+'[i] = a1[i];');
				}
				break;
			case 'number': return ( typeof(a2)!='undefined'? false:eval(vrb+'[a1]') );
			case 'string':
				if( typeof(a2)!='number' || typeof(eval(vrb+'[a2]'))=='undefined' ) { return false; }
				eval(vrb+'[a2] = a1;');
		}
		return  true;
	}
}

//showtime = new Date().format("yyyy-MM-dd hh:mm:ss");
Date.prototype.format = function(format)   
{   
   var o = {   
     "M+" : this.getMonth()+1, //month   
     "d+" : this.getDate(),    //day   
     "h+" : this.getHours(),   //hour   
     "m+" : this.getMinutes(), //minute   
     "s+" : this.getSeconds(), //second   
     "q+" : Math.floor((this.getMonth()+3)/3), //quarter   
     "S" : this.getMilliseconds() //millisecond   
   }   
   if(/(y+)/.test(format)) format=format.replace(RegExp.$1,   
     (this.getFullYear()+"").substr(4 - RegExp.$1.length));   
   for(var k in o)if(new RegExp("("+ k +")").test(format))   
     format = format.replace(RegExp.$1,   
       RegExp.$1.length==1 ? o[k] :    
         ("00"+ o[k]).substr((""+ o[k]).length));   
   return format;   
}

String.prototype.Trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

function getmounthdays(year,mounth)
{
    if(mounth==1||mounth==3||mounth==5||mounth==7||mounth==8||mounth==10||mounth==12)
    {
        return '31';
    }
    else if(mounth==4||mounth==6||mounth==9||mounth==11)
    {
        return '30';
    }
    else if(mounth==2)
    {
        if(year%4==0)
        {
            return '29';
        }
        else
        {
            return '28';
        }
    }
}

function pickDate(objOb,strURL)
{
	var	strIni = objOb.value;
	var	strFtr = "dialogHeight: 240px; dialogWidth: 320px; ";
	strFtr = strFtr + "dialogLeft: " + window.event.screenX + "px; ";
	strFtr = strFtr + "dialogTop: " + window.event.screenY + "px; ";
	strFtr = strFtr + "edge: Sunken; center: no; help: No; resizable: No; scroll: No; status: No;"

	var	strVal = window.showModalDialog (strURL, strIni,strFtr);		
	if (strVal != "")
	{
		objOb.value = strVal;
	}
}
function getmoudays(yy,mm)
{
    var mds=31;
    if(mm==4||mm==6||mm==9||mm==11)
    {
        mds=30;
    }
    else if(mm==2)
    {
        if(yy%4==0)
        {
            mds=28;
        }
        else
        {
            mds=29;
        }
    }
    return mds;
}
function getstrdatetime(time,days)
{
    var yy=time.getYear();
    var mm=time.getMonth()+1;
    var dd=time.getDate()+days;
    var mds=getmoudays(yy,mm);
    if(days>0)
    {
        while(dd>mds)
        {
            dd-=mds;
            mm++;
            if(mm>12)
            {
                yy++;
                mm=1;
            }
            mds=getmoudays(yy,mm);
        }
    }
    else if(days<0)
    {
        while(dd<0)
        {
            dd+=mds;
            mm--;
            if(mm<1)
            {
                yy--;
                mm=12;
            }
            mds=getmoudays(yy,mm);
        }
    }
    return yy+'-'+mm+'-'+dd;
}
