function testDate(key){
	if(isNaN(key)!=-1&&key.indexOf('/')!=true){
		return false;
	}
}


function escapeChars(x){
	x=x.replace(/&/g,"%26");
	return x;
}

function handleInfo_acctinfo() {
	if(http.readyState == 1) {
		closeajax();
	}
	if(http.readyState == 4) {
		var response = http.responseText;
		acctArray=response.split(",");
		checknum=acctArray[1];
		accttype=acctArray[0];
		if(accttype=="checking"){
			document.getElementById("checknumberid").style.display='';
			transactionfrm.checknum.value=checknum;
		}
		else
		{
			transactionfrm.checknum.value="";
			document.getElementById("checknumberid").style.display='none';
			document.getElementById("checknumberval").style.display='none';
			transactionfrm.checktest[0].selected=true;
		}
	}
}

function replaceAllChars(fromstr,tostr,str){
	var intIndexOfMatch=0;
	while (intIndexOfMatch != -1){
		str = str.replace( fromstr, tostr );
		intIndexOfMatch = str.indexOf( fromstr );
	}
	
	return str;
}


function UpdateNav_Submit(){
	$('NavigationMain').innerHTML="<div class=\"white padding3\">Loading, please wait...</div>";
	new Ajax.Request('save/updatenav.php',{method:'post',onComplete:UpdateNavPopup_Submit_Compete,parameters:Form.serialize(formNavigation)});
	return false;
}
function UpdateNavPopup_Submit_Compete(e){
	Element.hide('NavigationMainPopup');
	Nav_Update();
}
function CancelNavPopup(){
	Element.hide('NavigationMainPopup');
}
function newbill(x,y,z,acctid,returnurl,deposit){
	for(i=0;i<transactionfrm.catid.length;i++){
		if(transactionfrm.catid[i].value==z){
			transactionfrm.catid[i].selected=true;
		}
	}
	if(deposit==1){
		transactionfrm.transactionselect.value="deposit";
	}
	transactionfrm.tpaytonew.value=x;
	transactionfrm.tamount.value=y;
	if(acctid!=0){
		transactionfrm.account.value=acctid;
		transactionfrm.returnurl.value=returnurl;
		transactionfrm.submit();
	}
	else
	{
		transactionfrm.account.value="";
	}
}

function openfav(x){
	window.open(x,"favwin");
}

function closetips(){
	document.getElementById("tipspopup").style.display='none';
}
function disabletips(){
	document.getElementById("tipspopup").style.display='none';
	http.open("POST","save/disabletips.php",true);
	http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	sendvar="";
	http.send(sendvar);
}

function closeajax(){
	Element.hide('ajax_wait');
	Element.hide('loadingsmall');
}
function openajax(){
	Element.show('ajax_wait');
	setTimeout("closeajax()",5000);
}
function opensmallajax(){
		Element.show('loadingsmall');
}
function debtpayoff2(){
	debtdiv=document.getElementById("debtlist");
	if(debtdiv.style.display==''){
		debtdiv.style.display='none';
	}
	else
	{
		debtdiv.style.display=''
	}
}
function transactionsmore(){
	if(document.getElementById("transactionsmoreid").style.display==''){
		document.getElementById("transactionsmoreid").style.display='none';
	}
	else
	{
		document.getElementById("transactionsmoreid").style.display='';
	}
}
	
function TmoveDownNavList() {
	var selected = tForm.navmodifylist.selectedIndex;
	if(selected!=-1){
	if(tForm.navmodifylist.length-1!=tForm.navmodifylist.selectedIndex&&tForm.navmodifylist.selectedIndex!=-1){
			var moveText1 = tForm.navmodifylist[selected+1].text;
			var moveText2 = tForm.navmodifylist[selected].text;
			var moveValue1 = tForm.navmodifylist[selected+1].value;
			var moveValue2 = tForm.navmodifylist[selected].value;
			tForm.navmodifylist[selected].text = moveText1;
			tForm.navmodifylist[selected].value = moveValue1;
			tForm.navmodifylist[selected+1].text = moveText2;
			tForm.navmodifylist[selected+1].value = moveValue2;
			tForm.navmodifylist.selectedIndex = selected+1;
		}
	}
}

