
/***********************************************
* AnyLink Drop Down Menu- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var menuwidth='165px';			//default menu width
var disappeardelay=1000;		//menu disappear speed onMouseout (in miliseconds)
var hidemenu_onclick="yes";		//hide menu when user clicks within menu?
var LeftOffsetMargin = 15;

var ie4=document.all;
var ns6=document.getElementById&&!document.all;


//if(document.location.toString().indexOf("AdvancedSearch.aspx") >=0)
//{
	//menuwidth = '300px' // Flyttet tilIframe
	//disappeardelay=500;	
//}

//function DropDownPageClassHandler(obj,ev, url, style, Scrolling)

//As I am using classes here. Need to make sure that the classes I am using acctualy exists
function DropDownPageClassHandler(obj,ev, url, style, Scrolling, Width, Height)
{
		
	var html, sPos,sClass;
	sClass = " class='TxtBox" + Width + " FrameHeight" + Height + "' ";
	
	sPos = "";
    if(!compMode()) 
        sPos = "position: fixed;";
	
	menuwidth = "" + Width + "px";

	html = "<iframe  scrolling='" + Scrolling + "' src='" + url + "' style='background-color:white;border:1px solid black;" + sPos + "' " + sClass + " frameborder=0 ></iframe>";
	dropdownmenu(obj, ev, html, Width, Height, true);
	        
	return false;	
}

function DropDownPageClassHandler_NoIframe(obj,ev,html,Width, LeftOffset, PanelName)
{
    if(LeftOffset != null)
        LeftOffsetMargin = LeftOffset;
    if(Width != null)
        menuwidth = Width;
    
    
    
    /*
    if(!compMode()) 
    {
        var dropmenuobj=document.getElementById ? document.getElementById("dropmenudiv") : dropmenudiv;
        dropmenuobj.style.position = "fixed";
    }
    */
     
    dropdownmenu(obj, ev, html,null,null,null,PanelName);
}




//Handled by DropDownPageClassHandler
function ShowDropDownGetDate(obj,e,CallerID,SelectedDate)
{
	DropDownPageClassHandler(obj,e,"DropDownPage.aspx?action=selectdate&caller=" + CallerID + "&date=" + SelectedDate,'','no',185,175);
}

//Handled by DropDownPageClassHandler
function ShowDropDownPage(obj,e,did,rid)
{
    var docparam="";
	if(did > 0)
		docparam = "did=" + did;
	else if (rid > 0)
		docparam = "rid="+ rid;
	DropDownPageClassHandler(obj,e,"DropDownPage.aspx?action=newnote&" + docparam,'','no',280, 280);
}

//Handled by DropDownPageClassHandler
//ShowContent: 0 means show all. Else show according to notetype
function ShowNoteIframe(obj, e, id, EntityType, ShowContent)
{
	var entitykey="";
	if(EntityType == 1)
		entitykey="did";
	else if (EntityType == 5)
		entitykey="rid";
	else if (EntityType == 4)
		entitykey="uid";
	DropDownPageClassHandler(obj,e,"NotePopup.aspx?" + entitykey + "=" + id + "&show=" + ShowContent,'','yes',250,180);
	
}

//Helpfunction: Returns true if browser is IE, version less than 8.
function compMode() 
{
    if (navigator.appName == "Microsoft Internet Explorer") 
    {
        var bVersion = navigator.appVersion;
        if(bVersion.indexOf('MSIE') > -1) {
            var ptr = bVersion.indexOf('MSIE') + 5;
            var gf = parseFloat(bVersion.substring(ptr));
            if(gf < 8)
                return true;    // Compability mode...
        }
    }
    
    // No compability mode...
    return false;
}



if (ie4||ns6)
	document.write('<div id="dropmenudiv" style="visibility:hidden;width:' + menuwidth 
		 + '"; onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>');

function getposOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? (what.offsetLeft + LeftOffsetMargin) : what.offsetTop;
	
	var parentEl=what.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

function showhide(obj, e, visible, hidden, menuwidth){
	if (ie4||ns6)
		dropmenuobj.style.left=dropmenuobj.style.top=-500;
	if (menuwidth!=""){
		dropmenuobj.widthobj=dropmenuobj.style;
		dropmenuobj.widthobj.width=menuwidth;
	}
	if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
		obj.visibility=visible;
	else if (e.type=="click")
		obj.visibility=hidden;
}

function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

