/* SVN FILE: $Id: EPSWindows.js 3061 2010-11-11 10:34:15Z theo $ */
/**
 * Project Name : EPSVenue
 *
 * @author $Author: theo $
 * @version $Revision: 3061 $
 * @lastrevision $Date: 2010-11-11 11:34:15 +0100 (Thu, 11 Nov 2010) $
 * @modifiedby $LastChangedBy: theo $
 * @lastmodified $LastChangedDate: 2010-11-11 11:34:15 +0100 (Thu, 11 Nov 2010) $
 */
/*

	2Question
	EPSWindows version 8.0
	part of EPStudio
	Created: Jan 10, 2007
	Modified: Sep 08, 2007
	
	
*/
/*global Zapatec pref_desktop_theme */
/**
  *
  *
  */
function doHandleError(Er) {
	alert(Er + '\nError: \nLine: ' + Er.lineNumber);
}
/**
  *
  *
  */
function getHTTPObject() {
	var xmlhttp;
	/*@cc_on
	@if (@_jscript_version >= 5)
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {
			xmlhttp = false;
		}
	}
	@else
		xmlhttp = false
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest !== undefined) {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp = false;
			alert('Error: @line 54\n' + e);
		}
	}
	return xmlhttp;
}
var http = getHTTPObject();
/**
  * example: 	getURL(url, 'myDiv', {hideWaitIcon:true});
  * example: 	getURL(url, '', {format:'JSON', handler:myHandler, hideWaitIcon:true});
  *
  */
function getURL(url, target, prefs) {
	try {
		var hideWaitIcon = prefs.hideWaitIcon ? this: false;
		var plainID = prefs.plainID ? this: false; // plainID can be pointer (true) or a named element (false)
		var isSynchronous = prefs.isSynchronous ? this: true; // isSynchronous defined synchronous (true) or asynchronous (false) calls
		if(prefs!=null && prefs.format!=undefined) {
			format=prefs.format;
		} else {
			format='http';
		}
		if(prefs!=null && prefs.handler!=undefined) {
			handler=prefs.handler;
		} else {
			handler='';
		}
		try {
			if (!hideWaitIcon ) {
				if (document.getElementById('pleasewait') !== null) {
					document.getElementById('pleasewait').style.display = 'block';
				} else {
					// add element on the fly, if requested
					/*
					var leftPos=document.body.clientWidth/2-16;
					var topPos=document.body.clientHeight/2-16;
					var innerHTML="<img style='position: absolute; left: " + leftPos + "px; top: " + topPos + "px;' src='/EPSVenue/images/cms/wait30trans.gif' alt='please wait...'>";
					var pleaseWaitDiv=document.createElement('div');
					pleaseWaitDiv.id='pleasewait';
					pleaseWaitDiv.style.cssText='position:absolute;top:0px;left:0px;width:100%;height:100%;background-color:#fff;opacity:0.5;filter:alpha(opacity=50,style=0);z-index:1000;display:block';
					pleaseWaitDiv.innerHTML=innerHTML;
					document.getElementsByTagName('body')[0].appendChild(pleaseWaitDiv);
					*/
					var innerHTML="";
					innerHTML+="<div style='display:table;height:100%;width:100%'>";
					innerHTML+="<div style='display:table-cell;vertical-align:middle;text-align:center'>";
					innerHTML+="<img src='/EPSVenue/images/cms/wait30trans.gif' alt='please wait...'>";
					innerHTML+="</div>";
					innerHTML+="</div>";
					var pleaseWaitDiv=document.createElement('div');
					pleaseWaitDiv.id='pleasewait';
					pleaseWaitDiv.style.cssText="position:absolute;top:0px;left:0px;width:100%;height:100%;background-color:#fff;opacity:0.5;filter:alpha(opacity=50,style=0);z-index:1000;display:block";
					pleaseWaitDiv.innerHTML=innerHTML;
					document.getElementsByTagName('body')[0].appendChild(pleaseWaitDiv);
					
				}
			}
		} catch (e) {
			alert('Error: @line 111\n' + e);
		}
		http.open('POST', url, isSynchronous); // open url
		http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
		http.setRequestHeader('Content-Length', encodeURIComponent(url.length));
		if(format=='http') {
			http.onreadystatechange = function () { // handle for the http response
				if (http.readyState === 4) {
					var result = http.responseText; // get result
					var elements = result.split('<__SEPARATOR__>');
					for (var i = 0; i < elements.length; i++) { // add new content, both HTML and Javascript (which is loaded dynamically)
						var isJavascript = elements[i].split('<__SCRIPT__>').length === 2;
						if (document.getElementById(target) !== null) {
							if (isJavascript) { // load Javascript dynamically
								var newJavascript = '' + elements[i].split('<__SCRIPT__>')[1];
								var el = document.createElement('SCRIPT');
								el.text = newJavascript; // the javascript does NOT need the <SCRIPT ...> tags, they are placed with this command
								el.type = "text/javascript"; // the javascript does NOT need the type attribute
								document.getElementById(target).appendChild(el);
							} else {
								if (!plainID && target !== undefined) {
									document.getElementById(target).innerHTML = elements[i]; // load content into named id
								} else if (target !== null) {
									target.innerHTML = elements[i]; // load content into plain id (not a name, but the pointer)
								}
							}
						}
					}
					try {
						if (!hideWaitIcon) {
							document.getElementById('pleasewait').style.display = 'none';
							document.getElementsByTagName('body')[0].removeChild(document.getElementById('pleasewait'));
						}	
					} catch (e) {
					}
				}
			}
		} else if (format=='JSON') {
				http.onreadystatechange = function () { // handle for the http response
				if (http.readyState === 4) {
					try {
						if (!hideWaitIcon) {
							document.getElementsByTagName('body')[0].removeChild(document.getElementById('pleasewait'));
						}			
					} catch (e) {
					}
					handler(http);
				}
			}
		}
		http.send(null);
	} catch (e1) {
		alert('Error EPSWindows @line: 117\n' + e1);
	}
}
/**
  *
  *
  */
function loadXML(url, handler) {
    if (document.implementation && document.implementation.createDocument) {
        var xmldoc = document.implementation.createDocument("", "", null);
        xmldoc.onload = function(  ) { handler(xmldoc); }
        xmldoc.load(url);
    }
    else if (window.ActiveXObject) { 
        var xmldoc = new ActiveXObject("Microsoft.XMLDOM");   // Create doc
        xmldoc.onreadystatechange = function(  ) {             // Specify onload
            if (xmldoc.readyState == 4) {
            	handler(xmldoc);
            }
        }
        xmldoc.load(url);                                     // Start loading!
    }
}
/**
  *
  *
  */
function createWindow(ObjProperties) {
	var win;
	win = Zapatec.Window.setup({
		left: ObjProperties.l ? ObjProperties.l: 50,
		top: ObjProperties.t ? ObjProperties.t: 50,
		width: ObjProperties.w ? ObjProperties.w: 640,
		height: ObjProperties.h ? ObjProperties.h: 480,
		iframeContent: ObjProperties.iframe ? true: false,
		theme: ObjProperties.theme ? ObjProperties.theme: pref_desktop_theme,
		title: ObjProperties.title,
		raiseOnlyOnTitle: false,
		urlContent: ObjProperties.url
	});
	win.zpWinContent = ''; //	win.setStatus('Loading...')
}
