//funktion der ændrer farve i overskrifter ved sortering af biler
function bgcolor(order){
	document.getElementById("1").style.backgroundColor="#9DABD2";
	document.getElementById("2").style.backgroundColor="#9DABD2";
	document.getElementById("3").style.backgroundColor="#9DABD2";
	document.getElementById("4").style.backgroundColor="#9DABD2";
	document.getElementById("5").style.backgroundColor="#9DABD2";
	document.getElementById(order).style.backgroundColor="#dddddd";
}

//funktion der ændrer farve i overskrifter ved sortering.
function bgcolor_1(order){
	document.getElementById("1").style.backgroundColor="#9DABD2";
	document.getElementById("2").style.backgroundColor="#9DABD2";
	document.getElementById("3").style.backgroundColor="#9DABD2";
	document.getElementById("4").style.backgroundColor="#9DABD2";
	document.getElementById("5").style.backgroundColor="#9DABD2";
	document.getElementById(order).style.backgroundColor="#dddddd";
}

//funktion der ændrer farve i overskrifter ved sortering.
function bgcolor_2(order){
	document.getElementById("1").style.backgroundColor="#9DABD2";
	document.getElementById("2").style.backgroundColor="#9DABD2";
	document.getElementById("3").style.backgroundColor="#9DABD2";
	document.getElementById("4").style.backgroundColor="#9DABD2";
	document.getElementById("5").style.backgroundColor="#9DABD2";
	document.getElementById("6").style.backgroundColor="#9DABD2";
	document.getElementById("7").style.backgroundColor="#9DABD2";
	document.getElementById("8").style.backgroundColor="#9DABD2";
	document.getElementById(order).style.backgroundColor="#dddddd";
}

//funktion der ændrer farve i overskrifter ved sortering.
function bgcolor_3(order){
	document.getElementById("1").style.backgroundColor="#9DABD2";
	document.getElementById("2").style.backgroundColor="#9DABD2";
	document.getElementById("3").style.backgroundColor="#9DABD2";
	document.getElementById("4").style.backgroundColor="#9DABD2";
	document.getElementById("5").style.backgroundColor="#9DABD2";
	document.getElementById("6").style.backgroundColor="#9DABD2";
	document.getElementById("7").style.backgroundColor="#9DABD2";
	document.getElementById(order).style.backgroundColor="#dddddd";
}

//sætter edit ruden forrest
function  index_edit()
{
document.getElementById("edit").style.zIndex="1102";
document.getElementById("edit_2").style.zIndex="1101";
document.getElementById("main_vindue").style.zIndex="1100";
}

//sætter edet_2 ruden forrest
function  index_edit_2()
{
document.getElementById("edit_2").style.zIndex="1102";
document.getElementById("edit").style.zIndex="1101";
document.getElementById("main_vindue").style.zIndex="1100";
}

//sætter hovedruden forrest
function  index_main()
{
document.getElementById("main_vindue").style.zIndex="1102";
document.getElementById("edit_2").style.zIndex="1101";
document.getElementById("edit").style.zIndex="1100";
}

/*De funktioner der kaldes ved load af siden*/
function load(udstyr_id)
{
hide_edit();
hide_edit_2();
vis_forsiden();
hide_popup();
hide_popup_2();
vis_bruger_menu();
vis_adm_menu();
if (udstyr_id != ""){
 	direkte_til_booking(udstyr_id);
}
}


/*viser medlem forsiden*/
function direkte_til_booking(udstyr_id)
 { 
var str = "udstyr_id="+udstyr_id;

$.ajax({
data: str,
type: "POST", 
url: "direkte_til_booking.php", 
cache: false,
dataType: "html",
 success: function(data){
  $("div#tekst_edit").html(data);

 	  }
}); 
}


/*funktion der skjuler edeit ruden, men samtidig gør den klar på ny, med header og tekstrude*/
function hide_edit()
{
document.getElementById("edit").style.visibility="hidden";
document.getElementById("tekst_edit").innerHTML="";
}

/*funktion der skjuler edeit ruden, men samtidig gør den klar på ny, med header og tekstrude*/
function hide_edit_2()
{
document.getElementById("edit_2").style.visibility="hidden";
document.getElementById("tekst_edit_2").innerHTML="";
}

/*viser popup message ruden*/
function show_popup(tekst)
{
document.getElementById("message").style.visibility="visible";
document.getElementById("tekst_message").innerHTML=tekst;
document.getElementById("message").style.zIndex="1104";
}

/*Skjuler popup message ruden*/
function hide_popup()
{
document.getElementById("tekst_message").innerHTML="";
document.getElementById("message").style.visibility="hidden";
}

/*viser popup message ruden*/
function show_popup_2(tekst)
{
document.getElementById("message_2").style.visibility="visible";
 document.getElementById("tekst_message_2").innerHTML=tekst;
 document.getElementById("message_2").style.zIndex="1104";

}

/*Skjuler popup message ruden*/
function hide_popup_2()
{
 document.getElementById("tekst_message_2").innerHTML="";
 document.getElementById("message_2").style.visibility="hidden";
}


// If the length of the element's string is 0 then display helper message
function isEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return true;
	}
	return false;
}

