
//  all newsletter javascript

function SubOrUnSubcribe(objForm, strType, strXmlFileName, strEmailFieldName)
{
      objForm.elements['FileName'].value              = strXmlFileName;
      objForm.elements['NewsLetterAction'].value      = strType;

      ValidateEmail(strEmailFieldName, objForm);
}
 

function ValidateEmail(strFieldName, objForm)
{
      strValidString    = '';
      blnValid          = true;

      if(ValidateForEmpty(objForm.elements[strFieldName]))
      {
            if(!checkExpression(document.getElementById(strFieldName).value, g_ReEx_email))
            {
                  strValidString += 'email is incorrect';
                  blnValid    = false;
            }
      }

      if(blnValid)
      {
            SetCurrentPage(objForm);
            objForm.submit();
      }
      else
      {
            alert(strValidString);
      }
}
 

function AddParamIfNotEmpty(strParamName)
{
    objParam = document.getElementById(strParamName);
    if(document.getElementById(strParamName))
    {
        if(document.getElementById(strParamName).value != '')
        {
            return '&' + strParamName + '=' + document.getElementById(strParamName).value;
        }
    }
    return '';
}
 

function ValidateForEmpty(objInput)
{
      var blnThisValid  = true;

      if(trimspaces(objInput.value).length == 0)
      {
            strValidString +=  'geen email adres ingevuld';
            blnThisValid      = false;
            blnValid          = false;
      }

      return blnThisValid;
}


function SetCurrentPage(objForm)
{
    var strUrl = '?empty=';

    strUrl      += AddParamIfNotEmpty('pagename');
    strUrl      += AddParamIfNotEmpty('pageid');
    strUrl      += AddParamIfNotEmpty('pagetype');
    strUrl      += AddParamIfNotEmpty('xmlfile');
    strUrl      += AddParamIfNotEmpty('language');
    strUrl      += AddParamIfNotEmpty('parentlanguage');

    objForm.elements['currentPage'].value = strUrl;

}
