function calendar(input_id, new_date){
	window.clearTimeout(window.popup);
	new AjaxReq("POST", "/kunde/popup/calendar.php", {
		"id":input_id,
		"selected_date":gE(input_id).value,
		"new_date":new_date
	},
	function(oHttp){
		if(oHttp.responseText){
			gE('popup').innerHTML = oHttp.responseText;
			Show('popup');
		}
		else{
			Hide('popup');
		}
	}
	);
}


function changeCalendar(input_id, new_date){
	if(new_date.match(/\d{4}-\d{2}-\d{2}/)){
		calendar(input_id, new_date);
	}else{
		Hide('popup');
		window.clearTimeout(window.popup);
	}
}


function chooseDate(input_id,new_value){
	gE(input_id).value = new_value;
	Hide('popup');
}


function rotrinPickTur(kategoriId){
	new AjaxReq("POST", "/kunde/rotrin_pick_tur.php", {
		"search_tur":gE('findtur').value,
		"tur_type":gE('tur_type').value,
		"tur_id":gE('tur_id').value,
		"rs_id":gE('rs_id').value,
		"kategori":kategoriId
	}, 
	function(oHttp){
		if(oHttp.responseText){
			gE('rotrinPickTur').innerHTML = oHttp.responseText;
			Show('rotrinPickTur');
			$(document).ready(function(){
				$('#tur_gpx').fancybox({
					'width': '75%', 'height': '75%', 'autoScale':false, 'transitionIn':'none','transitionOut':'none','type'	: 'iframe'
				});
			});
			$(document).ready(function(){
				$('a#tur_image').fancybox();
			});
		}
		else{
			Hide('rotrinPickTur');
		}
	}
	);
}


function rotrinPickBaad(kategoriId){
	if(gE('baad_lock_kodeord') != null){
		baad_lock_kodeord = gE('baad_lock_kodeord').value;
	}
	else{
		baad_lock_kodeord = null;
	}
	new AjaxReq("POST", "/kunde/rotrin_pick_baad.php", {
		"search_baad":gE('findbaad').value,
		"baad_form":gE('baad_form').value,
		"baad_type":gE('baad_type').value,
		"baad_id":gE('baad_id').value,
		"baad_lock_kodeord":baad_lock_kodeord,
		"rs_id":gE('rs_id').value,
		"kategori":kategoriId
	}, 
	function(oHttp){
		if(oHttp.responseText){
			gE('rotrinPickBaad').innerHTML = oHttp.responseText;
			Show('rotrinPickBaad');
			$(document).ready(function() {
				$("a#baad_image").fancybox();
			});
		}
		else{
			Hide('rotrinPickBaad');
		}
	}
	);
}


function rotrinPickMedlem(nrId){
	new AjaxReq("POST", "/kunde/rotrin_pick_medlem.php", {
		"search_medlem":gE('findmedlem['+nrId+']').value,
		"rs_id":gE('rs_id').value,
		"number":nrId,
		"medlem":gE('medlem['+nrId+']').value	
	}, 
	function(oHttp){
		if(oHttp.responseText){
			gE('rotrinPickMedlem['+nrId+']').innerHTML = oHttp.responseText;
			Show('rotrinPickMedlem['+nrId+']');
			$(document).ready(function() {
				$("a#medlem_image").fancybox();
			});
		}
		else{
			Hide('rotrinPickMedlem['+nrId+']');
			
		}
	}
	);
}


function popupGPXmap(input_id){
	window.clearTimeout(window.popup);
	new AjaxReq("POST", "http://www.roseddel.dk/kunde/gpx/GPXmap.php?xmlfile=vrk_1.gpx", {
		"id":input_id
	},
	function(oHttp){
		if(oHttp.responseText){
			gE('popup').innerHTML = oHttp.responseText;
			Show('popup');
		}
		else{
			Hide('popup');
		}
	}
	);
}