function TmoveNavUpList() {
	var selected = tForm.navmodifylist.selectedIndex;
	
	if(selected!=-1){
		if(tForm.navmodifylist.selectedIndex!=0&&tForm.navmodifylist.selectedIndex!=-1){
			moveText1 =tForm.navmodifylist[selected-1].text;
			moveText2 = tForm.navmodifylist[selected].text;
			moveValue1 = tForm.navmodifylist[selected-1].value;
			moveValue2 = tForm.navmodifylist[selected].value;
			tForm.navmodifylist[selected].text = moveText1;
			tForm.navmodifylist[selected].value = moveValue1;
			tForm.navmodifylist[selected-1].text = moveText2;
			tForm.navmodifylist[selected-1].value = moveValue2;
			tForm.navmodifylist.selectedIndex = selected-1;
		}
	}
}
function TremoveList(){
	var selected = tForm.navmodifylist.selectedIndex;
	if(tForm.navmodifylist.length>0&&selected!=-1){
		tForm.removelist.length=tForm.removelist.length+1;
		tForm.removelist[tForm.removelist.length-1].value=tForm.navmodifylist[selected].value;
		tForm.removelist[tForm.removelist.length-1].text=tForm.navmodifylist[selected].text;
		
		for(i=0;i<tForm.navmodifylist.length;i++){
			if(selected<i){
				tForm.navmodifylist[i-1].value=tForm.navmodifylist[i].value;
				tForm.navmodifylist[i-1].text=tForm.navmodifylist[i].text;
			}
		}
		tForm.navmodifylist.length=tForm.navmodifylist.length-1;
	}
}

function TaddList(){
	var selected = tForm.removelist.selectedIndex;
	if(tForm.removelist.length>0&&selected!=-1){
		tForm.navmodifylist.length=tForm.navmodifylist.length+1;
		tForm.navmodifylist[tForm.navmodifylist.length-1].value=tForm.removelist[selected].value;
		tForm.navmodifylist[tForm.navmodifylist.length-1].text=tForm.removelist[selected].text;
		
		
		for(i=0;i<tForm.removelist.length;i++){
			if(selected<i){
				tForm.removelist[i-1].value=tForm.removelist[i].value;
				tForm.removelist[i-1].text=tForm.removelist[i].text;
			}
		}
		tForm.removelist.length=tForm.removelist.length-1;
	}
}

function updatetabs(){
	document.getElementById("updatetabsid").style.display='';
}
function closetabs(){
	document.getElementById("updatetabsid").style.display='none';
}

function savetabs(){
	tForm.orderlist.value="";
	
	for(i=0;i<tForm.navmodifylist.length;i++){
		tForm.orderlist.value=tForm.orderlist.value+tForm.navmodifylist[i].value+",";
	}
	http.open("POST","save/updatetabs.php",true);
	http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	http.onreadystatechange = handleInfo_tabs;
	sendvar="TABORDER="+tForm.orderlist.value;
	http.send(sendvar);
}

function handleInfo_tabs() {
	if(http.readyState == 1) {
		
	}
	if(http.readyState == 4) {
		var response = http.responseText;
		document.getElementById("updatetabsid").style.display='none';
		alert("Success! Your new Tab settings have been saved.");
	}
}

function updatemods(){
	document.getElementById("updatemodsid").style.display='';
}
function closemods(){
	document.getElementById("updatemodsid").style.display='none';
}

function savemods(){
	tForm.orderlist.value="";
	
	for(i=0;i<mForm.navmodifylist.length;i++){
		mForm.orderlist.value=mForm.orderlist.value+mForm.navmodifylist[i].value+",";
	}
	http.open("POST","save/updatemods.php",true);
	http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	http.onreadystatechange = handleInfo_mods;
	sendvar="MODORDER="+mForm.orderlist.value;
	http.send(sendvar);
}

