
var comment_id_contribution;
var type;
var statut;                                                            
var type_story;
var userExist = false;
var followUpStory = false;
                                                              
/// new variables
var ajaxObject_Alerts_Phrase;
var log;


function TestEncoding(url){
   var encodedInputString=escape(url);
   encodedInputString=encodedInputString.replace("+", "%2B");
   encodedInputString=encodedInputString.replace("/", "%2F");        
   return encodedInputString;        
}


function TestDeccoding(encodedInputString){
url=encodedInputString.replace(  "%2B" , "+");
url=url.replace("%2F" , "/"); 
   var url=unescape(url);
       
   return url;        
}

function GetXmlHttpObject()
{
    var xmlHttp=null;
    try
     {
         // Firefox, Opera 8.0+, Safari
         xmlHttp=new XMLHttpRequest();
     }
    catch (e)
     {
         //Internet Explorer
         try
           {
              xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
           }
        catch (e)
           {
              xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
           }
     }
  return xmlHttp;
 
} 

    function login(){
    if(document.getElementById("username").value==""){
        alert("You must enter your username");
        return;
    }
    else if(document.getElementById("password").value==""){
        alert("You must enter your password");
        return;
    }
     xmlHttp=GetXmlHttpObject()
     if (xmlHttp==null)
      {
          alert ("Browser does not support HTTP Request");
          return;
      } 
     var url="includes/ajax.php";
     url=url+"?q=1&username="+document.getElementById("username").value;
     url=url+"&pass="+document.getElementById("password").value;
     if (document.getElementById("remember").checked==true){
     url=url+"&remember=true"; 
     } else {
     url=url+"&remember=false";             
     }       
     url=url+"&sid="+Math.random();
     xmlHttp.onreadystatechange=loginReturn; 
     xmlHttp.open("GET",url,true);
     xmlHttp.send(null);
 }
 
function send_new_password(){
    if(document.getElementById("lost_email").value==""){
        alert("You must enter your email");
        return;
    }
    if(document.getElementById("lost_username").value==""){
        alert("You must enter your username");
        return;
    }
     xmlHttp=GetXmlHttpObject()
     if (xmlHttp==null)
      {
          alert ("Browser does not support HTTP Request");
          return;
      } 
     var url="includes/ajax.php";
     url=url+"?q=21&email="+document.getElementById("lost_email").value+"&username="+document.getElementById("lost_username").value;;
     url=url+"&sid="+Math.random();
    xmlHttp.onreadystatechange=function(){
        if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
            //alert(xmlHttp.responseText);
            if(xmlHttp.responseText.indexOf('bademail') != -1){document.getElementById("corner_lostpassword_pane_div").innerHTML ='<span class="grey_text" style="color:red; font-size:12px; padding-top:20px;">Please enter a correct email.</span>';}    
            else if(xmlHttp.responseText.indexOf('noquestion') != -1){document.getElementById("corner_lostpassword_pane_div").innerHTML ='<span class="grey_text" style="color:red; font-size:12px; padding-top:20px;">Sorry...<br /><br />You have not entered a password hint question in your profile.<br /><br />Email <a href="mailto:support@dreveryone.com">support@dreveryone.com</a> with a request for a new password.<br />(Please include your username in the email</span>';}    
            else if(xmlHttp.responseText.indexOf('toomuchattempts') != -1){
                document.getElementById("lostpasswordForm").innerHTML ='<span class="grey_text" style="color:red; font-size:12px; padding-top:20px;">Sorry, your attempts have failed.<br />Please email <a href="mailto:support@dreveryone.com">support@dreveryone.com</a> for assistance</span>';
                document.getElementById("corner_lostpassword_pane_div").innerHTML ='';
            }
            else if(xmlHttp.responseText.indexOf('wrong') != -1){document.getElementById("corner_lostpassword_pane_div").innerHTML ='<span class="grey_text" style="color:red; font-size:12px; padding-top:20px;">Oops Sorry...<br /><br />Wrong username and password combination.<br /><br />Try Again...</span>';}
            else {document.getElementById("lostpasswordForm").innerHTML=xmlHttp.responseText;
            document.getElementById("corner_lostpassword_pane_div").innerHTML ='';}
        }
    }
     xmlHttp.open("GET",url,true);
     xmlHttp.send(null);
 }
 
 function answer_hint_question(){
    if(document.getElementById("answer_hint_question").value==""){
        alert("You must enter your answer");
        return;
    }
     xmlHttp=GetXmlHttpObject()
     if (xmlHttp==null)
      {
          alert ("Browser does not support HTTP Request");
          return;
      } 
     var url="includes/ajax.php";
     url=url+"?q=22&id_member="+document.getElementById("id_member_answer_q").value+"&answer="+document.getElementById("answer_hint_question").value;;
     url=url+"&sid="+Math.random();
    xmlHttp.onreadystatechange=function(){
        if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
            //alert(xmlHttp.responseText);
            if(xmlHttp.responseText.indexOf('badanswer') != -1){document.getElementById("corner_lostpassword_pane_div").innerHTML ='<span class="grey_text" style="color:red; font-size:12px;">Wrong answer, try again...</span>';}    
            else if(xmlHttp.responseText.indexOf('toomuchattempts') != -1){
                document.getElementById("lostpasswordForm").innerHTML ='<span class="grey_text" style="color:red; font-size:12px;">Sorry, your attempts have failed.<br />Please email <a href="mailto:support@dreveryone.com">support@dreveryone.com</a> for assistance</span>';
                document.getElementById("corner_lostpassword_pane_div").innerHTML ='';
            }
            else {
                document.getElementById("lostpasswordForm").innerHTML=xmlHttp.responseText;
                setTimeout("location.href='myprofile.php'",4000);

                
            
            }
        }
    }
     xmlHttp.open("GET",url,true);
     xmlHttp.send(null);
 }
 
function loginReturn(){ 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {       
     
         if(xmlHttp.responseText==""){
            document.getElementById("error").innerHTML ="Username or password incorrect (case sensitive).";
         }        
        /*if(xmlHttp.responseText==""){
            document.getElementById("error").innerHTML ="Username or password incorrect.";
        }*/
        else{
                
                if(type=="question"){
                    document.getElementById("profile_detail").innerHTML  = xmlHttp.responseText;
                    new_question();
                }
                else if(type=="link"){
                    
                    document.getElementById("profile_detail").innerHTML  = xmlHttp.responseText;
                    new_link();                    
                }
                else if(type=="story"){
                    document.getElementById("profile_detail").innerHTML  = xmlHttp.responseText;
                    new_story(statut);
                }
                else if(type=="comment"){
                    load_comment(statut,comment_id_contribution);
 
                }
                else if(type=="answer") {
                    //alert( type+"/"+statut+"/"+comment_id_contribution);    
                    load_answer(type,comment_id_contribution);
                 
                }
                else if(type=='comment_for_answer')
                {
                    load_comment(type,comment_id_contribution);
                }
                else if(type=='treatment' || type=='goal' || type=='best_web' || type=='rate_question' || type=='rate_answer' || type=='article' || type=='fave_question')
                {
                    location.reload() ;
                }
                else if(type=='alerts_for_search_phrases' )
                {
                     check_alerts_phrase(ajaxObject_Alerts_Phrase,log); 
                }   
                else if(type=='verification' )
                {
                     location.reload() ;  
                }                                
                else {
                    window.location.replace("health_journal_home.php");
                    //location.reload() ;
                }
                Dialog.cancelCallback();
            }
     }
}

 // fonction pour ouvrir la fenêtre du login
 function openAjaxConfirm() {

          Dialog.info({url: "includes/login.php", options: {method: 'get'}}, 
                     {width:530, height:320, closable:true,okLabel: "Submit", buttonClass: "myButtonClass", id: "myDialogId",className: "alphacube", 
                     cancel:function(win) {debug("cancel confirm panel")}, 
                     ok:function(win) {login()} 
                     });  
                        
  } 
 

 // fonction pour ouvrir la fenêtre du login
 function openInappropriate(action,id) {
          Dialog.info({url: "inappropriate.php?id="+id+"&action="+action, options: {method: 'get'}}, 
                     {width:600, height:320, closable:true,okLabel: "Submit", buttonClass: "myButtonClass", id: "myDialogIdInappropriate",className: "alphacube"
                     });       
  }  

