﻿// JScript File

//BudgetDayWs Messages
var BudgetDayWs_Question1 = "You have extra income this week. You can leave it or<br/>transfer some or all of it to the accounts of your choice.";
var BudgetDayWs_Right1 = "You have distributed all of your extra income.";                         
var BudgetDayWs_Cross1 = "You can not allocate more money<br/>"
                       + "than your extra income this week.";
                       
var BudgetDayWs_Question2 = "You have allocated more money than required.<br/>"
                          + "The extra will create a cusion in your Mandatory Account.";
var BudgetDayWs_Right2 = "You have covered your shortfall.";                       
var BudgetDayWs_Cross2 = "Allocate money from your other accounts<br/>"
                       + "to make up for your shortfall this week."; 

//MonthEndWs Messages
var MonthEndWs_Question1 = "You have extra savings this month.<br/>"
                         + "Please allocate an amount to your savings account(s)";
var MonthEndWs_Right1 = "You have distributed all of your extra savings.";                       
var MonthEndWs_Cross1 = "You can not allocate more money<br/>"
                      + "than your extra savings this month.";

var MonthEndWs_Question2 = "You have allocated more money than required.<br/>"
                         + "The extra will create a cusion in your Mandatory Account.";
var MonthEndWs_Right2 = "You have covered your shortfall.";                        
var MonthEndWs_Cross2 = "Reduce your savings to cover your shortfall this month.";

var MonthEndWs_Right3 = "You neither have extra savings above your budget<br/>"
                      + "nor a shortfall of savings below your budget.";

//Image Sources
var src_Question = "images/questionmark.gif";
var src_Right = "images/rightmark.gif";
var src_Cross = "images/crossmark'.gif";

function trimAll(sString) 
{
    while (sString.substring(0,1) == ' ')
    {
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length-1, sString.length) == ' ')
    {
        sString = sString.substring(0,sString.length-1);
    }
    return sString;
}

function setLblErrorValue(text)
{
    if(document.getElementById('lblError'))
        document.getElementById('lblError').innerHTML=text;
    else if(document.getElementById('ctl00_ContentPlaceHolder1_lblError'))
        document.getElementById('ctl00_ContentPlaceHolder1_lblError').innerHTML=text;
}

function IsNumeric(field)
{
	var num='0123456789';			
	for(var i=0;i<field.length;i++)
	{
		if((num.indexOf(field.charAt(i)))==-1)
		{	
			return false;											
		}
	}
		
	return true;
}

function setSelectedOptionValueInHiddenField(drpId,hdnId)
{

    var drp=document.getElementById(drpId);
    var i=document.getElementById(drpId).selectedIndex;
    var hdn=document.getElementById(hdnId);
    hdn.value=drp.options[i].value;
   
}

function checkForDecimalValue(txtID,msg)
{
    var txtBoxValue='';
    txtBox=document.getElementById(txtID);
    if (txtBox==null) return;
    if (txtBox.style.display=="none") return true;
    txtBoxValue=trimAll(txtBox.value);
    txtBox.value=txtBoxValue;
    if((txtBoxValue!='') &&  (!IsNumericDot(txtBoxValue)))
    {
        setLblErrorValue(msg +' should be numeric value.');
        txtBox.focus();
        return false;
    }
    return true;
}

function checkForBlankValue(txtID,msg)
{
    var txtBoxValue='';
    txtBox=document.getElementById(txtID); 
    if (txtBox==null) return;
    if (txtBox.style.display=="none") return true;
    txtBoxValue=trimAll(txtBox.value);
    txtBox.value=txtBoxValue;
    if(txtBoxValue=='')
    {
        setLblErrorValue(msg +' should not be blank.');
        txtBox.focus();
        return false;
    }
    return true;
}

function IsNumericDot(field)
{
	var num='0123456789.';
	var dot=".";
	var NoOfDots=0;			
	for(var i=0;i<field.length;i++)
	{
		if((num.indexOf(field.charAt(i)))==-1)
		{	
			return false;											
		}
		if((dot.indexOf(field.charAt(i)))>=0)
		{	
			NoOfDots=NoOfDots+1;
		}
	}
	if(NoOfDots>1) return false;				
	return true;
}

function setAmountOfParentWindow(headtext)
{
    parent.document.getElementById('lblAmount').innerHTML=document.getElementById('hdnAmount').value;
    //parent.document.getElementById('lblPageHead').innerHTML=headtext;
}
function ChangeImage(imgID,strImage)
{
    if(document.getElementById(imgID))
        document.getElementById(imgID).src=strImage; 
}

function IsBlankSpaceExists(str)
{
    if(str.indexOf(' ')>=0) return true;
    return false;    
}

