function save_excel() {
var url;


var budget = unformat(document.forms.budget.budget.value);
var church = unformat(document.forms.budget.church.value);
var reception = unformat(document.forms.budget.reception.value);
var guests = unformat(document.forms.budget.guests.value);
var photographer = unformat(document.forms.budget.photographer.value);
var videographer = unformat(document.forms.budget.videographer.value);
var dj = unformat(document.forms.budget.dj.value);
var flowers = unformat(document.forms.budget.flowers.value);
var dress = unformat(document.forms.budget.dress.value);
var limo = unformat(document.forms.budget.limo.value);
var invitations = unformat(document.forms.budget.invitations.value);
var officient = unformat(document.forms.budget.officient.value);
var gifts = unformat(document.forms.budget.gifts.value);
var jewelry = unformat(document.forms.budget.jewelry.value);
var other1 = unformat(document.forms.budget.other1.value);
var other2 = unformat(document.forms.budget.other2.value);
var other3 = unformat(document.forms.budget.other3.value);
var other4 = unformat(document.forms.budget.other4.value);
var other5 = unformat(document.forms.budget.other5.value);
var textother1 = document.forms.budget.textother1.value;
var textother2 = document.forms.budget.textother2.value;
var textother3 = document.forms.budget.textother3.value;
var textother4 = document.forms.budget.textother4.value;
var textother5 = document.forms.budget.textother5.value;


url = 'excel.php?budget=' + budget + '&church=' + church + '&reception=' + reception + '&guests=' + guests + '&photographer=' + photographer + '&videographer=' + videographer + '&dj=' + dj + '&flowers=' + flowers + '&dress=' + dress + '&limo=' + limo + '&invitations=' + invitations + '&officient=' + officient + '&gifts=' + gifts + '&jewelry=' + jewelry + '&other1=' + other1 + '&other2=' + other2 + '&other3=' + other3 + '&other4=' + other4 + '&other5=' + other5 + '&textother1=' + textother1 + '&textother2=' + textother2 + '&textother3=' + textother3 + '&textother4=' + textother4 + '&textother5=' + textother5;

window.open(url,'newwindow','width=1,height=1');

}

function print() {
var url;

var total = unformat(document.forms.budget.total.value);
var overunder = unformat(document.forms.budget.overunder.value);
var ppg = unformat(document.forms.budget.ppg.value);

var budget = unformat(document.forms.budget.budget.value);
var church = unformat(document.forms.budget.church.value);
var reception = unformat(document.forms.budget.reception.value);
var guests = unformat(document.forms.budget.guests.value);
var photographer = unformat(document.forms.budget.photographer.value);
var videographer = unformat(document.forms.budget.videographer.value);
var dj = unformat(document.forms.budget.dj.value);
var flowers = unformat(document.forms.budget.flowers.value);
var dress = unformat(document.forms.budget.dress.value);
var limo = unformat(document.forms.budget.limo.value);
var invitations = unformat(document.forms.budget.invitations.value);
var officient = unformat(document.forms.budget.officient.value);
var gifts = unformat(document.forms.budget.gifts.value);
var jewelry = unformat(document.forms.budget.jewelry.value);
var other1 = unformat(document.forms.budget.other1.value);
var other2 = unformat(document.forms.budget.other2.value);
var other3 = unformat(document.forms.budget.other3.value);
var other4 = unformat(document.forms.budget.other4.value);
var other5 = unformat(document.forms.budget.other5.value);
var textother1 = document.forms.budget.textother1.value;
var textother2 = document.forms.budget.textother2.value;
var textother3 = document.forms.budget.textother3.value;
var textother4 = document.forms.budget.textother4.value;
var textother5 = document.forms.budget.textother5.value;


url = 'print.php?budget=' + budget + '&church=' + church + '&reception=' + reception + '&guests=' + guests + '&photographer=' + photographer + '&videographer=' + videographer + '&dj=' + dj + '&flowers=' + flowers + '&dress=' + dress + '&limo=' + limo + '&invitations=' + invitations + '&officient=' + officient + '&gifts=' + gifts + '&jewelry=' + jewelry + '&other1=' + other1 + '&other2=' + other2 + '&other3=' + other3 + '&other4=' + other4 + '&other5=' + other5 + '&textother1=' + textother1 + '&textother2=' + textother2 + '&textother3=' + textother3 + '&textother4=' + textother4 + '&textother5=' + textother5 + '&total=' + total + '&overunder=' + overunder + '&ppg=' + ppg;

window.open(url,'newwindow','width=600,height=600');

}


