/*
 * Copyright 1999-2007 by Vignette, Inc.,
 * All rights reserved.
 *
 * This software is the confidential and proprietary information
 * of Vignette, Inc. ("Confidential Information"). You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with Vignette.
 *
 */
function isdefined(variable)
{
    return (typeof(window[variable]) == "undefined") ? false : true;
}

function openWindow(url, myname, w, h, scroll, resize, dialog) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	var props = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable='+resize+',dialog='+dialog;
    if (isdefined("dynamicStartup")) {
        url = new VignettePortal.DynamicAJAXClient().parseRPIURL(url);
    }
	popupWin = window.open(url, myname, props);
	popupWin.focus();

	return popupWin;
}

   function scan() {
        var elems_length = document.add_form.elements.length;
        for (var i = 0; i < elems_length; i++) {
            var tmp = document.add_form.elements[i].name;
            if (tmp.indexOf('highlight_checkbox_')>-1) {
                if (document.add_form.elements[i].checked) {
                    highlightRow(document.add_form.elements[i]);
                } else {
		    resetRow(document.add_form.elements[i], i);
                }
            }
        }
	}

	function highlightRow(element) {
		while (element.tagName!="TR") {
			element=element.parentNode;
		}
		element.className = "epi-rowHighlight";
	}

	function resetRow(element, indexNumber) {
		while (element.tagName!="TR") {
			element=element.parentNode;
		}
		if (indexNumber % 2 == 0) {
			element.className = "epi-rowEven";
		} else {
			element.className = "epi-rowOdd";
		}
	}

    // expander code

    function flipEnd(imgname,toggle) {
        if (document.images) {
            var img = eval("document.images."+imgname);
            if (img) {
                if (toggle == "plusEnd") {
                    img.src=plusEnd.src;
                    img.title=plusEnd.title;
                } else {if (toggle == "minusEnd") {
                    img.src=minusEnd.src;
                    img.title=minusEnd.title;
                }
                }
            }
        }
    }

    // expand and collapse function
    function exploderEnd(){
        if (document.getElementById) {

            var imageName = arguments[0];
            var calsImage = document.getElementById(imageName);
            var isExploded = ( calsImage.src == minusEnd.src );

            if(isExploded) {
                flipEnd(imageName,"plusEnd");
            } else {
                flipEnd(imageName,"minusEnd");
            }

            for(var i = 1; i < arguments.length; i++ ) {
                var header = document.getElementById(arguments[i]);
                var head = header.style;
                    if(isExploded) {
                            head.display="none";
                    } else {
                            head.display="";
                    }
            }
        }
    }

	function goToURL() { //v3.0
        var i, args=goToURL.arguments;
        for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
	}

function getPortletScriptTag(UID,portletURL) {
	if (typeof(window["dynamicStartup"]) != "undefined") {
		portletURL = new VignettePortal.DynamicAJAXClient().parseRPIURL(portletURL,true);
	}
	portletURL = qualifyHREF(portletURL);
	var scriptID = "vgn_" +UID;
	var scriptTag = "<script type='text/javascript' id='"+ scriptID + "' src='" + portletURL + "'> <\/script>";
	return scriptTag;
}

var modalWin = null;
function getPortletPopUp(UID, actionURL, myname, w, h, scroll,resize) {
	if (typeof(window["dynamicStartup"]) != "undefined") {
		actionURL = new VignettePortal.DynamicAJAXClient().parseRPIURL(actionURL,true);
	}
	actionURL = qualifyHREF(actionURL);
	var array = new Array;
	array[0] = "vgn_" +UID;
	array[1] = actionURL;
	if (navigator.userAgent.toLowerCase().indexOf("firefox") == -1) {
		if (bw.ie) {
			showModalDialog("/portal/util/getPortletURL.jsp",array, "dialogWidth:400px; dialogHeight:265px; status:no; center:yes; help:no") ;
		} else {
			showModalDialog("/portal/util/getPortletURL.jsp",array, "dialogWidth:350px; dialogHeight:225px; status:no; center:yes; help:no") ;
		}
	} else {
		parentWindow = window;
		modalWin=openWindow("/portal/util/getPortletURL.jsp", myname, "400", h, scroll, resize, "yes");
		modalWin.dialogArguments=array;
		parentWindow.onfocus = function onFocus() {
			if (modalWin!=null && !modalWin.closed)
			{
				self.blur();
				modalWin.focus();
			}
		};
	}
}