function roseddelInfo(input_id){
	window.clearTimeout(window.popup);
	new AjaxReq("POST", "/kunde/popup/info.php", {
		"rs_id":input_id
	},
	function(oHttp){
		if(oHttp.responseText){
			gE('popup').innerHTML = oHttp.responseText;
			Show('popup');
			
		}
		else{
			Hide('popup');
			
		}
	}
	);
}


function filterTur(){
	new AjaxReq("POST", "/kunde/filter_tur.php", {
		"tur_kategori":gE('tur_kategori').value,
		"tur_type":gE('tur_type').value,
		"tur_id":gE('tur_id').value
	},
	function(oHttp){
		if(oHttp.responseText){
			gE('filterTur').innerHTML = oHttp.responseText;
			Show('filterTur');
		}
		else{
			Hide('filterTur');
			
		}
	}
	);
}


function filterBaad(){
	new AjaxReq("POST", "/kunde/filter_baad.php", {
		"baad_kategori":gE('baad_kategori').value,
		"baad_form":gE('baad_form').value,
		"baad_type":gE('baad_type').value,
		"baad_id":gE('baad_id').value
	},
	function(oHttp){
		if(oHttp.responseText){
			gE('filterBaad').innerHTML = oHttp.responseText;
			Show('filterBaad');
		}
		else{
			Hide('filterBaad');
			
		}
	}
	);
}


function listStatsMedlem(sortBy, orderBy){
	new AjaxReq("POST", "/kunde/stats_medlem_list.php", {
		"kategori":gE('kategori').value,
		"tur_kategori":gE('tur_kategori').value,
		"tur_type":gE('tur_type').value,
		"tur_id":gE('tur_id').value,
		"baad_kategori":gE('baad_kategori').value,
		"baad_form":gE('baad_form').value,
		"baad_type":gE('baad_type').value,
		"baad_id":gE('baad_id').value,
		"gender":gE('gender').value,
		"age_from":gE('age_from').value,
		"age_to":gE('age_to').value,
		"medlem_search":gE('medlem_search').value,
		"aktivitet":gE('aktivitet').value,
		"date_from":gE('date_from').value,
		"date_to":gE('date_to').value,
		"season":gE('season').value,
		"sorter":sortBy,
		"order":orderBy
	},
	function(oHttp){
		if(oHttp.responseText){
			gE('listStatsMedlem').innerHTML = oHttp.responseText;
			Show('listStatsMedlem');
		}
		else{
			Hide('listStatsMedlem');
			
		}
	}
	);
}


function listStatsRace(sortBy, orderBy){
	new AjaxReq("POST", "/kunde/stats_race_list.php", {
		"tur_kategori":gE('tur_kategori').value,
		"tur_type":gE('tur_type').value,
		"tur_id":gE('tur_id').value,
		"baad_kategori":gE('baad_kategori').value,
		"baad_form":gE('baad_form').value,
		"baad_type":gE('baad_type').value,
		"baad_id":gE('baad_id').value,
		"gender":gE('gender').value,
		"age_from":gE('age_from').value,
		"age_to":gE('age_to').value,
		"medlem_search":gE('medlem_search').value,
		"aktivitet":gE('aktivitet').value,
		"date_from":gE('date_from').value,
		"date_to":gE('date_to').value,
		"season":gE('season').value,
		"sorter":sortBy,
		"order":orderBy
	},
	function(oHttp){
		if(oHttp.responseText){
			gE('listStatsRace').innerHTML = oHttp.responseText;
			Show('listStatsRace');
		}
		else{
			Hide('listStatsRace');
		}
	}
	);
}


