function $(e){if(typeof e=="string")e=document.getElementById(e);return e};
function hide(o){ o.style.display = 'none'; }
function show(o, withFade ){
	if ( typeof(withFade) != 'undefined' && withFade == true ){
		o.style.zoom = 1; //to make layout ( alpha filter don't work without layout in IE)
		setOpacity(o.id, 0 ); //initial opacity to transparrent
	   	o.style.display = 'block';
	   	appear(o.id);
   	} else{
		o.style.display = 'block';
		o.style.visibility = '';
	}
}



//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	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;

	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;
}



function showLightBoxWithSize( contentID, width,height )
{

    if ( $("lightbox-content") == null )
	{
        var newElement = document.createElement('div');
	    newElement.id = "lightbox-content";
	    document.body.appendChild( newElement );
        }
    if ( $("lightbox-overlay") == null )
	{
         var newElement1 = document.createElement('div');
	     newElement1.id = "lightbox-overlay";
	     newElement1['class'] = "iePNG";
	     document.body.appendChild( newElement1 );
        }
    var objOverlay = document.getElementById('lightbox-overlay');
    var arrayPageSize = getPageSize();
    var arrayPageScroll = getPageScroll();
	// set height of Overlay to take up whole page and show
	objOverlay.style.height = (arrayPageSize[1] + 'px');
        show($('lightbox-overlay'),false);
        //objOverlay.style.display = 'block';
        var boxSizeWidth = width;
        var boxSizeHeight = height;
	var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - boxSizeHeight) / 2);
	var lightboxLeft = ((arrayPageSize[0] - 20 - boxSizeWidth) / 2) - 11;

	var objLightbox = document.getElementById('lightbox-content');
        objLightbox.innerHTML = $(contentID).innerHTML;
        $(contentID).innerHTML = '';
	objLightbox.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
	objLightbox.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";
//    objLightbox.style.top = "245px";
//	objLightbox.style.left = "357px";
//	objLightbox.style.margin = "0pt auto";

	objLightbox.style.width = boxSizeWidth + 'px' ;
        show($('lightbox-content'),false);
}




function hideLoginBox()
{
        hide($('lightbox-overlay'));
        hide($('lightbox-content'));
}

function hideLightAjaxBox( contentID, ajaxdiv )
{
        hide($('lightbox-overlay'));
        hide($('lightbox-content'));
        hide($(ajaxdiv));
        hide($('messages'+ajaxdiv));
        $('messagesdetails'+ajaxdiv).innerHTML = '';
        $(contentID).innerHTML = $('lightbox-content').innerHTML;
//        $('current_day_div').style.display = "none";
//        $('current_day_div_image').style.display = "block";

}

function hideLightAjaxBoxAnswer( contentID, ajaxdiv )
{
        hide($('lightbox-overlay'));
        hide($('lightbox-content'));
        hide($(ajaxdiv));
        hide($('messages'+ajaxdiv));
        $('messagesdetails'+ajaxdiv).innerHTML = '';
//        $(contentID).innerHTML = $('lightbox-content').innerHTML;
        $('current_day_div').style.display = "none";
        $('current_day_div_image').style.display = "block";
        setTimeout("location.href='http://www.dna.no/dna.no/Bli-medlem'",4000);

}

function showLightAjaxBoxRight( contentID, ajaxdiv )
{
//        $(contentID).innerHTML = $('lightbox-content').innerHTML;
        hide($('lightboxmain'));
        hide($(ajaxdiv));

        hide($('messages'+ajaxdiv));
        $('messagesdetails'+ajaxdiv).innerHTML = '';
        show($('lightboxrigth'), false);
        document.cookie="foo=bar; path=/; expires=Mon, 01-Jan-2001 00:00:00 GMT";
  
}

function showLightAjaxBoxWrong( contentID, ajaxdiv )
{
  //      $(contentID).innerHTML = $('lightbox-content').innerHTML;
        hide($('lightboxmain'));
        hide($(ajaxdiv));
        hide($('messages'+ajaxdiv));
        $('messagesdetails'+ajaxdiv).innerHTML = '';
        show($('lightboxwrong'), false);
//        document.cookie="foo=bar; path=/; expires=Mon, 01-Jan-2001 00:00:00 GMT";
        
        //document.cookie=  name + "=1";
}





function hideLightBox( contentID )
{
        hide($('lightbox-overlay'));
        hide($('lightbox-content'));
        $(contentID).innerHTML = $('lightbox-content').innerHTML;
}

function fixPNG(element)
{
  if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
  {
    var src;
    if (element.tagName=='IMG')
    {
      if (/\.png$/.test(element.src))
      {
        src = element.src;
        element.src = "/blank.gif";
      }
    }
    else
    {
      src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
      if (src)
      {
        src = src[1];
        element.runtimeStyle.backgroundImage="none";
      }
    }
    if (src)
    {
        element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
    }


  }

}

function showErrorLight(contentID, ajaxdiv)
{
    //hide($('lightbox-overlay'));
    //hide($('lightbox-content'));
    hide($(ajaxdiv));
    $('messagesdetails'+ajaxdiv).innerHTML = 'Vi beklager, men du kan kun svare en gang pr dag.';
    show($('messages'+ajaxdiv),false);

}

function showEmailErrorLight(contentID, ajaxdiv)
{
    //hide($('lightbox-overlay'));
    //hide($('lightbox-content'));
    hide($(ajaxdiv));
    $('messagesdetails'+ajaxdiv).innerHTML = 'Vennligst oppgi en gyldig e-postadresse';
    show($('messages'+ajaxdiv),false);

}



















