/* Default JavaScript File for Collection Rolf Heyne Website
 * 2005, Wirth & Horn, Informationssysteme GmbH
 */
 
function AjaxObject(url) {                                           // This is the object constructor
	var that=this;                                                    // A workaround for some javascript idiosyncrocies
	var updating = false;                                             // Set to true if this object is already working on a request
	this.callback = function() {}                                     // A post-processing call -- a stub you overwrite.

	this.update = function(passData, method) {                        // Initiates the server call.
		if (!method) { method = "POST"; }
		if (updating==true) { return false; }                          // Abort if we're already processing a call.
//		updating=true;                                                 // Set the updating flag.
		var AJAX = null;                                               // Initialize the AJAX variable.
		try {
			AJAX = new XMLHttpRequest();
		} catch (trymicrosoft) {
			try {
				AJAX = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (othermicrosoft) {
				try {
					AJAX = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (failed) {
					AJAX = null;
				}
			}
		}
		if (AJAX==null) {                                              // If we couldn't initialize Ajax...
			alert("Ihre Browser unterstützt kein AJAX.");               // Sorry msg.                                              
			return false                                                // Return false (WARNING - SAME AS ALREADY PROCESSING!)
		} else {
			AJAX.onreadystatechange = function() {                      // When the browser has the request info..
				if (AJAX.readyState==4 || AJAX.readyState=="complete") { //   see if the complete flag is set.
					if (AJAX.status == 200) {
						that.data = AJAX.responseText.replace(/^\s*([\S ]+)\s*$/,'$1'); //   It is, so put the new data in the object's layer
						that.responseText = AJAX.responseText;
						that.responseXML = AJAX.responseXML;
						delete AJAX;                                       //   delete the AJAX object since it's done.
						updating=false;                                    //   Set the updating flag to false so we can do a new request
						that.callback();                                   //   Call the post-processing function.
					} else {
						// AJAX response error
						alert("Fehler in AJAX Antwort.");
					}
				}                                                        // End Ajax readystate check.
			}                                                           // End create post-process fucntion block.
			var timestamp = new Date();                                 // Get a new date (this will make the url unique)
			if (method == 'POST') {
				AJAX.open(method, urlCall, true);                        // Open the url this object was set-up with.
				AJAX.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				AJAX.setRequestHeader('Content-length', passData.length);
				AJAX.send(passData);
			} else {
				var uri=urlCall+'?'+passData+'&timestamp='+(timestamp*1); // Append date to url (so the browser doesn't cache the call)
				AJAX.open(method, uri, true);                             // Open the url this object was set-up with.
				AJAX.send(null);                                          // Send the request.
			}
			return true;                                                // Everything went a-ok.
		}                                                              // End Ajax setup aok if/else block                 
	}
	
	// This area set up on constructor calls.
	var urlCall = url;                                                // Remember the url associated with this object.
}  
 
function wait(x,url) {
	setTimeout(x);
	this.href=url;
}

function popUp(myURL) {
	var myWindow = window.open(myURL,"meinFenster","width=600,height=400,scrollbars=yes")
	myWindow.focus();
	return false;
}

function w_pdf(tit) {
	pdfwindow=window.open("crh_waschzettel_pdf.cfm?bestellnr="+tit,"PDFDownload","menubar=no,scrollbars=yes,resizable=yes");
}

function switch_tagcloud(type) {
	var ajax = new AjaxObject('getTagCloud.cfm');
	ajax.callback = function () {
		document.getElementById('tag_cloud').innerHTML = this.data;
	}
	ajax.update('type=' + type,'get');
}