// If the element's string matches the regular expression it is all numbers
function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return false;
	}else{
		alert(helperMsg);
		elem.focus();
		return true;
	}
}

//længden skal være mellem max og min
function lengthRestriction(elem, min, max, helperMsg){
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max){
		return false;
	}else{
		alert(helperMsg);
		elem.focus();
		return true;
	}
}

function valueRestriction(elem, min, max, helperMsg){
	if(elem >= min && elem <= max){
		return false;
	}else{
		alert(helperMsg);
		elem.focus();
		return true;
	}
}

function lengthMax(elem, len, helperMsg){
	var uInput = elem.value;
	if(uInput.length <= len ){
		return false;
	}else{
		alert(helperMsg);
		elem.focus();
		return true;
	}
}

function lengthMin(elem, len, helperMsg){
	var uInput = elem.value;
	if(uInput.length >= len ){
		return false;
	}else{
		alert(helperMsg);
		elem.focus();
		return true;
	}
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return false;
	}else{
		alert(helperMsg);
		elem.focus();
		return true;
	}
}

function lengthSkal(elem, len, helperMsg){
	var uInput = elem.value;
	if(uInput.length == len ){
		return false;
	}else{
		alert(helperMsg);
		elem.focus();
		return true;
	}
}



/*viser medlem forsiden*/
function vis_forsiden()
 { 
$.ajax({
type: "POST", 
url: "forsiden.php", 
cache: false,
dataType: "html",
 success: function(data){
  $("div#my_main").html(data);

 	  }
}); 
}

/*viser medlem forsiden*/
function vis_bruger_menu()
 { 
$.ajax({
type: "POST", 
url: "bruger_menu.php", 
cache: false,
dataType: "html",
 success: function(data){
  $("div#bruger_menu").html(data);

 	  }
}); 
}

/*viser medlem forsiden*/
function vis_adm_menu()
 { 
$.ajax({
type: "POST", 
url: "adm_menu.php", 
cache: false,
dataType: "html",
 success: function(data){
  $("div#adm_menu").html(data);

 	  }
}); 
}


/*gem system settings*/
function gem_tilmeld()
{
if (isEmpty(document.form_tilmeld.navn, 'Der skal skrive et navn')){ return false};
if (isEmpty(document.form_tilmeld.adresse, 'Der skal skrive en adresse')){ return false};
if (lengthSkal(document.form_tilmeld.post_nr, '4', 'Der skal være 4 tal i post nummeret')){return false;}
if (isNumeric(document.form_tilmeld.post_nr, 'post nummer må kun indeholde tal')){ return false;};	
if (isEmpty(document.form_tilmeld.town, 'Der skal indtastes en by før der kan gemmes')){ return false};
if (isEmpty(document.form_tilmeld.email, 'Der skal skrive en email adresse')){ return false};
if (emailValidator(document.form_tilmeld.email, "Det er ikke en korrekt email adresse der er indtastet")){return false};

var mobil=document.form_tilmeld.mobil.value;
if (mobil != "") {
if (lengthSkal(document.form_tilmeld.mobil, '8', 'Der skal være 8 tal i mobil nummeret')){return false;}
if (isNumeric(document.form_tilmeld.mobil, 'Mobilnummer må kun indeholde tal')){ return false;};	
}

if (isNumeric(document.form_tilmeld.driver_license, 'Kørekort nummer må kun indeholde tal')){ }	
if (lengthSkal(document.form_tilmeld.driver_license, '8', 'Der skal være 8 tal i kørekort nummeret')){return false;}


 
var str = $("form").serialize();
$.ajax({
data: str,
type: "POST", 
scriptCharset: "utf-8",
cache: false,
dataType: "html",
url: "gem_tilmeld.php",
before: show_popup("Data gemmes"), 
 success: function(data){
	show_popup(data);
	hide_edit_2();
  booking_tilmeld();
 }
});
}

/*viser medlem forsiden*/
function kontrol_kort(driver_license)
 { 
var str = "driver_license="+driver_license;
if (driver_license !=""){
$.ajax({
data: str,
type: "POST", 
url: "kontrol_kort.php", 
cache: false,
dataType: "html",
 success: function(data){
if (data !=""){
 show_popup(data);
}
}
}); 
}
}

function show_profil()
{
show_popup("Du er allerede tilmeldt, oplysninger kan redigeres under profil");
vis_forsiden();
hide_edit_2;
}

/*edit settings*/
function edit_settings()
 { 
$.ajax({
type: "POST", 
url: "edit_settings.php", 
cache: false,
dataType: "html",
 success: function(data){
     $("div#my_main").html(data);
  	   }
}); 
}

/*edit settings*/
function admin_medlemmer()
 { 
$.ajax({
type: "POST", 
url: "admin_medlemmer.php", 
cache: false,
dataType: "html",
 success: function(data){
     $("div#my_main").html(data);
  	   }
}); 
}

