
function tS(){ x=new Date(); x.setTime(x.getTime()); return x; } 
function lZ(x){ return (x>9)?x:'0'+x; } 
function tH(x){ if(x==0){ x=12; } return (x>12)?x-=12:x; } 

function calculate1(){

var mydate=new Date()
var date_day=mydate.getDay()         //0=sun; 1=mon; 2=tue ...
var date_dd=mydate.getDate()         //1 to 31
var date_mm=mydate.getMonth()+1 //0=jan; 1=feb; 2=mar... to 11=dec
var date_yyyy=mydate.getYear()

var date_hh=lZ(mydate.getHours())
var date_ms=lZ(mydate.getMinutes())
var date_ss=lZ(mydate.getSeconds())

total = 0;
if (isNaN(document.giving1.th.value)){document.giving1.th.value = 0;}
if (isNaN(document.giving1.of.value)){document.giving1.of.value = 0;}
if (isNaN(document.giving1.bf.value)){document.giving1.bf.value = 0;}
if (isNaN(document.giving1.tv.value)){document.giving1.tv.value = 0;}
if (isNaN(document.giving1.mi.value)){document.giving1.mi.value = 0;}
if (isNaN(document.giving1.ip.value)){document.giving1.ip.value = 0;}

th = document.giving1.th.value*1;
of = document.giving1.of.value*1;
bf = document.giving1.bf.value*1;
tv = document.giving1.tv.value*1;
mi = document.giving1.mi.value*1;
ip = document.giving1.ip.value*1;

total = th + of + bf + tv + mi + ip;
document.giving1.amount_a3.value = total;


var item_number="FFM-OTG";
tx = "-x";
ox = "x";
bx = "x";
mx = "x";
ex = "x";
ix = "x";

if (document.giving1.th.value >0){tx = "-T";}
if (document.giving1.of.value >0){ox = "O";}
if (document.giving1.bf.value >0){bx = "B";}
if (document.giving1.tv.value >0){mx = "M";}
if (document.giving1.mi.value >0){ex = "E";}
if (document.giving1.ip.value >0){ix = "I";}

fname = document.giving1.fname.value;
fname = fname.toUpperCase();
if (fname.length > 1)
	{y=1;}else{y=fname.length}
fname = fname.substring(0, y)

lname = document.giving1.lname.value;
lname = lname.toUpperCase();
if (lname.length > 3)
	{y=3;}else{y=lname.length}
lname = lname.substring(0, y)

if (date_mm < 10){date_mm = "0"+date_mm;}
if (date_dd  < 10){date_dd   = "0"+date_dd;}

item_number =  item_number + "-" + lname + "-" + fname + date_mm + date_dd + date_hh + date_ms + date_ss + tx+ox+bx+mx+ex+ix;
document.giving1.item_number.value= item_number;

}



function calculate2(){

var mydate=new Date()
var date_day=mydate.getDay()         //0=sun; 1=mon; 2=tue ...
var date_dd=mydate.getDate()         //1 to 31
var date_mm=mydate.getMonth()+1 //0=jan; 1=feb; 2=mar... to 11=dec
var date_yyyy=mydate.getYear()

subtotal=0; 
total_a3=0;

gt = document.giving2.gift_type.value;
a3 = document.giving2.amount_a3.value*1;
p3 = document.giving2.billing_cycle_p3.value*1;
t3 = document.giving2.billing_cycle_t3.value;
srt = document.giving2.how_many_srt.value*1;

if (document.giving2.gift_type.value == "TH"){document.giving2.type.value = "TITHE";}
if (document.giving2.gift_type.value == "OF"){document.giving2.type.value = "OFFERING";}
if (document.giving2.gift_type.value == "BF"){document.giving2.type.value = "BUILDING FUND";}
if (document.giving2.gift_type.value == "TV"){document.giving2.type.value = "TV, RADIO, MEDIA";}
if (document.giving2.gift_type.value == "MS"){document.giving2.type.value = "MISSIONS";}
if (document.giving2.gift_type.value == "IP"){document.giving2.type.value = "IPMC";}

document.giving2.p3.value = document.giving2.billing_cycle_p3.value;

if (document.giving2.billing_cycle_t3.value == "W"){document.giving2.t3.value = "WEEK(S)";}
if (document.giving2.billing_cycle_t3.value == "M"){document.giving2.t3.value = "MONTH(S)";}
//if (document.giving2.billing_cycle_t3.value == "W"){document.giving2.t3x.value = "WEEK(S)";}
//if (document.giving2.billing_cycle_t3.value == "M"){document.giving2.t3x.value = "MONTH(S)";}
document.giving2.t3x.value = "INSTALLMENTS";

total_a3 = a3*srt;
document.giving2.total_a3.value = total_a3;

var date_hh=lZ(mydate.getHours())
var date_ms=lZ(mydate.getMinutes())
var date_ss=lZ(mydate.getSeconds())

var item_number="FFM-ARG";

fname = document.giving2.fname.value;
fname = fname.toUpperCase();
if (fname.length > 1)
	{y=1;}else{y=fname.length}
fname = fname.substring(0, y)

lname = document.giving2.lname.value;
lname = lname.toUpperCase();
if (lname.length > 3)
	{y=3;}else{y=lname.length}
lname = lname.substring(0, y)

if (date_mm < 10){date_mm = "0"+date_mm;}
if (date_dd  < 10){date_dd   = "0"+date_dd;}

item_number = item_number + "-" + lname + "-" + fname + date_mm + date_dd + date_hh + date_ms + date_ss + "-" + gt + "-" + a3 + "-EA" + p3 + t3 + "X"+ srt;
document.giving2.item_number.value= item_number;

}