function DeletePage(sDest, sXfer, sParams, sForm, sTarget)
{
	if(confirm("Are you sure you want to delete this page?"))
	{
		var sResult = FAModal_DeletePage(intThisNode);
		if(sResult.indexOf("deletenavinode-result")<0)
		{
			alert("An error has occured: " + sResult);
		}
		else
		{
			top.location.href = "../";
		}
	}
}
function TopMenuItem_OnClick(sDest, sXfer, sParams, sForm, sTarget, sType,sAnchorRef)
{
	//alert(sDest + ", " + sXfer + ", " + sParams + ", " + sForm + ", " + sTarget);
		
	var sUrl = "";
	if(sParams && sParams!='')
	{
		sUrl = sParams;
	}
	else if(sXfer && sXfer!='')
	{
		sUrl = "FineToolsAPI/FineDriver.aspx?<getpage naviid='" + sXfer + "'/>";
	}
	
	if(sUrl)

	{
		if(typeof encodeURI == 'function')
			sUrl = encodeURI(sUrl);
		
		if(sTarget && sTarget.toLowerCase().indexOf("top")>=0)
		{
			top.location.href = sUrl;
			return
		}
		else if(sTarget && sTarget!='')
		{
			window.open(sUrl,"newWindow","").focus();
			return;
		}
		else
		{
			var sBottomFrameUrl = "../Bottom.aspx?menuId=" + sDest + "&mainFrameUrl=" + sUrl;
			top.document.getElementById("BottomFrame").src = sBottomFrameUrl;
		}
	}
}
function GetRandomNr()
{
	//Always return same randomized nr, i.e if flashcontainerLEFTimage1 take also flashcontainerRIGHTimage1
	if(typeof(randflash) == "undefined")
	{		
		randflash = Math.round(Math.random()+1);
	}
	return randflash;
}

function RandomizeFlashObject(objectName)
{
	//If there is 2 versions of this flash uploaded. Randomize!
	if(document.getElementById('flashcontainer' + objectName + '2'))
	{
		flashContainer = document.getElementById('flashcontainer' + objectName + GetRandomNr());
		if(flashContainer)
		{
			flashContainer.style.display = '';
		}
	}
}
	
function ParentTemplateOnLoad()
{
	if(parent.document.title && document.title)
		parent.document.title = document.title;
}

function RandomizeFlashObjects()
{
	RandomizeFlashObject('leftimage');
	RandomizeFlashObject('rightimage');
}	

function GetStatistics()
{
	var year = document.getElementById("ddyear").value;
	var month = document.getElementById("ddmonth").value;
	var extraparams = "<r><year>" + year + "</year><month>" + month + "</month></r>"
	document.location.href = "FineDriver.aspx?<getpage naviid='" + intThisNode + "'>" + extraparams + "</getpage>";
}
function SelectOptions()
{
	var requestedyear = document.getElementById("requestedyear").value;
	var requestedmonth = document.getElementById("requestedmonth").value;
	var ddyear = document.getElementById("ddyear");
	var ddmonth = document.getElementById("ddmonth");
	SetSelectedOption(requestedyear, ddyear);
	SetSelectedOption(requestedmonth, ddmonth);
}
function SetSelectedOption(str, list)
{
	for (var i = 0; i < list.options.length; ++i) {
       if (list.options[i].value.toLowerCase().indexOf(str) == 0) {
          if (list.selectedIndex != i) 
		     list.selectedIndex = i;
          
          return;
       }
    }
}

function CallSearchPage(inputboxid, iconname)
{
	DisableSearch(iconname);
	var searchpage = document.getElementById('searchpagelinkhidden').value;
	var searchexp = document.getElementById(inputboxid).value.replace('+', 'and').replace('+', 'and').replace('+', 'and');

	var url = "finedriver.aspx?<getpage naviid='" + searchpage + "'>" + "<r><action>Search</action><searchexpression>" + searchexp + "</searchexpression></r></getpage>";

	document.location.href = url;			
}

function clickSearchButton(e, inputboxid, iconname)
{

	//var c=allEve(e).key;
	var Key = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
	
	if (Key== 13) 
	{
		CallSearchPage(inputboxid, iconname);
		return false;
	} 
	else 
		return true;
}

