// ******************************
// FOOTER SCROLLING MESSAGE
// ******************************
var msg = "Please note that this is the initial beta launch of our site, functionality continues to be added on a weekly basis. Keep checking our site for further upgrades.                                                         ";
var delay = 100;
var maxcount= 0;
var startcount = 1;
var ie5 = false;

function checkIE () {
ie5=(navigator.appVersion.indexOf("MSIE 5.0")!=-1)?true:false;
}


function scroll()
{
    if (maxcount == 0)
    {
        maxcount = 1 * msg.length;
    }

    window.status =msg;
    startcount++;
    msg = msg.substring (1, msg.length) + msg.substring(0,1);

    if (startcount >= maxcount)
    {
        window.status = "";
        return;
    }
    else
    {
        setTimeout("scroll()",delay);
    }
}


function hideAllElementsWithId(id)
{
	//aElements = document.all[id];
	alert(document.all)
	if (document.all) {
	   aElements = document.all[id];
	} else {
	   aElements = document.getElementById(id);
	}
	alert(aElements+'=='+id)
	if (aElements != null )
        {
            if (aElements.length == null)
            {
                    theElement = aElements;
                    aElements = new Array(1);
                    aElements[0] = theElement;
            }

            iNumElements = aElements.length;
            for (iLoop = 0; iLoop < iNumElements; iLoop++)
            {
                    currentElement = aElements[iLoop];
                    hide(currentElement);
            }
        }
}


function showAllElementsWithId(id)
{
	//aElements = document.all[id];
	if (document.all) {
	   aElements = document.all[id];
	} else {
	   aElements = document.getElementById(id);
	}

	if (aElements != null)
        {
            if (aElements.length == null)
            {
                    theElement = aElements;
                    aElements = new Array(1);
                    aElements[0] = theElement;
            }

            iNumElements = aElements.length;
            for (iLoop = 0; iLoop < iNumElements; iLoop++)
            {
                    currentElement = aElements[iLoop];
                    show(currentElement);
            }
        }
}

function showAllElementsWithId(id, color1, color2)
{
    var color = color1;
    //aElements = document.all[id];
	if (document.all) {
	   aElements = document.all[id];
	} else {
	   aElements = document.getElementById(id);
	}

    if (aElements != null)
    {
        if (aElements.length == null)
        {
                theElement = aElements;
                aElements = new Array(1);
                aElements[0] = theElement;
        }

        iNumElements = aElements.length;
        for (iLoop = 0; iLoop < iNumElements; iLoop++)
        {
                currentElement = aElements[iLoop];
                show(currentElement);

                currentElement.bgColor = color;
                color = (color == color1) ? color2 : color1;
        }
    }
    return color;
}


function HideShowSection(imageId, imageOn, imageOff, id, name)
{
    var theImage = document.getElementById(imageId);
    var section = document.getElementsByName(name);
    //if(section.length != null && section.length > 0)
      //section = section[0];
      
    var image = theImage.src;
    if (image.indexOf(imageOn) > 0 )
    {
        theImage.src = replaceString(image, imageOn, imageOff, 0);
        section[0].value = "N" + section[0].value.substring(1);
        section[1].value = "N" + section[1].value.substring(1);
    }
    else
    {
        theImage.src = replaceString(image, imageOff, imageOn, 0);
        section[0].value = "Y" + section[0].value.substring(1);
        section[1].value = "Y" + section[1].value.substring(1);
    }
    //aElements = document.all[id];
    if (document.all) {
	   aElements = document.all[id];
	} else {
	   aElements = document.getElementById(id);
	}

    if (aElements != null)
        {
            if (aElements.length == null)
            {
                    theElement = aElements;
                    aElements = new Array(1);
                    aElements[0] = theElement;
            }

            iNumElements = aElements.length;
            for (iLoop = 0; iLoop < iNumElements; iLoop++)
            {
                    currentElement = aElements[iLoop];
                    hideshow(currentElement);
            }
        }
}

function swapRight(theSection,theImage)
{
    hideshow(document.getElementById(theSection));
    toggleImage(theImage, bullet1.src, bullet2.src);
    //hideFocus();
}


function swapContent(theSection,theImage)
{
    hideshow(document.getElementById(theSection));
    toggleImage(theImage, bullet3.src, bullet4.src);
    //hideFocus();
}

// ******************************
// TIME/DATE STUFF
// ******************************
function showTheHours(theHour)
{
	if (theHour > 0 && theHour < 13)
    {
		return (theHour);
	}

	if (theHour == 0)
    {
		return (12);
	}

	return (theHour-12);
}

function showZeroFilled(inValue)
{
	if (inValue > 9)
    {
		return ":" + inValue;
	}

	return ":0" + inValue;
}

function showAmPm()
{
	if (now.getHours() < 12)
    {
		return (" am")
	}
	return (" pm");
}

function showTheTime()
{
	now = new Date
	return	showTheHours(now.getHours()) +
		showZeroFilled(now.getMinutes()) +
		showZeroFilled(now.getSeconds()) +
		showAmPm();
}

// ******************************
// OPEN WINDOWS
// ******************************
var otherWindow;

function openWindow(url)
{
    openSizedWindow(url, 400, 400);
}


function openETopicWin(url)
{
    openSizedWindow(url, 560, 400);
}


function openSizedWindow(url, width, height)
{
    otherWindow = window.open(url, 'info', 'toolbar=no,location=no,resizable=yes,scrollbars=yes,width='+width+',height='+height);
    otherWindow.focus();
}


// ******************************
// inits
// ******************************

initCoCatChoices();


function isVisibleElement(element)
{
	style = element.style;
	if (style != null)
	{
		display = style.display;
		if (display != null && display == "none")
			return false;
	}

	var parent = element.parentElement;
	if (parent != null)
		return isVisibleElement(parent);
	else
		return true;
}


function initFocus()
{
	theForm = document.forms[0];
	if (theForm == null)
		return;
	theElement = theForm.elements[0];
	if (theElement == null)
		return;
	if (isVisibleElement(theElement))
		theElement.focus();
}


function initRecordForm ()
{
    theForm = document.policy_management;

    if (theForm)
    {
        enforcePriority(theForm);
        //forget until we add slobs back in
        //switchSLOB2(theForm,false);
    }
}

function initCoCatChoices()
{
    theForm = document.companySearchResultList;

    if (theForm)
    {
        //display the categories appropriate for the initially chosen firm
        dispCompanyCatChoices(theForm);
    }
}

function initSaveEntityForm()
{
    theForm = document.saveEntityForm;

    if (theForm)
    {
        coChangeSetup(theForm);
    }
}

function initRCBForm ()
{
    theForm = document.RCBForm;

    if (theForm)
    {
        // build an array of analysisValues to be used later
        RCBAnalysisValues = new Array(theForm.analysisValues.options.length);

        for ( i=0; i < theForm.analysisValues.options.length; i++)
        {
            RCBAnalysisValues[i] = theForm.analysisValues.options[i].value;
        }

        //display the categories appropriate for the initially chosen firm
        changeAnalysis(theForm);
    }

}


function initPolicyView()
{
}

