// JavaScript Document
var ie7 = (document.all && !window.opera && window.XMLHttpRequest) ? true : false;

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function MM_validateContactForm() { //v4.0
  var i,p,q,nm,nd,test,num,min,max,errors='',args=MM_validateContactForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; nd=val.id; if (nm == "cFirstName" && val.value == 'First Name') { val.value = "";} else { if (nm == "cLastName" && val.value == 'Last Name') { val.value = "";}  else { if (nm == "cPhone" && val.value == 'Phone') { val.value = "";}}}if ((vVal=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=vVal.indexOf('@');
        if (p<1 || p==(vVal.length-1)) errors+='- '+nd+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(vVal);
        if (isNaN(vVal)) errors+='- '+nd+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nd+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nd+' is required.\n'; 
	if ( nm == "cFirstName" && val.value == '') {val.value = "First Name";} if (nm == "cLastName" && val.value == '') { val.value = "Last Name";} if (nm == "cPhone" && val.value == '') { val.value = "Phone";} }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
 	document.MM_returnValue = (errors == '');
  	document.cForm.action = "contact-us.cfm?sID=1";
}

function MM_validateHymnalForm() { //v4.0
  var i,p,q,nm,nd,test,num,min,max,errors='',args=MM_validateHymnalForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; nd=val.id; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nd+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nd+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nd+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nd+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
  document.dForm.action = "https://www6899.ssldomain.com/llchurch/submit-mobile-hymnal-order.cfm?sID=1";
}


function MM_validateDonationForm() { //v4.0
  var i,p,q,nm,nd,test,num,min,max,errors='',args=MM_validateDonationForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; nd=val.id; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nd+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nd+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nd+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nd+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
  document.dForm.action = "https://www6899.ssldomain.com/llchurch/submit-a-charitable-contribution.cfm?sID=1";
}

function MM_validatePaymentForm() { //v4.0
  var i,p,q,nm,nd,test,num,min,max,errors='',args=MM_validatePaymentForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; nd=val.id; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nd+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nd+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nd+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nd+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
  document.dForm.action = "https://www6899.ssldomain.com/llchurch/submit-a-payment.cfm?sID=1";
}

function MM_validateRenewalForm() { //v4.0
  var i,p,q,nm,nd,test,num,min,max,errors='',args=MM_validateRenewalForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; nd=val.id; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nd+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nd+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nd+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nd+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
  document.rForm.action = "https://www6899.ssldomain.com/llchurch/submit-subscription-renewal.cfm?sID=1";
}

function MM_validateNewSForm() { //v4.0
  var i,p,q,nm,nd,test,num,min,max,errors='',args=MM_validateNewSForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; nd=val.id; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nd+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nd+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nd+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nd+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
  document.rForm.action = "https://www6899.ssldomain.com/llchurch/submit-subscription-new.cfm?sID=1";
}


function MM_validateChangeForm() { //v4.0
  var i,p,q,nm,nd,test,num,min,max,errors='',args=MM_validateChangeForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; nd=val.id; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nd+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nd+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nd+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nd+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
  document.dForm.action = "http://www.llchurch.org/change-of-address.cfm?sID=1";
}

function MM_validateVZForm() { //v4.0
  var i,p,q,nm,nd,test,num,min,max,errors='',args=MM_validateVZForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; nd=val.id; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nd+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nd+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nd+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nd+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
  document.dForm.action = "https://www6899.ssldomain.com/llchurch/submit-an-announcement.cfm?sID=1";
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,nd,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; nd=val.id; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nd+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nd+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nd+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nd+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

var thisPage = document.URL.substring(document.URL.lastIndexOf("/")+1 ,document.URL.length);
thisPage = thisPage.substring(0 ,thisPage.lastIndexOf("."));

function setPrice(r,t) {
	if(thisPage == "mobile-hymnal-instructions" || thisPage == "submit-mobile-hymnal-order") {
		var ac = MM_findObj('Activation Cost');
		var fac = MM_findObj('fha');
		fac.value = ac.value;
		
		var pc = MM_findObj('Phone Code');
		var fpc = MM_findObj('fhpc');
		fpc.value = pc.value;
	}
	if (thisPage == "make-a-charitable-contribution" || thisPage == "submit-a-charitable-contribution") {
		$("#ff").val($("#Fund :selected").text());
		if($("#Fund").val().substring($("#Fund").val().lastIndexOf(",")+1)) {
			$("#ff").val($("#ff").val()+": "+$("#DonorSpecified").val());	
		}
		$("#fda").val($("#Amount").val());
	}
	if (thisPage == "make-a-payment" || thisPage == "submit-a-payment") {
		$("#ff").val($("#Fund").val());
		$("#fda").val($("#Amount").val());
	}
	if (thisPage == "subscriptions-renewal" || thisPage == "submit-subscription-renewal") {
		$("#fi").val($("#Invoice").val());
		$("#fra").val($("#Amount").val());
	}
	if(thisPage == "subscriptions-new" || thisPage == "submit-subscription-new") {
		var total = 0;
		if(rForm.sCountry[0].checked || rForm.sCountry[1].checked) {
			$('#naOrderC').show(1);
			$('#onaOrderC').hide(1);
			for(i=1; i<=$('#naItemsC .narC').length ;i++) {
				$('#cnaqty'+i).val($('#naqty'+i).val());
				$('#cnai'+i).val($('#nai'+i).val());
				$('#cnaqty'+i).val($('#naqty'+i).val());
				if($('#cnaqty'+i).val() > 0) {  $('#narC'+i).show(1); } else { $('#narC'+i).hide(1); }
				$('#cnais'+i).val($('#cnai'+i).val() * $('#cnaqty'+i).val());
				total += parseInt($('#cnais'+i).val());
			}
		}
		if(rForm.sCountry[2].checked) {
			$('#naOrderC').hide(1);
			$('#onaOrderC').show(1);
			for(i=1; i<=$('#onaItemsC .onarC').length ;i++) {
				$('#conaqty'+i).val($('#onaqty'+i).val());
				$('#conai'+i).val($('#onai'+i).val());
				$('#conaqty'+i).val($('#onaqty'+i).val());
				if($('#conaqty'+i).val() > 0) {  $('#onarC'+i).show(1); } else { $('#onarC'+i).hide(1); }
				$('#conais'+i).val($('#conai'+i).val() * $('#conaqty'+i).val());
				total += parseInt($('#conais'+i).val());
			}
		}
		$('#fna').val(total);
		$('.currency').currencyFormat();

	}
	if (thisPage == "voice-of-zion-announcements" || thisPage == "submit-an-announcement") {
		var confZText = '<div class="cHeader">'+ $("#vza").val() +'</div>';
		for(i=1; i<=$('#vzft').val() ;i++) {
			confZText += $('#vzf'+i).attr('title') + ": " + $('#vzf'+i).val() + "<br />";
		}
		$("#confZ").html(confZText);
		$("#fda").val($("#dAmount").val());
	}
}

function setConf() {
	if(thisPage == "voice-of-zion-announcements" || thisPage == "submit-an-announcement") {
		var confBText = '<div class="cHeader">Billing Details</div>' +
		$('#dFirstName').val() + ' ' + $('#dLastName').val() + '<br />' +
		$('#dAddress').val()+ '<br />' +
		$('#dCity').val() + ', ';
	} else {
		var confBText = '<div class="cHeader">Billing Details</div>' +
		MM_findObj('First Name').value + ' ' + MM_findObj('Last Name').value + '<br />' +
		MM_findObj('Address').value+ '<br />' +
		MM_findObj('City').value + ', ';
	}
	
	if (thisPage == "subscriptions-renewal" || thisPage == "submit-subscription-renewal" || thisPage == "subscriptions-new" || thisPage == "submit-subscription-new") {
		if($('#Country1').is(':checked')) {
			confBText += MM_findObj('sState1').value + ' ' + MM_findObj('Zip').value + ' ' + MM_findObj('Country1').value + '<br />';
		}
		if($('#Country2').is(':checked')) {
			confBText += MM_findObj('sState2').value +' ' + MM_findObj('Zip').value + ' ' + MM_findObj('Country2').value + '<br />';
		}
		if($('#Country3').is(':checked')) {
			confBText += "NUS" + ' ' + MM_findObj('Zip').value + ' ' + MM_findObj('sState3').value + '<br />';
		}
	}
	else {
		if(thisPage == "voice-of-zion-announcements" || thisPage == "submit-an-announcement") {
			confBText += $('#dState').val() + ' ' + $('#dZip').val() + '<br />';
		} else {
			confBText += MM_findObj('State').value + ' ' + MM_findObj('Zip').value + '<br />';
		}
	}
	
	if(thisPage == "voice-of-zion-announcements" || thisPage == "submit-an-announcement") {
		confBText += 'Phone: ' + $('#dPhone').val() + '<br />' + 'Email: ' + $('#dEmail').val() + '<br />';
	} else {
		confBText += 'Phone: ' + MM_findObj('Phone').value + '<br />' + 'Email: ' + MM_findObj('Email').value + '<br />';
	}
	
	var confCText = '<div class="cHeader">Credit Card Details</div>' +
	 MM_findObj('ccType').value.toUpperCase() + ' ending in: ' + MM_findObj('ccNumber').value.substring(MM_findObj('ccNumber').value.length-4) + '<br />' +
	'Expiration Date: ' + MM_findObj('ccMonth').value + '/' + MM_findObj('ccYear').value + '<br />';

	MM_findObj('confB').innerHTML = confBText;
	MM_findObj('confC').innerHTML = confCText;

	Nifty("div#confB,div#confC", "none same-height");
	
	if (thisPage == "subscriptions-renewal" || thisPage == "submit-subscription-renewal") {
		var confAText = '<div class="aHeader">New Address</div>';
		if($("#nay").is(":checked")) {
			confAText += $("#sna").val() + '<br />' + $("#snc").val() + ', ';
			if($('#snco1').is(':checked')) {
				confAText += MM_findObj('sns1').value + ' ' + $("#snz").val() + ' ' + MM_findObj('snco1').value +'<br />';
			}
			if($('#snco2').is(':checked')) {
				confAText += MM_findObj('sns2').value + ' ' + $("#snz").val() + ' ' + MM_findObj('snco2').value +'<br />';
			}
			if($('#snco3').is(':checked')) {
				confAText += 'NUS' + ' ' + $("#snz").val() + ' ' + MM_findObj('sns3').value +'<br />';
			}
		} else {
			confAText += "No Change";
		}
		
		var confNText = '<div class="nHeader">Notes</div>' +
		$("#Notes").val() + '<br />';
		MM_findObj('confA').innerHTML = confAText;
		MM_findObj('confN').innerHTML = confNText;
		Nifty("div#confA,div#confN", "none same-height");
	}
	
	if(thisPage == "subscriptions-new" || thisPage == "submit-subscription-new") {
		var confNText = '<div class="nHeader">Notes</div>' +
		$("#Notes").val() + '<br />';
		MM_findObj('confN2').innerHTML = confNText;
	}
	setPrice(1,7);
	
}

function testCreditCard() {
  var myCardNo = MM_findObj('ccNumber').value;
  var myCardType = MM_findObj('ccType').value;
  if (checkCreditCard(myCardNo,myCardType)) {
    $(MM_findObj('ccNumber')).removeClass("error");
  } 
  else {
	 alert (ccErrors[ccErrorNo]);
  	$(MM_findObj('ccNumber')).addClass("error");
  }
}

function checkNI(i) {
	thisFund = $("#Fund").val();
	thisCheck = thisFund.substring(thisFund.lastIndexOf(",")+1);
	if(thisCheck == 1) {
		$("#otherInput").css("display","block");
	} else {
		$("#otherInput").css("display","none");	
	}
}
var formCheck = 1;

function showNAddress() {
	if($('#nay').is(':checked')) {
		$('#newAddress').show(1);
	}
	if($('#nan').is(':checked')) {
		$('#newAddress').hide(1);
	}
}

function upDateSubTotal() {
	var total = 0;
	if($('#rForm input[name=sCountry]:radio:checked').val() != "other") {
		for(i=1; i<=$('#naItems .nar').length ;i++) {
			$('#nais'+i).val($('#nai'+i).val() * $('#naqty'+i).val());
			total += parseInt($('#nais'+i).val());
		}
	}
	if($('#rForm input[name=sCountry]:radio:checked').val() == "other") {
		for(i=1; i<=$('#onaItems .onar').length ;i++) {
			$('#onais'+i).val($('#onai'+i).val() * $('#onaqty'+i).val());
			total += parseInt($('#onais'+i).val());
		}
	}
	$('#Amount').val(total);
	$('.currency').currencyFormat();
}

function setSCounty(form) {
	if ($('#rForm input[name=sCountry]:radio:checked').val() == "US") { form.sState1.disabled = false; form.sState2.disabled = true;  form.sState3.disabled = true};
	if ($('#rForm input[name=sCountry]:radio:checked').val() == "CA") { form.sState1.disabled = true;  form.sState2.disabled = false; form.sState3.disabled = true};
	if ($('#rForm input[name=sCountry]:radio:checked').val() == "other") { form.sState1.disabled = true;  form.sState2.disabled = true; form.sState3.disabled = false};
	if (thisPage == "subscriptions-new" || thisPage == "submit-subscription-new") {
		if($('#rForm input[name=sCountry]:radio:checked').val() != "other") { $("#naOrder").show(1);  $("#onaOrder").hide(1); upDateSubTotal(); }
		if($('#rForm input[name=sCountry]:radio:checked').val() == "other") { $("#naOrder").hide(1);  $("#onaOrder").show(1); upDateSubTotal(); }
	}
	
	if (thisPage == "subscriptions-renewal" || thisPage == "submit-subscription-renewal") {
		if($('#rForm input[name=sCountry]:radio:checked').val() != "other") { $("#nna").show(1); $("#nona").hide(1); }
		if($('#rForm input[name=sCountry]:radio:checked').val() == "other") { $("#nna").hide(1); $("#nona").show(1); }
	}
}

function setSNCounty(form) {
	if (form.sNCountry[0].checked) {form.sNState1.disabled = false; form.sNState2.disabled = true;  form.sNState3.disabled = true};
	if (form.sNCountry[1].checked) {form.sNState1.disabled = true;  form.sNState2.disabled = false; form.sNState3.disabled = true};
	if (form.sNCountry[2].checked) {form.sNState1.disabled = true;  form.sNState2.disabled = true; form.sNState3.disabled = false};	
}

function checkEnrollAddress(s,f,n) {
	if(f == 1) {
		var dAddress = $('#eForm input[name=eAdultAddress1]').val();
		var dCity = $('#eForm input[name=eAdultCity1]').val();
		var dState = $('#eForm input[name=eAdultState1]').val();
		var dZip = $('#eForm input[name=eAdultZip1]').val();
		var dPhone = $('#eForm input[name=eAdultPhone1]').val();
	} else {
		var dAddress = $('#eForm input[name=eChildAddress1]').val();
		var dCity = $('#eForm input[name=eChildCity1]').val();
		var dState = $('#eForm input[name=eChildState1]').val();
		var dZip = $('#eForm input[name=eChildZip1]').val();
		var dPhone = $('#eForm input[name=eChildPhone1]').val();
	}
	
	if(s == 'a') {
		$('#eForm input[name=eAdultAddress'+n+']').val(dAddress);
		$('#eForm input[name=eAdultCity'+n+']').val(dCity);
		$('#eForm input[name=eAdultState'+n+']').val(dState);
		$('#eForm input[name=eAdultZip'+n+']').val(dZip);
		$('#eForm input[name=eAdultPhone'+n+']').val(dPhone);
	}
	if(s == 'c') {
		$('#eForm input[name=eChildAddress'+n+']').val(dAddress);
		$('#eForm input[name=eChildCity'+n+']').val(dCity);
		$('#eForm input[name=eChildState'+n+']').val(dState);
		$('#eForm input[name=eChildZip'+n+']').val(dZip);
		$('#eForm input[name=eChildPhone'+n+']').val(dPhone);
	}
	
	if(s == 'p') {
		$('#eForm input[name=eParentAddress]').val(dAddress);
		$('#eForm input[name=eParentCity]').val(dCity);
		$('#eForm input[name=eParentState]').val(dState);
		$('#eForm input[name=eParentZip]').val(dZip);
		$('#eForm input[name=eParentPhone]').val(dPhone);
	}
}

// mini jQuery plugin that formats to two decimal places
    (function($) {
        $.fn.currencyFormat = function() {
            this.each( function( i ) {
                    if( isNaN( parseFloat( this.value ) ) ) return;
                    this.value = parseFloat(this.value).toFixed(2);
            });
            return this; //for chaining
        }
    })( jQuery );
	
function callFailFunction() {
	//alert("oops!");	
}

function changeDate(x) {
	var datesArray = new Array();
	datesArray = x.split(",");
	$('#calendar').fullCalendar('gotoDate',datesArray[0],datesArray[1],datesArray[2]);	
}

$(document).ready(function(){
	
	$(".eventsNav:first").tabs("#eventPanes:first > .ep", { effect: 'fade', fadeOutSpeed: "slow", rotate: true, onBeforeClick: function(event, i) { $("#bbrTwo, #bblTwo").animate({ height: $("#bbrTwo div .ep").eq(i).height() + "px" }) } }).slideshow({ autoplay: true, interval: 6000, clickable: false });
		
	$(".pubsNav:first").tabs("#pubsPanes:first > .pp", { effect: 'fade', fadeOutSpeed: "slow", rotate: true }).slideshow({ autoplay: true, interval: 6000, clickable: false });

	if(thisPage  == "index" || thisPage  == "index2" || thisPage == '') {
		Nifty("div#bblOne,div#bbrOne", "none same-height");
		Nifty("div#bblTwo,div#bbrTwo", "none same-height");
		Nifty("div#bblThree,div#bbrThree", "none same-height");
		$(".newsNav:first").tabs("#newsPanes:first > .np", { effect: 'fade', fadeOutSpeed: "slow" }).slideshow({ autoplay: false, next: "#newsNext", prev: "#newsPrev", clickable: false });
		
		$(".vzNav:first").tabs("#vzPanes:first > .vzp", { effect: 'fade', fadeOutSpeed: "slow" }).slideshow({ autoplay: false, next: "#vzNext", prev: "#vzPrev", clickable: false });
		
	}
	if(thisPage == "listen-to-a-worship-service") {
		setTimeout("initialize()",500);
	}
	
	if(thisPage == "member-congregations") {
		setTimeout("initialize()",500);
	}
	
	if(thisPage == "locations") {
		setTimeout("initialize()",500);
	}

	if(thisPage == "contact-us") {
		setTimeout("initialize()",500);
		//Nifty("div.sbLeft,div.sbRight","none same-height");

		var tabContainers = $(".sRight > div");
		tabContainers.hide().filter(':first').show();
			
		var tabs = $(".sLeft > ul a");
			
		tabs.click(function () {
			tabContainers.hide();
			tabContainers.filter(this.hash).fadeIn("slow");
			tabs.removeClass('current');
			$(this).addClass('current');
			return false;
		});

	}
	
	if(thisPage == "enroll-in-a-camp") {
		$("#campAdults").click(function(){
			// Select input field contents
			this.focus();
			this.select();
		});	
		
		$("#campChildren").click(function(){
			// Select input field contents
			this.focus();
			this.select();
		});
		
		$("#eForm").validationEngine({
			openDebug: false,
			success : false,
			promptPosition: "centerRight",
			beforeSuccess :  function() {  },
			failure : function() { callFailFunction()  }
		})
		
	}
	
	if(thisPage == "application-for-camp-work") {
		$("#campAdults").click(function(){
			// Select input field contents
			this.focus();
			this.select();
		});	
		
		$("#campChildren").click(function(){
			// Select input field contents
			this.focus();
			this.select();
		});
		
		$("#aForm").validationEngine({
			openDebug: false,
			success : false,
			promptPosition: "centerRight",
			beforeSuccess :  function() {  },
			failure : function() { callFailFunction()  }
		})
		
	}
	
	if(thisPage == "calendar-of-events") {
		$('#calendar').fullCalendar({
				header: {
				left: 'prev,next today',
				center: 'title',
				right: 'month,agendaWeek,agendaDay'
				},
				editable: false,
				
				events: "getEvents.cfm",
				
				eventRender: function(event, element) {
					if(event.url != undefined) {
						element.colorbox({iframe:true, innerWidth:550, innerHeight:550, href:event.url});
					}
				},
				
				loading: function(bool) {
					if (bool) {
						$('#loading').show();
					} else {
						$('#fsbLeft').css({'height' : ''});
						$('#fsbRight').css({'height' : ''});
						Nifty("div#fsbLeft,div#fsbRight", "none same-height");
						//Nifty("div#fccFrameLeft,div#fccCenterBody,div#fccFrameRight", "none same-height");
						$('#loading').hide();
					}
				}
				
		});
		
	}
	
	if (thisPage == "subscriptions-new" || thisPage == "submit-subscription-new" || thisPage == "subscription-price-list") {
		// initialize tooltip
		$(".titleTip[title]").tooltip({
		
		   // tweak the position
		   offset: [1, -19],
		   position: "center right"
		  // effect: 'fade'
		
		// add dynamic plugin with optional configuration for bottom edge
		});
		//.dynamic({ right: { direction: 'right', bounce: true } })
	}
	
	if(thisPage == "mobile-hymnal-instructions" || thisPage == "submit-mobile-hymnal-order" || thisPage == "make-a-charitable-contribution" || thisPage == "submit-a-charitable-contribution" || thisPage == "change-of-address" || thisPage == "subscriptions-renewal" || thisPage == "submit-subscription-renewal" || thisPage == "subscriptions-new" || thisPage == "submit-subscription-new" || thisPage == "make-a-payment" || thisPage == "submit-a-payment" || thisPage == "voice-of-zion-announcements" || thisPage == "submit-an-announcement") {
		if(formCheck) {
		if(!ie7) {
			Nifty("ul#status li", "transparent");
		}
		
		var root = $("#orderForm").scrollable();
		
		// some variables that we need
		var api = root.scrollable(), drawer = $("#drawer");
		
		// validation logic is done inside the onBeforeSeek callback
		api.onBeforeSeek(function(event, i) {
		
			// we are going 1 step backwards so no need for validation
			if (api.getIndex() < i) {
		
				// 1. get current page
				var page = root.find(".page").eq(api.getIndex()),
		
					 // 2. .. and all required fields inside the page
					 inputs = page.find(".required :input").removeClass("error"),
		
					 // 3. .. which are empty
					 empty = inputs.filter(function() {
						return $(this).val().replace(/\s*/g, '') == '';
					 });
		
				 // if there are empty fields, then
				if (empty.length) {
		
					// slide down the drawer
					drawer.slideDown(function()  {
		
						// colored flash effect
						drawer.css("backgroundColor", "#900");
						setTimeout(function() { drawer.css("backgroundColor", "#fff"); }, 1000);
					});
		
					// add a CSS class name "error" for empty & required fields
					empty.addClass("error");
		
					// cancel seeking of the scrollable by returning false
					return false;
		
				// everything is good
				} else {
		
					// hide the drawer
					drawer.slideUp();
				}
		
			}
		
			// update status bar
			$("#status li").removeClass("active").eq(i).addClass("active");
		
		});
		
		
		
		// if tab is pressed on the next button seek to next page
		root.find("button.next").keydown(function(e) {
			if (e.keyCode == 9) {
		
				// seeks to next tab by executing our validation routine
				api.next();
				e.preventDefault();
			}
		});
		}
		
		if(thisPage == "voice-of-zion-announcements" || thisPage == "submit-an-announcement") {
			$(".sampleWindow").colorbox();
		}
		
	}

	
	ddsmoothmenu.init({
		mainmenuid: "mainNav", //menu DIV id
		orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
		classname: 'ddsmoothmenu', //class added to menu's outer DIV
		//customtheme: ["#1c5a80", "#18374a"],
		contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
	});
	
	
	
	Nifty("div#fsbLeft,div#fsbRight", "none same-height");
	Nifty("div.bnBlock", "none same-height");
	
	$(".newsWindow").colorbox({iframe:true, innerWidth:550, innerHeight:550});
	$(".subPWindow").colorbox({iframe:true, innerWidth:650, innerHeight:550});
	$(".listenWindow").colorbox({iframe:true, innerWidth:550, innerHeight:550});
	
	
});