//Updation of Wizard Amount
function UpdateAmount(obj,action,ctlToUpdate,Event)
{
    if(!Event) Event=window.event;
    if(Event && Event.keyCode==17) return;
        
    if((obj.prevAmount)=='') obj.prevAmount=0;     else     obj.prevAmount=parseFloat(obj.prevAmount);
    if((obj.currAmount)=='') obj.currAmount=0;     else     obj.currAmount=parseFloat(obj.currAmount);
    if(isNaN(obj.prevAmount))obj.prevAmount=0;
    if(isNaN(obj.currAmount))obj.currAmount=0; 


    var WzAmount;
    WzAmount=parent.document.getElementById('lblAmount').innerHTML; 
    WzAmount=WzAmount.replace('$','');
    WzAmount=WzAmount.replace(',','');
    
    var lprevAmount,lcurrAmount;
    lprevAmount=calculateAnnualAmt(obj.prevAmount,obj.prevFrequency)    
    lcurrAmount=calculateAnnualAmt(obj.currAmount,obj.currFrequency)
    
    updateStepsAmount(lprevAmount,lcurrAmount,ctlToUpdate,action)
    
    if(action=='add')
    {
        if(WzAmount.indexOf('-')!=-1)
            {
               WzAmount=WzAmount.replace('-','');
               if(IsNumericDot(WzAmount)==false)return;
               WzAmount=0-parseFloat(WzAmount)-parseFloat(lprevAmount)+parseFloat(lcurrAmount);
            }
        else
            {
                if(IsNumericDot(WzAmount)==false)return;
                WzAmount=parseFloat(WzAmount)-parseFloat(lprevAmount)+parseFloat(lcurrAmount);
            }
     }
     else if(action=='subtract')
     {
        if(WzAmount.indexOf('-')!=-1)
            {
               WzAmount=WzAmount.replace('-','');
               if(IsNumericDot(WzAmount)==false)return;
               WzAmount=0-parseFloat(WzAmount)+parseFloat(lprevAmount)-parseFloat(lcurrAmount);
            }
        else
            {
                if(IsNumericDot(WzAmount)==false)return;
                WzAmount=parseFloat(WzAmount)+parseFloat(lprevAmount)-parseFloat(lcurrAmount);
            } 
     }   
      
   WzAmount=parseFloat(WzAmount)*100;
   WzAmount=parseInt(Math.round(WzAmount));
   WzAmount=parseFloat(WzAmount)/100;
   parent.document.getElementById('lblAmount').innerHTML=WzAmount;  

}
function updateStepsAmount(lprevAmount,lcurrAmount,ctlToUpdate,action)
{
    var positiveText='If you feel that the Little Extra Cash is too high, lower your Income Entries or&nbsp;'
        + 'increase your Credit Payments, Personal Allowance and Savings Amounts. This will&nbsp;'
        + 'lower these numbers. Keep in mind that these are yearly amounts. You want a balanced&nbsp;'
        + 'budget so you know what is extra when it comes in.';
    var negativeText='You have a shortage of cashflow.'
        + 'You will either have to increase your income, or decrease your Expenses&nbsp;'
        + ', Credit Payments, Personal Allowance and Savings Amounts.&nbsp;'                     
        + 'You must bring your budget to a balance of zero.';
    var positiveColor='#069fff';
    var negativeColor='';
    var IsNegative='false';
    var lblExtraID='lblExtra';
    if (parent.window[1].document.getElementById(ctlToUpdate)==null) return;
    if (parent.window[1].document.getElementById(lblExtraID)==null) return;
    
    //Update Label's Value
    var ctlValue=trimAll(parent.window[1].document.getElementById(ctlToUpdate).innerHTML);
    parent.window[1].document.getElementById(ctlToUpdate).innerHTML=ctlValue;
    if(ctlValue.indexOf('-')!=-1)
    {
       ctlValue=ctlValue.replace('-','');
       IsNegative = 'true'
    }
    else
    {
        IsNegative = 'false';
    } 
    if(IsNumericDot(ctlValue)==false)return;
    if(IsNegative=='true')
        ctlValue=0-parseFloat(ctlValue)-parseFloat(lprevAmount)+parseFloat(lcurrAmount);
    else
        ctlValue=parseFloat(ctlValue)-parseFloat(lprevAmount)+parseFloat(lcurrAmount);
    ctlValue=getRoundedValue(ctlValue,2);
    parent.window[1].document.getElementById(ctlToUpdate).innerHTML=ctlValue;
    
    
    //Update Extra Amount
    var extraValue = trimAll(parent.window[1].document.getElementById(lblExtraID).innerHTML);
    parent.window[1].document.getElementById(lblExtraID).innerHTML=extraValue;
    extraValue= getNegativeValue(extraValue);
    if(extraValue.indexOf('-')!=-1)
    {
        extraValue=extraValue.replace('-','');
        IsNegative = 'true';
    }
    else
    {
        IsNegative ='false';
    }
    if(IsNumericDot(extraValue)==false)return;        
    switch(action)
    {
        case "add":
            if (IsNegative=='true')
                extraValue=0-parseFloat(extraValue)-parseFloat(lprevAmount)+parseFloat(lcurrAmount); 
            else
                extraValue=parseFloat(extraValue)-parseFloat(lprevAmount)+parseFloat(lcurrAmount);                     
            break;
        case "subtract":
            if (IsNegative=='true')
                extraValue=0-parseFloat(extraValue)+parseFloat(lprevAmount)-parseFloat(lcurrAmount); 
            else
                extraValue=parseFloat(extraValue)+parseFloat(lprevAmount)-parseFloat(lcurrAmount);                     
            break;
    }        
    extraValue=getRoundedValue(extraValue,2);
    if(parseFloat(extraValue)< 0)
    {
    if(parent.window[1].document.getElementById('tdExtra')!=null)
        parent.window[1].document.getElementById('tdExtra').style.color=negativeColor;
    if(parent.window[1].document.getElementById('tdTotalExtra')!=null)
        parent.window[1].document.getElementById('tdTotalExtra').style.color=negativeColor;
    if(parent.window[1].document.getElementById('tdBalancedBudgetText')!=null)
        parent.window[1].document.getElementById('tdBalancedBudgetText').innerHTML=negativeText;
    }
    else
    {
    if(parent.window[1].document.getElementById('tdExtra')!=null)
        parent.window[1].document.getElementById('tdExtra').style.color=positiveColor;
    if(parent.window[1].document.getElementById('tdTotalExtra')!=null)
        parent.window[1].document.getElementById('tdTotalExtra').style.color=positiveColor;
    if(parent.window[1].document.getElementById('tdBalancedBudgetText')!=null)
        parent.window[1].document.getElementById('tdBalancedBudgetText').innerHTML=positiveText;
    }
    parent.window[1].document.getElementById(lblExtraID).innerHTML=getNegativeFormat(extraValue);
    
    //Update Other Labels
    if(parent.window[1].document.getElementById('lblTotalExtra')!=null)
        parent.window[1].document.getElementById('lblTotalExtra').innerHTML=getNegativeFormat(extraValue);
    if(parent.window[1].document.getElementById('lblMandatoryExpenseExtra')!=null)
        parent.window[1].document.getElementById('lblMandatoryExpenseExtra').innerHTML=getNegativeFormat(getRoundedValue(parseFloat(extraValue/2),2));
    if(parent.window[1].document.getElementById('lblDiscretionaryExpenseExtra')!=null)
        parent.window[1].document.getElementById('lblDiscretionaryExpenseExtra').innerHTML=getNegativeFormat(getRoundedValue(parseFloat(extraValue/2),2));
    if(parent.window[1].document.getElementById('lblBalancedBudget')!=null)
        parent.window[1].document.getElementById('lblBalancedBudget').innerHTML='0';
}
function getNegativeFormat(valueToFormat)
{
    var strValueToFormat=String(valueToFormat);
    if (strValueToFormat.indexOf('-')!=-1)
    {
        strValueToFormat=strValueToFormat.replace('-','');
        strValueToFormat='(' + strValueToFormat + ')';
    }
    return strValueToFormat;
}
function getNegativeValue(value)
{
    var strValue=String(value);
    if(strValue.indexOf('(')!=-1) 
    {
        strValue = strValue.replace('(','');
        strValue = strValue.replace(')','');
        strValue = '-' + strValue;
    }
    return strValue;    
}
function getRoundedValue(valueToRound,scale)
{
    valueToRound=parseFloat(valueToRound)*(10*scale);
    valueToRound=parseInt(Math.round(valueToRound));
    valueToRound=parseFloat(valueToRound)/(10*scale);
    
    return valueToRound; 
}