//DefaultContentmeasure is used because I have problems detecting content width in Firefox 
function clearbrowseredge(obj, whichedge, DefaultContentmeasure){
	var edgeoffset=0;
	var iContentMeasure;
	if (whichedge=="rightedge"){
		var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15;
		dropmenuobj.contentmeasure=dropmenuobj.offsetWidth;
		
		iContentMeasure = dropmenuobj.contentmeasure;
		if(DefaultContentmeasure >0)
			iContentMeasure = DefaultContentmeasure
	
		//alert("windowedge: " +windowedge);
		//alert("dropmenuobj.x: " +dropmenuobj.x);
		//alert("dropmenuobj.contentmeasure: " +dropmenuobj.contentmeasure);
		
		if (windowedge-dropmenuobj.x < iContentMeasure)
			edgeoffset = iContentMeasure + dropmenuobj.x - windowedge;
		
		if(edgeoffset > 0)
			if(navigator.appName != "Microsoft Internet Explorer") 
				edgeoffset = edgeoffset + 15; //Need som extra padding in Firefox
				
		//edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth;
		//alert("obj.offsetWidth: " +obj.offsetWidth);
		//alert("edgeoffset: " +edgeoffset);

	}
	else
	{
		var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18;
		dropmenuobj.contentmeasure=dropmenuobj.offsetHeight;
		
		iContentMeasure = dropmenuobj.contentmeasure;
		if(DefaultContentmeasure >0)
			iContentMeasure = DefaultContentmeasure
		
		if (windowedge-dropmenuobj.y < iContentMeasure)
			edgeoffset=iContentMeasure+obj.offsetHeight;
		
		//if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
		//	edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight;
	}
	return edgeoffset;
}

function populatemenu(what){
	if (ie4||ns6)
	{
		dropmenuobj.innerHTML=what;
		MenuDroppedDownCallBackLocal();
	}
}

function MenuDroppedDownCallBackLocal() {

    if(parent.location.toString().toLowerCase().indexOf("tree.aspx") >= 0)
        parent.calcIFrameHeight();
    else
        return false;
}

function dropdownmenu(obj, e, menucontents, DropDownWidth, DropDownHeight, CalledFromMainHandler, PanelName){

	var o = document.getElementById("dropmenudiv");
    if(o!=null)
    {
	    if(CalledFromMainHandler) 
            o.style["border"] = "0px solid black"; //Setter bredde til 0 på border siden jeg viser border på iframe nedenfor.
        else
            o.style["border"] = "1px solid black"; //Setter bredde til 1 på border hvis ikke vises i iframe.
	}
	
	
	//DropDownHeight and DropDownWidth are used so that I dont have to calculate these values. 
	//Calculating values caused a problem in Firefox. 
	//Values are used when I'm trying to clear browser edge.
	if(!DropDownHeight)
		DropDownHeight = -1;
	if(!DropDownWidth)
		DropDownWidth = -1;	
	
	if (window.event) 
		event.cancelBubble=true;
	else if (e.stopPropagation) 
		e.stopPropagation();

	clearhidemenu();
	dropmenuobj=document.getElementById ? document.getElementById("dropmenudiv") : dropmenudiv;
	populatemenu(menucontents);
	if (ie4||ns6){
		showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth);
						
		dropmenuobj.x = getposOffset(obj, "left");
		dropmenuobj.y = getposOffset(obj, "top");
        
        
        var l = dropmenuobj.x - clearbrowseredge(obj, "rightedge", DropDownWidth);
		var t = dropmenuobj.y - clearbrowseredge(obj, "bottomedge", DropDownHeight)+obj.offsetHeight;
		if(l<10)
		    l = 10;
		if(t<10)
		    t = 10;

       
		if(!compMode()) 
		{
		    var o; 		    
		    if(PanelName != null)
                o = document.getElementById(PanelName);
		    else //TODO GGGGGG - Endre til inputverdier
		    {
		        o = document.getElementById("ResDocListDiv");//If called from ResDoc.aspx page. Should probably get this as input value instead.
		        if(o == null)
		            o = document.getElementById("DocListDiv");//If called from ListDoc.aspx page. Should probably get this as input value instead.
		    }
		    

            if(o != null)
                t = t - o.scrollTop;

            //TODO GGGGGG - Finn ut hvor denne var ment å skulle være med. Dersom jeg tar den med får jeg problemer med tree.aspx og DropDown på [i]
            //else 
		    //    t = t - (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);	
        }
        
        dropmenuobj.style.left = l + "px";
		dropmenuobj.style.top = t + "px";
        
		//dropmenuobj.style.left = dropmenuobj.x -clearbrowseredge(obj, "rightedge", DropDownWidth)+"px";
		//dropmenuobj.style.top = dropmenuobj.y-clearbrowseredge(obj, "bottomedge", DropDownHeight)+obj.offsetHeight+"px";

		MenuDroppedDownCallBackLocal();
	}
	return clickreturnvalue();
}