// fonction pour ouvrir la fenêtre du login
 function openSendFriend(action,id) {
          if(id!=""){
              Dialog.info({url: "send_to_friends.php?id="+id+"&action="+action, options: {method: 'get'}}, 
                         {width:600, height:590, closable:true,okLabel: "Submit", buttonClass: "myButtonClass", id: "myDialogIdSendToFriends",className: "alphacube", 
                         cancel:function(win) {debug("cancel confirm panel")}
                 });       
          }else{
          Dialog.info({url: "send_to_friends.php?action="+action, options: {method: 'get'}}, 
                     {width:600, height:590, closable:true,okLabel: "Submit", buttonClass: "myButtonClass", id: "myDialogIdSendToFriends",className: "alphacube", 
                     cancel:function(win) {debug("cancel confirm panel")}
                     });       
          }

}  


    // fonction pour ouvrir la fenêtre de la light registration
  function show_light_registration() {
      //Dialog.confirm($('light_registration').innerHTML, {className: "alphacube",height:270,width:500, okLabel: "Close All", ok: closeAllModalWindows})
    //  alert('this is light registration!');
    
    /// the following call opens a dialog box based on the values of the div with the id light_registration in the 
    // includes/login.php page
      Dialog.info($('light_registration').innerHTML, {className: "alphacube",height:360,width:520, closable:true,okLabel: "Submit", ok: light_registration})
  }
 
    // fonction pour ouvrir la fenêtre du login
 function openSendMailChoices(defaultMessageId,contributionId) {


          Dialog.info({url: "send_mail_choices.php?defaultMessageId="+defaultMessageId+"&contributionId="+contributionId,
           options: {method: 'get'}}, 
                     {width:530, height:320, closable:true,okLabel: "Submit", buttonClass: "myButtonClass", id: "myDialogIdChoices", 
                     className: "alphacube", 
                     cancel:function(win) {debug("cancel confirm panel")}
                     });  
                        
  } 
  function openSendMailWebmail(defaultMessageId,contributionId) {


          Dialog.info({url: "send_mail_webmail.php?defaultMessageId="+defaultMessageId+"&contributionId="+contributionId
          , options: {method: 'get'}}, 
                     {width:600, height:400, visible:false, closable:true,okLabel: "Submit", buttonClass: "myButtonClass", id: "myDialogIdWebmail", 
                     className: "alphacube", 
                     cancel:function(win) {debug("cancel confirm panel")}
                     });  
                        
  }   
 function openSendMailWebmailImport(email_box,password_box,provider_box,step) {

      //    Dialog.info({url: "controller_open_inviter_get_contacts.php", 
          Dialog.info({url: "send_mail_webmail_import.php",            
          options: {method: 'post',postBody: 
          'email_box='+email_box+'&password_box='+password_box+'&provider_box='+provider_box+'&step=get_contacts'}}, 
                     {width:640, height:650, closable:true,okLabel: "Submit", buttonClass: "myButtonClass", id: "myDialogIdWebmailImport", 
                     className: "alphacube", 
                     cancel:function(win) {debug("cancel confirm panel")}
                     });  
                        
  }  
  
 function openSendMailWebmailImportNEW(responseHTMLcontent) {

      //    Dialog.info({url: "controller_open_inviter_get_contacts.php", 
          Dialog.info(responseHTMLcontent, 
                     {width:640, height:650, closable:true,okLabel: "Submit", buttonClass: "myButtonClass", id: "myDialogIdWebmailImport2", 
                     className: "alphacube", 
                     cancel:function(win) {debug("cancel confirm panel")}
                     });  
                        
  } 
  
  
   function openSendMailSocial(defaultMessageId,contributionId) {

          Dialog.info({url: "send_mail_social.php?defaultMessageId="+defaultMessageId+"&contributionId="+contributionId,
           options: {method: 'get'}}, 
                     {width:600, height:370, visible:false, closable:true,okLabel: "Submit", buttonClass: "myButtonClass", id: "myDialogIdSocial", 
                     className: "alphacube", 
                     cancel:function(win) {debug("cancel confirm panel")}
                     });  
                        
  } 
  
  function closeAllModalWindows() {
    Windows.closeAllModalWindows();
    return true;
  }
  

  

function SessionReturn(){ 
    if(xmlHttpSession.readyState == 4 && xmlHttpSession.status == 200){        
        
        
    //    alert('html response is . '+xmlHttp.responseText);
        
        trimmedResponseText=xmlHttpSession.responseText.replace(/[\n\r\t]/g,'');  
        if(trimmedResponseText=="no"){            
            openAjaxConfirm();
        }else{
                if(type=="question"){
                    new_question();
                }
                else if(type=="link"){
                    new_link();
                }
                else if(type=="story"){
                    new_story(statut);
                }
                else if(type=="comment"){
                    load_comment(statut,comment_id_contribution);
                   
                }
                else if(type=="answer") {
                    //alert( type+"/"+statut+"/"+comment_id_contribution);    
                    load_answer(type,comment_id_contribution);
                  
                }
                else if(type=='comment_for_answer')
                {
                    load_comment(type,comment_id_contribution);
                 
                }
                else if(type=='alerts_for_search_phrases' )
                {
                     check_alerts_phrase(ajaxObject_Alerts_Phrase,log); 
                } 
                             

            }
    }
}

function checkSession(contribution,share_statut,id_contribution,
in_AjaxObject_Alerts_Phrase,in_Log){
    //alert(contribution);
 
     xmlHttpSession=GetXmlHttpObject()
     if (xmlHttpSession==null)
      {
          alert ("Browser does not support HTTP Request");
          return;
      } 
      
  
    type = contribution;    
    statut = share_statut;
    comment_id_contribution = id_contribution;
    ajaxObject_Alerts_Phrase=in_AjaxObject_Alerts_Phrase;
    log=in_Log;

     var url="includes/ajax.php";
     url=url+"?q=2";
     url=url+"&sid="+Math.random();
     xmlHttpSession.onreadystatechange=SessionReturn; 
     xmlHttpSession.open("GET",url,true);
     xmlHttpSession.send(null);
 }

