
function dss_addLoadEvent(fn) {
  if(typeof(fn)!="function")return;
  var tempFunc=window.onload;
  window.onload=function() {
    if(typeof(tempFunc)=="function")tempFunc();
    fn();
  }
}

function changeInputType(oldElm,iType,iValue,blankValue,noFocus) {
  if(!oldElm || !oldElm.parentNode || (iType.length<4) || 
    !document.getElementById || !document.createElement) return;
  var newElm = document.createElement('input');
  newElm.type = iType;
  if(oldElm.name) newElm.name = oldElm.name;
  if(oldElm.id) newElm.id = oldElm.id;
  if(oldElm.className) newElm.className = oldElm.className;
  if(oldElm.size) newElm.size = oldElm.size;
  if(oldElm.tabIndex) newElm.tabIndex = oldElm.tabIndex;
  if(oldElm.accessKey) newElm.accessKey = oldElm.accessKey;
  newElm.onfocus = function(){return function(){
    if(this.hasFocus) return;
    var newElm = changeInputType(this,'password',iValue,
      (this.value.toLowerCase()==iValue.toLowerCase())?true:false);
    if(newElm) newElm.hasFocus=true;
  }}();
  newElm.onblur = function(){return function(){
    if(this.hasFocus)
    if(this.value=='' || (this.value.toLowerCase()==iValue.toLowerCase())) {
      changeInputType(this,'text',iValue,false,true);
    }
  }}();
  newElm.hasFocus=false;
  oldElm.parentNode.replaceChild(newElm,oldElm);
  if(!blankValue) newElm.value = iValue;
  if(!noFocus || typeof(noFocus)=='undefined') {
    window.tempElm = newElm;
    setTimeout("tempElm.hasFocus=true;tempElm.focus();",1);
  }
  return newElm;
}

dss_addLoadEvent(function(){

  var ua = navigator.userAgent.toLowerCase();
  if(!((ua.indexOf('konqueror')!=-1) && (document.all || 
    (ua.indexOf('khtml/3.4')!=-1))) && !(((ua.indexOf('safari')!=-1) && 
    !window.print) || (document.defaultCharset && !window.print))) {

      changeInputType(document.forms[0].password,'text','Kodeord',false,true);
  }
});

function submenu_close(menu_id) {

	if (menu_array[menu_id]=='hide') {
	top_id=menu_id + "_div";
	selected_item=document.getElementById(menu_id);
	selected_top=document.getElementById(top_id);
	selected_item.style.visibility='hidden';
	selected_top.className='menuitem';
	menu_queue[menu_id]='closed';
	}
}


function submenu(menu_id,menu_status) {

top_id=menu_id + "_div";
selected_item=document.getElementById(menu_id);
selected_top=document.getElementById(top_id);

	if(menu_status=='show') {			
	menu_array[menu_id]='show';
	menu_queue[menu_id]='open';
	selected_item.style.visibility='visible';
	selected_top.className="menuitem_"+menu_id;
	} else if(menu_status=='hide') {	
	menu_array[menu_id]='hide';
	menu_queue[menu_id]='close_queued';
	window.setTimeout("submenu_close('" + menu_id + "')",750);
	} else if(menu_status=='close') {
	menu_array[menu_id]='hide';
	submenu_close(menu_id);
	} else if(menu_status=='keepmealive') {
	b=menu_queue[menu_id];
		if(b=='close_queued') {
		menu_array[menu_id]='show';
		menu_queue[menu_id]='open';
		} else {
		menu_array[menu_id]='show';
		menu_queue[menu_id]='open';
		}
	}

}

function submenu_closeall() {
	if(menu_queue['menu1']=='open' || menu_queue['menu1']=='close_queued') {
	menu_array['menu1']='hide';
	submenu_close('menu1');
	}
	if(menu_queue['menu2']=='open' || menu_queue['menu2']=='close_queued') {
	menu_array['menu2']='hide';
	submenu_close('menu2');
	}
}

function td_highlight (id) {
id.style.backgroundColor = "#840000";
}
function td_hide (id) {
id.style.backgroundColor = "transparent";
}



