/**************************************
* Filename   wsd.newsbox.form.php
* Content    text/javascript
* Comment    Fichier de fonctions pour WSD.NewsBox
* Comment    Un service de WSDiffusion.com
*
* WebSite    http://www.wsdiffusion.com
* Author     Cédric Charbonnel
* Contact    cedric.charbonnel@wsdiffusion.com
* Copyright  Cédric Charbonnel
* Licence    GPL version 2
*
***************************************

Use the SendEmailToWSDRM(formname) function in your own script with the following datas :
wsdnb_email : name of a form field with an email address
wsdnb_optin : name an optional form checkbox. If checked, the user agrees the sharing of his address
wsdnb_tag : name of an optional form field or a fixed javascript var

Following vars are optionaly customizable

wsdnbo_submit_img : the submit image in the form..
  string (absolute URL)
wsdnbo_mail : Localised string "Your e-mail..."
  string

wsdnbo_custom_form : If included in a form
  "Y" or "N" (default = N)
wsdnbo_mail : Localised string "Type your e-mail"
  string
wsdnbo_optin : Localised string "I want receive offers from partners"
  string
wsdnbo_submit : Localised string "Submit" (displayed in image "alt" and anchor "name")
  string
wsdnbo_optin_checked : The opt in checkbox checked by default (O) or not (N)
  "O" or "N"
wsdnbo_textsize : Size of the input field (default = 20)
  integer (must be >0 and <=255)
wsdnbo_input_style : CSS instructions for the input field
  string (valid CSS)
wsdnbo_optin_style : CSS instructions for the opt in checkbox text
  string (valid CSS)

**************************************************/

// *** Variables

var TheResult = "";
var wsdnb_divid = "WSDNB_form_result";
var wsdnb_url = "http://services.wsdiffusion.com/wsd.newsbox.addmail.php";
var wsdnb_key = 5;

// Custom Form
if(typeof(wsdnbo_custom_form)=='undefined' || wsdnbo_custom_form == "") wsdnbo_custom_form = "N";

// Bouton submit
if(typeof(wsdnbo_submit_img)=='undefined' || wsdnbo_submit_img == "") wsdnbo_submit_img = "http://services.wsdiffusion.com/img/valider.png";
if(typeof(wsdnbo_ok_img)=='undefined' || wsdnbo_ok_img == "") wsdnbo_ok_img = "http://services.wsdiffusion.com/img/ico_accept_16.gif";

// Tag
if(typeof(wsdnb_tag)=='undefined') wsdnb_tag = "";

// Opt In
if(typeof(wsdnbo_optin_display)=='undefined') wsdnbo_optin_display = "O";
if(typeof(wsdnb_optin)=='undefined') wsdnb_optin = "N";
if(typeof(wsdnbo_optin_checked)=='undefined') wsdnbo_optin_checked = "N";
if (wsdnbo_optin_checked == "O") {
  optin_check = " checked";
} else {
  optin_check = "";
}
if(typeof(wsdnbo_optin_style)=='undefined') wsdnbo_optin_style = "font-family:arial; font-size:12px;";

// Input field
if(typeof(wsdnbo_textsize)=='undefined') wsdnbo_textsize = "20";
if(typeof(wsdnbo_input_style)=='undefined') wsdnbo_input_style = "font-family:arial; font-size:12px; border:solid 1px #C6E5FE;";

// Langue
if(typeof(wsdnbo_mail)=='undefined') wsdnbo_mail = "Votre adresse...";
if(typeof(wsdnbo_optin)=='undefined') wsdnbo_optin = "Je souhaite que mon adresse soit diffus&eacute;e &agrave; des partenaires.";
if(typeof(wsdnbo_submit)=='undefined') wsdnbo_submit = "Valider";




// *** Affichage

if (wsdnbo_custom_form == "N") {
  document.write("<style>");
  document.write(".wsdnb_input { "+wsdnbo_input_style+" }");
  document.write(".wsdnb_optin { "+wsdnbo_optin_style+" }");
  document.write("</style>");

  document.write("<form name=\"WSDRM_FORM\" style=\"margin:0px; padding:0px;\">");
  document.write("<input type=\"hidden\" name=\"wsdnb_tag\" value=\""+wsdnb_tag+"\">");
  document.write("<input type=\"text\" size=\""+wsdnbo_textsize+"\" maxlength=\"255\" name=\"wsdnb_email\" value=\""+wsdnbo_mail+"\" onclick=\"if(this.value==wsdnbo_mail) this.value='';\" class=\"wsdnb_input\">");
  document.write(" <a name=\""+wsdnbo_submit+"\" href=\"javascript:SendEmailToWSDRM('WSDRM_FORM');\"><img name=\"WSDImgSubmit\" src=\""+wsdnbo_submit_img+"\" border=\"0\" align=\"absmiddle\" alt=\""+wsdnbo_submit+"\"></a>");
  document.write("<br />");
  document.write("<iframe name=\""+wsdnb_divid+"\" height=12 width=170 scrolling=no frameborder=0 style=\"border:0px; padding:0px; margin:0px;\" marginwidth=0 marginheight=0></iframe>");

  if (wsdnbo_optin_display=="O") {
    document.write("<br />");
    document.write("<input type=\"checkbox\" value=\"O\" name=\"wsdnb_optin\""+optin_check+"> <span class=\"wsdnb_optin\">"+wsdnbo_optin+"</span>");
  }
}

if (wsdnbo_custom_form == "N") {
  document.write("</form>");
}



// *** Fonctions

// SendEmailToWSDRM()
function SendEmailToWSDRM(formname) {

  // Launch pad
  if(typeof(formname)!='undefined'
    && formname != ""
    && typeof(wsdnb_key)!='undefined' 
    && wsdnb_key != "") {
    
    if (document.forms[formname].elements['wsdnb_optin']) {
      if (document.forms[formname].elements['wsdnb_optin'].checked == true) {
        wsdnb_optin = "O"
      } else {
        wsdnb_optin = "N"
      }
    }
    
    if (document.forms[formname].elements['wsdnb_tag']) {
      wsdnb_tag = document.forms[formname].elements['wsdnb_tag'].value;
    } else {
      wsdnb_tag = wsdnb_tag;
    }
    
    // On my mark
    the_wsdnb_url = wsdnb_url+"?wsdnb_key=5"+
      "&wsdnb_email="+document.forms[formname].elements['wsdnb_email'].value+
      "&wsdnb_tag="+wsdnb_tag+
      "&wsdnb_optin="+wsdnb_optin
      
    // Mark
    window.frames[wsdnb_divid].location.href=the_wsdnb_url;

    // Bravo!
    document.forms[formname].elements['wsdnb_email'].value = "";

  } // Else... pop !
 }

 