varRootURL = "http://reporting.responsiblecare-us.com/"
//varRootURL = "http://reportingbeta.responsiblecare-us.com/"
//varRootURL = "http://eadev:550/"

function submitGenForm(Form, Action, aryFieldValuePairs)
{
	document.forms[Form].target = ""
	document.forms[Form].action = Action;
	for(i=0; i < aryFieldValuePairs.length; i++)
	{
		document.forms[Form][aryFieldValuePairs[i][0]].value = aryFieldValuePairs[i][1];
	}	
	document.forms[Form].submit();
}
function openSubForm(Form, Action, Target, aryFieldValuePairs, Height, Width)
{
	x = ((window.screen.availWidth/2) - (parseInt(Width)/2))
	y = ((window.screen.availHeight/2) - (parseInt(Height)/2))
	if(x < 0){x="0"}
	if(y < 0){y="0";Height = window.screen.availHeight}
	
	document.forms[Form].action = Action;
	//Target = window.showModelessDialog('','','');
	xWin = window.open("", Target, "location=no,scrollbars=yes,resizable=yes");
	xWin.resizeTo(Width, Height)
	xWin.moveTo(x,y)
	document.forms[Form].target = Target;
	
	for(i=0; i < aryFieldValuePairs.length; i++)
	{
		document.forms[Form][aryFieldValuePairs[i][0]].value = aryFieldValuePairs[i][1];
	}	
	document.forms[Form].submit();
}
function cleanUp(arySearchCharacters,searchString)
{
	for(var j = 0; j < arySearchCharacters.length; j++)
	{
		newSearchString = "";
		for(var i = 0; i < searchString.length; i++)
		{
			initialPosition = searchString.indexOf(arySearchCharacters[j][0],i);
			if(initialPosition == -1)
			{
				newSearchString += searchString.substring(i,searchString.length);
				break;
			}
			newSearchString += searchString.substring(i,initialPosition) + arySearchCharacters[j][1]
			i = initialPosition;
		}
		searchString = newSearchString
	}
	return searchString;
}
function formatCurrencyDisplay(formFields, formName)
{	
	for(i=0; i < formFields.length; i++)
	{
		if(document.forms(formName).item(formFields[i]).value != "")
		{
			document.forms(formName).item(formFields[i]).value = formatCurrency(cleanUp([["$", ""],[",", ""]], document.forms(formName).item(formFields[i]).value));
		}
	}
}
function formatDecimal(varValue, DecimalPlaces)
{
	varWhole = new String("")
	varFraction = new String("")
	varDecIndex = varValue.indexOf(".",0)
	blSwapZero = false;
	if(varDecIndex == -1)
	{
		varWhole = varValue
		for(i=0;i<parseInt(DecimalPlaces);i++)
		{
			if(i==0){varFraction = "."}
			varFraction += "0"
		}
		return varWhole + varFraction
	}
	else
	{
		varWhole = varValue.substring(0, varDecIndex)
		varFraction = varValue.substring(varDecIndex + 1, varValue.length)
		if(varFraction.length < parseInt(DecimalPlaces))
		{
			for(i=varFraction.length;i<parseInt(DecimalPlaces);i++){varFraction += "0"}
		}
		else
		{
			varRoundNum = varFraction.substring(parseInt(DecimalPlaces),parseInt(DecimalPlaces) + 1)
			varFraction = varFraction.substring(0,parseInt(DecimalPlaces))
			if(varFraction.charAt(0) == "0" && varFraction.charAt(1) != "9")
			{
				varFraction = "1" + varFraction.substring(1,varFraction.length)
				blSwapZero = true;
			}
			if(parseInt(varRoundNum) >= 5){varFraction = parseInt(varFraction) + 1}
			varFraction = varFraction.toString()
			if(blSwapZero){varFraction = "0" + varFraction.substring(1,varFraction.length)}
			if(varFraction.length > parseInt(DecimalPlaces))
			{
				varWhole = parseInt(varWhole) + 1
				varFraction = varFraction.substring(1,parseInt(DecimalPlaces) + 1)
			}
		}
		return varWhole + "." + varFraction
	}
}
function confirmNavigation(Section)
{
	doConfirm = true;
	varExcludedElements = ['btnSave','btnSaveAndClose','lnkNewClient','lnkRequestProposalNumber','lnkGNGDecision','lnkDebriefInformation','btnClose','lnkSetClient','btnSend','lnkForwardEmail','lnkPrintPage','btnNoSub','btnSelect','lnkSelectClient']
	
	for(i=0;i<varExcludedElements.length;i++)
	{
		if(document.activeElement.name == varExcludedElements[i])
		{
			doConfirm = false;
			break;
		}
	}
	if(doConfirm)
	{		
		window.event.returnValue = "Any unsaved changes to this " + Section + " will be lost.";
	}
}
function openErrorWin(varText)
{
	x = ((window.screen.availWidth/2) - (200))
	y = ((window.screen.availHeight/2) - (200))
	
	//<input type='button' name='OK' value='OK' onClick='window.close()'>
	
	varMessage = window.open('','ErrorWin','location=no,scrollbars=yes');
	varMessage.resizeTo(400,400);
	varMessage.moveTo(x,y)	
	varMessage.document.writeln("<html><head></head><body>" + varText + "<center><input type='image' name='btnOK' src='" + varRootURL + "common/images/btnOK_Off.gif' onClick='window.close()' onmouseover=\"this.src='" + varRootURL + "common/images/btnOK_On.gif'\" onmouseout=\"this.src='" + varRootURL + "common/images/btnOK_Off.gif'\" width='50' height='30' border='0'></center></body></html>");
	varMessage.document.close();
}
function openErrorForm(File, Height, Width)
{
	x = ((window.screen.availWidth/2) - (parseInt(Width)/2))
	y = ((window.screen.availHeight/2) - (parseInt(Height)/2))
	if(x < 0){x="0"}
	if(y < 0){y="0";Height = window.screen.availHeight}
	
	varMessage = window.open(File,'ErrorForm','height:" + Height + "px;width:" + Width + "px;center:yes;status:no;help:no;scrollbars:yes;resizable:no');
	varMessage.resizeTo(Width, Height)
	varMessage.moveTo(x,y)
}
function openModalFormX(File, Height, Width, Options)
{
	if(Options == ""){Options = ";resizable:no"}
	window.showModalDialog(File,window,"dialogHeight:" + Height + "px;dialogWidth:" + Width + "px;center:yes;status:no;help:no;scroll:yes" + Options)
}
function openModelessForm(File, Height, Width, Options)
{
	if(Options == ""){Options = ";resizable:no"}
	if(navigator.userAgent.toLowerCase().indexOf('msie') !=-1)
	{
		window.showModelessDialog(File,window,"dialogHeight:" + Height + "px;dialogWidth:" + Width + "px;center:yes;status:no;help:no;scroll:yes" + Options)
	}
	else
	{
		x = ((window.screen.availWidth/2) - (parseInt(Width)/2))
		y = ((window.screen.availHeight/2) - (parseInt(Height)/2))
		if(x < 0){x="0"}
		if(y < 0){y="0";Height = window.screen.availHeight}
		
		varMessage = window.open(File,'HelpWin','height:" + Height + "px;width:" + Width + "px;center:yes;status:no;help:no;scroll:yes' + Options);
		varMessage.resizeTo(Width, Height)
		varMessage.moveTo(x,y)
	}
}
function openHelpWin(File, Height, Width, Options)
{
	if(Options == ""){Options = ";resizable=no;"}

		x = ((window.screen.availWidth/2) - (parseInt(Width)/2))
		y = ((window.screen.availHeight/2) - (parseInt(Height)/2))
		if(x < 0){x="0"}
		if(y < 0){y="0";Height = window.screen.availHeight}
		
		//varMessage = window.open(File,'HelpWin','scrollbars=yes' + Options);
		varMessage = window.open(File,'HelpWin','scrollbars=yes');
		varMessage.resizeTo(Width, Height)
		varMessage.moveTo(x,y)

}
function openCmntsWin(File, Height, Width, Options)
{
	if(Options == ""){Options = ";resizable=no;"}

		x = ((window.screen.availWidth/2) - (parseInt(Width)/2))
		y = ((window.screen.availHeight/2) - (parseInt(Height)/2))
		if(x < 0){x="0"}
		if(y < 0){y="0";Height = window.screen.availHeight}
		
		//varMessage = window.open(File,'HelpWin','scrollbars=yes' + Options);
		varMessage = window.open(File,'CmntsWin','scrollbars=yes,resizable=yes,menubar=yes');
		varMessage.resizeTo(Width, Height)
		varMessage.moveTo(x,y)

}
function showHelp(varTyp,varID)
{
	if(varTyp == 'T'){openHelpWin(varRootURL + "content/help/help_popup.aspx?ID=" + varID,"200","400","")}
	else{openHelpWin(varRootURL + "content/help/RCMDMS_Users_Manual_" + varTyp + ".pdf#page=" + varID,"600","700","")}
}
function FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.
 
	RETVAL:
		The formatted number!
 **********************************************************************/
{ 
        if (isNaN(parseInt(num))) return "NaN";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign
	
	
	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);

	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
		
	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}		
	}

	// See if we need to use parenthesis
	if (bolParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";

	return tmpNumStr;		// Return our formatted string!
}