﻿

	/* ------------------------------------------------	*
	 *  Common JavaScriptfile for ProjectX website		*
	 * ------------------------------------------------ *
	 *  Created: 2007-10-20								*
	 *  Author: Thomas Atterberg [thomas@version1.se]	*
	 * ------------------------------------------------ *
	 *  The use of this file or it's functions is		*
	 *  restricted. Pleas contact the author befor		*
	 *  using any of them in out own website			*
	 * ------------------------------------------------ */
	 
	 function OpenCenterdPopup(aLink, aWidth, aHeight, aPageName)
	 {
		var top;
		var left;
		
		if(navigator.userAgent.indexOf("MSIE") > 0)
		{
			top	 = ((document.body.clientHeight - aHeight) / 2) + 50;
			left = (document.body.clientWidth - aWidth) / 2;
		}
		else
		{
			top	 = ((window.innerHeight - aHeight) / 2) + 50;
			left = (window.innerWidth  - aWidth) / 2;
		}
		
		if(top < 0)
			top = 10;
		
		if(left < 0)
			left = 20;
		
		window.open(aLink, aPageName, 'width=' + aWidth + ',height=' + aHeight + ',left=' + left + ',top=' + top);	
	}
	
	function ShowEditPanel(aUrl, aWidth, aHeight, aUpdate)
	{
		var blocker		 = document.getElementById('blocker');
		var iframe		 = document.getElementById('popupeditor');
			
		var windowWidth;
		var windowHeight;

		if(navigator.userAgent.indexOf("MSIE") > 0)
		{
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}
		else
		{
			windowWidth = window.innerWidth;
			windowHeight = window.innerHeight;
		}
		
		if(windowWidth+10 > aWidth && windowHeight+10 > aHeight)
		{
			var left = (windowWidth - aWidth) / 2;
			var top  = ((windowHeight - aHeight) / 2) + 10;
		
			blocker.style.display = "";
		
			iframe.style.display  = "";
			iframe.style.width	  = aWidth;
			iframe.style.height	  = aHeight;
			iframe.style.left	  = left + "px";
			iframe.style.top	  = top + "px";
			iframe.src			  = aUrl;
		}
		else
		{
			if(aUrl.lastIndexOf('?') == -1)
				aUrl += "?open=popup";
			else
				aUrl += "&open=popup";
			
			OpenCenterdPopup(aUrl,aWidth,aHeight,'popup');
		}
	}
	
	function CloseEditWindow(content)
	{
		var popupeditor = document.getElementById('popupeditor');
		
	//	document.getElementById(document.getElementById('contentDiv').value).style.display = '';
	
		document.getElementById('blocker').style.display = 'none';
		
		popupeditor.style.display = 'none';
		popupeditor.src = 'about:blank';
		
	//	var editName = document.getElementById('contentDiv').value;
	//	var editor = document.getElementById(editName);
		
	//	if(content)
	//		editor.innerHTML = content;
	
		//PageMethods.UpdateList(AlertSuccess);
	}
	
	function AlertSuccess()
	{
		alert('Success');
	}
	
	function SetHeight(height)
	{
		var iframe		 = document.getElementById('popupeditor');
		iframe.style.height	  = height + "px";
	}
	
	
	function loadXMLDoc(url)
	{
		// branch for native XMLHttpRequest object
		if (window.XMLHttpRequest) {
			req = new XMLHttpRequest();
			req.onreadystatechange = processReqChange;
			req.open("GET", url, true);
			req.send(null);
			// branch for IE/Windows ActiveX version
		} else if (window.ActiveXObject) {
			req = new ActiveXObject("Microsoft.XMLHTTP");
			if (req) {
				req.onreadystatechange = processReqChange;
				req.open("GET", url, true);
				req.send();
			}
		}
	}
	
	function processReqChange()
	{
		// only if req shows "complete"
		if (req.readyState == 4) {
			// only if "OK"
			if (req.status == 200) {
				document.getElementById("content").innerHTML = req.responseText;
			} else {
				alert("There was a problem retrieving the XML data:\n" + req.statusText);
			}
		}
	}
