function popup(url, name, width, height)
{
settings=
"toolbar=no,location=no,directories=no,"+
"status=no,menubar=no,scrollbars=yes,"+
"resizable=yes,width="+width+",height="+height;

MyNewWindow=window.open(url,name,settings);

MyNewWindow.focus();
}
function popupForm(form, name, width, height){
	settings="toolbar=no,location=no,directories=no,"+
	"status=no,menubar=no,scrollbars=yes,"+
	"resizable=yes,width="+width+",height="+height;
	//alert("popupForm");
	MyNewWindow=window.open("about:blank",name,settings);
	//	alert("window.open");
	MyNewWindow.focus();
	form.target=name;
	form.submit();
	return false;
}

function faq(theme)
{
popup("/faq/"+theme,"faq",310,400);
}
function faqLG(theme)
{
popup(theme,"faq",310,400);
}
function faqFull(theme)
{
popup(theme,"faq",800,600);
}
function monstre(theme)
{
popup(theme,"monstre",800,600);
}
function fete(id,fete)
{
popup("/secure/fete.html?id="+id+"&fete="+fete,"fete",500,400);
}

function smileys(file)
{
	if(file==null)
		file="/smileys.html";
popup(file,"smileys",700,400);
}
function linkInParent(ref){
	var url=ref.href;
	opener.document.location.replace(url);
}
function emoticon(text) {
	//text = ' ' + text + ' ';
	if (opener.document.forms['post'].body.createTextRange && opener.document.forms['post'].body.caretPos) {
		var caretPos = opener.document.forms['post'].body.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		opener.document.forms['post'].body.focus();
	} else {
	opener.document.forms['post'].body.value  += text;
	opener.document.forms['post'].body.focus();
	}        
}
function insert(text) {
	text = ' ' + text + ' ';
	if (document.post.body.createTextRange && document.post.body.caretPos) {
		var caretPos = document.post.body.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		document.post.body.focus();
	} else {
	document.post.body.value  += text;
	document.post.body.focus();
	}
}
function storeCaret(textEl) {
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}

function MouseOver(button) {
    button.style.borderStyle="inset";
}
function MouseOut(button) {
 button.style.borderStyle="outset";
}
function switchTab(nom,dest,max){
        for(var i=1;i<=max;i++){
            var name=nom+"-"+i;
            var tab=document.getElementById(name);
            if(tab==null)
                alert("tab not found");
            tab.style.display="none";
            if(i==dest)
               var active=tab;
        }
    // activate active tab
        active.style.display="";      
}   
function highlightMag(id){
	if(highlightMag.highlighted!=null){
		highlightMag.highlighted.style.fontWeight="normal";	
		highlightMag.highlighted.style.color="";		
	}
	if(id!=null){
		var mag=document.getElementById(id);
		mag.style.fontWeight="bold";
		mag.style.color="#990000";
		highlightMag.highlighted=mag;	
	}
	else
		highlightMag.highlighted=null;	
}
function afficheEtab(etabId,classe){
    var name="etab-"+classe+"-"+etabId;
    if(afficheEtab.etab!=null)
        afficheEtab.etab.style.display="none";
    afficheEtab.etab=document.getElementById(name);
    afficheEtab.etab.style.display="";
}

