﻿// JScript File

function _gel(a)
{
  return document.getElementById ? document.getElementById(a): null
}

function _gelstn(a)
{
  if (a == "*" && document.all)
    return document.all;
  return document.getElementsByTagName ? document.getElementsByTagName(a): []
}

function _uc(a)
{
  return a.toUpperCase();
}

function _trim(a)
{
  return a.replace(/(^\s*)|(\s*$)/g, "")
}

function _esc(a)
{
  return window.encodeURIComponent ? encodeURIComponent(a): escape(a)
}

var _unesc = function(a)
{
  return window.decodeURIComponent ? decodeURIComponent(a): unescape(a)
}

String.prototype.trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

String.prototype._startswith = function(t)
{
    var re = new RegExp("^" + t, "i");
    return re.test(this);
}

String.prototype._endswith = function(t)
{
    var re = new RegExp(t + "$", "i");
    return re.test(this);
}

function IsNullOrEmpty(a)
{
    if(a == null || a.trim() == "")
        return true;
    else
        return false;
}

function GetBrotherObj(o, id)
{
    for(var i=0; i<o.parentNode.childNodes.length; ++i)
    {
        var t = o.parentNode.childNodes[i];
        if(t.id == id)
            return t;
    }
    return null;
}

function GetBrotherObjByName(o, name)
{
    for(var i=0; i<o.parentNode.childNodes.length; ++i)
    {
        var t = o.parentNode.childNodes[i];
        if(t.name == name)
            return t;
    }
    return null;
}

function GetSonObj(o, id)
{
    for(var i=0; i<o.childNodes.length; ++i)
    {
        var t = o.childNodes[i];
        if(t.id == id)
            return t;
    }
    return null;
}

function GetSonObjByName(o, name)
{
    for(var i=0; i<o.childNodes.length; ++i)
    {
        var t = o.childNodes[i];
        if(t.name == name)
            return t;
    }
    return null;
}


function GetSonObjByTagNameAndType(o, name, type)
{
    for(var i=0; i<o.childNodes.length; ++i)
    {
        var t = o.childNodes[i];
        if(t.tagName == name && t.type == type)
            return t;
    }
    return null;
}


String.prototype.QueryString = function(key)
{
	var arr = this.match(new RegExp("[\?\&]" + key + "=([^\&]*)(\&?)", "i"));
        return arr ? arr[1] : arr;
}

function GetObjRectById(ctrlId)
{
    var o = document.getElementById(ctrlId)
    return GetObjRectByObject(o);
}  

function GetObjRectByObject(obj)
{
    var o = obj;
    var to = new Object();
    to.left = to.right = to.top = to.bottom = 0;
    to.width = to.height = 0;
    to.width = o.offsetWidth;
    to.height = o.offsetHeight;
    
    while(o && o != document.body)
    {
        if(o.tagName && o.tagName.toUpperCase()=="HTML") 
	    {
		    break;
	    }
        to.left += o.offsetLeft;
        to.top += o.offsetTop;
        o = o.offsetParent; 
    } 
    to.right = to.left + to.width; 
    to.bottom = to.top + to.height; 
    return to; 
}  

function _img_resize(imgself, width, display) 
{ 
    var tempimg = new Image(); 
    tempimg.src = imgself.src;
    if(tempimg.width > width) 
    { 
        imgself.width =  width;
    }
    else
    {
        imgself.width = tempimg.width;
    }
    if(display)
        imgself.style.display = 'block';
} 

function _create_cover_div(display)
{
     var divCover = document.createElement("div"); 
     divCover.innerHTML = "";
     if(display)
        divCover.style.display = "block"; 
     else
        divCover.style.display = "none"; 
     divCover.style.position = "absolute"; 
     divCover.style.width = '2000px';
     divCover.style.height = '2000px';
     divCover.style.left = '-200px'
     divCover.style.top = '-200px'
     divCover.style.backgroundColor = 'Teal';
     divCover.style.filter="alpha(opacity=80)"
     document.body.appendChild(divCover); 
     return divCover;
}