function new_story(share_statut){
  //  alert ("new story 1");
  //container (div inside the form share_story_form)that holds input fields for the form share_story_form
  containerId='share_story_formNEW_div';
        document.getElementById('share_story_formNEW').action='sharing.php'  ;    
    xmlHttp1=GetXmlHttpObject();
     if (xmlHttp1==null)
      {
          alert ("Browser does not support HTTP Request");
          return;
      }
     var url="includes/ajax.php";
    url=url+"?q=9";   
    appendElementNEW(containerId,'new_content','new_story') ;
    // A modifier
    url=url+"&statut="+share_statut;
        appendElementNEW(containerId,'statut',share_statut) ; 
        
        
    /// modified part
        url=url+"&story_health_topic1="+document.getElementById("story_health_topic").value;    
                            appendElementNEW(containerId,'story_health_topic1',document.getElementById("story_health_topic").value) ;    
        if(document.getElementById("story_health_topic_1")) {
            url=url+"&story_health_topic2="+document.getElementById("story_health_topic_1").value;
                                appendElementNEW(containerId,'story_health_topic2',document.getElementById("story_health_topic_1").value) ;    
        }
        if(document.getElementById("story_health_topic_2")) {
            url=url+"&story_health_topic3="+document.getElementById("story_health_topic_2").value;    
                                appendElementNEW(containerId,'story_health_topic3',document.getElementById("story_health_topic_2").value) ;    
        }
        if(document.getElementById("story_health_topic_3")){
         url=url+"&story_health_topic4="+document.getElementById("story_health_topic_3").value;    
                             appendElementNEW(containerId,'story_health_topic4',document.getElementById("story_health_topic_3").value) ;    
        }
        if(document.getElementById("story_health_topic_4")) {
            url=url+"&story_health_topic5="+document.getElementById("story_health_topic_4").value;    
                                appendElementNEW(containerId,'story_health_topic5',document.getElementById("story_health_topic_4").value) ;    
        }
    
    /// end of modification         
        
        
        
    // si treatment
    if(this.document.form6.story_type[0].checked){
        type_story = "treatment";
        /// setting the action url of the form

        url=url+"&type_story=treatment";
            appendElementNEW(containerId,'type_story','treatment') ;
        url=url+"&condition="+document.getElementById("condition").value;  
                    appendElementNEW(containerId,'condition',document.getElementById("condition").value) ;   
        url=url+"&family_story="+document.getElementById("family_member").value;
                   appendElementNEW(containerId,'family_story',document.getElementById("family_member").value) ;          
        url=url+"&follow_up="+document.getElementById("follow_up_story").value;    
   appendElementNEW(containerId,'follow_up',document.getElementById("follow_up_story").value) ;          


        
        url=url+"&symptom1="+document.getElementById("symptom").value;  
        appendElementNEW(containerId,'symptom1',document.getElementById("symptom").value) ;   
        if(document.getElementById("symptom_1")) {
            url=url+"&symptom2="+document.getElementById("symptom_1").value;
            appendElementNEW(containerId,'symptom2',document.getElementById("symptom_1").value) ; 
        }
        if(document.getElementById("symptom_2")) {
            url=url+"&symptom3="+document.getElementById("symptom_2").value;   
                    appendElementNEW(containerId,'symptom3',document.getElementById("symptom_2").value) ; 
        } 
        if(document.getElementById("symptom_3")) {
            url=url+"&symptom4="+document.getElementById("symptom_3").value;    
                    appendElementNEW(containerId,'symptom4',document.getElementById("symptom_3").value) ; 
        }
        if(document.getElementById("symptom_4")) {
            url=url+"&symptom5="+document.getElementById("symptom_4").value;
                    appendElementNEW(containerId,'symptom5',document.getElementById("symptom_4").value) ; 
        }
        
    }else{//goals
        type_story = "goal";
   
        url=url+"&type_story=goal";
                appendElementNEW(containerId,'type_story',document.getElementById("goal").value) ; 
        url=url+"&goal="+document.getElementById("goal").value;
                appendElementNEW(containerId,'goal',document.getElementById("goal").value) ; 
        url=url+"&family_story="+document.getElementById("family_member").value;
                appendElementNEW(containerId,'family_story',document.getElementById("family_member").value) ; 
        url=url+"&follow_up="+document.getElementById("follow_up_story").value;  
                appendElementNEW(containerId,'follow_up',document.getElementById("follow_up_story").value) ;   
    }
    
    url=url+"&descriptive="+document.getElementById("descriptive").value;
            appendElementNEW(containerId,'descriptive',document.getElementById("descriptive").value) ; 
    //alert (document.getElementById("treatment").value);
    //alert (document.getElementById("t_photo_1").value);
    url=url+"&treatment1="+document.getElementById("treatment").value;
            appendElementNEW(containerId,'treatment1',document.getElementById("treatment").value) ; 
       // if(document.getElementById("treatment_1")) url=url+"&treatment1="+document.getElementById("treatment_1").value; 
    if(document.getElementById("treatment_1")) {
        url=url+"&treatment2="+document.getElementById("treatment_1").value;
                appendElementNEW(containerId,'treatment2',document.getElementById("treatment_1").value) ; 
    }
    if(document.getElementById("treatment_2")) {
        url=url+"&treatment3="+document.getElementById("treatment_2").value;    
                appendElementNEW(containerId,'treatment3',document.getElementById("treatment_2").value) ; 
    }
    if(document.getElementById("treatment_3")) {
        url=url+"&treatment4="+document.getElementById("treatment_3").value;    
                appendElementNEW(containerId,'treatment4',document.getElementById("treatment_3").value) ; 
    }
    if(document.getElementById("treatment_4")) {
        url=url+"&treatment5="+document.getElementById("treatment_4").value;
                appendElementNEW(containerId,'treatment5',document.getElementById("treatment_4").value) ; 
    }
    
    if(document.getElementById("t_photo_1")) {
        url=url+"&photo1="+document.getElementById("t_photo_1").value;
                appendElementNEW(containerId,'photo1',document.getElementById("t_photo_1").value) ; 
    }
    if(document.getElementById("t_photo_2")) {
     url=url+"&photo2="+document.getElementById("t_photo_2").value;    
             appendElementNEW(containerId,'photo2',document.getElementById("t_photo_2").value) ; 
    }
    if(document.getElementById("t_photo_3")) {
        url=url+"&photo3="+document.getElementById("t_photo_3").value;    
                appendElementNEW(containerId,'photo3',document.getElementById("t_photo_3").value) ; 
    }
    if(document.getElementById("t_photo_4")) {
        url=url+"&photo4="+document.getElementById("t_photo_4").value;    
                appendElementNEW(containerId,'photo4',document.getElementById("t_photo_4").value) ; 
    }
    if(document.getElementById("t_photo_5")) {
        url=url+"&photo5="+document.getElementById("t_photo_5").value;    
                appendElementNEW(containerId,'photo5',document.getElementById("t_photo_5").value) ; 
    }

    if(document.getElementById("val_link_1")) {
        url=url+"&link1="+document.getElementById("val_link_1").value;
                appendElementNEW(containerId,'link1',document.getElementById("val_link_1").value) ; 
    }
    if(document.getElementById("val_link_2")) {
        url=url+"&link2="+document.getElementById("val_link_2").value;
                appendElementNEW(containerId,'link2',document.getElementById("val_link_2").value) ; 
    }
    if(document.getElementById("val_link_3")) {
        url=url+"&link3="+document.getElementById("val_link_3").value;    
                appendElementNEW(containerId,'link3',document.getElementById("val_link_3").value) ; 
    }
    if(document.getElementById("val_link_4")) {
        url=url+"&link4="+document.getElementById("val_link_4").value;    
                appendElementNEW(containerId,'link4',document.getElementById("val_link_4").value) ; 
    }
    if(document.getElementById("val_link_5")) {
        url=url+"&link5="+document.getElementById("val_link_5").value;
                appendElementNEW(containerId,'link5',document.getElementById("val_link_5").value) ; 
    }
    // medication
    
    if(document.getElementById("medication") && document.getElementById("medication").value != 'Medication name'){ 
            url=url+"&medication1="+document.getElementById("medication").value;
                    appendElementNEW(containerId,'medication1',document.getElementById("medication").value) ; 
          //  alert ('med0') ;
    }
            
    if(document.getElementById("medication_1") && document.getElementById("medication_1").value !='Medication name')     {
            url=url+"&medication2="+document.getElementById("medication_1").value;
                    appendElementNEW(containerId,'medication2',document.getElementById("medication_1").value) ; 
          //              alert ('med1') ;
    }
            
    if(document.getElementById("medication_2") && document.getElementById("medication_2").value !='Medication name')  {
            url=url+"&medication3="+document.getElementById("medication_2").value;    
                    appendElementNEW(containerId,'medication3',document.getElementById("medication_2").value) ; 
          //              alert ('med2') ;
    }
            
    if(document.getElementById("medication_3") && document.getElementById("medication_3").value !='Medication name')    {
            url=url+"&medication4="+document.getElementById("medication_3").value; 
                    appendElementNEW(containerId,'medication4',document.getElementById("medication_3").value) ;   
          //              alert ('med3') ;
    }
             
    if(document.getElementById("medication_4") && document.getElementById("medication_4").value !='Medication name')  {
        
            url=url+"&medication5="+document.getElementById("medication_4").value;
                    appendElementNEW(containerId,'medication5',document.getElementById("medication_4").value) ; 
          //              alert ('med4') ;
    }
            
    // dosage
    if(document.getElementById("dosage")) {
        url=url+"&dosage1="+document.getElementById("dosage").value;
                appendElementNEW(containerId,'dosage1',document.getElementById("dosage").value) ; 
    }
    if(document.getElementById("dosage_1")) {
        url=url+"&dosage2="+document.getElementById("dosage_1").value;
                appendElementNEW(containerId,'dosage2',document.getElementById("dosage_1").value) ; 
    }
    if(document.getElementById("dosage_2")) {
        url=url+"&dosage3="+document.getElementById("dosage_2").value;    
                appendElementNEW(containerId,'dosage3',document.getElementById("dosage_2").value) ; 
    }
    if(document.getElementById("dosage_3")) {
        url=url+"&dosage4="+document.getElementById("dosage_3").value;    
                appendElementNEW(containerId,'dosage4',document.getElementById("dosage_3").value) ; 
    }
    if(document.getElementById("dosage_4")) {
        url=url+"&dosage5="+document.getElementById("dosage_4").value;
                appendElementNEW(containerId,'dosage5',document.getElementById("dosage_4").value) ; 
    }
    // frequency
    if(document.getElementById("frequency")) {
        url=url+"&frequency1="+document.getElementById("frequency").value;
                appendElementNEW(containerId,'frequency1',document.getElementById("frequency").value) ; 
    }
    if(document.getElementById("frequency_1")){
        url=url+"&frequency2="+document.getElementById("frequency_1").value;
                appendElementNEW(containerId,'frequency2',document.getElementById("frequency_1").value) ; 
    }
    if(document.getElementById("frequency_2")){
     url=url+"&frequency3="+document.getElementById("frequency_2").value;    
             appendElementNEW(containerId,'frequency3',document.getElementById("frequency_2").value) ; 
     }
    if(document.getElementById("frequency_3")) {
        url=url+"&frequency4="+document.getElementById("frequency_3").value;  
                appendElementNEW(containerId,'frequency4',document.getElementById("frequency_3").value) ; 
    }  
    if(document.getElementById("frequency_4")) {
        url=url+"&frequency5="+document.getElementById("frequency_4").value;
                appendElementNEW(containerId,'frequency5',document.getElementById("frequency_4").value) ; 
    }
    
    
    
    if(document.getElementById("month_started")){
        url=url+"&month_started="+document.getElementById("month_started").value;
                appendElementNEW(containerId,'month_started',document.getElementById("month_started").value) ; 
    }
    
    if(document.getElementById("year_started")){
        url=url+"&year_started="+document.getElementById("year_started").value;
                appendElementNEW(containerId,'year_started',document.getElementById("year_started").value) ; 
    }
    
    if(document.getElementById("end_month")){
        url=url+"&month_ended="+document.getElementById("end_month").value;
                appendElementNEW(containerId,'month_ended',document.getElementById("end_month").value) ; 
    }
    
    if(document.getElementById("end_year")){
        url=url+"&year_ended="+document.getElementById("end_year").value;
                appendElementNEW(containerId,'year_ended',document.getElementById("end_year").value) ; 
    }
    if(document.getElementById("ongoing")){
        url=url+"&ongoing="+document.getElementById("ongoing").value;
                appendElementNEW(containerId,'ongoing',document.getElementById("ongoing").value) ; 
     //   alert('ongoing is:'+url);
    }
    
    if(document.getElementById("insurer_name")){    
        url=url+"&insurer_name="+document.getElementById("insurer_name").value;
                appendElementNEW(containerId,'insurer_name',document.getElementById("insurer_name").value) ; 
    }
    
    if(document.getElementById("care_speciality")){    
        url=url+"&care_giver_speciality="+document.getElementById("care_speciality").value;
                appendElementNEW(containerId,'care_giver_speciality',document.getElementById("care_speciality").value) ; 
    }    
    
    if(document.getElementById("provider_lastname")){    
        url=url+"&provider_lastname="+document.getElementById("provider_lastname").value;
                appendElementNEW(containerId,'provider_lastname',document.getElementById("provider_lastname").value) ; 
    }
    
    if(document.getElementById("provider_firstname")){    
        url=url+"&provider_firstname="+document.getElementById("provider_firstname").value;
                appendElementNEW(containerId,'provider_firstname',document.getElementById("provider_firstname").value) ; 
    }    
    
    //// COMMENT :NEW added secondary care provider
      if(document.getElementById("care_speciality2")){    
        url=url+"&care_giver_speciality2="+document.getElementById("care_speciality2").value;
                appendElementNEW(containerId,'care_giver_speciality2',document.getElementById("care_speciality2").value) ; 
    }    
    
    if(document.getElementById("provider_lastname2")){    
        url=url+"&provider_lastname2="+document.getElementById("provider_lastname2").value;
                appendElementNEW(containerId,'provider_lastname2',document.getElementById("provider_lastname2").value) ; 
    }
    
    if(document.getElementById("provider_firstname2")){    
        url=url+"&provider_firstname2="+document.getElementById("provider_firstname2").value;
                appendElementNEW(containerId,'provider_firstname2',document.getElementById("provider_firstname2").value) ; 
    }  
    
    
    
    ///// end of adding
    
    
    if(document.getElementById("pocket_cost")){    
        url=url+"&total_cost="+document.getElementById("pocket_cost").value;
                appendElementNEW(containerId,'total_cost',document.getElementById("pocket_cost").value) ; 
    }
    if(document.getElementById("out_pocket_cost")){    
        url=url+"&pocket_cost="+document.getElementById("out_pocket_cost").value;
                appendElementNEW(containerId,'pocket_cost',document.getElementById("out_pocket_cost").value) ; 
    }
    

       if(document.getElementById("confirm_rating").value=='confirmed'){  // the following two items are sent only if rating is confirmed          
 
        if(document.getElementById("easy_to_follow")){
  
            url=url+"&easy_to_follow="+document.getElementById("easy_to_follow").value;
                    appendElementNEW(containerId,'easy_to_follow',document.getElementById("easy_to_follow").value) ; 
        }
        if(document.getElementById("duration")){    
            url=url+"&duration="+document.getElementById("duration").value;
            appendElementNEW(containerId,'duration',document.getElementById("duration").value) ;  

        }  
       }  
    
    
    url=url+"&effectiveness="+document.getElementById("effectiveness").value;
            appendElementNEW(containerId,'effectiveness',document.getElementById("effectiveness").value) ; 
    url=url+"&side_effects="+document.getElementById("side_effects").value;
            appendElementNEW(containerId,'side_effects',document.getElementById("side_effects").value) ; 
    url=url+"&recommend="+document.getElementById("recommend").value;
            appendElementNEW(containerId,'recommend',document.getElementById("recommend").value) ; 
    
 //   var storyInput=TestEncoding(tinyMCE.getInstanceById('story').getContent());
 //  alert('tinymce output is'+tinyMCE.getInstanceById('story').getContent());
 //   if (tinyMCE.getInstanceById('story').getContent().value=="<p>Enter Your story here.</p><p>Tell us what worked (or didn\'t work) for you.</p><p>Avoid large blocks of text. Reasonably short paragraphs are inviting and much easier to read and understand.</p>"){    
      //  alert('reseting story input');
//      alert ('there is a match 1');
 //       storyInput=TestEncoding("<p> </p>");  /// for some reason we need to have at least one space in an empty story
//    }    else {
 //       alert('there is no match 1');
//    }
   
//    var storyInput=document.getElementById("story").value; 
//   alert('storyInput is is'+storyInput);
//    if (storyInput=="<p>Enter Your story here.</p><p>Tell us what worked (or didn\'t work) for you.</p><p>Avoid large blocks of text. Reasonably short paragraphs are inviting and much easier to read and understand.</p>"){    
      //  alert('reseting story input');
//      alert ('there is a match between default and entered story')    ; 
//        storyInput=TestEncoding("<p> </p>");  /// for some reason we need to have at least one space in an empty story
//    }    else{
//        alert ('there is no match between default and entered story')  ;
//        storyInput= TestEncoding(tinyMCE.getInstanceById('story').getContent()); 
//    }
   
   
    
 //   alert ('story is: '+storyInput);
var storyString=new String(tinyMCE.getInstanceById('story').getContent()); 
   var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version); 
