function getCookie(name) {    var arg = name + "=";    var alen = arg.length;    var clen = document.cookie.length;    var i = 0;    while (i < clen) {        var j = i + alen;        if (document.cookie.substring(i, j) == arg) {            return getCookieVal(j);        }        i = document.cookie.indexOf(" ", i) + 1;        if (i == 0)break;    }    return null;}function getCookieVal(offset) {    var endstr = document.cookie.indexOf(";", offset);    if (endstr == -1) {        endstr = document.cookie.length;    }    return unescape(document.cookie.substring(offset, endstr));}function setCookie(name, value, expires, path, domain, secure) {    document.cookie = name + "=" + escape(value) +                      ((expires) ? "; expires=" + expires : "") +                      ((path) ? "; path=" + path : "") +                      ((domain) ? "; domain=" + domain : "") +                      ((secure) ? "; secure" : "");}function trashcan_init (xmlHttpReq) {var addDiv = document.createElement("div");var arrow1 = new Image();var arrow2 = new Image();arrow1.src = this.imagePath + "/arrows/01_down.gif";arrow2.src = this.imagePath + "/arrows/01_right.gif";var body = document.getElementsByTagName("body")[0];if (this.loadingImage) {body.removeChild(this.loadingImage);this.loadingImage = null;}addDiv.style.textAlign = "left";addDiv.style.zIndex = "9";addDiv.style.position = "relative";addDiv.innerHTML = xmlHttpReq.responseText;//		body.insertAfter(addDiv, body.childNodes[body.childNodes.length - 1]);body.insertBefore(addDiv, body.childNodes[0]);this.menu = document.getElementById(this.ppid + "_content");if (this.menu != null) {/*yPos = window.screen.height / 2 - 150;xPos = window.screen.width / 2 - 150;this.menu.style["top"] = yPos + "px";this.menu.style["left"] = xPos + "px";*/var list = this.menu.childNodes;for (var i = 0; i < list.length; i++) {if (list[i].className != null && list[i].className.match("portal-add-content")) {this.menuDiv = list[i];}if (list[i].nodeName != null && list[i].nodeName.toLowerCase().match("iframe")) {this.menuIframe = list[i];}}var elems = this.menu.getElementsByTagName("div");			Drag.makeDraggable(this.menu);this.menu.ppid = this.ppid;this.menu.onDragEnd = trashcan_onDragEnd;this.initialized = true;this.toggle();}}function trashcan_onDragEnd (nwPosition, sePosition, nwOffset, seOffset) {        setCookie(this.ppid + "-yPos", nwOffset.y, "", "/");setCookie(this.ppid + "-xPos", nwOffset.x, "", "/");    }function trashcan_toggle (ppid, plid,  mainPath, imagePath) {        var menu = document.getElementById(this.ppid + "_content");        if (!this.initialized) {            this.imagePath = imagePaththis.loadingImage = document.createElement("div");var image = document.createElement("img");this.loadingImage.className = "portal-add-content";this.loadingImage.style.position = "absolute";this.loadingImage.style.top = document.getElementsByTagName("body")[0].scrollTop + "px";this.loadingImage.style.left = "0";this.loadingImage.style.zIndex = "9";image.src = this.imagePath + "/progress_bar/loading_animation.gif";this.loadingImage.appendChild(image);document.getElementsByTagName("body")[0].appendChild(this.loadingImage);            loadPage(mainPath + "/portal/render_portlet", "p_p_id=" + this.ppid + "&p_l_id=" + plid, this.returnPortlet);}else {            if (this.menu.style.display == "none") {//				yPos = document.getElementsByTagName("body")[0].scrollTop;//				this.menu.style["top"] = yPos + "px";                yPos = getCookie(this.ppid + "-yPos");                if(!yPos) {yPos = window.screen.height / 2 - 150;}xPos = getCookie(this.ppid + "-xPos");                if(!xPos) {xPos = window.screen.width / 2 - 150;if(this.ppid == "trashcan") {xPos = xPos + 170;} else {xPos = xPos - 170;}}//                log.error("yPos : " + yPos);//                log.error("xPos : " + xPos);                this.menu.style["top"] = yPos + "px";this.menu.style["left"] = xPos + "px";this.menu.style.display = "block";this.menu.style.zIndex = "9";this.resize();                setCookie(this.ppid.substring(0,2) + "_e", "true", "", "/");//                log.error("set cookie" + getCookie("cl_e"));            }else {this.menu.style.display = "none";setCookie(this.ppid.substring(0,2) + "_e", "false", "", "/");}}}function trashcan_resize () {if (this.menuIframe != null) {this.menuIframe.height = this.menuDiv.offsetHeight;this.menuIframe.width = this.menuDiv.offsetWidth;}}var Trashcan = {imagePath : "",initialized : false,loadingImage : null,menu : null,menuDiv : null,menuIframe : null,ppid : "trashcan",returnPortlet : function (xmlHttpReq) {    Trashcan.init(xmlHttpReq);},pageLoaded : function(plid,  mainPath, imagePath) {        var trashcan_enabled = getCookie("tr_e");        if(trashcan_enabled && (trashcan_enabled == "true")) {Trashcan.toggle('trashcan', plid, mainPath, imagePath);}        var clipboard_enabled = getCookie("cl_e");//        log.error("clipboard_enabled" + clipboard_enabled);        if(clipboard_enabled && (clipboard_enabled == "true")) {Clipboard.toggle('clipboard', plid, mainPath, imagePath);}        var layoutPortlet_enabled = getCookie("la_e");if(layoutPortlet_enabled && (layoutPortlet_enabled == "true")) {LayoutPortlet.toggle('layoutPortlet', plid, mainPath, imagePath);}    }};var Clipboard = {imagePath : "",initialized : false,loadingImage : null,menu : null,menuDiv : null,menuIframe : null,ppid : "clipboard",returnPortlet : function (xmlHttpReq) {    Clipboard.init(xmlHttpReq);    var column = document.getElementById("clipboard_content");if (column) {column.columnId = "column-clipboard";column.nextContainer = DragDrop.firstContainer;column.previousContainer = null;DragDrop.firstContainer.previousContainer = column;DragDrop.firstContainer = column;}	    }};var LayoutPortlet = {imagePath : "",initialized : false,loadingImage : null,menu : null,menuDiv : null,menuIframe : null,ppid : "layoutPortlet",returnPortlet : function (xmlHttpReq) {    LayoutPortlet.init(xmlHttpReq);	       }};Trashcan.init = trashcan_init;Trashcan.toggle = trashcan_toggle;Trashcan.resize = trashcan_resize;Trashcan.onDragEnd = trashcan_onDragEnd;Clipboard.init = trashcan_init;Clipboard.toggle = trashcan_toggle;Clipboard.resize = trashcan_resize;Clipboard.onDragEnd = trashcan_onDragEnd;LayoutPortlet.init = trashcan_init;LayoutPortlet.toggle = trashcan_toggle;LayoutPortlet.resize = trashcan_resize;LayoutPortlet.onDragEnd = trashcan_onDragEnd;
