function showSendToFriendBox() {
    if ($('#sendToFriendBox')) hideSendToFriendBox();

    $('body').prepend('<div id="sendToFriendBg"></div>');
	positionBox();

	$.ajax({
      url: "/ajax/send-to-friend-box.html",
      cache: false,
      success: function(html){
        document.getElementById('sendToFriendBg').onclick = hideSendToFriendBox;

        $('body').prepend('<div id="sendToFriendBox"><div id="sendToFriendBoxInner"></div></div>');
        $("#sendToFriendBoxInner").append(html);

	    $(window).bind("resize", positionBox);
	    $(window).bind("scroll", positionBox);
        positionBox();
        $("#sendToFriendBox").css('display', 'block');
      }
    });

    return false;
}
function showNewsletterSignupBox() {
    if ($('#sendToFriendBox')) hideSendToFriendBox();

    $('body').prepend('<div id="sendToFriendBg"></div>');
	positionBox();

	$.ajax({
      url: "/ajax/newsletter-signup.aspx",
      cache: false,
      success: function(html){
        document.getElementById('sendToFriendBg').onclick = hideSendToFriendBox;

        $('body').prepend('<div id="sendToFriendBox"><div id="newsletterSignupBoxInner"></div></div>');
        $("#newsletterSignupBoxInner").append(html);

	    $(window).bind("resize", positionBox);
	    $(window).bind("scroll", positionBox);
        positionBox();
        $("#sendToFriendBox").css('display', 'block');
      }
    });

    return false;
}

function showGivingBox() {
    window.open('https://web12.anaxanet.com/atnewlife-org/online-giving.php', 'Giving', 'status=0,toolbar=0,menubar=0,resizable=0,scrollbars=1,height=627,width=866');
    return false;


    if ($('#sendToFriendBox')) hideSendToFriendBox();

    $('body').prepend('<div id="sendToFriendBg"></div>');
	positionBox();

	document.getElementById('sendToFriendBg').onclick = hideSendToFriendBox;

	$('body').prepend('<div id="sendToFriendBox"><iframe src="/ajax/cc.html" frameborder="0" allowtransparency="true" style="background:transparent;border:0;width:393px;height:285px"></iframe></div>');

	$(window).bind("resize", positionBox);
	$(window).bind("scroll", positionBox);
	positionBox();
	$("#sendToFriendBox").css('display', 'block');

    return false;
}
function showPartnerBox() {
    if ($('#sendToFriendBox')) hideSendToFriendBox();

    $('body').prepend('<div id="sendToFriendBg"></div>');
	positionBox();

	document.getElementById('sendToFriendBg').onclick = hideSendToFriendBox;

	$('body').prepend('<div id="sendToFriendBox" style="width:850px;height:625px;"><a href="javascript:hideSendToFriendBox()"><img style="position:absolute;top:13px;right:13px;border:0;z-index:99" src="/images/iconX.png" alt="Close Window" title="Close Window" /></a><iframe src="/donations.aspx" frameborder="0" allowtransparency="true" style="background:transparent;border:0;width:850px;height:625px"></iframe></div>');

	$(window).bind("resize", positionBox);
	$(window).bind("scroll", positionBox);
	positionBox();
	$("#sendToFriendBox").css('display', 'block');

    return false;
}

function showMinistryBox(MinistriesID, MinistryEmail, action) {
    if ($('#sendToFriendBox')) hideSendToFriendBox();

    $('body').prepend('<div id="sendToFriendBg"></div>');
	positionBox();

	$.ajax({
      url: "/ajax/ministry-connect.aspx?MinistriesID=" + MinistriesID + "&MinistryEmail=" + MinistryEmail + "&action=" + action,
      cache: false,
      success: function(html){
        document.getElementById('sendToFriendBg').onclick = hideSendToFriendBox;

        $('body').prepend('<div id="sendToFriendBox"><div id="ministryBoxInner"></div></div>');
        $("#ministryBoxInner").append(html);

	    $(window).bind("resize", positionBox);
	    $(window).bind("scroll", positionBox);
        positionBox();
        $("#sendToFriendBox").css('display', 'block');
      }
    });

    return false;
}


