﻿bgImage = new Image(1, 1);
bgImage.src = "/content/images/quick-links-drop-bg.png";

jQuery(document).ready(function() {

    var sitePath = location.protocol + '//' + location.hostname; // 'https://www.alliancedefensefund.org'
    //var sitePath = 'http://localhost:53407' // + location.hostname;
    jQuery('[rel]').prettyPhoto();
    jQuery('#go').click(function() {
        document.location.href = "/Search?terms=" + jQuery('#search').val();
    });

	// SUBMIT SEARCH FORM WHEN ENTER KEY IS PRESSED
    jQuery('#search').keyup(function(e) {
        if (e.keyCode == 13) {
            document.location.href = "/Search?terms=" + jQuery('#search').val();
        }
    });

	// SUBMIT EMAIL SIGN UP FORM WHEN ENTER KEY IS PRESSED
    jQuery('#emailAddress').keyup(function(e) {
        if (e.keyCode == 13) {
            document.location.href = "/SignUp?email=" + jQuery('#emailAddress').val();
        }
    });

    jQuery("#donateForm").submit(function() {
        //jQuery("#donateButton").attr("disabled", "true");
        jQuery.prettyPhoto.open("#donateProcessing");
        contentAjax = false;
        var frm = jQuery("#donateForm");
        var action = sitePath + frm.attr("action");
        var customReceipt = jQuery("#CustomReceipt").val();
        var serializedFrm = frm.serialize();
        //alert(action);
        jQuery.post(action, serializedFrm, function(data) {
            //alert(data);
            //alert(data.txId);
            jQuery.prettyPhoto.close("#donateProcessing");

            if (data.txId != null) {
                if (customReceipt != undefined) {
                    document.location.href = customReceipt + "?txid=" + data.txId;
                }
                else {
                    document.location.href = "/Donate/ThankYou";
                }
            }
            else {
                jQuery("#errorsBottom").html(data);
                jQuery.prettyPhoto.open("#errorsBottom");
                //jQuery("#donateButton").attr("disabled", "false");
            }
        });
        return false;
    });
	

    jQuery("#donateForm911").submit(function() {
		$.extend({
			getUrlVars: function() {
				var vars = [],
					hash;
				var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
				for (var i = 0; i < hashes.length; i++) {
					hash = hashes[i].split('=');
					vars.push(hash[0]);
					vars[hash[0]] = hash[1];
				}
				return vars;
			},
			getUrlVar: function(name) {
				return $.getUrlVars()[name];
			}
		});
		var byName = $.getUrlVar('referral');
		
		// Heads up, this is different:
		var URL = document.location.href.toLowerCase();
		if (URL.indexOf('referral') == -1) {
			if ( $('#amount').val() >= '25.00') {
				$("#sourcecode").val('I0911MCP');
			} else {
				$("#sourcecode").val('I0911MC');
			}
		} else {
			if ( $('#amount').val() >= '25.00') {
				$("#sourcecode").val(byName + 'P');
			} else {
				$("#sourcecode").val(byName);
			}
		}



        //jQuery("#donateButton").attr("disabled", "true");
        jQuery.prettyPhoto.open("#donateProcessing");
        contentAjax = false;
        var frm = jQuery("#donateForm911");
        var action = sitePath + frm.attr("action");
        var customReceipt = jQuery("#CustomReceipt").val();
        var serializedFrm = frm.serialize();
        //alert(action);
        jQuery.post(action, serializedFrm, function(data) {
            //alert(data);
            //alert(data.txId);
            jQuery.prettyPhoto.close("#donateProcessing");

            if (data.txId != null) {
                if (customReceipt != undefined) {
                    document.location.href = customReceipt + "?txid=" + data.txId;
                }
                else {
                    document.location.href = "/Donate/ThankYou";
                }
            }
            else {
                jQuery("#errorsBottom").html(data);
                jQuery.prettyPhoto.open("#errorsBottom");
                //jQuery("#donateButton").attr("disabled", "false");
            }
        });
        return false;
    });
    jQuery("#contactForm").submit(function() {
        jQuery.prettyPhoto.open("#donateProcessing");
        contentAjax = false;
        var frm = jQuery("#contactForm");

        var action = frm.attr("action");
        var serializedFrm = frm.serialize();
        jQuery.post(sitePath + action, serializedFrm, function(data) {
            jQuery.prettyPhoto.close("#donateProcessing");

            if (data.toString() == "") {

                document.location.href = "/Home/ContactThanks";
            }
            else {
                jQuery("#errorsBottom").html(data);
                jQuery.prettyPhoto.open("#errorsBottom");
            }
        });
        return false;
    });
    jQuery("#tellafriendForm").submit(function() {
        jQuery.prettyPhoto.open("#donateProcessing");
        contentAjax = false;
        var frm = jQuery("#tellafriendForm");
        var customLanding = jQuery("#CustomLanding").val();
        var action = frm.attr("action");
        var serializedFrm = frm.serialize();
        jQuery.post(sitePath + action, serializedFrm, function(data) {
            jQuery.prettyPhoto.close("#donateProcessing");
            if (data.toString() == "") {
                if (customLanding != undefined) {
                    document.location.href = customLanding;
                }
                else {
                    document.location.href = "/Home/TellAFriendThanks";
                }
            }
            else {
                jQuery("#errorsBottom").html(data);
                jQuery.prettyPhoto.open("#errorsBottom");
            }
        });
        return false;
    });

    jQuery("#signupForm").submit(function() {
        jQuery.prettyPhoto.open("#donateProcessing");
        contentAjax = false;
        var frm = jQuery("#signupForm");
        var customLanding = jQuery("#CustomLanding").val();
        var action = frm.attr("action");
        var serializedFrm = frm.serialize();
        jQuery.post(sitePath + action, serializedFrm, function(data) {
            jQuery.prettyPhoto.close("#donateProcessing");
            if (data.toString() == "") {
                if (customLanding != undefined) {
                    document.location.href = customLanding;
                }
                else {
                    document.location.href = "/Home/SignUpThanks";
                }
            }
            else {
                jQuery("#errorsBottom").html(data);
                jQuery.prettyPhoto.open("#errorsBottom");
            }
        });
        return false;
    });
    // GROUND ZERO CROSS FORM #1 - SIGN STATEMENT
    jQuery("#GroundZeroCross").submit(function() {
        contentAjax = false;
        var frm = jQuery("#GroundZeroCross");
        var action = frm.attr("action");
        var serializedFrm = frm.serialize();
        jQuery.post(sitePath + action, serializedFrm, function(data) {
            if (data.toString() == "") {
		jQuery('.formwrapper').hide("fast");
		jQuery('.thankyouwrapper').show("slow");
            }
            else {
                jQuery("#errorsBottom").html(data);
                jQuery.prettyPhoto.open("#errorsBottom");
            }
        });
        return false;
    });
    // GROUND ZERO CROSS #2 - REVISED PIN VERSION
    jQuery("#GroundZeroCross2").submit(function() {
        contentAjax = false;
        var frm = jQuery("#GroundZeroCross2");
        var action = frm.attr("action");
        var serializedFrm = frm.serialize();
        jQuery.post(sitePath + action, serializedFrm, function(data) {
            if (data.toString() == "") {
		jQuery('.formwrapper').hide("fast");
		jQuery('.thankyouwrapper').show("slow");
            }
            else {
                jQuery("#errorsBottom").html(data);
                jQuery.prettyPhoto.open("#errorsBottom");
            }
        });
        return false;
    });

    jQuery("#legalhelpForm").submit(function() {
        jQuery.prettyPhoto.open("#donateProcessing");
        contentAjax = false;
        var frm = jQuery("#legalhelpForm");
        var action = frm.attr("action");
        var serializedFrm = frm.serialize();
        jQuery.post(sitePath + action, serializedFrm, function(data) {
            jQuery.prettyPhoto.close("#donateProcessing");
            if (data.toString() == "") {
                document.location.href = "/LegalHelp/Thanks";
            }
            else {
                jQuery("#errorsBottom").html(data);
                jQuery.prettyPhoto.open("#errorsBottom");
            }
        });
        return false;
    });
});

	


function EnableRecurring(value) {
    var elem = document.getElementById("recurringDate");

    if (elem != null) {

        if (elem.style.display == "none")
            elem.style.display = "inline";
        else
            elem.style.display = "none";

    }
}

