//var support_gifttype_map={ff:'fftotal',other:'onetimetotal',monthlyother:'monthlytotal',wcsgdaysponsor:'wcsgdaysponsordata',hkrdaysponsor:'hkrdaysponsordata'};
var support_gifttype_map={ff:'fftotal',other:'onetimetotal',monthlyother:'monthlytotal',wcsgdaysponsor:'wcsgdaysponsordata'};

//var gifttype_map={friendraisergift:'friendraisertotal',ff:'fftotal',other:'onetimetotal',monthlyother:'monthlytotal',wcsgdaysponsor:'wcsgdaysponsordata',hkrdaysponsor:'hkrdaysponsordata'};
//var gifttype_map={onetime:'onetimetotal',monthly:'monthlytotal',wcsgdaysponsor:'wcsgdaysponsordata',hkrdaysponsor:'hkrdaysponsordata'};
var gifttype_map={onetime:'onetimetotal',monthly:'monthlytotal',wcsgdaysponsor:'wcsgdaysponsordata'};

//var moved_map={no:'noaddress',yes:'oldaddress'};
var moved_map={yes:'oldaddress'};

var paytype_map={1:'paybycc',2:'paybyeft',3:'paybycheck'};
window.giverUpdate = (function() {
	var that = {};
	that.process = function(data) {
		var title = document.getElementById('title');
		for (var i = 0; i < title.options.length; i++) {
			if (title.options[i].value == data.title) {
				title.selectedIndex = i;
				break;
			}
		}
		document.getElementById('fname').value = data.fname;
		document.getElementById('lname').value = data.lname;
		document.getElementById('address1').value = data.address1;
		document.getElementById('address2').value = data.address2;
		document.getElementById('city').value = data.city;
		document.getElementById('state').value = data.state;
		document.getElementById('zip').value = data.zip;
		var phone = data.phone.replace('(', '').replace(')', '').replace('-', '').replace(' ', '');
		document.getElementById('phone1').value = phone.substring(0, 3);
		document.getElementById('phone2').value = phone.substring(3, 6);
		document.getElementById('phone3').value = phone.substring(6);
		document.getElementById('email').value = data.email;
		var birthmonth = document.getElementById('birthmonth');
		for (var i = 0; i < birthmonth.options.length; i++) {
			if (birthmonth.options[i].value == data.bdate.substring(5, 7)) {
				birthmonth.selectedIndex = i;
				break;
			}
		}
		var birthday = document.getElementById('birthday');
		for (var i = 0; i < birthday.options.length; i++) {
			if (birthday.options[i].value == data.bdate.substring(8, 10)) {
				birthday.selectedIndex = i;
				break;
			}
		}
		document.getElementById('birthyear').value = data.bdate.substring(0, 4);
		updateTime.update();
		window.focus();
	}
	return that;
})();

var quickGiftUpdate = function() {
	var that = {};
	var cache = null;
	var waiting = false;
	var onetime = document.getElementById('onetime_amount');
	var monthly = document.getElementById('monthlyamount');
	var dsAmount = document.getElementById('ds_amount');
	var id = 0;
	var postUpdate = function(XHR) {
		if (id == 0) id = XHR.responseText;
		waiting = false;
		if (cache) { that.update(); }
	}
	that.update = function() {
		var idString = id > 0 ? '&id='+id : '';
		var amount;
		if (cache) {
			amount = cache;
			cache = null;
		} else {
			amount = this.id == 'monthlyamount' ? this.value * 12 : this.value;
		}
		if (waiting) {
			cache = this.id == 'monthlyamount' ? this.value * 12 : this.value;
		} else {
			waiting = true;
			amount = amount || 0;
			cvhXHR(postUpdate, '/includes/support/quick_gift_update.php?amount='+amount+idString);
		}
	}
	onetime.update = that.update;
	monthly.update = that.update;
	dsAmount.update = that.update;
	onetime.onkeyup = onetime.update;
	monthly.onkeyup = monthly.update;
	dsAmount.onkeyup = dsAmount.update;
	var onetimeclick = document.getElementById('onetime').onclick;
	var monthlyclick = document.getElementById('monthly').onclick;
	var dsclick = document.getElementById('wcsgdaysponsor').onclick;
	document.getElementById('onetime').onclick = function() {
		show_div(this, gifttype_map);
		eRcpt.check();
		daySponsor.toggleCheck();
		daySponsor.toggleRemainder();
		onetime.update();
	}
	document.getElementById('monthly').onclick = function() {
		show_div(this, gifttype_map);
		eRcpt.check();
		daySponsor.toggleCheck();
		daySponsor.toggleRemainder();
		monthly.update();
	}
	document.getElementById('wcsgdaysponsor').onclick = function() {
		show_div(this, gifttype_map);
		eRcpt.check();
		daySponsor.toggleCheck();
		daySponsor.toggleRemainder();
		dsAmount.update();
	}
}

function switch_div() {

  if(document.getElementById('flyer').checked) {
    document.getElementById('flyer_yes').style.display = "block";
    } else {
    document.getElementById('flyer_yes').style.display = "none";
    }
}

function show_div(selector, map){
  for (ii in map) {
    var choice;
    if (selector.type=='radio') choice=selector.value
    else choice=selector.selectedIndex
    if (choice == ii)
      document.getElementById(map[ii]).style.display='block';
    else
      document.getElementById(map[ii]).style.display='none';
  }
}

<!-- Copyright 2003 Bontrager Connection, LLC
// Code obtained from http://WillMaster.com/