function handleInfo_mods() {
	if(http.readyState == 1) {
		
	}
	if(http.readyState == 4) {
		var response = http.responseText;
		document.getElementById("updatemodsid").style.display='none';
		alert("Success! Your new Module settings have been saved.");
	}
}
function hideLeftNav(){
	if($("leftbodyid").style.display==''){
		$("leftbodyid").style.display='none';
		$("leftnavTxtID").innerHTML="show&nbsp;&raquo;";
		savenavigation("leftnav","hide");
	}
	else
	{
		$("leftbodyid").style.display='';
		$("leftnavTxtID").innerHTML="&laquo;&nbsp;hide";
		savenavigation("leftnav","show");
	}
}
function hideRightNav(){
	if($("rightbodyid").style.display==''){
		$("rightbodyid").style.display='none';
		$("rightnavTxtID").innerHTML="&laquo;&nbsp;show";
		savenavigation("rightnav","hide");
	}
	else
	{
		$("rightbodyid").style.display='';
		$("rightnavTxtID").innerHTML="hide&nbsp;&raquo;";
		savenavigation("rightnav","show");
	}
}

function savenavigation(side,hide){
	if(window.XMLHttpRequest)
		http = new XMLHttpRequest();
	else if (window.ActiveXObject)
		http = new ActiveXObject("Microsoft.XMLHTTP");
	http.open("POST","settings_save.php",true);
	http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	sendvar="noredir=1&"+side+"="+hide;
	http.send(sendvar);
}

function testcheck(x){
	if(x=="check"){
		document.getElementById("checknumberval").style.display='';
	}
	else
	{
		document.getElementById("checknumberval").style.display='none';
	}
}

Tasks = {
	additem_save: function(){
		var sendvar="TASKNAME="+escapeChars(newtaskfrm.taskname.value)+"&TASKDESC="+escapeChars(newtaskfrm.taskdesc.value)+"&STATUS="+escapeChars(newtaskfrm.status.value)+"&NEWCATNAME="+escapeChars(newtaskfrm.newcatname.value)+"&DUEDATE="+escapeChars(newtaskfrm.duedate.value)+"&SHOWCAL="+newtaskfrm.newcalcheck.checked+"&COLOR="+newtaskfrm.color.value;
		if(newtaskfrm.catid){
			sendvar+="&CATID="+escapeChars(newtaskfrm.catid.value);
		}
		var url = "save/newtask.php";
		new Ajax.Request(url, {asynchronous:true,method:'post',parameters:sendvar,onSuccess:Tasks.additem_save_success});
		return false;
	},
	checknewcal: function(x){
		if(x==true){
			Element.show('newtaskID');
		}
		else
		{
			Element.hide('newtaskID');
		}
	},
	newtask: function(){
		Element.toggle('taskbody');
	},
	additem_save_success: function(){
		$('tasksuccessmsgID').innerHTML="<font color=red>Success! Your task has been saved.</font>";
		newtaskfrm.taskname.value='';
		newtaskfrm.taskdesc.value='';
		p=setTimeout("Tasks.closesuccess()",3000);
	},
	closesuccess: function(){
		$('tasksuccessmsgID').innerHTML="";
	}
}

Shop = {
	additem_save: function(){
		sendvar="GROCERYITEM="+newgroceryfrm.groceryitem.value+"&QUANTITY="+newgroceryfrm.quantity.value+"&SECTION="+newgroceryfrm.section.value+"&PRICE="+newgroceryfrm.price.value+"&NOTES="+newgroceryfrm.notes.value+"&NEWSTORENAME="+newgroceryfrm.newstorename.value;
		if(newgroceryfrm.storeid){
			sendvar+="&STOREID="+newgroceryfrm.storeid.value;
		}
		var url = "save/newgrocery.php";
		new Ajax.Request(url, {asynchronous:true,method:'post',parameters:sendvar,onSuccess:Shop.additem_save_success});
		return false;
	},
	additem_save_success: function(t){
		$('shopMessage').innerHTML=t.responseText;
		setTimeout("Shop.CloseSuccess()",3000);
		newgroceryfrm.groceryitem.value="";
		newgroceryfrm.quantity.value="";
		newgroceryfrm.price.value="";
		newgroceryfrm.notes.value="";
	},
	CloseSuccess: function(){
		$('shopMessage').innerHTML="";
	}
}