var pattern;
if (browser=='Microsoft Internet Explorer'){
     pattern='<!--[.]*-->';  
 
} else {
         pattern='<!--[^]*-->';  

}
  //pattern='&lt;!--[^]*--&gt';
  var replacement="";     
  var re = new RegExp(pattern, "g");

  replaced_storyString = storyString.replace(re , replacement); 
  // alert ( replaced_storyString);   
    
    url=url+"&story="+TestEncoding(replaced_storyString);
            appendElementNEW(containerId,'story',replaced_storyString) ; 
 //   url=url+"&story="+storyInput;
     
    if(document.getElementById("alert_me").checked){
        url=url+"&alert_me=1";
                appendElementNEW(containerId,'alert_me',1) ; 
    }else{
        url=url+"&alert_me=0";
                appendElementNEW(containerId,'alert_me',0) ; 
    }
    if(document.getElementById("alert_conditions").checked){
        url=url+"&alert_conditions=1";
                appendElementNEW(containerId,'alert_conditions',1) ; 
    }else{
        url=url+"&alert_conditions=0";
                appendElementNEW(containerId,'alert_conditions',0) ; 
    }
    if(document.getElementById("alert_treatment").checked){
        url=url+"&alert_treatment=1";
                appendElementNEW(containerId,'alert_treatment',1) ; 
    }else{
        url=url+"&alert_treatment=0";
                appendElementNEW(containerId,'alert_treatment',0) ; 
    }
      if(document.getElementById("alert_symptom").checked){
        url=url+"&alert_symptom=1";
                appendElementNEW(containerId,'alert_symptom',1) ; 
    }else{
        url=url+"&alert_symptom=0";
                appendElementNEW(containerId,'alert_symptom',0) ; 
    }
        


    xmlHttp1.onreadystatechange=function(){
        if(xmlHttp1.readyState == 4 && xmlHttp1.status == 200){                        
     //     alert('comencing congratulation');

            var values = xmlHttp1.responseText.split("|");
     //       alert('value 0 is'+values[0]);
            
            //comment : eliminating the newlines from the beginning of the string
            values[0]=values[0].replace(/[\n\r\t]/g,'');
            /// end of newlines elimination
            
            //    alert('valu e 0 is'+values[0]);   
  var str=String(values[0]);
 // alert ('string is str'+typeof(str));
 // alert ('string is:'+str);
  var pos=str.indexOf("congratulation")   ; 
 // alert ('value of pos is:'+pos); 
      
 //            if(values[0]=='congratulation'){        // on teste si c'est la 1ère contribution de ce membre
              if(pos!=-1){        // on teste si c'est la 1ère contribution de ce membre   
              
              HideStoryDetailNEW(log4javascript.getLogger()); 
                  //   alert ("statut is:"+statut);
     //             alert("about to print congratulation");
               if (statut=='draft'){
                    document.getElementById("congratulation_story").style.display='none';
                    document.getElementById("congratulation_story_pending").style.display='block';
                    document.getElementById("congratulation_story_private").style.display='none';                   
               }   else if (statut=='health_journal'){
                //   alert ('entering health diary');
                     document.getElementById("congratulation_story").style.display='none';
                    document.getElementById("congratulation_story_pending").style.display='none';
                    document.getElementById("congratulation_story_private").style.display='block';                     
               }   else {
                     document.getElementById("congratulation_story").style.display='block';
                    document.getElementById("congratulation_story_pending").style.display='none';
                    document.getElementById("congratulation_story_private").style.display='none';                    
               }
               
           /*     if(values[1]==1){
                    document.getElementById("story_congratulation_title").innerHTML = '<img src="images/text_images/thank_u_story_first.gif" border="0" />';
                }else{
                    document.getElementById("story_congratulation_title").innerHTML = '<img src="images/text_images/thank_u_story.gif" border="0" />';
                }                
        
                if(type_story=="treatment"){
                    document.getElementById("congratulation_goal").style.display='none';
                    document.getElementById("congratulation_treatment").style.display='block';
                    document.getElementById("email_them_treatment").innerHTML=values[2];
         //           document.getElementById("your_treatment").innerHTML=values[3];  // no longer in use (was congratulation detail)  
                }else{
                    document.getElementById("congratulation_goal").style.display='block';
                    document.getElementById("congratulation_treatment").style.display='none';
                    document.getElementById("email_them_goal").innerHTML=values[2];
        //            document.getElementById("your_goal").innerHTML=values[3];     // no longer in use (was congratulation detail)
                }
               //             alert('setting preview_story display to none');
               
               
               
               */
                document.getElementById("preview_story").style.display='none';
   //             alert('about to reload tabs');
                if(type_story=="treatment"){
                    load_treatments_tab_ordered('treatments','most_recent','0');
                }else {
                    load_treatments_tab_ordered('goals','most_recent','0');
                }
            }
         }        
    } 
   /// adding pending story parameters 
      url=url+"&pendingType="+document.getElementById("pendingType").value;  
                appendElementNEW(containerId,'pendingType',document.getElementById("pendingType").value) ;          
      url=url+"&pendingID="+document.getElementById("pendingID").value;  
                      appendElementNEW(containerId,'pendingID',document.getElementById("pendingID").value) ;   
      
          url=url+"&sid="+Math.random();  
                                appendElementNEW(containerId,'sid',Math.random()) ;   
  //   alert ("final url is:  "+url);
  //   xmlHttp1.open("GET",url,true);
  //   xmlHttp1.send(null);
  document.getElementById('share_story_formNEW').submit();
}



function new_question(){
   containerId='share_question_formNEW_div';
        document.getElementById('share_question_formNEW').action='sharing.php'  ; 
    xmlHttp3=GetXmlHttpObject();
    
     if (xmlHttp3==null)
      {
          alert ("Browser does not support HTTP Request");
          return;
      } 
     var url="includes/ajax.php";
    url=url+"?q=7";    
                        appendElementNEW(containerId,'new_content','new_question') ;    
    //url=url+"&topic="+document.getElementById("question_topic").value;
    url=url+"&detail="+tinyMCE.getInstanceById('detail_question').getContent();
                        appendElementNEW(containerId,'detail',tinyMCE.getInstanceById('detail_question').getContent()) ;    
    url=url+"&question="+document.getElementById("question_label").value;
                        appendElementNEW(containerId,'question',document.getElementById("question_label").value) ;    
    
    /// modified part
        url=url+"&health_topic1="+document.getElementById("health_topic").value;  
                                appendElementNEW(containerId,'health_topic1',document.getElementById("health_topic").value) ;   
        if(document.getElementById("health_topic_1")){
         url=url+"&health_topic2="+document.getElementById("health_topic_1").value;
                             appendElementNEW(containerId,'health_topic2',document.getElementById("health_topic_1").value) ;    
        }
        if(document.getElementById("health_topic_2")) {
            url=url+"&health_topic3="+document.getElementById("health_topic_2").value;    
                                appendElementNEW(containerId,'health_topic3',document.getElementById("health_topic_2").value) ;    
        }
        if(document.getElementById("health_topic_3")) {
            url=url+"&health_topic4="+document.getElementById("health_topic_3").value;    
                                appendElementNEW(containerId,'health_topic4',document.getElementById("health_topic_3").value) ;    
        }
        if(document.getElementById("health_topic_4")) {
            url=url+"&health_topic5="+document.getElementById("health_topic_4").value;    
                                appendElementNEW(containerId,'health_topic5',document.getElementById("health_topic_4").value) ;    
        }
    
    /// end of modification
    
    if(document.getElementById("question_alert_me").checked){
        url=url+"&alert_me=1";
                            appendElementNEW(containerId,'alert_me',1) ;    
    }else{
        url=url+"&alert_me=0";
                            appendElementNEW(containerId,'alert_me',0) ;    
    }
    
    if(document.getElementById("new_question_alert").checked){
        url=url+"&alert_new_question=1";
                            appendElementNEW(containerId,'alert_new_question',1) ;    
    }else{
        url=url+"&alert_new_question=0";
                            appendElementNEW(containerId,'alert_new_question',0) ;    
    }
    
    url=url+"&sid="+Math.random();
                        appendElementNEW(containerId,'sid',Math.random()) ;    
     xmlHttp3.onreadystatechange=function(){
        if(xmlHttp3.readyState == 4 && xmlHttp3.status == 200){
 
            var values = xmlHttp3.responseText.split("|");
             //comment : eliminating the newlines from the beginning of the string
            values[0]=values[0].replace(/[\n\r\t]/g,'');
            /// end of newlines elimination
            
            
            if(values[0]=='congratulation'){
                cancel_questionNEW(log4javascript.getLogger());
                // on teste si c'est la 1ère contribution de ce membre
                if(values[1]==1){
                    document.getElementById("q_congratulation_title").innerHTML = '<img src="images/text_images/thank_u_question_first.gif" border="0" />';
                }else{
                    document.getElementById("q_congratulation_title").innerHTML = '<img src="images/text_images/thank_u_question.gif" border="0" />';
                }
                document.getElementById("email_them_question").innerHTML=values[2];
                
                // on affiche la page de congratulation                
                document.getElementById("congratulation_question").style.display='block';
                document.getElementById("preview_question").style.display='none';    
                load_treatments_tab_ordered('questions','most_recent','0');
            }
         }        
    } 
   //  xmlHttp3.open("GET",url,true);
   //  xmlHttp3.send(null); 
   document.getElementById('share_question_formNEW').submit();          
}

