// ==============================================================
// telepark.cms

// This Software is copyright (c) 2007 by telepark, 
// Inh. Patrick Thomas, www.telepark.de. 
// All rights reserved. 

// You may not modify, extend, alter, reverse engineer or emulate
// the functionality, or create derivative works of the 
// Software in parts or it's entirety without the prior
// written consent of telepark.
// ==============================================================

// DIASHOW
// =======

// reload diashow list
function reloadDiashowList(searchstring,cw) {
	loading(true);
	var s = '';
	if (!searchstring || searchstring == "undefined" || searchstring == '') {
		if (document.getElementById('searchdiashow')) {
			s = encodeURI(document.getElementById('searchdiashow').value);
		}
	}
	else if (searchstring != '') {
		s = encodeURI(searchstring);
	}
	
	var target = domain +  "/modules/diashow/ajax/reloadDiashowList.php";
	
	var xmlhttp = createHttpRequest();
	xmlhttp.open("GET", target + "?searchstring=" + s, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
			//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
				loading();
				if (cw && cw!='' && cw!="undefined") {
					fenster.close();
				}
			}
		}
		catch(e) {
			status = '';
			loading();
			if (cw && cw!='' && cw!="undefined") {
				fenster.close();
			}
		}
	  }
	}
	xmlhttp.send(null);
}

// toggle diashow filter (only active / all dias)
function toggleDiashowFilter(mode) {
	if (document.getElementById('searchdiashow')) var searchstring = document.getElementById('searchdiashow').value;
	else var searchstring = "";
	
	if (mode == "active") {
		var param = "active";
	} else if (mode == "inactive") {
		var param = "inactive";
	} else {
		var param = "";
	}
	
	var xmlhttp = createHttpRequest();
	xmlhttp.open("GET", "../ajax/toggleDiashowFilter.php?mode=" + param, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
			//alert(xmlhttp.responseText);
			reloadDiashowList(searchstring);
			}
		}
		catch(e) {
			status = '';
			reloadDiashowList(searchstring);
		}
	  }
	}
	xmlhttp.send(null);
}

// toggle diashow status (active / inactive)
function toggleDiashowStatus(diaid,newstatus) {
	if (document.getElementById('searchdiashow')) var searchstring = document.getElementById('searchdiashow').value;
	else var searchstring = "";
	
	if (newstatus == 0) var question = 'Do you really want to deactivate this slideshow?';
	else if (newstatus == 1) var question = 'Do you really want to activate this slideshow?';
	var c = confirm(question);
	if (c == true) {
		var xmlhttp = createHttpRequest();
		xmlhttp.open("GET", "../ajax/toggleDiashowStatus.php?diaid=" + diaid + "&status=" + newstatus + "&searchstring=" + searchstring, true);
		xmlhttp.onreadystatechange=function() {
		  // readyState==4 - meaning the load is complete
		  if (xmlhttp.readyState==4) {
			// only if "OK"
			var status = '';
			try {
				status = xmlhttp.status;
				if (status==200) {
				//alert(xmlhttp.responseText);
					eval(xmlhttp.responseText);
					loading();
				}
			}
			catch(e) {
				status = '';
				loading();
			}
		  }
		}
		xmlhttp.send(null);
	}
	else {
		loading();
	}
}

// confirm diashow action
function confirmDiashowAction(mode) {
	loading(true);
	if (mode == "active") {
		var c = confirm("Do you really want to activate the selected slideshows?");
	} else if (mode == "inactive") {
		var c = confirm("Do you really want to deactivate the selected slideshows?");
	} else if (mode == "delete") {
		var c = confirm("Do you really want to delete the selected slideshows?");
	}
	if (c == true) {
		return true;
	} else {
		loading();
		return false;
	}
}

// upload dia image
function uploadSingleDiaImage() {
	loading(true);
	document.uploadDiaImage.submit();
}

// display dia list
function displayDiaList() {
	loading(true);
	var dialist = document.getElementById('dia_images').value;
	var xmlhttp = createHttpRequest();
	var param = "list=" + dialist;
	xmlhttp.open("POST", domain + "/modules/diashow/ajax/displayDiaList.php", true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
			loading();
		}
	  }
	}
	xmlhttp.send(param);
}

// remove single dia from list
function removeDia(img) {
	var c = confirm("Really delete this slide?");
	if (c == true) {
		var dialist = document.getElementById('dia_images').value;
		dialist = dialist.replace(img,"");
		document.getElementById('dia_images').value = dialist;
		displayDiaList();
	}
}

// display next dia (frontend)
function showNextDia(dianr) {
	// Quelle des IMG mit Namen diabild aendern = Diabild anzeigen
	document.getElementById('diaimg').src = alleDias[dianr];
}

