/*
 * File           : $Header: //depot/projects/hallingdolen/hallingdolen-publication/src/main/webapp/template/version/javascript/show-hide-div.js#1 $
 * Last edited by : $Author: Iftikhar Ul Hassan $ $Date: 2008/03/12 $
 * Version        : $Revision: #1 $
 *
 * Copyright (C) 2007 Escenic AS.
 * All Rights Reserved.  No use, copying or distribution of this
 * work may be made except in accordance with a valid license
 * agreement from Escenic AS.  This notice must be included on
 * all copies, modifications and derivatives of this work.
 */

function hideDiv(divId) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(divId).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.divId.display = 'none';
		}
		else { // IE 4
			document.all.divId.style.display = 'none';
		}
	}
}

function showDiv(divId) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(divId).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.divId.display = 'block';
		}
		else { // IE 4
			document.all.divId.style.display = 'block';
		}
	}
}

function isDivHidden(divId) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		return (document.getElementById(divId).style.display == 'none');
	}
	else {
		if (document.layers) { // Netscape 4
			return (document.divId.display == 'none');
		}
		else { // IE 4
			return (document.all.divId.style.display == 'none');
		}
	}
}

function showHideDiv(divId) {
	if(isDivHidden(divId)) {
		 showDiv(divId);
	}
	else {
		 hideDiv(divId);
	}
}

function showHideComments(showHideCommentsDivId,showHideCommentsLinkId,
                          showAllCommentsLinktext,showLatestCommentsLinktext) {
  if(isDivHidden(showHideCommentsDivId)) {
    showDiv(showHideCommentsDivId);
    var showHideCommentsLink = document.getElementById(showHideCommentsLinkId);
    showHideCommentsLink.innerHTML=showLatestCommentsLinktext;
  }
  else {
    hideDiv(showHideCommentsDivId);
    var showHideCommentsLink = document.getElementById(showHideCommentsLinkId);
    showHideCommentsLink.innerHTML=showAllCommentsLinktext;
  }
}

function showHidePostings(postingDivId, postingTitleLinkId, arrowDownImageUrl, arrowRightImageUrl) {
  var postingTitleLink = document.getElementById(postingTitleLinkId);
  if(isDivHidden(postingDivId)) {
    showDiv(postingDivId);
    postingTitleLink.style.backgroundImage="url("+ arrowDownImageUrl+")";
  }
  else {
    hideDiv(postingDivId);
    postingTitleLink.style.backgroundImage="url("+ arrowRightImageUrl+")";
  }
}

/*Adding code for show divs as popups*/
var cX = 0;
var cY = 0;
var rX = 0;
var rY = 0;
function UpdateCursorPosition(e) {
    cX = e.pageX;
    cY = e.pageY;
}
function UpdateCursorPositionDocAll(e) {
    cX = event.clientX;
    cY = event.clientY;
}
if (document.all) {
    document.onmousemove = UpdateCursorPositionDocAll;
}
else {
    document.onmousemove = UpdateCursorPosition;
}
function AssignPosition(d) {
    if (self.pageYOffset) {
        rX = self.pageXOffset;
        rY = self.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop) {
        rX = document.documentElement.scrollLeft;
        rY = document.documentElement.scrollTop;
    }
    else if (document.body) {
            rX = document.body.scrollLeft;
            rY = document.body.scrollTop;
        }
    if (document.all) {
        cX += rX;
        cY += rY;
    }
    d.style.left = (cX + 20) + "px";
    d.style.top = (cY + 10) + "px";
}
function HideContent(d) {
    if (d.length < 1) {
        return;
    }
    document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
    if (d.length < 1) {
        return;
    }
    var dd = document.getElementById(d);
    AssignPosition(dd);
    dd.style.display = "block";
}
function ReverseContentDisplay(d) {
    if (d.length < 1) {
        return;
    }
    var dd = document.getElementById(d);
    AssignPosition(dd);
    if (dd.style.display == "none") {
        dd.style.display = "block";
    }
    else {
        dd.style.display = "none";
    }
}
