
var OBJ_SELECT = "_sel";
var OBJ_HIGHLIGHT = "_hgh";

function openWindow(url,height,width,title,top,left,scroll,status,resizable) {
	left = (left)? left :  parseInt((window.screen.width - width)/2);
	top = (top)? top : parseInt((window.screen.height - height)/2);
	title = (title)? title : "popUp";
	scrollBar = (scroll) ? ",scrollbars=yes" : "";
	statusBar = (status) ? ",statusbar=yes" : "";
	resizable = (resizable) ? ",resizable=yes" : "";
	params = "height="+height+",width="+width+",left="+left+",top="+top + scrollBar +statusBar +resizable;
	newWin = window.open(url,title,params);
	newWin.focus();
	return newWin;
}

function reloadOpener(checkPage) {
    if (window.opener) {
        if (checkPage) {
            if (window.opener.location.toString().indexOf(checkPage) == -1)
                return;
        }
        window.opener.location.reload();
    }
}

function openPolicy(page) {

	//if (isIE)
		page = "/" + page;
    openWindow(page,400,550,"policy");
}

function openWin(page) {
    openWindow(page,400,563,"popup",false,false,true);
}

function closeWindow(refresh) {
	if (window.opener) {
	    if (refresh)
	        window.opener.location.reload();
		window.opener.focus();
    }
	window.close();
}

function isIE() {
	return (navigator.appName.indexOf("Microsoft"));
}

function getObj(objName) {
	return document.getElementById(objName);
}

function showLayer(obj) {
	if (typeof(obj) == "string")
		obj = getObj(obj);
	obj.style.display = "";
}

function hideLayer(obj) {
	if (typeof(obj) == "string")
		obj = getObj(obj);
	obj.style.display = "none";
}

function toggleLayer(show,hide) {
	showLayer(show);
	hideLayer(hide);
}

function returnPosition(obj) {
	var retVal = new Object();
	retVal.x = 0;
	retVal.y = 0;	
	while (obj) {
		retVal.x += obj.offsetLeft;
		retVal.y += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return retVal;
}

function trim(str,frontOnly) {
	while (str.substr(0,1) == " ")
		str = str.substring(1,str.length)
	if (!frontOnly) {
		while (str.substr(str.length-1,1) == " ")
			str = str.substring(0,str.length-1)
	}
	return str;
}

function stripImgTag(imgObj,clearSelect) {
	notSelected = (imgObj.src.indexOf(OBJ_SELECT) == -1 || clearSelect);
	if (imgObj.src.indexOf("_") != -1 && notSelected)
		imgObj.src = imgObj.src.substring(0,imgObj.src.indexOf("_")) + ".gif";
}

function addImgTag(imgObj,tag) {
	if (imgObj.src.indexOf(OBJ_SELECT) != -1) return;
	stripImgTag(imgObj)
	imgObj.src = imgObj.src.substring(0,imgObj.src.indexOf(".gif")) + tag + ".gif";
}

function stripClassName(obj,clearSelect) {
	notSelected = (obj.className.indexOf(OBJ_SELECT) == -1 || clearSelect);
	if (obj.className.indexOf("_") != -1 && notSelected)
		obj.className = obj.className.substring(0,obj.className.indexOf("_"));
}

function addClassName(obj,tag) {
	if (obj.className.indexOf(OBJ_SELECT) != -1) return;
	stripClassName(obj)
	obj.className = obj.className + tag;
}

function isEmpty(str,checkWhitespace) {
	if (!str || str.length == 0)
		return true;
	if (checkWhitespace)
		return (trim(str) == "")
	return false;	 
}

function showInfo(msg,type) {
	infoObj = getObj("infoLayer");
	if (!infoObj || !msg) return;
	if (type == "error") {
		infoObj.className = "errorText";
		msg = "<img src=\"images/iconError.gif\" valign=\"vertical-align:text-top;\"> <span class=\"errorText\">" + msg + "</span>";
	} else if (type == "info") {
		msg = "<img src=\"img/icon/info.gif\" style=\"vertical-align:text-top;\"> " + msg;
		setTimeout("clearInfo()",4000);
	}
	infoObj.innerHTML = msg;
}

function clearInfo() {
    infoObj = getObj("infoLayer");
    infoObj.innerHTML = "";
}

function setSelect(fieldObj,value) {
    if (fieldObj) {
        for (i=0;i<fieldObj.length;i++) {
            if (fieldObj.options[i].value == value)
                fieldObj.options[i].selected = true;
        }
    }
}
