function ecardNext(sysID,actID,appID){
var controlIndex;
var element;
var msg = "";
var allerrors = "";

if (isRadioChecked(document.frmMain["C1"]) != true){
allerrors = "You must select an e-card template.";
alert(allerrors);
}
else{
document.frmMain.action = "ecard2.asp?sysID=" + sysID + "&actID=" + actID + "&appID=" + appID
document.frmMain.method = "post";
document.frmMain.submit();
}
}

function ecardSubmit(sysID,actID,appID,coupon){
var msg = "";
if (document.frmMain["empFName"].value == ""){
msg = msg + "You must enter an employee first name.\n"
}	
if (document.frmMain["empLName"].value == ""){
msg = msg + "You must enter an employee last name.\n"
}
if (validateEmail(document.frmMain["empEmail"].value) != true){
msg = msg + "Invalid employee email address:\n" + validateEmail(document.frmMain["empEmail"].value) + "\n\n";
}
if (document.frmMain["mgrName"].value == ""){
msg = msg + "You must enter your name.\n"
}
if (validateEmail(document.frmMain["mgrEmail"].value) != true){
msg = msg + "Invalid manager email address:\n" + validateEmail(document.frmMain["mgrEmail"].value) + "\n\n";
}
if ((document.frmMain["redeem"].value == "") & (coupon == "SO")){
msg = msg + "You must enter a customized coupon offer.\n"
} 
if (msg != ""){
  alert(msg);
}
else{
document.frmMain.action = "ecard3.asp?sysID=" + sysID + "&actID=" + actID + "&appID=" + appID + "&coupon=" + coupon
document.frmMain.method = "post";
document.frmMain.submit();
}

}

function ecardSend(sysID,actID,appID,coupon){
var userConfirm = confirm("Click OK if you are ready to send this coupon.");
if (userConfirm == true){
document.frmMain.action = "ecardSend.asp?sysID=" + sysID + "&actID=" + actID + "&appID=" + appID + "&coupon=" + coupon
document.frmMain.method = "post";
document.frmMain.submit();
}
else{

}

}

function isRadioChecked(radioObject) {
	var val = false;
	
	for (var i=0; i<radioObject.length; i++) {
		if (radioObject[i].checked) {
			val = true;
			return val;
			break;
		}
	}
	if (!val){
		return val;
	}
	return "";
}

function validateEmail(email) {
	// Script prepared by Answer Studios / ToUnite.com
	// Version 1.1 (Feb. 1, 2001)
	// Logic:
	// 8 steps: Preset elements, 6 error checks, write error (if appicable)
	
	// --- Presets
	var count = 0;
	var error = "";
	
	// #1 Check if email address field is blank
	
		if (email == "") {
			error = "You must enter your email address.\n";
		}

	
	// #1 Check for invalid characters
	// Create an arroay of invalid characters
	if (error == "") {
	var invChars = new Array(" ", "#", "$", "%", "!", "^", "~", "'", "*", "(", ")", ",", "<", ">", "/", "\\");
	// Loop through Array and see if there are any matches, if yes then throw and error.
	for (var i = 0; i < invChars.length; i++) {
		if (email.indexOf(invChars[i]) >= 0) {
			error = error + "Invalid character found.\n";
		}
	}
	}
	// #2 If passed previous error step  >>> Check the @ symbol (1 instance of the symbol)
	if (error == "") {
		// Loop by character through the email string for the @ symbol, count the number of instances
		for (var i = 0; i < email.length; i++) {
			if (email.charAt(i) == "@") {
				count = count+1;
			}
		}
		// If there is not 1 instance (0 or more than 1) then throw an error.
		if (count != 1) {
			error = error + "Missing the @ symbol.\n";
		}
	}
	
	// Split the email string by the @ sign, forming the name portion and the domain portion.
	if (error == "") {
		var splitEmail = email.split("@");
		var emailName = splitEmail[0];
		var emailDom = splitEmail[1];
		// #3 Verify minimum characters in name portion (minimum of 1), if not throw an error.
		if (emailName.length<1) {
			error = error + "Problem with the email name.\n";
		}
		// #4 Verify there is a . (dot) in the domain portion
		if (emailDom.indexOf(".")<0) {
			error = error + "Missing the dot for the domain name.\n";
		} else {
			// #5 Verify a minimum of 2 characters before the dot, if not throw an error.
			// First split the domain portion by the . (dot)
			var splitDom = emailDom.split(".");
			if (splitDom[0].length<2) {
				error = error + "Problem with the domain name or domain name missing.\n";
			}
			// #6 Verify a minimum of 2 characters after the dot, if not throw an error.
			if (splitDom[1].length<2) {
				error = error + "Invalid domain name extension (.com).\n";
			}
		}
	}
	
	// Associate the error number into the message array for displaying results on the screen.
	
	if (error != ""){
	  emailerror = error
	}
	else{
	  emailerror = true
	}
	return emailerror

}
