// JavaScript Document
//script de validation de formulaire
function checkemail(idElement){
var invalidcheck=0;
var str=document.getElementById(idElement).value
var filter=/^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str)){
var tempstring=str.split("@")
tempstring=tempstring[1].split(".")
if (invalidcheck!=1)
{
	document.getElementById(idElement).style.backgroundColor ='#FFFFFF';
	document.getElementById(idElement).style.borderColor = '#cccccc';
	testresults=true
}
else{
testresults=false
}
}
else{
document.getElementById(idElement).style.backgroundColor ='#fdf8f8';
document.getElementById(idElement).style.borderColor = '#ff9999';
testresults=false
}
return (testresults)
}


function checkCivilite(){
	if (document.form1.c[0].checked || document.form1.c[1].checked || document.form1.c[2].checked)
	{
		//document.getElementById('c1').style.color = '#000000'
		//document.getElementById('c2').style.color = '#000000'
		//document.getElementById('c3').style.color = '#000000'
		return true
	}
	else
	{
		//document.getElementById('c1').style.color = '#FF0000'
		//document.getElementById('c2').style.color = '#FF0000'
		//document.getElementById('c3').style.color = '#FF0000'
		return false
	}
}

function checkCond(idElement){
	if (document.getElementById(idElement).checked)
	{
		document.getElementById('condition').style.color ='#666666';
		//document.getElementById('condition').style.borderColor = '#cccccc';
		return true
	}
	else
	{
		document.getElementById('condition').style.color = 'red';
		//document.getElementById('condition').style.borderColor = '#ff9999';
		return false
	}
}

function checkTxtEmpty(idElement){
	if (document.getElementById(idElement).value != "")
	{
		document.getElementById(idElement).style.backgroundColor = '#FFFFFF';
		document.getElementById(idElement).style.borderColor = '#cccccc';
		return true
	}
	else
	{
		document.getElementById(idElement).style.backgroundColor = '#fdf8f8';
		document.getElementById(idElement).style.borderColor = '#ff9999';
		return false
	}
}

function checkCodePostal(idElement){
	nbr = document.getElementById(idElement).value
	if (nbr.length >= 2 && !isNaN(nbr))
	{
		document.getElementById(idElement).style.backgroundColor = '#FFFFFF';
		document.getElementById(idElement).style.borderColor = '#cccccc';
		return true
	}
	else
	{
		document.getElementById(idElement).style.backgroundColor = '#fdf8f8';
		document.getElementById(idElement).style.borderColor = '#ff9999';
		return false
	}
}

function checkTel(idElement){
	nbr = document.getElementById(idElement).value
	if (nbr.length >= 1 && !isNaN(nbr))
	{
		document.getElementById(idElement).style.backgroundColor = '#FFFFFF';
		return true
	}
	else
	{
		document.getElementById(idElement).style.backgroundColor = '#fdf8f8';
		return false
	}
}

function checkall(){
 var pseudo = checkTxtEmpty('pseudo')
 var motDePasse = checkTxtEmpty('motDePasse')
 var confirmeMdp = checkTxtEmpty('confirmeMdp')
 var email = checkemail('email')
 var confirmeMail = checkemail('confirmeMail')
 var conditionUtilisation = checkCond('conditionUtilisation')



if (!(pseudo && motDePasse && confirmeMdp && email && confirmeMail && conditionUtilisation))
{
	//document.getElementById('erreursaisie').style.visibility = 'visible';
	alert('Veuillez remplir le formulaire correctement svp.');
	return false ;
}
else
	document.insertion.submit();
	return true;
}

function verif_contact(){
	
	var nom = checkTxtEmpty('nom');
	var prenom = checkTxtEmpty('prenom');
	var mail = checkemail('mail');
	var objet = checkTxtEmpty('objet');
	var message = checkTxtEmpty('message');
	
	
	
	if (!(nom && prenom && mail && objet && message)){
		alert('Veuillez remplir le formulaire correctement svp.');
		return false;
	}
}