function initLossTargetForm()
{
    theForm = document.LossTargetForm;

    if (theForm)
    {
        displayLossTargetRanges(theForm);
        setLossTargetLOB(theForm);

        // default eval date
        eValue = theForm.eval_date.value;
        if (!eValue || eValue=="")
        {
            var today = new Date();
            theForm.eval_date.value = (today.getMonth()+1)+"/"+today.getYear();
        }
    }

    theExpressForm = document.ExpressForm;
    if (theExpressForm)
    {
        displayLossTargetRanges(theExpressForm);
    }
}

function initProRataWheelForm()
{
    theForm = document.ProRataWheelForm;

    if (theForm)
    {
        displayShortRatePenalty(theForm.TERMINATION_TYPE);
    }
}



// ******************************
// UTILITIES
// ******************************
function addMessage(msg, addition)
{
    if (msg == "")
    {
        return addition;
    }
    else
    {
        return msg + "\n" + addition;
    }
}

function hide(which)
{
    if (which)
    {
        which.style.display="none";
    }
}

function show(which)
{
    if (which)
    {
        which.style.display="";
    }
}

function isHidden(which)
{
    if (which)
    {
        return which.style.display=="none";
    }
}

function setFieldValue(theField, theValue)
{
    if (theField)
    {
        theField.value = theValue;
    }
}

function checkAllBoxes(theForm, checkBoxName)
{
    resetCheckBoxes(theForm, checkBoxName, true)
}

function unCheckAllBoxes(theForm, checkBoxName)
{
    resetCheckBoxes(theForm, checkBoxName, false)
}

function resetCheckBoxes(theForm, checkBoxName, value)
{
    for (var i = 0; i<theForm.elements.length; i++)
    {
        name = theForm.elements[i].name;

        if (name == checkBoxName)
        {
            theForm.elements[i].checked = value;
        }
    }
}

function hideAllBoxes(theForm, checkBoxName)
{
    displayCheckBoxes(theForm, checkBoxName, false)
}

function showAllBoxes(theForm, checkBoxName)
{
    displayCheckBoxes(theForm, checkBoxName, true)
}

function displayCheckBoxes(theForm, checkBoxName, display)
{
    for (var i = 0; i<theForm.elements.length; i++)
    {
        name = theForm.elements[i].name;

        if (name == checkBoxName)
        {
            if(display)
                show(theForm.elements[i]);
            else
                hide(theForm.elements[i]);
        }
    }
}

function selectOptions(whichField, whichValue)
{
    for(i=0; i < whichField.options.length; i++)
    {
        whichField.options[i].selected = whichValue;
    }
    return;
}

function checkLength(theElement, theMax)
{
    theValue = theElement.value;
    if(theValue.length >= theMax)
        theElement.blur();
}


function getElementsById (id)
{
    var els = document.all[id];
    if (typeof els == 'undefined')
      return [];
    else if (!els.length)
      return [els];
    else
      return els;
}

function toggleImage(image, switchOne, switchTwo)
{
   if (image.src == switchOne)
   {
      image.src = switchTwo;
   }
   else
   {
      image.src = switchOne;
   }
}

function hideshow(which)
{
	if (isHidden(which))
	{
	   show(which);
	}
	else
	{
	   hide(which);
	}
}


function toggleSection(section)
{
  if(section.value=="YY")
    section.value = "YN";
  else
  if(section.value=="YN")
    section.value = "YY";
  else
  if(section.value=="NY")
    section.value = "NN";
  else
  if(section.value=="NN")
    section.value = "NY";
}

function hideFocus(which)
{
	//removed so long screens won't jump
    //this.focus();
}

function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function getDate (theDate)
{
    if (theDate.length == 6)
    {
        theDate = "0"+theDate;
    }

    if (theDate.length == 7)
    {
        if (theDate.substring(2,3) == '/')
        {
            var month = theDate.substring(0,2);
            var year  = theDate.substring(3,7);
            var test  = new Date(year,month-1,'01');

            if (year == y2k(test.getYear()) && (month-1 == test.getMonth()))
            {
                return test;
            }
            else
            {
                return null;
            }
        }
        else
        {
            return null;
        }
    }
    else
    {
        return null;
    }
}


function replaceString(sOriginal, sSearch, sReplace, iStartPos)
{
	if (iStartPos > (sOriginal.length - 1))
		return sOriginal;
	iSearchPos = sOriginal.indexOf(sSearch, iStartPos);
	if (iSearchPos == -1)
		return sOriginal;
	iEndSearchPos = iSearchPos + sSearch.length;
	sPre = sOriginal.substring(0, iSearchPos);
	sPost = sOriginal.substring(iEndSearchPos);
	sUpToEndOfReplaced = sPre + sReplace;
	sFinal = sUpToEndOfReplaced + sPost;

	return replaceString(sFinal, sSearch, sReplace, (sUpToEndOfReplaced.length - 1));
}


function convertForUrl(sValue)
{
	sTemp = replaceString(sValue, " ", "+", 0);
	sTemp = replaceString(sTemp, ":", "%3A", 0);
	sTemp = replaceString(sTemp, "/", "%2F", 0);
	sTemp = replaceString(sTemp, ".", "%2E", 0);
	sTemp = replaceString(sTemp, "=", "%3D", 0);
	sTemp = replaceString(sTemp, ",", "%2C", 0);
	sTemp = replaceString(sTemp, "?", "%3F", 0);

	return sTemp;
}


function convertForHTML(sValue)
{
	sTemp = replaceString(sValue, "&", "&amp;", 0);
	sTemp = replaceString(sTemp, "<", "&lt;", 0);
	sTemp = replaceString(sTemp, ">", "&gt;", 0);
	sTemp = replaceString(sTemp, "\n", "<br>", 0);

	return sTemp;
}

function onRemoveCompanySubmit(frmForm)
{
	// don't let the user submit the form if they've chosen a company which
	// has policies associated with it. we know which companies have policies
	// associated with them by looking for hidden field values on this form
	// with the name HAS_POLICIES_<company id> - if the value is TRUE, then
	// that company has policies associated with it
	
	if (frmForm == null)
		return true;
		
	var fldSelectedCompany = frmForm.drp_user_company;
	if (fldSelectedCompany == null)
		return true;
	var sSelectedCompany = fldSelectedCompany.value;
	if (sSelectedCompany == null || sSelectedCompany == "")
		return true;
	
	var sSelectedCompanyHasPoliciesFieldName = 'HAS_POLICIES_' + sSelectedCompany;
	var fldSelectedCompanyHasPolicies = frmForm[sSelectedCompanyHasPoliciesFieldName];
	if (fldSelectedCompanyHasPolicies != null)
	{
		var sSelectedCompanyHasPolicies = fldSelectedCompanyHasPolicies.value;
		if (sSelectedCompanyHasPolicies != null && sSelectedCompanyHasPolicies == 'TRUE')
		{
			alert('The company you have selected has records associated to it.  Please delete these records before removing the company from your company list.');
			return false;
		}
	}
	
	var sSelectedCompanyHasProjectsFieldName = 'HAS_PROJECTS_' + sSelectedCompany;
	var fldSelectedCompanyHasProjects = frmForm[sSelectedCompanyHasProjectsFieldName];
	if (fldSelectedCompanyHasProjects != null)
	{
		var sSelectedCompanyHasProjects = fldSelectedCompanyHasProjects.value;
		if (sSelectedCompanyHasProjects != null && sSelectedCompanyHasProjects == 'TRUE')
		{
			alert('The company you have selected has projects associated to it.  Please delete these projects before removing the company from your company list.');
			return false;
		}
	}

	return true;
}

