var SubmitClicked=false;

//this function catches the enter key 
//to prevent unintentional form submissions, 
//and to just call a custom function
function HeaderSearchFormKeyClicked(e)
{
	var code;

	if (e.keyCode)
	{
		code = e.keyCode;
	}
	else if(e.which)
	{ 
		code = e.which;
	}
	
	if(code == 13)
	{
		HeaderSearchClicked();

		return false;
	}
}

function changePage(newLoc)
{
	nextPage = newLoc.options[newLoc.selectedIndex].value

	if (nextPage != "")
	{
		document.location.href = nextPage
	}
}

function beginShow(url, name, xSize, ySize) {
	RemoteWindow = window.open(url,name,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,copyhistory=0,width=' + xSize + ',height=' + ySize);
	RemoteWindow.location = url;
}

//Added the following function to accomodate resizable window feature and specific Survey Pop-Ups.  We may want to add this as a parameter to the above beginShow function
function beginSurvey(url, name, xSize, ySize) {
	RemoteWindow = window.open(url,name,'toolbar=0,resizable=1,location=0,directories=0,status=0,menubar=0,scrollbars=1,copyhistory=0,width=' + xSize + ',height=' + ySize);
	RemoteWindow.location = url;
}

//Added the following function to accomodate resizable window, menu, and scrollbars for the VeriSign "verify this site" pop up window
//(this code was copied from the instructions on the VeriSign site)
function popUpVeriSign(url) {
	sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=500,height=450');
	self.name = "mainWin";
}

/*Added the following function to accomodate anything that needs a pop-up window and requires the following params:
PARAMS:
	url			: path to web page to load
	windowName	: name of the window
	toolbar		: display tool bar				(0=no, 1=yes, "yes", "no")
	location	: display the location window	(0=no, 1=yes, "yes", "no")
	directories	: display the directories		(0=no, 1=yes, "yes", "no")
	status		: display the status bar		(0=no, 1=yes, "yes", "no")
	menubar		: display the menu bar			(0=no, 1=yes, "yes", "no")
	scrollbars	: allow scrolling				(0=no, 1=yes, "yes", "no")
	resizable	: allow resize of window		(0=no, 1=yes, "yes", "no")
	width		: width of window in pixels
	height		: height of window in pixels

*/
function popUpWindow(url,windowName,toolbar,location,directories,status,menubar,scrollbars,resizable,width,height) {
	window.open(url,windowName,'toolbar=' + toolbar + ',location=' + location + ',directories=' + directories + ',status=' + status + ',menubar=' + menubar + ',scrollbars=' + scrollbars + ',resizable=' + resizable + ',width=' + width + ',height=' + height);
}

/*Added the following function to close window:*/
function closeClientWindow() {
	this.window.close();
}

// script to help prevent double submits
var submitted = false;
function DoSubmit() {
    if(DoSubmit.IsDebugging)
        debugger;
        
	if(typeof(Page_IsValid)!='undefined')
	{
		PGEWebControls.Page_ClientValidate();
		if(Page_IsValid==false){return false;}
	}
		
	if (submitted != true) {
		submitted = true;
		return true;
	} else {
		return false;
	}
}
DoSubmit.IsDebugging=false;

// This function is an override of the Page_clientValidate function present in the WebUIValidation.js(ASP .net JS file).
// The additional functionality  in this function is to call SetControlFocus if the page is not valid.
// Also submitclicked is set to true to find out if the submit has been processed.
function MyPage_ClientValidate() 
{
	SubmitClicked=true;
	if(typeof Page_Validators!="object" || Page_Validators==null)
		return true;
		
	var i;
	for (i = 0; i < Page_Validators.length; i++) 
	{
		ValidatorValidate(Page_Validators[i]);
	}
	ValidatorUpdateIsValid();    
	ValidationSummaryOnSubmit();
	Page_BlockSubmit = !Page_IsValid;
	if(!Page_IsValid)
	{
		//SetControlFocus();	
		// kc - 2008-04-22 - reset the variable so that the next call from
		//                   onblur of a composite control will not assume
		//                   that the user just hit the submit button.
		SubmitClicked=false;	
	}
	return Page_IsValid;
}

/*
function WebForm_FireDefaultButton(event, target) 
{
    if (event.keyCode == 13) 
    {
        var el=event.srcElement;
        
        if(el)
        {
            if(el.tagName.toLowerCase()=="textarea")
                return true;
            else if(el.tagName.toLowerCase()=="input")
                if((el.type=="submit") || (el.type=="button"))
                {
                    el.click();
                    event.cancelBubble=true;
                    if (event.stopPropagation) event.stopPropagation();
                    return false;
                }
        }

        var defaultButton;
        if (__nonMSDOMBrowser) 
        {
            defaultButton = document.getElementById(target);
        }
        else 
        {
            defaultButton = document.all[target];
        }

        if (defaultButton && typeof(defaultButton.click) != "undefined") 
        {
            defaultButton.click();
            event.cancelBubble = true;
            if (event.stopPropagation) event.stopPropagation();
            return false;
        }
    }

    return true;
}*/

// returns true if any validator for the specified control is invalid.                        
function IsAnyValidatorInvalidForControl(controlId)
{
    var targetedControl=document.getElementById(controlId);
    
    var vals;
    if (typeof(targetedControl.Validators) != "undefined") 
        vals = targetedControl.Validators;
    else 
    {
        if (targetedControl.tagName.toLowerCase() == "label") 
        {
            targetedControl = document.getElementById(targetedControl.htmlFor);
            vals = targetedControl.Validators;
        }
    }
    var i;
    for (i = 0; i < vals.length; i++) 
    {
        if(!vals[i].isvalid)
            return true;
    }
    return false;
}

function CustomValidatorCustomerID_ClientValidate(source, arguments)
{	
	var SSNVal = "";
	var StateIDVal = "";
	var FederalIDVal = "";
	var TribalIDVal = "";
	var validatorFederalID;
	var validatorTribalID;
	var FederalIDType = "";
	var TribalIDType = "";
	var divMain;
	var divMoreIDOptionsContainer;
	var cssTblErrStyle = "border-color: Red; border-right: red thin dashed; border-top: red thin dashed; border-left: red thin dashed; border-bottom: red thin dashed;padding:10px;";
	var cssTblNormalStyle = "border-right: 0px; padding-right: 0px; border-top: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; border-left: 0px; padding-top: 0px; border-bottom: 0px; border:0px; text-align: left;";
	var chkAgreeToProvideAlternateInfo;
	var iNumOptions = 0;
	
	//Get divMain reference
	if(!(document.getElementById(source.divMain) == null))
		divMain = document.getElementById(source.divMain);	
	
	//Get MoreIDOptionsContainer
	if(!(document.getElementById(source.divMoreIDOptionsContainer) == null))
		divMoreIDOptionsContainer = document.getElementById(source.divMoreIDOptionsContainer);
	
	//Get Social Security Number
	if(document.getElementById(source.SSN1) == null)
		SSNVal = "";
	else if(document.getElementById(source.SSN2) == null) 
		SSNVal = "";
	else if(document.getElementById(source.SSN3) == null)
		SSNVal = "";
	else 
		SSNVal = document.getElementById(source.SSN1).value + 
			  document.getElementById(source.SSN2).value + 
			  document.getElementById(source.SSN3).value ;		

	//Get State ID Number
	if(!(document.getElementById(source.StateID) == null))
		StateIDVal = document.getElementById(source.StateID).value;
	
	//Get Federal ID Value
	if(!(document.getElementById(source.FederalID) == null))
		FederalIDVal = document.getElementById(source.FederalID).value;
	
	//Get Tribe ID Value
	if(!(document.getElementById(source.TribalID) == null))
		TribalIDVal = document.getElementById(source.TribalID).value;	
	
	//Get Federal ID Type
	if(!(document.getElementById(source.FederalIDType) == null))
		FederalIDType = document.getElementById(source.FederalIDType).value;
		
	//Get Tribe ID Type
	if(!(document.getElementById(source.TribalIDType) == null))
		TribalIDType = document.getElementById(source.TribalIDType).value;

	//Get FederalID Validator
	if(!(document.getElementById(source.validatorFederalID) == null))
		validatorFederalID = document.getElementById(source.validatorFederalID);
	
	//Get TribalID Validator
	if(!(document.getElementById(source.validatorTribalID) == null))
		validatorTribalID = document.getElementById(source.validatorTribalID);
	
	//Get Other Documents Alternative.
	if(!(document.getElementById(source.chkAgreeToProvideAlternateInfo) == null))
		chkAgreeToProvideAlternateInfo = document.getElementById(source.chkAgreeToProvideAlternateInfo);	
	
	/****************************************************************************************/
	
	// If FederalIDValue is filled, Check Type
	if(!(FederalIDVal == ""))
		if(FederalIDType == "") {
			validatorFederalID.style.display = "";
			validatorFederalID.style.visibility = "visible";
			divMoreIDOptionsContainer.style.display = "";
		}
			
	// If TribalIDValue is filled, Check Type
	if(!(TribalIDVal == ""))
		if(TribalIDType == "") {
			validatorTribalID.style.display = "";
			validatorTribalID.style.visibility = "visible";
			divMoreIDOptionsContainer.style.display = "";
		}
	
	//count number of options provided
	
	if(!(source.id.indexOf("CustomValidatorCustomerID") == -1)) {
		//SSN
		if(!(SSNVal == "")) iNumOptions++;
		
		//State ID
		if(!(StateIDVal == "")) iNumOptions++;
		
		//Federal ID
		if(!(FederalIDType == "") && !(FederalIDVal == "")) iNumOptions++;
		
		//Tribal ID
		if(!(TribalIDType == "") && !(TribalIDVal == "")) iNumOptions++;
		
		//Doc check box
		if(chkAgreeToProvideAlternateInfo)
			if(chkAgreeToProvideAlternateInfo.checked) iNumOptions++;
		
		if(iNumOptions >= 1) {
			divMain.style.cssText = cssTblNormalStyle;	
			return;		
		} else {
			// change the table border style		
			divMain.style.cssText = cssTblErrStyle;
			
			// change the div style to show the optional info
			if(divMoreIDOptionsContainer)
				document.getElementById(source.divMoreIDOptionsContainer).style.display = "";
			
			source.clientcontroltovalidate = source.SSN1;	
			
			arguments.IsValid = false;
			return;	
		}
	}

	return;
}

// remove spaces from a string
function trim(str) { 
   return str.replace(/^\s*/, '').replace(/\s*$/, ''); 
}

function NameChange_ClientValidate(source,arguments)
{

	//if(!IsFormSubmitted()){return;}
	if(document.getElementById(source.name)==null) {return;}
	if(typeof source.initialvalue=='undefined') {return;}
	if(typeof source.changereason=='undefined'){return;}
		
	value=trim(document.getElementById(source.name).value);
	if(value=="" || IsMatch(value,"\\s*")) {return;} // return if the value is blank;
	
	//changereason=document.getElementById(source.changereason).value;
	var cr=document.getElementById(source.changereason);
    var crValue=cr.value;	
	var originalValue = trim(source.initialvalue);
	
	if(value!=originalValue && crValue=="")
	{
		arguments.IsValid=false;
		source.clientcontroltovalidate=source.changereason;
		return;
	}
}

function ClientValidateSiteType(source,arguments)
{
	
	if(!IsFormSubmitted()){return;}
	if(source.SiteTypes==null) {return;}
		
	var arrSiteType=source.SiteTypes.split(":");
	var i;
	for (i = 0; i < arrSiteType.length; i++) 
	 {
		if(document.getElementById(arrSiteType[i]+"_choice_ctrl").selectedIndex != 0) 
			{
				return;
			}
	}	
	
		arguments.IsValid=false;
		source.clientcontroltovalidate=arrSiteType[0];
		return;
}

function ClientValidateArrivalDate(source,arguments)
{
  
	if(!IsFormSubmitted()){return;}
	if ((trim(document.getElementById("ArrivalDate_month").value)== "") || (trim(document.getElementById("ArrivalDate_day").value) == "")||(trim(document.getElementById("ArrivalDate_year").value) == "")) {return;}
		var dtArrival= (document.getElementById("ArrivalDate_month").value+"/"+ document.getElementById("ArrivalDate_day").value + "/" + document.getElementById("ArrivalDate_year").value)
		if( dtArrival< source.Opendate)
		{	
	        arguments.IsValid=false;
			source.clientcontroltovalidate=document.getElementById("ArrivalDate_month");
			return;
		}
}
function ClientValidateDepartureDate(source,arguments)
{
  
	if(!IsFormSubmitted()){return;}
		if ((trim(document.getElementById("DepartureDate_month").value)== "") || (trim(document.getElementById("DepartureDate_day").value) == "")||(trim(document.getElementById("DepartureDate_year").value) == "")) {return;}

		var dtDeparture= (document.getElementById("DepartureDate_month").value+"/"+ document.getElementById("DepartureDate_day").value + "/" + document.getElementById("DepartureDate_year").value)
		
		if( dtDeparture > source.Closingdate)
		{	
	        arguments.IsValid=false;
			source.clientcontroltovalidate=document.getElementById("DepartureDate_month");
			return;
		}
}


function ClientValidateDaterequested(source,arguments)
{
  
	if(!IsFormSubmitted()){return;}
			if ((trim(document.getElementById("DateRequested_month").value)== "") || (trim(document.getElementById("DateRequested_day").value) == "")||(trim(document.getElementById("DateRequested_year").value) == "")) {return;}

		var dtDaterequested= (document.getElementById("DateRequested_month").value+"/"+ document.getElementById("DateRequested_day").value + "/" + document.getElementById("DateRequested_year").value)

		if(( dtDaterequested< source.Opendate) || (dtDaterequested > source.Closingdate))
		{	
			arguments.IsValid=false;
			source.clientcontroltovalidate=document.getElementById("DateRequested_month");
			return;
		}
}





function IsMatch(value,exp)
{
	if(value=='')return true; 
    var rx = new RegExp(exp);
    var matches = rx.exec(value);
    return (matches != null && value == matches[0]);
}
function Validate(valmain,valimage)
{
	ValidatorValidate(valmain);
	ValidatorValidate(valimage);
}

// TODO: This needs to move to WebControls
// TODO: jcillis- My response to above comment: I'm hoping we can leave this here - this function is now dependent on the IsEnterKey function
function keyUpTab(e){
	var key;
	var altKeyDown;
	var nextField;
	var targetValueLength;
	var maxLength;	
	
	if (e){
		//Netscape does not support onKeyUp for text input boxes
		//Mozilla code:
		key = e.keyCode;
		altKeyDown = e.altKey;
		nextField = e.target.nextField;
        
        //if(!IsEnterKey(key))
		  //  return;
		    
        // if the field that is next is not found, then there's nothing to do here
		if(!nextField)
		    return;

		targetValueLength = e.target.textLength;
		maxLength = e.target.maxLength;
	}
	if (window.event) {
		//IE code
		key = window.event.keyCode;
		altKeyDown = window.event.altKey;
		
		// *** disabled this as it was creating other defects. I initially created this for Job 1
		//     but don't think it's necessary. dont remove, just in case - jcillis 7/3/08
		//if(!IsEnterKey(key))
		  //  return;
		
		nextField = window.event.srcElement.nextField;
        // if the field that is next is not found, then there's nothing to do here
		if(!nextField)
		    return;

		targetValueLength = window.event.srcElement.value.length;
		maxLength = window.event.srcElement.maxLength;
    }
	if (!altKeyDown){
		//
		// there is some weird nonsense with unicode
		// values going on here this seems to work
		// but needs more investigation
		//
		if ((key > 43) && (key < 126)){
			if (nextField){
				if(targetValueLength >= maxLength){
					eval(nextField + ".focus()");
				}
			}
		}
	}
}

function keyUpFocus(){
	if (window.event){
		window.event.srcElement.select();
	}
}

// global keyUp handler
document.onkeyup = keyUpTab;

function ContactUs_RequiredFields(source,arguments)
{		
	if(typeof source.address == 'undefined') return;
	if(typeof source.city == 'undefined') return;
	if(typeof source.zip == 'undefined') return;
	if(typeof source.accountnumber == 'undefined') return;
		
	if(document.getElementById(source.address) == null) return;
	if(document.getElementById(source.city) == null) return;
	if(document.getElementById(source.zip) == null) return;
	if(document.getElementById(source.accountnumber) == null) return;
	
	var address = document.getElementById(source.address).value;
	var city = document.getElementById(source.city).value;
	var zip = document.getElementById(source.zip).value;
	var accountnumber = document.getElementById(source.accountnumber).value;
	
	if (accountnumber =='' && (address=='' && city=='' && zip==''))
	{
		arguments.IsValid=false;
		return;
	}
	else
	{
		return;
	}
}

function ContactUs_IncompleteAddress(source,arguments)
{		
	if(typeof source.address=='undefined') return;
	if(typeof source.city=='undefined') return;
	if(typeof source.zip=='undefined') return;
	if(typeof source.tbladdress=='undefined') return;
		
	if(document.getElementById(source.address)==null) return;
	if(document.getElementById(source.city)==null) return;
	if(document.getElementById(source.zip)==null) return;
	if(document.getElementById(source.tbladdress)==null) return;
		
	var address = document.getElementById(source.address).value;
	var city = document.getElementById(source.city).value;
	var zip = document.getElementById(source.zip).value;
	var accountnumber = document.getElementById(source.accountnumber).value;
	
	// Reset the border style
//	document.getElementById(source.tbladdress).style.cssText="";
	document.getElementById(source.tbladdress).className="addressok";
	document.getElementById(source.incompleteaddressvalidator).className="addressokfont";  //ujh 
	
	if (accountnumber =='' && (address=='' && city=='' && zip==''))
	{
		return;
	}
	else if (accountnumber != '' && (address=='' && city=='' && zip==''))
	{
		return;
	}	
	else if (accountnumber != '' && (address=='' || city=='' || zip==''))
	{
		return;
	}	
	else if (address=='' || city=='' || zip=='')
	{	
//		document.getElementById(source.tbladdress).style.cssText="border: red medium dashed;width:98%";
		document.getElementById(source.tbladdress).className="incompleteaddress";
		document.getElementById(source.incompleteaddressvalidator).className="incompleteaddressfont";  //ujh
		if (address == '')
		{	
			source.clientcontroltovalidate=source.address;
			arguments.IsValid=false;
			return;
		} else if (city == '')
		{	
			source.clientcontroltovalidate=source.city;
			arguments.IsValid=false;
			return;
			
		} else if (zip == '')
		{	
			source.clientcontroltovalidate=source.zip;
			arguments.IsValid=false;
			return;
		}			
	}			
}

function IsFormSubmitted()
{
	return SubmitClicked;
}

//function TextLength_ClientValidate(source,arguments)
//{
//	debugger;
//	if(typeof source.controltovalidate=='undefined') {return;}
//	if(document.getElementById(source.controltovalidate)==null) {return;}
//	if(document.getElementById(source.controltovalidate).value.length>document.getElementById(source.controltovalidate).maxlength)
//		{
//			arguments.IsValid=false;
//		}
//}

//END WEBCONTROLS SCRIPTS

// START -Progress bar scripts -Used by Payment page

	var iLoopCounter = 1;
	var iMaxLoop = 10;
	var iIntervalId;
			
	function BeginPageLoad() {
		iIntervalId = window.setInterval("iLoopCounter=UpdateProgress(iLoopCounter, iMaxLoop)", 500);
		document.forms[0].submit();
	}
		
	function EndPageLoad() {
		window.clearInterval(iIntervalId);
	}
		
	function UpdateProgress(iCurrentLoopCounter, iMaximumLoops) {
		iCurrentLoopCounter += 1;
				
		if (iCurrentLoopCounter <= iMaximumLoops) {
			progressBar.width = (30*iCurrentLoopCounter) + "px";
					
			return iCurrentLoopCounter;
		}
		else {
			progressBar.width = 10;
			return 1;
		}
	}
// END -Progress bar scripts -Used by Payment page	

function openPrintAuthWindow()
{
	window.open("viewPrint.aspx?printview=true", "printAuthorization", "width=700,height=550,resizable,toolbar,scrollbars,menubar");
}

function popUpVeriSign(url) {
	sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=500,height=450');
	self.name = "mainWin";
}

function OpenBillMatrix(BillMatrixUrl, BillMatrixReturnUrl)
{
		// pop-up the BillMatrix window
		// chage made in the if statement for supporting IE7 previous button in the bill matrix page.
		//if(window.open(BillMatrixUrl,'billmatrix','yes','yes','yes','yes','yes','yes','yes','600','400')==null)
        if(window.open(BillMatrixUrl,'billmatrix','toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=600,height=400')==null)		{
			// pop-up window could not be opened.
			if(document.getElementById("OpenWindowFailed")!=null)
				document.getElementById("OpenWindowFailed").style.display="";
			if(document.getElementById("OpenWindow")!=null)
				document.getElementById("OpenWindow").style.display="none";
			return;
		}
		
		// redirect the main pge page back to the Manage Your Account page...
		window.open(BillMatrixReturnUrl,"_self");		
}

// Enrollment page functions
function DeselectCancelOption(sender)
{
	if (sender.checked == true)
	{
		//MainPostBackForm.chkCancelOptions.checked = false;
	}
}

function SelectCancelOption()
{
	if (MainPostBackForm.chkCancelOptions.checked == true)
	{
		MainPostBackForm.chkCleanWind.checked = false;
		MainPostBackForm.chkGreenSource.checked = false;
		MainPostBackForm.chkHabitatSupport.checked = false;
		MainPostBackForm.chkRenewableFuture.checked = false;
	}
}

function toDollars(val)
{
	var amount = val.toString();
	var iPos = amount.indexOf(".");

	if(iPos != -1)
	{
		if (iPos == (amount.length - 2))
		{
			amount += "0";
			iPos = amount.indexOf(".");
		}
		else if (iPos == (amount.length - 1))
		{
			amount += "00";
			iPos = amount.indexOf(".");
		}
	}
	else
	{
		amount = amount + ".00";
		iPos = amount.indexOf(".");
	}

	return "$" + amount;
}

function isEmpty(s)
{
	return ((s == null) || (s.length == 0));
}

function isDigit(c)
{
	return ((c >= "0") && (c <= "9"));
}



function toBool(value)
{
	// convert string representation of a boolean, to *type* boolean.
	
	/* ### EXAMPLES  ###
	   "true" = true
	   true = true
	   "false" = false
	   false = false
	   "Ellie May" = false
	*/
	
	value = value.toString();	
	if (value.toLowerCase() == "true")
	{ return true; }
	else
	{ return false; }
}




// helper function that helps reduce redundant code writing
function IsObject(object)
{
	if(document.getElementById(object)!=null && document.getElementById(object)!='undefined')
	{
		return true;
	}
	else
	{
		return false;
	}
}

function EnrollNewsletter(id)
{
	window.navigate("/NewsletterEnrollment.aspx?cEmail=" + document.getElementById(id).value);
}


function loadInfoWindow(url, name, xSize, ySize)
{
	RemoteWindow = window.open(url,name,'toolbar=1,location=1,directories=0,status=1,menubar=1,scrollbars=1,copyhistory=0,resizable=1,width=' + xSize + ',height=' + ySize);
	RemoteWindow.location = url;
	RemoteWindow.focus();
}




//function AddressYears_ClientValidate(source,arguments)
//{
//	if(!IsFormSubmitted()){return;}
//	if(trim(document.getElementById(source.Years).value)=="" && trim(document.getElementById(source.Months).value)=="") 	
//	{
//		arguments.IsValid=false;
//		return;
//	}
//}

// For the case where a certain value selected in a radio button list requires
// that a value to be entered in a textbox, this object can perform the validation.
// Requires a "textName" control to have a value
// when the "radioName" control has the value "radioValueTriggeringRequired".
//
// To use, create an instance of this object on page load, and then, from the
// client validation function, call the Validate() method, passing a handle
// to the "arguments" object passed to the client validation function.
function RadioTextPair(radioName, textName, radioValueTriggeringRequired)
{
    this.Validate=function(arguments)
    {
	    if(typeof $get == "undefined")
	        return;
	    var control=$get(textName);
	    if(control==null)
	        return;

        // don't crash on client-side validation
        try
        {
	        var triggerSelected = getCheckedValue(radioName).toUpperCase()==radioValueTriggeringRequired.toUpperCase();
    	    
	        // fail validation if the trigger is set, but the user entered no value
	        if(triggerSelected && control.value=='')	
    	        arguments.IsValid=false;
        }
        catch(e)
        {
            return;
        }
    }
}

// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioButtonNames) {
    var radioObj=document.forms[0].elements[radioButtonNames];
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

String.format = function( text )
{
    //check if there are two arguments in the arguments list
    if ( arguments.length <= 1 )
    {
        //if there are not 2 or more arguments there’s nothing to replace
        //just return the original text
        return text;
    }

    //decrement to move to the second argument in the array
    var tokenCount = arguments.length - 2;
    for( var token = 0; token <= tokenCount; token++ )
    {
        //iterate through the tokens and replace their placeholders from the original text in order
        text = text.replace(new RegExp("\\{" + token + "\\}", "gi"), arguments[ token + 1 ]);
    }
    return text;
};

