function checkIDNotBlank(theid, descr) {
	var theelement = document.getElementById(theid);
	if (theelement) if (theelement.value=="") {
		alert("You did not enter " + descr);
		theelement.focus();
		return false;
	}
	return true;
}

function formcheckLogin() {
    if (!checkIDNotBlank("name", "a user name")) return false;
    if (!checkIDNotBlank("password", "a password")) return false;
	return true;
}

function formcheckEmailLogin() {
    if (!checkIDNotBlank("maillogin", "an email address")) return false;
	
	var maillogin = document.getElementById("maillogin");
	if (maillogin.match(/^([a-zA-Z0-9_.-]+)@([a-zA-Z0-9_.-]+)\.([a-zA-Z]{2,4})$/)==null) {
		alert("The email address is not valid!");
		maillogin.focus();
		return false;
	}
	return true;
}

function formcheckSignUp() {
    if (!checkIDNotBlank("UserName", "a user name")) return false;
    if (!checkIDNotBlank("Password", "a password")) return false;
    if (!checkIDNotBlank("Email", "an email address")) return false;
    if (!checkIDNotBlank("SecurityCode", "the security code")) return false;

	var Password = document.getElementById("Password");
	if (Password) if (Password.value.length<5) {
		alert("The password is too short, it must be at least 5 characters.");
		Password.focus();
		return false;
	}
    
	var maillogin = document.getElementById("Email");
	if (maillogin) if (maillogin.match(/^([a-zA-Z0-9_.-]+)@([a-zA-Z0-9_.-]+)\.([a-zA-Z]{2,4})$/)==null) {
		alert("The email address is not valid!");
		maillogin.focus();
		return false;
	}
	return true;
}
function doOnLoaded() {
	//Run this if it is on the buy.php page otherwise ignore.
    var sPath = window.location.pathname;
    var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	if (sPage == "buy.php") {
		document.getElementById("standardrow").className = "selected";
		document.getElementById("customsubscription").disabled = true;
}
	return true;
}

function clickRadio(theItem) {
	document.getElementById("basicrow").className = "";
	document.getElementById("standardrow").className = "";
	document.getElementById("goldrow").className = "";
	document.getElementById("customrow").className = "";
//	document.getElementById("platinumrow").className = "";	
	
	if (theItem=="basicrow") {
		document.getElementById("basicrow").className= "selected";
		document.getElementById("customsubscription").disabled = true;
	} else if (theItem=="standardrow") {
		document.getElementById("standardrow").className = "selected";
		document.getElementById("customsubscription").disabled = true;
	} else if (theItem=="goldrow") {
		document.getElementById("goldrow").className = "selected";
		document.getElementById("customsubscription").disabled = true;
	} else if (theItem=="customrow") {
		document.getElementById("customrow").className = "selected";
		document.getElementById("customsubscription").disabled = false;
//	}else {
//		document.getElementById("platinumrow").className = "selected";
//		document.getElementById("customsubscription").disabled = "true";

	}
}

function onsubmitBuy() {
    if (document.getElementById("customrow").className=="selected") {
        document.getElementById("paymentAmount").value = document.getElementById("customsubscription").value;
    }
    //Probably is a more elegant way to do this...but just 3 so whatever.
    if (document.getElementById("basicrow").className=="selected") {
        document.getElementById("paymentAmount").value = document.getElementById("buybasic").value;
    }
    if (document.getElementById("standardrow").className=="selected") {
        document.getElementById("paymentAmount").value = document.getElementById("buystandard").value;
    }
    if (document.getElementById("goldrow").className=="selected") {
        document.getElementById("paymentAmount").value = document.getElementById("buygold").value;
    }
}