function seatAdminSetOptions(fldOption, aNewOptions)
{
	if (fldOption == null || aNewOptions == null)
		return;
	var aOptions = fldOption.options;
	if (aOptions == null)
		return;
	aOptions.length = 0;
	iNumNewOptions = aNewOptions.length;
	for (iSetOptionsLoop = 0; iSetOptionsLoop < iNumNewOptions; iSetOptionsLoop++)
	{
		aOptions[aOptions.length] = aNewOptions[iSetOptionsLoop];
	}
}

function seatAdminAddUsers()
{
	var frmForm = document.seatAdminDetail;
	if (frmForm == null)
		return;
	var fldEligibleUsers = frmForm.eligibleUsers;
	if (fldEligibleUsers == null)
		return;
	var aEligibleOptions = fldEligibleUsers.options;
	if (aEligibleOptions == null)
		return;
	var fldSeatedUsers = frmForm.seatedUsers;
	if (fldSeatedUsers == null)
		return;
	var aSeatedOptions = fldSeatedUsers.options;
	if (aSeatedOptions == null)
		return;
		
	var aNewEligibleOptions = new Array();
	iNumOptions = aEligibleOptions.length;
	for (iSeatAdminLoop = 0; iSeatAdminLoop < iNumOptions; iSeatAdminLoop++)
	{
		var eligibleOption = aEligibleOptions[iSeatAdminLoop];
		if (eligibleOption == null)
			continue;
		if (eligibleOption.selected)
		{
			var newSeatedOption = new Option();
			newSeatedOption.value = eligibleOption.value;
			newSeatedOption.text = eligibleOption.text;
			aSeatedOptions[aSeatedOptions.length] = newSeatedOption;
		}
		else
			aNewEligibleOptions[aNewEligibleOptions.length] = eligibleOption;
	}
	seatAdminSetOptions(fldEligibleUsers, aNewEligibleOptions);
}

function seatAdminRemoveUsers()
{
	var frmForm = document.seatAdminDetail;
	if (frmForm == null)
		return;
	var fldEligibleUsers = frmForm.eligibleUsers;
	if (fldEligibleUsers == null)
		return;
	var aEligibleOptions = fldEligibleUsers.options;
	if (aEligibleOptions == null)
		return;
	var fldSeatedUsers = frmForm.seatedUsers;
	if (fldSeatedUsers == null)
		return;
	var aSeatedOptions = fldSeatedUsers.options;
	if (aSeatedOptions == null)
		return;
		
	var aNewSeatedOptions = new Array();
	iNumOptions = aSeatedOptions.length;
	for (iSeatAdminLoop = 0; iSeatAdminLoop < iNumOptions; iSeatAdminLoop++)
	{
		var seatedOption = aSeatedOptions[iSeatAdminLoop];
		if (seatedOption == null)
			continue;
		if (seatedOption.selected)
		{
			var newEligibleOption = new Option();
			newEligibleOption.value = seatedOption.value;
			newEligibleOption.text = seatedOption.text;
			aEligibleOptions[aEligibleOptions.length] = newEligibleOption;
		}
		else
			aNewSeatedOptions[aNewSeatedOptions.length] = seatedOption;
	}
	seatAdminSetOptions(fldSeatedUsers, aNewSeatedOptions);
}

function seatAdminOnSubmit(frmForm)
{
	if (frmForm == null)
		return false;
	var fldSeatedUsers = frmForm.seatedUsers;
	if (fldSeatedUsers == null)
		return false;
	var aSeatedOptions = fldSeatedUsers.options;
	if (aSeatedOptions == null)
		return false;
	iNumOptions = aSeatedOptions.length;
	for (iSeatAdminLoop = 0; iSeatAdminLoop < iNumOptions; iSeatAdminLoop++)
	{
		var seatedOption = aSeatedOptions[iSeatAdminLoop];
		if (seatedOption == null)
			continue;
		seatedOption.selected = true;
	}
	
	return true;
}


function scroll()
{
    if (maxcount == 0)
    {
        maxcount = 1 * msg.length;
    }

    window.status =msg;
    startcount++;
    msg = msg.substring (1, msg.length) + msg.substring(0,1);

    if (startcount >= maxcount)
    {
        window.status = "";
        return;
    }
    else
    {
        setTimeout("scroll()",delay);
    }
}


function hideAllElementsWithId(id)
{
	//aElements = document.all[id];
	if (document.all) {
	   aElements = document.all[id];
	} else {
	   aElements = document.getElementById(id);
	}
	if (aElements != null )
        {
            if (aElements.length == null)
            {
                    theElement = aElements;
                    aElements = new Array(1);
                    aElements[0] = theElement;
            }

            iNumElements = aElements.length;
            for (iLoop = 0; iLoop < iNumElements; iLoop++)
            {
                    currentElement = aElements[iLoop];
                    hide(currentElement);
            }
        }
}


function showAllElementsWithId(id)
{
	//aElements = document.all[id];
	if (document.all) {
	   aElements = document.all[id];
	} else {
	   aElements = document.getElementById(id);
	}
	if (aElements != null)
        {
            if (aElements.length == null)
            {
                    theElement = aElements;
                    aElements = new Array(1);
                    aElements[0] = theElement;
            }

            iNumElements = aElements.length;
            for (iLoop = 0; iLoop < iNumElements; iLoop++)
            {
                    currentElement = aElements[iLoop];
                    show(currentElement);
            }
        }
}

function showAllElementsWithId(id, color1, color2)
{
    var color = color1;
    //aElements = document.all[id];
	if (document.all) {
	   aElements = document.all[id];
	} else {
	   aElements = document.getElementById(id);
	}
    if (aElements != null)
    {
        if (aElements.length == null)
        {
                theElement = aElements;
                aElements = new Array(1);
                aElements[0] = theElement;
        }

        iNumElements = aElements.length;
        for (iLoop = 0; iLoop < iNumElements; iLoop++)
        {
                currentElement = aElements[iLoop];
                show(currentElement);

                currentElement.bgColor = color;
                color = (color == color1) ? color2 : color1;
        }
    }
    return color;
}


// ******************************
// Printable Pages
// ******************************
function printPage()
{
    makePrintable();
    print();
    makeNonPrintable();        
}

