String.prototype.trim=function(){
    return this.replace(/(^\s*)|(\s*$)/g,"");
}

function $(){
    var elements = new Array();
    for (var i = 0; i < arguments.length; i++) {
        var element = arguments[i];
        if (typeof element == 'string')
            element = document.getElementById(element);
        if (arguments.length == 1)
            return element;
        elements.push(element);
    }
    return elements;
}

function isHex(num){
    return num.match(/^(0x)?[0-9a-f]+$/ig);
}

function ShowDialog(url,width,height,arg,modeless){
    if(navigator.appName.indexOf("Explorer")>-1){
        if(modeless){
            return showModelessDialog(url,arg,"dialogWidth:" + width + "px;dialogHeight:" + height + "px;help:no;scroll:yes;resizable:0;status:no");
        }
        else{
    	    return showModalDialog(url,arg,"dialogWidth:" + width + "px;dialogHeight:" + height + "px;help:no;scroll:yes;resizable:0;status:no");
        }  
    }
    else{
        return null;
    }
}

function GetAbsoluteId(codeId){
    if (codeId == null)return "";
    if (codeId.length % 2 == 1) codeId += "0";
    var sb="";
    for (var i = 0; i < codeId.length; i += 2)
    {
        var tmpstr = codeId.substr(i, 2);
        if (tmpstr!="00")
        {
            sb+=tmpstr;
        }
    }
    return sb;
}

function ShowWindow(url,winname,width,height,top,left){
    if(!top)top=0.5;
    if(!left)left=0.5;
    if(top<=1)top=(window.screen.availHeight-height)*top;
    if(left<=1)left=(window.screen.availWidth-width)*left;
    window.open(url,winname,"width=" + width + ",height=" + height + ",top=" + top + ",left=" + left + ",toolbar=no,menubar=no,resizable=no,location=no,status=no");
}

function getOffsetTop(elm) {
	var mOffsetTop = elm.offsetTop;
	var mOffsetParent = elm.offsetParent;
	while(mOffsetParent){
		mOffsetTop += mOffsetParent.offsetTop;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	return mOffsetTop;
}

function getOffsetLeft(elm) {
	var mOffsetLeft = elm.offsetLeft;
	var mOffsetParent = elm.offsetParent;
	while(mOffsetParent) {
		mOffsetLeft += mOffsetParent.offsetLeft;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	return mOffsetLeft;
}

function addEvent(obj,evtType,func,cap){
    cap=cap||false;
	if(obj.addEventListener){
	    obj.addEventListener(evtType,func,cap);
		return true;
	}else if(obj.attachEvent){
        if(cap){
	        obj.setCapture();
	        return true;
	    }else{
		    return obj.attachEvent("on" + evtType,func);
		}
	}else{
		return false;
    }
}
function removeEvent(obj,evtType,func,cap){
    cap=cap||false;
	if(obj.removeEventListener){
		obj.removeEventListener(evtType,func,cap);
		return true;
	}else if(obj.detachEvent){
	    if(cap){
	        obj.releaseCapture();
	        return true;
		}else{
		    return obj.detachEvent("on" + evtType,func);
		}
	}else{
		return false;
    }
}

function getPageScroll(){
    var xScroll,yScroll;

	if (self.pageXOffset) {
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollLeft){
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {
		xScroll = document.body.scrollLeft;
	}

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array(xScroll,yScroll);
	return arrayPageScroll;
}

function CheckAll(IsChk,pid,newcmd){
	var inputs;
	if(pid){
	    inputs=document.getElementById(pid).getElementsByTagName("input");
	}
	else{
	    inputs=document.getElementsByTagName("input");
	}
	if(newcmd){
	    newcmd=newcmd.replace("{0}","inputs[i]").replace("{1}","IsChk");
	}else{
	    newcmd="";
	}
	for(i=0;i<inputs.length;i++){
	    if(inputs[i].getAttribute("type").toLowerCase()=="checkbox"){
	        inputs[i].checked=IsChk;
	        eval(newcmd);
	    }
	}
}

function GetPageSize(){
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY) {	
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else {
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
    var windowWidth, windowHeight;
    if (self.innerHeight) {
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) {
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }	
    if(yScroll < windowHeight){
        pageHeight = windowHeight;
    } else { 
        pageHeight = yScroll;
    }
    if(xScroll < windowWidth){	
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }
    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
    return arrayPageSize;
}

function CommonDown(id,sp,type){
    $("BlankFrame").src = sp + "Down.aspx?" + type + "=" + id;
    return false;
}

function LocationGo(url){
    location.href=url;
    return;
}