function clickreturnvalue(){
	if (ie4||ns6) return false;
		else return true;
}

function contains_ns6(a, b) {
	while (b && b.parentNode)
		if ((b = b.parentNode) == a)
			return true;
	return false;
}

function dynamichide(e){
	if (ie4&&!dropmenuobj.contains(e.toElement))
		delayhidemenu()
	else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
		delayhidemenu()
}

function hidemenu(e){
	if (typeof dropmenuobj!="undefined"){
		if (ie4||ns6)
			dropmenuobj.style.visibility="hidden"
	}
}

function delayhidemenu(){
	var tmpDisappearDelay = disappeardelay; //If this is not from DropDownPage.aspx use default
	
	try
	{
		if(dropmenuobj.innerHTML.indexOf("DropDownPage.aspx?action=newsearch") >=0)
			tmpDisappearDelay=60000;
		else if(dropmenuobj.innerHTML.indexOf("DropDownPage.aspx?action=taskconnect")>=0)
			tmpDisappearDelay=5000;
		else if(dropmenuobj.innerHTML.indexOf("DropDownPage.aspx?action=newnote")>=0)
			tmpDisappearDelay=60000;
		/*
		else if(dropmenuobj.innerHTML.indexOf("DropDownPage.aspx?action=addtext")>=0)
			tmpDisappearDelay=30000;
		*/
		else if(dropmenuobj.innerHTML.indexOf("DropDownPage.aspx?action=forwardtask")>=0)
			tmpDisappearDelay=15000;	
		else if(dropmenuobj.innerHTML.indexOf("DropDownPage.aspx?action=selectdate")>=0)
			tmpDisappearDelay=2500;	
		else if(dropmenuobj.innerHTML.indexOf("DropDownPage.aspx?action=dontsigndocument")>=0)
			tmpDisappearDelay=10000;	
		else if(dropmenuobj.innerHTML.indexOf("DropDownPage.aspx?action=signdocument")>=0)
			tmpDisappearDelay=0;	
		else if(dropmenuobj.innerHTML.indexOf("DisappearDelay=")>=0)
		{
			var s = dropmenuobj.innerHTML.substring(dropmenuobj.innerHTML.indexOf("DisappearDelay=") + 15);
			s = s.substring(0,s.indexOf("s"));
			tmpDisappearDelay = parseInt(s) *1000;
		}
		if(dropmenuobj.innerHTML.indexOf("HideMenu=no")>=0)
			document.onclick="";		
	}
	catch(err)
	{}
	
	if (ie4||ns6)
		if(tmpDisappearDelay>0)
			delayhide=setTimeout("hidemenu()",tmpDisappearDelay)
}

function clearhidemenu()
{
	if (typeof delayhide!="undefined")
		clearTimeout(delayhide);
}

if (hidemenu_onclick=="yes")
	document.onclick=hidemenu;
		
/*DYNAMIC PART*/	

var ekw_xmlhttp2, ekw_alert2, ekw_url;
 /*@cc_on @*//*@if (@_jscript_version >= 5);try{ekw_xmlhttp2=new ActiveXObject("Msxml2.XMLHTTP")}catch(e){try {ekw_xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP")}catch(E){}};@else;ekw_xmlhttp2=false;ekw_alert2=true;@end @*/
if (!ekw_xmlhttp2 && !ekw_alert2){ try { ekw_xmlhttp2 = new XMLHttpRequest(); }catch(e){}}

function ekw_rsc() {
	if (ekw_xmlhttp2.readyState == 4)
		{
			populatemenu(ekw_xmlhttp2.responseText);
		}
	}
function ekw_t24(){
	if(ekw_xmlhttp2)	{
		ekw_xmlhttp2.open("GET", ekw_url, true);
		ekw_xmlhttp2.onreadystatechange=ekw_rsc;
		ekw_xmlhttp2.send(null);
	}
}
