﻿ onerror=handleErr
 var method;
 var hovered = false;
 var hrStatus = false;
var isIndexPage = false;
var isAdminMode = false;

    var savingImage = new Image();
    savingImage.src = '../Private/images/saving.gif';	
    
    
function handleErr(msg,url,l)
{
    txt="Line Number="+ l  + "$#$#Errormessage=" + msg + " $#Method Name=" + method +"$#$# URL:" + url;
    ClickHandler.LogError(txt);
    return true
}

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll()
{
 
	var yScroll;
    method = "getPageScroll";
    
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	 method = "getPageSize";
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

//
// pause(numberMillis)
// Pauses code execution for specified time. Uses busy code, not good.
// Code from http://www.faqts.com/knowledge_base/view.phtml/aid/1602
//
function pause(numberMillis) {
    method = "pause";
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}

//
// showLightbox()
// Calculates the height and width of the crop interface and opens it in iframe then centers and displays.
//
function showIFramePages(pageSrc,pageHeight,pageWidth)
{
    method = "showIFramePages";

	//get the objects for loading the cropping interface
	var objOverlay = document.getElementById('overlay');
	objOverlay.style.display = 'none';
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
 	objOverlay.style.width = '100%';
 	objOverlay.style.height = '90%'; //screen.height + 'px'; //(arrayPageScroll[1] + 'px');
	objOverlay.style.zIndex = 0;
	
	var objLightbox = document.getElementById('lightbox');
	objLightbox.style.width = 'auto';
	
	
	
	var objFrame = document.getElementById('lightboxFrame');
	
	// read the page size, window size and the scrolled position
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	objOverlay.style.display = 'block';
	
	// A small pause between the image loading and displaying is required with IE,
	// this prevents the previous image displaying for a short burst causing flicker.
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		pause(250);
	}
	
	//setting the height and width of the iframe in which to display the cropping page : crop.aspx
	objFrame.height = (pageHeight + 35) + 'px';
	objFrame.width = (pageWidth + 2) + 'px';
	var h = (pageHeight + 35 );
	var w = (pageWidth + 2) ;
	
	var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] -  h) / 2);
	var lightboxLeft = ((arrayPageSize[0] - 20 - w) / 2);
	
	objLightbox.style.left = lightboxLeft+'px';
	objLightbox.style.top = lightboxTop+'px';
	
	
	objFrame.src = pageSrc;

		
	// After crop interface is loaded, update the overlay height as the crop interface might have
	// increased the overall page height.

	arrayPageSize = getPageSize();
	
	objOverlay.style.height = (arrayPageSize[1] + 'px');

	//display the crop interface
	objLightbox.style.display = 'block';

}

//
// hideLightbox()
// hides the crop interface and resize the main frame back to normal
//
function hideIFramePages()
{
     method = "hideIFramePages";
	 if(!isAdminMode)
    {
	    // get objects
	    var objOverlay = document.getElementById('if_overlay');
	    var objLightbox = document.getElementById('if_lightbox');
        var objFrame = document.getElementById('if_lightboxFrame');


	    // hide lightbox and overlay
	    objOverlay.style.display = 'none';
	    objLightbox.style.display = 'none';
	    if(isIndexPage)
	        objFrame.src = "Norwegian/frame_pages.aspx";
	    else
	        objFrame.src = "frame_pages.aspx";
        isIndexPage = false;
    }
	
}


function showLogoUpload(isIndex)
{
    if(!isAdminMode)
    {
        //Display logo page in iframe
        isIndexPage = isIndex;
        if(isIndex)
            showIFramePages("Norwegian/if_bestal.aspx",495,383);
        else
            showIFramePages("if_bestal.aspx",495,383);
    }
}    

function showChocolate()
{
    if(!isAdminMode)
    {
        showIFramePages("if_chocolate.aspx",290,372);
    }
}

function showTips()
{
    if(!isAdminMode)
    {
        showIFramePages("if_tips.aspx",258,332);
    }        
}

function showTipsThanks()
{
    if(!isAdminMode)
    {
        showIFramePages("if_tips_thanks.aspx",258,332);
    }        
}


function showSendAway()
{
    if(!isAdminMode)
    {
        showIFramePages("if_sendaway.aspx",207,428);
    }
}


function showThanks()
{
    if(!isAdminMode)
    {
        //Display logo page in iframe
        if(isIndexPage)
	        showIFramePages("Norwegian/if_thanks.aspx",362,478); //objFrame.src = "/frame_pages.aspx";
	    else
            showIFramePages("if_thanks.aspx",362,478);
    }
}

function showEgenLogo()
{
    if(!isAdminMode)
    {
        showIFramePages("if_egenlogo.aspx",189,513);
    }
}

function showEgenFarg()
{
    if(!isAdminMode)
    {
        showIFramePages("if_egenfarg.aspx",189,513);
    }
}


function showHalsning()
{
    if(!isAdminMode)
    {
        showIFramePages("if_halsning.aspx",189,513);
    }
}


function showLeverans()
{
    if(!isAdminMode)
    {
        //Display logo page in iframe
        showIFramePages("if_Leverans.aspx",189,513);
    }
}

function showBusy()
{

    var objOverlay = document.getElementById('if_overlay');
	objOverlay.style.display = 'block';
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
 	objOverlay.style.width = '100%';
 	objOverlay.style.height = '100%'; //screen.height + 'px'; //(arrayPageScroll[1] + 'px');
	objOverlay.style.zIndex = 0;
	
	var objBusy = document.getElementById('busyImage');
    
    var arrayPageSize = getPageSize();
    var arrayPageScroll = getPageScroll();


	var h = savingImage.height;
	var w = savingImage.width ;
	
	var imgTop = arrayPageScroll[1] + ((arrayPageSize[3] -  h) / 2);
	var imgLeft = ((arrayPageSize[0] - 20 - w) / 2);
	
	if (objBusy) {
		objBusy.style.top = imgTop; 	
		objBusy.style.left = imgLeft;
		objBusy.style.display = 'block';
	}
	
	objOverlay.style.height = (arrayPageSize[1] + 'px');


}

function hideBusy()
{

	objOverlay = document.getElementById('if_overlay');
	var objBusy = document.getElementById('busyImage');
    
	objOverlay.style.display = 'none';
	objBusy.style.display = 'none';

}