function calculateAnnualAmt(prevAmount,prevFrequency)    
{
    var lAmount = 0;
    switch(prevFrequency)
    {
        case '0':
            lAmount=parseFloat(prevAmount)*52; 
            break;
        case '1':
            lAmount=parseFloat(prevAmount)*26;
            break;
        case '2':
            lAmount=parseFloat(prevAmount)*12;
            break;
        case '3':
            lAmount=parseFloat(prevAmount)*4;
            break;
        case '4':
            lAmount=parseFloat(prevAmount)*1;
            break;
    }
    return lAmount;
}
function getFormattedValue(WzAmount,prevAmount,currAmount)
{
    var xmlHttpObj;
    xmlHttpObj=getxmlHttpObj();
    if (xmlHttpObj==null)
    {
        WzAmount=Math.round(WzAmount)-Math.round(prevAmount)+Math.round(currAmount);
        parent.document.getElementById('lblAmount').innerHTML='$'+WzAmount; 
    }
    else
    {
        var QuerySting;
        QuerySting='?Handler=returnFormattedValue' + '&WzAmount=' + WzAmount + '&InitAmount=' + prevAmount + '&CurrAmount=' + currAmount;
        xmlHttpObj.onreadystatechange=function()
                            {
                                if(xmlHttpObj.readyState==4)
                                {
                                    parent.document.getElementById('lblAmount').innerHTML=''+xmlHttpObj.responseText;
                                }
                            }
        xmlHttpObj.open("GET","ajaxServer.aspx"+QuerySting,true);
        xmlHttpObj.send(null); 
    }
}
//

//Ajax
function getxmlHttpObj()
{  
    var xmlHttp;
    try
    {    
        // Firefox, Opera 8.0+, Safari    
        xmlHttp=new XMLHttpRequest();    
    }
    catch (e)
    {    
        // Internet Explorer    
        try
        {      
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
        }
        catch (e)
        {      
            try
            {        
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
            }
            catch (e)
            {        
                return null;        
            }      
        }    
    }
    return xmlHttp;
}
//    