function recommend() {

var budget = unformat(document.forms.budget.budget.value);

var points = 0;
var churchfactor = 3;
var receptionfactor = 48;
var photographerfactor = 12;
var videographerfactor = 8;
var djfactor = 5;
var flowersfactor = 8;
var dressfactor = 10;
var limofactor = 3.5;
var invitationsfactor = 3;
var officientfactor = 1.5;
var giftsfactor = 2;
var jewelryfactor = 4;

if (document.forms.budget.chkchurch.checked) {points = points + churchfactor;}
else {churchfactor = 0;}
if (document.forms.budget.chkreception.checked) {points = points + receptionfactor;}
else {receptionfactor = 0;}
if (document.forms.budget.chkphotographer.checked) {points = points + photographerfactor;}
else {photographerfactor = 0;}
if (document.forms.budget.chkvideographer.checked) {points = points + videographerfactor;}
else {videographerfactor = 0;}
if (document.forms.budget.chkdj.checked) {points = points + djfactor;}
else {djfactor = 0;}
if (document.forms.budget.chkflowers.checked) {points = points + flowersfactor;}
else {flowersfactor = 0;}
if (document.forms.budget.chkdress.checked) {points = points + dressfactor;}
else {dressfactor = 0;}
if (document.forms.budget.chklimo.checked) {points = points + limofactor;}
else {limofactor = 0;}
if (document.forms.budget.chkinvitations.checked) {points = points + invitationsfactor;}
else {invitationsfactor = 0;}
if (document.forms.budget.chkofficient.checked) {points = points + officientfactor;}
else {officientfactor = 0;}
if (document.forms.budget.chkgifts.checked) {points = points + giftsfactor;}
else {giftsfactor = 0;}
if (document.forms.budget.chkjewelry.checked) {points = points + jewelryfactor;}
else {jewelryfactor = 0;}


document.forms.budget.church.value = budget * (churchfactor / points);
document.forms.budget.reception.value = budget * (receptionfactor / points);
document.forms.budget.photographer.value = budget * (photographerfactor / points);
document.forms.budget.videographer.value = budget * (videographerfactor / points);
document.forms.budget.dj.value = budget * (djfactor / points);
document.forms.budget.flowers.value = budget * (flowersfactor / points);
document.forms.budget.dress.value = budget * (dressfactor / points);
document.forms.budget.limo.value = budget * (limofactor / points);
document.forms.budget.invitations.value = budget * (invitationsfactor / points);
document.forms.budget.officient.value = budget * (officientfactor / points);
document.forms.budget.gifts.value = budget * (giftsfactor / points);
document.forms.budget.jewelry.value = budget * (jewelryfactor / points);
document.forms.budget.other1.value = 0;
document.forms.budget.other2.value = 0;
document.forms.budget.other3.value = 0;
document.forms.budget.other4.value = 0;
document.forms.budget.other5.value = 0;



reception_change()

}



function enter() {

if(event.keyCode==13) {
event.keyCode=9
field_change();
};

}


