function verifprofil(){
	var exp=new RegExp("^[0-9]*$","g");
	if(document.profil.pseudo.value.length == 0){
		document.getElementById('errorPseudo').innerHTML = '<img src="img/error.png" alt="champ manquant" />';
		return false;
	}else{
		document.getElementById('errorPseudo').innerHTML = '';
	}
	if (document.profil.newpwd.value != document.profil.newpwd2.value){
		alert("Vos mots de passe sont differents, veuillez recommencer");
		return false;
	}
	if(document.profil.email.value.length == 0){
		document.getElementById('errorMail').innerHTML = '<img src="img/error.png" alt="champ manquant" />';
		return false;
	}else{
		document.getElementById('errorMail').innerHTML = '';
	}
	if (!checkMail(document.profil.email)) return false;
	
	return true;
}
function verif(){
	var exp=new RegExp("^[0-9]*$","g");
	if(document.register.pseudo.value.length == 0){
		document.getElementById('errorPseudo').innerHTML = '<img src="img/error.png" alt="champ manquant" />';
		return false;
	}else{
		document.getElementById('errorPseudo').innerHTML = '';
	}
	if(document.register.pwd.value.length == 0){
		document.getElementById('errorPwd').innerHTML = '<img src="img/error.png" alt="champ manquant" />';
		return false;
	}else{
		document.getElementById('errorPwd').innerHTML = '';
	}
	if(document.register.pwd2.value.length == 0){
		document.getElementById('errorPwd2').innerHTML = '<img src="img/error.png" alt="champ manquant" />';
		return false;
	}else{
		document.getElementById('errorPwd2').innerHTML = '';
	}
	if (document.register.pwd.value != document.register.pwd2.value){
		alert("Vos mots de passe sont differents, veuillez recommencer");
		return false;
	}
	if(document.register.email.value.length == 0){
		document.getElementById('errorMail').innerHTML = '<img src="img/error.png" alt="champ manquant" />';
		return false;
	}else{
		document.getElementById('errorMail').innerHTML = '';
	}
	if (!checkMail(document.register.email)) return false;
	
	return true;
}

function verif_pm(){
	if(document.pm_send.send_to.value.length == 0){
		alert('Veuillez entrer le pseudo du destinataire');
		return false;
	}
	if(document.pm_send.sujet.value.length == 0){
		alert('Veuillez entrer le sujet de votre message');
		return false;
	}
	return true;
}

function verif_up(){
	var errors = '';
	var error = false;
	
	if(document.upload.categorie.value == 0){
		document.upload.categorie.style.backgroundColor = '#FF9494';
		error = true;
		errors = errors + '\t - Catégorie du média \n';
	}
	if(document.upload.title.value.length == 0){
		document.upload.title.style.backgroundColor = '#FF9494';
		error = true;
		errors = errors + '\t - Titre du média \n';
	}
	if(document.upload.hoster.value == 0){
		document.upload.hoster.style.backgroundColor = '#FF9494';
		error = true;
		errors = errors + '\t - Hébergeur du média \n';
	}
	if((document.upload.categorie.value == 1 || document.upload.categorie.value == 2 || document.upload.categorie.value == 6) && document.upload.quality.value == 0){
		document.upload.quality.style.backgroundColor = '#FF9494';
		error = true;
		errors = errors + '\t - Qualité du média \n';
	}
	if(document.upload.categorie.value == 5 && document.upload.plateform.value == 0){
		document.upload.plateform.style.backgroundColor = '#FF9494';
		error = true;
		errors = errors + '\t - Plateform du jeux \n';
	}
	
	if(document.upload.thumbnail.value.length == 0 || document.upload.thumbnail.value == 'http://'){
		document.upload.thumbnail.style.backgroundColor = '#FF9494';
		error = true;
		errors = errors + '\t - Url de l\'image miniature du média \n';
	}
	if(document.upload.image.value.length == 0 || document.upload.image.value == 'http://'){
		document.upload.image.style.backgroundColor = '#FF9494';
		error = true;
		errors = errors + '\t - Url de l\'image du média \n';
	}
	if(document.upload.desc.value.length == 0 || document.upload.desc.value == 'Description...'){
		document.upload.desc.style.backgroundColor = '#FF9494';
		error = true;
		errors = errors + '\t - Description du média \n';
	}
	if(document.upload.link.value.length == 0 || document.upload.link.value == 'http://'){
		document.upload.link.style.backgroundColor = '#FF9494';
		error = true;
		errors = errors + '\t - Liens de téléchargement du média \n';
	}
	if (error){
		alert('Merci de corriger les erreurs suivantes : \n\n' + errors);
	}
	return !error
}

function remplir(elt, data){
	document.getElementById(elt).innerHTML = data;
}

function verifMail(mail){
	if(mail != ''){
		var verif     = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]{2,}[.][a-zA-Z]{2,3}$/;
        if (verif.exec(mail) == null){
		    document.getElementById('vmail').innerHTML = "<label style=\"color:red\">Vérification: <b>"+mail+" :</b> email</label>";
		}else{
			document.getElementById('vmail').innerHTML = "<label style=\"color:green\">Vérification: <b>"+mail+" :</b> email OK</label>";
     	}
	}
}

function checkMail(mail){
    var email     = mail.value;
    var verif     = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]{2,}[.][a-zA-Z]{2,3}$/;
    if (verif.exec(email) == null){
		alert("Votre Email est incorrecte, veuillez la ressaisir svp");
        return false;
	}else{
		return true;
	}
}



function categorieChange(cat){
	if(cat == '1' || cat == '2' || cat == '6'){
		document.getElementById('upquality').style.visibility = 'visible';
		document.getElementById('upqualitylab').style.visibility = 'visible';
	}else{
		document.getElementById('upquality').style.visibility = 'hidden';
		document.getElementById('upqualitylab').style.visibility = 'hidden';
	}

	if(cat == '5'){
		document.getElementById('upplateform').style.visibility = 'visible';
		document.getElementById('upplateformlab').style.visibility = 'visible';
	}else{
		document.getElementById('upplateform').style.visibility = 'hidden';
		document.getElementById('upplateformlab').style.visibility = 'hidden';
	}	
}

function loadCat(id,path, aff, limit, host){
	$('#contenu').html('<p align="center"><img src="img/ajax-loader.gif" title="loading..." alt="loading..." /></p>');

	$.ajax({
		"url": path+"/cat2.php?id="+id+"&aff="+aff+"&limite="+limit+'&host='+host+'&path='+path,
		"type": "GET",
		"contentType": "application/x-www-form-urlencoded;charset=ISO-8859-1",
		"success": function(data){
			$('#contenu').html(data);
		},
		"error": function(){
			$('#contenu').html('<div class="error">Une erreur est survenue durant le traitement de la requête</div>');
		}
	});

}



