//=========================================================================
//
//
//=========================================================================
function callback(url, params)
{ 
	// url:    URL to invoke
	// params: string object to pass to the remote URL
	
	// Add some parameters to the query string
	var pageUrl = url + "?callback=true" + params;
	var xmlRequest;
	if (window.ActiveXObject)//using IE
	{
		// Initialize the XmlHttp object
		xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	else if (window.XMLHttpRequest)//using Mozilla
	{
		xmlRequest=new XMLHttpRequest();
		xmlRequest.overrideMimeType("text/xml"); 
	}
	// Initialize the XmlHttp object
	//var xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
	   
	// Prepare for a POST statement and synchronous. (All this is 
	// arbitrary and can be changed in your own implementation.)
	xmlRequest.open("POST", pageUrl, false);
	xmlRequest.setRequestHeader("Content-Type", 
			"application/x-www-form-urlencoded");
	xmlRequest.send(''); 

	// Return the XmlHttp object
	return xmlRequest;
}


//=========================================================================
// 
//=========================================================================
function isFirefox()
{
	var isFirefox = false;
	
	if(navigator.userAgent.indexOf("Firefox") > -1)
		isFirefox = true;
		
	return isFirefox;
}


//=========================================================================
// Function: isNumber
// Purpose: Checks to see if the control that currently lost focus has a valid numeric
// value.  If not set the control as the ERRORCTL and then set the error flag.
// We can't maintain focus on the error control here, so when the onfocus event
// of the next control fires we place focus back on ERRORCTL and inform the user
// of the problem. In this way we force the error to be corrected. 
// See setEditorValue function on the parent page that included this script.
// 
// Paramters:
//-----------
// ctlSrc: the control whose value is to be verified.
// errorMsg: the message to be displayed on error.
// 
// Notes on the variables ERRORCTL and error:
// ERRORCTL: a global variable (page scope) for tracking the last control to 
//           to contain an error.
// error:    a boolean flag indicating that an error has occurred.
//=========================================================================
function isNumber(ctlSrc, errorMsg, min, max, prefixMax, postfixMax)
{
	if(ctlSrc.value.length > 0)
	{
		var values = ctlSrc.value.split(".");

		if(isNaN(values[0]) || values.length > 2 ||
		   (values.length == 2 ? (values[1].length > postfixMax) : false) || 
		   (values.length == 2 ? isNaN(values[1]) : false) ||
		   values[0].length > prefixMax ||
		   parseInt(values[0]) > max ||
		   parseInt(values[0]) < min ||
		   parseFloat(ctlSrc.value) > max)
		{
			ERRORCTL = ctlSrc;
			alert(ctlSrc.value + errorMsg);
			error = true;
			ERRORCTL.focus();
			ERRORCTL.select();
			return false;
		}
	}
	error = false;
	return true;
}

function isValidAdj(source, args)
{
    var ctl=document.forms[1].txtROI;
	var adj = ctl.value;

	if(adj == null || adj.length == 0 || isNaN(adj) || parseInt(adj) < 3 || parseInt(adj) > 7) {
		args.IsValid = false;
		ctl.style.background = "Yellow"
		ctl.focus();
		ctl.select();
	}
	else {
		args.IsValid = true;
			ctl.style.background = "White";	
	}
}

/**
 *
 */
function checkNumLength(regex, ctl, args)
{
	var re = new RegExp(regex);
	var test=ctl.value.replace(/^\s*|\s*$/g,'');
	
	if (!re.test(test) || parseInt(ctl.value) > 100 ||
	    parseInt(ctl.value) < 0)
	{
		args.IsValid = false;
		ctl.style.background = "Yellow";
		ctl.focus();
	}
	else
	{
		args.IsValid = true;
		ctl.style.background = "White";
	}
}

function popUp(URL) 
{
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=375,height=250,left = 600,top = 50');");
}

//=========================================================================
//
//
//=========================================================================
function trim(data) {
	data.replace(/^\s*|\s*$/g,'')
	return data;
}

function savePrompt() 
{
	save_dialog.show();
	/*if (confirm('Would you like to save changes before logging out?'))
	{
		document.getElementById('navFooter1_hdnLogoutAfterSave').value="true";
		document.getElementById('navFooter1_cmdSave').click();
		return false;
	}
	else 
	{
		return true;
	}*/
	return false;
} 
function init_save_dialog() {
					
	// Define various event handlers for Dialog
	var handleYes = function() {
		this.hide();
		document.getElementById('navFooter1_hdnLogoutAfterSave').value="true";
		document.getElementById('navFooter1_cmdSave').click();
		
	};
	var handleNo = function() {
		this.hide();
		window.location="login.aspx?logout=1";
	};
	
	var handleCancel = function() {
		this.hide();
	};

	// Instantiate the Dialog
	save_dialog= new YAHOO.widget.SimpleDialog("save_dialog", 
		{ width: "300px",
		fixedcenter: true,
		visible: false,
		draggable: true,
		close: true,
		text: "Would you like to save changes before logging out?",
		icon: YAHOO.widget.SimpleDialog.ICON_WARN,
		constraintoviewport: true,
		buttons: [ { text:"Yes", handler:handleYes, isDefault:true },
					{ text:"No",  handler:handleNo },
					{ text:"Cancel",  handler:handleCancel }]
		} );
	save_dialog.setHeader("Save Changes?");
	
	// Render the Dialog
	save_dialog.render(document.body);

}

/** 
 * Toggle Printer friendly view.
 */
function switchView() {
	var tr = document.getElementById("row1");
	var visible = "none";
	var a = document.getElementById("apv");
	if(tr.style.display == "none") {
		visible = "";
		a.innerText = "Printer-friendly View";
	}
	else {
		a.innerText = "Return to Normal View";
	}
	
	tr.style.display = visible;
	tr = document.getElementById("row2");
	tr.style.display = visible;
	tr = document.getElementById("row3");
	tr.style.display = visible;
	tr = document.getElementById("row4");
	tr.style.display = visible;
	
	document.getElementById("tblRCFooter").style.display = visible;
}

var RetirementCalculator=
{
	Confirm_Save:function()
	{
		alert('Your information has been saved.');
	}
};



