/* LBE */
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.href && anchor.rel == "external") {       
     anchor.target = "_blank";
   }   
 }
}
window.onload = externalLinks;


function popupForm(sideid, height) {
  if (height != null && height != "") {
    h = height;
  } else {
    h = 500;
  }
  w = 586;
  link = "http://www.ebst.dk/form/form.xsql?emne="+sideid;

  fromLeft = (screen.width-w)/2;
  fromTop = (screen.height-h)/2;

  open(link,"_blank","left="+fromLeft+",top="+fromTop+",width="+w+",height="+h+",status=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes");
}


function mailMe() {
  var URL = '' + encodeURIComponent(location.href);
  var rr_subject = encodeURIComponent("Du er blevet tippet");
  var rr_body = encodeURIComponent("Hej, Jeg har fundet en side du skal se:");
  location.href="mailto:?subject=" + rr_subject + "&body=" + rr_body + escape('\n')+URL;
}


function showHideFaq(which,gfx) {
	var status = document.getElementById(which).style.display;		
	
	if (status=='none')
	{
		document.getElementById(which).style.display='';
		document.getElementById(which+'arrow').src=gfx+'/iconer/sort_selected.gif';			
		document.getElementById(which+'link').title='Skjul';	
		document.getElementById(which+'link').className='open';	
		equalHeight($(".card."+which));	
	}
	else
	{
		document.getElementById(which).style.display='none';
		document.getElementById(which+'arrow').src=gfx+'/iconer/sort.gif';
		document.getElementById(which+'link').title='Vis';
		document.getElementById(which+'link').className='close';		    
	}
}


//Faneblade
function showDiv8(theDiv, theElement) {
  var selectedDiv = document.getElementById(theDiv);
  try { var theDiv1 = document.getElementById('div1');} catch (e) { null; }
  try { var theDiv2 = document.getElementById('div2');} catch (e) { null; }
  try { var theDiv3 = document.getElementById('div3');} catch (e) { null; }
  try { var theDiv4 = document.getElementById('div4');} catch (e) { null; }
  try { var theDiv5 = document.getElementById('div5');} catch (e) { null; }
  try { var theDiv6 = document.getElementById('div6');} catch (e) { null; }
  try { var theDiv7 = document.getElementById('div7');} catch (e) { null; }
  try { var theDiv8 = document.getElementById('div8');} catch (e) { null; }

  try { var thePane1 = document.getElementById('pane1');} catch (e) { null; }
  try { var thePane2 = document.getElementById('pane2');} catch (e) { null; }
  try { var thePane3 = document.getElementById('pane3');} catch (e) { null; }
  try { var thePane4 = document.getElementById('pane4');} catch (e) { null; }
  try { var thePane5 = document.getElementById('pane5');} catch (e) { null; }
  try { var thePane6 = document.getElementById('pane6');} catch (e) { null; }
  try { var thePane7 = document.getElementById('pane7');} catch (e) { null; }
  try { var thePane8 = document.getElementById('pane8');} catch (e) { null; }

  try { thePane1.className = 'unselectedFane';} catch (e) { null; }
  try { thePane2.className = 'unselectedFane';} catch (e) { null; }
  try { thePane3.className = 'unselectedFane';} catch (e) { null; }
  try { thePane4.className = 'unselectedFane';} catch (e) { null; }
  try { thePane5.className = 'unselectedFane';} catch (e) { null; }
  try { thePane6.className = 'unselectedFane';} catch (e) { null; }
  try { thePane7.className = 'unselectedFane';} catch (e) { null; }
  try { thePane8.className = 'unselectedFane';} catch (e) { null; }

  if (theDiv == 'div1') { thePane1.className = 'selectedFane'; }
  if (theDiv == 'div2') { thePane2.className = 'selectedFane'; }
  if (theDiv == 'div3') { thePane3.className = 'selectedFane'; }
  if (theDiv == 'div4') { thePane4.className = 'selectedFane'; }
  if (theDiv == 'div5') { thePane5.className = 'selectedFane'; }
  if (theDiv == 'div6') { thePane6.className = 'selectedFane'; }
  if (theDiv == 'div7') { thePane7.className = 'selectedFane'; }
  if (theDiv == 'div8') { thePane8.className = 'selectedFane'; }

  // Set all layers to none
  try { theDiv1.style.display = "none";} catch (e) { null; }
  try { theDiv2.style.display = "none";} catch (e) { null; }
  try { theDiv3.style.display = "none";} catch (e) { null; }
  try { theDiv4.style.display = "none";} catch (e) { null; }
  try { theDiv5.style.display = "none";} catch (e) { null; }
  try { theDiv6.style.display = "none";} catch (e) { null; }
  try { theDiv7.style.display = "none";} catch (e) { null; }
  try { theDiv8.style.display = "none";} catch (e) { null; }

  // Show the actual layer
  selectedDiv.style.display = "block";
}



// Anvender jquery
function equalHeight(group) {
  tallest = 0;    
  group.each(function() { 
      thisHeight = $(this).height();
      if(thisHeight > tallest) {
          tallest = thisHeight;
      }
  });
  if (tallest > 0) {
    group.height(tallest);
  }
}


function clearForm(oForm) {
  var elements = oForm.elements; 
  oForm.reset();
  for(i=0; i<elements.length; i++) {
  if (elements[i].name == 'i_kategori_id' ||
      elements[i].name == 'i_start_dato' ||  
      elements[i].name == 'i_slut_dato' ||  
      elements[i].name == 'i_vis_afholdte' ||  
      elements[i].name == 'i_fritekst' ||
      elements[i].name == 'k1' || elements[i].name == 'k2' ||
      elements[i].name == 'e1' || elements[i].name == 'e2' || elements[i].name == 'e3' || elements[i].name == 'e4' || elements[i].name == 'e5' ||   
      elements[i].name == 'a1' || elements[i].name == 'a2' || elements[i].name == 'a3' || elements[i].name == 'a4' || elements[i].name == 'a5' ){
	field_type = elements[i].type.toLowerCase();
	switch(field_type) {
		case "text": 
		case "password": 
		case "textarea":
	        case "hidden":	
			elements[i].value = ""; 
			break;
		case "radio":
		case "checkbox":
  			if (elements[i].checked) {
   				elements[i].checked = false; 
			}
			break;
		case "select-one":
		case "select-multi":
            		elements[i].selectedIndex = -1;
			break;
		default: 
			break;
	}
        }
    }
}