function GoToStartPage()
{

	var url = top.location.protocol + '//' +
	((typeof top.all != 'undefined' && typeof top.opera == 'undefined') ?
	top.location.hostname : top.location.hostname) +
	top.location.port + top.location.pathname;
	top.location = url;
	
}

//-------    popImg()    ---------------------------------------
//--   Input : (iName, width, height) - the name of the large image to be shown in the popup
//--   Options : (pInfo) - These are for the base window settings when opened
//--------------------------------------------------------------

function popImg(iName, width, height) {
            var pURL=iName;
                pInfo='toolbar=0,';
                pInfo+='location=0,';
                pInfo+='directories=0,';
                pInfo+='status=0,';
                pInfo+='menubar=0,';
                pInfo+='scrollbars=0,';
                pInfo+='resizable=1,';
                pInfo+=width+',';
                pInfo+=height;
            window.open(pURL, 'bigPop', pInfo);
        }


function SearchArticleInfo()
{
	var artnrbox = document.getElementById('searcharticleinfoarcticlenr');
	var iframesrcbox = document.getElementById('linktoiframepage');
	var templatebox = document.getElementById('searcharticleinfocatalogueurltemplate');
	var companybox = document.getElementById('searcharticlecompanyid');
	
	if(artnrbox == null || iframesrcbox == null || templatebox == null || companybox == null)
		return;
	
	var catalogueurl = templatebox.value.replace('*artnr*', artnrbox.value).replace('*bolagid*', companybox.value);
	var command = "finedriver.aspx?<getpage naviid='" + iframesrcbox.value.substring(iframesrcbox.value.indexOf('=')+1) + "'><r><iframesrc>" + catalogueurl + "</iframesrc><force-echo/></r></getpage>";
	document.location = command;
}

function SearchArticleImage()
{
	var artnrbox = document.getElementById('searcharticleinfoarcticlenr');
	var iframesrcbox = document.getElementById('linktoiframepage');
	var templatebox = document.getElementById('searcharticleimagecatalogueurltemplate');
	var companybox = document.getElementById('searcharticlecompanyid');
	var sizedd = document.getElementById('ddimagesize');
	if(artnrbox == null || iframesrcbox == null || templatebox == null || companybox == null || sizedd == null)
		return;
	var catalogueurl = templatebox.value.replace('*artnr*', artnrbox.value).replace('*bolagid*', companybox.value).replace('*storlek*', sizedd.options[sizedd.selectedIndex].value);
	var command = "finedriver.aspx?<getpage naviid='" + iframesrcbox.value.substring(iframesrcbox.value.indexOf('=')+1) + "'><r><iframesrc>" + catalogueurl + "</iframesrc><force-echo/></r></getpage>";
	document.location = command;
}

function SearchPartner()
{
	var mappagebox = document.getElementById('mappagelink');
	var citybox = document.getElementById('searchpartnerfield');
	
	if(mappagebox == null || citybox == null)
		return;
	var command = "finedriver.aspx?<getpage naviid='" + mappagebox.value.substring(mappagebox.value.indexOf('=')+1) + "' city='" + escape(citybox.value) + "'/>";
	
	document.location = command;
}
function DisableSearch(searchiconname)
{
	
	var iconsearch = document.getElementById(searchiconname).parentNode;
	var iconsearchdisabled = document.getElementById(searchiconname + '_disabled');

	if(iconsearch == null || iconsearchdisabled== null)
		return;
	iconsearch.style.visibility = 'hidden';
	iconsearch.style.display = 'none';
	iconsearchdisabled.style.visibility = 'visible';
	iconsearchdisabled.style.display = 'inline';
}
function autoIframe(frameId){
	iframe = document.getElementById(frameId);
        try
        {
          	var innerDoc = (iframe.contentDocument) ? iframe.contentDocument : iframe.contentWindow.document;
          	if (innerDoc.body.offsetHeight) //ns6 syntax
          	{
             		iframe.height = innerDoc.body.offsetHeight + 32; //Extra height FireFox
	        }
        	else if (iframe.Document && iframe.Document.body.scrollHeight) //ie5+ syntax
	        {
             		iframe.height = iframe.Document.body.scrollHeight + 10;
          	}
        }
        catch(err)
        {
             iframe.className = "ContentFromOtherDomain";
        }
}
