
// ------------------------------------------------------------
// Global variables
// ------------------------------------------------------------
var gArticleRows = new Array();


function adaptStartPageDivs()
{
	var right = document.getElementById('rightAreaStartPage');
	var left = document.getElementById('leftAreaStartPage');
	if(right && left)
	{
		if(right.clientHeight > left.clientHeight)
		{
			left.style.height = right.clientHeight + 'px';
		}
		else if(left.clientHeight > right.clientHeight)
		{
			right.style.height = left.clientHeight + 'px';
		}
	}
}
function adaptDivs()
{
	var IDs = document.getElementById('hiddenClientIDs').value.split(';');
	var left = document.getElementById(IDs[0]);
	var center = document.getElementById(IDs[1]);
	var right = document.getElementById(IDs[2]);
	
	var height = 0;
	if(left)
	{
		if(left.clientHeight > height)
		{
			height = left.clientHeight;
		}
	}
	if(center)
	{
		if(center.clientHeight > height)
		{
			height = center.clientHeight;
		}
	}
	if(right)
	{
		if(right.clientHeight > height)
		{
			height = right.clientHeight;
		}
	}
	if(left)
		left.style.height = height + 'px';
	if(center)
		center.style.height = height + 'px';
	if(right)
		right.style.height = height + 'px';
}
// ------------------------------------------------------------
// Changes the height of the main divs of the page so
// they are the same height.
// ------------------------------------------------------------
function adaptMainDivs()
{
    var leftDiv		   = document.getElementById('leftareadiv');
    var mainDiv		   = document.getElementById('mainareadiv');
    var rightDiv	   = document.getElementById('rightareadiv');
    var mainandleftdiv = document.getElementById('mainandleftdiv');

    // min-height
    var height = 400;
       
    // find the highest div
    if (leftDiv  && leftDiv.clientHeight  > height) height = leftDiv.clientHeight;
    if (mainDiv  && mainDiv.clientHeight  > height) height = mainDiv.clientHeight;
    if (rightDiv && rightDiv.clientHeight > height)	height = rightDiv.clientHeight;
    if (mainandleftdiv && mainandleftdiv.clientHeight > height) height = mainandleftdiv.clientHeight;

    // set new height
    if (leftDiv)  leftDiv.style.height  = height + 'px';
    if (mainDiv)  mainDiv.style.height  = height + 'px';
    if (rightDiv) rightDiv.style.height = height + 'px';
    if (mainandleftdiv) mainandleftdiv.style.height = height + 'px';
}


// ------------------------------------------------------------
// Adapts the height of the rows containing articles
// ------------------------------------------------------------
function adaptArticleRows()
{
    // Loop over all the article rows specified in the global array
    for (var i = 0; i < gArticleRows.length; i++)    
    {
        alignChildHeight(gArticleRows[i]);
    }
}

// ------------------------------------------------------------
// Sets the height of all the children of the specified element
// to the height of the highest child.
// ------------------------------------------------------------
function alignChildHeight(parentId)
{
    var parentElement = document.getElementById(parentId);
    if (parentElement)
    {
        var maxHeight = 0;

        // Loop over all children to find the maxHeight
        for (i = 0; i < parentElement.childNodes.length; i++)
        {
            if (parentElement.childNodes[i].clientHeight > maxHeight)
            {
                maxHeight = parentElement.childNodes[i].clientHeight;
            }
        }

        // Loop over all children and set the height
        for (i = 0; i < parentElement.childNodes.length; i++)
        {
            if (parentElement.childNodes[i].style && 
                (parentElement.childNodes[i].style.clear != 'both'))
            {
                parentElement.childNodes[i].style.height = maxHeight + 'px';
            }
        }
    }
}


// ---------------
// Open window for object on map
// ---------------
function openObjectMapWindow(url)
{
	new_str = url.replace(" ","");
	old_str = url;
	while (old_str != new_str)
	{
        old_str = new_str;
        new_str = new_str.replace(" ","");	
	}
	url = new_str;
	
	// Size the window slightly smaller than the screen
    var width  = (screen.width  * 0.8);
    var height = (screen.height * 0.7);

    // Center window on screen
    var left = (screen.width  - width)  / 2;
    var top  = (screen.height - height) / 2;
	
    w = window.open(url, 'ObjectMapWindow', 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',location=no,scrollbars=yes,menubar=no,toolbar=no,resizable=yes,status=yes');
    
    if(w != null)
		w.focus();
}


// This function will fire a click event on the specified control when the 
// enter key is pressed in a text field. Attach this function to the 
// onkeypressed-event on the text field.
function fireClickOnEnter(evt, controlId)
{	
    var control = document.getElementById(controlId);
    var keyCode = (typeof window.event == 'object') ? window.event.keyCode : evt.keyCode;

    // If enter is pressed -> fire click-event on the control
    if (control && (keyCode == 13))
    {
        control.focus();
        control.click();        
        return false;
    }
    else
    {
        return true;
    }
}		

function showText(intID) {
	document.getElementById('div' + intID).style.display = 'block';
	document.getElementById('link' + intID).style.display = 'none';	
}
function hideText(intID) {
	document.getElementById('div' + intID).style.display = 'none';
	document.getElementById('link' + intID).style.display = 'block';	
}

function printPage(id) 
{
	var da = (document.all) ? 1 : 0;
	var pr = (window.print) ? 1 : 0;
	
	/*
	if(!pr)
		return;
	*/
	var printArea = document.getElementById(id);
	
	if(printArea == null && da) 
		printArea = document.all.mainareadiv;
	
	if(printArea) 
	{
		var sStart = "<html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"<%=Configuration.RootDir%>styles/structure.css\"><link rel=\"stylesheet\" type=\"text/css\" href=\"<%=Configuration.RootDir%>styles/editor.css\"><link rel=\"stylesheet\" type=\"text/css\" href=\"<%=Configuration.RootDir%>styles/units.css\"></head><body onload=\"javascript:window.print();\">";
		sStop = "</body></html>";

		var w = window.open('','printWin','width=650,height=440,scrollbars=yes');
		wdoc = w.document;
		wdoc.open();
		wdoc.write( sStart + printArea.innerHTML ) ;
		wdoc.writeln( sStop );
		wdoc.close();
	}
}

/****Expand Control Java Script****/
function ExpandUnit(id,exp)
{
	Avantime.Classes.ExpandUnitWriteToCookie.SetExpandProperty(id,exp,ExpandUnit_CallBack);
}
function ExpandUnit_CallBack(val)
{
	
}

function hideShow(id){
	var body = document.getElementById('body_'+id);

	if(body.style.display=='block'){
		ExpandUnit(id,'0');
		hide(id);
	}
	else{
		ExpandUnit(id,'1');
		show(id);
	}	
	fixHigth();
	adaptDivs();
	adaptStartPageDivs();
}
function hide(id)
{
	var body = document.getElementById('body_'+id);
	var arrow = document.getElementById('img_'+id);

	body.style.display='none';
	arrow.src='/images/danderyd/arrow_down.gif';
}
function show(id)
{
	var body = document.getElementById('body_'+id);
	var arrow = document.getElementById('img_'+id);
			
	body.style.display='block';
	arrow.src='/images/danderyd/arrow_up.gif';
}
/*** *** ***/