﻿//Trim系列函数(C#格式)提供如下：
String.prototype.LTrim = function()
{
    return this.replace(/^[\s]+/,"");
} 
String.prototype.RTrim = function()
{
    return this.replace(/[\s]+$/,"");
}
String.prototype.Trim = function()
{
    return this.LTrim().RTrim();
}
//判断字符串的长度，1个汉字占2字符
String.prototype.Len=function()
{
    return this.replace(/[^x00-xff]/g,"**").length;
}

function getobjectbrandname(brandname)
{
    var temp = brandname.split('└');
    if(temp.length >1)
    {
        return temp[1];
    }
    else
    {
        return temp[0];
    }
    
}

function $(strID)
{
    return document.getElementById(strID);
}

function ByName(strName)
{
    return document.getElementsByName(strName);
}

//判断html元素被选中的数量,以及全选all，反选reverse
function  SelectedCount(tagName,type,nameTag,selectType)
{
       
    var num = 0;  
    var objs = document.getElementsByTagName(tagName);
     
    for(var i=0;i<objs.length;i++)
    {
        if ((objs[i].type.toLowerCase() == type.toLowerCase()) && (objs[i].name.indexOf(nameTag) != -1))
        {
            if (objs[i].checked)
            {
                num = num + 1;
            }
            if(selectType!=undefined)
            {
                if(selectType=='all')
                {
                    objs[i].checked = true;
                }
                if(selectType=='reverse')
                {
                    if(objs[i].checked==true)
                    {
                        objs[i].checked=false;
                    }
                    else
                    {
                        objs[i].checked=true;
                    }
                }
            }
        }    
    }
    return num;　 
}

function OpenWindow(URL,width,height)
{
    window.open(URL,null,'height='+height+',width='+width+',location=no,scrollbars=no,status=no,menubars=no,toolbars=no');
}

//设置cookie
function SetCookie(sName, sValue, timeKeep)
{
	var now=new Date();
	var expireTime= new Date(now.valueOf()+timeKeep*60000*60);
	document.cookie = sName + "=" + sValue + "; path=/; expires=" + expireTime.toGMTString() + ";";
}
//读取cookie
function GetCookie(sName)
{
	var aCookie = document.cookie.split("; ");
	for (var i=0; i < aCookie.length; i++)
	{
		var aCrumb = aCookie[i].split("=");
		if (sName == aCrumb[0]) 
			return aCrumb[1];
	}
	return '';
}
//删除cookie
function DelCookie(sName)
{
    document.cookie = sName + "=" + sValue + "; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}

function getLeft(s)
{   
    var l=s.offsetLeft;  
    while(s=s.offsetParent)
    {   
        l+=s.offsetLeft;  
    }  
    return l;
}  

function getTop(s)
{   
    var t=s.offsetTop;  
    while(s=s.offsetParent)
    {   
        t+=s.offsetTop;  
    }  
    return t;
} 
//Object.prototype.addEvent = function (type, fn ) {  
//  if ( this.attachEvent ) {  
//    this['e'+type+fn] = fn;  
//    this[type+fn] = function(){this['e'+type+fn]( window.event );}  
//    this.attachEvent( 'on'+type, this[type+fn] );  
//  } else  
//    this.addEventListener( type, fn, false );  
//}  

  function   formatDate()   {   
  var   year=this.getYear();   
  var   month=this.getMonth()+1;   
  var   date=this.getDate();   
  var   hour=this.getHours();   
  var   minute=this.getMinutes();   
  var   second=this.getSeconds();   
  return   year+"-"+month+"-"+date+"   "+hour+":"+minute+":"+second;   
  }   
  Date.prototype.format=formatDate;   


function ClearForm() {
	var formObj = $(['aspnetForm']);
	var formEl = formObj.elements;
	for (var i=0; i<formEl.length; i++)
	{
		var element = formEl[i];
		if (element.type == 'submit') { continue; }
		if (element.type == 'reset') { continue; }
		if (element.type == 'button') { continue; }
		if (element.type == 'hidden') { continue; }

		if (element.type == 'text') { element.value = ''; }
		if (element.type == 'textarea') { element.value = ''; }
		if (element.type == 'checkbox') { element.checked = false; }
		if (element.type == 'radio') { element.checked = false; }
		if (element.type == 'select-multiple') { element.selectedIndex = -1; }
		if (element.type == 'select-one') { element.selectedIndex = -1; }
	}
}

document.getElementsByClassName = function(className,oBox) {
	//适用于获取某个HTML区块内部含有某一特定className的所有HTML元素
	var d= oBox || document;
	var children = d.getElementsByTagName('*');
	var elements = new Array();
	for (var i = 0; i < children.length; i++ ) {
		var child = children[i];
		var classNames = child.className.split(' ');
		for (var j = 0; j < classNames.length; j++ ) {
			if (classNames[j] == className) {
				elements.push(child);
				break;
			}
		}
	}
	return elements;
}

