var NomNav, Hauteur, Largeur;
NomNav=navigator.appName;
Hauteur=screen.height;
Largeur=screen.width;

if (top.frames.length!=0) top.location=self.document.location;

/*
function VersionNavigateur(Netscape, Explorer){
	if ((navigator.appVersion.substring(0,3) >= Netscape && navigator.appName == 'Netscape') || (navigator.appVersion.substring(0,3) >= Explorer && navigator.appName.substring(0,9) == 'Microsoft')) 
	return true;
		else return false;
} // VersionNavigateur
*/

function popUp(strURL,strType,strWidth,strHeight,nomPop){
	var strOptions="";
	if (strType=="console") strOptions="scrollbars,resizable,resizable,height="+strHeight+",width="+strWidth;
	if (strType=="fixed") strOptions="status,height="+strHeight+",width="+strWidth;
	if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth;
	window.open(strURL, nomPop, strOptions);
} // popUp


/// Categories (hover)
window.onload=montre;
function montre(id){
	var MaxCat=40;
	var d = document.getElementById(id);
	for(var i = 1; i<=MaxCat; i++){
		if (document.getElementById('smenu'+i)){document.getElementById('smenu'+i).style.display='none';}
	}
	if (d){d.style.display='block';}
}

// Nettoie le champ de recherche
function clean(cleanfield){
document.getElementById(cleanfield).value = '';
} // clean

function writediv(texte)
{
document.getElementById('pseudobox').innerHTML = texte;
}

function writediv2(texte2)
{
document.getElementById('pseudobox2').innerHTML = texte2;
}

function verifPseudo(Login_utilisateur)
{
if(Login_utilisateur != '')
{
  var exp=new RegExp("^[a-zA-Z0-9]{1,31}$","g");
  if ( exp.test(Login_utilisateur) ) {writediv2('<span style="color:#1A7917"><b>'+Login_utilisateur+' :</b> ce login est valide</span>'); }
  else {writediv2('<span style="color:#cc0000"><b>'+Login_utilisateur+' :</b> ce login contient des caractères spéciaux</span>');}
if(Login_utilisateur.length<2)
writediv('<span style="color:#cc0000"><b>'+Login_utilisateur+' :</b> ce login est trop court</span>');
else if(Login_utilisateur.length>30)
writediv('<span style="color:#cc0000"><b>'+Login_utilisateur+' :</b> ce login est trop long</span>');
else if(texte = file('../../verifpseudo.php?pseudo='+escape(Login_utilisateur)))
{
if(texte == 1)
writediv('<span style="color:#cc0000"><b>'+Login_utilisateur+' :</b> ce login est déja pris</span>');
else if(texte == 2)
writediv('<span style="color:#1A7917"><b>'+Login_utilisateur+' :</b> ce login est libre</span>');
else
writediv(texte);
}
}

}




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);
}

var currentlyActiveInputRef = false;
var currentlyActiveInputClassName = false;

function highlightActiveInput()
{
	if(currentlyActiveInputRef){
		currentlyActiveInputRef.className = currentlyActiveInputClassName;
	}
	currentlyActiveInputClassName = this.className;
	this.className = 'inputHighlighted';
	currentlyActiveInputRef = this;
	
	
}

function blurActiveInput()
{
	this.className = currentlyActiveInputClassName;
	
	
}


function initInputHighlightScript()
{
	var tags = ['INPUT','TEXTAREA'];
	
	for(tagCounter=0;tagCounter<tags.length;tagCounter++){
		var inputs = document.getElementsByTagName(tags[tagCounter]);
		for(var no=0;no<inputs.length;no++){
			if(inputs[no].className && inputs[no].className=='doNotHighlightThisInput')continue;
			
			if(inputs[no].tagName.toLowerCase()=='textarea' || (inputs[no].tagName.toLowerCase()=='input' && inputs[no].type.toLowerCase()=='text')){
				inputs[no].onfocus = highlightActiveInput;
				inputs[no].onblur = blurActiveInput;
			}
		}
	}
}


var xmlhttp
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
  try {
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
 } catch (e) {
  try {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  } catch (E) {
   xmlhttp=false
  }
 }