function makePrintable()
{
    hideAllElementsWithId('screenSubHeader');
    hideAllElementsWithId('screenLeftMenu');
    hideAllElementsWithId('screenTitleRow');

    hideAllElementsWithId('headerRow1');
    hideAllElementsWithId('headerRow2');

    //show(document.getElementById('headerPrintRow1'));
    showAllElementsWithId('headerPrintRow2');
    hideAllElementsWithId('printButton');
    hideAllElementsWithId('requestButton');
    showAllElementsWithId('normalViewButton');
/*
	// expand any scrollable divs
	aScrollDivs = document.all.scrollablediv;
	if (aScrollDivs != null)
	{
		if (aScrollDivs.length == null)
		{
			theDiv = aScrollDivs;
			aScrollDivs = new Array(1);
			aScrollDivs[0] = theDiv;
		}

		iNumDivs = aScrollDivs.length;
		for (iLoop = 0; iLoop < iNumDivs; iLoop++)
		{
			divCurrent = aScrollDivs[iLoop];
			if (divCurrent != null)
			{
                        //show_props(divCurrent,"div");
				divCurrent.style.overflow = "";
				divCurrent.style.margin = "5px";
			}
		}
	}

	// expand any Notes areas
	aNotes = document.all.ts_notesarea;
	if (aNotes != null)
	{
		if (aNotes.length == null)
		{
			theNote = aNotes;
			aNotes = new Array(1);
			aNotes[0] = theNote;
		}

		iNumNotes = aNotes.length;
		for (iLoop = 0; iLoop < iNumNotes; iLoop++)
		{
			fldNote = aNotes[iLoop];
			if (fldNote != null)
			{
				sNoteName = fldNote.name;
				sDivName = sNoteName + "_printablediv";
				fldDiv = document.all[sDivName];
				if (fldDiv != null)
				{
					sText = fldNote.value;
					if (sText != null)
					{
						fldNote.style.display = "none";
						sConvertedText = convertForHTML(sText);
						fldDiv.innerHTML = sConvertedText;
						fldDiv.style.display = "";
					}
				}
			}
		}
	}
*/	
}


// for debug - shows the properties of an object, 20 at a time in an alert window
function show_props(obj, obj_name)
{   var result = "" ;
    var j = 0;
    for (var i in obj)
    {
      j++;
      result += obj_name + "." + i + " = " + obj[i] + "\n" ;
      if (j %20 == 0)
      {
        alert(result);
        result = "";
      }
    }
}





// ******************************
// Revert Printable Pages back again
// ******************************
function makeNonPrintable()
{
    showAllElementsWithId('screenSubHeader');
    showAllElementsWithId('screenLeftMenu');
    showAllElementsWithId('screenTitleRow');

    showAllElementsWithId('headerRow1');
    showAllElementsWithId('headerRow2');

    hideAllElementsWithId('headerPrintRow2');
    showAllElementsWithId('printButton');
    showAllElementsWithId('requestButton');
    hideAllElementsWithId('normalViewButton');

	// collapse any scrollable divs
	aScrollDivs = document.all.scrollablediv;
	if (aScrollDivs != null)
	{
		if (aScrollDivs.length == null)
		{
			theDiv = aScrollDivs;
			aScrollDivs = new Array(1);
			aScrollDivs[0] = theDiv;
		}

		iNumDivs = aScrollDivs.length;
		for (iLoop = 0; iLoop < iNumDivs; iLoop++)
		{
			divCurrent = aScrollDivs[iLoop];
			if (divCurrent != null)
			{
				divCurrent.style.overflow = "auto";
				divCurrent.style.margin = "5px";
			}
		}
	}

	// collapse any Notes areas
	aNotes = document.all.ts_notesarea;
	if (aNotes != null)
	{
		if (aNotes.length == null)
		{
			theNote = aNotes;
			aNotes = new Array(1);
			aNotes[0] = theNote;
		}

		iNumNotes = aNotes.length;
		for (iLoop = 0; iLoop < iNumNotes; iLoop++)
		{
			fldNote = aNotes[iLoop];
			if (fldNote != null)
			{
				sNoteName = fldNote.name;
				sDivName = sNoteName + "_printablediv";
				fldDiv = document.all[sDivName];
				if (fldDiv != null)
				{
                                        fldNote.style.display = "";
                                        fldDiv.innerHTML="";
                                        fldDiv.style.display = "none";
				}
			}
		}
	}
}



// ******************************
// BULLET IMAGE SWAPPING
// ******************************
function swapLeft(theSection,theImage)
{
    hideshow(document.getElementById(theSection));
    toggleImage(theImage, bullet1.src, bullet2.src);
    //hideFocus();
}


function swapRight(theSection,theImage)
{
    hideshow(document.getElementById(theSection));
    toggleImage(theImage, bullet1.src, bullet2.src);
    //hideFocus();
}


function swapContent(theSection,theImage)
{
    hideshow(document.getElementById(theSection));
    toggleImage(theImage, bullet3.src, bullet4.src);
    //hideFocus();
}

// ******************************
// TIME/DATE STUFF
// ******************************
function showTheHours(theHour)
{
	if (theHour > 0 && theHour < 13)
    {
		return (theHour);
	}

	if (theHour == 0)
    {
		return (12);
	}

	return (theHour-12);
}

function showZeroFilled(inValue)
{
	if (inValue > 9)
    {
		return ":" + inValue;
	}

	return ":0" + inValue;
}

function showAmPm()
{
	if (now.getHours() < 12)
    {
		return (" am")
	}
	return (" pm");
}

function showTheTime()
{
	now = new Date
	return	showTheHours(now.getHours()) +
		showZeroFilled(now.getMinutes()) +
		showZeroFilled(now.getSeconds()) +
		showAmPm();
}

// ******************************
// OPEN WINDOWS
// ******************************
var otherWindow;

function openWindow(url)
{
    openSizedWindow(url, 400, 400);
}


function openETopicWin(url)
{
    openSizedWindow(url, 560, 400);
}


function openSizedWindow(url, width, height)
{
    otherWindow = window.open(url, 'info', 'toolbar=no,location=no,resizable=yes,scrollbars=yes,width='+width+',height='+height);
    otherWindow.focus();
}


// ******************************
// inits
// ******************************

initCoCatChoices();


function isVisibleElement(element)
{
	style = element.style;
	if (style != null)
	{
		display = style.display;
		if (display != null && display == "none")
			return false;
	}

	var parent = element.parentElement;
	if (parent != null)
		return isVisibleElement(parent);
	else
		return true;
}


function initFocus()
{
	theForm = document.forms[0];
	if (theForm == null)
		return;
	theElement = theForm.elements[0];
	if (theElement == null)
		return;
	if (isVisibleElement(theElement))
		theElement.focus();
}


function initRecordForm ()
{
    theForm = document.policy_management;

    if (theForm)
    {
        enforcePriority(theForm);
        //forget until we add slobs back in
        //switchSLOB2(theForm,false);
    }
}

function initCoCatChoices()
{
    theForm = document.companySearchResultList;

    if (theForm)
    {
        //display the categories appropriate for the initially chosen firm
        dispCompanyCatChoices(theForm);
    }
}

function initSaveEntityForm()
{
    theForm = document.saveEntityForm;

    if (theForm)
    {
        coChangeSetup(theForm);
    }
}

function initRCBForm ()
{
    theForm = document.RCBForm;

    if (theForm)
    {
        // build an array of analysisValues to be used later
        RCBAnalysisValues = new Array(theForm.analysisValues.options.length);

        for ( i=0; i < theForm.analysisValues.options.length; i++)
        {
            RCBAnalysisValues[i] = theForm.analysisValues.options[i].value;
        }

        //display the categories appropriate for the initially chosen firm
        changeAnalysis(theForm);
    }

}