function afficheArb(nom){
   //alert("afficheArb "+nom+"args: "+arguments);
   var name=nom;
   clearAll();
   for(var i=1; i<arguments.length; i++){
        name=name+"-"+arguments[i];
      //  alert(name);
        var mag=document.getElementById(name);
        if(mag!=null){
            afficheArb.affiche[afficheArb.affiche.length]=mag;
            if(afficheArb.affiche[0]==null)
                    alert("bug");
            mag.style.display="";
        }
        var high="text-"+name
    //    alert(high);
        var mag=document.getElementById(high);
        if(mag!=null){
            afficheArb.high[afficheArb.high.length]=mag;
            if(afficheArb.high[0]==null)
                    alert("bug");
            mag.style.fontWeight="bold";
        }
   }
}
function afficheArb(nom){
   //alert("afficheArb "+nom+"args: "+arguments);
   var name=nom;
   clearAll();
   for(var i=1; i<arguments.length; i++){
        name=name+"-"+arguments[i];
      //  alert(name);
        var mag=document.getElementById(name);
        if(mag!=null){
            afficheArb.affiche[afficheArb.affiche.length]=mag;
            if(afficheArb.affiche[0]==null)
                    alert("bug");
            mag.style.display="";
        }
        var high="text-"+name
    //    alert(high);
        var mag=document.getElementById(high);
        if(mag!=null){
            afficheArb.high[afficheArb.high.length]=mag;
            if(afficheArb.high[0]==null)
                    alert("bug");
            mag.style.fontWeight="bold";
        }
   }
}
function selectionneTexte(groupe){
	//alert("selection");
	name="text";
	if(selectionneTexte[groupe]!=null)
		selectionneTexte[groupe].style.fontWeight="normal";
	for(var i=1; i<arguments.length; i++){
        name=name+"-"+arguments[i];
	}
	//alert("name "+name);
	var mag=document.getElementById(name);
	//alert("mag "+mag);
  if(mag!=null){
      selectionneTexte[groupe]=mag;
      mag.style.fontWeight="bold";
  }
}
function highLight(nom){
	
}
function clearAll(){
       if(afficheArb.affiche!=null){
           for(var i=0; i<afficheArb.affiche.length; i++) {
                var mag=afficheArb.affiche[i];
                if(mag==null)
                        alert("mag is null i="+i);
                mag.style.display="none";
           }
       }
       if(afficheArb.high!=null){
           for(var i=0; i<afficheArb.high.length; i++) {
                var mag=afficheArb.high[i];
                if(mag==null)
                        alert("mag is null i="+i);
                mag.style.fontWeight="normal";
           }
       }
       afficheArb.affiche=new Array();
       afficheArb.high=new Array();
}
function afficheFrame(){
        var noframe=document.getElementById("noframe");
        if(noframe!=null)
            noframe.style.visibility="hidden";
        var frame=document.getElementById("iframe");
        frame.style.display="";
        return true;
}
function cacheTabs(){ 

        var noframe=document.getElementById("noframe");
        if(noframe!=null)
            noframe.style.display="none";
        var frame=document.getElementById("iframe");
        frame.style.display="none";
        return true;
}
function reload_parent(url){
    top.location.reload(url);
}
function goTop(){
    if(top!=window){
        var url=window.location.url;
        top.location.reload(url);
    }
}
function positionne(nb, nom){
    var max;
    var position;
    var inventaire=document.getElementById("invBlock");
    if(inventaire!=null){
          var name=nom;
          for(var i=2; i<arguments.length; i++)
                name=name+"-"+arguments[i];
            var suivant=document.getElementById(name);
            if(suivant==null)
                nb--;
            if(nb>1)
                var pos=215*(nb-1);
            else
                pos=0;
            positionne.max=nb;
            positionne.position=nb;
            inventaire.style.marginLeft="-"+pos+"px";    
          //  var right=pos+620;
           // inventaire.style.clip="rect(auto "+right+"px auto "+pos+"px)";

    }
    afficheScroll();
}
function scroll(value){
    var nb=positionne.position+value;
   // alert("scroll "+value+" "+nb);
    if(nb>0&&nb<=positionne.max){
        positionne.position=nb;
        if(nb>1)
            var pos=215*(nb-1)
        else
            pos=0
        var inventaire=document.getElementById("invBlock");
        inventaire.style.marginLeft="-"+pos+"px"; 
      //  var right=pos+620;
      //  inventaire.style.clip="rect(auto "+right+"px auto "+pos+"px)"; 

    }
    afficheScroll();
}
function afficheScroll(){
   var fleche=document.getElementById("flecheGauche");
    if(positionne.position>1)
        fleche.style.visibility="visible";
    else
        fleche.style.visibility="hidden";
    fleche=document.getElementById("flecheDroite");
    if(positionne.position<positionne.max)
        fleche.style.visibility="visible";
    else
        fleche.style.visibility="hidden";
}
function select(formName, name) {
    var form=document.getElementById(formName);
    if(form!=null) {
      var nodes=form[name];
      if(nodes!=null){
            if(nodes.length==undefined){
                if(nodes.checked==false)
                    nodes.checked=true;
                else
                    nodes.checked=false;
               return;
            }
            var allchecked=true;
            for(var i=0;i<nodes.length;i++) {
                var elt=nodes[i];
                if(elt.type=="checkbox"){
                        if(elt.checked==false)
                            allchecked=false;
                        elt.checked=true;
                }
            }
            if(allchecked){
                for(var i=0;i<nodes.length;i++) {
                        nodes[i].checked=false;
                }
            }
        }
    }
    else
        alert("form null");
}
function confirmDelete(formName, name){
    var form=document.getElementById(formName);
    if(form!=null) {
        var nodes=form[name];
        if(nodes==null){
            alert("vous n'avez aucun message");
            return;
        }
        var count=0;
        if(nodes.length==undefined && nodes.checked)
                count=1;   
        else{
            for(var i=0;i<nodes.length;i++) {
                if( nodes[i].checked)
                    count++;
            }
        }
        if(count==0){
            alert("Vous devez selectionnez les messages ? supprimer");
            return false;
            }
        if(count==1)
            return confirm("Voulez vous supprimer ce message ?")
        return confirm("Voulez vous supprimer ces "+count+" messages ?")
    }
}
function confirmIfChecked(id, texte){
	var checkbox=document.getElementById(id);
    if(checkbox.checked){
    	return confirm(texte);
    }
    return true;	
}