function edit_medlem(medlem_id,retur)
{
var str = "medlem_id="+medlem_id+"&retur="+retur;
$.ajax({
data: str,
type: "POST", 
url: "edit_medlem.php", 
cache: false,
dataType: "html",
scriptCharset: "UTF-8",
before: show_popup("Data hentes"),
 success: function(data){
 document.getElementById("edit_2").style.visibility="visible";
   $("div#tekst_edit_2").html(data);
  index_edit_2();
 hide_popup();
	  }
}); 
}


function gem_medlem(medlem_id,retur)
{
if (isEmpty(document.form_medlem.navn, 'Der skal skrive et navn')){ return false};
if (isEmpty(document.form_medlem.adresse, 'Der skal skrive en adresse')){ return false};
if (lengthSkal(document.form_medlem.post_nr, '4', 'Der skal være 4 tal i post nummeret')){return false;}
if (isNumeric(document.form_medlem.post_nr, 'post nummer må kun indeholde tal')){ return false;};	
if (isEmpty(document.form_medlem.town, 'Der skal indtastes en by før der kan gemmes')){ return false};
if (isEmpty(document.form_medlem.email, 'Der skal skrive en email adresse')){ return false};
if (emailValidator(document.form_medlem.email, "Det er ikke en korrekt email adresse der er indtastet")){return false};

var mobil=document.form_medlem.mobil.value;
if (mobil != "") {
if (lengthSkal(document.form_medlem.mobil, '8', 'Der skal være 8 tal i mobil nummeret')){return false;}
if (isNumeric(document.form_medlem.mobil, 'Mobilnummer må kun indeholde tal')){ return false;};	
}

if (lengthSkal(document.form_medlem.driver_license, '8', 'Der skal være 8 tal i kørekort nummeret')){return false;}
if (isNumeric(document.form_medlem.driver_license, 'Kørekort nummer må kun indeholde tal')){ return false;}	

 
var str = $("form").serialize()+"&medlem_id="+medlem_id;;
$.ajax({
data: str,
type: "POST", 
scriptCharset: "utf-8",
cache: false,
dataType: "html",
url: "gem_medlem.php",
before: show_popup("Data gemmes"), 
 success: function(data){
	show_popup(data);
	hide_edit_2();
if (retur=='admin') {admin_medlemmer();}
if (retur=='profil'){vis_profil();}
if (retur=='booking'){booking_tilmeld();}
	  }
});
}

//sletter deltager
function slet_medlem(medlem_id)
{
var r=confirm("Skal medlem slettes?");
if (r==true)
{
var str = "medlem_id="+medlem_id;
$.ajax({
data: str,
type: "POST", 
url: "slet_medlem.php", 
cache: false,
dataType: "html",
scriptCharset: "UTF-8",
before: show_popup("Medlem slettes"),
 success: function(data){
 admin_medlemmer();
 show_popup(data);
 	 }
}); 
}
}

function vis_profil()
 { 
$.ajax({
type: "POST", 
url: "vis_profil.php", 
cache: false,
dataType: "html",
 success: function(data){
     $("div#my_main").html(data);
  	   }
}); 
}

/*gem system settings*/
function gem_settings()
{
if (isEmpty(document.form_edit_settings.klub_navn, 'Der skal skrive et navn')){ return false};

if (isEmpty(document.form_edit_settings.email, 'Der skal skrive en email adresse')){ return false};
if (emailValidator(document.form_edit_settings.email, "Det er ikke en korrekt email adresse der er indtastet")){return false};

if (isEmpty(document.form_edit_settings.adresse, 'Der skal skrive en adresse')){ return false};
if (lengthSkal(document.form_edit_settings.post_nr, '4', 'Der skal være 4 tal i post nummeret')){return false;}
if (isNumeric(document.form_edit_settings.post_nr, 'post nummer må kun indeholde tal')){ return false;};	
if (isEmpty(document.form_edit_settings.town, 'Der skal indtastes en by før der kan gemmes')){ return false};

var mobil=document.form_edit_settings.mobil.value;
if (mobil != "") {
if (lengthSkal(document.form_edit_settings.mobil, '8', 'Der skal være 8 tal i mobil nummeret')){return false;}
if (isNumeric(document.form_edit_settings.mobil, 'Mobilnummer må kun indeholde tal')){ return false;};	
}

var start_kl=document.form_edit_settings.start_kl.value;
var slut_kl=document.form_edit_settings.slut_kl.value;

if (slut_kl >= start_kl){alert("Start kl. skal være større end slut kl.");return true;}
		
var str = $("form").serialize();
$.ajax({
data: str,
type: "POST", 
scriptCharset: "utf-8",
cache: false,
dataType: "html",
url: "gem_settings.php",
before: show_popup("Data gemmes"), 
 success: function(data){
	show_popup(data);
	vis_forsiden();
	  }
});
}

/*edit settings*/
function admin_udstyr(afdeling_id,gruppe_id)
 {
var str = "afdeling_id="+afdeling_id+"&gruppe_id="+gruppe_id;   
$.ajax({
data: str,
type: "POST", 
url: "admin_udstyr.php", 
cache: true,
dataType: "html",
 success: function(data){
     $("div#my_main").html(data);
admin_udstyr_2();
	     }
}); 
}

