function verifyListSignup()
{
	if (document.emaillistform.Email.value.length == 0)
	{
		alert("Email must be entered.");
		return;
	}
	
	document.emaillistform.submit();
}

function verifyAddAct()
{
	if (document.addact.name.value.length == 0)
	{
		alert ("name must be specified");
		return false;
	}
	if (document.addact.description.value.length == 0)
	{
		alert ("description must be specified");
		return false;
	}

	document.addact.submit();
}

function verifyUpdateAct()
{
	for (i = 0; i < document.updateact.length; i++)
	{
		if (document.updateact[i].type == "text" || document.updateact[i].type == "textarea")
		{
			if (document.updateact[i].name.indexOf("name") == 0 && document.updateact[i].value.length == 0)
			{
				alert ("name must be specified");
				return;
			}
			if (document.updateact[i].name.indexOf("description") == 0 && document.updateact[i].value.length == 0)
			{
				alert ("description must be specified");
				return;
			}
		}
	}

	document.updateact.submit();
}

function verifyPromoCode(promocode, amount)
{
	if (!document.ticketform.promocode.disabled)
	{
		//decrypt the promo code
		promocode = encrypt_decrypt(promocode);
	
		if (document.ticketform.promocode.value)
		{
			if (document.ticketform.promocode.value == promocode)
			{
				alert("Valid code - the price has been adjusted from $" + document.ticketform.amount.value + " to $" + amount);
				document.ticketform.amount.value = amount;
			}
			else
			{
				alert("That is not a valid promo code - no promotion will be applied to the price.");
			}
		}
	}
}

//this function is a javascript replica of its php counterpart
function encrypt_decrypt(str)
{
    $len = str.length;
    $str_encrypted = "";
    for ($pos = 0; $pos < $len; $pos++)
	{
        $key = (($len + $pos) + 1);
        $key = (255 + $key) % 255;
        $ascii = str.charCodeAt($pos);
        $xored_byte = $ascii ^ $key;
        $encrypted_byte = String.fromCharCode($xored_byte);
        $str_encrypted = $str_encrypted + $encrypted_byte;
    }
	
    return $str_encrypted;
}
