function doChangeUrl(url){
	if (url != null && url != ""){
		window.location = url;
	}
}


function validate_form(thisform)
{

	var ok = true;
	var message = "";
	for(i=0; i<thisform.elements.length; i++){
		if(thisform.elements[i].type != 'submit'){
		  var elName = thisform.elements[i].name;
		  var elValue = thisform.elements[i].value;
		  if (elName.slice(-2) == '_r' && elValue == ""){
			  var word = elName.slice(1);
			  var word = word.slice(0,word.length-2);
			  var first = elName.slice(0,1);
			  var first = first.toUpperCase();
			  var message = message + first + word + "\n";
			  var ok= false;
		  }
	   }
	}
	if(ok){
		return true;
	}else{
		alert("Du må fylle ut disse feltene:\n" + message);
		return false;
	}

}

function zoomImage(url, width, height) {
    if(!url || !width || !height) return;
    width += 20;
    height += 40;
    var win = window.open('', 'zoomimg', 'width='+width+',height='+height+'resizable=0,scrollbars=0,directories=0,location=0,menubar=0,status=0,toolbar=0');
    if(win) {
        win.document.open();
        win.document.write('<html><head><title>gsm.no</title></head><body style="margin:0;padding:0;" onclick="self.close();">' +
            '<div align="center"><img src="'+url+'" border="0" alt=""></div>' +
            '</body></html>');
        win.document.close();
        win.focus();
    }
}


function savequestionresult( questionid )
{
    username = document.getElementById( "user_name_"+questionid).value;
    useremail = document.getElementById( "user_email_"+questionid).value;
	vmail=0;

	if (document.getElementById( "vmail_"+questionid).checked){
		vmail=1;
	}
	
    if (username == '')
    {

       $('messagesdetailsajax-loader'+questionid).innerHTML = 'Du må fylle inn fullt navn og e-postadresse';
       show($('messagesajax-loader'+questionid),false);
       return;
    }
    if (useremail == '')
    {
       $('messagesdetailsajax-loader'+questionid).innerHTML = 'Du må fylle inn fullt navn og e-postadresse';
       show($('messagesajax-loader'+questionid),false);
       return;
    }
    nodeID = document.getElementById( "nodeid_"+questionid).value;
    divobj = document.getElementById( "optionlist_"+questionid);
    answeritem = -1;
    var objlist = divobj.getElementsByTagName("input");
    if ( objlist )
    {
        for ( i = 0; i < objlist.length; i++ )
        {
             strobj = new String(objlist.item(i).name);
            if( strobj.substr( 0, 8) == "eZOption" )
            {
                if ( objlist.item(i).type == 'radio' )
                {
                    if (objlist.item(i).checked)
                    {
                        answeritem = objlist.item(i).value;
                    }
                }

            }
        }
    }
 if ( answeritem == -1) {
        $('messagesdetailsajax-loader'+questionid).innerHTML = 'Du må krysse av for ett av alternativene';
        show($('messagesajax-loader'+questionid),false);
        return;
    }
    document.getElementById( 'ajax-loader'+questionid ).style.display = 'inline';
    $('messagesdetailsajax-loader'+questionid).innerHTML = "";
    hide($('messagesajax-loader'+questionid));
    xajax_savekalendaranswer(username,useremail, nodeID, answeritem, questionid, vmail );
}

function check_checkbox( questionid ){
	if (document.getElementById( "vmail_"+questionid).checked){
		$('qres').innerHTML = 'Jeg vil motta nyheter fra Arbeiderpartiet på e-post';
		show($('qres'),false);
		return;
		
	}else{
		$('qres').innerHTML = 'NB: Du må godta å bli lagt til vårt nyhetsbrev for å være med i trekningen av premier';
		show($('qres'),false);
		return;
	}
	
}



function hidespinner( id )
{
    setTimeout( function(){ hidespinnerByID(id);}, 1 ); 
}

function hidespinnerByID( id )
{
    document.getElementById(id).style.display='none';
}


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

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 showPayLightBoxWithSize(  width,height )
{

    var objBody = document.getElementsByTagName("body").item(0);

    if ( document.getElementById("lightbox-content") == null )
	{
        var objOverlay = document.createElement("div");
        objOverlay.setAttribute('id','overlay');
        //objOverlay.onclick = function () {hideLightbox(); return false;}
        objOverlay.style.display = 'none';
        objOverlay.style.position = 'absolute';
        objOverlay.style.top = '0';
        objOverlay.style.left = '0';
        objOverlay.style.zIndex = '90';
        objOverlay.style.width = '100%';
        objBody.insertBefore(objOverlay, objBody.firstChild);
    }
    if ( document.getElementById("lightbox-overlay") == null )
	{
        var objLightbox = document.createElement("div");
        objLightbox.setAttribute('id','lightbox');
        objLightbox.style.display = 'none';
        objLightbox.style.position = 'absolute';
        objLightbox.style.zIndex = '100';
        objBody.insertBefore(objLightbox, objOverlay.nextSibling);

        try {
          ifrm = document.createElement('<iframe name="paydestination">');
        } catch (ex) {
          ifrm = document.createElement('IFRAME');
        }
        ifrm.setAttribute("name", "paydestination");
        ifrm.setAttribute("id", "paydestination");
        ifrm.setAttribute("src", "");
        ifrm.style.width = 550+"px";
        ifrm.style.height = 600+"px";
        objLightbox.appendChild(ifrm);
    }




    var objOverlay = document.getElementById('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(document.getElementById('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');
	objLightbox.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
	objLightbox.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";

	objLightbox.style.width = boxSizeWidth + 'px' ;
        show(document.getElementById('lightbox'),false);
}

function removeLightBox()
{
    var objBody = document.getElementsByTagName("body").item(0);
    divlightbox = document.getElementById('lightbox');
    if ( divlightbox ) {
        objBody.removeChild(divlightbox);
    }
    divoverlay = document.getElementById('overlay');
    if ( divoverlay ) {
        objBody.removeChild(divoverlay);
    }

}


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 dont 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 = '';
	}
}

function setannet()
{
    document.getElementById('annet_input').checked = true;
}

function hideflash()
{
        /* hide all flash in the page */
        flash = document.getElementsByTagName('embed')
        for (var i = 0; i < flash.length; i++) 
        { 
                flash[i].style.visibility = 'hidden';
        }
}

function showflash()
{
        /* show all flash */
        flash = document.getElementsByTagName('embed')
        for (var i = 0; i < flash.length; i++) 
        { 
                flash[i].style.visibility = 'visible';
        }
}

function jk_fb() {

		u="http://arbeiderpartiet.no/Julekalender";
		window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u),'sharer','toolbar=0,status=0,width=626,height=436');
		return false;

	}