function admin_udstyr_2()
{ 
var str = $("form").serialize();
$.ajax({
data: str,
type: "POST", 
url: "admin_udstyr_2.php", 
cache: false,
dataType: "html",
beforeSend: function(){
show_popup_2("Visning opdateres<br>vent venligst");;
},
 success: function(data){
  $("div#vis_udstyr").html(data);
	hide_popup_2();
   }
}); 
}


/*edit settings*/
function add_udstyr()
 { 
var str = $("form").serialize();
$.ajax({
data: str,
type: "POST", 
url: "add_udstyr.php", 
cache: false,
dataType: "html",
 success: function(data){
  document.getElementById("edit").style.visibility="visible";
   $("div#tekst_edit").html(data);
  index_edit();
	   }
}); 
}

function opret_udstyr()
 {
if (isEmpty(document.form_add_udstyr.tekst, 'Der skal skrive et bil navn')){ return false}; 

if (isNumeric(document.form_add_udstyr.day_pris, 'Prisen må kun indeholde tal')){ return false;};	

if (isNumeric(document.form_add_udstyr.day_km, 'Km må kun indeholde tal')){ return false;};	

var x=document.getElementById("afdeling_id");
if (x.selectedIndex==0){
alert("Der skal vælges en afdeling før der kan gemmes");
document.form_add_udstyr.afdeling_id.focus();
return false;	
}

var x=document.getElementById("gruppe_id");
if (x.selectedIndex==0){
alert("Der skal vælges en gruppe før der kan gemmes");
document.form_add_udstyr.gruppe_id.focus();
return false;	
}

var email=document.form_add_udstyr.email.value;
if (email != "") {
if (emailValidator(document.form_add_udstyr.email, "Det er ikke en korrekt email adresse der er indtastet")){return false};
}

var mobil=document.form_add_udstyr.mobil.value;
if (mobil != "") {
if (lengthSkal(document.form_add_udstyr.mobil, '8', 'Der skal være 8 tal i mobil nummeret')){return false;}
if (isNumeric(document.form_add_udstyr.mobil, 'Mobilnummer må kun indeholde tal')){ return false;};	

}
var str = $("form").serialize();
$.ajax({
data: str,
type: "POST", 
url: "opret_udstyr.php", 
cache: false,
dataType: "html",
success: function(data){
admin_udstyr_2();
hide_edit();
show_popup(data);
  	   }
}); 
}

function open_udstyr(udstyr_id)
{
var str = "udstyr_id="+udstyr_id;
$.ajax({
data: str,
type: "POST", 
url: "open_udstyr.php", 
cache: false,
dataType: "html",
success: function(data){
document.getElementById("edit").style.visibility="visible";
$("div#tekst_edit").html(data);
index_edit();
 	 }
}); 
}

function edit_udstyr(udstyr_id)
{
var str = "udstyr_id="+udstyr_id;
$.ajax({
data: str,
type: "POST", 
url: "edit_udstyr.php", 
cache: false,
dataType: "html",
scriptCharset: "UTF-8",
before: show_popup("Data hentes"),
 success: function(data){
 document.getElementById("edit_2").style.visibility="visible";
   $("div#tekst_edit_2").html(data);
  index_edit_2();
 hide_popup();
 	 }
}); 
}


function gem_udstyr(udstyr_id)
 {
 if (isEmpty(document.form_edit_udstyr.tekst, 'Der skal skrive et udstyr navn')){ return false}; 

if (isNumeric(document.form_edit_udstyr.day_pris, 'Prisen må kun indeholde tal')){ return false;};

if (isNumeric(document.form_edit_udstyr.day_km, 'Km må kun indeholde tal')){ return false;};

if (isNumeric(document.form_edit_udstyr.week_pris, 'Ugepris må kun indeholde tal')){ return false;};

if (isNumeric(document.form_edit_udstyr.week_km, 'Uge km må kun indeholde tal')){ return false;};

if (isNumeric(document.form_edit_udstyr.month_pris, 'Månedspris må kun indeholde tal')){ return false;};

if (isNumeric(document.form_edit_udstyr.month_km, 'Måneds km må kun indeholde tal')){ return false;};


var email=document.form_edit_udstyr.email.value;
if (email != "") {
if (emailValidator(document.form_edit_udstyr.email, "Det er ikke en korrekt email adresse der er indtastet")){return false};
}

var mobil=document.form_edit_udstyr.mobil.value;
if (mobil != "") {
if (lengthSkal(document.form_edit_udstyr.mobil, '8', 'Der skal være 8 tal i mobil nummeret')){return false;}
if (isNumeric(document.form_edit_udstyr.mobil, 'Mobilnummer må kun indeholde tal')){ return false;};	
}

if (lengthMax(document.form_edit_udstyr.remark, '100', 'Der må max være 100 tegn i beskrivelsen')){return false;}

var str = $("form").serialize()+"&udstyr_id="+udstyr_id;
$.ajax({
data: str,
type: "POST", 
url: "gem_udstyr.php", 
cache: false,
dataType: "html",
success: function(data){
hide_edit_2();
show_popup(data);
open_udstyr(udstyr_id);
admin_udstyr_2();
  	   }
}); 
}