function resizeIframe() {

	// Must launched on the body onload event handler for IE
	// Use document.documentElement if you are in Compat mode
	i = parent.document.getElementById(window.name)
	iHeight = document.body.scrollHeight
	i.style.height = iHeight + 5 + "px"
}
function resizeIframeLarge() {

	// Must launched on the body onload event handler for IE
	// Use document.documentElement if you are in Compat mode
	i = parent.document.getElementById(window.name)
	iHeight = document.body.scrollHeight
	i.style.height = iHeight + 100 + "px"
}
function scrollToIframe(){
        frame = parent.document.getElementById(window.name)
        frame.scrollIntoView(false);
}
function scrollToId(id){
        element = document.getElementById(id);  
        element.scrollIntoView(true);
}
function showActionAff(){
    var id=showAction.id;
    tab=document.getElementsByName("ouvert-"+id);
    for(var i=0; i<tab.length; i++){
        tab[i].style.display="";
    }
    tab=document.getElementsByName("ferme-"+id);
    for(var i=0; i<tab.length; i++){
        tab[i].style.display="none";
    }
}
function showAction(id){
    if(showAction.ActionVisibleid!=null){
        var tab=document.getElementsByName("ouvert-"+showAction.ActionVisibleid);
   //     alert("tab length "+tab.length+" id "+showAction.ActionVisibleid);
        for(var i=0; i<tab.length; i++){
            tab[i].style.display="none";
        }
        tab=document.getElementsByName("ferme-"+showAction.ActionVisibleid);
        for(var i=0; i<tab.length; i++){
            tab[i].style.display="";
        }
    }
    showAction.id=id;
    showActionAff();
   // setTimeout("showActionAff()", 500);
    showAction.ActionVisibleid=id;
}

function getTabByName(id){
    elt=document.getElementById(id);
    alert("elt : "+elt+" id: "+id);
    if(elt==null)
        return new Array();
    else if(elt.length==undefined){
        var tab=new Array();
        tab[0]=elt;
        return tab;
    }
    else
        return elt;
}
function showdrop(id){
    elt=document.getElementById("dropdown-"+id);
    if(elt.style.display=="none"){
            elt.style.display="";
        }
    else
        elt.style.display="none";
}
function validateDrop(dropid,eltid){
    hid=document.getElementById("drop-"+dropid);
    hid.value=eltid;
    showdrop(dropid);
    if(hid.form.onsubmit){
    	if(hid.form.onsubmit())
    		hid.form.submit();
    }
    else
    	hid.form.submit();
   hid.value="";
}
ActionSwitcher=function(){
	this.before=new Object();
	this.after=new Object();
};
ActionSwitcher.prototype.setCurrentElement=function(element, value){
	this[element]=value;
}
ActionSwitcher.prototype.switchElement=function(element, selecteur){
		var value=selecteur.options[selecteur.selectedIndex].value;
		this.setElement(element,value);
}
ActionSwitcher.prototype.setElement=function(element, value){
	var oldvalue=this[element];
	if(oldvalue!=null){
		var beforeElt=this.before[element+"_"+oldvalue];
		var afterElt=this.after[element+"_"+oldvalue];
		if(beforeElt!=null && beforeElt.parentNode!=null)
			beforeElt.parentNode.removeChild(beforeElt);
		if(afterElt!=null)
			afterElt.parentNode.removeChild(afterElt);
	}
	if(value!=null){
		this[element]=value;
		var beforeElt=this.before[element+"_"+value];
		var afterElt=this.after[element+"_"+value];
		beforeDiv=document.getElementById("dynbefore_"+element);	
	  afterDiv=document.getElementById("dynafter_"+element);
		if(beforeDiv!=null && beforeElt!=null)
			beforeDiv.appendChild(beforeElt)
		if(afterDiv!=null && afterElt!=null)
			afterDiv.appendChild(afterElt);
	}
}
ActionSwitcher.prototype.registerElement=function(element,value){
	var beforeElt=document.getElementById("dynbefore_"+element+"_"+value);
	if(beforeElt!=null){
		beforeElt.parentNode.removeChild(beforeElt);
		this.before[element+"_"+value]=beforeElt;
		beforeElt.style.display="";
	}	
	var afterElt=document.getElementById("dynafter_"+element+"_"+value);
		if(afterElt!=null){
		afterElt.parentNode.removeChild(afterElt);
		this.after[element+"_"+value]=afterElt;
		afterElt.style.display="";
	}	
}
var actionSwitcher= new ActionSwitcher();
ActionSwitch=function(){
	this.old=new Object();
};
ActionSwitch.prototype.SwitchElement=function(element, selecteur){
	var value=selecteur.options[selecteur.selectedIndex].value;
	//alert("switeElement");
	this.setElement(element,value);
}
ActionSwitch.prototype.hideElement=function(element,value,hide){
		//alert("switchElement "+element+" "+value+" "+hide);
	var beforeElt=document.getElementById("dynbefore_"+element+"_"+value);
	if(beforeElt!=null){
		if(hide)
			beforeElt.style.display="none";
		else
			beforeElt.style.display="";
	}	
	var afterElt=document.getElementById("dynafter_"+element+"_"+value);
	if(afterElt!=null){
		if(hide)
			afterElt.style.display="none";
		else
			afterElt.style.display="";
	}
		
}
ActionSwitch.prototype.hideAll=function(element,value,hide){
	var beforeElt=document.getElementById("dynbefore_"+element);
	
	tab=beforeElt.childNodes;
//	alert("hideAll bef "+tab+"");
  for(var i=0; i<tab.length; i++){
  	//	alert("hideAll bef "+i);
  			if(tab[i].nodeType==1 && tab[i].style.display==""){
        	tab[i].style.display="none";
        	break;
  			}
  }
  var afterElt=document.getElementById("dynafter_"+element);
  tab=afterElt.childNodes;
 // alert("hideAll afterElt "+tab);
  for(var i=0; i<tab.length; i++){
       if(tab[i].nodeType==1 && tab[i].style.display==""){
        	tab[i].style.display="none";
        	break;
  		}
  }
}
ActionSwitch.prototype.clear=function(){
	this.old=new Object();
}
ActionSwitch.prototype.setElement=function(element, value){
	//alert("setElement "+element+" "+value);
	var oldvalue=this.old[element];

	if(oldvalue!=null){
		this.hideElement(element,oldvalue,true);
	}
	else
		this.hideAll(element);
		//alert("setElement after hide "+value);
	if(value!=null){
		this.old[element]=value;
		this.hideElement(element,value,false);
	}
}

