//$Id: PersonalFinance.js,v 1.1 2008/11/25 16:25:40 sathyav Exp $

var PersonalFinance = new function()
{

    this.showDialog = function(elID,title)
    {
        var dlg= $(elID);
        dlg.style.display="";
        ZDBDialogUtil.showDialog(dlg,{TITLE:title, ADDFRAME:true,MODAL:true, DONTREMOVE:true});
    }

    this.fetchViews = function(tab)
    {
        var frameId = tab.getAttribute("reportId");
        if (frameId != '' && frameId != null)
        {
                var embed = $(frameId);
                if(embed != null && (embed.getAttribute("src") == '' || embed.getAttribute("src") == 'about:blank'))
                {
                        var origSrc = embed.getAttribute("origSrc");
                        embed.src = origSrc;
                }
        }
    }

    this.tabSelected = function(tab)
    {
	var parentTable = $("mainTable");
	var classtoapply = tab.getAttribute("selectionclass");
	if(classtoapply=="tab2Selected")
	{
        	document.body.className = "bodybg4tab2"
	}
	else
	{
        	document.body.className = "none"
	}
	parentTable.className = classtoapply;
	this.fetchViews(tab);
    }

    this.reportSelected = function(tab)
    {
        var parentTable = $("reportTable");
        var classtoapply = tab.getAttribute("selectionclass");
        parentTable.className = classtoapply;
        this.fetchViews(tab);
    }

    this.validateData = function(formElement)
    {
        var dateVar = formElement.date.value;
        if (dateVar == '')
        {
                alert ('date field cannot be empty');
                return false;
        }
        var amountVar = formElement.amount.value;

        if (amountVar == '0.00' || amountVar == '')
        {
                alert ('amount field cannot be 0 or Empty');
                return false;
        }

        if (/^[+-]?[0-9]*[.]?[0-9]+$/.test(amountVar))
        {
		var val = parseFloat(amountVar);
		if(val > 50000)
		{
			alert('Amount field cannot have values greater than 50,000');
                	return false;
		}
		else if (val == 0)
		{
                	alert ('amount field cannot be 0 or Empty');
	                return false;
		}
        }
	else
	{
		alert ('Please enter any valid value for the Amount field');
		return false;	
	}
   	return true;
    }

}
    $ = function(e) 
    {
 	return document.getElementById(e);
    }