function initPolicyView()
{
}

function initLossTargetForm()
{
    theForm = document.LossTargetForm;

    if (theForm)
    {
        displayLossTargetRanges(theForm);
        setLossTargetLOB(theForm);

        // default eval date
        eValue = theForm.eval_date.value;
        if (!eValue || eValue=="")
        {
            var today = new Date();
            theForm.eval_date.value = (today.getMonth()+1)+"/"+today.getYear();
        }
    }

    theExpressForm = document.ExpressForm;
    if (theExpressForm)
    {
        displayLossTargetRanges(theExpressForm);
    }
}

function initProRataWheelForm()
{
    theForm = document.ProRataWheelForm;

    if (theForm)
    {
        displayShortRatePenalty(theForm.TERMINATION_TYPE);
    }
}



// ******************************
// UTILITIES
// ******************************
function addMessage(msg, addition)
{
    if (msg == "")
    {
        return addition;
    }
    else
    {
        return msg + "\n" + addition;
    }
}

function hide(which)
{
    if (which)
    {
        which.style.display="none";
    }
}

function show(which)
{
    if (which)
    {
        which.style.display="";
    }
}

function isHidden(which)
{
    if (which)
    {
        return which.style.display=="none";
    }
}

function setFieldValue(theField, theValue)
{
    if (theField)
    {
        theField.value = theValue;
    }
}

function checkAllBoxes(theForm, checkBoxName)
{
    resetCheckBoxes(theForm, checkBoxName, true)
}

function unCheckAllBoxes(theForm, checkBoxName)
{
    resetCheckBoxes(theForm, checkBoxName, false)
}

function resetCheckBoxes(theForm, checkBoxName, value)
{
    for (var i = 0; i<theForm.elements.length; i++)
    {
        name = theForm.elements[i].name;

        if (name == checkBoxName)
        {
            theForm.elements[i].checked = value;
        }
    }
}

function hideAllBoxes(theForm, checkBoxName)
{
    displayCheckBoxes(theForm, checkBoxName, false)
}

function showAllBoxes(theForm, checkBoxName)
{
    displayCheckBoxes(theForm, checkBoxName, true)
}

function displayCheckBoxes(theForm, checkBoxName, display)
{
    for (var i = 0; i<theForm.elements.length; i++)
    {
        name = theForm.elements[i].name;

        if (name == checkBoxName)
        {
            if(display)
                show(theForm.elements[i]);
            else
                hide(theForm.elements[i]);
        }
    }
}

function selectOptions(whichField, whichValue)
{
    for(i=0; i < whichField.options.length; i++)
    {
        whichField.options[i].selected = whichValue;
    }
    return;
}

function checkLength(theElement, theMax)
{
    theValue = theElement.value;
    if(theValue.length >= theMax)
        theElement.blur();
}


function getElementsById (id)
{
    var els = document.all[id];
    if (typeof els == 'undefined')
      return [];
    else if (!els.length)
      return [els];
    else
      return els;
}

function toggleImage(image, switchOne, switchTwo)
{
   if (image.src == switchOne)
   {
      image.src = switchTwo;
   }
   else
   {
      image.src = switchOne;
   }
}

function hideshow(which)
{
	if (isHidden(which))
	{
	   show(which);
	}
	else
	{
	   hide(which);
	}
}

function hideFocus(which)
{
	//removed so long screens won't jump
    //this.focus();
}

function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function getDate (theDate)
{
    if (theDate.length == 6)
    {
        theDate = "0"+theDate;
    }

    if (theDate.length == 7)
    {
        if (theDate.substring(2,3) == '/')
        {
            var month = theDate.substring(0,2);
            var year  = theDate.substring(3,7);
            var test  = new Date(year,month-1,'01');

            if (year == y2k(test.getYear()) && (month-1 == test.getMonth()))
            {
                return test;
            }
            else
            {
                return null;
            }
        }
        else
        {
            return null;
        }
    }
    else
    {
        return null;
    }
}


function replaceString(sOriginal, sSearch, sReplace, iStartPos)
{
	if (iStartPos > (sOriginal.length - 1))
		return sOriginal;
	iSearchPos = sOriginal.indexOf(sSearch, iStartPos);
	if (iSearchPos == -1)
		return sOriginal;
	iEndSearchPos = iSearchPos + sSearch.length;
	sPre = sOriginal.substring(0, iSearchPos);
	sPost = sOriginal.substring(iEndSearchPos);
	sUpToEndOfReplaced = sPre + sReplace;
	sFinal = sUpToEndOfReplaced + sPost;

	return replaceString(sFinal, sSearch, sReplace, (sUpToEndOfReplaced.length - 1));
}


function convertForUrl(sValue)
{
	sTemp = replaceString(sValue, " ", "+", 0);
	sTemp = replaceString(sTemp, ":", "%3A", 0);
	sTemp = replaceString(sTemp, "/", "%2F", 0);
	sTemp = replaceString(sTemp, ".", "%2E", 0);
	sTemp = replaceString(sTemp, "=", "%3D", 0);
	sTemp = replaceString(sTemp, ",", "%2C", 0);
	sTemp = replaceString(sTemp, "?", "%3F", 0);

	return sTemp;
}


function convertForHTML(sValue)
{
	sTemp = replaceString(sValue, "&", "&amp;", 0);
	sTemp = replaceString(sTemp, "<", "&lt;", 0);
	sTemp = replaceString(sTemp, ">", "&gt;", 0);
	sTemp = replaceString(sTemp, "\n", "<br>", 0);

	return sTemp;
}

function onRemoveCompanySubmit(frmForm)
{
	// don't let the user submit the form if they've chosen a company which
	// has policies associated with it. we know which companies have policies
	// associated with them by looking for hidden field values on this form
	// with the name HAS_POLICIES_<company id> - if the value is TRUE, then
	// that company has policies associated with it
	
	if (frmForm == null)
		return true;
		
	var fldSelectedCompany = frmForm.drp_user_company;
	if (fldSelectedCompany == null)
		return true;
	var sSelectedCompany = fldSelectedCompany.value;
	if (sSelectedCompany == null || sSelectedCompany == "")
		return true;
	
	var sSelectedCompanyHasPoliciesFieldName = 'HAS_POLICIES_' + sSelectedCompany;
	var fldSelectedCompanyHasPolicies = frmForm[sSelectedCompanyHasPoliciesFieldName];
	if (fldSelectedCompanyHasPolicies != null)
	{
		var sSelectedCompanyHasPolicies = fldSelectedCompanyHasPolicies.value;
		if (sSelectedCompanyHasPolicies != null && sSelectedCompanyHasPolicies == 'TRUE')
		{
			alert('The company you have selected has records associated to it.  Please delete these records before removing the company from your company list.');
			return false;
		}
	}
	
	var sSelectedCompanyHasProjectsFieldName = 'HAS_PROJECTS_' + sSelectedCompany;
	var fldSelectedCompanyHasProjects = frmForm[sSelectedCompanyHasProjectsFieldName];
	if (fldSelectedCompanyHasProjects != null)
	{
		var sSelectedCompanyHasProjects = fldSelectedCompanyHasProjects.value;
		if (sSelectedCompanyHasProjects != null && sSelectedCompanyHasProjects == 'TRUE')
		{
			alert('The company you have selected has projects associated to it.  Please delete these projects before removing the company from your company list.');
			return false;
		}
	}

	return true;
}