//sletter deltager
function slet_udstyr(udstyr_id)
{
var r=confirm("Skal udstyret slettes?");
if (r==true)
{
var str = "udstyr_id="+udstyr_id;
$.ajax({
data: str,
type: "POST", 
url: "slet_udstyr.php", 
cache: false,
dataType: "html",
scriptCharset: "UTF-8",
before: show_popup("Udstyr slettes"),
 success: function(data){
 hide_edit();
admin_udstyr_2();
 show_popup(data);
  	 }
}); 
}
}

/*edit settings*/
function admin_afdeling()
 { 
$.ajax({
 type: "POST", 
url: "admin_afdeling.php", 
cache: true,
dataType: "html",
 success: function(data){
     $("div#my_main").html(data);
  	   }
}); 
}

/*edit settings*/
function add_afdeling()
 { 
$.ajax({
type: "POST", 
url: "add_afdeling.php", 
cache: false,
dataType: "html",
 success: function(data){
   document.getElementById("edit").style.visibility="visible";
     $("div#tekst_edit").html(data);
     index_edit;
  	   }
}); 
}


function opret_afdeling()
 {
 if (isEmpty(document.form_afdeling.afdeling_navn, 'Der skal skrive et afdelings navn')){ return false}; 
if (isEmpty(document.form_afdeling.adresse, 'Der skal skrive en adresse')){ return false};
if (lengthSkal(document.form_afdeling.post_nr, '4', 'Der skal være 4 tal i post nummeret')){return false;}
if (isNumeric(document.form_afdeling.post_nr, 'post nummer må kun indeholde tal')){ return false;};	
if (isEmpty(document.form_afdeling.town, 'Der skal indtastes en by før der kan gemmes')){ return false};
if (isEmpty(document.form_afdeling.email, 'Der skal skrive en email adresse')){ return false};
if (emailValidator(document.form_afdeling.email, "Det er ikke en korrekt email adresse der er indtastet")){return false};
if (isEmpty(document.form_afdeling.bank, 'Der skal skrive et bank navn')){ return false}; 
if (lengthSkal(document.form_afdeling.reg_nr, '4', 'Der skal være 4 tal i registrerings nummeret')){return false;}
if (isNumeric(document.form_afdeling.reg_nr, 'Registrerings nummer må kun indeholde tal')){ return false;};	
if (isNumeric(document.form_afdeling.konto_nr, 'Konto nummer må kun indeholde tal')){ return false;};
if (lengthRestriction(document.form_afdeling.konto_nr,7,10, 'Der skal være mellem 7 og 10 cifre i kontonummer')){ return false}; 

var str = $("form").serialize();
$.ajax({
data: str,
type: "POST", 
url: "opret_afdeling.php", 
cache: false,
dataType: "html",
success: function(data){
hide_edit();
show_popup(data);
admin_afdeling();
  	   }
}); 
}

function edit_afdeling(afdeling_id)
{
var str = "afdeling_id="+afdeling_id;
$.ajax({
data: str,
type: "POST", 
url: "edit_afdeling.php", 
cache: false,
dataType: "html",
scriptCharset: "UTF-8",
before: show_popup("Data hentes"),
 success: function(data){
            $("div#my_main").html(data);
   hide_popup();
 	 }
}); 
}

function gem_afdeling(afdeling_id)
 {
 if (isEmpty(document.form_afdeling.afdeling_navn, 'Der skal skrive et afdelings navn')){ return false}; 
if (isEmpty(document.form_afdeling.adresse, 'Der skal skrive en adresse')){ return false};
if (lengthSkal(document.form_afdeling.post_nr, '4', 'Der skal være 4 tal i post nummeret')){return false;}
if (isNumeric(document.form_afdeling.post_nr, 'post nummer må kun indeholde tal')){ return false;};	
if (isEmpty(document.form_afdeling.town, 'Der skal indtastes en by før der kan gemmes')){ return false};
if (isEmpty(document.form_afdeling.email, 'Der skal skrive en email adresse')){ return false};
if (emailValidator(document.form_afdeling.email, "Det er ikke en korrekt email adresse der er indtastet")){return false};
if (isEmpty(document.form_afdeling.bank, 'Der skal skrive et bank navn')){ return false}; 
if (lengthSkal(document.form_afdeling.reg_nr, '4', 'Der skal være 4 tal i registrerings nummeret')){return false;}
if (isNumeric(document.form_afdeling.reg_nr, 'Registrerings nummer må kun indeholde tal')){ return false;};	
if (isNumeric(document.form_afdeling.konto_nr, 'Konto nummer må kun indeholde tal')){ return false;};
if (lengthRestriction(document.form_afdeling.konto_nr,7,10, 'Der skal være mellem 7 og 10 cifre i kontonummer')){ return false}; 

var mobil=document.form_afdeling.mobil.value;
if (mobil != "") {
if (lengthSkal(document.form_afdeling.mobil, '8', 'Der skal være 8 tal i mobil nummeret')){return false;}
if (isNumeric(document.form_afdeling.mobil, 'Mobilnummer må kun indeholde tal')){ return false;};	
}

var str = $("form").serialize()+"&afdeling_id="+afdeling_id;
$.ajax({
data: str,
type: "POST", 
url: "gem_afdeling.php", 
cache: false,
dataType: "html",
success: function(data){
show_popup(data);
admin_afdeling();
  	   }
}); 
}