var actionSwitch= new ActionSwitch();
function ouvreLive(id){
	var left;
	var URL;
	URL="http://sms.rentabiliweb.com/SMSLive.php?idP="+id;
	left = ((screen.width - 320) / 2);
	win = window.open(URL, "Micropaiement", "toolbar=0,scrollbars=0,location=0,status=0,menubar=0,directories=0,resizable=0,width=310,height=191,left="+left+",top=40")
}
function alerteKarma(quantite){
	alert("il vous faut "+quantite+" pts de karma");
}
function karmabuy(karma){
	alerteKarma(karma);
	opener.document.location.reload("/secure/karmabuy.svm");
}
function karmabuyConfirm(quantite){
	return confirm("cette operation vous coutera "+quantite+" pts de karma");
}
function karmabuySelf(karma){
	alerteKarma(karma);
	document.location.reload("/secure/karmabuy.svm");
}
function useForwarder(objet){
	 if(objet.href.substr(0,7)=="http://")
				objet.href="/forward/"+objet.href.substr(7);
		 	return true;
}
function fold(name){

	elt=document.getElementById(name);
	if(elt!=null){
		if(elt.style.display=="none"){
			elt.style.display="";
		}
		else
			elt.style.display="none";
	}
	return false;
}
function fold_group(classe,fold){
	rule=null;
		styles=document.styleSheets;
		 for(var i=0; i<styles.length; i++){
		 		if(styles[i].title=="folder_groupe"){
		 				sheet=styles[i];
		 				break;
		 		}
		 }
		 if(sheet!=null){
		 	//	alert("sheet "+sheet);
		 		if(sheet.cssRules)
					crossrule=sheet.cssRules;
				else if(sheet.rules)
					crossrule=sheet.rules;
				if(crossrule!=null && crossrule.length>0){
						 for(var i=0; i<crossrule.length>0; i++){
						 		if(crossrule[i].selectorText=="."+classe){
						 				rule=i;
						 				break;
						 		}
						 }
					}
					//alert("crossrule.length "+crossrule.length+" rule "+rule);
					if(rule!=null && fold!=true){
							if(sheet.deleteRule)
			 					sheet.deleteRule(rule);
			 				else if(sheet.removeRule)
			 					sheet.removeRule(rule);	 					
					}
		 			else if(rule==null && fold!=false){
		 				if(sheet.insertRule)
		 					sheet.insertRule("."+classe+" { display: none;}",0);
		 				else{
		 					sheet.addRule("."+classe,"display: none;");

		 				}
		 		}			
		 }
		 return false;
}