function new_link(){    
    containerId='share_link_formNEW_div';
        document.getElementById('share_link_formNEW').action='sharing.php'  ; 
    xmlHttp4=GetXmlHttpObject();
     if (xmlHttp4==null)
      {
          alert ("Browser does not support HTTP Request");
          return;
      }
     var url="includes/ajax.php";
    url=url+"?q=8";     
                        appendElementNEW(containerId,'new_content','new_link') ;    
//    url=url+"&topic="+document.getElementById("link_topic").value;
    url=url+"&title="+document.getElementById("link_title").value;
                        appendElementNEW(containerId,'title',document.getElementById("link_title").value) ;    
    url=url+"&url="+document.getElementById("url").value;
                        appendElementNEW(containerId,'url',document.getElementById("url").value) ;    

 var linkString=new String(tinyMCE.getInstanceById('link_description').getContent()); 
   var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version); 
var pattern;
if (browser=='Microsoft Internet Explorer'){
     pattern='<!--[.]*-->';  
 
} else {
         pattern='<!--[^]*-->';  

}
  //pattern='&lt;!--[^]*--&gt';
  var replacement="";     
  var re = new RegExp(pattern, "g");

  replaced_linkString = linkString.replace(re , replacement);                        
    url=url+"&description="+replaced_linkString;
                        appendElementNEW(containerId,'description',replaced_linkString) ;    
    
    /// modified part
        url=url+"&link_health_topic1="+document.getElementById("link_health_topic").value;    
                            appendElementNEW(containerId,'link_health_topic1',document.getElementById("link_health_topic").value) ;    
        if(document.getElementById("link_health_topic_1")) {
            url=url+"&link_health_topic2="+document.getElementById("link_health_topic_1").value;
                                appendElementNEW(containerId,'link_health_topic2',document.getElementById("link_health_topic_1").value) ;    
        }
        if(document.getElementById("link_health_topic_2")) {
            url=url+"&link_health_topic3="+document.getElementById("link_health_topic_2").value;    
                                appendElementNEW(containerId,'link_health_topic3',document.getElementById("link_health_topic_2").value) ;    
        }
        if(document.getElementById("link_health_topic_3")){
         url=url+"&link_health_topic4="+document.getElementById("link_health_topic_3").value;    
                             appendElementNEW(containerId,'link_health_topic4',document.getElementById("link_health_topic_3").value) ;    
        }
        if(document.getElementById("link_health_topic_4")) {
            url=url+"&link_health_topic5="+document.getElementById("link_health_topic_4").value;    
                                appendElementNEW(containerId,'link_health_topic5',document.getElementById("link_health_topic_4").value) ;    
        }
    
    /// end of modification    
    if(document.getElementById("link_alert_me").checked){
        url=url+"&alert_me=1";
                            appendElementNEW(containerId,'alert_me',1) ;    
    }else{
        url=url+"&alert_me=0";
                            appendElementNEW(containerId,'alert_me',0) ;    
    }
    if(document.getElementById("new_link_alert").checked){
        url=url+"&alert_new_link=1";
                            appendElementNEW(containerId,'alert_new_link',1) ;    
    }else{
        url=url+"&alert_new_link=0";
                            appendElementNEW(containerId,'alert_new_link',0) ;    
    }    
    
    
    url=url+"&sid="+Math.random();
                        appendElementNEW(containerId,'sid',Math.random()) ;    
     xmlHttp4.onreadystatechange=function(){
        if(xmlHttp4.readyState == 4 && xmlHttp4.status == 200){
            var values = xmlHttp4.responseText.split("|");
 
             //comment : eliminating the newlines from the beginning of the string
            values[0]=values[0].replace(/[\n\r\t]/g,'');
            /// end of newlines elimination            
      //          alert('value is:'+values[0]);
            if(values[0]=='congratulation'){
                
                 cancel_webNEW(log4javascript.getLogger());
                // on teste si c'est la 1ère contribution de ce membre
                if(values[1]==1){
                    document.getElementById("link_congratulation_title").innerHTML = '<img src="images/text_images/thank_u_link_first.gif" border="0" />';
                }else{
                    document.getElementById("link_congratulation_title").innerHTML = '<img src="images/text_images/thank_u_link.gif" border="0" />';
                }
                // on affiche la page de congratulation
                document.getElementById("congratulation_link").style.display='block';
                document.getElementById("preview_link_last").style.display='none';
                document.getElementById("email_them_link").innerHTML=values[2];    
                load_treatments_tab_ordered('web','most_recent','0');
                
            }
         }        
    } 
   //  xmlHttp4.open("GET",url,true);
   //  xmlHttp4.send(null);     
   document.getElementById('share_link_formNEW').submit();      
}

 function light_registration(){
     xmlHttpLR=GetXmlHttpObject();
     if (xmlHttpLR==null)
      {
          alert ("Browser does not support HTTP Request");
          return;
      } 
    var url="includes/ajax.php";
     url=url+"?q=3";
    
    if(document.getElementById("email").value==""){
        alert("Please enter your Email");
        return;
     }else if(!isValidEmail(document.getElementById('email').value)){
        alert("Please enter a valid Email");
        return;        
    }
    
    if(document.getElementById("conf_email").value==""){
        alert("Please confirm your Email");
        return;
     }else if(document.getElementById("email").value != document.getElementById("conf_email").value){
        alert("Your email is not correct");
        return;                
    }    
    
    if(document.getElementById("username").value==""){    
        alert("Please enter your username");
        return;
    }
    
    if (document.getElementById("r_password").value==""){
        alert("Please enter your password");
        return;        
    }
    
    if (document.getElementById("conf_password").value==""){
        alert("Please Confirm your password");
        return;        
    }else if(document.getElementById("r_password").value != document.getElementById("conf_password").value){
        alert("Your password is not correct");
        return;                
    }

    if(!document.getElementById('term').checked ) {
        alert("Please accept Dr.everyone.com Terms & Conditions and Privacy Policy");
        return;        
    }
 
 

    if(!document.getElementById('gender_female').checked && !document.getElementById('gender_male').checked  ) {
        alert("Please select your gender");
        return;        
    } else {
        if (document.getElementById('gender_female').checked){
        gender="F";
        } else {
        gender="M";             
        }
    } 
    
       

    url=url+"&email="+document.getElementById("email").value;
    url=url+"&pass="+document.getElementById("r_password").value;
    url=url+"&username="+document.getElementById("username").value;
        url=url+"&gender="+gender;   
     
    url=url+"&sid="+Math.random();
 
     xmlHttpLR.onreadystatechange=RegistrationReturn; 
     xmlHttpLR.open("GET",url,true);
     xmlHttpLR.send(null);
 }
 
 function RegistrationReturn(){ 
    if (xmlHttpLR.readyState==4 || xmlHttpLR.readyState=="complete")
    {
       //        alert('entering registration return');
       //     alert ('response text is:'+xmlHttpLR.responseText);
        if(xmlHttpLR.responseText=="trouve_email"){
            alert("Please choose another email.");
            document.getElementById("error").innerHTML  ="Please choose another email.";
            return false;
        }
        else if(xmlHttpLR.responseText=="trouve_username"){
            alert("Please choose another username.");
            document.getElementById("error").innerHTML  ="Please choose another username.";
            return false;
        }
        else{
            

                if(type=="question"){
                    document.getElementById("profile_detail").innerHTML  = xmlHttpLR.responseText;
                    new_question();
                }
                else if(type=="link"){
                    
                    document.getElementById("profile_detail").innerHTML  = xmlHttpLR.responseText;
                    new_link();                    
                }
                else if(type=="story"){
                    document.getElementById("profile_detail").innerHTML  = xmlHttpLR.responseText;
                    new_story(statut);
                }
                else if(type=="comment"){
                    load_comment(statut,comment_id_contribution);
                }
                else if(type=="answer") {
                    //alert( type+"/"+statut+"/"+comment_id_contribution);    
                    load_answer(type,comment_id_contribution);
                }
                else if(type=='comment_for_answer')
                {
                    load_comment(type,comment_id_contribution);
                }
                else if(type=='treatment' || type=='goal' || type=='best_web' || type=='rate_question' || type=='rate_answer' || type=='article' || type=='fave_question')
                {
                    location.reload() ;
                }
                else if(type=='alerts_for_search_phrases' )
                {
                     check_alerts_phrase(ajaxObject_Alerts_Phrase,log); 
                }                
                else {
                    window.location.replace("health_journal_home.php");
                    //location.reload() ;
                }
                Dialog.cancelCallback();
                
               Windows.closeAll();
               location.reload() ;
            //closeAllModalWindows                      
         
         /* // The old    light registration return
          //  alert ('registration type is:'+type);
            if(type=="question"){
                new_question();                
            }
            else if(type=="link"){
                new_link();
            }
            else if(type=="story"){
            
                new_story(statut);    
                            
            }
             else if(type=='alerts_for_search_phrases' )       /// NEEDS to be checked
                {
                     check_alerts_phrase(ajaxObject_Alerts_Phrase,log); 
                }            
        //    Windows.closeAll();
        //    location.reload() ;
            //closeAllModalWindows
            
          */  
        }
     }
}

 function alerts_best_web(id,obj,table,id_table){
     xmlHttp=GetXmlHttpObject();
     if (xmlHttp==null)
      {
          alert ("Browser does not support HTTP Request");
          return;
      } 
     var url="includes/ajax.php";
    url=url+"?q=4";    
    url=url+"&id_table="+id_table;
    url=url+"&table="+table;
    url=url+"&id="+id;
    
    if(document.getElementById(obj).checked == true){
        alert_me = 1;
    }else{
        alert_me = 0;
    }
    url=url+"&alert_me="+alert_me;     
    url=url+"&sid="+Math.random();
     xmlHttp.onreadystatechange=function(){
        //alert(url);
    } 
     xmlHttp.open("GET",url,true);
     xmlHttp.send(null);
 }

 function topics_alerts(id,field,id_topic){
     xmlHttp=GetXmlHttpObject();
     if (xmlHttp==null)
      {
          alert ("Browser does not support HTTP Request");
          return;
      } 
     var url="includes/ajax.php";
    url=url+"?q=5";    
    url=url+"&field="+field;
    url=url+"&id="+id_topic;
    
    if(document.getElementById(id).checked == true){
        alert_me = 1;
    }else{
        alert_me = 0;
    }
    url=url+"&alert_me="+alert_me;     
    url=url+"&sid="+Math.random();
     xmlHttp.onreadystatechange=function(){
        
    } 
     xmlHttp.open("GET",url,true);
     xmlHttp.send(null);
 }

 function get_topic(id,contribution){
    xmlHttp=GetXmlHttpObject();
     if (xmlHttp==null)
      {
          alert ("Browser does not support HTTP Request");
          return;
      } 
    var url="includes/ajax.php";
    url=url+"?q=6";    
    url=url+"&id="+id;
    url=url+"&sid="+Math.random();
     xmlHttp.onreadystatechange=function(){
        if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
             if(contribution=="question"){
                document.getElementById("preview_question_topic").innerHTML=xmlHttp.responseText;
            }
            else if(contribution=="link"){
                document.getElementById("preview_link_topic").innerHTML=xmlHttp.responseText;
            }
         }        
    } 
     xmlHttp.open("GET",url,true);
     xmlHttp.send(null);
 }

