﻿// JScript 文件

function gotourl(obj)
{
    window.location =obj;
    
}

function openpage(obj)
{          
   var hostname="http://"+window .location.host+"/JCYYGJW/";
   //window.open(hostname+obj,"","","");
   window .location =hostname +obj;
}

function txtonblur(obj)
{
    obj.style.background='whitesmoke'; 
    obj.style.border='whitesmoke 1px solid'; 
}

function txtonfocus(obj)
{
    obj.style.background='#ffffff';
    obj.style.border='black 1px solid';
}

function txtonmouseover(obj)
{
    obj.style.border='black 1px solid';
}

function txtonmouseout(obj)
{
 
    obj.style.border='whitesmoke 1px solid';
  
}

function validate(obj)
{
    var regA=/<|>|'|#|"|>=|--/;
	if(obj.value.match(regA) != null)
	{
		alert("不能包含非法字符: "+obj.value.match(regA));
		obj.focus();
		return false;
	}
	else
	{
	    return true;
	}
}

function validateValue()
{
	for(var i=0;i<window.document.all.length;i++)
	{
		if((window.document.all(i).tagName.toLowerCase() == "input" && (window.document.all(i).type.toLowerCase() == "text" || window.document.all(i).type.toLowerCase() == "password")) ||  window.document.all(i).tagName.toLowerCase() == "textarea")
		{
			var obj = window.document.all(i);		
			if(obj.value == "" || obj.disabled == 'true' || obj.readonly == 'true' || obj.style.display == 'none')
			{
				continue;
			}	
			
			if(validate(obj))
			{
			    continue;
			}
			else
			{
			    return false;
			}				
		}
	}
	return true;	
}

/**
* 时间对象的格式化;
*/
Date.prototype.format = function(format)
{
    /*
    * eg:format="yyyy-MM-dd hh:mm:ss";
    */
    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;
}

function parseDate(str){   
  if(typeof str == 'string'){   
    var results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) *$/);   
    if(results && results.length>3)   
      return new Date(parseInt(results[1]),parseInt(results[2]) -1,parseInt(results[3]));    
    results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) +(\d{1,2}):(\d{1,2}):(\d{1,2}) *$/);   
    if(results && results.length>6)   
      return new Date(parseInt(results[1]),parseInt(results[2]) -1,parseInt(results[3]),parseInt(results[4]),parseInt(results[5]),parseInt(results[6]));    
    results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) +(\d{1,2}):(\d{1,2}):(\d{1,2})\.(\d{1,9}) *$/);   
    if(results && results.length>7)   
      return new Date(parseInt(results[1]),parseInt(results[2]) -1,parseInt(results[3]),parseInt(results[4]),parseInt(results[5]),parseInt(results[6]),parseInt(results[7]));    
  }   
  return null;   
}   