function seatAdminSetOptions(fldOption, aNewOptions)
{
	if (fldOption == null || aNewOptions == null)
		return;
	var aOptions = fldOption.options;
	if (aOptions == null)
		return;
	aOptions.length = 0;
	iNumNewOptions = aNewOptions.length;
	for (iSetOptionsLoop = 0; iSetOptionsLoop < iNumNewOptions; iSetOptionsLoop++)
	{
		aOptions[aOptions.length] = aNewOptions[iSetOptionsLoop];
	}
}

function seatAdminAddUsers()
{
	var frmForm = document.seatAdminDetail;
	if (frmForm == null)
		return;
	var fldEligibleUsers = frmForm.eligibleUsers;
	if (fldEligibleUsers == null)
		return;
	var aEligibleOptions = fldEligibleUsers.options;
	if (aEligibleOptions == null)
		return;
	var fldSeatedUsers = frmForm.seatedUsers;
	if (fldSeatedUsers == null)
		return;
	var aSeatedOptions = fldSeatedUsers.options;
	if (aSeatedOptions == null)
		return;
		
	var aNewEligibleOptions = new Array();
	iNumOptions = aEligibleOptions.length;
	for (iSeatAdminLoop = 0; iSeatAdminLoop < iNumOptions; iSeatAdminLoop++)
	{
		var eligibleOption = aEligibleOptions[iSeatAdminLoop];
		if (eligibleOption == null)
			continue;
		if (eligibleOption.selected)
		{
			var newSeatedOption = new Option();
			newSeatedOption.value = eligibleOption.value;
			newSeatedOption.text = eligibleOption.text;
			aSeatedOptions[aSeatedOptions.length] = newSeatedOption;
		}
		else
			aNewEligibleOptions[aNewEligibleOptions.length] = eligibleOption;
	}
	seatAdminSetOptions(fldEligibleUsers, aNewEligibleOptions);
}

function seatAdminRemoveUsers()
{
	var frmForm = document.seatAdminDetail;
	if (frmForm == null)
		return;
	var fldEligibleUsers = frmForm.eligibleUsers;
	if (fldEligibleUsers == null)
		return;
	var aEligibleOptions = fldEligibleUsers.options;
	if (aEligibleOptions == null)
		return;
	var fldSeatedUsers = frmForm.seatedUsers;
	if (fldSeatedUsers == null)
		return;
	var aSeatedOptions = fldSeatedUsers.options;
	if (aSeatedOptions == null)
		return;
		
	var aNewSeatedOptions = new Array();
	iNumOptions = aSeatedOptions.length;
	for (iSeatAdminLoop = 0; iSeatAdminLoop < iNumOptions; iSeatAdminLoop++)
	{
		var seatedOption = aSeatedOptions[iSeatAdminLoop];
		if (seatedOption == null)
			continue;
		if (seatedOption.selected)
		{
			var newEligibleOption = new Option();
			newEligibleOption.value = seatedOption.value;
			newEligibleOption.text = seatedOption.text;
			aEligibleOptions[aEligibleOptions.length] = newEligibleOption;
		}
		else
			aNewSeatedOptions[aNewSeatedOptions.length] = seatedOption;
	}
	seatAdminSetOptions(fldSeatedUsers, aNewSeatedOptions);
}

function seatAdminOnSubmit(frmForm)
{
	if (frmForm == null)
		return false;
	var fldSeatedUsers = frmForm.seatedUsers;
	if (fldSeatedUsers == null)
		return false;
	var aSeatedOptions = fldSeatedUsers.options;
	if (aSeatedOptions == null)
		return false;
	iNumOptions = aSeatedOptions.length;
	for (iSeatAdminLoop = 0; iSeatAdminLoop < iNumOptions; iSeatAdminLoop++)
	{
		var seatedOption = aSeatedOptions[iSeatAdminLoop];
		if (seatedOption == null)
			continue;
		seatedOption.selected = true;
	}
	
	return true;
}




// ******************************
// Printable Pages
// ******************************
function printPage2()
{
    makePrintable2();
    print();
    makeNonPrintable2();
}

function makePrintable2()
{
    hideAllElementsWithId('screenSubHeader');
    hideAllElementsWithId('screenLeftMenu');
    hideAllElementsWithId('screenTitleRow');

    hideAllElementsWithId('headerRow1');
    hideAllElementsWithId('headerRow2');

    //show(document.getElementById('headerPrintRow1'));
    showAllElementsWithId('headerPrintRow3');
    hideAllElementsWithId('printButton');
    hideAllElementsWithId('requestButton');
    showAllElementsWithId('normalViewButton');

	// expand any scrollable divs
	aScrollDivs = document.all.scrollablediv;
	if (aScrollDivs != null)
	{
		if (aScrollDivs.length == null)
		{
			theDiv = aScrollDivs;
			aScrollDivs = new Array(1);
			aScrollDivs[0] = theDiv;
		}

		iNumDivs = aScrollDivs.length;
		for (iLoop = 0; iLoop < iNumDivs; iLoop++)
		{
			divCurrent = aScrollDivs[iLoop];
			if (divCurrent != null)
			{
                        //show_props(divCurrent,"div");
				divCurrent.style.overflow = "";
				divCurrent.style.margin = "5px";
			}
		}
	}

	// expand any Notes areas
	aNotes = document.all.ts_notesarea;
	if (aNotes != null)
	{
		if (aNotes.length == null)
		{
			theNote = aNotes;
			aNotes = new Array(1);
			aNotes[0] = theNote;
		}

		iNumNotes = aNotes.length;
		for (iLoop = 0; iLoop < iNumNotes; iLoop++)
		{
			fldNote = aNotes[iLoop];
			if (fldNote != null)
			{
				sNoteName = fldNote.name;
				sDivName = sNoteName + "_printablediv";
				fldDiv = document.all[sDivName];
				if (fldDiv != null)
				{
					sText = fldNote.value;
					if (sText != null)
					{
						fldNote.style.display = "none";
						sConvertedText = convertForHTML(sText);
						fldDiv.innerHTML = sConvertedText;
						fldDiv.style.display = "";
					}
				}
			}
		}
	}
}



