String.prototype.trim = function() {return this.replace(/^\s+|\s+$/g,"");}			// trim both sides
String.prototype.ltrim = function() {return this.replace(/^\s+/,"");}				// trim left side
String.prototype.rtrim = function() {return this.replace(/\s+$/,"");}				// trim right side
String.prototype.isEmpty = function() {return (this==null||this.value==null||this.length==0);}		// check if the value is an empty string or null
String.prototype.empty = function() {this.value = EMPTY_STRING; }

var POS_LEFT        = 0;
var POS_TOP         = 1;
var popUpsBlocked   = true;
var EMPTY_STRING	= "";

CheckPops();

function CheckPops(){
    //var win = window.open('','','width=1,height=1,left=0,top=0,scrollbars=no');
    //if(win){popUpsBlocked = false;} win.close();
}

function FindElement(tag, name){
	var l = document.getElementsByTagName(tag);
	var e = null;
	for (var i=0;i<l.length;i++){
		if (l[i].id.toLowerCase().indexOf(name.toLowerCase())!=-1){
			e = l[i];
			break;
		}
	}
	return e;
}

function FindElementsByName(tag, name, parent){
    var l = parent.getElementsByTagName(tag);
	var aE = new Array();
	var ct = 0;
	for (var i=0;i<l.length;i++){
		if (l[i].name.toLowerCase().indexOf(name.toLowerCase())!=-1){
			aE[ct]=l[i];
			ct++;
		}
	}
	return aE;
}

function switchIt(e, flag)
{
	if (e.tagName=="A"||e.tagName=="a")	
	{
		if (flag)		
			e.childNodes[0].src = e.childNodes[0].src.replace("btn", "btnOn");
		else
			e.childNodes[0].src = e.childNodes[0].src.replace("btnOn", "btn");	
	}
	else
	{
		if (flag)
			e.src = e.src.replace("btn", "btnOn");
		else
			e.src = e.src.replace("btnOn", "btn");
	}
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return [curleft,curtop];
}

function findRelativePos(obj, objParent) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop		
		
		while (obj = obj.offsetParent) {
		    if (obj.id == objParent.id) {break;}
		    curleft += obj.offsetLeft;
    		curtop += obj.offsetTop;					
		}
	}
	return [curleft,curtop];
}

function ShowPopMsg(msgType, html, relElement)
{
	var eStatus		= FindElement("div", WIN_POP_STATUS);
	var eMessage	= FindElement("div", CLS_POP_MESSAGE);
	var h = relElement.offsetHeight;
	var w = relElement.offsetWidth;
	var pos = findPos(relElement);
	var l = pos[0];
	var t = pos[1];
	var tPos = ((h/2)-85)+t;
	var lPos = ((w/2)-150)+l;	
	eStatus.style.left = lPos;
	eStatus.style.top = tPos;
	eMessage.innerHTML = html;
	eStatus.className = MSG_CLASSES[msgType] +" "+ CLS_POP_POS;	

}

function HidePopMsg()
{
	var e = FindElement("div", WIN_POP_STATUS);
	e.className = "Hide";
}

function GridHover(e, isHover)
{
    e.className = "GridRow";
    if(isHover)
        e.className+=" GridHover";
}

function PopImage(path, label, width, height)
{
    window.open("ShowImage.aspx?pop="+path+"&label="+label, "ImagePop", "height=600, width=800, status=1, toolbar=0, menubar=0, location=0, resizable=1, scrollbars=1");
}

function PreviewImage(path, width, height)
{

}