function getStoryFollowUp(){
     
    followUpStory = true;
    xmlHttp=GetXmlHttpObject()
     if (xmlHttp==null)
      {
          alert ("Browser does not support HTTP Request");
          return;
      } 

    var url="includes/ajax.php";    
    url=url+"?q=12";    
    
    if(this.document.form6.story_type[0].checked){
        if(document.getElementById("follow_up_story").value!=-1){
            type_story = "treatment";
            url=url+"&type="+type_story;            
            url=url+"&follow_up_story="+document.getElementById("follow_up_story").value;
            url=url+"&sid="+Math.random();
            xmlHttp.onreadystatechange=FollowUpReturn; 
            xmlHttp.open("GET",url,true);
            xmlHttp.send(null);
        }else{
            document.getElementById("div_family_member").innerHTML = 'Myself';
            document.getElementById("family_member").disabled = false;
            document.getElementById("condition").value = "";
            document.getElementById("condition").disabled=false;
        }
    }else{
        if(document.getElementById("follow_up_story").value!=-1){
            type_story = "goal";
            url=url+"&type="+type_story;                    
            url=url+"&follow_up_story="+document.getElementById("follow_up_story").value;
            url=url+"&sid="+Math.random();
            xmlHttp.onreadystatechange=FollowUpReturn; 
            xmlHttp.open("GET",url,true);
            xmlHttp.send(null);
        }else{
            document.getElementById("div_family_member").innerHTML = 'Myself';
            document.getElementById("family_member").disabled = false;
            document.getElementById("goal").value = "";    
            document.getElementById("goal").disabled=false;
        }    
    }
}

function FollowUpReturn(){ 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {            
            var values = xmlHttp.responseText.split("|");            
            /* On affiche les traitements */
            if(values[23]!=''){
                document.getElementById("treatment").value = values[23];
            }else{
                document.getElementById("treatment").value = '';
            }
            if(values[24]!=''){
                document.getElementById("treatment_1").value = values[24];
                document.getElementById("div_treatment_1").style.display='block';
            }else{
                document.getElementById("treatment_1").value = '';
                document.getElementById("div_treatment_1").style.display='none';
            }
            if(values[25]!=''){
                document.getElementById("treatment_2").value = values[25];
                document.getElementById("div_treatment_2").style.display='block';
            }else{
                document.getElementById("treatment_2").value = '';
                document.getElementById("div_treatment_2").style.display='none';
            }
            if(values[26]!=''){
                document.getElementById("treatment_3").value = values[26];
                document.getElementById("div_treatment_3").style.display='block';
            }else{
                document.getElementById("treatment_3").value = '';
                document.getElementById("div_treatment_3").style.display='none';
            }
            if(values[27]!=''){
                document.getElementById("treatment_4").value = values[27];
                document.getElementById("div_treatment_4").style.display='block';
            }else{
                document.getElementById("treatment_4").value = '';
                document.getElementById("div_treatment_4").style.display='none';
            }            
                    
            
            // on efface les divs contenant les liens
            if(document.getElementById('links_1')) removeElement('links_div','links_1','i_link');
            if(document.getElementById('links_2')) removeElement('links_div','links_2','i_link');
            if(document.getElementById('links_3')) removeElement('links_div','links_3','i_link');
            if(document.getElementById('links_4')) removeElement('links_div','links_4','i_link');
            if(document.getElementById('links_5')) removeElement('links_div','links_5','i_link');
            
            // on affiche les liens
            for(var i =33; i<38; i++){
                if(values[i]!=''){
                    more_link(values[i]);
                }
            }        
                                
            /* Sliders values */
            s.setValue(values[3]);
            s2.setValue(values[4]);
            s3.setValue(values[5]);            
            // easy to follow
            s7.setValue(values[15]);
            // Duration
            s8.setValue(values[16]);            

            // Care provider category speciality
            document.getElementById("category_value").innerHTML = values[54];
            document.getElementById("categorie").value = values[54] ;
            
            // Care provider speciality
            document.getElementById("care_speciality_value").innerHTML = values[14];
            document.getElementById("care_speciality").value = values[14] ;
            
            // on désactive save shared story as
            //document.getElementById("user_statut").value = values[22] ;
            document.getElementById("statut").innerHTML = values[22] ;
            //document.getElementById("user_statut").disabled = true;
            // Start Date
            date_start=values[6].split("/");
            document.getElementById("month_started").value=date_start[0];
            document.getElementById("year_started").value=date_start[1];
            document.getElementById("start_month").innerHTML=date_start[0];
            document.getElementById("start_year").innerHTML=date_start[1];                    
            //si La storie est Ongoing :
            if(values[7]==1){
                document.getElementById("ongoing").checked=true;
            }
            // Date end
            if(values[8]!=''){
                date_end=values[8].split("/");                    
                document.getElementById("end_month").value=date_end[0];
                document.getElementById("end_year").value=date_end[1];                
                document.getElementById("ended_month").innerHTML=date_end[0];
                document.getElementById("ended_year").innerHTML=date_end[1];                                    
            }
        
                /* On affiche les medications */
                if(values[38]!=''){
                    document.getElementById("medication").value = values[38];
                    document.getElementById("dosage").value = values[39];
                    document.getElementById("frequency").value = values[40];
                }else{
                    document.getElementById("medication").value = '';
                    document.getElementById("dosage").value = '';
                    document.getElementById("frequency").value = '';
                }
                if(values[41] && values[41]!=''){
                    more_medication();
                    document.getElementById("medication_1").value = values[41];
                    document.getElementById("dosage_1").value = values[42];
                    document.getElementById("frequency_1").value = values[43];
                }else{
                    if(document.getElementById("medication_1")){
                        removeElement('medications_div','medication_1','i_medications');    
                    }
                }                
                if(values[44] && values[44]!=''){        
                    more_medication();
                    document.getElementById("medication_2").value = values[44];
                    document.getElementById("dosage_2").value = values[45];
                    document.getElementById("frequency_2").value = values[46];
                }else{
                    if(document.getElementById("medication_2")){
                        removeElement('medications_div','medication_2','i_medications');    
                    }
                }
                if(values[47] && values[47]!=''){            
                    more_medication();
                    document.getElementById("medication_3").value = values[47];
                    document.getElementById("dosage_3").value = values[48];
                    document.getElementById("frequency_3").value = values[49];
                }else{
                    if(document.getElementById("medication_3")){
                        removeElement('medications_div','medication_3','i_medications');    
                    }
                }
                if(values[50] && values[50]!=''){                        
                    more_medication();
                    document.getElementById("medication_4").value = values[50];
                    document.getElementById("dosage_4").value = values[51];
                    document.getElementById("frequency_4").value = values[52];
                }else{
                    if(document.getElementById("medication_4")){
                        removeElement('medications_div','medication_4','i_medications');    
                    }
                }
        
            //out of pocket cost
            document.getElementById("out_pocket_cost").value =values[9];
            // Total cost
            document.getElementById("pocket_cost").value =values[11];
            // insurer name
            document.getElementById("insurer_name").value =values[10];
            // provider name
            provider = values[13].split(" ");
            document.getElementById("provider_firstname").value=provider[0];
            document.getElementById("provider_lastname").value=provider[1];            
        
            if(type_story=="treatment"){
                document.getElementById("condition").value = values[0];
                document.getElementById("condition").disabled=true;
                // On positionne la valeur de Family Member
                if(values[1]!=''){                                                    
                    document.getElementById("family_member").value = values[17];
                    document.getElementById("div_family_member").innerHTML = values[17];
                }else{
                    document.getElementById("family_member").value = 'Myself';
                    document.getElementById("div_family_member").innerHTML = 'Myself';
                }
                // On désactive Famlily member
                document.getElementById("family_member").disabled = true;
            
                /* On affiche les symptoms */
                if(values[28]!=''){
                    document.getElementById("symptom").value = values[28];
                }else{
                    document.getElementById("symptom").value = '';
                }
                if(values[29]!=''){
                    document.getElementById("symptom_1").value = values[29];
                    document.getElementById("div_symptom_1").style.display='block';
                }else{
                    document.getElementById("symptom_1").value = '';
                    document.getElementById("div_symptom_1").style.display='none';
                }
                if(values[30]!=''){
                    document.getElementById("symptom_2").value = values[30];
                    document.getElementById("div_symptom_2").style.display='block';
                }else{
                    document.getElementById("symptom_2").value = '';
                    document.getElementById("div_symptom_2").style.display='none';
                }
                if(values[31]!=''){
                    document.getElementById("symptom_3").value = values[31];
                    document.getElementById("div_symptom_3").style.display='block';
                }else{
                    document.getElementById("symptom_3").value = '';
                    document.getElementById("div_symptom_3").style.display='none';
                }
                if(values[32]!=''){
                    document.getElementById("symptom_4").value = values[32];
                    document.getElementById("div_symptom_4").style.display='block';
                }else{
                    document.getElementById("symptom_4").value = '';
                    document.getElementById("div_symptom_4").style.display='none';
                }                
            }else{
                document.getElementById("goal").value = values[0];
                document.getElementById("goal").disabled=true;
                // On positionne la valeur de Family Member
                if(values[1]!=''){
                    document.getElementById("family_member").value = values[17];
                    document.getElementById("div_family_member").innerHTML = values[17];
                }else{
                    document.getElementById("family_member").value = 'Myself';
                    document.getElementById("div_family_member").innerHTML = 'Myself';
                }
                // On désactive Famlily member
                document.getElementById("family_member").disabled = true;

            }    
    }
}

 function getSpeciality(){
    xmlHttp=GetXmlHttpObject();
     if (xmlHttp==null)
      {
          alert ("Browser does not support HTTP Request");
          return;
      } 
    var categorie = document.getElementById("categorie").value;
    var url="includes/ajax.php";
    url=url+"?q=13";    
    url=url+"&categorie="+categorie;
    url=url+"&sid="+Math.random();
     xmlHttp.onreadystatechange=function(){
        if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
             document.getElementById("care_speciality").innerHTML=xmlHttp.responseText;

           /// dodatak za automatsko populisanje druge komponente
           //   document.getElementById('care_speciality').options[0].selected=true;
           //  select_value(
           //  document.getElementById('care_speciality').options[0].value
           //  ,'care_speciality_value');            
         }        
    } 
     xmlHttp.open("GET",url,true);
     xmlHttp.send(null);
 }
 
 ///// COMMENT : new funtion
  function getSpeciality2(){
    xmlHttp=GetXmlHttpObject();
     if (xmlHttp==null)
      {
          alert ("Browser does not support HTTP Request");
          return;
      } 
    var categorie = document.getElementById("categorie2").value;
    var url="includes/ajax.php";
    url=url+"?q=13";    
    url=url+"&categorie="+categorie;
    url=url+"&sid="+Math.random();
     xmlHttp.onreadystatechange=function(){
        if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
             document.getElementById("care_speciality2").innerHTML=xmlHttp.responseText; 
             
             
            /// dodatak za automatsko populisanje druge komponente
            //  document.getElementById('care_speciality2').options[0].selected=true;
            // select_value(
            // document.getElementById('care_speciality2').options[0].value
            // ,'care_speciality_value2');                           
         }        
    } 
     xmlHttp.open("GET",url,true);
     xmlHttp.send(null);
 }
 ////////////////////////////////
 
 function load_selected_results_tab(type)
{
     // alert('load page function');
     // var comment = document.getElementById('comment').value;
      xmlHttp=GetXmlHttpObject();
      if (xmlHttp)
        {
         try
                         {
                           var cache = new Array();
                           cache.push("type="+type); 
                             if ((xmlHttp.readyState == 4 || xmlHttp.readyState == 0) && cache.length > 0)
                               {    
                                    var cacheEntry = cache.shift();
                                    xmlHttp.open("POST","search_results_tab.php", true);
                                    xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
                                    xmlHttp.onreadystatechange = waitForResponse4;
                                    xmlHttp.send(cacheEntry);
                                   }
                         }
                         catch (e)
                         {
                          displayError(e.toString());
                         }
        }
}

