
// ==============================================================
// 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.
// ==============================================================

function getfocus() {
	self.focus();
}

function newWindow(url,name,width,height) {
	fenster = window.open (
	url,
	name, 					// name
	'toolbar=0' 			// tool bar 
	+',dependent=1'			// dependent
	+',location=0' 			// address bar
	+',directories=0' 		// additional bars
	+',status=0' 			// status bar
	+',menubar=0' 			// menu bar
	+',scrollbars=1' 		// scroll bars
	+',resizable=1' 		// window resizable
	+',width=' + width 		// window width in pixels
	+',height=' + height 	// window height in pixels
	);
}

function createHttpRequest() {
	var xmlhttp;
 	try {
 		xmlhttp = new XMLHttpRequest();
 	} catch (e) {
  		var XmlHttpVersions = new Array('MSXML2.XMLHTTP.6.0',
  										'MSXML2.XMLHTTP.5.0',
  										'MSXML2.XMLHTTP.4.0',
  										'MSXML2.XMLHTTP.3.0',
  										'MSXML2.XMLHTTP',
  										'Microsoft.XMLHTP'
  										);
  		for (var i = 0; i<XmlHttpVersions.length && !xmlhttp; i++) {
  			try {
  				xmlhttp = new ActiveXObject(XmlHttpVersions[i]);
  			}
  			catch(e) {
  			}
  		}
 	}
 	if (!xmlhttp) {
 		alert('Error creating the XMLHttpRequest object.');
 	} else {
		return xmlhttp;
 	}
}

function reloadTopicList(searchstring,referer,querystring,month,year,old,all,backend,sv) {
	var s = '';
	if (searchstring!='') var s = encodeURI(searchstring);
	
	//alert("searchstring: " + searchstring);
	//alert("referer: " + referer);
	//alert("querystring: " + querystring);
	//alert("month: " + month);
	//alert("year: " + year);
	//alert("old: " + old);
	//alert("all: " + all);
	//alert("sv: " + sv);
	//alert("backend: " + backend);
	
	var xmlhttp = createHttpRequest();
	//alert(querystring);
	currentURL = window.location.href;
	webURL = currentURL.split("index.php");
	//searchURL = currentURL.split("forum.php");
	// web
	if (webURL.length>1) targetURL = "admin/modules/forum/ajax/reloadtopiclist_web.php";
	// admin safe form
	else if(sv==true) targetURL = "reloadtopiclist.php";
	// admin form
	else targetURL = "ajax/reloadtopiclist.php";
	//alert(targetURL);
	xmlhttp.open("GET", targetURL + "?searchstring=" + s + "&referer=" + referer + "&querystring=" + querystring + "&month=" + month + "&year=" + "&old=" + old + "&all=" + all + "&backend=" + backend, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  //alert("ReadyState: " + xmlhttp.readyState);
	  if (xmlhttp.readyState==4) {
		// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			//alert("Status: " + status);
			if (status==200) {
				//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

function displayReplies(forumid,searchstring) {
	var s = '';
	if (searchstring!='') var s = encodeURI(searchstring);
	
	var xmlhttp = createHttpRequest();
	
	var targetURL = "ajax/displayreplies.php";
	
	xmlhttp.open("GET", targetURL + "?forumid=" + forumid + "&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);
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

function displayForm(forumid) {
	
	//alert(forumid);
	
	var xmlhttp = createHttpRequest();
	
	var targetURL = "ajax/displayform.php";
	
	xmlhttp.open("GET", targetURL + "?forumid=" + forumid, 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);
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

function saveEditData(forumid) {
	var xmlhttp = createHttpRequest();
	
	var targetURL = "ajax/saveform.php";
	
	xmlhttp.open("GET", targetURL + "?forumid=" + forumid, 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);
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

function deleteTopic(topicid) {
	//alert(topicid);
	
	var c = confirm(deletetopicconfirm);
	if (c == true) {
		var xmlhttp = createHttpRequest();
		xmlhttp.open("GET", "ajax/deletetopic.php?id=" + topicid , 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);
				}
			}
			catch(e) {
				status = '';
			}
		  }
		}
		xmlhttp.send(null);
	}
	else
		return false;
}

function deletePost(postid) {
	var c = confirm(deletepostconfirm);
	if (c == true) {
		var xmlhttp = createHttpRequest();
		xmlhttp.open("GET", "ajax/deletepost.php?id=" + postid , 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);
				}
			}
			catch(e) {
				status = '';
			}
		  }
		}
		xmlhttp.send(null);
	}
	else
		return false;
}
