/* Script to validate the English version of the send greeting card page */
<!-- ImageReady Preload Script -->

function Validate()
{
	missinginfo   = "";

	if (document.greetingcardform.sender_name.value == "")
	{
		missinginfo += "\n     -  Sender's Name";
	}

	str1 = document.greetingcardform.sender_email.value;

	if (document.greetingcardform.sender_email.value == "")
	{
		missinginfo += "\n     -  Sender's Email Address";
	}
	else
	{
        var at   = "@"
        var dot  = "."
        var lat  = str1.indexOf(at)
        var lstr = str1.length
        var ldot = str1.indexOf(dot)

        if (str1.indexOf(at) == -1)
		    missinginfo += "\n     -  Sender's Email Address (Invalid)";
        else if (str1.indexOf(at) == -1 || str1.indexOf(at) == 0 || str1.indexOf(at) == lstr)
		    missinginfo += "\n     -  Sender's Email Address (Invalid)";
        else if (str1.indexOf(dot) == -1 || str1.indexOf(dot) == 0 || str1.indexOf(dot) == lstr)
		    missinginfo += "\n     -  Sender's Email Address (Invalid)";
        else if (str1.indexOf(at, (lat + 1)) != -1)
		    missinginfo += "\n     -  Sender's Email Address (Invalid)";
        else if (str1.substring(lat - 1, lat) == dot || str1.substring(lat + 1, lat + 2) == dot)
		    missinginfo += "\n     -  Sender's Email Address (Invalid)";
        else if (str1.indexOf(dot, (lat + 2)) == -1)
		    missinginfo += "\n     -  Sender's Email Address (Invalid)";
        else if (str1.indexOf(" ") != -1)
		    missinginfo += "\n     -  Sender's Email Address (Invalid)";
    }

	if (document.greetingcardform.recipient_name.value == "")
	{
		missinginfo += "\n     -  Recipient's Name";
	}

	str2 = document.greetingcardform.recipient_email.value;

	if (document.greetingcardform.recipient_email.value == "")
	{
		missinginfo += "\n     -  Recipient's Email Address";
	}
	else
	{
        var at   = "@"
        var dot  = "."
        var lat  = str2.indexOf(at)
        var lstr = str2.length
        var ldot = str2.indexOf(dot)

        if (str2.indexOf(at) == -1)
		    missinginfo += "\n     -  Recipient's Email Address (Invalid)";
        else if (str2.indexOf(at) == -1 || str2.indexOf(at) == 0 || str2.indexOf(at) == lstr)
		    missinginfo += "\n     -  Recipient's Email Address (Invalid)";
        else if (str2.indexOf(dot) == -1 || str2.indexOf(dot) == 0 || str2.indexOf(dot) == lstr)
		    missinginfo += "\n     -  Recipient's Email Address (Invalid)";
        else if (str2.indexOf(at, (lat + 1)) != -1)
		    missinginfo += "\n     -  Recipient's Email Address (Invalid)";
        else if (str2.substring(lat - 1, lat) == dot || str2.substring(lat + 1, lat + 2) == dot)
		    missinginfo += "\n     -  Recipient's Email Address (Invalid)";
        else if (str2.indexOf(dot, (lat + 2)) == -1)
		    missinginfo += "\n     -  Recipient's Email Address (Invalid)";
        else if (str2.indexOf(" ") != -1)
		    missinginfo += "\n     -  Recipient's Email Address (Invalid)";
    }

	if (document.greetingcardform.sender_message.value == "")
	{
		missinginfo += "\n     -  Message";
	}

	if (missinginfo != "")
	{
		missinginfo =
			"The following fields must be filled out or corrected:\n"
			+ missinginfo
			+ "\nPlease enter the missing information and submit again!";

		alert(missinginfo);

		return false;
	}
	else
		return true;
}

<!-- End Preload Script -->