//Object Template
function rowData(txtID,ddlID,prevAmount,prevFrequency,currAmount,currFrequency)
{
    this.txtID=txtID;
    this.ddlID=ddlID;
    this.prevAmount=prevAmount;
    this.prevFrequency=prevFrequency;
    this.currAmount=currAmount;
    this.currFrequency=currFrequency;
}
//
function setPreviousValues(obj,Event)
{
    var Element;
    if(!Event) Event=window.event;
    if(Event && Event.keyCode==17) return;
    
    //prevAmount
    Element = document.getElementById(obj.txtID);
    if(Element!=null)
        obj.prevAmount=Element.value;
    else
        obj.prevAmount=0;
        
    if(trimAll(obj.prevAmount)=='') obj.prevAmount=0;
    
    //prevFrequency
    Element = document.getElementById(obj.ddlID);
    if(Element!=null)
        obj.prevFrequency=Element.value;        
    else
        obj.prevFrequency=0;
}
function setCurrValues(obj,Event)
{
    var Element;
    if(!Event) Event=window.event;
    if(Event && Event.keyCode==17) return;
    
    //Curr Amount
    Element = document.getElementById(obj.txtID);
    if(Element!=null)
        obj.currAmount = Element.value;
    else
        obj.currAmount = 0;
        
    if(trimAll(obj.currAmount)=='') obj.currAmount=0;
    
    //Curr Frequency
    Element = document.getElementById(obj.ddlID);
    if(Element!=null)
        obj.currFrequency=Element.value;        
    else
        obj.currFrequency=0;    
}
function returnObject(txtID,ddlID)
{
    var lprevAmount,lprevFrequency,lcurrAmount,lcurrFrequency;
    var Element;
    
    if(document.getElementById(txtID)==null)
    {
        obj=null;
    }
    else
    {
        Element = document.getElementById(txtID);
        if(Element!=null)
            lprevAmount= Element.value;
        else
            lprevAmount=0;
            
        Element = document.getElementById(ddlID);    
        if(Element!=null)
            lprevFrequency=Element.value; 
        else
            lprevFrequency=0;
            
        lcurrAmount=lprevAmount; 
        lcurrFrequency=lprevFrequency; 
        obj=new rowData(txtID,ddlID,lprevAmount,lprevFrequency,lcurrAmount,lcurrFrequency);
    }
    return obj;
}
function fnDelete(delID,strSP)
{
    var xmlHttpObj;
    var deleted='false';

    if (delID=='0') 
    {
        deleted='true'
        return deleted;
    }
    xmlHttpObj=getxmlHttpObj();
    if (xmlHttpObj==null)
    {
        deleted = 'false';
        return deleted;
    }
    else
    {
        var QuerySting;
        QuerySting='?Handler=fnDelete' + '&delID=' + delID + '&strSP=' + strSP;
        xmlHttpObj.onreadystatechange=function()
                            {
                                if(xmlHttpObj.readyState==4)
                                {
                                    if(xmlHttpObj.responseText=='TRUE')
                                    {    
                                        deleted = 'true';
                                    }
                                    else
                                    {
                                        deleted = 'false';
                                    }
                                }
                                return deleted;
                            }
        xmlHttpObj.open("GET","ajaxServer.aspx"+QuerySting,true);
        xmlHttpObj.send(null); 
    }
}
function tabMouseOver(imageId,imageSrc)
{
    if(document.getElementById(imageId))
        document.getElementById(imageId).src=imageSrc;
}
function tabMouseOut(tabNo,imageId,imageSrc1,imageSrc2)
{
if(clickedTab==tabNo)
   document.getElementById(imageId).src=imageSrc2;
     else document.getElementById(imageId).src=imageSrc1;
}
 function restoreImages()
    {
    document.getElementById('Image9').src='../images/aboutnew01.gif';
    document.getElementById('Image19').src='../images/SystemExplained01.gif';
    document.getElementById('Image20').src='../images/sysBen01.gif';
    document.getElementById('Image21').src='../images/SystemTools01.gif';
    document.getElementById('Image22').src='../images/commQuew01.gif';
    }
function displayRow(tableRowId)
{
     if(!document.getElementById(tableRowId)) return;
     
     try
     {
       document.getElementById(tableRowId).style.display='table-row';
     }
     catch(err)
     {
       document.getElementById(tableRowId).style.display='block';
     }
     finally
     {
       //document.getElementById(tableRowId).style.height='23px';
     }
}

function hideRow(tableRowId)
{
     if(!document.getElementById(tableRowId)) return;
     document.getElementById(tableRowId).style.display='none';
}

function checkExistence(elementID)
{
    if(document.getElementById(elementID)!=null) return true;
    return false;
}