function listRosedler(sortBy, orderBy, pageBy){
	new AjaxReq("POST", "/kunde/administration/rosedler_list.php", {
		"tur_kategori":gE('tur_kategori').value,
		"tur_type":gE('tur_type').value,
		"tur_id":gE('tur_id').value,
		"baad_kategori":gE('baad_kategori').value,
		"baad_form":gE('baad_form').value,
		"baad_type":gE('baad_type').value,
		"baad_id":gE('baad_id').value,
		"gender":gE('gender').value,
		"age_from":gE('age_from').value,
		"age_to":gE('age_to').value,
		"medlem_search":gE('medlem_search').value,
		"aktivitet":gE('aktivitet').value,
		"date_from":gE('date_from').value,
		"date_to":gE('date_to').value,
		"season":gE('season').value,
		"sorter":sortBy,
		"order":orderBy,
		"paging":pageBy,
		"pr_page":gE('pr_page').value
	},
	function(oHttp){
		if(oHttp.responseText){
			gE('listRosedler').innerHTML = oHttp.responseText;
			Show('listRosedler');
			$(document).ready(function() {
				$('a#roseddel_info').fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
				});
			});
		}
		else{
			Hide('listRosedler');
			
		}
	}
	);
}


function listMedlem(sortBy, orderBy, pageBy){
	new AjaxReq("POST", "/kunde/administration/medlem_list.php", {
		"gender":gE('gender').value,
		"age_from":gE('age_from').value,
		"age_to":gE('age_to').value,
		"medlem_search":gE('medlem_search').value,
		"sorter":sortBy,
		"order":orderBy,
		"paging":pageBy,
		"pr_page":gE('pr_page').value
	},
	function(oHttp){
		if(oHttp.responseText){
			gE('listMedlem').innerHTML = oHttp.responseText;
			Show('listMedlem');
		}
		else{
			Hide('listMedlem');
			
		}
	}
	);
}


function listMedlem_reg(sortBy, orderBy, pageBy){
	new AjaxReq("POST", "/kunde/administration/medlem_reg_list.php", {
		"sorter":sortBy,
		"order":orderBy,
		"paging":pageBy,
		"pr_page":gE('pr_page').value
	},
	function(oHttp){
		if(oHttp.responseText){
			gE('listMedlem_reg').innerHTML = oHttp.responseText;
			Show('listMedlem_reg');
		}
		else{
			Hide('listMedlem_reg');
			
		}
	}
	);
}



function listBaad(sortBy, orderBy, pageBy){
	new AjaxReq("POST", "/kunde/administration/baad_list.php", {
		"baad_kategori":gE('baad_kategori').value,
		"baad_form":gE('baad_form').value,
		"baad_type":gE('baad_type').value,
		"baad_id":gE('baad_id').value,
		"sorter":sortBy,
		"order":orderBy,
		"paging":pageBy,
		"pr_page":gE('pr_page').value
	},
	function(oHttp){
		if(oHttp.responseText){
			gE('listBaad').innerHTML = oHttp.responseText;
			Show('listBaad');
		}
		else{
			Hide('listBaad');
		}
	}
	);
}


function listBaad_type(sortBy, orderBy, pageBy){
	new AjaxReq("POST", "/kunde/administration/baad_type_list.php", {
		"baad_kategori":gE('baad_kategori').value,
		"baad_form":gE('baad_form').value,
		"baad_type":gE('baad_type').value,
		"baad_id":gE('baad_id').value,
		"sorter":sortBy,
		"order":orderBy,
		"paging":pageBy,
		"pr_page":gE('pr_page').value
	},
	function(oHttp){
		if(oHttp.responseText){
			gE('listBaad_type').innerHTML = oHttp.responseText;
			Show('listBaad_type');
		}
		else{
			Hide('listBaad_type');
		}
	}
	);
}


function listBaad_lock(sortBy, orderBy, pageBy){
	new AjaxReq("POST", "/kunde/administration/baad_lock_list.php", {
		"baad_kategori":gE('baad_kategori').value,
		"baad_form":gE('baad_form').value,
		"baad_type":gE('baad_type').value,
		"baad_id":gE('baad_id').value,
		"sorter":sortBy,
		"order":orderBy,
		"paging":pageBy,
		"pr_page":gE('pr_page').value
	},
	function(oHttp){
		if(oHttp.responseText){
			gE('listBaad_lock').innerHTML = oHttp.responseText;
			Show('listBaad_lock');
		}
		else{
			Hide('listBaad_lock');
		}
	}
	);
}


