// JavaScript Document

function CheckEmail (theStr) 
{
	var atIndex = theStr.indexOf('@');
	var dotIndex = theStr.indexOf('.', atIndex);
	var flag = true;
	theSub = theStr.substring(0, dotIndex+1)
	
	if ((atIndex < 1)||(atIndex != theStr.lastIndexOf('@'))||(dotIndex < atIndex + 2)||(theStr.length <= theSub.length)) 
	{
		flag = true;
	}
	else
	{
		flag = false; 
	}
	return(flag);
}

function goto(pageno)
{
	document.frm1.extRec.value=pageno;
	document.frm1.submit();
	
}

function DownloadNSL(nslID)
{
	
	var url="downloadnewsletter.asp?nslID="+nslID;
	window.open(url,'n','scrollbars=1,toolbar=no,status=no,width=430, height=350');
}

function get_radio_value()
{
	var rad_val="Both"
	for (var i=0; i < document.frm.txtRcvNSLBy.length; i++)
	{
		if (document.frm.txtRcvNSLBy[i].checked)
		{
			rad_val = document.frm.txtRcvNSLBy[i].value;
		 }
	}
	return rad_val;
}


function validatesubscriptionform ()
{
	var err=0;
	var errMsg="";
	if (document.frm.txtName.value=="")
	{
		alert ("Please enter your name.");
		err=1;
		document.frm.txtName.focus();
	}
	else if (document.frm.txtBName.value=="")
	{
		alert ("Please enter your bussiness name.");
		err=1;
		document.frm.txtBName.focus();
	}
	else if (get_radio_value()=="eMail")
	{
		if (CheckEmail(document.frm.txtEMail.value))
		{
			alert ("Please enter a valid email address.");
			err=1;
			document.frm.txtEMail.focus();
		}
	}
	else if (get_radio_value()=="Post")
	{
		if (document.frm.txtAddress.value=="")
		{
			alert ("Please enter your address.");
			err=1;
			document.frm.txtAddress.focus();
		}
		else if (document.frm.txtPostCode.value=="")
		{
			alert ("Please enter your Post Code.");
			err=1;
			document.frm.txtPostCode.focus();
		}
		else if (CheckEmail(document.frm.txtEMail.value))
		{
			alert ("Please enter a valid email address.");
			err=1;
			document.frm.txtEMail.focus();
		}
	}
	else if (get_radio_value()=="Both")
	{
		if (document.frm.txtAddress.value=="")
		{
			alert ("Please enter your address.");
			err=1;
			document.frm.txtAddress.focus();
		}
		else if (document.frm.txtPostCode.value=="")
		{
			alert ("Please enter your Post Code.");
			err=1;
			document.frm.txtPostCode.focus();
		}
		else if (CheckEmail(document.frm.txtEMail.value))
		{
			alert ("Please enter a valid email address.");
			err=1;
			document.frm.txtEMail.focus();
		}
	}
	//if (err==0)
	//{
	//	if (document.frm.checkbox3.checked==false)
	//	{
	//		alert ("Please accept the terms & condation first.");
	//		err=1;
	//	}
	//}
	
	if (err==0)
	{
		document.frm.action="subscription.asp?operation=sub";
		document.frm.submit();
	}
}

function validateloginform ()
{
	var err=0;
	var errMsg="";
	if (CheckEmail(document.frm.txtEmail.value))
	{
		alert ("Please enter a valid email address.");
		err=1;
		document.frm.txtEmail.focus();
	}

	if (err==0)
	{
		document.frm.action="loginform.asp";
		document.frm.submit();
	}
}

function validateunsubform ()
{
	var err=0;
	var errMsg="";
	if (CheckEmail(document.frm.txtEMail.value))
	{
		alert ("Please enter a valid email address.");
		err=1;
		document.frm.txtEMail.focus();
	}

	if (err==0)
	{
		document.frm.action="subscription.asp";
		document.frm.submit();
	}
}


