function displayPopup()
{
	var h;
	
	if(jQuery.browser.msie)
	{
		h = document.body.clientHeight <= document.body.offsetHeight?document.body.offsetHeight:document.body.clientHeight;
		if(parseInt(jQuery.browser.version) < 7)
		{
			window.location.href = "#";
			document.getElementById("popup_container").style.position = "absolute";
		}
	}else
	{
		h = document.body.clientHeight <= window.innerHeight?window.innerHeight:document.body.clientHeight;
	}
	
	document.getElementById("popup").style.height = h+"px";
	document.getElementById("popup").style.width = document.body.clientWidth+"px";
	document.getElementById("popup").style.display = "block";
	document.getElementById("popup_container").style.visibility = "visible";
	document.getElementById("popup_container").style.display = "block";
	/*
document.getElementById("popup_container").style.position = "absolute";
	document.getElementById("popup_container").style.position = "fixed";
*/
	$("#popup_container").fadeIn("slow");
	document.getElementById("popup_container").style.top = (window.screen.availHeight /2 - document.getElementById("popup_container").clientHeight / 2 - 100)+"px";
	document.getElementById("popup_container").style.left = (window.screen.availWidth /2 - document.getElementById("popup_container").clientWidth / 2)+"px";	
return false;
}

function hidePopup()
{
	document.getElementById("popup").style.display = "none";
	$("#popup_container").fadeOut("fast");
	document.popupFeedbackForm.email.value = "";
	document.popupFeedbackForm.comments.value = "";
	document.getElementById("popup_error").innerHTML = "";
}


function submitPopupFeedback()
{
	if (document.popupFeedbackForm.email.value != "" && document.popupFeedbackForm.comments.value != "") {
		var url = "/secure/feedback_ajax.cfm?view=sendFeedback";
		var tmpstring = "&email=" + encodeURI(document.popupFeedbackForm.email.value) + "&comments=" + encodeURI(document.popupFeedbackForm.comments.value);
		submitRequest(url + tmpstring);
		hidePopup();
	}else
	{
		document.getElementById("popup_error").style.display = "block";
		document.getElementById("popup_error").innerHTML = "Please fill out the form completely";
	}
}


/************************************************************************************************/

function submitRequest(url)
{
	if (window.XMLHttpRequest)
	{
		req = new XMLHttpRequest();
		req.onreadystatechange = updatePage;
		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 = updatePage;
			req.open("GET", url, true);
			req.send();
		}
	}
}

function updatePage()
{
	if(req.readyState == 4)
	{
	  createXML(req.responseText);
	}
}

function submitFileName()
{
	document.newfileform.submit();
}

function createXML(t)
{
	var tmptext = t;
	tmptext = tmptext.substring(tmptext.indexOf("<"),tmptext.length);
	if (window.ActiveXObject)
	{
		var xmlobject=new ActiveXObject("Microsoft.XMLDOM");
		xmlobject.async="false";
		xmlobject.loadXML(tmptext);
	}
	// code for Mozilla, Firefox, Opera, etc.
	else
	{
		var parser=new DOMParser();
		var xmlobject=parser.parseFromString(tmptext,"text/xml");
	}
	
	root = xmlobject.getElementsByTagName("node");
	
	for(x=0;x<root.length;x++)
	{
		switch(root[x].getElementsByTagName("method")[0].firstChild.data)
		{
			case "add":
				if(document.getElementById(root[x].getElementsByTagName("id")[0].firstChild.data))
				{
					document.getElementById(root[x].getElementsByTagName("id")[0].firstChild.data).innerHTML += root[x].getElementsByTagName("content")[0].firstChild.data;
					setTimeout("addElement('"+root[x].getElementsByTagName("newid")[0].firstChild.data+"',0)","0");
				}
				break;
			case "replace":
				if(document.getElementById(root[x].getElementsByTagName("id")[0].firstChild.data))
				{
					document.getElementById(root[x].getElementsByTagName("id")[0].firstChild.data).innerHTML = root[x].getElementsByTagName("content")[0].firstChild.data;
				}
				break;
			case "delete":
				if(document.getElementById(root[x].getElementsByTagName("id")[0].firstChild.data))
				{
					deleteElement(root[x].getElementsByTagName("id")[0].firstChild.data,90);
				}
				break;
			case "donothing":
				break;
			case "error":
				alert(root[x].getElementsByTagName("content")[0].firstChild.data);
				break;
			case "execute":
				eval(""+root[x].getElementsByTagName("content")[0].firstChild.data);
				break;
		}
	}
}

function deleteElement(id,opac)
{
	if(document.getElementById(id))
	{
		document.getElementById(id).style.background = "#E2CD81";
		if(document.getElementById(id).style.filter)
		{document.getElementById(id).style.filter = "alpha(opacity=."+opac/100+")";}
		if(document.getElementById(id).style.mozOpacity)
		{document.getElementById(id).style.mozOpacity = opac/100;}
		document.getElementById(id).style.opacity = opac/100;
		if(opac == 0)
		{
			document.getElementById(id).parentNode.removeChild(document.getElementById(id));
		}else
		{
			opac = parseInt(opac) - 5;
		}
		setTimeout("deleteElement('"+id+"','"+opac+"')","60");
	}
}

function addElement(id, opac){
	if (opac < 100) {
		document.getElementById(id).style.background = "#A3D7A3";
		if (document.getElementById(id).style.filter) {
			document.getElementById(id).style.filter = "alpha(opacity=." + opac / 100 + ")";
		}
		if (document.getElementById(id).style.mozOpacity) {
			document.getElementById(id).style.mozOpacity = opac / 100;
		}
		document.getElementById(id).style.opacity = opac / 100;
		opac = parseInt(opac) + 5;
		setTimeout("addElement('" + id + "','" + opac + "')", "60");
	}
	else {
		document.getElementById(id).style.background = "transparent";
	}
}