function gotolink(link) {
document.location.href=link;
}










var fadeSteps = 20; 
var fadeDelay = 50; 
var nextSetDelay = 2000; 
var loopPrepend = true; 
var elIdx = 0, msgIdx = 0, fadeStep = 0; 
var fadeElem; 
function my_fadeMsg(){ 
    if(elIdx == 1 || (!loopPrepend && (msgIdx == msgLen))){ 
        if(elIdx != 1)msgIdx = 0; 
        elIdx = 0; 
        setTimeout('my_fadeMsg()', nextSetDelay); 
    }else{ 
        if(msgIdx == msgLen)msgIdx = 0; 
        if(elIdx == 0){ 
            for(var i=0;i<1;i++){my_setOpacity(document.getElementById('fadeElem'+i), 0);} 
        } 
        fadeStep = 20; 
        fadeElem = document.getElementById('fadeElem' + elIdx); 
        fadeElem.innerHTML = arMessage[msgIdx]; 
        fadeStep = 0; 
        elIdx++; 
        msgIdx++; 
        my_fadeIn(); 
    } 
} 
function my_fadeIn() { 
    if(fadeStep > fadeSteps){ 
        my_fadeMsg(); 
        return; 
    } 
    my_setOpacity(fadeElem, (fadeStep/fadeSteps)); 
    fadeStep++; 
    window.setTimeout("my_fadeIn()", fadeDelay); 
} 
function my_setOpacity( el, opacity){ 
    if(el.style.opacity != undefined){ 
        el.style.opacity = opacity; 
    }else if( el.style.MozOpacity != undefined){ 
        el.style.MozOpacity = opacity; 
    }else if ( el.style.filter != undefined){ 
        el.style.filter="alpha(opacity=" + Math.round(opacity * 100) + ")"; 
    } 
} 


//
//  --- FRONT SCROLLER
//


function sineInOut(t, b, c, d)
{
	return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
}

function findElementPos(elemFind)
{
	var elemX = 0;
	var elemY = 0;
	do {
		elemX += elemFind.offsetLeft;
		elemY += elemFind.offsetTop;
	} while ( elemFind = elemFind.offsetParent )

	return Array(elemX, elemY);
}

var currentSection = "cal_1-pane"; // The default loaded section on the page
var tabTag = "-tab";
var paneTag = "-pane";

// Scroll the page manually to the position of element "link", passed to us.

function ScrollSection(link, scrollArea, offset)
{

	// Store the last section, and update the current section

	if (currentSection == link) {
		return;
	}
	lastSection = currentSection;
	currentSection = link;
	
	// Change the section highlight.
	// Extract the root section name, and use that to change the background image to 'top', revealing the alt. state

    sectionTab = currentSection.split("-")[0] + tabTag;
    document.getElementById(sectionTab).className = "active";
    if (lastSection) {
	    lastTab = lastSection.split("-")[0] + tabTag;
	    document.getElementById(lastTab).className = "inactive";
	}
    
	// Get the element we want to scroll, get the position of the element to scroll to
	
	theScroll = document.getElementById(scrollArea);
	position = findElementPos(document.getElementById(link));

	// Get the position of the offset div -- the div at the far left.
	// This is the amount we compensate for when scrolling
	
	if (offset != "") {
		offsetPos = findElementPos(document.getElementById(offset));
		position[0] = position[0] - offsetPos[0];
	}

	scrollStart(theScroll, theScroll.scrollLeft, position[0], "horiz");
	// return false;
}

// Scroll the page using the arrows