function waitForResponse4()
{
 if (xmlHttp.readyState == 4) 
  { 
    if (xmlHttp.status == 200) 
    {
      try
      {
        var response = xmlHttp.responseText;
        //alert(response);
        document.getElementById('tabbed_results_div').innerHTML=response;
      }
      catch(e)
      {
        displayError(e.toString());
      }
    }
    else
    {
      displayError(xmlHttp.statusText);
    }
  }        
}

function load_answer(type,id_question)
{
     // alert('load page function');
   //   var answer = tinyMCE.getInstanceById('comment').getContent();
   ///   
var answerString=new String(tinyMCE.getInstanceById('comment').getContent()); 

var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version); 
var pattern;
if (browser=='Microsoft Internet Explorer'){
 pattern='<!--[.]*-->';  

} else {
     pattern='<!--[^]*-->';  

}
  //pattern='&lt;!--[^]*--&gt';
var replacement="";     

var re = new RegExp(pattern, "g");   

replaced_answerString = answerString.replace(re , replacement);   
var answer=  replaced_answerString;  
 ///  
;
        
      if(answer=="" || answer=="<p>Tell us what worked for you...</p>" 
      || answer.match("Tell us what worked for you")!=null){
          alert("Please write your answer");  
          return;
      }

      xmlHttp=GetXmlHttpObject();
      if (xmlHttp)
        {
         try
                         {
                           var cache = new Array();
                           cache.push("type="+type+"&id_contribution="+id_question+"&comment="
                           +encodeURIComponent(answer)); 
                        //   alert(cache);
                        //    alert ("answer is:"+answer);
                             if ((xmlHttp.readyState == 4 || xmlHttp.readyState == 0) && cache.length > 0)
                               {    
                                    var cacheEntry = cache.shift();
                                    xmlHttp.open("POST","comment_validation.php", true);
                                    xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
                                    xmlHttp.onreadystatechange = waitForResponse5Answer;
                                    xmlHttp.send(cacheEntry);
                                    var browserName=navigator.appName; 
                                   }
                         }
                         catch (e)
                         {
                          displayError(e.toString());
                         }
        }
}

function load_comment(type,id_contribution)
{

     // alert('load page function');   
  ////    var comment = tinyMCE.getInstanceById('comment').getContent();
var commentString=new String(tinyMCE.getInstanceById('comment').getContent()); 

var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version); 
var pattern;
if (browser=='Microsoft Internet Explorer'){
 pattern='<!--[.]*-->';  

} else {
     pattern='<!--[^]*-->';  

}
  //pattern='&lt;!--[^]*--&gt';
var replacement="";     

var re = new RegExp(pattern, "g");   

replaced_commentString = commentString.replace(re , replacement);   
var comment=  replaced_commentString;    
 
   
      if(comment=="" || comment=="<p>What are your thoughts?</p>"
      || comment.match("Write your comment here")!=null ){
          alert("Please write your comment");  
          return;
      }
      
      
      xmlHttp=GetXmlHttpObject();
      if (xmlHttp)
        {
         try
                         {
                           var cache = new Array();
                           cache.push("type="+type+"&id_contribution="+id_contribution+"&comment="
                           +encodeURIComponent(comment)); 
                             if ((xmlHttp.readyState == 4 || xmlHttp.readyState == 0) && cache.length > 0)
                               {    
                                    var cacheEntry = cache.shift();
                                    xmlHttp.open("POST","comment_validation.php", true);
                                    xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
                                    xmlHttp.onreadystatechange = waitForResponse5;
                                    xmlHttp.send(cacheEntry);
                                    var browserName=navigator.appName; 
                                   }
                         }
                         catch (e)
                         {
                          displayError(e.toString());
                         }
        }
}

function waitForResponse5()
{
 if (xmlHttp.readyState == 4) 
  { 
    if (xmlHttp.status == 200) 
    {
      try
      {
        var response = xmlHttp.responseText;
        //alert(response);
        document.getElementById('bloc_comments').innerHTML=response;
        tinyMCE.getInstanceById('comment').setContent("<p>What are your thoughts?</p>");

        editComment();
        location.reload();  
 
      }
      catch(e)
      {
        displayError(e.toString());
      }
    }
    else
    {
      displayError(xmlHttp.statusText);
    }
  }        
}
function waitForResponse5Answer()
{
 if (xmlHttp.readyState == 4) 
  { 
    if (xmlHttp.status == 200) 
    {
      try
      {
        var response = xmlHttp.responseText;
        //alert(response);
        document.getElementById('bloc_comments').innerHTML=response;
        tinyMCE.getInstanceById('comment').setContent("<p>Tell us what worked for you...</p>");
        editAnswer(); 
        location.reload();  
 
      }
      catch(e)
      {
        displayError(e.toString());
      }
    }
    else
    {
      displayError(xmlHttp.statusText);
    }
  }        
}

function confirmSubmit()
{
    var agree=confirm("Are you sure to delete this alert ?");
    if (agree){
        return true ;
    }else{
        return false ;
    }
}

function checkEmailAndCode(formId){

 xmlHttp=GetXmlHttpObject()
      if (xmlHttp==null)
       {
        alert ("Browser does not support HTTP Request");
        return;
       } 
  
    if( ValidateForm(formId) )
     { 
       var url="includes/ajax.php";
       
       if( formId==1 ) 
       {
           url=url+"?q=14&email="+document.getElementById("email").value;
           url=url+"&login="+document.getElementById("username").value;  // cas d'inscription
           url=url+"&code="+document.getElementById("valid_img").value;
          url=url+"&codecounter="+codeCounter;           
       }else{
           
           url=url+"?q=15&email="+document.getElementById("email").value;       
       }
       
       url=url+"&sid="+Math.random();
       
       xmlHttp.onreadystatechange= function(){ 
               if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
               {     
                   var checkResponseNEW= xmlHttp.responseText;
                  // alert(checkResponseNEW);
                   checkResponseNEW=checkResponseNEW.replace(/[\n\r\t]/g,'');     
                   if(checkResponseNEW!="")
                   { 
                    setCode();         
                    alert(xmlHttp.responseText);
                   }
                   else
                   {
                    document.form.submit();      
                   }
               
               }
         }
      
       xmlHttp.open("GET",url,true);
       xmlHttp.send(null);
     } 

     
}



function SendInappropriate(id,action)
{
 
 var msg=''; 
 var error=false;
 
 if(document.getElementById('message').value=='') { 
     alert("Please type your message");
    return;
 }
 
 xmlHttp=GetXmlHttpObject()
  if (xmlHttp==null){
        alert ("Browser does not support HTTP Request");
        return;
  } 
      
  var url="send_inappropriate.php?message="+document.getElementById('message').value+"&id="+id+"&action="+action+"";
          
   xmlHttp.onreadystatechange= function(){ 
           if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
           {          
                alert("Thank you for your input.");
                Windows.closeAll();
           }
    }
        
       xmlHttp.open("GET",url,true);
       xmlHttp.send(null);
}




