/*
*******************************************************************************************
change ID	:	WI_2.3_UserStats
Date		:	03-26-2004
Author		:	PrioritySupport
Comments	:	New Mailing function
*******************************************************************************************
*/

  			  function isEmail(email)
				{
					var emailPattern = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
					return emailPattern.test(email);
				}

			  function SplitEmail(frmName,objName)
			    {
			    	var CheckMail=1;
					var arrToEmail=document[frmName][objName].value.split(",")
					for(i=0;i<arrToEmail.length;i++)
						{
						 if(!isEmail(arrToEmail[i]))
							 {
								 CheckMail=0;
								 break;
							 }
						}
					if(CheckMail==0)
					  {
						alert('Enter a valid email address/es in the '+objName+' box');
						document[frmName][objName].focus()
						return false
					  }
					else
						return true
			    }
			function SplitEmail1(frmName,objName)
						    {
						    	var CheckMail1=1;
								var arrToEmail1=document[frmName][objName].value.split(",")
								for(i=0;i<arrToEmail1.length;i++)
									{
									 if(!isEmail(arrToEmail1[i]))
										 {
											 CheckMail1=0;
											 break;
										 }
									}
								if(CheckMail1==0)
								  {
									//alert('Enter a valid email address/es in the '+objName+' box');
									document[frmName][objName].focus()
									return false
								  }
								else
									return true
						    }

			function doAdminSubmit(Action,Url)
			{
				if(Action=="Cancel")
				{
					document.frmEmailContent.action=Url;
					document.frmEmailContent.submit();
				}
				else
				{
					var Len;
					Len=document.frmEmailContent.Message.value
					if (Len.length>2000)
					{
						alert("Do not insert more than 2000 characters")
						document.frmEmailContent.Message.focus();
						return false;
					}
					if ((document.frmEmailContent.From.value!="") && (document.frmEmailContent.To.value!="") && (document.frmEmailContent.Bcc.value!=""))
					{
						if (!isEmail(document.frmEmailContent.From.value))
						{
							alert("Enter a valid email address in the From box");
							document.frmEmailContent.From.focus();
							return false;
						}	
						else
						{
							if (!isEmail(document.frmEmailContent.From.value))
							{
								alert("Enter a valid email address in the From box\nEnter a valid email address/es in the To box\nEnter a valid email address/es in the Bcc box");
								ChMail1=SplitEmail1('frmEmailContent','To')
								ChMail1=SplitEmail1('frmEmailContent','Bcc')
								document.frmEmailContent.From.focus();
								return false;
							}
						}
						
					}
					if(document.frmEmailContent.From.value=="")
					{
						alert('From Email should not be Empty')
						document.frmEmailContent.From.focus();
						return false;
					}
					else
					{
						if(!isEmail(document.frmEmailContent.From.value))
						{
							alert('Enter a valid email address in the From box')
							document.frmEmailContent.From.focus();
							return false;
						}
					    else
					    {
							var ChMail;
							if(document.frmEmailContent.To.value!="")
								ChMail=SplitEmail('frmEmailContent','To')
							if(ChMail)
							{
								if(document.frmEmailContent.Bcc.value!="")
									ChMail=SplitEmail('frmEmailContent','Bcc')
							}
							if(ChMail)
							{
								document.frmEmailContent.action=Url;
								document.frmEmailContent.submit();
							}

					    }
				    }
				    if(document.frmEmailContent.To.value=="")
					{
						alert('TO Email should not be Empty')
						document.frmEmailContent.To.focus();
						return false;
					}
    			 }
    		}

