/*****************************************************************

	blueCart E-Commerce 2007 - (c) 2007-2008 Bergan Blue, Australia
	THIS IS COMMERCIAL SOFTWARE. DO NOT COPY/USE/SELL.
	
	Filename			: ajax-store.js (JavaScript)
	File Version		: 1.00.00
	File Summary		: JavaScript Library to handle all Store related AJAX functions
	
	Developed by		: Jon Bergan <jbergan@berganblue.com.au>
	Creation Date		: 20 Aug 2008
	
	Modifications		: None
	
*****************************************************************/

function ajaxSendFriendEmail(prodid)
{
	var alertmsg = "You must complete all of the required fields before you can email this page to your friend!\n\nPlease complete the following fields:\n\n";
	var err = 0;

	if (document.getElementById('tafName').value == "")	{
		err = 1;
		alertmsg = alertmsg+"- Your Name\n";
	}

	if (document.getElementById('tafEmail').value == "")	{
		err = 1;
		alertmsg = alertmsg+"- Your Email Address\n";
	}

	if (document.getElementById('tafRecipient').value == "")	{
		err = 1;
		alertmsg = alertmsg+"- Your Friend's Email Address\n";
	}
	
	if (!checkEmailAddress(document.getElementById('tafEmail').value))
	{
		err = 1;
		alertmsg = alertmsg+"- Your Email Address is invalid\n";
	}

	if (!checkEmailAddress(document.getElementById('tafRecipient').value))
	{
		err = 1;
		alertmsg = alertmsg+"- Your Friend's Email Address is invalid\n";
	}

	if (err == 1)
	{
		alert(alertmsg);
	} else {
		getContentFullCustom('taf-form', 'taf-loader', 'ajax.php?command=sendEmailToFriend&name='+document.getElementById('tafName').value+'&email='+document.getElementById('tafEmail').value+'&recipient='+document.getElementById('tafRecipient').value+'&prodid='+prodid, '<div style="text-align: center; margin: 20px 0 0 0;"><img src="'+bluecartPublicRoot+'templates/images/bluecart-large-ajax-loader.gif" alt="Loading"><p>Please wait - sending message</p></div>');
	}
	
	return false;
}

function ajaxCheckDeliveryDate()
{
	var dateString = document.getElementById('orderRequestedDeliveryDate').value;

    var now = new Date();
    var today = new Date(now.getFullYear(),now.getMonth(),now.getDate());
    var century = parseInt(now.getYear()/100)*100;
        
    var date = new Date(dateString.substring(6,10),
                        (dateString.substring(3,5)-1),
						dateString.substring(0,2));

	if (date < today)
	{
		alert ("Error:\n\nYour requested delivery date cannot be in the past!\n\nPlease choose today's date or a date in the future.\n\n\n");
		document.getElementById('orderRequestedDeliveryDate').value = "";
	}
}

function ajaxCheckUsername()
{
	var username = document.getElementById('username').value;
	
	updateAjaxPanel('ajaxCheck1', bluecartPublicRoot+'users.php?command=ajaxCheckUsername&username='+username);
}

function ajaxCheckEmailAddress()
{
	var emailaddr = document.getElementById('emailAddress').value;
	
	updateAjaxPanel('ajaxCheck2', bluecartPublicRoot+'users.php?command=ajaxCheckEmailAddress&email='+emailaddr);
}

function ajaxCheckEmailForExistingUser()
{
	var emailaddr = document.getElementById('emailAddress').value;
	
	updateAjaxPanel('ajaxCheck2', bluecartPublicRoot+'users.php?command=ajaxCheckEmailForExistingUser&email='+emailaddr);
}

function openTellAFriend() 
{
	if (document.getElementById('tell-a-friend-wrap'))
	{
		new Effect.Appear('tell-a-friend-wrap', { duration:0.5});
		new Effect.Appear('tell-a-friend-title', { duration:0.5});
		new Effect.Appear('product-image', { duration:0.5});
		new Effect.Appear('product-content', { duration:0.5});
		new Effect.Appear('taf-form', { duration:2.0});
	}
}

function closeTellAFriend() 
{
	if (document.getElementById('tell-a-friend-wrap'))
	{
		new Effect.Fade('tell-a-friend-wrap', { duration:0.5});
		new Effect.Fade('tell-a-friend-title', { duration:0.5});
		new Effect.Fade('product-image', { duration:0.5});
		new Effect.Fade('product-content', { duration:0.5});
		new Effect.Fade('taf-form', { duration:0.5});
	}
}