function setPaymentInfo()
{
    if(checkExistence('txtBusiness')==true && checkExistence('business')==true)
        document.getElementById('business').value=document.getElementById('txtBusiness').value;

    if(checkExistence('txtNotifyURL')==true && checkExistence('notify_url')==true)
        document.getElementById('notify_url').value=document.getElementById('txtNotifyURL').value;

    if(checkExistence('txtCancelReturn')==true && checkExistence('cancel_return')==true)
        document.getElementById('cancel_return').value=document.getElementById('txtCancelReturn').value;

    if(checkExistence('txtReturn')==true && checkExistence('return')==true)
        document.getElementById('return').value=document.getElementById('txtReturn').value;

    if(checkExistence('txtItemNumber')==true && checkExistence('item_number')==true)
        document.getElementById('item_number').value=document.getElementById('txtItemNumber').value;
        
   if(checkExistence('txtActionUrl')==true && checkExistence('frmPaypal')==true)
        document.getElementById('frmPaypal').action=document.getElementById('txtActionUrl').value;

   if(checkExistence('txtAmount3')==true && checkExistence('a3')==true)
        document.getElementById('a3').value=document.getElementById('txtAmount3').value;
}



function _validateInputs(direction,NoOfTabs,objTabIds)
{
    if(parent.parentTabClicked==true)
        return validateInputs();

    var StepNo = 0;
    var returnValue = new Boolean();
    var objStepNo = document.getElementById('stepNo');
    if(objStepNo!=null) StepNo = objStepNo.innerText;
    
    if(validateInputs()==false)
    {
        returnValue = false;
    }
    else
    {
        switch(direction)
        {
            case -1:   //Previous
                if(selectedTabIndex > 1)
                {
                    switch(selectedTabIndex)
                    {
                        case 2:
                        case 3:
                            ShowTableRow(objTabIds[--selectedTabIndex]);
                            break;
                    }                                
                    StepNo--;
                    returnValue = false;
                }
                else
                {
                    returnValue = true;
                }    
                break;
            case 1:   //Next
                if(selectedTabIndex < NoOfTabs)
                {
                    switch(selectedTabIndex)
                    {
                        case 1:
                        case 2:
                            ShowTableRow(objTabIds[++selectedTabIndex]);
                            break;
                    }                                
                    StepNo++;
                    returnValue = false;
                }
                else
                {
                    returnValue = true;
                }    
                break;
        }
    }
    
    if((objStepNo != null) && (StepNo > 0)) 
    {
        objStepNo.innerText = StepNo;
        parent.currentStep = StepNo;
    }
    
    return returnValue;     
}

function setCurrentStep(stepNo)
{
    parent.currentStep = stepNo;
    if(document.getElementById('stepNo'))
        document.getElementById('stepNo').innerText = parent.currentStep;

}

function printPage()
{
   print();
}

function canContinue(txtBoxID,hideElement)
{
    var returnValue = new Boolean();
    returnValue = true;
    
    if((txtBoxID!='') && hideElement)
    {
        var txtBox = document.getElementById(txtBoxID);
        if((txtBox!=null) && (txtBox.value!=''))
        {
            alert('Can not hide an item with an amount indicated.');
            returnValue = false;
        }
    }
    
    return returnValue;   
}

function showAllPredefinedDescriptions(PageName)
{
    var startIndex=0, endIndex=0, RowPrefix='tr';
    
    switch(selectedTabIndex)
    {
        case 1:
            switch(PageName)
            {
                case "ME":
                    startIndex=1;
                    endIndex=10;
                    break;
                case "DE":
                    startIndex=1;
                    endIndex=6;
                    break;
                case "SA":
                    startIndex=1;
                    endIndex=2;
                    break;
            }
            break;
        case 2:
            switch(PageName)
            {
                case "ME":
                    startIndex=16;
                    endIndex=19;
                    break;
                case "DE":
                    startIndex=12;
                    endIndex=18;
                    break;
                case "SA":
                    startIndex=8;
                    endIndex=15;
                    break;
            }
            break;
        case 3:
            switch(PageName)
            {
                case "ME":
                    startIndex=25;
                    endIndex=36;
                    break;
            }
            break;
    }
    if((startIndex > 0) && (endIndex > 0))
    {
        for(var counter=startIndex; counter<=endIndex; counter++)
        {
            displayRow(RowPrefix + counter);
            displayRow('_' + RowPrefix + counter);
            if(document.getElementById("Hidden" + counter))
                document.getElementById("Hidden" + counter).value = 0;
        }
    }
}

function showHideRows(PageName)
{
    var startIndex=0, endIndex=0, RowPrefix='tr';
    switch(selectedTabIndex)
    {
        case 1:
            switch(PageName)
            {
                case "ME":
                    startIndex=1;
                    endIndex=10;
                    break;
                case "DE":
                    startIndex=1;
                    endIndex=6;
                    break;
                case "SA":
                    startIndex=1;
                    endIndex=2;
                    break;
            }
            break;
        case 2:
            switch(PageName)
            {
                case "ME":
                    startIndex=16;
                    endIndex=19;
                    break;
                case "DE":
                    startIndex=12;
                    endIndex=18;
                    break;
                case "SA":
                    startIndex=8;
                    endIndex=15;
                    break;
            }
            break;
        case 3:
            switch(PageName)
            {
                case "ME":
                    startIndex=25;
                    endIndex=36;
                    break;
            }
            break;
    }
    var hdnField;
    for(var Counter=startIndex;Counter<=endIndex;Counter++)
    {
        if((Counter >= 31) && (Counter <= 35) && (PageName=="ME")) continue;
    
        hdnField=document.getElementById("Hidden" + Counter);
        if(hdnField==null) continue;
        
        switch(hdnField.value)
        {
            case '0':   //make visible
                displayRow(RowPrefix + Counter);
                displayRow("_" + RowPrefix + Counter);
                break;
            case '1':  //make hidden
                hideRow(RowPrefix + Counter);
                hideRow("_" + RowPrefix + Counter);
                break;
        }
    }
}


