jQuery(document).ready(function(){
$("#my_main").click(function(e){
		position_edit_3(e);
	
   });
$("#edit_2").click(function(e){
		position_edit_3(e);
   });

$( "#edit" ).draggable({ opacity: 0.9, handle: '#rude_header'});
$( "#edit_2" ).draggable({ opacity: 0.9, handle: '#rude_header_2'});
$( "#edit_3" ).draggable({ opacity: 0.9, handle: '#rude_header_3'});
$( "#popup" ).draggable({ opacity: 0.9, handle: '#rude_header_popup'});

}); 

function position_edit_3(e)
{
	var x = e.pageX-50;
	var y = e.pageY-200;
      
document.getElementById("edit_3").style.top=y+"px";
document.getElementById("edit_3").style.left=x+"px";
	
}

/*De funktioner der kaldes ved load af siden*/
function load()
{
$('#edit').hide(0);
$('#edit_2').hide(0);
$('#edit_3').hide(0);
$('#message').hide(0);
$('#popup').hide(0);
vis_oversigt();
}

/*viser den første side*/
function vis_oversigt(row_start,filter)
 {
$.ajax({
data: "row_start="+row_start+"&filter="+filter,
type: "POST", 
url: "vis_oversigt.php", 
cache: false,
dataType: "html",
beforeSend: function(){
$("div#my_main").html("<span class='overskrift'>Data hentes, vent venligst</span>");
},
 success: function(data){
  $("div#my_main").html(data);
  vis_menu_adm('start');
   vis_menu_bruger('start');
 	  }
}); 
}

//kalder sidenavigationen
function ajax_makepagenav(row_start, poster_side, rows, bokse, script_navn, filter)
 { 
$.ajax({
data: "row_start="+row_start+"&poster_side="+poster_side+"&rows="+rows+"&bokse="+bokse+"&script_navn="+script_navn+"&filter="+filter,
type: "POST", 
url: "ajax_makepagenav.php", 
cache: false,
dataType: "html",
 success: function(data){
  $("div#page_nav").html(data);
   
 	  }
}); 
}

/*viser bruger menuen*/
function vis_menu_bruger(menu_valg,id,id_2)
 { 
$.ajax({
data: "menu_valg="+menu_valg+"&id="+id+"&id_2="+id_2,
type: "POST", 
url: "menu_bruger.php", 
cache: false,
dataType: "html",
 success: function(data){
  $("div#bruger_menu").html(data);
     update_kurv_link_antal();
 	  }
}); 
}
/*viser adm menuen*/
function vis_menu_adm(menu_valg,id)
 { 
$.ajax({
data: "menu_valg="+menu_valg+"&id="+id,
type: "POST", 
url: "menu_adm.php", 
cache: false,
dataType: "html",
 success: function(data){
  $("div#adm_menu").html(data);
 	  }
}); 
}

//bruges i send email
function showHint_1(str,id)
{ 
$.ajax({
data: "q="+str+"&id="+id,
type: "POST", 
url: "getkontakter_1.php", 
cache: false,
dataType: "html",
beforeSend: function(){
document.getElementById("til_gruppe_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,id)
{ 
$.ajax({
data: "q="+str+"&id="+id,
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);
 	  }
}); 
}

//bruges i send sms
function showHint_3(str,id)
{ 
$.ajax({
data: "q="+str+"&id="+id,
type: "POST", 
url: "getkontakter_3.php", 
cache: false,
dataType: "html",
beforeSend: function(){
document.getElementById("til_gruppe_id").value="ingen";
document.getElementById("txtHint").innerHTML="<b>Data hentes, vent venligst</b>"; 
},
 success: function(data){
   $("div#txtHint").html(data);
 	  }
}); 
}

//bruges i send sms
function showHint_4(str,id)
{ 
$.ajax({
data: "q="+str+"&id="+id,
type: "POST", 
url: "getkontakter_4.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);
 	  }
}); 
}

// Radio Button Validation
// copyright Stephen Chapman, 15th Nov 2004,14th Sep 2005
// you may copy this function but please keep the copyright notice with it
function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}

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

// If the element's string matches the regular expression it is all numbers
function isNumeric_2(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.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 wwwValidator(elem, helperMsg){
	var wwwExp = /^[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
     
	if(elem.value.match(wwwExp)){
		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;
	}
}

/*funktion der skjuler edeit ruden, men samtidig gør den klar på ny, med header og tekstrude*/
function hide_edit()
{
$('#edit').hide('slow');
}

function show_edit()
{
$('#edit').fadeIn('slow');
index_edit();
}

function hide_edit_2()
{
$('#edit_2').hide('slow');
}

function show_edit_2()
{
$('#edit_2').fadeIn('slow');
index_edit_2();
}

function hide_edit_3()
{
$('#edit_3').hide('slow');
}

function show_edit_3()
{
$('#edit_3').fadeIn('slow');
index_edit_3();
}

/*viser message message ruden*/
function show_message(tekst)
{
document.getElementById("tekst_message").innerHTML=tekst;
document.getElementById("message").style.zIndex="4";
$('#message').fadeIn('slow');
}

/*Skjuler message message ruden*/
function hide_message()
{
 $('#message').hide('slow');
 document.getElementById("tekst_message").innerHTML="";
}

/*viser popup message ruden*/
function show_popup(tekst)
{
 document.getElementById("tekst_popup").innerHTML=tekst;
 document.getElementById("popup").style.zIndex="4";
 $('#popup').fadeIn('slow');
}

/*Skjuler popup message ruden*/
function hide_popup()
{
$('#popup').hide('slow');
 document.getElementById("tekst_popup").innerHTML="";
}

//sætter edit ruden forrest
function  index_edit()
{
document.getElementById("edit").style.zIndex="3";
document.getElementById("edit_3").style.zIndex="2";
document.getElementById("edit_2").style.zIndex="1";
document.getElementById("my_main").style.zIndex="0";
}

//sætter edet_2 ruden forrest
function  index_edit_2()
{
document.getElementById("edit_2").style.zIndex="3";
document.getElementById("edit_3").style.zIndex="2";
document.getElementById("edit").style.zIndex="1";
document.getElementById("my_main").style.zIndex="0";
}

//sætter edit_3 ruden forrest
function  index_edit_3()
{
document.getElementById("edit_3").style.zIndex="3";
document.getElementById("edit_2").style.zIndex="2";
document.getElementById("edit").style.zIndex="1";
document.getElementById("my_main").style.zIndex="0";
}

//sætter hovedruden forrest
function  index_main()
{
document.getElementById("my_main").style.zIndex="3";
document.getElementById("edit_3").style.zIndex="2";
document.getElementById("edit_2").style.zIndex="1";
document.getElementById("edit").style.zIndex="0";
}




