// JavaScript Document
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
  {
  xhttp=new XMLHttpRequest();
  }
else
  {
  xhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xhttp.open("GET",dname,false);
xhttp.send("");
return xhttp.responseXML;
};
function getQueryVariable(variable) {
 	var query = window.location.search.substring(1);
 	var vars = query.split("&");
 	for (var i=0;i<vars.length;i++) {
   		var pair = vars[i].split("=");
   		if (pair[0] == variable) {
   			return pair[1];
  		}
 	}
};
function getXMLPath(IRS) {
	if (IRS == false) {
		var dataType = "&type=0";
	} else {
		var dataType = "&type=1";
	}
	var orgId = getQueryVariable("orgId");
	xmlPath = "/components/custom.ashx?handler=LoneStarWeb.OrganizationFinancialSummaryListHandler,Blackbaud.LoneStar.LoneStarWeb&orgId=" + orgId + dataType;
	
	return xmlPath
};
function getXml(transform,IRS)
{
xmlPath=getXMLPath(IRS)
xml=loadXMLDoc(xmlPath);
xsl=loadXMLDoc(transform);
// code for IE
if (window.ActiveXObject)
  {
  var xmlDoc = xml.transformNode(xsl);
  }
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
  {
  xsltProcessor=new XSLTProcessor();
  xsltProcessor.importStylesheet(xsl);
  var orgData = xsltProcessor.transformToDocument(xml);
  var xmlDoc = (new XMLSerializer()).serializeToString(orgData);
  }  
return xmlDoc;
};
function helpPopup(contents, closeable) {
	if (closeable == true) {
	contents = '<a id="helpPopClose"><img src="images/closeX_16x16.png" alt="close" /></a>' + contents;
	};
	$('div#helpPopInner').html(contents);
	$('div#helpPopWrap').show();
	$('a#helpPopClose').click(function() {
		$('div#helpPopWrap').hide();
	});
};
function fixPositioning() {
	$('div[id *= "_panelPopup"]').appendTo('body');
	$('div[id *= "_designPaneCloak"]').css({"top": "0px","left": "0px"});
	$('.DesignPane').css("position", "relative");
	var numRand = Math.floor(Math.random()*2 + 1);
	$('div#wrapMedia').addClass('photo'+numRand);
};
function updateOrgName() {
	var orgName = $("span[id$='lblDesignationValue']").html();
	if (orgName) {
		$('span.LSOrgNameReplace').replaceWith(orgName);
		$('.LSOrgNameReplace').removeClass('LSOrgNameReplace');
	};
};
function donationFix() {
	$("select[id$='cboCardType'] > option:last").attr('selected', 'selected');
	$("select[id$='cboCardType']").parent().parent().hide();
	$("label[id$='lblPhone']").parent().parent().hide();
	$("label[id$='lblCountry']").parent().parent().hide();
	$("span[id$='lblDesignationValue']").parent().parent().hide();
	$("a.BBLinkHelpIcon").children().replaceWith("What is this?");
	$("a.BBLinkHelpIcon").removeAttr('href');
	$("label:contains('Frequency')").parent().siblings(".DonationFieldControlCell").addClass("FrequencyFieldControlCell");
	$("label:contains('Frequency')").parent().siblings(".DonationFieldControlCell").find("select").after(" <a class='recurringHelpLink'>What is this?</a>");
	$("label:contains('Accept Terms')").parent().siblings(".DonationCaptureRequiredFieldMarker").remove();
	$("label:contains('Accept Terms')").parent().siblings(".taLeft").attr("colSpan", "2");
    $("label:contains('Anonymous')").parent().siblings(".taLeft").attr("colSpan", "2");
	$("table.DonationFormTable table.LoginFormCheckList label:contains('Terms of Service')").html("I have reviewed and agree to the <a href='https://www.visagiving.com/terms'>Terms of Service</a> and <a href='https://www.visagiving.com/privacy'>Privacy Policy</a> <span style='color:red;'>*</span>");
	$("div.DonationValidationSummary li:contains('Accept Terms')").html("You must review and agree to the Terms of Service and Privacy Policy.");
	$("div.DonationECardSectionBody input[style|='width: 95px;']").addClass("DonationTextboxNarrow");
	$("div.DonationECardSectionBody input[style|='width: 200px;']").addClass("DonationTextboxWide");
	$("select.DonationSelectList option:contains('Day 31 of every month')").html("Last day of every month");
	$("select.DonationSelectList option:contains('Day 31 of every three months')").html("Last day of every three months");
	$("span.frequency:contains('Day 31 of every month')").html("Last day of every month");
	$("span.frequency:contains('Day 31 of every three months')").html("Last day of every three months");
	$("td.DonationListingHeading input").parent("td.DonationListingHeading").removeClass("eCardChecked");
	$("td.DonationListingHeading input:checked").parent("td.DonationListingHeading").addClass("eCardChecked");
	var giftAmount = $("input[id$='txtAmount']").val();
	if (giftAmount) {
		var giftString = giftAmount.split('.', 1);
		if (giftString[0]) {
			$("input[id$='txtAmount']").val(giftString[0]);
		} else {
			$("input[id$='txtAmount']").val('0');
		};
	};
	$('a.BBLinkHelpIcon').click(function() {
		var contents = '<h2>What is this?</h2><p><img class="floatLeft" alt="Three digit code from back of Visa card." src="https://www.visagiving.com/view.image?Id=453" /></p><p>&nbsp;</p><p>The <strong>3-digit code</strong> appears only on the back of the card itself (not on receipts or statements), so it provides some assurance that the physical card is in your possession. This helps us reduce fraud.</p>'
		helpPopup(contents, true);
	});
	$('a.searchHelpLink').click(function() {
		var contents = '<h2>Trouble finding your charity?</h2><p>Try searching on parts of the charity name to broaden your results, or narrow down your search results further by selecting a combination of category and/or location.  To focus on charities with a specific interest area use the keyword or category search.   If you are still having trouble, it may be that your <a href="faq#charities7">charity is not registered on the site</a>.</p></p>However, there may still be a national branch of your charity that is affiliated with your favorite local charity, or perhaps you can find a similar charity in your neighborhood by searching charities by category in your zip code. With multiple ways to refine a search, you can likely find a charity that means a lot to you through which you can use your Visa card to donate.</p>'
		helpPopup(contents, true);
	});
	$('a.recurringHelpLink').click(function() {
		var contents = '<h2>Recurring Gifts</h2><p>Determine the frequency of your recurring gift.  Your recurring gift can be either <strong>Day 15 of every month</strong>, the <strong>Last day of every month</strong>, or the <strong>Last day of every three months</strong>.  Starting date will default to today&#39;s date, but the first recurring gift will occur based on your frequency choice.  For example:</p><ul><li>a recurring donation with a starting date of 12/15 and a frequency of <strong>Day 15 of every month</strong> will be processed on 12/15, 1/15, 2/15, 3/15, etc.</li><li>a recurring donation with a starting date of 12/28 and a frequency of <strong>Last day of every month</strong> will be processed on 12/31, 1/31/, 2/28, 3/31, etc.</li><li>a recurring donation with a starting  date of 12/5 and a frequency of <strong>Last day of every three months</strong> will be processed on 12/31, 3/31, 6/30, etc.</li></ul>'
		helpPopup(contents, true);
	});
	$("input[id$='txtAmount']").blur(function(e) {
		var giftAmount = $("input[id$='txtAmount']").attr('value');
		if (giftAmount) {
			giftString = giftAmount.split('.', 2);
			$("input[id$='txtAmount']").attr('value', giftString[0]);
			if (giftString[1]) {
				alert('Only whole dollar donations are allowed. Your donation amount has been rounded down.');
			};
		};
	});
	$('input.DonationSubmitButton').click(function() {
		var contents = '<h2><img align=right src="view.image?id=481" alt="Donation Processing" />Donation Processing</h2><p>You will receive a Thank You page after you press <em>DONATE NOW</em>. Do not hit the back button or press <em>DONATE NOW</em> again.</p><p>This message will disappear once your donation has finished processing or if any errors occured.</p>';
		helpPopup(contents, false);
	});
	$('a[target="_blank"]').click(function() {
		var pageURL = $(this).attr('href');
		var contents = '<h2>Leaving This Site</h2><p>You are now leaving this site. If you continue you will be directed to: ' + pageURL + '</p><p style="text-align:right;"><a href="' + pageURL + '" target="_blank">Continue and leave this site</a>.</p>';
		helpPopup(contents, true);
		return false;
	});
	$('#helpPopInner a').click(function() {
		return true;
	});
	$('table.GivingHistoryList span[id$="lblPayMethod"]').text('Visa Card');
};
function featuredCharity() {
	var featured = 0;
	var allCharities = $("ul.featuredCharity li");
	if ( allCharities.length >0 ) {
		$('ul.featuredCharity li').hover(function(){stopRotateCharity();},function(){rotateCharity();});
		$("ul.featuredIndicator").width(10 * allCharities.length);
		rotateIndicatior();
		rotateCharity();
	};
};
function rotateIndicatior() {
	var indicators = 1;
	var allCharities = $("ul.featuredCharity li");
	while (indicators < allCharities.length) {
		$("ul.featuredIndicator").append("<li></li>");
		indicators++;
	};
};
function rotateCharity() {
	var featured = 0;
	var allIndicators = $("ul.featuredIndicator li");
	var allCharities = $("ul.featuredCharity li");
	intervalID = window.setInterval(function() {
		$(allIndicators).removeClass('current');
		$("ul.featuredCharity li:visible").fadeOut(1000);
		featured++;
   		if (featured == allCharities.length) {
			featured = 0;
		}
		$(allCharities[featured]).fadeIn(1000);
		$(allIndicators[featured]).addClass('current');
	}, 15000);
};
function stopRotateCharity()
{
  clearInterval(intervalID);
};
function loadGraphs () {
	if ($('#summaryExtended').length > 0) { 
		var summaryExtended = new FusionCharts("Document.Doc?id=4", "summaryExtended", "200", "150");
		var summaryExtendedXML=getXml("Document.Doc?id=6", false);
		summaryExtended.setDataXML(summaryExtendedXML);
		summaryExtended.render("summaryExtended");
	};
	if ($('#expensesExtended').length > 0) {
		var expensesExtended = new FusionCharts("Document.Doc?id=4", "expensesExtended", "430", "250");
		var expensesExtendedXML=getXml("Document.Doc?id=3", false);
		expensesExtended.setDataXML(expensesExtendedXML);
		expensesExtended.render("expensesExtended");
	};
	if ($('#summaryIRS').length > 0) {
		var summaryIRS = new FusionCharts("Document.Doc?id=4", "summaryIRS", "200", "150");
		var summaryIRSXML=getXml("Document.Doc?id=6", true);
		summaryIRS.setDataXML(summaryIRSXML);
		summaryIRS.render("summaryIRS");
	};
	if ($('#expensesIRS').length > 0) {
		var expensesIRS = new FusionCharts("Document.Doc?id=4", "expensesIRS", "430", "250");
		var expensesIRSXML=getXml("Document.Doc?id=3", true);
		expensesIRS.setDataXML(expensesIRSXML);
		expensesIRS.render("expensesIRS");
	};
};
function pageSharing() {
	$("#ulShare li:contains('Facebook')").addClass("facebook");
	$("#ulShare li:contains('Email')").addClass("email");
	$("#ulShare").show();
};
function visaAll() {
	$('div#helpPopWrap').animate({fontSize: "1em"}, 500).fadeOut("fast");
	updateOrgName();
	if ($("table.DonationFormTable")) {
		donationFix();
	}
	fixPositioning();
	featuredCharity();
	loadGraphs();
	pageSharing();
};

Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(visaAll);

////////////////////////////////////////////
// End of script
if (typeof (Sys) !== 'undefined') {
    Sys.Application.notifyScriptLoaded();
};
////////////////////////////////////////////
// Do not add any code below this
////////////////////////////////////////////