// ******************************
// Revert Printable Pages back again
// ******************************
function makeNonPrintable2()
{
    showAllElementsWithId('screenSubHeader');
    showAllElementsWithId('screenLeftMenu');
    showAllElementsWithId('screenTitleRow');

    showAllElementsWithId('headerRow1');
    showAllElementsWithId('headerRow2');

    hideAllElementsWithId('headerPrintRow3');
    showAllElementsWithId('printButton');
    showAllElementsWithId('requestButton');
    hideAllElementsWithId('normalViewButton');

	// collapse any scrollable divs
	aScrollDivs = document.all.scrollablediv;
	if (aScrollDivs != null)
	{
		if (aScrollDivs.length == null)
		{
			theDiv = aScrollDivs;
			aScrollDivs = new Array(1);
			aScrollDivs[0] = theDiv;
		}

		iNumDivs = aScrollDivs.length;
		for (iLoop = 0; iLoop < iNumDivs; iLoop++)
		{
			divCurrent = aScrollDivs[iLoop];
			if (divCurrent != null)
			{
				divCurrent.style.overflow = "auto";
				divCurrent.style.margin = "5px";
			}
		}
	}

	// collapse any Notes areas
	aNotes = document.all.ts_notesarea;
	if (aNotes != null)
	{
		if (aNotes.length == null)
		{
			theNote = aNotes;
			aNotes = new Array(1);
			aNotes[0] = theNote;
		}

		iNumNotes = aNotes.length;
		for (iLoop = 0; iLoop < iNumNotes; iLoop++)
		{
			fldNote = aNotes[iLoop];
			if (fldNote != null)
			{
				sNoteName = fldNote.name;
				sDivName = sNoteName + "_printablediv";
				fldDiv = document.all[sDivName];
				if (fldDiv != null)
				{
                                        fldNote.style.display = "";
                                        fldDiv.innerHTML="";
                                        fldDiv.style.display = "none";
				}
			}
		}
	}
}
//********************************************************
//common function of companyHierarchy.jsp,  
//                   companyHierarchyContactView.jsp 
//		         and companyHierarchyFinDemoView.jsp
//********************************************************
 function printHierarchyPage()
 {
 	 hideAllElementsWithId('hierarchyButtonRow');
     makePrintable();
     print();
     makeNonPrintable();
     showAllElementsWithId('hierarchyButtonRow');
 }
//********************************************************
//common function of feedback.jsp, 
//                   helpYourself.jsp 
//		         and requestMissingCompanyConfirm.jsp
//********************************************************
 function flashWindow_(){
     window.open('/flash/index.html','advisenPop','menubar=no,scrollbars=no');
 }
 function manualWindow_(){
 	 window.open('manual.pdf','PopUp','menubar=yes,scrollbars=yes');
 }
//********************************************************
//common function of tool_do_detail_1.jsp, tool_fd_detail_1.jsp,
//					 tool_limits_analysis_1.jsp,
//               and tool_rims_detail_1.jsp   	
//********************************************************
 function getCompanyName(formName){
	var id = formName.co_name_selection.value;
	if (id != null) {
	var companyValueArray = id.split("|");
		if (companyValueArray != null && companyValueArray.length > 1) {
		    formName.co_name.value=companyValueArray[1];
		}
	}
 }
//********************************************************
//common function of tool_do_detail_1.jsp, tool_fd_detail_1.jsp,
//					 tool_limits_analysis_1.jsp, tool_rims_detail_1.jsp
//					 policy_mgmnt_view.jsp, tool_xpress_chart.jsp
//               and projectTab.jsp   	
//******************************************************** 
 function showAllCompanies() {
    var options = document.all['companyOption'];
    for (var i = 0; i < options.length; i++) {
        var option = options[i];
        var rows = getElementsById('cid' + option.value);
        for (var j = 0; j < rows.length; j++) {
            var row = rows[j];
            if ((row.sourceIndex % 2) == 0) {
                row.bgColor = 'EEEFF0';
            } else {
                row.bgColor = 'FFFFFF';
            }
            show(row);
        }
    }
 } 
 
 /*
==================================================================
LTrim(string) : Returns a copy of a string without leading spaces.
==================================================================
*/
function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

/*
==================================================================
RTrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
*/
function RTrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to RTrim

*/
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}

/*
=============================================================
Trim(string) : Returns a copy of a string without leading or trailing spaces
=============================================================
*/
function Trim(str)
/*
   PURPOSE: Remove trailing and leading blanks from our string.
   IN: str - the string we want to Trim

   RETVAL: A Trimmed string!
*/
{
   return RTrim(LTrim(str));
}
//********************************************************
//dynamic list box - add an option 
//********************************************************
function addToList(listField, newText, newValue) {
   if ( ( newValue == "" ) || ( newText == "" ) ) {
      alert("You cannot add blank values!");
   } else {
	  var flag = false;   	  
	  var currLen = listField.options.length;
	  for (i=0;i<currLen;i++){
		var x = Trim(listField.options[i].text);
		var y = Trim(newValue);
	  	if (x == y){
			flag = true
		 	break;
		}
	  }
	  if (flag == false){
      	var len = listField.options.length++; // Increase the size of list and return the size
	  	listField.options[len].value = newValue;
      	listField.options[len].text = newText+"   ";
      	//listField.selectedIndex = len; // Highlight the one just entered (shows the user that it was entered)
	  }
	  for (i=0;i<len+1;i++){
	  	listField.options[i].selected = true;	
	  }
   } // Ends the check to see if the value entered on the form is empty
}
//********************************************************
//dynamic list box - remove an option(s) 
//********************************************************
function removeFromList(listField) {
   if ( listField.length == -1) {  // If the list is empty
      alert("There are no values which can be removed!");
   } else {
      var selected = listField.selectedIndex;
      if (selected == -1) {
         alert("You must select an entry to be removed!");
      } else {  
		 var tempArray1 = new Array(listField.length);
		 var tempArray2 = new Array(listField.length);
		 var delLen = 0;var j = 0;
         for (var i = 0; i < listField.length; i++) {
		 	var o=listField.options[i]; 
			if (o.selected){
				delLen++;
			}else{
				tempArray1[j] = o.text;
				tempArray2[j] = o.value;
				j++;
			}	
         }
		 var remLen = listField.length - delLen;
		 listField.length = remLen;		 
		 for (i = 0; i < remLen; i++){
		 	listField.options[i].value = tempArray1[i];
            listField.options[i].text = tempArray2[i]+"   ";
            listField.options[i].selected = true;
		 }
		 listField.selectedIndex = -1;
      } 
   }
}

//********************************************************
// PrametrizedJspItenPM related
//********************************************************

function showDesciption(object) {

alert(object.options[object.selectedIndex].value);
object.selectedIndex=-1;
}

function synchParams(param1, param2)
{
  param1.value = param2.value;
//  alert(parent.document.getElementsByName(<%=fieldNameId%>).value); 
 // alert(param1.value);
  
}


function modifyParameters(param, name, plan, value, parentId)
{
//alert(param.value + " " + name + " " + plan + " " + value);
  str = param.value;
  var str1;
  var str2;
  name_index = str.indexOf(name);
  //alert(str + " : " + name_index);
  if(name_index >= 0) //have this name already
  {
    next_index = str.indexOf("[", name_index+1); //look for the end of this parameter
	//alert("next [=" + next_index);
    if(!(next_index >= 0))
      next_index = str.length;
    str1 = str.substr(0, next_index);
    plan_index = str1.indexOf("{"+plan, name_index+1);
    next_plan = plan+1;
    next_plan_index = str1.indexOf("{"+next_plan, name_index+1);
    if(plan_index >= 0)
    {
      //data_index = str1.indexOf("|", plan_index);
      if(next_plan_index >=0)
        str2 = str.substr(next_plan_index);
      else
        str2 = str.substr(next_index);
      //if(data_index>=0)
        str1=str.substr(0, plan_index);
    }
    else
    {
      str1 = str.substr(0, next_index);
      str2 = str.substr(next_index);
      }
  }
  else //first for this name
  {
    if(str.length > 0)
      str1 = str + "[" + name;
    else
      str1 = name;
    str2 = "";
    }
  param.value = str1 + "{" + plan + "|" + value + str2;
if(parentId != null && parentId.length > 0)
 parent.document.getElementById(parentId).value=param.value;
 
}