function showMinistryContactBox(MinistriesID, MinistryEmail, action) {
    if ($('#sendToFriendBox')) hideSendToFriendBox();

    $('body').prepend('<div id="sendToFriendBg"></div>');
	positionBox();

	$.ajax({
      url: "/ajax/ministry-contact.aspx?MinistriesID=" + MinistriesID + "&MinistryEmail=" + MinistryEmail + "&action=" + action,
      cache: false,
      success: function(html){
        document.getElementById('sendToFriendBg').onclick = hideSendToFriendBox;

        $('body').prepend('<div id="sendToFriendBox"><div id="ministryContactBoxInner"></div></div>');
        $("#ministryContactBoxInner").append(html);

	    $(window).bind("resize", positionBox);
	    $(window).bind("scroll", positionBox);
        positionBox();
        $("#sendToFriendBox").css('display', 'block');
      }
    });

    return false;
}
function showEventContactBox(EventID, EventEmail) {
    if ($('#sendToFriendBox')) hideSendToFriendBox();

    $('body').prepend('<div id="sendToFriendBg"></div>');
	positionBox();

	$.ajax({
      url: "/ajax/events-contact.aspx?EventID=" + EventID + "&EventEmail=" + EventEmail,
      cache: false,
      success: function(html){
        document.getElementById('sendToFriendBg').onclick = hideSendToFriendBox;

        $('body').prepend('<div id="sendToFriendBox"><div id="eventContactBoxInner"></div></div>');
        $("#eventContactBoxInner").append(html);

	    $(window).bind("resize", positionBox);
	    $(window).bind("scroll", positionBox);
        positionBox();
        $("#sendToFriendBox").css('display', 'block');
      }
    });

    return false;
}

function showPrivacyPolicyBox() {
    if ($('#sendToFriendBox')) hideSendToFriendBox();

    $('body').prepend('<div id="sendToFriendBg"></div>');
	positionBox();

	$.ajax({
      url: "/ajax/privacy-policy.html",
      cache: false,
      success: function(html){
        document.getElementById('sendToFriendBg').onclick = hideSendToFriendBox;

        $('body').prepend('<div id="sendToFriendBox"><div id="privacyBoxInner"></div></div>');
        $("#privacyBoxInner").append(html);

	    $(window).bind("resize", positionBox);
	    $(window).bind("scroll", positionBox);
        positionBox();
        $("#sendToFriendBox").css('display', 'block');
      }
    });

    return false;
}

function showCalendarBox() {if ($('#sendToFriendBox')) hideSendToFriendBox();

    $('body').prepend('<div id="sendToFriendBg"></div>');
	positionBox();

	document.getElementById('sendToFriendBg').onclick = hideSendToFriendBox;

	$('body').prepend('<div id="sendToFriendBox"><div id="calendarBoxInner"><a href="javascript:hideSendToFriendBox()"><img style="position:absolute;top:-2px;right:-2px;border:0;z-index:99" src="/images/btnCloseWhite.png" alt="Close Window" title="Close Window" /></a><iframe src="http://www.google.com/calendar/embed?src=atnewlife%40gmail.com&ctz=America/New_York" style="border: 0" width="800" height="600" frameborder="0" scrolling="no"></iframe></div></div>');

	$(window).bind("resize", positionBox);
	$(window).bind("scroll", positionBox);
	positionBox();
	$("#sendToFriendBox").css('display', 'block');

    return false;
}
function showMapBox() {
    if ($('#sendToFriendBox')) hideSendToFriendBox();

    $('body').prepend('<div id="sendToFriendBg"></div>');
	positionBox();

	$.ajax({
      url: "/ajax/google-map.html",
      cache: false,
      success: function(html){
        document.getElementById('sendToFriendBg').onclick = hideSendToFriendBox;

        $('body').prepend('<div id="sendToFriendBox"><div id="mapBoxInner"></div></div>');
        $("#mapBoxInner").append(html);

	    $(window).bind("resize", positionBox);
	    $(window).bind("scroll", positionBox);
        positionBox();
        $("#sendToFriendBox").css('display', 'block');
		load(41.912539, -71.513541);
      }
    });

    return false;
}