@else
 xmlhttp=false
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 try {
  xmlhttp = new XMLHttpRequest();
 } catch (e) {
  xmlhttp=false
 }
}
function myXMLHttpRequest() {
  var xmlhttplocal;
  try {
    xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP")
 } catch (e) {
  try {
    xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP")
  } catch (E) {
    xmlhttplocal=false;
  }
 }

if (!xmlhttplocal && typeof XMLHttpRequest!='undefined') {
 try {
  var xmlhttplocal = new XMLHttpRequest();
 } catch (e) {
  var xmlhttplocal=false;
  alert('couldn\'t create xmlhttp object');
 }
}
return(xmlhttplocal);
}


function sndReq(rcp_name,vote,id_num,ip_num) {
	
	var element = document.getElementById('star_long');
    element.innerHTML = '<img src="interface/logos/ajaxloader.gif" />';
	
    xmlhttp.open('get', rcp_name+'.php?j='+vote+'&q='+id_num+'&t='+ip_num);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);
	
}

function SessionLogin() {
	
	var element = document.getElementById('login');
    element.innerHTML = '<em>Loading ...</em>';
	
    xmlhttp.open('get', 'gabarits/infosession.php');
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);
	
	
}


function Commentaire() {

 if(document.fiche_ajout.Nom.value == "")  {
   alert("Veuillez entrer un Nom!");
   document.fiche_ajout.Nom.focus();
   document.getElementById("Nom-div").style.visibility="visible";
   return false;
  }
 if(document.fiche_ajout.Email.value == "")  {
   alert("Veuillez entrer un E-mail!");
   document.fiche_ajout.Email.focus();
   document.getElementById("Email-div").style.visibility="visible";
   return false;
  }
  if(document.fiche_ajout.Texte.value.length<5)  {
   alert("Ce message est trop court!");
   document.fiche_ajout.Texte.focus();
   document.getElementById("Texte-div").style.visibility="visible";
   return false;
  }

	
	var element = document.getElementById('ajoutcommentaire');

	
	var Ref = document.fiche_ajout.Ref.value;
	var Modele = document.fiche_ajout.Modele.value;
	var Nom = document.fiche_ajout.Nom.value;
	var Email = document.fiche_ajout.Email.value;
	var Website = document.fiche_ajout.Website.value;
	var Titre = document.fiche_ajout.Titre.value;
	var Texte = document.fiche_ajout.Texte.value;
	
	element.innerHTML = '<img src="interface/logos/ajaxloader.gif" />';
	
    xmlhttp.open('POST', 'gabarits/ajoutcommentaire.php');
	xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xmlhttp.send("Ref="+Ref+"&Modele="+Modele+"&Nom="+Nom+"&Email="+Email+"&Website="+Website+"&Titre="+Titre+"&Texte="+Texte);
}

function okpasok(bool,id,elementdiv) {
	
	var element = document.getElementById(elementdiv);
    element.innerHTML = '<img src="../interface/logos/ajaxloader.gif" />';
	
    xmlhttp.open('GET','valide_com.php?bool='+bool+'&id='+id+'&div='+elementdiv);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);
	
}

function handleResponse() {


    if(xmlhttp.readyState == 4){
		 if (xmlhttp.status == 200){
       	
        var response = xmlhttp.responseText;
        var update = new Array();

        if(response.indexOf('|') != -1) {
            update = response.split('|');
			
            changeText(update[0], update[1]);
			
        }
		
		 }
    }
}



function changeText( div2show, text ) {
    // Detect Browser
    var IE = (document.all) ? 1 : 0;
    var DOM = 0; 
    if (parseInt(navigator.appVersion) >=5) {DOM=1};

    // Grab the content from the requested "div" and show it in the "container"

    if (DOM) {
        var viewer = document.getElementById(div2show)
        viewer.innerHTML=text
    }
    else if(IE) {
        document.all[div2show].innerHTML=text
    }
}



function showHideAnswer()
{
	var numericID = this.id.replace(/[^\d]/g,'');
	var obj = document.getElementById('a' + numericID);
	if(obj.style.display=='block'){
		obj.style.display='none';
	}else{
		obj.style.display='block';
	}		
}


function initShowHideContent()
{
	var divs = document.getElementsByTagName('DIV');
	for(var no=0;no<divs.length;no++){
		if(divs[no].className=='question'){
			divs[no].onclick = showHideAnswer;
		}	
		
	}	
}

window.onload = initShowHideContent;





