/*

Author				: Tahseen Johnson
Date Created		: 04-Nov-2008

*/

function SubscribeMe(Action){

	    var AfterSubscribe = function(oXML) {			
		    var result = oXML.responseText;
		    regularCursor();
			alert (result);
			//prompt('',result);
	    }
	    var thepage = '/modules/newsletter/processsubscribe.asp';
	    if (validateSubscribe()){
			var data = "action="+ Action + "&" + fetchInputFormData('frmSubscribe');	
			hiddenSubmit(thepage,data, AfterSubscribe, 0, null, null,true);
	    }    
}


function edSubscribe(){

	    var AfterSubscribe = function(oXML) {			
		    var result = oXML.responseText;
		    regularCursor();
			//prompt('',result);
			alert (result);
	    }
	    var thepage = '/modules/newsletter/processsubscribe.asp';
	    if (validateSubscribe()){
			var lstSelected = document.getElementById("lstSelected");
			for(var i=0;i<lstSelected.options.length;i++)
			{
				lstSelected.options[i].selected = true;	
			}
			var data = "action=edit&" + fetchInputFormData('frmSubscribe');	
			hiddenSubmit(thepage,data, AfterSubscribe, 0, null, null,true);
			checkAction(46,199,2,null,false,null,false);	
	    }    
}

function UserStatus(Locked)
{
	var UserLocked = function(oXML) {			
		var result = oXML.responseText;
		regularCursor();
	}
	var thepage = '/modules/newsletter/processsubscribe.asp';
	var data = "action=UserStatus&UserID=" + document.getElementById("UserID").value + "&Locked="+ Locked;
	hiddenSubmit(thepage,data, UserLocked, 0, null, null,true);
}

function validateSubscribe(){
	
	var thereturn;
	thereturn = false;

	var GroupID = '';
	for(var i=0;i<document.frmSubscribe.chkGroup.length;i++)
	{
			if (document.frmSubscribe.chkGroup[i].checked == true)
			{
					GroupID = GroupID + document.frmSubscribe.chkGroup[i].value + '|';
			}
	}
	
	if (document.frmSubscribe.txtFName.value.trim() != "")
	{
		if (document.frmSubscribe.txtSurName.value.trim() != "")
		{
			if (document.frmSubscribe.txtEmail.value.trim() != "")
			{
				if(isValidEmail(document.frmSubscribe.txtEmail.value.trim()))
				{
					if (GroupID != '')
					{		
						document.frmSubscribe.txtGroup.value = GroupID;
						thereturn = true;
					}
					else
					{
						alert ("Please enter a valid Group before continuing");	
					}
				}
				else
				{
					alert ("Please enter a valid Email before continuing");
					document.frmSubscribe.txtEmail.focus();
				}
			}
			else
			{
				alert ("Please enter a valid Email before continuing");
				document.frmSubscribe.txtEmail.focus();
			}
		}
		else
		{
			alert ("Please enter a valid Surname before continuing");
			document.frmSubscribe.txtSurName.focus();
		}
	}
	else
	{
		alert ("Please enter a valid First Name before continuing");
		document.frmSubscribe.txtFName.focus();
	}
	
	if(document.frmSubscribe.txtNewPassword.value.trim() != document.frmSubscribe.txtConfirmPassword.value.trim())
	{
		alert('The password entered in New Password and Confirm Password needs to be the same');
		document.frmSubscribe.txtNewPassword.focus();
		thereturn = false;
	}
	
	return thereturn;
	
}

