function InitIframe()
{
	var iframe = document.getElementById("intranet_iframe");
	iframe.setAttribute("oldURL", intranet_iframe.document.URL);
}
function ShowIFrame()
{
	var iframe = document.getElementById("intranet_iframe");
    
	//If iframe is already visible, do nothing
	if(iframe.style.display == "") { return; }
	
	//Called on onload iframe event. This event is fired many times.
	//We need to find out if this time the iframe has been loaded with an URL. 
    //if(iframe.src=="") {return;}
	
	//And we need to find out if this time the iframe has been loaded with a document. 
	var objDoc = null;
	try
	{
		//If iframe has been loaded with an URL outside of the current host,
		//this will raise access denied error.
		objDoc = intranet_iframe.document;
	}
	catch(ex)
	{
		//Catch access denied exception, meaning document has been loaded.
		objDoc = null;
	}
	if	(!objDoc || //Check if external url loaded
		(iframe.getAttribute("oldURL") != null && iframe.src != iframe.getAttribute("oldURL"))) //Check if internal url loaded
	{
		//Show iframe
		var cellMain = document.getElementById("content");
		iframe.width = cellMain.offsetWidth-2;
		iframe.height = 285;
		//Enlarge iframe if there's room
		var clientHeight = (document.documentElement.clientHeight) - 500; //500 = approximate header and footer height
		if(clientHeight > iframe.height) iframe.height = clientHeight;
		
		iframe.style.display = "";
		iframe.setAttribute("oldURL", iframe.src);
		//Clear all content except iframe!!
		for(i = cellMain.childNodes.length - 1; i >= 0 ; i--)
		{
		    if(cellMain.childNodes[i] != iframe)
		        cellMain.removeChild(cellMain.childNodes[i]);
		}
	}
}
addEvent(window, "load", InitIframe);
addEvent(window, "load", InitUserForm);

function OpenIframeLink(url)
{
	var iframe = document.getElementById("intranet_iframe");
	iframe.src = url;
}

/*
Script used for user form handling
User forms are created via CuteEditor and sent via email when submitted.
*/
function InitUserForm()
{
	var userForm_Started = false;
	var userSubmit = document.getElementsByTagName("INPUT");
	//Loop through INPUT controls
	for(var i = 0; i < userSubmit.length; i++)
	{
		//Don't do anything until we reach the user form area (avoid breaking other parts of the app)
		if(userForm_Started)
		{
			if(userSubmit[i].type.toUpperCase()=="SUBMIT")
			{
				//The button is a submit button included between the USERFORM_START and USERFORM_END hidden fields. Bind to it the special user form postback function.
				userSubmit[i].onclick = SubmitUserForm;
			}
			else if(userSubmit[i].name == "USERFORM_END")
			{
				//We just reached the end of the user form area. Stop processing to avoid breaking other parts of the app.
				break;
			}
		}
		else if(userSubmit[i].name == "USERFORM_START")
		{
			//Set the flag telling we reached the start of the user form area
			userForm_Started = true;
		}
	}
		
}