function check() {

if (!document.forms.budget.chkchurch.checked) {
document.forms.budget.church.value=0;
document.forms.budget.church.disabled = true;
}
else {document.forms.budget.church.disabled = false;}

if (!document.forms.budget.chkreception.checked) {
document.forms.budget.reception.value=0;
document.forms.budget.reception.disabled = true;
document.forms.budget.guests.disabled = true;
document.forms.budget.ppg.disabled = true;

}
else {
document.forms.budget.reception.disabled = false;
document.forms.budget.guests.disabled = false;
document.forms.budget.ppg.disabled = false;
}

if (!document.forms.budget.chkphotographer.checked) {
document.forms.budget.photographer.value=0;
document.forms.budget.photographer.disabled = true;
}
else {document.forms.budget.photographer.disabled = false;}

if (!document.forms.budget.chkvideographer.checked) {
document.forms.budget.videographer.value=0;
document.forms.budget.videographer.disabled = true;
}
else {document.forms.budget.videographer.disabled = false;}

if (!document.forms.budget.chkdj.checked) {
document.forms.budget.dj.value=0;
document.forms.budget.dj.disabled = true;
}
else {document.forms.budget.dj.disabled = false;}

if (!document.forms.budget.chkflowers.checked) {
document.forms.budget.flowers.value=0;
document.forms.budget.flowers.disabled = true;
}
else {document.forms.budget.flowers.disabled = false;}

if (!document.forms.budget.chkdress.checked) {
document.forms.budget.dress.value=0;
document.forms.budget.dress.disabled = true;
}
else {document.forms.budget.dress.disabled = false;}

if (!document.forms.budget.chklimo.checked) {
document.forms.budget.limo.value=0;
document.forms.budget.limo.disabled = true;
}
else {document.forms.budget.limo.disabled = false;}

if (!document.forms.budget.chkinvitations.checked) {
document.forms.budget.invitations.value=0;
document.forms.budget.invitations.disabled = true;
}
else {document.forms.budget.invitations.disabled = false;}

if (!document.forms.budget.chkgifts.checked) {
document.forms.budget.gifts.value=0;
document.forms.budget.gifts.disabled = true;
}
else {document.forms.budget.gifts.disabled = false;}

if (!document.forms.budget.chkofficient.checked) {
document.forms.budget.officient.value=0;
document.forms.budget.officient.disabled = true;
}
else {document.forms.budget.officient.disabled = false;}


if (!document.forms.budget.chkjewelry.checked) {
document.forms.budget.jewelry.value=0;
document.forms.budget.jewelry.disabled = true;
}
else {document.forms.budget.jewelry.disabled = false;}

if (!document.forms.budget.chkother1.checked) {
document.forms.budget.other1.value=0;
document.forms.budget.other1.disabled = true;
document.forms.budget.textother1.disabled = true;

}
else {
document.forms.budget.other1.disabled = false;
document.forms.budget.textother1.disabled = false;
}

if (!document.forms.budget.chkother2.checked) {
document.forms.budget.other2.value=0;
document.forms.budget.other2.disabled = true;
document.forms.budget.textother2.disabled = true;

}
else {
document.forms.budget.other2.disabled = false;
document.forms.budget.textother2.disabled = false;
}

if (!document.forms.budget.chkother3.checked) {
document.forms.budget.other3.value=0;
document.forms.budget.other3.disabled = true;
document.forms.budget.textother3.disabled = true;

}
else {
document.forms.budget.other3.disabled = false;
document.forms.budget.textother3.disabled = false;
}

if (!document.forms.budget.chkother4.checked) {
document.forms.budget.other4.value=0;
document.forms.budget.other4.disabled = true;
document.forms.budget.textother4.disabled = true;

}
else {
document.forms.budget.other4.disabled = false;
document.forms.budget.textother4.disabled = false;
}

if (!document.forms.budget.chkother5.checked) {
document.forms.budget.other5.value=0;
document.forms.budget.other5.disabled = true;
document.forms.budget.textother5.disabled = true;

}
else {
document.forms.budget.other5.disabled = false;
document.forms.budget.textother5.disabled = false;
}








field_change();
}