function LoadContainer(container,url){
	new Ajax.Updater(container,url, {asynchronous:true,onComplete:LoadContainer_success});
}

function LoadContainer_success(t){
	var response = t.responseText;
	Element.hide('ajax_wait');
}
function LoadContainerParams(container,url,params){
	new Ajax.Updater(container,url, {asynchronous:true,parameters:params});
}

function SaveContainer(url,params){
	new Ajax.Request(url, {asynchronous:true,method:'post',parameters:params});
}
function SaveContainerUpdater(container,url,params){
	new Ajax.Updater(container,url, {asynchronous:true,method:'post',parameters:params});
}

function ToggleTransToolbar(toolbar){
	Element.toggle('transtoolID');
	if($('transtoolID').style.display!='none'){
		new Ajax.Request('save/closetranstoolbar.php',{asynchronous:true,method:'post',parameters:'toolbar=show'});
	}
	else
	{
		new Ajax.Request('save/closetranstoolbar.php',{asynchronous:true,method:'post',parameters:'toolbar=hide'});
	}
	if($('innerTransToolbar')!=null&&$('innerTransToolbar').innerHTML=='Loading, please wait...'){
		LoadTransToolbar();
	}

	
}
Navigation = {
	addcurrent: function(url,alias){
		$('NavigationMain').innerHTML="<div class=\"white padding3\">Loading, please wait...</div>";
		var sendurl = "save/updatenavigation.php";
		var params = "add=1&alias="+escape(alias)+"&url="+escape(url);
		new Ajax.Request(sendurl, {asynchronous:true,method:'post',parameters:params,onSuccess:Navigation.current_success});
	},
	removecurrent: function(url){
		$('NavigationMain').innerHTML="<div class=\"white padding3\">Loading, please wait...</div>";
		var sendurl = "save/updatenavigation.php";
		var params = "add=0&url="+url;
		new Ajax.Request(sendurl, {asynchronous:true,method:'post',parameters:params,onSuccess:Navigation.current_success});
	},
	current_success: function(){
		Nav_CurrentUpdate();
	}
}

QuickSettings = {
	currency: function(currency){
		if(currency=="new"){
			location.href="settings.php?curr=new";
		}
		else
		{
			var sendurl = "settings_save.php";
			var params = "noredir=1&currency="+currency;
			new Ajax.Request(sendurl, {asynchronous:true,method:'post',parameters:params,onSuccess:QuickSettings.quick_success});
		}
	},
	dateformat: function(dateformat){
		var sendurl = "settings_save.php";
		var params = "noredir=1&dateformat="+dateformat;
		new Ajax.Request(sendurl, {asynchronous:true,method:'post',parameters:params,onSuccess:QuickSettings.quick_success});
	},
	resetacct: function(){
		var testconfirm = confirm("By reseting your account, all information except your profile will be deleted from the system and can not be recovered. Are you sure you want to reset your Account?");
		if(testconfirm==true){
			var sendurl = "save/resetuser.php";
			var params = "noredir=1&resetacct=1";
			new Ajax.Request(sendurl, {asynchronous:true,method:'post',parameters:params,onSuccess:QuickSettings.quick_success});
		}
	},
	quick_success: function(e){
		alert("Your settings have been saved. Please refresh to view changes.");
	}
}

function openhelp(){
	Element.show('tophelpid');
	Element.hide('tophelplnkid');
}
function closehelp(){
	Element.hide('tophelpid');
	Element.show('tophelplnkid');
}
function updatehelp(){
	
}

