
/* === CONFIRMATIONS === */

// confirm deletion of item:
function confirmDelete(formObj, item) {
    if (formObj.deleted.checked) {
        return confirm("Are you sure you want to delete this " + item + "?");
    } else {
        return true;
    }
}


/* === POPUPS === */

    function popup(cPopUrl, cPopName, iPopWidth, iPopHeight, bScrollBars, resizable) {
    	var iPopLeft, iPopTop;
    	var oPopWindow = null;
    	if (!oPopWindow || oPopWindow.closed){
    		//Center popup window inside parent window.
    		iPopLeft = (window.screen.width/2) - ((iPopWidth/2) + 10);
    		iPopTop = (window.screen.height/2) - ((iPopHeight/2) + 50);
    		//Open popup window
    		oPopWindow=open(cPopUrl, cPopName,"height="+ iPopHeight +",width="+ iPopWidth +",left=" + iPopLeft + ",top=" + iPopTop + ",screenX=" + iPopLeft + ",screenY=" + iPopTop + ",scrollbars=" + bScrollBars + ",resizable=" + resizable + ", status=yes");
    		oPopWindow.location.href = cPopUrl;
    		oPopWindow.focus()
        } else {
        	oPopWindow.focus()
    	}
    }


/* === XHTML COMPATABILITY === */

    onLoadFuncs = new Array();
    function addOnLoad(func){
    	onLoadFuncs[onLoadFuncs.length] = func;
    }
    function runOnLoad(){
    	for(i in onLoadFuncs){
    		eval(onLoadFuncs[i]+"()");
    	}
    }
    window.onload = runOnLoad;

    function handleExternalLinks() {
    	var anchors = document.getElementsByTagName("a");
    	var i, href;
    	for(i=0; i < anchors.length; i++){
    		if(!anchors[i].href) continue;
    		href = anchors[i].href;

    		if(href.indexOf("beyondsecond.") == -1 && href.indexOf("localhost") == -1 && href.indexOf("b2.") == -1){ // Href is not a file on my server
    			if(href.indexOf("javascript:") == -1){ // Href is not a javascript call
    				if(!anchors[i].onclick){ // Href does not have an onclick event
    					if(href.indexOf("mailto:") == -1){ // Href is not a mailto:
    						if(href.indexOf("http://") != -1 || href.indexOf("https://") != -1) { // Href is not relative (for Safari)
    							anchors[i].setAttribute("target","_blank");
    						}
    					}
    				}
    			}
    		}

    		// things that must open in a new browser window.
    		if (href.indexOf(".pdf") > 0 && href.indexOf("download.php?file") <= 0) anchors[i].setAttribute("target","_blank");
    		if (anchors[i].getAttribute("rel") == "external") anchors[i].setAttribute("target","_blank");

    	}
    }

    if(document.getElementsByTagName){
    	addOnLoad("handleExternalLinks");
    }

/* === LOGIN === */

    function login_validate(formObj) {
        //add validation;
        formObj.submit();
    }
