﻿function   fixTo(s,i){   
  if   (s==null   ||   s==""   ||   isNaN(s)   ||   Math.round(s)==0)   return   0;   
  i   =   Math.round(i);   
  if   (i==0)   return   Math.round(s);   
  if   (i==null   ||   isNaN(i)   ||   i<0)   i=2;   
  var   v   =   Math.round(s*Math.pow(10,i)).toString();   
  if   (/e/i.test(v))   return   s;   
  return   v.substr(0,v.length-i)+"."+v.substr(v.length-i);   
  }
  
/**
* 时间对象的格式化;
*/
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 $(x){
    return document.getElementById(x);
}

function  QueryString(sName)   
{   
    var   sSource   =   String(window.document.location);   
    var   sReturn   =   "";   
    var   sQUS   =   "?";   
    var   sAMP   =   "&";   
    var   sEQ   =   "=";   
    var   iPos;    
    iPos   =   sSource.indexOf(sQUS);      
    var   strQuery   =   sSource.substr(iPos,   sSource.length   -   iPos);   
    var   strLCQuery   =   strQuery.toLowerCase();   
    var   strLCName   =   sName.toLowerCase();     
    iPos   =   strLCQuery.indexOf(sQUS   +   strLCName   +   sEQ);   
    if   (iPos   ==   -1)   
    {   
        iPos   =   strLCQuery.indexOf(sAMP   +   strLCName   +   sEQ);   
        if   (iPos   ==   -1)   
        return   "";   
    }    
    sReturn   =   strQuery.substr(iPos   +   sName.length   +   2,strQuery.length-(iPos   +   sName.length   +   2));   
    var   iPosAMP   =   sReturn.indexOf(sAMP);     
    if   (iPosAMP   ==   -1)   
    return   sReturn;   
    else   
    {   
        sReturn   =   sReturn.substr(0,   iPosAMP);   
    }
    return   sReturn;   
}   
function InputCheck(name,message)
{
	if($(name).value == "")
	{
		alert(message);
		$(name).focus();
		return false;
	}
	return true;
}
function InputCheckStyle(name,message)
{
	if($(name).value == "")
	{
		ShowError(message);
		$(name).focus();
		return false;
	}
	return true;
}
function ImageCheckStyle(tag,message)
{	
	var name = document.getElementById(tag).value;	
	if(name == "")
	{		
		return true;
	}
	if(/^.+\.(gif|jpg|jpeg|png|bmp|tif)$/i.test(name.toLowerCase())) 
	{		
		return true;
	}
	else
	{	
	    ShowError(message);
	    document.getElementById(tag).focus();
		return false;
	}
}
//字符处理;
//去左右空格; 
function trim(s){
 	return rtrim(ltrim(s)); 
}
//去左空格; 
function ltrim(s){
 	return s.replace( /^\s*/, ""); 
} 
//去右空格; 
function rtrim(s){ 
 	return s.replace( /\s*$/, ""); 
}
//Email;
function isEmail(s){
	s = trim(s); 
 	var p = /^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.){1,4}[a-z]{2,3}$/i;
 	return p.test(s);
}
function EmailCheck(name,message)
{
    if($(name).value == "") return true;
	if(!isEmail($(name).value))
	{
	    alert(message);
	    $(name).focus();
	    return false;	    
	}
	return true;
}

//验证E-mail地址有效性
function isEmail(email)
{
    var emailReg = /^[-_A-Za-z0-9+.]+@([_A-Za-z0-9]+\.)+[A-Za-z0-9]{2,3}$/;
    return emailReg.test(email);
}
function HideEmail(Email)
{
	if(Email.indexOf("@") != -1)
	{
    	return Email.substring(0,Email.lastIndexOf("@"));
    }
    else
    {
    	return Email;
    }
}
    function GetCint(dbl_num, int_dig)
    {
        var dbl_temp = fixTo(dbl_num,int_dig);
        if (dbl_temp < dbl_num)
        {
            dbl_temp = fixTo(parseFloat(dbl_temp) + (1 / (Math.pow(10, int_dig))),int_dig);
        }
        
        return dbl_temp;
    }