function slide(idimg,img)
{
  document.getElementById('img_all').innerHTML = "<img src='"+img+"' />";
  document.getElementById('img_all').onload = function() {
    document.getElementById('img_all').innerHTML= "Now Loading";
  };
}

function PopupImage(img) {
	w=open("",'image','width=400,height=400'); //,location=no,directories=no,status=no,menubar=no,toolbar=no,scrollbars=no,resizable=no');
	w.document.write("<HTML><HEAD><TITLE>cTTns Image</TITLE></HEAD>");
	w.document.write("<SCRIPT language=javascript>function checksize()  { if (document.images[0].complete) {  window.resizeTo(document.images[0].width+0,document.images[0].height+70); window.focus();} else { setTimeout('check()',250) } }</"+"SCRIPT>");
	w.document.write("<BODY onload='checksize()' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0 style='background-color:black;'><IMG src='"+img+"' border=0>");
	w.document.write("<br /><div style='text-align:center;'><a style='color:white;text-decoration:none;' href='' onclick='javascript:window.close();'>Fermer la fenêtre</a>");
	w.document.write("</BODY></HTML>");
	w.document.close();
}

function req(url,id,sp,title,prs,b)
{
    if (sp == 's')
    {
      document.getElementById('url').innerHTML = unescape('http://cttns.com/'+url);
      document.getElementById('h_title').innerHTML = title;
      url = '/s_'+url;
      document.title = 'cTTns - '+title;
    }
    var xhr_object = null;
    var position = id;
     if(window.XMLHttpRequest) {
      try {
        xhr_object = new XMLHttpRequest();
      }
      catch (e) {
        xhr_object = false;
      }
     }
     else
     {
      if (window.ActiveXObject) {
        try {
          xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e) {
          xhr_object = false;
        }
      }
     }
     if (xhr_object)
     {
      window.scrollTo (0,0);url=url.substring(1);
      if (typeof(prs) != 'undefined') xhr_object.open('POST', "/"+url, true);
      else xhr_object.open('GET', "/"+url, true);
      xhr_object.onreadystatechange = function() {
      if (xhr_object.readyState == 4)
      {
          document.getElementById(position).innerHTML = xhr_object.responseText;
          get_btn ();
          get_a (position);
          if (title == 'S\'enregistrer' && sp == 's' && document.getElementById('div_umenu').innerHTML == ""){
            req ('/menu', 'div_umenu', '', 'test');  }
          else if (sp != 's') menub ();
          if (typeof(b) != 'undefined') b.disabled = false;
      } else if (position !='div_umenu') document.getElementById('div_change').innerHTML = "<img src='/images/ajax-loader.gif' align='right' />Veuillez attendre.<br />En cours de chargement...";
      }
     }

    if (typeof(prs) != 'undefined')
    {
      xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
      var txt = '';
      for (var v in prs)
      {
        txt+= v+'='+escape(prs[v])+'&';
      }
      xhr_object.send(txt);
    }
    else
      xhr_object.send(null);
}

var tab_menu = [
  "signin", "register", "items", "categories", "contact", "faq", "search"
];

var tab_menub = [
  "add_category", "add_subcategory", "add_item", "your_profil", "your_cotations", "your_items"
];

function menua ()
{
  for (i = 0; i < tab_menu.length; i++)
  {
    document.getElementById(tab_menu[i]).onclick = function () {
       var ctt = this.innerHTML;
       req(this.id+'.html', 'div_change', 's', ''+ctt);
       return false; };
  }
}

function menub ()
{
  for (i = 0; i < tab_menub.length; i++)
  {
    if (document.getElementById(tab_menub[i]) != null)
    document.getElementById(tab_menub[i]).onclick = function () {
       var ctt = this.innerHTML;
       req(this.id+'.html', 'div_change', 's', ''+ctt);
       return false; };
  }
}

function load ()
{
  menua ();
  menub ();
  get_a ('div_change');
  //get_a ('div_help');
  get_btn ();
}

function get_a (d_n)
{
  t_div = document.getElementById(d_n);
  if (typeof(t_div) != 'undefined')
  {
    t_div_c = t_div.childNodes;
    if (typeof(t_div_c) != 'undefined')
    {
      for (i = 0; i < t_div_c.length; i++)
      {
        if (t_div_c[i].nodeType == 1 && t_div_c[i].nodeName == 'A')
        {
          t_div_c[i].onclick = function () {
            var ctt = this.innerHTML;
            exp=new RegExp("^http://(www.)?cttns.com/(.*)$");
            t=exp.exec(this.href);
            if (typeof(t) != 'undefined') req (t[2], 'div_change', 's', ctt);
            return false;
          }
        }
      }
    }
  }
}

function ele (f)
{
  frm = document.getElementById (f);
  var prs = Array();
  for (var i = 0; i < frm.elements.length; i++)
  {
    if (frm.elements[i].type == 'radio') {
      if (frm.elements[i].checked == true)
        prs[frm.elements[i].name] = frm.elements[i].value;
    }
    else
      prs[frm.elements[i].name] = frm.elements[i].value;
  }
  return prs;
}

function set_btn (btn_n, frm, pge, tt)
{
  btn = document.getElementById (btn_n);
  if (btn != null)
  {
    btn.onclick = function () {
      var prs = ele (frm);
      this.disabled = true;
      req (pge, 'div_change', 's', tt, prs, this);
      return false;
    }
  }

}

function get_btn ()
{
  set_btn ('btn_ctc', 'form_ctc', 'contact.html', 'Contact');
  set_btn ('btn_crtcpte', 'form_crtcpte', 'register.html', 'Créer un Compte');
  set_btn ('btn_cct', 'form_cct', 'signin.html', 'S\'enregistrer');
  set_btn ('btn_cctb', 'form_cct', 'signin.html', 'S\'enregistrer');
  set_btn ('btn_cc', 'form_cc', 'add_category.html', 'Ajouter une Catégorie');
  set_btn ('btn_csc', 'form_csc', 'add_subcategory.html', 'Ajouter une Sous-catégorie');
  set_btn ('btn_maj', 'form_maj', 'your_profil.html', 'Votre Profil');
  set_btn ('btn_abus', 'form_abus', 'report.html', 'Reporter un Abus');
  set_btn ('btn_btq', 'form_btq', 'your_cotations.html', 'Vos Estimations');
  set_btn ('btn_ac', 'form_ac', 'add_cotation.html', 'Ajouter une Estimation');
  set_btn ('btn_rech', 'form_rech', 'search.html', 'Recherche');
  set_btn ('btn_upc', 'form_upc', 'update_cotation.html', 'Mettre à jour Estimation');
}

function set_mb ($t)
{

}

window.onload = load;


