//basic form check before real submit
function check_form(which) {
    var lang = document.getElementById('lng').value;
    if(which=='contact') {
	if((document.getElementById('name').value == "") || (document.getElementById('name').value.length < 3))  {
	    if(lang=='en') alert("please enter your name or company");
	    else alert("précisez votre nom ou votre société svp");
	    document.getElementById('name').focus();
	    return false;
	}
	else if(document.getElementById('eml').value == "") {
	    if(lang=='en') alert("please enter your email address");
	    else alert("veuillez fournir une adresse email svp");
	    document.getElementById('eml').focus();
	    return false;
	}
	else if((document.getElementById('eml').value.indexOf('@') == -1) || (document.getElementById('eml').value.indexOf('.') == -1)) {
	    if(lang=='en') alert("please enter a valid email address");
	    else alert("veuillez fournir une adresse email valide svp");
	    document.getElementById('eml').focus();
	    return false;
	}
	else if((document.getElementById('txt').value == "") || (document.getElementById('txt').value.length < 10))  {
	    if(lang=='en') alert("don't you have anything to say ?");
	    else alert("n'avez vous rien à dire ?");
	    document.getElementById('txt').focus();
	    return false;
	}
	else if(document.getElementById('chk').value.length != 4) {
	    if(lang=='en') alert("you must type the letters and/or numbers you see on the image");
	    else alert("vous devez écrire les lettres et/ou chiffres que vous voyez sur l'image");
	    document.getElementById('chk').focus();
	    return false;
	}
	else return true;
    }
    return false;
}
function Plop() {
    var myAs = document.getElementsByTagName('a');
    if(!myAs) return;
    for (var a = 0; a < myAs.length; ++a) {
    
	// faux popups pour afficher les images du portfolio en grand
	if(myAs[a].className == 'thumb') {
	    var Popup = document.createElement('div');
	    var divID = document.createAttribute('id');
	    divID.nodeValue = 'big_div';
	    Popup.setAttributeNode(divID);
	    var legend = document.createElement('p');
	    //var bold = document.createElement('b');
	    //var txt = document.createTextNode('Legende: ');
	    //bold.appendChild(txt);
	    var Img = document.createElement('img');
	    var imgsrc = document.createAttribute('src');
	    Img.setAttributeNode(imgsrc);
	    Popup.appendChild(Img);
	    Popup.appendChild(legend);
	    
	    myAs[a].onclick = function() {
		Popup.style.display = 'block';
		Popup.style.top = (document.all) ? (document.documentElement.scrollTop+ 10 +'px') : (window.pageYOffset+ 10 +'px');
		imgsrc.nodeValue = this.href;
		
		var tit = document.createTextNode(this.title);
		if(legend.firstChild == null) legend.appendChild(tit);
		else legend.replaceChild(tit, legend.firstChild);
		
		document.body.appendChild(Popup);
		return false;
	    };
	    Popup.onclick = function() {
		imgsrc.nodeValue = './img/loading.gif';
		this.style.display = 'none';
		return false;
	    };
	}
	
	// plop des emails dans l'admin en cliquant sur le titre du msg
        else if (myAs[a].className == 'nextli') {
	    // on extrait l'id de la popup à partir du href
	    var hLI = document.getElementById(myAs[a].href.substring(myAs[a].href.lastIndexOf('#') + 1));
	    if(hLI) {
		hLI.style.display = 'none';
		myAs[a].onclick = function() {
		    deHide = document.getElementById(this.href.substring(this.href.lastIndexOf('#') + 1));
		    //alert(deHide);
		    deHide.style.display = (deHide.style.display == 'none') ? 'block' : 'none';
		    return false;
		};
	    }
	}
	// confirmation de la suppression des contenus (lien $_GET['del']) dans l'admin
	else if(myAs[a].className == 'delconf') {
	    myAs[a].onclick = function() {
		if(confirm('êtes sûr de vouloir supprimer cet élément?')) return true; else return false;
	    };
	}
    }
}
window.onload = function() {
    Plop();
};