

function update_password(context_path)
{
  if(trimString(document.getElementById("old_pass").value) ==''
  || trimString(document.getElementById("pass").value) ==''
  || trimString(document.getElementById("passv2").value) ==''
  )
  {
    alert("Παρακαλώ πληκτρολογήστε όλα τα υποχρεωτικά πεδία.");
  }
  else
  {
    document.getElementById("load_update_password").innerHTML="<img align='absmiddle' src='"+context_path+"/images/loader2.gif'/>" ;
    var parameters = "current_pass=" + encodeURIComponent( document.getElementById("old_pass").value ) +
    "&new_pass=" + encodeURIComponent( document.getElementById("pass").value )+
    "&confirm_pass=" + encodeURIComponent( document.getElementById("passv2").value );
    
    http.open('POST',context_path+"/UpdatePassword" , true);
    http.onreadystatechange = function(){SendUpdatePassword();};
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", parameters.length);
    http.setRequestHeader("Connection", "close");
    http.send(parameters);  
  }
}

function SendUpdatePassword()
{
      if (http.readyState == 4)
      {
         if (http.status == 200)
         {
            var response = http.responseText;
            document.getElementById("load_update_password").innerHTML="" ;
            alert(response);
         } 
         else
         {
            document.getElementById("load_update_password").innerHTML="" ;
            alert('Σφάλμα κατά την φόρτωση των δεδομένων.Παρακαλώ προσπάθηστε ξανά αργότερα.');
         }
      }
     
}

function update_account(context_path)
{
  if(trimString(document.getElementById("email").value) ==''
  || trimString(document.getElementById("name").value) ==''
  || trimString(document.getElementById("sex").value) =='0'
  || trimString(document.getElementById("birth_day").value) =='0'
  || trimString(document.getElementById("birth_month").value) =='0'
  || trimString(document.getElementById("birth_year").value) =='0'
  )
  {
    alert("Παρακαλώ πληκτρολογήστε όλα τα υποχρεωτικά πεδία.");
  }
  else
  {
    var informed = 0;
    if(document.getElementById("inform_user").checked)
    {
      informed = 1;
    }
    document.getElementById("load_update_account").innerHTML="<img align='absmiddle' src='"+context_path+"/images/loader2.gif'/>" ;
    var parameters = "email=" + encodeURIComponent( document.getElementById("email").value ) +
    "&name=" + encodeURIComponent( document.getElementById("name").value )+
    "&surname=" + encodeURIComponent( document.getElementById("surname").value )+
    "&sex=" + encodeURIComponent( document.getElementById("sex").value )+
    "&birth_day=" + encodeURIComponent( document.getElementById("birth_day").value )+
    "&birth_month=" + encodeURIComponent( document.getElementById("birth_month").value )+
    "&birth_year=" + encodeURIComponent( document.getElementById("birth_year").value )+
    "&inform_user=" + informed;
    
    http.open('POST',context_path+"/UpdateAccount" , true);
    http.onreadystatechange = function(){SendUpdateAccount();};
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", parameters.length);
    http.setRequestHeader("Connection", "close");
    http.send(parameters);  
  }
}

function SendUpdateAccount()
{
      
      if (http.readyState == 4)
      {
         if (http.status == 200)
         {
            var response = http.responseText;
            document.getElementById("load_update_account").innerHTML="" ;
            alert('Οι αλλαγές στον λογαριασμό σας αποθηκεύτηκαν με επιτυχία.');
         } 
         else
         {
            document.getElementById("load_update_account").innerHTML="" ;
            alert('Σφάλμα κατά την φόρτωση των δεδομένων.Παρακαλώ προσπάθηστε ξανά αργότερα.');
         }
         
      }
     
}


function transfer_saved_results(context_path,favorite_id)
{
  var response= confirm("Θα μεραφερθείτε στα αποτελέσματα αναζήτησης που μόλις επιλέξατε.Είστε σίγουρος;");
  if (response== true)
  {
    var URL = context_path+"/TransferSavedResults.jsp?favorite_id="+favorite_id;
    window.location.replace(URL);
  }
}