function ScrollArrow(direction, toolbar, scrollArea, offset) {

	toolbarElem = document.getElementById(toolbar);
	toolbarNames = new Array();
    
	// Find all the <li> elements in the toolbar, and extract their id's into an array.
    
	if (toolbarElem.hasChildNodes())
	{
		var children = toolbarElem.childNodes;
		for (var i = 0; i < children.length; i++) 
		{
			if (toolbarElem.childNodes[i].tagName == "LI") {
				toolbarNames.push(toolbarElem.childNodes[i].id.split("-")[0]);
			}
		}
	}

	// Now iterate through our array of tab names, find matches, and determine where to go.

	for (var i = 0; i < toolbarNames.length; i++) {
		if (toolbarNames[i] == currentSection.split("-")[0]) {
			if (direction == "left") {
				if (i - 1 < 0) {
					gotoTab = toolbarNames[toolbarNames.length - 1];
				} else {
					gotoTab = toolbarNames[i - 1];
				}
			} else {
				if ((i + 1) > (toolbarNames.length - 1)) {
					gotoTab = toolbarNames[0];
				} else {
					gotoTab = toolbarNames[i + 1];
				}
			}
		}
	}
	
	// Go to the section name!
	
	ScrollSection(gotoTab+paneTag, scrollArea, offset);

}

//
// Animated Scroll Functions
// Scrolls are synchronous -- only one at a time.
//

var scrollanim = {time:0, begin:0, change:0.0, duration:0.0, element:null, timer:null};

function scrollStart(elem, start, end, direction)
{

	if (scrollanim.timer != null) {
		clearInterval(scrollanim.timer);
		scrollanim.timer = null;
	}
	scrollanim.time = 0;
	scrollanim.begin = start;
	scrollanim.change = end - start;
	scrollanim.duration = 25;
	scrollanim.element = elem;
	
	if (direction == "horiz") {
		scrollanim.timer = setInterval("scrollHorizAnim();", 15);
	}
	else {
		scrollanim.timer = setInterval("scrollVertAnim();", 15);
	}
}

function scrollVertAnim()
{
	if (scrollanim.time > scrollanim.duration) {
		clearInterval(scrollanim.timer);
		scrollanim.timer = null;
	}
	else {
		move = sineInOut(scrollanim.time, scrollanim.begin, scrollanim.change, scrollanim.duration);
		scrollanim.element.scrollTop = move; 
		scrollanim.time++;
	}
}

function scrollHorizAnim()
{
	if (scrollanim.time > scrollanim.duration) {
		clearInterval(scrollanim.timer);
		scrollanim.timer = null;
	}
	else {
		move = sineInOut(scrollanim.time, scrollanim.begin, scrollanim.change, scrollanim.duration);
		scrollanim.element.scrollLeft = move;
		scrollanim.time++;
	}
}


//
// Gallery displayimage functions
//

var oid=0;
var homedir="http://www.diskotekeast-end.dk/2";

function display_image(did) {

var db_id=img_array[did];

var img_url=homedir + "/gallery/image.php?imgid=" + db_id + "&galid=" + gal_id + "&thumb=false";

var myimage=new Image();
myimage.src=img_url;
var largeimage=document.getElementById('largeimage');
largeimage.src=homedir + "/gallery/loading.gif";
largeimage.src=img_url;

var postcard_input=document.getElementById('postcard_id');
postcard_input.value=db_id;

var deletereq_id=document.getElementById('deletereq_id');
deletereq_id.value=db_id;

hide_errorfields();

var dido="img_"+did;
var oido="img_"+oid;

setborders(dido,'active');
setborders(oido,'inactive');
oid=did;	
}


function setborders(img_id, state) {

var img=document.getElementById(img_id);

if(state=="active") {
img.style.borderColor='#da00dd';
img.onmouseover='';
img.onmouseout='';
} else if(state=="inactive") {
img.style.borderColor='#FFFFFF';
img.onmouseover="this.style.borderColor='#da00dd'";
img.onmouseout="this.style.borderColor='#FFFFFF'";
}


}