//sletter 
function slet_afdeling(afdeling_id)
{
var r=confirm("Skal afdelingen slettes?");
if (r==true)
{
var str = "afdeling_id="+afdeling_id;
$.ajax({
data: str,
type: "POST", 
url: "slet_afdeling.php", 
cache: false,
dataType: "html",
scriptCharset: "UTF-8",
before: show_popup("Afdeling slettes"),
 success: function(data){
 admin_afdeling();
 show_popup(data);
 	 }
}); 
}
}

/*tilføj logo siden*/
function add_afd_fil(afdeling_id)
{
var str = "afdeling_id="+afdeling_id;
$.ajax({
data: str,
type: "POST", 
scriptCharset: "utf-8",
url: "add_afd_fil.php", 
cache: false,
dataType: "html",
success: function(data){
document.getElementById("edit_2").style.visibility="visible";
$("div#tekst_edit_2").html(data);
index_edit_2();
 	  }
}); 
}

//funktion til upload af afdelings fil
function startCallback_3() {
			// make something useful before submit (onStart)
			show_popup("Fil upload starter");
			return true;
		}

		function completeCallback_3(response) {
			// make something useful after (onComplete)
			var numericExpression = /^[0-9]+$/;
				if(response.match(numericExpression)){
					admin_afdeling();
					hide_edit_2();
					show_popup(response);
		}
	else {
		admin_afdeling();
		hide_edit_2();
		show_popup(response);
	}
	}

function slet_afd_fil(afdeling_id)
{
var r=confirm("Skal beskrivelse slettes?");
if (r==true)
{
var str = "afdeling_id="+afdeling_id;
$.ajax({
data: str,
type: "POST", 
scriptCharset: "utf-8",
url: "slet_afd_fil.php", 
cache: false,
dataType: "html",
success: function(data){
admin_afdeling();
show_popup(data);
 	  }
}); 
}
}


/*edit settings*/
function admin_grupper()
 { 
$.ajax({
 type: "POST", 
url: "admin_grupper.php", 
cache: true,
dataType: "html",
 success: function(data){
     $("div#my_main").html(data);
  	   }
}); 
}

/*edit settings*/
function add_gruppe()
 { 
$.ajax({
type: "POST", 
url: "add_gruppe.php", 
cache: false,
dataType: "html",
 success: function(data){
  document.getElementById("edit").style.visibility="visible";
   $("div#tekst_edit").html(data);
  index_edit();
	   }
}); 
}

function opret_gruppe()
 {
 if (isEmpty(document.form_add_gruppe.gruppe_navn, 'Der skal skrive et gruppe navn')){ return false}; 
var str = $("form").serialize();
$.ajax({
data: str,
type: "POST", 
url: "opret_gruppe.php", 
cache: false,
dataType: "html",
success: function(data){
hide_edit();
show_popup(data);
admin_grupper();
  	   }
}); 
}

function edit_gruppe(gruppe_id)
{
var str = "gruppe_id="+gruppe_id;
$.ajax({
data: str,
type: "POST", 
url: "edit_gruppe.php", 
cache: false,
dataType: "html",
scriptCharset: "UTF-8",
before: show_popup("Data hentes"),
 success: function(data){
 document.getElementById("edit").style.visibility="visible";
   $("div#tekst_edit").html(data);
  index_edit();
 hide_popup();
 	 }
}); 
}

function gem_gruppe(gruppe_id)
 {
 if (isEmpty(document.form_gruppe.gruppe_navn, 'Der skal skrive et gruppe navn')){ return false}; 
var str = $("form").serialize()+"&gruppe_id="+gruppe_id;
$.ajax({
data: str,
type: "POST", 
url: "gem_gruppe.php", 
cache: false,
dataType: "html",
success: function(data){
hide_edit();
show_popup(data);
admin_grupper();
  	   }
}); 
}

//sletter deltager
function slet_gruppe(gruppe_id)
{
var r=confirm("Skal gruppe slettes?");
if (r==true)
{
var str = "gruppe_id="+gruppe_id;
$.ajax({
data: str,
type: "POST", 
url: "slet_gruppe.php", 
cache: false,
dataType: "html",
scriptCharset: "UTF-8",
before: show_popup("Gruppe slettes"),
 success: function(data){
 admin_grupper();
 show_popup(data);
 	 }
}); 
}
}

//funktion til upload af billeder til en bil
function startCallback_2() {
			// make something useful before submit (onStart)
			show_popup("Fil upload starter");
			return true;
		}

		function completeCallback_2(response) {
			// make something useful after (onComplete)
			var numericExpression = /^[0-9]+$/;
				if(response.match(numericExpression)){
					admin_udstyr_2();
					hide_edit_2();
					show_popup(response);
		}
	else {
		admin_udstyr_2();
		hide_edit_2();
		show_popup(response);
	}
	}