function formIsCompleted()
{
 
 var msg=''; 
 var error=false;
 var friendExists=false;
 var FriendsMailIncorrect=false;
 
 if(document.getElementById('senderName').value=='')          msg+= "- name\n"; 
 if(document.getElementById('senderEmail').value=='')         msg+= "- email\n";
 if(document.getElementById('message').value=='')         msg+= "- message\n";
 
 if(msg!='') msg="Please type your :\n"+msg;
 
 if( !isValidEmail(document.getElementById('senderEmail').value ) )
     msg+="\nPlease correct your email\n";         
 
  for(i=1;i<6;i++)
 {
   var nom='name'+i; 
   var mail='email'+i;
      
   if(( document.getElementById(nom).value!='' && document.getElementById(mail).value=='' ) 
      || document.getElementById(nom).value=='' && document.getElementById(mail).value!='' ) {
     
     error=true;
   
     
   }
   else if( document.getElementById(nom).value!='' && document.getElementById(mail).value!=''){
   
       friendExists=true; 
     
    } 
    
  if( document.getElementById(mail).value!=''){
     if( ! isValidEmail(document.getElementById(mail).value) )  {
       FriendsMailIncorrect=true;
      }
  }
 }
 
 if( FriendsMailIncorrect==true)  msg+= "\nPlease correct the email of your friend.";
 if (error || !friendExists) msg+= "\nPlease give the name and the email of your friend "; 


 if(msg!='' ) { alert(msg); return;}
 else{
      
     xmlHttp=GetXmlHttpObject()
      if (xmlHttp==null)
       {
        alert ("Browser does not support HTTP Request");
        return;
       } 

 //     var messageString= document.getElementById('message').innerHTML;
      
   var messageString= document.getElementById('message').value;  
 // alert ("original  is: "+messageString);  
    var pattern='\n'; 
  //pattern='&lt;!--[^]*--&gt';
  var replacement=" <br/>";     
  var re = new RegExp(pattern, "g");

  replaced_messageString = messageString.replace(re , replacement); 
 // alert ("replaced is: "+replaced_messageString);        
      
          
      var url="send_mails.php?message="+replaced_messageString+"&senderName="+document.getElementById('senderName').value+"&senderEmail="+document.getElementById('senderEmail').value;
       url = url+ "&name1="+document.getElementById('name1').value+"&email1="+document.getElementById('email1').value;
       url= url+ "&myaction="+document.getElementById('myaction').value;
 url= url+ "&contributionId="+document.getElementById('contributionId').value;   
 

       for(i=2;i<6;i++)
         {
            var nom='name'+i; 
            var mail='email'+i;
            
            url = url + "&name"+i+"="+document.getElementById(nom).value+"&email"+i+"="+document.getElementById(mail).value;
        }
        
   xmlHttp.onreadystatechange= function(){ 
           if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
           {   
                alert('Your email has been sent');       
                Windows.closeAll();
           }
          }
        
       xmlHttp.open("GET",url,true);
       xmlHttp.send(null);
 };
}


function formIsCompleted_Webmail()
{
 
 var msg=''; 
 var error=false;
 var friendExists=false;
 var FriendsMailIncorrect=false;
 
 if(document.getElementById('senderName').value=='')          msg+= "- name\n"; 
 if(document.getElementById('senderEmail').value=='')         msg+= "- email\n";
 if(document.getElementById('message').value=='')         msg+= "- message\n";
 
 if(msg!='') msg="Please type your :\n"+msg;
 
 if( !isValidEmail(document.getElementById('senderEmail').value ) )
     msg+="\nPlease correct your email\n";         
 
/*  for(i=0;i<document.getElementById('total_contacts').value ;i++)
 {
   var nom='name_'+i; 
   var mail='email_'+i;
      
   if(( document.getElementById(nom).value!='' && document.getElementById(mail).value=='' ) 
      || document.getElementById(nom).value=='' && document.getElementById(mail).value!='' ) {
     
     error=true;
   
     
   }
   else if( document.getElementById(nom).value!='' && document.getElementById(mail).value!=''){
   
       friendExists=true; 
     
    } 
    
  if( document.getElementById(mail).value!=''){
     if( ! isValidEmail(document.getElementById(mail).value) )  {
       FriendsMailIncorrect=true;
      }
  }
 }
 
 if( FriendsMailIncorrect==true)  msg+= "\nPlease correct the email of your friend.";
 if (error || !friendExists) msg+= "\nPlease give the name and the email of your friend "; 

*/
 if(msg!='' ) { alert(msg); return;}
 else{
      
     xmlHttp=GetXmlHttpObject()
      if (xmlHttp==null)
       {
        alert ("Browser does not support HTTP Request");
        return;
       } 

 //     var messageString= document.getElementById('message').innerHTML;
      
   var messageString= document.getElementById('message').value;  
 // alert ("original  is: "+messageString);  
    var pattern='\n'; 
  //pattern='&lt;!--[^]*--&gt';
  var replacement=" <br/>";     
  var re = new RegExp(pattern, "g");

  replaced_messageString = messageString.replace(re , replacement); 
 // alert ("replaced is: "+replaced_messageString);        
      
   var actionPage="send_webmails.php";
   if (document.getElementById('provider_box')){
       if (document.getElementById('provider_box').value=="twitter" ||
           document.getElementById('provider_box').value == 'facebook'){
           actionPage="send_socialmails.php";   
       }
   }
   
          
      var url=actionPage+"?message="+replaced_messageString+
      "&provider_box="+document.getElementById('provider_box').value+ 
      "&oi_session_id="+document.getElementById('oi_session_id').value+ 
      "&senderName="+document.getElementById('senderName').value+
      "&senderEmail="+document.getElementById('senderEmail').value+
      "&total_contacts="+document.getElementById('total_contacts').value+
      "&defaultMessageId="+document.getElementById('defaultMessageId').value+
      "&contributionId="+document.getElementById('contributionId').value;    


       for(i=0;i<document.getElementById('total_contacts').value;i++)
         {
            var check="check_"+i; 
            var nom='name_'+i; 
            var mail='email_'+i;
            if  (document.getElementById(check).checked){
                checkValue=true;
            }   else {
                checkValue=false;
            }            
            
            url = url + "&name_"+i+"="+document.getElementById(nom).value+"&email_"+i+"="+document.getElementById(mail).value
            + "&check_"+i+"="+checkValue;
            // alert ("url is:"+url);
            
        }
        
     //    alert ("url is:"+url); 
        
   xmlHttp.onreadystatechange= function(){ 
           if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
           {   
           //    alert(xmlHttp.responseText);
                alert('Your emails have been sent');       
                Windows.closeAll();
           }
          }
        
       xmlHttp.open("GET",url,true);
       xmlHttp.send(null);
 };
}

function addToFaves(id_user,type,id_contribution){
    //alert("thank you");
    if(id_user=="" || id_user==0){
        //alert("You must login");
        checkSession(type,'',id_contribution);
        return;
    }
     xmlHttp=GetXmlHttpObject();
     if (xmlHttp==null)
      {
          alert ("Browser does not support HTTP Request");
          return;
      } 
     var url="includes/ajax.php";
     url=url+"?q=16&user="+id_user;
     url=url+"&type="+type;
     url=url+"&id_contribution="+id_contribution;
     xmlHttp.onreadystatechange=function(){
         if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
           {          
                alert("Added to favorites");
           }
    } 
     xmlHttp.open("GET",url,true);
     xmlHttp.send(null);
 }
 
 function rateStory(id_user,type,id_contribution,note){
    //alert("thank you");
    if(id_user=="" || id_user==0){
        //alert("You must login");
        checkSession(type,'',id_contribution);
        return;
    }
     xmlHttp=GetXmlHttpObject();
     if (xmlHttp==null)
      {
          alert ("Browser does not support HTTP Request");
          return;
      } 
     var url="includes/ajax.php";
     url=url+"?q=17&user="+id_user;
     url=url+"&type="+type;
     url=url+"&id_contribution="+id_contribution;
    url=url+"&note="+note;
     xmlHttp.onreadystatechange=function(){
         if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
           {          
                alert(xmlHttp.responseText);
           }
    } 
     xmlHttp.open("GET",url,true);
     xmlHttp.send(null);
     
 }
 
  function result_poll(objectID){
         //alert("thank you");
     xmlHttp=GetXmlHttpObject();
     if (xmlHttp==null)
      {
          alert ("Browser does not support HTTP Request");
          return;
      } 
     var url="includes/ajax.php";
     url=url+"?q=18";
     xmlHttp.onreadystatechange=function(){
         if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
           {   
           var object = document.getElementById(objectID);
            object.innerHTML = xmlHttp.responseText;
                //alert(note);
           }
    } 
     xmlHttp.open("GET",url,true);
     xmlHttp.send(null);
     
 }
 
function add_article(type){
    xmlHttp=GetXmlHttpObject();
     if (xmlHttp==null)
      {
          alert ("Browser does not support HTTP Request");
          return;
      } 
     var url="includes/ajax.php";
    if(type=="add"){url=url+"?q=19";    }
    else if (type=="modify"){ url=url+"?q=20"; }
    var text = null; var oEditor = FCKeditorAPI.GetInstance('article_texte') ; if(oEditor) { text = oEditor.GetXHTML(true); } 
    var data="title="+document.getElementById("article_title").value+"&texte="+encodeURIComponent(text);
    var k=0;
    //alert(document.getElementById('article_topic_0').value);
    while(document.getElementById('article_topic_'+k).value!=""){
        //alert("ok");
        data=data+"&topic"+k+"="+document.getElementById('article_topic_'+k).value;
        k++;
    }
    if (type=="modify"){ data=data+"&id_article="+document.getElementById("id_contribution").value;}
    //alert(data);
     xmlHttp.onreadystatechange=function(){
        if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
            var response = xmlHttp.responseText;
      alert(response);
      location.reload(true);
            //document.getElementById("q_congratulation_title").innerHTML = '<img src="images/text_images/thank_u_question_first.gif" border="0" />';
         }        
    } 

    xmlHttp.open('POST', url, true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", data.length);
    xmlHttp.setRequestHeader("Connection", "close");
     xmlHttp.send(data);        
}

function topic_search(query){    
    containerId='topic_search_form_div';
    document.getElementById('topic_search_form').action='controller_topic_search.php'  ; 

   appendElementNEW(containerId,'query',query) ; 
 

   appendElementNEW(containerId,'sid',Math.random()) ;    
  
   document.getElementById('topic_search_form').submit();    
   
 
   
     
}