function CheckRequiredFields() {
var errormessage = new String();

// Put field checks below this point.


if(WithoutContent(document.sharathon_form.fname.value))
        { errormessage += "\n\nPlease enter your first name."; }

if(WithoutContent(document.sharathon_form.lname.value))
        { errormessage += "\n\nPlease enter your last name."; }

if(WithoutContent(document.sharathon_form.address1.value))
        { errormessage += "\n\nPlease enter your address."; }

if(WithoutContent(document.sharathon_form.city.value))
        { errormessage += "\n\nPlease enter your city."; }

if(WithoutContent(document.sharathon_form.state.value))
        { errormessage += "\n\nPlease enter your state."; }

if(WithoutContent(document.sharathon_form.zip.value))
        { errormessage += "\n\nPlease enter your zip code."; }

if(WithoutContent(document.sharathon_form.phone2.value))
        { errormessage += "\n\nPlease enter your phone number."; }

if(WithoutContent(document.sharathon_form.email.value))
        { errormessage += "\n\nPlease enter your email address."; }

if(WithoutSelectionValue(document.sharathon_form.paytype))
        { errormessage += "\n\nPlease choose a payment type, either Credit Card, EFT, or Check."; }

if(document.getElementById('onetime').checked && WithoutContent(document.sharathon_form.onetime_amount.value))
		{ errormessage += "\n\nPlease enter a Gift Amount."; }

if(document.getElementById('monthly').checked && WithoutContent(document.sharathon_form.monthlyamount.value))
		{ errormessage += "\n\nPlease enter a Gift Amount."; }
// Daysponsor Block
if(document.getElementById('wcsgdaysponsor').checked) {
	if(document.getElementById('ds_paytype_monthly').checked && !(document.getElementById('ds_remainder_type_cc').checked || document.getElementById('ds_remainder_type_check').checked || document.getElementById('ds_remainder_type_check_eft').checked || document.getElementById('ds_remainder_type_eft').checked))
		{ errormessage += "\n\nPlease tell how you would like to make the remainder payments." }
	if(NoneWithCheck(document.sharathon_form.hoodie_accept))
		{ errormessage += "\n\nPlease choose whether or not you'd like a hoodie in the Day Sponsor section." }
}

if(document.sharathon_form.paytype.options[document.sharathon_form.paytype.selectedIndex].value == 'choose')
		{ errormessage += "\n\nPlease choose a payment type, either Credit Card, EFT, or Check."; }
// Credit Card Block
if(document.sharathon_form.paytype.options[document.sharathon_form.paytype.selectedIndex].value == 'paybycc') {
	if(WithoutSelectionValue(document.sharathon_form.cctype))
		{ errormessage += "\n\nPlease enter your Credit/Debit Card Type."; }
	if(WithoutContent(document.sharathon_form.card_name.value))
		{ errormessage += "\n\nPlease enter the name on your Credit/Debit Card."; }
	if(WithoutContent(document.sharathon_form.card_number1.value) || WithoutContent(document.sharathon_form.card_number2.value) || WithoutContent(document.sharathon_form.card_number3.value) || WithoutContent(document.sharathon_form.card_number4.value))
		{ errormessage += "\n\nPlease enter your Credit/Debit Card Number."; }

// require card expiration
if((document.sharathon_form.expiremonth.options[document.sharathon_form.expiremonth.selectedIndex].value == '' || document.sharathon_form.expireyear.options[document.sharathon_form.expireyear.selectedIndex].value == ''))
                { errormessage += "\n\nPlease enter your credit card's expiration date."; }


	//if(document.getElementById('cce-receipts-yes').checked && WithoutContent(document.sharathon_form['cce-receipts-email']))
		//{ errormessage += "\n\nPlease enter your email address for e-receipts."; }
}
// EFT block
if(document.sharathon_form.paytype.options[document.sharathon_form.paytype.selectedIndex].value == 'eft') {
	if(WithoutSelectionValue(document.sharathon_form.eft_type))
		{ errormessage += "\n\nPlease enter your Account Type."; }
	if(WithoutContent(document.sharathon_form.eft_routing_number.value))
		{ errormessage += "\n\nPlease enter your Routing Number."; }
	if(WithoutContent(document.sharathon_form.eft_account_number.value))
		{ errormessage += "\n\nPlease enter your Account Number."; }
	if(WithoutContent(document.sharathon_form.eft_bank_name.value))
		{ errormessage += "\n\nPlease enter your Bank Name."; }
	//if(document.getElementById('efte-receipts-yes').checked && WithoutContent(document.sharathon_form['efte-receipts-email']))
		//{ errormessage += "\n\nPlease enter your email address for e-receipts."; }
}


// Put field checks above this point.
if(errormessage.length > 2) {
        alert('NOTE:' + errormessage);
        return false;
        }
return true;
} // end of function CheckRequiredFields()


function WithoutContent(ss) {
if(ss.length > 0) { return false; }
return true;
}

function NoneWithContent(ss) {
for(var i = 0; i < ss.length; i++) {
        if(ss[i].value.length > 0) { return false; }
        }
return true;
}

function NoneWithCheck(ss) {
for(var i = 0; i < ss.length; i++) {
        if(ss[i].checked) { return false; }
        }
return true;
}

function WithoutCheck(ss) {
if(ss.checked) { return false; }
return true;
}

function WithoutSelectionValue(ss) {
for(var i = 0; i < ss.length; i++) {
        if(ss[i].selected) {
                if(ss[i].value.length) { return false; }
                }
        }
return true;
}

var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode; 
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}
function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
return true;
}