function mainbt(id){
	if(id=="1"){
		Element.hide('rightBudgetTracker');
		$('mainBudgetTracker').innerHTML="<iframe frameborder=0 width=100% height=100% src=\"http://google.com/calendar/\"></iframe>";
	}
}

function checkaddto(addto){
	Element.hide('budgetdateid');
	Element.hide('couponId');
	Element.hide('cashbackId');
	if(addto=="future"){
		Element.show('budgetdateid');
	}
	else if(addto=="coupon"){
		Element.show('couponId');
	}
	else if(addto=="cashback"){
		Element.show('cashbackId');
	}
}
function checkuaddto(addto){
	Element.hide('budgetdateuid');
	Element.hide('ucouponId');
	
	if(addto=="future"){
		Element.show('budgetdateuid');
	}
	else if(addto=="coupons"){
		Element.show('ucouponId');
	}
}

function UpdateTheme(x){
	if(x=='simple'){
		location.href="settings_save.php?theme=5";
	}
	else if(x=="adv"){
		location.href="settings_save.php?theme=1";
	}
	else if(x=="kids"){
		location.href="settings_save.php?theme=10&returnurl=kids_budget.php";
	}
	else if(x=="emerald"){
		location.href="settings_save.php?theme=2";
	}
	else if(x=="rounded"){
		location.href="settings_save.php?theme=11";
	}
	else if(x=="business"){
		location.href="settings_save.php?theme=12";
	}
	else if(x=="setforlife"){
		location.href="settings_save.php?theme=13";
	}
}


function MmoveDownNavList() {
	var selected = mForm.navmodifylist.selectedIndex;
	if(selected!=-1){
	if(mForm.navmodifylist.length-1!=mForm.navmodifylist.selectedIndex&&mForm.navmodifylist.selectedIndex!=-1){
			var moveText1 = mForm.navmodifylist[selected+1].text;
			var moveText2 = mForm.navmodifylist[selected].text;
			var moveValue1 = mForm.navmodifylist[selected+1].value;
			var moveValue2 = mForm.navmodifylist[selected].value;
			mForm.navmodifylist[selected].text = moveText1;
			mForm.navmodifylist[selected].value = moveValue1;
			mForm.navmodifylist[selected+1].text = moveText2;
			mForm.navmodifylist[selected+1].value = moveValue2;
			mForm.navmodifylist.selectedIndex = selected+1;
		}
	}
}

function MmoveNavUpList() {
	var selected = mForm.navmodifylist.selectedIndex;
	
	if(selected!=-1){
		if(mForm.navmodifylist.selectedIndex!=0&&mForm.navmodifylist.selectedIndex!=-1){
			moveText1 =mForm.navmodifylist[selected-1].text;
			moveText2 = mForm.navmodifylist[selected].text;
			moveValue1 = mForm.navmodifylist[selected-1].value;
			moveValue2 = mForm.navmodifylist[selected].value;
			mForm.navmodifylist[selected].text = moveText1;
			mForm.navmodifylist[selected].value = moveValue1;
			mForm.navmodifylist[selected-1].text = moveText2;
			mForm.navmodifylist[selected-1].value = moveValue2;
			mForm.navmodifylist.selectedIndex = selected-1;
		}
	}
}

function savemodules(){
	mForm.orderlist.value="";
	for(i=0;i<mForm.navmodifylist.length;i++){
		mForm.orderlist.value=mForm.orderlist.value+mForm.navmodifylist[i].value+",";
	}
	return true;
}

function UpdateTabNavigation(page){
	var jscript="javascript";
	var printp="print";
	if(page!=""){
		if(jscript.indexOf(page)!=-1){
			eval(page);
		}
		else if(printp.indexOf(page)!=-1){
			window.open('print',page);
		}
		else
		{
			location.href=page;
		}
	}
}

function updatenavtype(type){
	$('NavigationMain').innerHTML="<div class=\"white padding3\">Loading, please wait...</div>";
	new Ajax.Request('save/updatenavtype.php',{method:'post',onComplete:UpdateNavPopup_Submit_Compete,parameters:'type='+type});
}

