// Title: SBS Javascript Functions
// Version: 0.2
// Last Edit: 2006-10-22
// 2007-03-20 - Clean up unused sections of code



// --- menu class ---
// Function to turn the header on the top of the page off
function sbsheaderoff () {
	thisheader =  document.getElementById("div-header");
        thisheader.style.visibility="hidden";
        thisheader.style.display="none";
        return;
}


// Function to turn the header on the top of the page on
function sbsheaderon () {
	thisheader =  document.getElementById("div-header");
        thisheader.style.visibility="visible";
        thisheader.style.display="inline";
        return;
}


// SBS User List
function sbsuserlist () {
	var url = 'http://zts-1/ta/users/user-list-ajax.php';
	var pars = 'empID=200&year=2000';
	var myAjax = new Ajax.Updater('div-app', url, { method: 'get', parameters: pars }); 
        return;
}

// SBS Application Updater
// Updates the given div with the output from the given url
function sbsappupdate (url, pars, meth, div) {
	var myAjax = new Ajax.Updater(div, url, { method: meth, parameters: pars, evalScripts: 'true' }); 
        return;
}

// SBS Application Updater
function sbsformupdate (url, meth, div, formname) {
	var pars = Form.serialize(formname);
	var myAjax = new Ajax.Updater(div, url, { method: meth, parameters: pars, evalScripts: 'true' }); 
        return;
}

// SBS div update
// 2007-03-19
function sbsdivupdatehtml (divname, value) {
	thisheader =  document.getElementById("payorname");
        thisheader.style.visibility="hidden";
        thisheader.style.display="none";
        return;
}


// SBS Application Updater
function sbscontactlist (formname, varname, divtoupdate) {
	var sbslookuplist = window.open(
				'/ta/contacts/contacts-lookup-action.php?formname='+formname+'&varname='+varname+'&divtoupdate='+divtoupdate,
				'Contact Lookup',
				'width=1000,height=500,status=no,resizable=yes,top=200,left=200,dependent=yes,alwaysRaised=yes,scrollbars=yes'
				);
        sbslookuplist.opener = window;
        sbslookuplist.focus();
        return;

}

// SBS New Contact
function sbsnewcontact (formname, varname, divtoupdate) {
	var sbslookuplist = window.open(
				'/ta/contacts/contacts-newonfly-form.php?formname='+formname+'&varname='+varname+'&divtoupdate='+divtoupdate,
				'Contact Lookup',
				'width=1000,height=500,status=no,resizable=yes,top=200,left=200,dependent=yes,alwaysRaised=yes'
				);
        sbslookuplist.opener = window;
        sbslookuplist.focus();
        return;

}



// SBS Set form variable
function sbsupdateformvar (formname, varname, value) {
	thischange = document.getElementById("formname");
        thischange.elements[varname].value=value;
}


// SBS Function to calc Minpayment
function sbsupdateminpayment (formname) {
	thischange = document.getElementById(formname);
//	var thisval=Math.round((thischange.piminpayment.value+thischange.timinpayment.value+thischange.payorfee.value)*100)/100;
	var thisval1=thischange.piminpayment.value * 1;
	var thisval2=thischange.timinpayment.value * 1;
	var thisval3=thischange.payorfee.value * 1;
	var thisval4=thischange.otheramount.value * 1;
	var thisval=thisval1 + thisval2 + thisval3 + thisval4;
        thischange.minpayment.value=thisval.toFixed(2);
}

// SBS Function to calc Principle
function sbsupdateprincipal (formname) {
	thischange = document.getElementById(formname);
	var thisval=Math.round((thischange.pipayment.value-thischange.interest.value)*100)/100;
        thischange.principal.value=thisval.toFixed(2);
}

// SBS Function to calc Interest
function sbsupdateinterest (formname) {
	thischange = document.getElementById(formname);
	var thisval=Math.round((thischange.pipayment.value-thischange.principal.value)*100)/100;
        thischange.interest.value=thisval.toFixed(2);
}

// SBS Function to calc Remaining Balance
function sbsupdateremaining (formname) {
	thischange = document.getElementById(formname);
        var thisval=Math.round((thischange.totalpayment.value-thischange.principal.value-thischange.interest.value-thischange.other1amount.value-thischange.other2amount.value-thischange.latecharge.value)*100)/100;
        thischange.remaining.value=thisval.toFixed(2);

}


// SBS Function to calc Ending Balance
function sbsupdateremaining (formname) {
	thischange = document.getElementById(formname);
        var thisval=thischange.curbal.value-thischange.totalpayment.value;
        thischange.endbalance.value=thisval.toFixed(2);
}

// SBS Function to hide P&I on processing
function sbsclosebutton(formname) {
	thisform = document.getElementById(formname);
        var thisamount=thisform.amount.value;
        var thispastdue=thisform.pastdue.value;
	if ((thisamount!=0) || (thispastdue!=0)) {
		thispi = document.getElementById('close-button');
		thispi.style.visibility="hidden";
		thispi.style.display="none";
	} else {
		thispi = document.getElementById('close-button');
		thispi.style.visibility="visible";
		thispi.style.display="";
	}
}



// SBS Function to hide P&I on processing
function sbshidepi(formname) {
	thiscycle = document.getElementById(formname);
        var thisval=thiscycle.numcycles.value;
	if (thisval > 1) {
		thispi = document.getElementById('receipt-pi');
		thispi.style.visibility="hidden";
		thispi.style.display="none";
		thisprin = document.getElementById("receipt-principal");
		thisprin.style.visibility="hidden";
		thisprin.style.display="none";
		thispint = document.getElementById("receipt-interest");
		thispint.style.visibility="hidden";
		thispint.style.display="none";
		thispayor = document.getElementById("receipt-payorfee");
		thispayor.style.visibility="hidden";
		thispayor.style.display="none";
		thisimpdesc = document.getElementById("receipt-impounddesc");
		thisimpdesc.style.visibility="hidden";
		thisimpdesc.style.display="none";
		thisimpamt = document.getElementById("receipt-impound1amount");
		thisimpamt.style.visibility="hidden";
		thisimpamt.style.display="none";
		thispint = document.getElementById("receipt-extraprin");
		thispint.style.visibility="visible";
		thispint.style.display="";
	} else {
		thispi = document.getElementById('receipt-pi');
		thispi.style.visibility="visible";
		thispi.style.display='';
		thisprin = document.getElementById("receipt-principal");
		thisprin.style.visibility="visible";
		thisprin.style.display="";
		thispint = document.getElementById("receipt-interest");
		thispint.style.visibility="visible";
		thispint.style.display="";
		thispayor = document.getElementById("receipt-payorfee");
		thispayor.style.visibility="visible";
		thispayor.style.display="";
		thisimpdesc = document.getElementById("receipt-impounddesc");
		thisimpdesc.style.visibility="visible";
		thisimpdesc.style.display="";
		thisimpamt = document.getElementById("receipt-impound1amount");
		thisimpamt.style.visibility="visible";
		thisimpamt.style.display="";
		thispint = document.getElementById("receipt-extraprin");
		thispint.style.visibility="hidden";
		thispint.style.display="none";
	}
	return;

}