function save_note(context_path,favorite_id)
{
  var URL = context_path+"/AddFavoriteNote.jsp?favorite_id="+favorite_id;
  windowHandle=window.open(URL,"my_new_window",'width=670,height=280,scrollbars,left=500,top=350');
  windowHandle.focus();
  /*if(trimString(document.getElementById(favorite_id+"_text").value)=="")
  {
    alert("please type your note")
  }*/
  /*else
  {
    var parameters = "favorite_id=" + encodeURIComponent( favorite_id ) +
    "&note=" + encodeURIComponent( document.getElementById(favorite_id+"_text").value );
    http.open('POST',context_path+"/AddFavoriteNote" , true);
    http.onreadystatechange = function(){SendFavoriteNote();};
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", parameters.length);
    http.setRequestHeader("Connection", "close");
    http.send(parameters);               
  }*/
}

/*function SendFavoriteNote()
{
      if (http.readyState == 4)
      {
         if (http.status == 200)
         {
            var response = http.responseText;
            alert('Note was saved succesfully.');
         } 
         else
         {
            alert('There was a problem saving the data you typed.');
         }
      }
     
}*/

function show_password(context_path)
{
   document.getElementById("load_profile").style.display='';
   document.getElementById("load_profile").innerHTML="<img align='absmiddle' src='"+context_path+"/images/loader_big.gif'/>" ;
   document.getElementById('guides').style.color='';
   document.getElementById('favorites').style.color='';
   document.getElementById('searches').style.color='';
   document.getElementById('password').style.color='red';
   document.getElementById('account').style.color='';
   
   http.open('get', context_path+"/GetUserPassword");
   http.onreadystatechange = function(){ShowPassword();};
   http.send(null);
}

function ShowPassword() 
{
    if(http.readyState == 4)
    {
       
      if(http.status==200)
      {
        var response = http.responseText;
        document.getElementById("profile_area").innerHTML = response;
      }  
      else
      {
        alert("Σφάλμα κατά την φόρτωση των δεδομένων.Παρακαλώ προσπάθηστε ξανά αργότερα.");
      }
      document.getElementById("load_profile").innerHTML="" ;
      document.getElementById("load_profile").style.display='none';
    }
}

function show_account(context_path)
{
   document.getElementById("load_profile").style.display='';
   document.getElementById("load_profile").innerHTML="<img align='absmiddle' src='"+context_path+"/images/loader_big.gif'/>" ;
   document.getElementById('guides').style.color='';
   document.getElementById('favorites').style.color='';
   document.getElementById('searches').style.color='';
   document.getElementById('password').style.color='';
   document.getElementById('account').style.color='red';
   
   http.open('get', context_path+"/GetUserAccount");
   http.onreadystatechange = function(){ShowAccount();};
   http.send(null);
}

function ShowAccount() 
{
    if(http.readyState == 4)
    {
       
      if(http.status==200)
      {
        var response = http.responseText;
        document.getElementById("profile_area").innerHTML = response;
      }  
      else
      {
        alert("Σφάλμα κατά την φόρτωση των δεδομένων.Παρακαλώ προσπάθηστε ξανά αργότερα.");
      }
      document.getElementById("load_profile").innerHTML="" ;
      document.getElementById("load_profile").style.display='none';
    }
}


function show_searches(context_path)
{
   document.getElementById("load_profile").style.display='';
   document.getElementById("load_profile").innerHTML="<img align='absmiddle' src='"+context_path+"/images/loader_big.gif'/>";
   document.getElementById('guides').style.color='';
   document.getElementById('favorites').style.color='';
   document.getElementById('searches').style.color='red';
   document.getElementById('account').style.color='';
   document.getElementById('password').style.color='';
   http.open('get', context_path+"/GetUserSearches");
   http.onreadystatechange = function(){ShowSearches();};
   http.send(null);
}

function show_remove_searches(context_path,favorite_id)
{
   document.getElementById("load_profile").innerHTML="<img align='absmiddle' src='"+context_path+"/images/loader_big.gif'/>" ;
   http.open('get', context_path+"/GetUserSearches?favorite_id="+favorite_id);
   http.onreadystatechange = function(){ShowSearches();};
   http.send(null);
}

function ShowSearches() 
{
    if(http.readyState == 4)
    {
       
      if(http.status==200)
      {
        var response = http.responseText;
        document.getElementById("profile_area").innerHTML = response;
      }  
      else
      {
        alert("Σφάλμα κατά την φόρτωση των δεδομένων.Παρακαλώ προσπάθηστε ξανά αργότερα.");
      }
      document.getElementById("load_profile").innerHTML="" ;
      document.getElementById("load_profile").style.display='none';
    }
}