function listBaadStatistik(sortBy, orderBy, pageBy){
	new AjaxReq("POST", "/kunde/administration/baad_stats_list.php", {
		"baad_kategori":gE('baad_kategori').value,
		"baad_form":gE('baad_form').value,
		"baad_type":gE('baad_type').value,
		"baad_id":gE('baad_id').value,
		"aktivitet":gE('aktivitet').value,
		"date_from":gE('date_from').value,
		"date_to":gE('date_to').value,
		"season":gE('season').value,
		"sorter":sortBy,
		"order":orderBy,
		"paging":pageBy
	},
	function(oHttp){
		if(oHttp.responseText){
			gE('listBaadStatistik').innerHTML = oHttp.responseText;
			Show('listBaadStatistik');
		}
		else{
			Hide('listBaadStatistik');
			
		}
	}
	);
}


function listTur(sortBy, orderBy, pageBy){
	new AjaxReq("POST", "/kunde/administration/tur_list.php", {
		"tur_kategori":gE('tur_kategori').value,
		"tur_type":gE('tur_type').value,
		"tur_id":gE('tur_id').value,
		"sorter":sortBy,
		"order":orderBy,
		"paging":pageBy,
		"pr_page":gE('pr_page').value
	},
	function(oHttp){
		if(oHttp.responseText){
			gE('listTur').innerHTML = oHttp.responseText;
			Show('listTur');
			
		}
		else{
			Hide('listTur');
			
		}
	}
	);
}


function listTur_type(sortBy, orderBy, pageBy){
	new AjaxReq("POST", "/kunde/administration/tur_type_list.php", {
		"tur_kategori":gE('tur_kategori').value,
		"tur_type":gE('tur_type').value,
		"tur_id":gE('tur_id').value,
		"sorter":sortBy,
		"order":orderBy,
		"paging":pageBy,
		"pr_page":gE('pr_page').value
	},
	function(oHttp){
		if(oHttp.responseText){
			gE('listTur_type').innerHTML = oHttp.responseText;
			Show('listTur_type');
			
		}
		else{
			Hide('listTur_type');
			
		}
	}
	);
}


function listTurStatistik(sortBy, orderBy, pageBy){
	new AjaxReq("POST", "/kunde/administration/tur_stats_list.php", {
		"tur_kategori":gE('tur_kategori').value,
		"tur_type":gE('tur_type').value,
		"tur_id":gE('tur_id').value,
		"aktivitet":gE('aktivitet').value,
		"date_from":gE('date_from').value,
		"date_to":gE('date_to').value,
		"season":gE('season').value,
		"sorter":sortBy,
		"order":orderBy,
		"paging":pageBy
	},
	function(oHttp){
		if(oHttp.responseText){
			gE('listTurStatistik').innerHTML = oHttp.responseText;
			Show('listTurStatistik');
			
		}
		else{
			Hide('listTurStatistik');
			
		}
	}
	);
}


function listAktivitet(sortBy, orderBy, pageBy){
	new AjaxReq("POST", "/kunde/administration/aktivitet_list.php", {
		"season":gE('season').value,
		"sorter":sortBy,
		"order":orderBy,
		"paging":pageBy,
		"pr_page":gE('pr_page').value
	},
	function(oHttp){
		if(oHttp.responseText){
			gE('listAktivitet').innerHTML = oHttp.responseText;
			Show('listAktivitet');
			
		}
		else{
			Hide('listAktivitet');
			
		}
	}
	);
}


function listSeason(sortBy, orderBy, pageBy){
	
	new AjaxReq("POST", "/kunde/administration/season_list.php", {
		"sorter":sortBy,
		"order":orderBy,
		"paging":pageBy,
		"pr_page":gE('pr_page').value
	},
	function(oHttp){
		if(oHttp.responseText){
			gE('listSeason').innerHTML = oHttp.responseText;
			Show('listSeason');
			
		}
		else{
			Hide('listSeason');
			
		}
	}
	);
}