function field_change() {

var total;
var overunder;
var budget = unformat(document.forms.budget.budget.value);


var church = unformat(document.forms.budget.church.value);
var reception = unformat(document.forms.budget.reception.value);
var photographer = unformat(document.forms.budget.photographer.value);
var videographer = unformat(document.forms.budget.videographer.value);
var dj = unformat(document.forms.budget.dj.value);
var flowers = unformat(document.forms.budget.flowers.value);
var dress = unformat(document.forms.budget.dress.value);
var limo = unformat(document.forms.budget.limo.value);
var invitations = unformat(document.forms.budget.invitations.value);
var officient = unformat(document.forms.budget.officient.value);
var gifts = unformat(document.forms.budget.gifts.value);
var jewelry = unformat(document.forms.budget.jewelry.value);

var other1 = unformat(document.forms.budget.other1.value);
var other2 = unformat(document.forms.budget.other2.value);
var other3 = unformat(document.forms.budget.other3.value);
var other4 = unformat(document.forms.budget.other4.value);
var other5 = unformat(document.forms.budget.other5.value);





document.forms.budget.church.value = format(church, 2, ',', '.', '$', '', '-', '');
document.forms.budget.reception.value = format(reception, 2, ',', '.', '$', '', '-', '');
document.forms.budget.photographer.value = format(photographer, 2, ',', '.', '$', '', '-', '');
document.forms.budget.videographer.value = format(videographer, 2, ',', '.', '$', '', '-', '');
document.forms.budget.dj.value = format(dj, 2, ',', '.', '$', '', '-', '');
document.forms.budget.flowers.value = format(flowers, 2, ',', '.', '$', '', '-', '');
document.forms.budget.dress.value = format(dress, 2, ',', '.', '$', '', '-', '');
document.forms.budget.limo.value = format(limo, 2, ',', '.', '$', '', '-', '');
document.forms.budget.invitations.value = format(invitations, 2, ',', '.', '$', '', '-', '');
document.forms.budget.officient.value = format(officient, 2, ',', '.', '$', '', '-', '');
document.forms.budget.gifts.value = format(gifts, 2, ',', '.', '$', '', '-', '');
document.forms.budget.jewelry.value = format(jewelry, 2, ',', '.', '$', '', '-', '');

document.forms.budget.other1.value = format(other1, 2, ',', '.', '$', '', '-', '');
document.forms.budget.other2.value = format(other2, 2, ',', '.', '$', '', '-', '');
document.forms.budget.other3.value = format(other3, 2, ',', '.', '$', '', '-', '');
document.forms.budget.other4.value = format(other4, 2, ',', '.', '$', '', '-', '');
document.forms.budget.other5.value = format(other5, 2, ',', '.', '$', '', '-', '');



total = church + reception + photographer + videographer + dj + flowers + dress + limo + invitations + officient + gifts + jewelry + other1 + other2 + other3 + other4 + other5;
document.forms.budget.total.value = format(total, 2, ',', '.', '$', '', '-', '');

overunder = budget - total;
document.forms.budget.overunder.value = format(overunder, 2, ',', '.', '$', '', '-', '');

if (overunder > -.001) {document.forms.budget.overunder.style.color = "green";}
else {document.forms.budget.overunder.style.color = "red";}


}


function reception_change() {

field_change();

var ppg;
var reception = unformat(document.forms.budget.reception.value);
var guests = unformat(document.forms.budget.guests.value);
if (guests > 0) {
ppg = reception / guests;
document.forms.budget.ppg.value = format(ppg, 2, ',', '.', '$', '', '-', '');

}


}


function ppg_change() {

var reception;
var ppg = unformat(document.forms.budget.ppg.value);
var guests = unformat(document.forms.budget.guests.value);
if (guests > 0 && ppg > 0) {
reception = guests * ppg;
document.forms.budget.reception.value = format(reception, 2, ',', '.', '$', '', '-', '');
document.forms.budget.ppg.value = format(ppg, 2, ',', '.', '$', '', '-', '');

}


}





function budget_change() {
var budget = unformat(document.forms.budget.budget.value);
document.forms.budget.budget.value = format(budget, 2, ',', '.', '$', '', '-', '');
}






function unformat(input) {
 if (input == '') {input = '0';}
          re = /\$|,|@|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\-|\_|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$|/g;
          // remove special characters like "$" and "," etc...
          input = input.replace(re, "");
if (checkNumber(input)) {
		return parseFloat(input);
}
else {
alert ('Invalid Entry');
return 0;
}
     
}



function checkNumber(input)
{
    for (var i = 0; i < input.length; i++)
  {
   var ch = input.substring(i, i + 1)
   if ((ch < "0" || "9" < ch) && ch != '.') 
   {
     return false;
   }
  }
    return true;
}












function format(num,dec,thou,pnt,curr1,curr2,n1,n2) {var x = Math.round(num * Math.pow(10,dec));if (x >= 0) n1=n2='';var y = (''+Math.abs(x)).split('');var z = y.length - dec; if (z<0) z--; for(var i = z; i < 0; i++) y.unshift('0');y.splice(z, 0, pnt); while (z > 3) {z-=3; y.splice(z,0,thou);}var r = curr1+n1+y.join('')+n2+curr2;return r;}