//Updation of WorkSheet Amount
function UpdateWSAmount(obj,action,ctlToUpdate,Event)
{
    if(!Event) Event=window.event;
    if(Event && Event.keyCode==17) return;
        
    if((obj.prevAmount)=='') obj.prevAmount=0;     else     obj.prevAmount=parseFloat(obj.prevAmount);
    if((obj.currAmount)=='') obj.currAmount=0;     else     obj.currAmount=parseFloat(obj.currAmount);
    if(isNaN(obj.prevAmount))obj.prevAmount=0;
    if(isNaN(obj.currAmount))obj.currAmount=0;

    
    var lprevAmount,lcurrAmount;
    lprevAmount=obj.prevAmount;
    lcurrAmount=obj.currAmount;
    
    updateWSActualAmount(lprevAmount,lcurrAmount,ctlToUpdate,action)
    
    updateTotalAmount(ctlToUpdate);    

}
function updateWSActualAmount(lprevAmount,lcurrAmount,ctlToUpdate,action)
{
    var positiveColor='#069fff';
    var negativeColor='#ff4d0e';
    var IsNegative='false';
    var ctlElement,ctlValue;
    
    ctlElement = document.getElementById(ctlToUpdate);
    if (ctlElement==null) return;
    ctlValue=trimAll(ctlElement.innerHTML);
    ctlElement.innerHTML=ctlValue;
    if(ctlElement.style.color==negativeColor)
    {
        if(ctlValue.indexOf('-')!=0)
        {
            ctlValue = '-' + ctlValue;
        }
    }
    
    if(ctlValue.indexOf('-')!=-1)
    {
       ctlValue=ctlValue.replace('-','');
       IsNegative = 'true'
    }
    else
    {
        IsNegative = 'false';
    } 
    if(IsNumericDot(ctlValue)==false)return;
    switch(action)
    {
        case "add":
            if (IsNegative=='true')
            {
                ctlValue=0-parseFloat(ctlValue)-parseFloat(lprevAmount)+parseFloat(lcurrAmount); 
            }
            else
            {
                ctlValue=parseFloat(ctlValue)-parseFloat(lprevAmount)+parseFloat(lcurrAmount);                     
            }
            break;
        case "subtract":
            if (IsNegative=='true')
            {
                ctlValue=0-parseFloat(ctlValue)+parseFloat(lprevAmount)-parseFloat(lcurrAmount); 
            }
            else
            {
                ctlValue=parseFloat(ctlValue)+parseFloat(lprevAmount)-parseFloat(lcurrAmount);                     
            }
            break;
    }        
    ctlValue=getRoundedValue(ctlValue,2);
    if(ctlValue < 0)
    {
        ctlValue = 0 - ctlValue;
        ctlElement.style.color = negativeColor;
    }
    else
    {
        ctlElement.style.color = positiveColor;
    }
    ctlElement.innerHTML=ctlValue;
}

