function edify (id,status,message)
{
	if(status == 1)
	{
		document.getElementById(id).innerHTML = "<span style=\"color:#D9A978;font-weight:500;font-size:14px;\">Explaination Box:</span><hr style=\"margin-top:3px;\" />" + message;
	}else
	{
		document.getElementById(id).innerHTML = "";
	}
}

function dynDisplay(id,status,retColor)
{
	if(status == 1)
	{
		document.getElementById(id).style.background = '#f6f6f6';
		document.getElementById(id).style.border = '1px solid #DAD7D7';
	}else
	{
		document.getElementById(id).style.background = '#'+retColor;
		document.getElementById(id).style.border = '';
	}
}

function checkFormSignUp(formobj)
{
	//1) Enter name of mandatory fields
	var fieldRequired = Array("apassword","first_name", "last_name", "phone_a", "phone_b", "phone_c", "username", "password1", "password2", "email1", "email2");
	//2) Enter field description to appear in the dialog box
	var fieldDescription = Array("Authorization Password", "First Name", "Last Name", "Phone 1", "Phone 2", "Phone 3", "Username", "Password", "Re-type Password", "Email", "Re-type Email");
	
	return alertValidation(fieldRequired,fieldDescription,formobj);
}


function checkFormTempPass(formobj){
	//1) Enter name of mandatory fields
	var fieldRequired = Array("first_name", "last_name", "email");
	//2) Enter field description to appear in the dialog box
	var fieldDescription = Array("First Name", "Last Name", "Email");
	//3) Enter dialog message
	
	return alertValidation(fieldRequired,fieldDescription,formobj);
}

function checkFormAddAcount(formobj){
	//1) Enter name of mandatory fields
	var fieldRequired = Array("aname", "abalance", "type");
	//2) Enter field description to appear in the dialog box
	var fieldDescription = Array("Account Name", "Account Balance", "Account Type");
	//3) Enter dialog message
	
	return alertValidation(fieldRequired,fieldDescription,formobj);
}

function checkFormAddExpense(formobj){
	//1) Enter name of mandatory fields
	var fieldRequired = Array("ename", "ebudget", "type");
	//2) Enter field description to appear in the dialog box
	var fieldDescription = Array("Account Name", "Account Budget", "Account Type");
	//3) Enter dialog message
	
	return alertValidation(fieldRequired,fieldDescription,formobj);
}

function checkFormRecExpense(formobj){
	//1) Enter name of mandatory fields
	var fieldRequired = Array("cat", "source", "amount");
	//2) Enter field description to appear in the dialog box
	var fieldDescription = Array("Expense Category", "Expense Payee", "Expense Amount");
	//3) Enter dialog message
	
	return alertValidation(fieldRequired,fieldDescription,formobj);
}


function checkFormAddDebt(formobj){
	//1) Enter name of mandatory fields
	var fieldRequired = Array("dname", "dbalance", "dpayment");
	//2) Enter field description to appear in the dialog box
	var fieldDescription = Array("Account Name", "Balance Amount", "Payment Amount");
	//3) Enter dialog message
	
	return alertValidation(fieldRequired,fieldDescription,formobj);
}

function alertValidation(fieldRequired,fieldDescription, formobj)
{
	//3) Enter dialog message
	var alertMsg = "Please complete the following fields:\n";
	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++)
	{
		var obj = formobj.elements[fieldRequired[i]];
		if (obj)
		{
			switch(obj.type){
			case "select-one":
			if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
			alertMsg += " - " + fieldDescription[i] + "\n";
			}
			break;
			case "select-multiple":
			if (obj.selectedIndex == -1){
			alertMsg += " - " + fieldDescription[i] + "\n";
			}
			break;
			case "text":
			case "textarea":
			if (obj.value == "" || obj.value == null){
			alertMsg += " - " + fieldDescription[i] + "\n";
			}
			break;
			default:
			if (obj.value == "" || obj.value == null){
			alertMsg += " - " + fieldDescription[i] + "\n";
			}
		}
	}
	}
	
	if (alertMsg.length == l_Msg)
	{
		return true;
	}else
	{
		alert(alertMsg);
		return false;
	}
}

	
function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function addComma(inObj){
       outStr =inObj.value.replace(/,|[a-z]/g, "");
        leftStr = outStr
        rightStr = ""
        if (outStr.indexOf(".") > -1){
            leftStr = outStr.substr(0, outStr.indexOf("."))
            rightStr = outStr.substr(outStr.indexOf(".")+1)
        }
        if (leftStr.length > 3){
            numCommas = Math.floor(( leftStr.length - 1 ) / 3 );
            tempStr = ""
            for (x=0; x<numCommas; x++){
                tempStr =  "," + leftStr.substr(leftStr.length-3) + tempStr
                leftStr = leftStr.substr(0,leftStr.length-3)
            }
             leftStr += tempStr
        }
        outStr = outStr.indexOf(".") > -1 ? leftStr + "." + rightStr : leftStr
        inObj.value = outStr        
    }


function startCalc(){
  interval = setInterval("calc()",1);
}
function calc(){
  one = document.monthlyIncome.gross_monthly_income.value;
  one = one.replace(/[a-zA-Z,]/g, "");
  two = document.monthlyIncome.taxes.value; 
  two = two.replace(/[a-zA-Z,]/g, "");
  three = document.monthlyIncome.other_deductions.value; 
  three = three.replace(/[a-zA-Z,]/g, ""); 
  var total = (one * 1) - (two * 1) - (three * 1);
  total = Math.round(total*100)/100;
  total = addCommas(total);
  document.getElementById("sub_total").innerHTML = "$"+total;
}
function stopCalc(){
  clearInterval(interval);
}

function display(close, open)
{
	document.getElementById(close).style.display = "none";
	document.getElementById(open).style.display = "block";
}

function ajaxRequest(url,div,id,year)
{
  // Set up the request
  //var xmlhttp = new XMLHttpRequest();
  var xmlhttp; //declare the variable to hold the object.
  var browser = navigator.appName; //find the browser name
  if(browser == "Microsoft Internet Explorer")
  {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }else{
    xmlhttp = new XMLHttpRequest();
  }
  xmlhttp.open('POST', url, true);
  // The callback function
  xmlhttp.onreadystatechange = function()
  {
  
   if (xmlhttp.readState !=4){
		document.getElementById(div).innerHTML = '<div style="text-align:center;color:#868686;"><img src="../images/loader.gif"> Loading Content...<\/div>';
    	}
  
    try{if (xmlhttp.readyState == 4) // Finished loading
    {
      if (xmlhttp.status == 200) // Completeed Successfully
      {
         var response = xmlhttp.responseText;
         //alert(response_stat);
         document.getElementById(div).innerHTML = response;
      }
    }}catch(e){
      //alert('There was an error!');
    }
  }

  // Send the POST request
  xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
 var data = "id="+ id+ "&year="+ year;
  xmlhttp.send(data);
}


function confirmDelete(helperMsg){
	return confirm(helperMsg);
}


var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

function popUpWizard(url,winName,width,height)
{
	var w = 800, h = 600;

	if (document.all || document.layers) 
	{
  		 w = screen.availWidth;
  		 h = screen.availHeight;
	}

	var leftPos = (w-width)/2, topPos = (h-height)/2;
	
	mywindow = window.open (url,
	winName,'location=0,status=0,scrollbars=0,width=' + width + ',height=' + height + ',top=' + topPos + ',left=' + leftPos);		
 } 