/*tilføj logo siden*/
function add_billede(udstyr_id)
{
var str = "udstyr_id="+udstyr_id;
$.ajax({
data: str,
type: "POST", 
scriptCharset: "utf-8",
url: "add_billede.php", 
cache: false,
dataType: "html",
success: function(data){
document.getElementById("edit_2").style.visibility="visible";
$("div#tekst_edit_2").html(data);
index_edit_2();
 	  }
}); 
}

/**/
function slet_billede(udstyr_id)
{
var r=confirm("Skal billede slettes?");
if (r==true)
{
var str = "udstyr_id="+udstyr_id;
$.ajax({
data: str,
type: "POST", 
scriptCharset: "utf-8",
url: "slet_billede.php", 
cache: false,
dataType: "html",
success: function(data){
open_udstyr(udstyr_id);
show_popup(data);
 	  }
}); 
}
}

/*edit settings*/
function vis_bookinger(afdeling_id)
 {
var str="afdeling_id="+afdeling_id;
$.ajax({
data: str,
type: "POST", 
url: "vis_bookinger.php", 
cache: true,
dataType: "html",
 success: function(data){
     $("div#my_main").html(data);
vis_bookinger_2();
  	   }
}); 
}

function vis_bookinger_2()
{ 
var str = $("form").serialize();
$.ajax({
data: str,
type: "POST", 
url: "vis_bookinger_2.php", 
cache: false,
dataType: "html",
beforeSend: function(){
show_popup_2("Booking visning opdateres<br>vent venligst");;
},
 success: function(data){
  $("div#vis_bookinger").html(data);
	hide_popup_2();
   }
}); 
}





/*edit settings*/
function indtast_betaling(booking_id)
 { 
$.ajax({
 data: "booking_id="+booking_id,
type: "POST", 
url: "indtast_betaling.php", 
cache: false,
dataType: "html",
 success: function(data){
 document.getElementById("edit").style.visibility="visible";
$("div#tekst_edit").html(data);
index_edit();
  	   }
}); 
}

function reg_betaling(booking_id)
 {
var str = $("form").serialize()+"&booking_id="+booking_id;
$.ajax({
data: str,
type: "POST", 
url: "reg_betaling.php", 
cache: false,
dataType: "html",
before: show_popup("Data gemmes"), 
success: function(data){
hide_edit();
show_popup(data);
vis_bookinger_2();
  	   }
}); 
}

/*edit settings*/
function mail_slet_booking(booking_id,retur)
 {
var str="booking_id="+booking_id+"&retur="+retur;
$.ajax({
data: str, 
type: "POST", 
url: "mail_slet_booking.php", 
cache: false,
dataType: "html",
 success: function(data){
 document.getElementById("edit").style.visibility="visible";
$("div#tekst_edit").html(data);
index_edit();
  	   }
}); 
}

function slet_booking(booking_id,retur)
{

var r=confirm("Skal bookingen slettes?");
if (r==true)
{
var str = $("form").serialize()+"&booking_id="+booking_id+"&retur="+retur;
$.ajax({
data: str, 
type: "POST", 
url: "slet_booking.php", 
cache: false,
dataType: "html",
scriptCharset: "UTF-8",
before: show_popup("Bookingen slettes"),
success: function(data){
show_popup(data);
hide_edit();
if (retur=="bruger"){
	vis_profil();
}
if (retur=="booking"){
vis_bookinger_2();
}
 	 }
}); 
}
}

/*edit settings*/
function vis_udstyr_afdelinger()
 { 
$.ajax({
type: "POST", 
url: "vis_udstyr_afdelinger.php", 
cache: false,
dataType: "html",
 success: function(data){
     $("div#my_main").html(data);
  	   }
}); 
}

/*edit settings*/
function vis_udstyr_grupper(afdeling_id)
 { 
$.ajax({
data: "afdeling_id="+afdeling_id,
type: "POST", 
url: "vis_udstyr_grupper.php", 
cache: false,
dataType: "html",
 success: function(data){
     $("div#my_main").html(data);
  	   }
}); 
}

/*edit settings*/
function vis_udstyr(gruppe_id,afdeling_id)
 { 
$.ajax({
data: "afdeling_id="+afdeling_id+"&gruppe_id="+gruppe_id,
type: "POST", 
url: "vis_udstyr.php", 
cache: false,
dataType: "html",
 success: function(data){
     $("div#my_main").html(data);
  	   }
}); 
}



/*edit settings*/
function vis_booking_siden(udstyr_id,gruppe_id,afdeling_id)
 { 
$.ajax({
 data: "udstyr_id="+udstyr_id+"&gruppe_id="+gruppe_id+"&afdeling_id="+afdeling_id,
type: "POST", 
url: "vis_booking_siden.php", 
cache: false,
dataType: "html",
 success: function(data){
     $("div#my_main").html(data);
	   }
}); 
}

/*edit settings*/
function change_udstyr_liste()
 { 
var str = $("form").serialize();
$.ajax({
data: str,
type: "POST", 
url: "change_udstyr_liste.php", 
cache: false,
dataType: "html",
success: function(data){
$("div#udstyr_liste").html(data);
vis_booking_udstyr();
vis_kalender();
vis_kalender_slut();
  	   }
}); 
}