function hideSendToFriendBox() {
    $('#sendToFriendBox').remove();
    $('#sendToFriendBg').remove();
	$(window).unbind("resize", positionBox);
	$(window).unbind("scroll", positionBox);
}
function visibleHeight() {
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        return window.innerHeight;
      } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        return document.documentElement.clientHeight;
      } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        return document.body.clientHeight;
      }
}
function scrollTop() {
    if (window.pageYOffset) {
        return window.pageYOffset;
    } else {
        return (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
    }
}
function positionBox() {
	if ($('#sendToFriendBg')) {
        $('#sendToFriendBg').css('height', document.documentElement.scrollHeight+"px");		
	}
    if ($('#sendToFriendBox')) {
        var w = self.innerWidth || document.body.clientWidth || (de&&de.clientWidth);
        $('#sendToFriendBox').css('top', (visibleHeight()/2- ($('#sendToFriendBox').height()/2) +scrollTop())+"px");
        $('#sendToFriendBox').css('left', (w/2- ($('#sendToFriendBox').width()/2) )+"px");
    }
}
function validEmail(str) {
    return (str.indexOf('@',1)!=-1 && str.indexOf('.',3)!=-1);
}
function validString(str) {
    return (str != '');
}

function sendEmailToFriend() {
    var name = document.getElementById('txtYourName').value;
    var email = document.getElementById('txtYourEmail').value;
    var friendName = document.getElementById('txtFriendName').value;
    var friendEmail = document.getElementById('txtFriendEmail').value;

    if (!validString(name)) {
        alert('Please enter your name'); return false;
    }
    if (!validEmail(email)) {
        alert('Please enter your email'); return false;
    }
    if (!validString(friendName)) {
        alert("Please enter your friend's name"); return false;
    }
    if (!validEmail(friendEmail)) {
        alert("Please enter your friend's email"); return false;
    }

    // send email
    $.post("/ajax/send-email-to-friend.aspx", { name: name, email: email, friendName: friendName, friendEmail: friendEmail, page: encodeURIComponent(document.location) } );

    hideSendToFriendBox();
    return false;
}

function signUpForNewsletter() {
    var firstName = document.getElementById('txtFirstName').value;
    var lastName = document.getElementById('txtLastName').value;
    var email = document.getElementById('txtEmail').value;

    if (!validString(firstName)) {
        alert('Please enter your first name'); return false;
    }
    if (!validString(lastName)) {
        alert('Please enter your last name'); return false;
    }
    if (!validEmail(email)) {
        alert('Please enter your email'); return false;
    }

    // send email
    $.post("/ajax/newsletter-signup.aspx", { FirstName: firstName, LastName: lastName, Email: email});

    hideSendToFriendBox();
    return false;
}

function sendEmailMinistry() {
	var FirstName = document.getElementById('FirstName').value;
	var LastName = document.getElementById('LastName').value;
    var City = document.getElementById('City').value;
    var Phone = document.getElementById('Phone').value;
    var Email = document.getElementById('Email').value;
    var MinistriesID = document.getElementById('MinistriesID').value;
    var MinistryEmail = document.getElementById('MinistryEmail').value;
	var Message = (document.getElementById('Message')) ? document.getElementById('Message').value : -1;

    if (!validString(FirstName)) {
        alert('Please enter your first name'); return false;
    }
    if (!validString(LastName)) {
        alert('Please enter your last name'); return false;
    }
    if (!validString(City)) {
        alert('Please enter your city'); return false;
    }
    if (!validString(Phone)) {
        alert('Please enter your phone number'); return false;
    }
    if (!validEmail(Email)) {
        alert("Please enter your email address"); return false;
    }
    if (Message != -1 && !validString(Message)) {
        alert("Please enter a message"); return false;
    }

    // send email
	if (Message != -1) {
		$.post("/ajax/ministry-contact.aspx", { sending: 1, FirstName: FirstName, LastName: LastName, City: City, Phone: Phone, Email: Email, MinistriesID: MinistriesID, MinistryEmail: MinistryEmail, Message: Message } );
	} else {
		$.post("/ajax/ministry-connect.aspx", { sending: 1, FirstName: FirstName, LastName: LastName, City: City, Phone: Phone, Email: Email, MinistriesID: MinistriesID, MinistryEmail: MinistryEmail } );
	}

    hideSendToFriendBox();
    return false;
}
function sendEmailEvent() {
	var FirstName = document.getElementById('FirstName').value;
	var LastName = document.getElementById('LastName').value;
    var City = document.getElementById('City').value;
    var Phone = document.getElementById('Phone').value;
    var Email = document.getElementById('Email').value;
    var EventID = document.getElementById('EventID').value;
    var EventEmail = document.getElementById('EventEmail').value;
	var Message = document.getElementById('Message').value;

    if (!validString(FirstName)) {
        alert('Please enter your first name'); return false;
    }
    if (!validString(LastName)) {
        alert('Please enter your last name'); return false;
    }
    if (!validString(City)) {
        alert('Please enter your city'); return false;
    }
    if (!validString(Phone)) {
        alert('Please enter your phone number'); return false;
    }
    if (!validEmail(Email)) {
        alert("Please enter your email address"); return false;
    }
    if (!validString(Message)) {
        alert("Please enter a message"); return false;
    }

    // send email
	$.post("/ajax/events-contact.aspx", { sending: 1, FirstName: FirstName, LastName: LastName, City: City, Phone: Phone, Email: Email, EventID: EventID, EventEmail: EventEmail, Message: Message } );

    hideSendToFriendBox();
    return false;
}