function addtags(tagname,count){
	$('tagsId').value+=tagname+",";
	Element.hide("transtags_"+count);
}

function addupdatetags(tagname,count){
	$('tagsupdateId').value+=tagname+",";
	Element.hide("updatetranstags_"+count);
}

function UpdateDateColor(dateid){
	dateid.style.color="#000000";
	
}

function UpdateSearchOptions(val){
	Element.hide('searchbycalendarId');
	Element.hide('searchbykeywordId');
	if(val=="daterange"){
		Element.show('searchbycalendarId');
	}
	else{
		Element.show('searchbykeywordId');
	}
}

function openbiztabs(){
	Element.toggle('tabchange');
}
function closebiztabs(){
	Element.hide('tabchange');
}
function updatebiztabs(obj){
	var tab2=obj.tab2.value;
	var tab4=obj.tab4.value;
	var params="tab2="+tab2+"&tab4="+tab4;
	new Ajax.Request('save/updatetabs.php',{asynchronous:true,method:'post',parameters:params,onComplete:updatebiztabs_complete});
	Element.hide('tabchange');
	return false;
}
function updatebiztabs_complete(){
	alert("Your tab settings have been saved. Please refresh to view.");
}
function openquickfeedback(){
	Element.toggle('givefeedbackid');
}
function closequickfeedback(){
	Element.hide('givefeedbackid');
}
function sendquickfeedback(obj){
	new Ajax.Request('save/sendfeedback.php',{asynchronous:true,method:'post',parameters:'pagename='+obj.pagename.value+'&message='+obj.message.value,onComplete:sendquickfeedback_complete});
	closequickfeedback();
	return false;
}
function sendquickfeedback_complete(){
	alert("Thank you, your feedback has been received.");
}

function IsLoggedIn(){
	new Ajax.Request('loggedin.php',{asynchronous:'true',parameters:'text=1',onComplete:IsLoggedIn_Complete});
}
function IsLoggedIn_Complete(e){
	var response=e.responseText;
	if(response=="success"){
		setTimeout("IsLoggedIn()",3600000);
	}
	else if(response=="failed")
	{
		location.href="login_secure.php?timeout=1";	
	}
}
function hidetips(){
	new Ajax.Request('settings_save.php',{method:'post',parameters:'noredir=1&helpfultips=1'});
	Element.hide('helpfultipmain');
	alert("To turn helpful tips back on, click Settings");
}
function openslider(){
	jQuery("#tabs").tabs();
	jQuery('#slider').toggle();
	if(jQuery('#slidepin').attr('class')=="appstaboff"){
		jQuery('#slidepin').attr('class','appstab');
	}
	else
	{
		jQuery('#slidepin').attr('class','appstaboff');
	}
	if($('tab_fav').innerHTML=="Loading, please wait..."){
		new Ajax.Updater('tab_fav','getfavs.php',{asynchronous:true});
	}

}
function closeslider(){
	jQuery('#slider').hide();

}
function savepage(){
	if($('star').src.indexOf('gstarLg.png')==-1){
		$('star').src="pics/icons/gstarLg.png";
	}
	else
	{
		$('star').src="pics/icons/starLg.png";
		alert('This page has been add to your Push Pin Favorites on the right.');
	}
	var pagename=escape($('pagename').value);
	var pagetitle=$('pagetitle').value;
	var url = escape(location.href);
	new Ajax.Request('save/newfav.php',{method:'post',parameters:'url='+url+'&pagename='+pagename+'&pagetitle='+pagetitle});
}

function googlesearch(){
	window.open('http://budgettracker.com/googlesearch.php?cs=partner-pub-8852055528408257:h6e23n85vu7&cof=FORID:10&ie=ISO-8859-1&q='+escape($('gq').value),'googlesearch');
	return false;
}
function openchat(){
	window.open('chat/index.php','chat','menubar=0,toolbar=0,location=1,width=750,height=475');
	chat.focus();
}
