/* call register form ---------------------------------------------------------------------------------------------------- */
function showRegister()
{
  var oXmlHttp = createXMLHttp();
  link = "action/show_register.php";
  document.body.style.cursor = "wait";
  oXmlHttp.open("get",link,true);
  oXmlHttp.onreadystatechange = function (){
        if( oXmlHttp.readyState == 4)
        {
          if(oXmlHttp.status == 200)
          {
            // do something
            var response = oXmlHttp.responseText
            var el4 = document.getElementById('content');
            el4.innerHTML = response;
          }
          else
          {
            alert("status:" + oXmlHttp.statusText);
          }
          document.body.style.cursor = "default";
        }
    }
  oXmlHttp.send(null);
}
/* sign up ---------------------------------------------------------------------------------------------------------------- */
function checkSignup1()
{
  var oXmlHttp = createXMLHttp();
  var el1 = document.getElementById('user');
  if(el1.value == '')
  {
    alert("You have to input your Login Name!");
    return;
  }
  var sParam = "user_name="+encodeURIComponent(el1.value);
  var sParams = new Array();
  sParams.push(sParam);
  //
  el1 = document.getElementById('email');
  if(!test(el1.value))
  {
    alert("You have to input your valid email address!");
    return;
  }
  sParam = "user_email="+encodeURIComponent(el1.value);
  sParams.push(sParam);
  // The Password a bit complicated
  el1 = document.getElementById('pass');
  if(!el1.value)
  {
    alert("You have to input Password!");
    return;
  }
  var el2 = document.getElementById('pass1');
  if(el1.value != el2.value)
  {
    alert("Your Password did mot match with Retype!");
    return;
  }
  sParam = "user_pass="+encodeURIComponent(el1.value);
  sParams.push(sParam);
  // rest unchange able ------------------------------
  el1 = document.getElementById('provider');
  if(el1.checked)
  {
    sParam = "provider="+encodeURIComponent(el1.value);
    sParams.push(sParam);
  }
  //
  el1 = document.getElementById('company');
  if(el1.checked)
  {
    sParam = "company="+encodeURIComponent(el1.value);
    sParams.push(sParam);
  }
  //
  el1 = document.getElementById('consumer');
  if(el1.checked)
  {
    sParam = "consumer="+encodeURIComponent(el1.value);
    sParams.push(sParam);
  }
  //
  el1 = document.getElementById('pshow');
  if(el1.checked)
  {
    sParam = "pshow="+encodeURIComponent(el1.value);
    sParams.push(sParam);
  }
  //
  el1 = document.getElementById('names');
  sParam = "names="+encodeURIComponent(el1.value);
  sParams.push(sParam);
  //
  el1 = document.getElementById('pweb');
  sParam = "pweb="+encodeURIComponent(el1.value);
  sParams.push(sParam);
  //
  el1 = document.getElementById('pemail');
  sParam = "pemail="+encodeURIComponent(el1.value);
  sParams.push(sParam);
  //
  el1 = document.getElementById('phone');
  sParam = "phone="+encodeURIComponent(el1.value);
  sParams.push(sParam);
  //
  el1 = document.getElementById('mobile');
  sParam = "mobile="+encodeURIComponent(el1.value);
  sParams.push(sParam);
  //
  link = "action_signup.php?"+sParams.join("&");
  document.body.style.cursor = "wait";
  oXmlHttp.open("get",link,true);
  oXmlHttp.onreadystatechange = function (){
        if( oXmlHttp.readyState == 4)
        {
          if(oXmlHttp.status == 200)
          {
            // do something
            var response = oXmlHttp.responseText
            var el4 = document.getElementById('content');
            el4.innerHTML = response;
          }
          else
          {
            alert("status:" + oXmlHttp.statusText);
          }
          document.body.style.cursor = "default";
        }
    }
  oXmlHttp.send(null);
}
/* update personal data ------------------------------------------------------------------------------------ */
function checkUpdate()
{
  var oXmlHttp = createXMLHttp();
  var el1 = document.getElementById('user');
  if(el1.value == '')
  {
    alert("You have to input your Login Name!");
    return;
  }
  var sParam = "user_name="+encodeURIComponent(el1.value);
  var sParams = new Array();
  sParams.push(sParam);
  //
  el1 = document.getElementById('email');
  if(!test(el1.value))
  {
    alert("You have to input your valid email address!");
    return;
  }
  sParam = "user_email="+encodeURIComponent(el1.value);
  sParams.push(sParam);
  // The Password a bit complicated
  el1 = document.getElementById('pass');
  if(!el1.value)
  {
    alert("You have to input Password!");
    return;
  }
  var el2 = document.getElementById('pass1');
  if(el1.value != el2.value)
  {
    alert("Your Password did mot match with Retype!");
    return;
  }
  sParam = "user_pass="+encodeURIComponent(el1.value);
  sParams.push(sParam);
  // rest unchange able ------------------------------
  el1 = document.getElementById('provider');
  if(el1.checked)
  {
    sParam = "provider="+encodeURIComponent(el1.value);
    sParams.push(sParam);
  }
  //
  el1 = document.getElementById('company');
  if(el1.checked)
  {
    sParam = "company="+encodeURIComponent(el1.value);
    sParams.push(sParam);
  }
  //
  el1 = document.getElementById('consumer');
  if(el1.checked)
  {
    sParam = "consumer="+encodeURIComponent(el1.value);
    sParams.push(sParam);
  }
  //
  el1 = document.getElementById('pshow');
  if(el1.checked)
  {
    sParam = "pshow="+encodeURIComponent(el1.value);
    sParams.push(sParam);
  }
  //
  el1 = document.getElementById('names');
  sParam = "names="+encodeURIComponent(el1.value);
  sParams.push(sParam);
  //
  el1 = document.getElementById('pweb');
  sParam = "pweb="+encodeURIComponent(el1.value);
  sParams.push(sParam);
  //
  el1 = document.getElementById('pemail');
  sParam = "pemail="+encodeURIComponent(el1.value);
  sParams.push(sParam);
  //
  el1 = document.getElementById('phone');
  sParam = "phone="+encodeURIComponent(el1.value);
  sParams.push(sParam);
  //
  el1 = document.getElementById('mobile');
  sParam = "mobile="+encodeURIComponent(el1.value);
  sParams.push(sParam);
  //
  link = "action_update.php?"+sParams.join("&");
  document.body.style.cursor = "wait";
  oXmlHttp.open("get",link,true);
  oXmlHttp.onreadystatechange = function (){
        if( oXmlHttp.readyState == 4)
        {
          if(oXmlHttp.status == 200)
          {
            // do something
            var response = oXmlHttp.responseText
            var el4 = document.getElementById('content');
            el4.innerHTML = response;
          }
          else
          {
            alert("status:" + oXmlHttp.statusText);
          }
          document.body.style.cursor = "default";
        }
    }
  oXmlHttp.send(null);
}
/* ajax style login --------------------------------------------------------------------------------------- */
function login()
{
  var oXmlHttp = createXMLHttp();
  var el1 = document.getElementById('loguser');
  if(el1.value == '')
  {
    alert("You have to input your Login Name!");
    return;
  }
  var sParam = "user_name="+encodeURIComponent(el1.value);
  var sParams = new Array();
  sParams.push(sParam);
  //
  el1 = document.getElementById('logpass');
  if(!el1.value)
  {
    alert("You have to input your Login Password!");
    return;
  }
  sParam = "user_pass="+encodeURIComponent(el1.value);
  sParams.push(sParam);
  //
  link = "action_login.php?"+sParams.join("&");
  document.body.style.cursor = "wait";
  oXmlHttp.open("get",link,true);
  oXmlHttp.onreadystatechange = function (){
        if( oXmlHttp.readyState == 4)
        {
          if(oXmlHttp.status == 200)
          {
            // do something
            var response = oXmlHttp.responseText;
            var rObject =  eval('(' + response + ')');
            if(rObject.error == 'none')
            {
              var el4 = document.getElementById('content');
              el4.innerHTML = rObject.tpl;
            }
            else
            {
              alert("error:"+rObject.error);
            }
          }
          else
          {
            alert("status:" + oXmlHttp.statusText);
          }
          document.body.style.cursor = "default";
        }
    }
  oXmlHttp.send(null);
}
/* ajax style login with redirect --------------------------------------------------------------------------------------- */
function need_login()
{
  var oXmlHttp = createXMLHttp();
  var el1 = document.getElementById('loguser');
  if(el1.value == '')
  {
    alert("You have to input your Login Name!");
    return;
  }
  var sParam = "user_name="+encodeURIComponent(el1.value);
  var sParams = new Array();
  sParams.push(sParam);
  //
  el1 = document.getElementById('logpass');
  if(!el1.value)
  {
    alert("You have to input your Login Password!");
    return;
  }
  sParam = "user_pass="+encodeURIComponent(el1.value);
  sParams.push(sParam);
  //
  link = "action_login_redirect.php?"+sParams.join("&");
  document.body.style.cursor = "wait";
  oXmlHttp.open("get",link,true);
  oXmlHttp.onreadystatechange = function (){
        if( oXmlHttp.readyState == 4)
        {
          if(oXmlHttp.status == 200)
          {
            // do something
            var response = oXmlHttp.responseText;
            var rObject =  eval('(' + response + ')');
            if(rObject.error == 'none')
            {
              var el4 = document.getElementById('content');
              el1 = document.getElementById('action_id');
              if(el1.value)
              {
                getAction(el1.value);
              }
            }
            else
            {
              alert(rObject.error);
            }
          }
          else
          {
            alert("status:" + oXmlHttp.statusText);
          }
          document.body.style.cursor = "default";
        }
    }
  oXmlHttp.send(null);
}
/* get action put in content */
function getAction(action_id)
{
  var oXmlHttp = createXMLHttp();
  document.body.style.cursor = "wait";
  oXmlHttp.open("get",action_id,true);
  oXmlHttp.onreadystatechange = function (){
        if( oXmlHttp.readyState == 4)
        {
          if(oXmlHttp.status == 200)
          {
            // do something
            var response = oXmlHttp.responseText;
            var el4 = document.getElementById('content');
            el4.innerHTML = response;
          }
          else
          {
            alert("status:" + oXmlHttp.statusText);
          }
          document.body.style.cursor = "default";
        }
    }
  oXmlHttp.send(null);
}
/* alias manipulating functions --------------------------------------------------------------------------------- */
function addAlias()
{
  var oXmlHttp = createXMLHttp();
  var el1 = document.getElementById('alias');
  if(el1.value)
  {
    var sParam = "known_as="+encodeURIComponent(el1.value);
    var sParams = new Array();
    sParams.push(sParam);
    //
    el1 = document.getElementById('place');
    sParam = "known_at="+encodeURIComponent(el1.value);
    sParams.push(sParam);
    //
    el1 = document.getElementById('lang');
    sParam = "lang="+encodeURIComponent(el1.value);
    sParams.push(sParam);
    link = "action_add_alias.php?"+sParams.join("&");
    document.body.style.cursor = "wait";
    oXmlHttp.open("get",link,true);
    oXmlHttp.onreadystatechange = function (){
        if( oXmlHttp.readyState == 4)
        {
          if(oXmlHttp.status == 200)
          {
            // do something
            var response = oXmlHttp.responseText;
            var rObject =  eval('(' + response + ')');
            if(rObject.error == 'none')
            {
              var el4 = document.getElementById('content');
              el4.innerHTML = rObject.tpl;
            }
            else
            {
              alert(rObject.error);
            }
          }
          else
          {
            alert("status:" + oXmlHttp.statusText);
          }
          document.body.style.cursor = "default";
        }
    }
    oXmlHttp.send(null);
  }
}
//
function removeAliast(known_as, known_at, user_id)
{
  if(confirm("Do you wish to delete alias "+known_as+" ?")==true)
  {
    var oXmlHttp = createXMLHttp();
    link = "action_delete_alias.php?known_as="+encodeURIComponent(known_as)+"&known_at="+encodeURIComponent(known_at);
    document.body.style.cursor = "wait";
    oXmlHttp.open("get",link,true);
    oXmlHttp.onreadystatechange = function (){
        if( oXmlHttp.readyState == 4)
        {
          if(oXmlHttp.status == 200)
          {
            // do something
            var response = oXmlHttp.responseText;
            var rObject =  eval('(' + response + ')');
            if(rObject.error == 'none')
            {
              var el4 = document.getElementById('content');
              el4.innerHTML = rObject.tpl;
            }
            else
            {
              alert(rObject.error);
            }
          }
          else
          {
            alert("status:" + oXmlHttp.statusText);
          }
          document.body.style.cursor = "default";
        }
    }
    oXmlHttp.send(null);
  }
}
//
function saveDescription()
{
  var oXmlHttp = createXMLHttp();
  var el1 = document.getElementById('sdescr');
  link = "action_save_description.php?short_descr="+encodeURIComponent(el1.value);
    document.body.style.cursor = "wait";
    oXmlHttp.open("get",link,true);
    oXmlHttp.onreadystatechange = function (){
        if( oXmlHttp.readyState == 4)
        {
          if(oXmlHttp.status == 200)
          {
            // do something
            var response = oXmlHttp.responseText;
            var rObject =  eval('(' + response + ')');
            if(rObject.error == 'none')
            {
              alert(rObject.result);
            }
            else
            {
              alert(rObject.error);
            }
          }
          else
          {
            alert("status:" + oXmlHttp.statusText);
          }
          document.body.style.cursor = "default";
        }
    }
    oXmlHttp.send(null);
}
/* --------------------------------------------------------------------------------------------------------- */
/* search and browseing finction related functions                                                                                  */
/* --------------------------------------------------------------------------------------------------------- */
function searchWhoiswho()
{
  var oXmlHttp = createXMLHttp();
  var el1 = document.getElementById('s');
  link = "action_search.php?src_txt="+encodeURIComponent(el1.value);
    document.body.style.cursor = "wait";
    oXmlHttp.open("get",link,true);
    oXmlHttp.onreadystatechange = function (){
        if( oXmlHttp.readyState == 4)
        {
          if(oXmlHttp.status == 200)
          {
            // do something
            var response = oXmlHttp.responseText;
            var rObject =  eval('(' + response + ')');
            if(rObject.error == 'none')
            {
              var el4 = document.getElementById('content');
              el4.innerHTML = rObject.tpl;
            }
            else
            {
              alert("error:"+rObject.error);
            }
          }
          else
          {
            alert("status:" + oXmlHttp.statusText);
          }
          document.body.style.cursor = "default";
        }
    }
    oXmlHttp.send(null);
}
/* */
/* show user details */
function showDetails(user_id)
{
    var oXmlHttp = createXMLHttp();
    link = "action_details.php?user_id="+encodeURIComponent(user_id);
    document.body.style.cursor = "wait";
    oXmlHttp.open("get",link,true);
    oXmlHttp.onreadystatechange = function (){
        if( oXmlHttp.readyState == 4)
        {
          if(oXmlHttp.status == 200)
          {
            // do something
            var response = oXmlHttp.responseText;
            var el = document.getElementById("content");
            el.innerHTML = response;
          }
          else
          {
            alert("status:" + oXmlHttp.statusText);
          }
          document.body.style.cursor = "default";
        }
    }
    oXmlHttp.send(null);
}
/* ---------------------- upload images finctions ---------------------------------------------------------------------*/
// javascript finction 
function setUpper(i)
{
  el = document.getElementById("icontainer");
  if(el)
  {
    s = el.innerHTML;
    parent.setPhoto1(s,i);
  }
}
/* */
function setPhoto1(s,i)
{
  var el;
  switch(i)
  {
    case 1:       // need login
      el = document.getElementById("content");
      el.innerHTML = s;
      break;
    default :     // upload image
      el = document.getElementById("photos");
      var q;
      q = el.innerHTML
      el.innerHTML = q+s;
  }
}
/* remove myPhoto */
function removeImage(g_id)
{
  if(confirm("Do you wish to delete image?")==true)
  {
    var oXmlHttp = createXMLHttp();
    link = "action_remove_photo.php?g_id="+encodeURIComponent(g_id);
    document.body.style.cursor = "wait";
    oXmlHttp.open("get",link,true);
    oXmlHttp.onreadystatechange = function (){
        if( oXmlHttp.readyState == 4)
        {
          if(oXmlHttp.status == 200)
          {
            // do something
            var response = oXmlHttp.responseText;
            var el = document.getElementById("content");
            el.innerHTML = response;
          }
          else
          {
            alert("status:" + oXmlHttp.statusText);
          }
          document.body.style.cursor = "default";
        }
    }
    oXmlHttp.send(null);
  }
}
/* **************************************************************************************************************** */
/* invitation related functions                                                                                     */
/* **************************************************************************************************************** */
function showInvite()
{
    var oXmlHttp = createXMLHttp();
    link = "action_show_invite.php";
    document.body.style.cursor = "wait";
    oXmlHttp.open("get",link,true);
    oXmlHttp.onreadystatechange = function (){
        if( oXmlHttp.readyState == 4)
        {
          if(oXmlHttp.status == 200)
          {
            // do something
            var response = oXmlHttp.responseText;
            var el = document.getElementById("content");
            el.innerHTML = response;
          }
          else
          {
            alert("status:" + oXmlHttp.statusText);
          }
          document.body.style.cursor = "default";
        }
    }
    oXmlHttp.send(null);
}
function saveInvite()
{
  var oXmlHttp = createXMLHttp();
  var sParams = new Array();
  var el1 = document.getElementById('iemail');
  if(!test(el1.value))
  {
    alert("You have to input your valid email address!");
    return;
  }
  sParam = "inv_email="+encodeURIComponent(el1.value);
  sParams.push(sParam);
  //
  el1 = document.getElementById('pdescr');
  sParam = "pdescr="+encodeURIComponent(el1.value);
  sParams.push(sParam);
  //
  link = "action_send_invitation.php?"+sParams.join("&");
    document.body.style.cursor = "wait";
    oXmlHttp.open("get",link,true);
    oXmlHttp.onreadystatechange = function (){
        if( oXmlHttp.readyState == 4)
        {
          if(oXmlHttp.status == 200)
          {
            // do something
            var response = oXmlHttp.responseText;
            var rObject =  eval('(' + response + ')');
            if(rObject.error == 'none')
            {
              alert(rObject.result);
            }
            else
            {
              alert(rObject.error);
            }
          }
          else
          {
            alert("status:" + oXmlHttp.statusText);
          }
          document.body.style.cursor = "default";
        }
    }
    oXmlHttp.send(null);
}