function updateTotalAmount(ctlToUpdate)
{
    var positiveColor='#069fff';
    var negativeColor='#ff4d0e';
    var element;
    var totalTextBoxAmount = 0;
    var totalLabelAmount   = 0;
    var txtID = '', totalTxtID = '', lblID = '', totalLblID = '';
    var ExtraAmount = '';
    var extraAmountIsNegative = new Boolean(false);

    
    if (document.getElementById(ctlToUpdate)==null) return;
    
    switch(PageName)                
    {
        case "budgetdayws1.aspx":   
            txtID       = 'TextBox';
            totalTxtID  = 'lblTotalActualAmount';
            lblID       = 'lblDifference';
            totalLblID  = 'lblTotalDifference';
            break;
        case "budgetdayws2.aspx":  
        case "monthendworksheet.aspx":
            txtID       = 'TextBox';
            totalTxtID  = 'lblTotalAllocationAmount';
            lblID       = 'lblActualAmount';
            totalLblID  = 'lblTotalActualAmount';
            break;
    }
    for(var Counter=1;Counter<=20;Counter++)
    {
        element = document.getElementById(txtID + Counter);
        if (element!=null)
            totalTextBoxAmount += isNaN(parseFloat(element.value)) ? 0 : parseFloat(element.value);

        element = document.getElementById(lblID + Counter);
        if (element!=null)
        {
            if(element.style.color == negativeColor && element.innerHTML.indexOf('-')!=0)
            {
                totalLabelAmount += isNaN(parseFloat('-'+element.innerHTML)) ? 0 : parseFloat('-'+element.innerHTML);
            }
            else
                totalLabelAmount += isNaN(parseFloat(element.innerHTML)) ? 0 : parseFloat(element.innerHTML);
            
        }
    }

    //ExtraAmount
    element = document.getElementById('extraAmount');
    if (element!=null)
    {
        ExtraAmount = element.innerHTML;
        if(ExtraAmount.indexOf("(")>=0)
        {
            extraAmountIsNegative = true;    
            
            ExtraAmount = ExtraAmount.replace("(","");
            ExtraAmount = ExtraAmount.replace(")","");
        }
        
        ExtraAmount = parseFloat(ExtraAmount);
        
        if(isNaN(ExtraAmount)==false)
        {
            totalTextBoxAmount = ExtraAmount - totalTextBoxAmount;
            if(extraAmountIsNegative==true)
                totalTextBoxAmount = 0-totalTextBoxAmount;
        }
    }

    //01-sep-2007
    switch(PageName)                
    {
        case "monthendworksheet.aspx":
            if(isNaN(ExtraAmount)==false)
            {
                if(extraAmountIsNegative==true)
                    totalLabelAmount -= ExtraAmount;
                else
                    totalLabelAmount += ExtraAmount;
            }
            break;
    }   


    element=document.getElementById(totalTxtID);
    if (element!=null)
    {
        switch(PageName)                
        {
            case "budgetdayws1.aspx":  
                element.innerHTML = totalTextBoxAmount; 
                break;
            default:
                element.innerHTML = (totalTextBoxAmount==0) ? "Balanced" : totalTextBoxAmount;
                setColor(totalTxtID,true);
                setMessageAndImage(ExtraAmount, extraAmountIsNegative, totalTextBoxAmount);
                break;
        }
    }

    element=document.getElementById(totalLblID);
    if (element!=null)
    {
        if(parseFloat(totalLabelAmount) < 0) 
        {
            element.style.color = negativeColor;
            totalLabelAmount = 0 - parseFloat(totalLabelAmount);
        }
        else
        {
            element.style.color = positiveColor;
        }
        element.innerHTML = totalLabelAmount;
    }
}
function setMessageAndImage(ExtraAmount, extraAmountIsNegative, totalTextBoxAmount)
{
    var positiveColor='#069fff';
    var negativeColor='#ff4d0e';
    var img = document.getElementById("imgMessages");
    var lbl = document.getElementById("lblMessage");
    var imgSrc = "";
    var lblText = "", lblColor = "";
    
    if(img == null || lbl == null) return;

    if (extraAmountIsNegative==true) ExtraAmount = 0 - ExtraAmount;
    switch(PageName)                
    {
        case "budgetdayws2.aspx":  
            if(ExtraAmount>=0)
            {
                if(totalTextBoxAmount==0)
                {
                    imgSrc = src_Right;
                    lblText = BudgetDayWs_Right1; 
                    lblColor = positiveColor; 
                }
                else if(totalTextBoxAmount>0)
                {
                    imgSrc = src_Question;
                    lblText = BudgetDayWs_Question1; 
                    lblColor = positiveColor; 
                }
                else if(totalTextBoxAmount<0)
                {
                    imgSrc = src_Cross;
                    lblText = BudgetDayWs_Cross1; 
                    lblColor = negativeColor; 
                }
            }
            else
            {
                if(totalTextBoxAmount==0)
                {
                    imgSrc = src_Right;
                    lblText = BudgetDayWs_Right2; 
                    lblColor = positiveColor; 
                }
                else if(totalTextBoxAmount>0)
                {
                    imgSrc = src_Question;
                    lblText = BudgetDayWs_Question2; 
                    lblColor = positiveColor; 
                }
                else if(totalTextBoxAmount<0)
                {
                    imgSrc = src_Cross;
                    lblText = BudgetDayWs_Cross2; 
                    lblColor = negativeColor; 
                }
            }
            break;
        case "monthendworksheet.aspx":
            if(ExtraAmount==0)
            {
                imgSrc = src_Right;
                lblText = MonthEndWs_Right3; 
                lblColor = positiveColor; 
            }
            else if(ExtraAmount>0)
            {
                if(totalTextBoxAmount==0)
                {
                    imgSrc = src_Right;
                    lblText = MonthEndWs_Right1; 
                    lblColor = positiveColor; 
                }
                else if(totalTextBoxAmount>0)
                {
                    imgSrc = src_Question;
                    lblText = MonthEndWs_Question1; 
                    lblColor = positiveColor; 
                }
                else if(totalTextBoxAmount<0)
                {
                    imgSrc = src_Cross;
                    lblText = MonthEndWs_Cross1; 
                    lblColor = negativeColor; 
                }
            }
            else if(ExtraAmount<0)
            {
                if(totalTextBoxAmount==0)
                {
                    imgSrc = src_Right;
                    lblText = MonthEndWs_Right2; 
                    lblColor = positiveColor; 
                }
                else if(totalTextBoxAmount>0)
                {
                    imgSrc = src_Question;
                    lblText = MonthEndWs_Question2; 
                    lblColor = positiveColor; 
                }
                else if(totalTextBoxAmount<0)
                {
                    imgSrc = src_Cross;
                    lblText = MonthEndWs_Cross2; 
                    lblColor = negativeColor; 
                }
            }
            break;
    } 
    if(imgSrc != "" && lblText != "")
    {
        img.src = imgSrc;
        lbl.innerHTML = lblText;
        lbl.style.color = lblColor;
    }     
}
function getElementsValue(elementID,elementType,dataType)
{
    var element,result;
    
    element = document.getElementById(elementID);
    if(element!=null)
    {
        switch(elementType.toLowerCase())
        {
            case "textbox":
            case "dropdownlist":
                result = element.value;
                break;
            case "label":
                result = element.innerHTML;
                break;    
        }
    }
    else
    {
        switch(dataType.toLowerCase())
        {
            case "string":
                result='';
                break;
            case "numeric":
                result=0;
                break;
        }
    }
    
    return result;
}

