var catId = null;

function InitPDS()
{
	//AddCategoryClicks(); //moved in load function
	MovePartners();
	//Pour être plus rapide la requete ajax est faites juste après l'affichage de la div categories
  //load("includes/ajaxleft_cat.php","ajax=1","categories");
}
function AddCategoryClicks()
{
	var catList = $("catList");
	if (catList)
	{
		for (var i = 0; i < catList.childNodes.length; i++)
		{
			var catItem = catList.childNodes[i];		
			if (catItem.id != undefined)
			{
				var catLink = null;
				
				for (var j = 0; j < catItem.childNodes.length; j++)
				{
					if (catItem.childNodes[j].className == "parent")
					{
						catLink = catItem.childNodes[j];
						break;
					}
				}
				if (catLink != null)
				{
					catLink.onclick = function() { CategoryClick(this); return false; }
				}
			}
		}
	}
}
function MovePartners()
{
	var p = $("partners");
	if (p)
	{
		var w = $("wrapper");
		var wL = FindObjectLeft(w);
		var wW = parseInt(((w.currentStyle) ? w.currentStyle.width : document.defaultView.getComputedStyle(w, null).getPropertyValue("width")).replace("px", ""));	
		p.style.left = (wL + wW) + "px";
	}
}
function FindObjectLeft(obj)
{
	var curLeft = 0;
	if (obj.offsetParent)
	{
		curLeft = obj.offsetLeft
		while (obj = obj.offsetParent)
		{
			curLeft += obj.offsetLeft
		}
	}
	return curLeft;
}
function CategoryClick(obj)
{
	var treeNode = obj.parentNode;
	var className = treeNode.className;

	treeNode.className = (className == "expand") ? "" : "expand";

	if (catId && treeNode.id != catId) { $(catId).className = ""; }

	catId = treeNode.id;
}
function $(id)
{
	return document.getElementById(id);
}

//Menu
function jump(targ,selObj,restore)
{
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}

//For ajax
function load(page, param, target_id) {
    if (window.all && !window.opera){
        var XhrObj = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else {
        var XhrObj = new XMLHttpRequest();
 
    }
 
    var target = document.getElementById(target_id);
 
    XhrObj.open("POST", page, true);
 
    XhrObj.onreadystatechange = function() {
        if (XhrObj.readyState == 4 && XhrObj.status == 200)
        target.innerHTML = XhrObj.responseText;
 
        var scripts = target.getElementsByTagName("script")
        for (var i = 0; i < scripts.length; ++i) {
            var s = scripts[i];
            if (!s.text) {
                dump(s);
                dump("len =" + scripts.length + "   i=" + i);
 
            }
            if (s.text) {
                eval(s.text);
 
            }
 
        }
        AddCategoryClicks();
 
 
    }
    XhrObj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    XhrObj.send(param);
 
}

function favoris()
{
	if ( navigator.appName != 'Microsoft Internet Explorer' )
	{
 		window.sidebar.addPanel("Portaildusexe.com","http://www.portaildusexe.com/index.php","");
  }
  else
  {
  	window.external.AddFavorite("http://www.portaildusexe.com/index.php","Portaildusexe.com");
  }
}

function copier(nom_chp_txt,nom_form)
{
	var chp_txt = eval("document." + nom_form + "." + nom_chp_txt);
  chp_txt.focus();
  chp_txt.select();
  texte = chp_txt.createTextRange();
  texte.execCommand("Copy");
}

//AJAX - Module avis videos

function file(fichier)
     {
     if(window.XMLHttpRequest) // FIREFOX
          xhr_object = new XMLHttpRequest();
     else if(window.ActiveXObject) // IE
          xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
     else
          return(false);
     xhr_object.open("GET", fichier, false);
     xhr_object.send(null);
     if(xhr_object.readyState == 4) return(xhr_object.responseText);
     else return(false);
     }

function AvisVideo(id){
	if(id != ''){
        if(texte = file('./get_avis_video.php?id='+id)){
					writediv('avis-video',texte,id);
        }
     }
}
function ie_eval(id) { 
  var scripts = document.getElementById(id).getElementsByTagName("script");
  for (var i = 0; i < scripts.length;++i) {
      var s = scripts[i];
      if (!s.text) {
          dump(s);
          dump("len =" + scripts.length + "   i=" + i);
      }
      if (s.text) {
          eval(s.text);
      }
  }
}
function VoirVideo(id){
	if(id != ''){
        if(texte = file('./get_video.php?id='+id)){
					writediv('voir-video',texte,id);
        }
     }
}

function writediv(nomdiv,texte,id){
	document.getElementById(nomdiv+id).innerHTML = texte;
	ie_eval(nomdiv+id);
}

//Compte le nombre de caractères
function CheckLen(Target)
{
	StrLen = Target.value.length
	if (StrLen > 250 )
	{
		Target.value = Target.value.substring(0,250);
		CharsLeft = 250;
	}

	else
	{
		CharsLeft = 250-StrLen;
	}
	document.forms[0].caracteres.value = CharsLeft;
}

//Ligne en surbrillance
function setPointer(theRow, thePointerColor)
{
if(typeof(theRow.style) == 'undefined' || typeof(theRow.cells) == 'undefined'){return false;}
var row_cells_cnt= theRow.cells.length;
for(var c = 0; c < row_cells_cnt; c++){theRow.cells[c].bgColor = thePointerColor;}
return true;
}

//Confirmation
function confirmation(txt,url)
{
if(confirm(txt)){document.location.href=''+url+'';}
}

function count(id, type, trc)
{
if(document.images)
(new Image()).src="/count_out.php?id=" + id + "&type=" + type + "&tracker=" + trc;
return true;
}

//Clignotement du formulaire du catcheur
var clignotte = true;
var OldValue='Entre ton email ici';
var EmptyValue = 'Entre ton email ici'; 
function clignoteArobase(nbr) {
	if(clignotte == true) {
		if(nbr == 0) {
			if(OldValue!='') OldValue = document.formulaire.form_email.value;
			document.formulaire.form_email.value = OldValue;
			nbr = 1;
		} else {
			document.formulaire.form_email.value = '';
			nbr = 0;
		}
		if('@' =='@'){
			setTimeout("clignoteArobase("+nbr+")",500);
		}
	}
}
function StopClignotte() {
	clignotte = false;
	return clignotte;
}

function clickee() {
	clickeeRun(0,0);
}

function clickeeRun(nbr,maxNbr) {
	if(document.formulaire.form_email.value == ''){
		document.formulaire.form_email.value = EmptyValue;
	}
	if(maxNbr < 10 ) {
		if(nbr == 0 ) {
			document.getElementById("form_email").style.backgroundColor = '#FFF61A';
			document.getElementById("form_email").style.color = '#FFF';
			nbr = 1;
		} else {
			document.getElementById("form_email").style.backgroundColor = '#fff';
			document.getElementById("form_email").style.color = '#000';
			nbr = 0;
		}
		maxNbr++;
		setTimeout("clickeeRun("+nbr+","+maxNbr+")",100);
	}
}
