
var stab=null;
var smtab=null;

function initMenu() {
    var obj=document.getElementById(defaultMenu);
    setMenu(obj);
    obj=document.getElementById(defaultSubMenu);
    if (obj) setSubMenu(obj);
}

function setMenu(obj) {
    var sm=null;
//    if (stab==null || stab.id!=obj.id) {
	if (stab!=null) {
	    stab.className="";
	    sm=document.getElementById('s'+stab.id);
	    if(sm) sm.style.display="none";
	}
	if (smtab) {
	    smtab.className="";
	    smtab=null;
	}
	obj.className="here";
	sm=document.getElementById('s'+obj.id);
	if (sm) sm.style.display="";
	stab=obj;
	//alert(homeuri+'content.php','menu='+obj.id);
        if (ajax!=0) callDB(homeuri+'content.php','menu='+obj.id,'content');
//    }
}

function setSubMenu(obj) {
    if (smtab) smtab.className="";
    if (smtab==null || smtab.id!=obj.id) {
	obj.className="here";
	smtab=obj;
	if (ajax!=0) callDB(homeuri+'content.php','menu='+stab.id+'&submenu='+obj.id,'content');
    }
}

function setSubMenuA(id) {
    var obj=document.getElementById(id);
    if (obj) setSubMenu(obj);
}

function showVideo(url) {
    var data='agent='+homeagent+'&ip='+homeip+'&url='+url.replace('&','%26')+'&ref='+homeref.replace('&','%26');
    callDB(homeuri+'count.php',data,'');
    window.open(url);
    return false;
}

function showVideoID(url,id) {
    var data='agent='+homeagent+'&ip='+homeip+'&url='+url.replace('&','%26')+'&ref='+homeref.replace('&','%26')+'&videoid='+id;
    callDB(homeuri+'count.php',data,'');
    window.open(url);
    return false;
}

function showOnlyWithURL(url) {
    window.open(url);
    return false;
}

function callDB(php,data,cid){
   var xhr_object = null;

   if(window.XMLHttpRequest) // Firefox
      xhr_object = new XMLHttpRequest();
   else if(window.ActiveXObject) // Internet Explorer
      xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
   else { // XMLHttpRequest non supporté par le navigateur
      alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
      return;
   }

   xhr_object.open("POST", php, true);

   xhr_object.onreadystatechange = function() {
      if(xhr_object.readyState == 4) {
	  if (cid!='') {
	      var html=document.getElementById(cid);
	      if (html) html.innerHTML=xhr_object.responseText;
	  }
      }
   }

   xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   xhr_object.send(data);
}

function setSearch(obj) {
    var txt=document.getElementById('search');
    callDB(homeuri+'content.php','menu=search&submenu='+txt.value,'content');
    return false;
}

function submitForm(action) {
    var f=document.getElementById("loginw");
    if (f) {
	var obj=document.getElementById("action");
	if (obj) obj.value=action;
	f.submit();
    }
    return false;
}