function setFocus(elementID)
{
    var element;
    element = document.getElementById(elementID);
    if(element!=null)
        element.focus();   
}


function checkAllocation()
{
    var result = new Boolean(true);
    var difference, msg;
    
    var element, ExtraAmount, TotalBudgetAmount, TotalActualAmount;
    TotalBudgetAmount = parseFloat(getElementsValue("lblTotalBudgetAmount","label","numeric"));
    TotalBudgetAmount = isNaN(TotalBudgetAmount)? 0 : TotalBudgetAmount;
    
    TotalActualAmount = parseFloat(getElementsValue("lblTotalActualAmount","label","numeric"));
    TotalActualAmount = isNaN(TotalActualAmount)? 0 : TotalActualAmount;
    
    //extra Amount
    element = document.getElementById('extraAmount');
    if(element!=null && element.innerHTML!='')
    {
        ExtraAmount = element.innerHTML;
        ExtraAmount = ExtraAmount.replace('(','');
        ExtraAmount = ExtraAmount.replace(')','');
        ExtraAmount = parseFloat(ExtraAmount);
        ExtraAmount = isNaN(ExtraAmount) ? 0 : ExtraAmount;
        
        if(checkExistence("lblTotalBudgetAmount") && checkExistence("lblTotalActualAmount"))
        {
            if(element.innerHTML.indexOf('(')>=0)   //negative case
            {
                return result;
            }
            else                                    //positive case
            {
                difference = TotalActualAmount - TotalBudgetAmount;
                
                //01-sep-2007
                if (PageName=="monthendworksheet.aspx")
                {
                    difference = difference-ExtraAmount;
                }
                
                msg = "You can not allocate more than your extra";
                if (PageName=="budgetdayws2.aspx")
                    msg += " income.";
                else
                    msg += " savings.";
            }
            if(difference>ExtraAmount)
            {
                setLblErrorValue(msg);
                result=false;
            }
       }
    }
    
    return result;
}

function setColorOnLoad(elementID)
{
    var element;
    element = document.getElementById(elementID);
    if(element!=null)
    {
        if(element.innerHTML.indexOf("-")!=-1)
        {
            element.innerHTML = element.innerHTML.replace('-','');
            element.style.color = '#ff4d0e';
        }
        else
            element.style.color = '#069fff';
    }
}

function setColor(elementID,putBrackets)
{
    var element;
    var elementsText='';
    element = document.getElementById(elementID);
    if(element!=null)
    {
        if(element.innerHTML.indexOf("-")!=-1)
        {
            elementsText = element.innerHTML.replace('-','');
            if(putBrackets==true) 
                elementsText = "(" + elementsText + ")";
                
            element.innerHTML = elementsText;
            element.style.color = '#ff4d0e';
        }
        else
            element.style.color = '#069fff';
    }
}

function checkForMoreAllocation(elementID,txtID)
{
    var positiveColor='#069fff';
    var negativeColor='#ff4d0e';
    var element,amount;
    
    element = document.getElementById(elementID);
    if(element==null) return true;
    
    amount = element.innerHTML;
    if(element.style.color == negativeColor && element.innerHTML.indexOf('-')!=0) amount = '-'+amount;
    amount = parseFloat(amount);
    amount = isNaN(amount) ? 0 : amount;
    if(amount<0)
    {
        setLblErrorValue('You can not allocate more than budget amount.');
        setFocus(txtID);
        return false;
    }
    
    return true;
}

function checkSneakPeekMember()
{
    var element;
    element = document.getElementById('sneakpeek');
    
    if(element!=null && element.value=="1") 
    {
        setLblErrorValue('This feature is not available for Sneak Peek Members.');
        return true;
    }
    
    return false;
}

function checkSpecialCharacters(elementID)
{
    var element = document.getElementById(elementID);
    if (element==null) return true;
    strToCheck = element.value;
    
	var strSpecialCharacters = '~!@#$%^&*()=|{}[]:\\";<>?/.,';			
	for(var charCounter = 0; charCounter < strToCheck.length; charCounter++)
	{
		if((strSpecialCharacters.indexOf(strToCheck.charAt(charCounter))) >= 0)
		{	
            setLblErrorValue(strToCheck.charAt(charCounter) + ' character is not allowed.');
            element.focus();
			return false;											
		}
	}				
	return true;
}

function hideElement(ElementId)
{
    var element;
    element = document.getElementById(ElementId);
    if(element!=null)
        element.style.display='none';
}

