MailingList={};
MailingList.initialize=function()
{
}
MailingList.findEmailAddresses=function(StrObj,userid) 
{
   if(StrObj!='')
   {
	var separateEmailsBy = ';';
	var email = '<none>'; // if no match, use this
	var emailsArray = StrObj.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi);if (emailsArray) {
		email = '';for (var i = 0; i < emailsArray.length; i++) {if (i != 0) email += separateEmailsBy;
		email += emailsArray[i];      }
   		}
	
	var url="/phpclasses/serviceConnector.php?object=MailingListManager&method=scourEmails&params="+ userid +";"+ email;
	AjaxUpdater.Update("GET",url,MailingList.onScourEmails);
   }
}
MailingList.onScourEmails=function()
{
   if(Ajax.checkReadyState('loading')=="200")
   {
      var response=Ajax.getResponse();
      if(!response.match("ERROR"))
      {
         Utilities.getElement('emaildiv').innerHTML=response;
      }
      else Utilities.getElement('emaildiv').innerHTML="<table width=100% cellspacing=2 cellpadding=2><tr align=center><td><br><br>"+ response +"<br><br></td></tr></table>";
   }
   else
   {
      Utilities.getElement('emaildiv').innerHTML="<table width=100% cellspacing=2 cellpadding=2><tr align=center><td><br><br><img src=\"http://californiaoutdoorproperties.com/images/pleasewait.gif\" border=0></td></tr></table>";
   }
}
MailingList.join=function(first,last,email,address1,address2,city,state,zip,emailblasts,catalogs)
{
   if(emailblasts) emailblasts='x';
   else emailblasts='x';
   if(catalogs) catalogs='x';
   else catalogs='';
   if(first=='' || last=='' || (emailblasts=='x' && email=='') || (catalogs=='x' && (address1=='' || city=='' || state=='' || zip=='')))
   {
      var html=Utilities.getElement('maildivfull').innerHTML;
      if(!html.match("If you are not interested"))
         html=html.replace("<b>We respect your privacy and will not share your information.</b>","<b>We respect your privacy and will not share your information.</b></td></tr><tr align=left><td colspan=2><font style=\"color:#600000;\">Please enter your full name.  Also make sure to enter your e-mail address to receive e-mails and your <i>full</i> address to receive catalogs.  If you are not interested in joining our mailing list, please click \"Cancel\".</font>");
      Utilities.getElement('maildivfull').innerHTML=html;
   }
   else
   {
      address1=address1.replace(/\"/g,"`");  address2=address2.replace(/\"/g,"`");
      var url="/phpclasses/serviceConnector.php?object=MailingListManager&method=join&params="+ first +";"+ last +";"+ email +";"+  address1 +";"+ address2 +";"+ city +";"+ state +";"+ zip +";"+ emailblasts +";"+ catalogs;
      AjaxUpdater.Update("GET",url,MailingList.onJoin);
   }
}
MailingList.onJoin=function()
{
   if(Ajax.checkReadyState('loading')=="200")
   {
      var response=Ajax.getResponse();
      if(response=="OK")
      {
         Utilities.getElement('maildivfull').innerHTML="<table width=100% cellspacing=2 cellpadding=2><tr align=center><td><br><br>You have been added to our mailing list.<br><br>Thank you for joining!<br><br><img src=\"images/close.gif\" style=\"border:65360d 1px solid;cursor:hand;pointer:hand;\" onClick=\"maildivfull.style.display='none';joindiv.style.display='';\"></td></tr></table>";
	 setTimeout("Utilities.getElement('maildivfull').style.display='none';",1000);
      }
      else Utilities.getElement('maildivfull').innerHTML="<table width=100% cellspacing=2 cellpadding=2><tr align=center><td><br><br>"+ response +"<br><br>&nbsp;&nbsp;<img src=\"images/close.gif\" style=\"border:#65360d 1px solid;cursor:hand;pointer:hand;\" onClick=\"maildivfull.style.display='none';joindiv.style.display='';\"></td></tr></table>";
   }
   else
   {
      Utilities.getElement('maildivfull').innerHTML="<table width=100% cellspacing=2 cellpadding=2><tr align=center><td><br><br>Please Wait...</td></tr></table>";
   }
}