/*edit settings*/
function vis_booking_udstyr()
{ 
var str = $("form").serialize();
$.ajax({
data: str,
type: "POST", 
url: "vis_booking_udstyr.php", 
cache: false,
dataType: "html",
success: function(data){
$("div#booking_udstyr").html(data);
vis_booking_pris();
  	   }
}); 
}

/*edit settings*/
function vis_ekstra_afdeling()
{ 
var str = $("form").serialize();
$.ajax({
data: str,
type: "POST", 
url: "vis_ekstra_afdeling.php", 
cache: false,
dataType: "html",
success: function(data){
$("div#booking_gruppe").html(data);
  	   }
}); 
}



/*edit settings*/
function vis_booking_pris()
{ 
var str = $("form").serialize();
$.ajax({
data: str,
type: "POST", 
url: "vis_booking_pris.php", 
cache: false,
dataType: "html",
before: document.getElementById("booking_pris").innerHTML="Pris beregnes",
success: function(data){
$("div#booking_pris").html(data);
  	   }
}); 
}


function vis_kalender()
{ 
var str = $("form").serialize();
$.ajax({
data: str,
type: "POST", 
url: "booking_kalender.php", 
cache: false,
dataType: "html",
 success: function(data){
  $("div#booking_kalender").html(data);
   	vis_booking_pris();
	     }
}); 
}

/*bruges i kalenderen ved skift dag*/
function change_dag(valg)
{
 document.getElementById("list_dag").value=valg;
 vis_kalender();
}

/*bruges i kalenderen ved skift måned med pilene*/
function change_month(valg)
{
 document.getElementById("list_month").value=valg;
 vis_kalender();
}

function vis_kalender_slut()
{ 
var str = $("form").serialize();
$.ajax({
data: str,
type: "POST", 
url: "booking_kalender_slut.php", 
cache: false,
dataType: "html",
 success: function(data){
  $("div#booking_kalender_slut").html(data);
     		vis_booking_pris();
   	  }
}); 
}

/*bruges i kalenderen ved skift dag*/
function change_dag_slut(valg)
{
 document.getElementById("list_dag_slut").value=valg;
 vis_kalender_slut();
}

/*bruges i kalenderen ved skift måned med pilene*/
function change_month_slut(valg)
{
 document.getElementById("list_month_slut").value=valg;
 vis_kalender_slut();
}

/*viser medlem forsiden*/
function booking_tilmeld()
 { 
var str = $("form").serialize();
$.ajax({
data: str,
type: "POST", 
url: "booking_tilmeld.php", 
cache: false,
dataType: "html",
 success: function(data){
document.getElementById("edit").style.visibility="visible";
$("div#tekst_edit").html(data);
index_edit();
 	  }
}); 
}



function opret_booking()
{
var list_udstyr=document.getElementById("list_udstyr");
var udstyr_id=list_udstyr.options[list_udstyr.selectedIndex].value; 

var str = $("form").serialize();
$.ajax({
data: str,
type: "POST", 
url: "opret_booking.php", 
cache: false,
dataType: "html",
beforeSend: function(){
show_popup("Vent venligst, bookingen tjekkes");
},
 success: function(data){
show_popup(data);
if (data.match("Booking er oprettet")){
vis_profil();
}
hide_edit();
 	  }
}); 

 }


function vis_email(booking,modtager_id)
 { 
  $.ajax({
 data: "booking="+booking+"&modtager_id="+modtager_id,
 type: "POST", 
 url: "vis_email.php", 
cache: false,
dataType: "html",
beforeSend: function(){
show_popup("Data hentes, vent venligst");
},
success: function(data){
document.getElementById("edit").style.visibility="visible";
$("div#tekst_edit").html(data);
index_edit();
hide_popup();
 	  }
}); 
 }

/*send email*/
function send_email()
{
if (isEmpty(document.form_mail.mail_emne, 'Der skal skrive et enme')){ return false};;

if (isEmpty(document.form_mail.mitTextarea, 'Der kan ikke sendes en tom besked')){ return false};;

var str = $("form").serialize();
$.ajax({
 type: "POST", 
 url: "send_email.php", 
cache: false,
 data: str,
 beforeSend: function(){
show_popup("Email afsendes<br>vent venligst");;
},
 success: function(data){
show_popup(data);
  }
});
}  

//bruges i send email
function showHint_1(str)
{ 
$.ajax({
data: "q="+str,
type: "POST", 
url: "getkontakter_1.php", 
cache: false,
dataType: "html",
beforeSend: function(){
document.getElementById("til_afdeling_id").value="ingen";
document.getElementById("txtHint").innerHTML="<b>Data hentes, vent venligst</b>"; 
},
 success: function(data){
   $("div#txtHint").html(data);

 	  }
}); 
}

//bruges i send email
function showHint_2(str)
{ 
$.ajax({
data: "q="+str,
type: "POST", 
url: "getkontakter_2.php", 
cache: false,
dataType: "html",
beforeSend: function(){
document.getElementById("til_kontakt_id").value="ingen";
document.getElementById("txtHint").innerHTML="<b>Data hentes, vent venligst</b>"; 
},
 success: function(data){
   $("div#txtHint").html(data);
 	  }
}); 
}