function listLogging(sortBy, orderBy, pageBy){
	
	new AjaxReq("POST", "/kunde/administration/logging_list.php", {
		"log_database":gE('log_database').value,
		"log_case":gE('log_case').value,
		"log_user_id":gE('log_user_id').value,
		"date_from":gE('date_from').value,
		"date_to":gE('date_to').value,
		"sorter":sortBy,
		"order":orderBy,
		"paging":pageBy,
		"pr_page":gE('pr_page').value
	},
	function(oHttp){
		if(oHttp.responseText){
			gE('listLogging').innerHTML = oHttp.responseText;
			Show('listLogging');
			
		}
		else{
			Hide('listLogging');
			
		}
	}
	);
}


function listSikkerhed(sortBy, orderBy, pageBy){
	
	new AjaxReq("POST", "/kunde/administration/sikkerhed_list.php", {
		"sorter":sortBy,
		"order":orderBy,
		"paging":pageBy
	},
	function(oHttp){
		if(oHttp.responseText){
			gE('listSikkerhed').innerHTML = oHttp.responseText;
			Show('listSikkerhed');
			
		}
		else{
			Hide('listSikkerhed');
			
		}
	}
	);
}


function listSikkerhed_ip(sortBy, orderBy, pageBy){
	
	new AjaxReq("POST", "/kunde/administration/sikkerhed_ip_list.php", {
		"sorter":sortBy,
		"order":orderBy,
		"paging":pageBy,
		"pr_page":gE('pr_page').value
	},
	function(oHttp){
		if(oHttp.responseText){
			gE('listSikkerhed_ip').innerHTML = oHttp.responseText;
			Show('listSikkerhed_ip');
			
		}
		else{
			Hide('listSikkerhed_ip');
			
		}
	}
	);
}


function adminBaadPick(bdID){
	
	new AjaxReq("POST", "/kunde/administration/baad_pick_baadtype.php", {
		"baad_kategori":gE('baad_kategori['+bdID+']').value,
		"baad_form":gE('baad_form['+bdID+']').value,
		"baad_type":gE('baad_type['+bdID+']').value,
		"baad_id":bdID
	},
	function(oHttp){
		if(oHttp.responseText){
			gE('adminBaadPick['+bdID+']').innerHTML = oHttp.responseText;
			Show('adminBaadPick['+bdID+']');
			
		}
		else{
			Hide('adminBaadPick['+bdID+']');
			
		}
	}
	);
}


function adminBaad_lockPickBaad(bdID){
	new AjaxReq("POST", "/kunde/administration/baad_lock_pick_baad.php", {
		"baad_kategori":gE('baad_kategori['+bdID+']').value,
		"baad_form":gE('baad_form['+bdID+']').value,
		"baad_type":gE('baad_type['+bdID+']').value,
		"baad_id":bdID
	},
	function(oHttp){
		if(oHttp.responseText){
			gE('adminBaad_lockPickBaad['+bdID+']').innerHTML = oHttp.responseText;
			Show('adminBaad_lockPickBaad['+bdID+']');
		}
		else{
			Hide('adminBaad_lockPickBaad['+bdID+']');
		}
	}
	);
}


function adminBaad_lockPickMedlem(bl_Id){
	new AjaxReq("POST", "/kunde/administration/baad_lock_pick_medlem.php", {
		"search_medlem":gE('findmedlem['+bl_Id+']').value,
		"bl_Id":bl_Id
	}, 
	function(oHttp){
		if(oHttp.responseText){
			gE('adminBaad_lockPickMedlem['+bl_Id+']').innerHTML = oHttp.responseText;
			Show('adminBaad_lockPickMedlem['+bl_Id+']');
		}
		else{
			Hide('adminBaad_lockPickMedlem['+bl_Id+']');
		}
	}
	);
}


