/* ************************************* */
/* Begin Open Window Functions */
/* ************************************* */
//variables to close all windows when logging out or closing window
openWins = new Array();
curWin = 0;

//function to open a centered window 
function openCenteredWindow( url, width, height)
{
	var left = 0;
	var top = 0;

	if( document.all )
	{
	  top = ((screen.height - height) / 2) - 40; 
	  left = window.top.screenLeft + (window.top.document.body.clientWidth/2) - (width/2);
	}
	else
	{
	  left = (screen.width/2)-(width/2);
	  top = (screen.height/2)-(height/2);
	}
	openWins[curWin++] = window.open( url,"","height=" + (height) + ",width=" + (width) +",left=" +left+",top="+top+",location=no,menubar=no,resizable=yes,status=yes,titlebar=yes,toolbar=no,scrollbars=yes");
}
/* ************************************* */
/* End Open Window Functions */
/* ************************************* */


/* ************************************* */
/* Begin CLOSE WINDOW Functions */
/* ************************************* */
window.onbeforeunload = unloadFcn;
var LaunchSurvey = false;

function unloadFcn()
{	
	if (LaunchSurvey)
	{
		//check to see if they have a pop up blocker
		if (popupBlockerEnabled())
		{
			var strMessage = trim(callrequest_withresponse('../app/core/getsetting.jsp','name=PopupBlockerMessage'));
			if (strMessage.indexOf('username') < 0)
			{
				alert(strMessage);
			}			
		}
		else
		{
			var responsetext = callrequest_withresponse('../app/portlets/survey/checksurveylauncher.jsp','');
			responsetext = trim(responsetext);
			if (responsetext == 'launchsurvey')
			{
				openCenteredWindow( '../app/portlets/survey/survey.jsp', '800', '600');
			}
		}
	}	
}
/* ************************************* */
/* End CLOSE WINDOW Functions */
/* ************************************* */


/* ************************************* */
/* Begin check Pop up blocker Function */
/* ************************************* */
function popupBlockerEnabled()
{
	 var popUpsBlocked = false;
	 var mine = window.open('../app/portlets/survey/closewindow.html','','width=1,height=1,left=0,top=0,scrollbars=no');
	 if(mine)
		popUpsBlocked = false;
	 else
		popUpsBlocked = true;
	 return popUpsBlocked;
}
/* ************************************* */
/* End check Pop up blocker Function */
/* ************************************* */


/* ************************************* */
/* Begin AJAX Functions */
/* ************************************* */
function callrequest_withresponse(href,params)
{
	var httpresponse = '';	
	var _xmlHttp;
	var browser = '';
	// internet explorer    
	try 
	{
		_xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		browser = 'ie';
	} 
	catch(e) 
	{
		try 
		{
			_xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			browser = 'ie';
		} 
		catch(e) 
		{				
			try
			{
				//other browsers
				_xmlHttp = new XMLHttpRequest();
				browser = 'other';
			}
			catch (e)
			{					
			}
		}
	}

	if(_xmlHttp)
	{ 
		_xmlHttp.open("POST", href, false);
		_xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		_xmlHttp.setRequestHeader("Content-length", params.length);
		_xmlHttp.setRequestHeader("Connection", "close");


		if (browser == 'ie')
		{
			_xmlHttp.onreadystatechange=function() 
			{
				if (_xmlHttp.readyState==4) 
				{
					httpresponse = _xmlHttp.responseText;				
				}
			}
		}
		else
		{
			_xmlHttp.onload=function() 
			{
				if (_xmlHttp.readyState==4) 
				{
					httpresponse = _xmlHttp.responseText;				
				}
			}
		}

		_xmlHttp.send(params);	
	}
	return httpresponse;
}
/* ************************************* */
/* End AJAX Functions */
/* ************************************* */