function gal_arrow(direction, totalimages) {

display_section('gallery_list');

if(direction=="up") {
	var nextid=oid+1;

	if(nextid>(totalimages-1)) {
	nextid=0;
	}

	// show image

	display_image(nextid);

	// Scroll section, if needed

	if(nextid==0) {
	ScrollSection('cal_1-pane', 'scroller', 'cal_1-pane');
	}

	var b=nextid/10;
	if(b=="1" || b=="2" || b=="3" || b=="4" || b=="5" || b=="6" || b=="7" || b=="8" || b=="9" || b=="10" || b=="11" || b=="12" || b=="13" || b=="14" || b=="15" || b=="16" || b=="17" || b=="18" || b=="19" || b=="20" || b=="21" || b=="22" || b=="23" || b=="24" || b=="25" || b=="26" || b=="27" || b=="28" || b=="29" || b=="30" || b=="31" || b=="32" || b=="33" || b=="34" || b=="35" || b=="36" || b=="37" || b=="38" || b=="39") {
	b++;
	var t="cal_"+b+"-pane";
	ScrollSection(t, 'scroller', 'cal_1-pane');		
	}

} else if(direction=="down") {
	var nextid=oid-1;

	if(nextid<0) {
	nextid=(totalimages-1);
	var scroll=0;
	}

	// show image

	display_image(nextid);

	// Scroll section, if needed
	
	var panecount=0;
	var i=0;
	while(i<totalimages) {
	panecount++;
	i=i+10;
	}

	if(scroll==0) {
	var t="cal_"+panecount+"-pane";
	ScrollSection(t, 'scroller', 'cal_1-pane');
	}

	var b=(nextid+1)/10;
	if(b=="1" || b=="2" || b=="3" || b=="4" || b=="5" || b=="6" || b=="7" || b=="8" || b=="9" || b=="10" || b=="11" || b=="12" || b=="13" || b=="14" || b=="15" || b=="16" || b=="17" || b=="18" || b=="19" || b=="20" || b=="21" || b=="22" || b=="23" || b=="24" || b=="25" || b=="26" || b=="27" || b=="28" || b=="29" || b=="30" || b=="31" || b=="32" || b=="33" || b=="34" || b=="35" || b=="36" || b=="37" || b=="38" || b=="39") {
	var t="cal_"+b+"-pane";
	ScrollSection(t, 'scroller', 'cal_1-pane');		
	}
}



}

var gal_section_displayed="gallery_list";

function display_section(section) {

hide_sections();

var gallery_list=document.getElementById('gallery_list');
var gallery_postcard=document.getElementById('gallery_postcard');
var gallery_postcard_succes=document.getElementById('gallery_postcard_succes');
var gallery_delete=document.getElementById('gallery_delete');
var gallery_delete_succes=document.getElementById('gallery_delete_succes');

if(section=="gallery_list") {
gallery_list.style.display="block";
gallery_list.style.visibility="visible";
} else if(section=="gallery_postcard") {
gallery_postcard.style.display="block";
gallery_postcard.style.visibility="visible";
} else if(section=="gallery_postcard_succes") {
gallery_postcard_succes.style.display="block";
gallery_postcard_succes.style.visibility="visible";
} else if(section=="gallery_delete") {
gallery_delete.style.display="block";
gallery_delete.style.visibility="visible";
} else if(section=="gallery_delete_succes") {
gallery_delete_succes.style.display="block";
gallery_delete_succes.style.visibility="visible";
}  

}

function hide_sections() {

var gallery_list=document.getElementById('gallery_list');
var gallery_postcard=document.getElementById('gallery_postcard');
var gallery_postcard_succes=document.getElementById('gallery_postcard_succes');
var gallery_delete=document.getElementById('gallery_delete');
var gallery_delete_succes=document.getElementById('gallery_delete_succes');

gallery_list.style.display="none";
gallery_list.style.visibility="hidden";

gallery_postcard.style.display="none";
gallery_postcard.style.visibility="hidden";

gallery_postcard_succes.style.display="none";
gallery_postcard_succes.style.visibility="hidden";

gallery_delete.style.display="none";
gallery_delete.style.visibility="hidden";

gallery_delete_succes.style.display="none";
gallery_delete_succes.style.visibility="hidden";
}

var hide_postcard_error=0;

function hide_errorfields() {
var postcard_error=document.getElementById('postcard_error');
var deletereq_error=document.getElementById('deletereq_error');

if(hide_postcard_error==0) {
hide_postcard_error++;
} else {
postcard_error.style.display="none";
postcard_error.style.visibility="hidden";

deletereq_error.style.display="none";
deletereq_error.style.visibility="hidden";

}

}
