// JScript source code
////////////////////////////////////////////////////////
// Create new mail for the user
////////////////////////////////////////////////////////
////////////////////////////////////////////////////
// global variables
////////////////////////////////////////////////////

//////////////////////////////////////
// Unsubscribe from dB customer database
//////////////////////////////////////
/* function unsubscribe()
{
// Timmy: Enter your tablename below on right
tableName = "tableName";
// Create XML doc and insert mail data into XML doc
//  loadDocument is routine from General js to create XML doc
//  setXMLValue is routine from General js to insert info into the XML doc
//  sendDoc is routine from General js to send the document to backend
//  getXMLValue is routine from General js to get info from XML Doc
  loadDocument("xml/massMail.xml");
// Validate eMail
action = "unsubscribe"; 
  val = valEmail(action);
// if validation is good load data into XML doc and send to backend
  if (val == true)
  {
      setXmlValue("functionName", "unsubscribe");
      var mailAddressx = document.getElementById("unSubEmail").value;
      setXmlValue("eMail", mailAddressx);
      setXmlValue("tableName", tableName);
	  setXmlValue("message", "test Message");
	  //alert(xmlDoc.xml);
	  xmlDoc = sendDoc("aspx/massMail.aspx");
	  //alert(xmlDoc.xml);
	  alert(getXmlValue("message"));
  }
}

function getSetList()
{
// Create XML doc
//  loadDocument is routine from General js to create XML doc
//  setXMLValue is routine from General js to insert info into the XML doc
//  sendDoc is routine from General js to send the document to backend
//  getXMLValue is routine from General js to get info from XML Doc
	loadDocument("xml/massMail.xml");
// Insert data into XML doc
	setXmlValue("functionName", "getSetList");
	setXmlValue("message", "customer view Message");
	//alert(xmlDoc.xml);
	xmlDoc = sendDoc("aspx/massMail.aspx");
	//alert(xmlDoc.xml);
    var setString = getXmlValue("setNames");
	document.getElementById("showSets").innerHTML = setString;
} */
//////////////////////////////////////
// Add new email to customer database
//////////////////////////////////////
function addSymEmail()
{
// Create XML doc and insert mail data into XML doc
//  loadDocument is routine from General js to create XML doc
//  setXMLValue is routine from General js to insert info into the XML doc
//  sendDoc is routine from General js to send the document to backend
//  getXMLValue is routine from General js to get info from XML Doc
  loadDocument("xml/massMail.xml");
// Validate eMail 
  val = valSymEmail();
// if validation is good load data into XML doc and send to backend
  if (val == true)
  {      
      setXmlValue("functionName", "addSymEmail");
      var mailAddressx = document.getElementById("newEmail").value;
      //var fName = document.getElementById("fName").value;
      //var lName = document.getElementById("lName").value;
      var fName = "None";
      var lName = "None";
      //var setValue = document.getElementById("setGroup").value;
      setXmlValue("eMail", mailAddressx);
      setXmlValue("fName", fName);
      setXmlValue("lName", lName);
      setXmlValue("setValue", "Group1");
	  setXmlValue("message", "test Message");
	  //alert(xmlDoc.xml);
	  xmlDoc = sendDoc("aspx/massMail.aspx");
	  //alert(xmlDoc.xml);
	  alert(getXmlValue("message"));
    }
}

////////////////////////////////////////////////////////
// Validate each field to make sure each field 
// is in correct form
////////////////////////////////////////////////////////
function valSymEmail()
{
// email must be a with @ and another word with a . and two or three characters
    var sEmailString = "^([a-zA-Z0-9_\\.\\-])+\@(([a-zA-Z0-9\\-])+\\.)+([a-zA-Z0-9]{2,4})+\\s*$";
    var sNameString = "^([a-zA-Z])*$";
    var sSetString = "^([a-zA-Z0-9])*$";
	    if (!validateField("newEmail", sEmailString) )
	    {
		    alert("Invalid Email ex(m_2.m2u2@m_2.m2u2.tv)");
		    document.getElementById("newEmail").select();
		    return false;
	    }
	    /*if (!validateField("setGroup", sSetString) )
	    {
		    alert("Invalid set name");
		    document.getElementById("setGroup").select();
		    return false;
	    }*/
	return true;		
}