function adminMedlemPickMedlem(ml_Id){
	new AjaxReq("POST", "/kunde/administration/medlem_pick_medlem.php", {
		"search_medlem":gE('findmedlem['+ml_Id+']').value,
		"ml_Id":ml_Id
	}, 
	function(oHttp){
		if(oHttp.responseText){
			gE('adminMedlemPickMedlem['+ml_Id+']').innerHTML = oHttp.responseText;
			Show('adminMedlemPickMedlem['+ml_Id+']');
		}
		else{
			Hide('adminMedlemPickMedlem['+ml_Id+']');
		}
	}
	);
}


function adminBaad_typePick(btID){
	
	new AjaxReq("POST", "/kunde/administration/baad_type_pick_baadform.php", {
		"baad_kategori":gE('baad_kategori['+btID+']').value,
		"baad_form":gE('baad_form['+btID+']').value,
		"baad_type":btID
	},
	function(oHttp){
		if(oHttp.responseText){
			gE('adminBaad_typePick['+btID+']').innerHTML = oHttp.responseText;
			Show('adminBaad_typePick['+btID+']');
			
		}
		else{
			Hide('adminBaad_typePick['+btID+']');
			
		}
	}
	);
}





function adminTurPick(trID){
	
	new AjaxReq("POST", "/kunde/administration/tur_pick_farvand.php", {
		"tur_kategori":gE('tur_kategori['+trID+']').value,
		"tur_type":gE('tur_type['+trID+']').value,
		"tur_id":trID
	},
	function(oHttp){
		if(oHttp.responseText){
			gE('adminTurPick['+trID+']').innerHTML = oHttp.responseText;
			Show('adminTurPick['+trID+']');
			
		}
		else{
			Hide('adminTurPick['+trID+']');
			
		}
	}
	);
}


function listUserStatistik(sortBy, orderBy, pageBy){
	
	new AjaxReq("POST", "/kunde/administration/user_stats_list.php", {
		"season":gE('season').value,
		"sorter":sortBy,
		"order":orderBy,
		"paging":pageBy
	},
	function(oHttp){
		if(oHttp.responseText){
			gE('listUserStatistik').innerHTML = oHttp.responseText;
			Show('listUserStatistik');
		}
		else{
			Hide('listUserStatistik');
			
		}
	}
	);
}


function passGenerator(idBy, length, special){
  var iteration = 0;
  var password = "";
  var randomNumber;
  if(special == undefined){
      var special = false;
  }
  while(iteration < length){
    randomNumber = (Math.floor((Math.random() * 100)) % 94) + 33;
    if(!special){
      if ((randomNumber >=33) && (randomNumber <=47)) { continue; }
      if ((randomNumber >=58) && (randomNumber <=64)) { continue; }
      if ((randomNumber >=91) && (randomNumber <=96)) { continue; }
      if ((randomNumber >=123) && (randomNumber <=126)) { continue; }
    }
    iteration++;
    password += String.fromCharCode(randomNumber);
  }
  gE(idBy).value = password;
}


function Hide(div_id){
	gE(div_id).style.display = 'none';
}
 
function Show(div_id){
	gE(div_id).style.display = 'block';
}

function HideShow(div_id) {
	if(gE(div_id).style.display != 'block'){
		gE(div_id).style.display = 'block';
	}     
	else {
		gE(div_id).style.display = 'none';
	}
}

function move(div_id, y_axis, x_axis){
	if(y_axis + 300 > window.screen.height){
		gE(div_id).style.top = document.documentElement.scrollTop + y_axis - 250 + "px";
	}
	else{
		gE(div_id).style.top = document.documentElement.scrollTop + y_axis + 20 + "px";		
	}
	if(x_axis + 300 > window.screen.width){
		gE(div_id).style.left = document.documentElement.scrollLeft + x_axis - 200 + "px";
	}
	else{
		gE(div_id).style.left = document.documentElement.scrollLeft + x_axis + 20 + "px";	
	}
}
