var galleryblockid;
var galleryblockcount;
var gallerytimer;

function startImageGallery(){

	gallerytimer=setTimeout("startImageGallery();nextImageGallery()",8000);

}

function initImageGallery(id,maxcount){

	galleryblockid = id;
	galleryblockcount = maxcount;
	
	document.getElementById('galleryblock'+id).style.display = 'block';

}

function prevImageGallery(){

	if (galleryblockcount > 1){

		if (galleryblockid==1){
			document.getElementById('galleryblock'+galleryblockid).style.display = 'none';
			galleryblockid = galleryblockcount;
		} else {
			document.getElementById('galleryblock'+galleryblockid).style.display = 'none';
			galleryblockid = (galleryblockid-1);
		}
		
		document.getElementById('galleryblock'+galleryblockid).style.display = 'block';
		opacity('image'+galleryblockid,50,100,500);

	}

}

function nextImageGallery(){

	if (galleryblockcount > 1){

		if (galleryblockid==galleryblockcount){
			document.getElementById('galleryblock'+galleryblockid).style.display = 'none';
			galleryblockid = 1;
		} else {
			document.getElementById('galleryblock'+galleryblockid).style.display = 'none';
			galleryblockid = (galleryblockid+1);
		}
		
		document.getElementById('galleryblock'+galleryblockid).style.display = 'block';
		opacity('image'+galleryblockid,50,100,500);

	}

}

function initSubsiteSearch(me,value){

	var scopes = value.split(",")

	for ( var i=0;i<scopes.length;i++ )
	{

		for ( var t=0;t<me.length;t++ )
		{
			if(me[t].value==parseInt(scopes[i])){
				me[t].checked=true;
			}		
		}
	
	}
}

function initBGImage(color,file){

	document.body.style.backgroundColor='#'+color;
	document.body.style.backgroundImage='url(\'files/baggrunde/' + color + '_' + file + '\')';
	document.body.style.backgroundPosition='top center';
	document.body.style.backgroundRepeat='no-repeat';

}


function getDocHeight() {
    var D = document;
    var docheight = Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
    
    document.getElementById('layer').style.height=docheight+'px';
}

function rendermail(user, domain, classname){
  var1=user;
  var2=domain;
  var3=var1+'@'+var2;
  emailE=(var3);
  document.write ('<a class="'+ classname +'" href="mailto:' + emailE + '">' + emailE + '<\/a>');
}

function StartClientMail(user, domain){
  var1=user;
  var2=domain;
  var3=var1+'@'+var2;
  emailE=(var3);
  document.location.href='mailto:' + emailE;
}

//usage onkeypress="return onEnter(event,btnid)" on field

function onEnter( evt, btnid ) {
	var keyCode = null;

	if( evt.which ) {
		keyCode = evt.which;
	} else if( evt.keyCode ) {
		keyCode = evt.keyCode;
	}
	if( 13 == keyCode ) {
		document.getElementById(btnid).click();
		return false;
	}
	return true;
}

function getPrintPage(){
	if(document.getElementById('ajrprintcontent') != null){
		var pageP = window.open('/print.asp','Print','width=680, height=650, resizable=1')
	}
}

function printPage(){

	window.document.title = window.opener.document.title;

	var sOut;
	sOut = '';

	if (window.opener.document.getElementById('ajrprintcontent')) {
	  sOut = sOut + window.opener.document.getElementById('ajrprintcontent').innerHTML;
	}

	if (window.opener.document.getElementById('ajrprintcontent2')) {
	  sOut = sOut + '<div style="margin-top: 30px;">' + window.opener.document.getElementById('ajrprintcontent2').innerHTML + '</div>';
	}

	document.getElementById('ajrprintcontent').innerHTML = sOut;
	document.body.style.backgroundImage='none';
	document.body.style.backgroundColor='#ffffff';

	window.print();
}

function checkmyform(me) {
		
	resetfieldclasses(me);
	
	if (me.navn.value==''){alert('Angiv venligst dit navn.'); redalert(me.navn); return false;}
	if (me.adresse.value==''){alert('Angiv venligst adresse.'); redalert(me.adresse); return false;}
	if (me.postnummer.value==''){alert('Angiv venligst dit postnummer.'); redalert(me.postnummer); return false;}
	if (me.by.value==''){alert('Angiv venligst din by.'); redalert(me.by); return false;}
	if (!emailCheck(me.email.value)){alert('Din mailadresse er ikke gyldig.'); redalert(me.email); return false;}
	if (me.antal.value==''){alert('Angiv venligst et antal.'); redalert(me.antal); return false;}
	
	me.submit();

}

function resetfieldclasses(me){
	for ( var i=0;i<me.elements.length;i++ )
	{
		if(me.elements[i].name != ''){
			if( me.elements[i].type=='text' )
			{
			me.elements[i].style.border='1px solid #cccccc';
			}
		}		
	}
}

function redalert(me){
	me.style.border='1px solid red';
	me.focus();
}

function setSelectedIndex( me, valsearch )
{
  for (i = 0; i< me.options.length; i++)
  {
    if (me.options[i].value == valsearch)
    {
      me.options[i].selected = true;
      me.options[i].style.backgroundColor = '#dddddd';
      break;
    }
  }
  return;
}

function showhidediv(id){
	if (document.getElementById(id)){
		if(document.getElementById(id).style.display=='none'){
			document.getElementById(id).style.display='block';
		} else {
			document.getElementById(id).style.display='none';
		}
	}
}

function flipthisimage(me){

	if(me.src.indexOf('on')==-1){
		me.src=me.src.replace('_off','_on');
	} else {
		me.src=me.src.replace('_on','_off');
	}

}

function flipthisclass(me){

	if(me.className.indexOf('on')==-1){
		me.className=me.className+'on';
	} else {
		me.className=me.className.replace('on','');
	}

}

function disableAFocus() {
  var A_nodes = document.getElementsByTagName("A");

  for(i=0;i<A_nodes.length;++i) {
    a = A_nodes.item(i);
    a.onfocus = a.blur;
  }
} 