function createValue(cId)
{
		var els = getElementsById(cId);
    var str = "";
		for (var e = 0; e < els.length; e++)
		{
          tmp = els[e].value;
          if(tmp != null && tmp.length > 0)
          {
            str += tmp;
            if(e < els.length-1)
              str +="|";
            }
		}
    return str;
}

function isDate(date)
{
  var ret = false;
  var ValidChars = "0123456789";
  if(date == null || date.length == 0)
    return ret;
  var slash = "/";
  if(date.length == 10)
  {
    ret = true;
    for(i=0; i<10; i++)
    {
      if(i==2 || i==5)
      {
        if(slash.indexOf(date.charAt(i)) == -1)
        {
          ret = false;
          break;
        }
      }
      else if(ValidChars.indexOf(date.charAt(i)) == -1)
      {
          ret = false;
          break;
      }
    }
  }
  if(!ret)
    alert("Date format should be mm/dd/yyy, not " + date + " !");
  return ret;
}

function setSelectedPage(numberOfPaging, pageNumber, maxPage, type)
{
	var selectedPage = document.all('selectedPage');
	var startPageNumber = document.all('startPageNumber');
	var endPageNumber = document.all('endPageNumber');

	selectedPageValue = selectedPage.value;
	startPageNumberValue = startPageNumber.value;
	endPageNumberValue = endPageNumber.value;

	selectedPage.value = pageNumber;

	if (Trim(type) == "")
	{
		if (parseInt(pageNumber) == 1)
		{
			startPageNumber.value = 1;
			endPageNumber.value = numberOfPaging;
		}
		else if (parseInt(pageNumber) == parseInt(maxPage))
		{
			startPageNumber.value = parseInt(pageNumber) - (parseInt(numberOfPaging) - 1);
			endPageNumber.value = pageNumber;
			if (parseInt(startPageNumber.value) < 1)
			{
				startPageNumber.value = 1;
				endPageNumber.value = numberOfPaging;
			}
		}
		else if (parseInt(pageNumber) == (parseInt(startPageNumberValue) + 1) || parseInt(pageNumber) == parseInt(startPageNumberValue))
		{
			startPageNumber.value = parseInt(pageNumber) - (parseInt(numberOfPaging) - 1);
			endPageNumber.value = parseInt(startPageNumber.value) + (parseInt(numberOfPaging) - 1);
			if (parseInt(startPageNumber.value) < 1)
			{
				startPageNumber.value = 1;
				endPageNumber.value = numberOfPaging;
			}
		}
		else if (parseInt(pageNumber) == (parseInt(endPageNumberValue) - 1) || parseInt(pageNumber) == parseInt(endPageNumberValue))
		{
			startPageNumber.value = pageNumber;
			endPageNumber.value = parseInt(startPageNumber.value) + (parseInt(numberOfPaging) - 1);
			if (parseInt(endPageNumber.value) > parseInt(maxPage))
			{
				startPageNumber.value = parseInt(maxPage) - (parseInt(numberOfPaging) - 1);
				endPageNumber.value = maxPage;
			}
		}
	}
	else if (Trim(type) == "back")
	{
		if (parseInt(pageNumber) == (parseInt(startPageNumberValue) + 1) || parseInt(pageNumber) == parseInt(startPageNumberValue))
		{
			startPageNumber.value = parseInt(pageNumber) - (parseInt(numberOfPaging) - 1);
			endPageNumber.value = parseInt(startPageNumber.value) + (parseInt(numberOfPaging) - 1);
			if (parseInt(startPageNumber.value) < 1)
			{
				startPageNumber.value = 1;
				endPageNumber.value = numberOfPaging;
			}
		}
		else
		{
			if (parseInt(pageNumber) < startPageNumber.value)
			{
				endPageNumber.value = parseInt(pageNumber);
				startPageNumber.value = parseInt(endPageNumber.value) - (parseInt(numberOfPaging) - 1);
				if (parseInt(startPageNumber.value) < 1)
				{
					startPageNumber.value = 1;
					endPageNumber.value = numberOfPaging;
				}
			}
			else
			{
				startPageNumber.value = parseInt(endPageNumber.value) - (parseInt(numberOfPaging) - 1);
			}
		}
	}
	else if (Trim(type) == "forward")
	{
		if (parseInt(pageNumber) == (parseInt(endPageNumberValue) - 1) || parseInt(pageNumber) == parseInt(endPageNumberValue))
		{
			startPageNumber.value = pageNumber;
			endPageNumber.value = parseInt(startPageNumber.value) + (parseInt(numberOfPaging) - 1);
			if (parseInt(endPageNumber.value) > parseInt(maxPage))
			{
				startPageNumber.value = parseInt(maxPage) - (parseInt(numberOfPaging) - 1);
				endPageNumber.value = maxPage;
			}
		}
		else
		{
			if (parseInt(pageNumber) > endPageNumber.value)
			{
				startPageNumber.value = parseInt(pageNumber);
				endPageNumber.value = parseInt(startPageNumber.value) + (parseInt(numberOfPaging) - 1);
				if (parseInt(endPageNumber.value) > parseInt(maxPage))
				{
					endPageNumber.value = parseInt(maxPage);
					startPageNumber.value = parseInt(endPageNumber.value) - (parseInt(numberOfPaging) - 1);
				}
			}
			else
			{
				endPageNumber.value = parseInt(startPageNumber.value) + (parseInt(numberOfPaging) - 1);
			}
		}
	}
}
		
function selectAllCheckBox(checkbox)
{
	if (checkbox != null)
	{
		if (checkbox.length == undefined)
		{
			checkbox.checked = true;
		}
		else
		{
			for (i = 0; i < checkbox.length; i++)
			{
				checkbox[i].checked = true;
			}
		}
	}
}

function clearAllCheckBox(checkbox)
{
	if (checkbox != null)
	{
		if (checkbox.length == undefined)
		{
			checkbox.checked = false;
		}
		else
		{
			for (i = 0; i < checkbox.length; i++)
			{
				checkbox[i].checked = false;
			}
		}
	}
}

function setOrderBy(form, orderBy, index)
{
	var selectedPage = document.all('selectedPage');
	var isOrderBy = document.all('isOrderBy');
	var order_by = document.all('orderBy');
	var order = document.all('order');
	var headerIndex = document.all('headerIndex');
	var image = document.all('image');
	
	order_by.value = orderBy;

	if (Trim(order.value) == "ASC")
	{
		order.value = "DESC";
		image.value = "arrow-down.gif";
	}
	else
	{
		order.value = "ASC";
		image.value = "arrow-up.gif";
	}
	isOrderBy.value = true;
	headerIndex.value = index;
	selectedPage.value = "1";

	form.submit();
	return false;
}