function checkebook(){
 var titre = checkTxtEmpty('titre');
 var ebook = checkTxtEmpty('ebook');
 var presentation = checkTxtEmpty('presentation');
 var conditions = checkCond('conditions');


if (!(titre && ebook && presentation && conditions))
{
	//document.getElementById('erreursaisie').style.visibility = 'visible';
	alert('Veuillez remplir le formulaire correctement svp.');
	return false ;
}
else
	if (((document.getElementById('ebook').value).substr((((document.getElementById('ebook').value).length)-3),(document.getElementById('ebook').value).length)) != "pdf"){
		alert('Seul le format pdf est accept'+String.fromCharCode(233)+' !');
		return false;
	} else {
		
	if (confirm('Voil'+String.fromCharCode(224)+' donc votre derni'+String.fromCharCode(232)+'re cr'+String.fromCharCode(233)+'ation, je ne doute pas qu\'elle trouve son public sur Auteurenherbe.com\n\nCependant, '+String.fromCharCode(234)+'tes-vous certain d\'y avoir mis la touche finale, l\'ultime point '+String.fromCharCode(63)+' Vous aimeriez peut '+String.fromCharCode(234)+'tre relire une derni'+String.fromCharCode(232)+'re fois votre œuvre avant de la mettre en ligne '+String.fromCharCode(63)+' A ce stade, tout est encore possible.'))
	{
		document.insertion.submit();
		return true;
	}
	else{
		return false;
	}
	}
	
}

function checkfiche(){
 var titre = checkTxtEmpty('titre');
 var presentation = checkTxtEmpty('presentation');
 var conditions = checkCond('conditions');
 var dateEdition = checkTxtEmpty('dateEdition');


if (!(titre && ((tinyMCE.getInstanceById('presentation').getContent()).length > 0) && conditions && dateEdition))
{
	//document.getElementById('erreursaisie').style.visibility = 'visible';
	alert('Veuillez remplir le formulaire correctement svp.');
	return false ;
}
else
	if (confirm('Vous souhaitez faire partager vos impressions sur cet ouvrage, rien de plus l'+String.fromCharCode(233)+'gitime.\nCependant, '+String.fromCharCode(234)+'tes vous s'+String.fromCharCode(251)+'r de votre orthographe et de vos arguments, peut '+String.fromCharCode(234)+'tre d'+String.fromCharCode(233)+'sireriez vous effectuer une derni'+String.fromCharCode(232)+'re relecture '+String.fromCharCode(63)+' Vous en avez encore la possibilit'+String.fromCharCode(233)+', rien ne presse.'))
	{
		document.insertion.submit();
		return true;
	}
	else{
		return false;
	}
	
}

function checkdroits(){
    if(document.getElementById('creative').checked){
        document.getElementById('arrCreative1').disabled = false;
        document.getElementById('arrCreative2').disabled = false;
        document.getElementById('arrCreative3').disabled = false;
        document.getElementById('arrCreative4').disabled = false;
    }else{
        document.getElementById('arrCreative1').disabled = true;
        document.getElementById('arrCreative2').disabled = true;
        document.getElementById('arrCreative3').disabled = true;
        document.getElementById('arrCreative4').disabled = true;
    }
}
function limitcomments(theForm)
{
	var msg = "";
	if(theForm.commentaire.value.length <202)
	{
		msg = 'Vous devez au moins '+String.fromCharCode(233)+'crire 2 ou 3 lignes, pour ajouter un commentaire';
		alert(msg);
		return false;
	}
	else
	{
		return true;
	}
}

function commentaireVide(){
	if (!checkTxtEmpty('commentaire')){
		alert('Veuillez saisir votre commentaire.');
		return false
	} else {
		return true;
	}
}

function videoVide(){
	if (!(checkTxtEmpty('titre') && checkTxtEmpty('codeVideo'))){
		alert('Veuillez saisir titre et le code');
		return false;
	} else {
		return true;
	}
}

function chargframe(prix,id){
//alert("le prix :"+prix+"et lid est :"+id);
document.getElementById('iframepaiement').innerHTML="<iframe  width=\"460px\"  height=\"180px\" border='0' src=\"http://www.auteurenherbe.com/cgi-bin/call_request.pl?prix="+prix+"&id_utilisateur="+id+"\" ></iframe>" ;
}
function chargpaypal(lien){
//alert("le id :"+id);
document.getElementById('iframepaypal').innerHTML="<a href="+lien+"><img style='margin-left:60px; border:0;' width='140' src='http://auteurenherbe.com/p/logo/paypal_logo.gif' /></a>" ;
}
