﻿// JScript 文件
//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元素被选中的数量
function  SelectedCount(tagName,type,nameTag)
{
       
    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;
            }
        }    
    }
    return num;　 
}

//设置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 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; }
	}
}

function OpenWindow(URL,width,height)
{
    window.open(URL,null,'height='+height+',width='+width+',location=no,scrollbars=no,status=no,menubars=no,toolbars=no');
}
