//<script language="javascript" %>

//
// Display a text selection dialog and get text result
//
function TextDialog(sTitle)
{
	// Default dialog title
	if(typeof(sTitle) == "undefined" || sTitle == null)
	{
		sTitle = "Enter Text";
	}	
	
	// Show dialog
	var sWindowResult = window.showModalDialog("WebsDialogModal.aspx?PageTitle=" + sTitle.replace(" ", "+") + "&page=websTextDialog.aspx?reference=" + sUserLoginId, sTitle,"dialogHeight:200px;dialogWidth:450px;center:Yes;help:No;resizable:No;status:No;scroll:no" );
								
	// Return result
	if( typeof(sWindowResult) != "undefined" && sWindowResult != null )
	{		
		return sWindowResult;
	}
	
	return "";	
}

//
// Display a file upload dialog and get result
// Returns an array of saved Image Id and real client file name
// or null if invalid result
//
function ImageUploadDialog(sTitle)
{
	// Default dialog title
	if(typeof(sTitle) == "undefined" || sTitle == null)
	{
		sTitle = "Upload Image";
	}	
	
	var sWindowResult = window.showModalDialog("WebsDialogModal.aspx?PageTitle=" + sTitle.replace("", "+") + "&page=websImageUploadDialog.aspx?reference=" + sUserLoginId, sTitle,"dialogHeight:200px;dialogWidth:450px;center:Yes;help:No;resizable:No;status:No;scroll:no" );
		
	if( typeof(sWindowResult) != "undefined" && sWindowResult != null )
	{
		// Parse result string from dialog
		var aResult = sWindowResult.split("||");
		if(aResult.length == 2)
		{								
			return aResult
		}
	}
	
	return null;
}

//
// Display a file upload dialog and get result
// Returns an array of saved Attachment Id and real client file name
// or null if invalid result
//
function AttachmentUploadDialog(sTitle)
{
	// Default dialog title
	if(typeof(sTitle) == "undefined" || sTitle == null)
	{
		sTitle = "Upload Attachment";
	}	
	
	var sWindowResult = window.showModalDialog("WebsDialogModal.aspx?PageTitle=" + sTitle.replace("", "+") + "&page=websAttachmentUploadDialog.aspx?reference=" + sUserLoginId, sTitle,"dialogHeight:200px;dialogWidth:450px;center:Yes;help:No;resizable:No;status:No;scroll:no" );
		
	if( typeof(sWindowResult) != "undefined" && sWindowResult != null )
	{
		// Parse result string from dialog
		var aResult = sWindowResult.split("||");
		if(aResult.length == 2)
		{								
			return aResult
		}
	}
	
	return null;
}
		
function ChangePage( sPage, sFrameName, sQueryString )
{
	if ( typeof( sFrameName ) == "undefined" )
		sFrameName = "frameMain";				
			
	/*
	if( typeof( sQueryString ) != "undefined" )
	{
		if( sPage.indexOf("?") != -1 )
		{
			var aPage = sPage.split("?");
			sPage = aPage[0] + sQueryString + "&" + aPage[1];
		}
		else
		{		
			sPage += sQueryString;		
		}
	}
	*/
	
	if( sUserLoginId != 0 )
	{
		if( sPage.indexOf("?") == -1 )
			sPage += "?";
		else
			sPage += "&";	
			
		sPage += "reference=" + sUserLoginId;
	}

	if( typeof( sQueryString ) != "undefined" )
	{
		if( sPage.indexOf("?") != -1 )
			sPage += "&" + sQueryString;
		else
			sPage += "?" + sQueryString;		
	}

	if( typeof( eval( "window.parent." + sFrameName ) ) == "undefined" )
	{				
		document.forms.frmNavigation.action = sPage;
		document.forms.frmNavigation.submit();
	}
	else
	{		
		eval("window.parent." + sFrameName + ".document.location.href = \"" + sPage + "\"");
	}
	
}
	
// Popup window, no return value
function WinPopup(winUrl, winName, winWidth, winHeight, winFeatures ) 
{
	WinPopupObj(winUrl, winName, winWidth, winHeight, winFeatures); 
}

// Popup window, returns window object
function WinPopupObj(winUrl, winName, winWidth, winHeight, winFeatures ) {
	
	var clientWidth = screen.width;
	var clientHeight = screen.height;
	var leftPos = (clientWidth - winWidth)/2;
	var topPos = (clientHeight - winHeight)/2;		
	if(leftPos < 0) {
		leftPos = 0;
	}
	if(topPos < 0) {
		topPos = 0;
	}
	if(winFeatures == null) {
		winFeatures = "left=" + leftPos + ",top=" + topPos + ",width=" + winWidth +",height=" + winHeight +",status=1,address=0,location=0,scrollbars=1,resizable=1";
	} else {
		winFeatures = "left=" + leftPos + ",top=" + topPos + ",width=" + winWidth +",height=" + winHeight +"," + winFeatures;
	}	

	var oWindow = window.open( winUrl, winName, winFeatures );	
	
	oWindow.focus();
	
	return oWindow;
}

//
// Handle page cancel functionality in webs pages
//
function PageCancel(ReturnUrl)
{
	if( ReturnUrl != "" )
	{
		document.location.href = ReturnUrl;
	}
	else
	{
		// Refresh the page
		document.location.href 	= document.location.href;
	}
}

//</script>