
var requete = null;

var Timer=null;
var Pas = 3;
var Pas2 = 450;
function moveLayer22(Sens) {
	var Objet=document.getElementById("photos_cont");
    if(parseInt(Objet.style.left) + (Pas*Sens)>0)  {
		clearTimeout(Timer);
	}
	else if(parseInt(Objet.style.left) + (Pas*Sens)<-(Objet.offsetWidth-document.getElementById("photos").offsetWidth)) {
		clearTimeout(Timer);
	}
    else {
        Objet.style.left = (parseInt(Objet.style.left) + (Pas*Sens)) + "px";
	}
	Timer = setTimeout("moveLayer22(" + Sens + ");", 30);
}
function addToFavorites() {
	if (document.all) { window.external.AddFavorite(location.href, document.title); }
	else { alert("Votre navigateur n'autorise pas l'ajout direct de signets.\n"
	            +"Pour ce faire, faites 'Control + D' pour l'ajouter ou utilisez le menu marque-pages.") }
}

function creerRequete() {
    try {
        requete = new XMLHttpRequest();
    } catch (microsoft) {
        try {
            requete = new ActiveXObject('Msxml2.XMLHTTP');
        }
        catch(autremicrosoft) {
            try {
                requete = new ActiveXObject('Microsoft.XMLHTTP');
            } catch(echec) {
                requete = null;
            }
        }
    }
    if(requete == null) {
        alert('Impossible de créer l\'objet requête,\nVotre navigateur ne semble pas supporter les object XMLHttpRequest.');
    }
}
function page(catid) {
	creerRequete();
	var url = 'js/page.php?id='+catid;
	requete.open('GET', url, true);
	//document.getElementById('centre').innerHTML = requete.responseText;
	requete.onreadystatechange = function() {
		if(requete.readyState == 4) {
			if(requete.status == 200) {
				document.getElementById('centre').innerHTML = requete.responseText;
				setupZoom();
			//	Lightbox.init();
			}
		}
	};
	
	requete.send(null);
}
var Timer=null;
var Pas = 5;
function moveLayer6(Sens) {
	var Objet=document.getElementById("defil_anim_contenu");
    if(parseInt(Objet.style.left) + (Pas*Sens)>0)  {
		clearTimeout(Timer);
	}
	else if(parseInt(Objet.style.left) + (Pas*Sens)<-(Objet.offsetWidth-document.getElementById("defil_anim").offsetWidth)) {
		clearTimeout(Timer);
		
	}
    else {
        Objet.style.left = (parseInt(Objet.style.left) + (Pas*Sens)) + "px";
	}
	Timer = setTimeout("moveLayer6(" + Sens + ");", 30);
}
function resetField(theObj,strDefault){
	var curentValue = theObj.value;
	if(curentValue == strDefault){
		theObj.value = '';
	}
	else {
		return;
	}
}
function marqu(aa)
{
document.form_rech.action=aa+'?mm='+document.form_rech.marque.value;
document.form_rech.submit();
}
function CheckForm () {

	//Intialise variables
	var errorMsg = "";
	var errorMsgLong = "";

	//Check for a name
	if (document.frmNewsComments.nom.value == "") {
		errorMsg="err";
		 alert("Le nom est vide!");
   document.frmNewsComments.nom.style.backgroundColor = "#F3C200";
   	return false;
	} 
	
	
	//Check for a country
	if (document.frmNewsComments.pays.value == ""){
		errorMsg="err";
		alert("Le pays est vide!");
   document.frmNewsComments.pays.style.backgroundColor = "#F3C200";
   	return false;
	}
	
	//Check for email
	if(document.frmNewsComments.email.value == "") {
   alert("Le mail est incorrect!");
   document.frmNewsComments.email.style.backgroundColor = "#F3C200";
   
   return false;
  }
 
  	//Vérification du mail s'il n'est pas vide on vérifie le . et @
 
		if (document.frmNewsComments.email.value != "")	{
		indexAroba = document.frmNewsComments.email.value.indexOf('@');
		indexPoint = document.frmNewsComments.email.value.indexOf('.');
		
		if ((indexAroba < 0) || (indexPoint < 0 ))		{
 
//dans le cas ou il manque soit le . soit l'@ on modifie la couleur d'arrière plan du champ mail et définissons un message d'alerte
 
			document.frmNewsComments.email.style.backgroundColor = "#F3C200";
			errorMsg += "Le mail est incorrect\n";
		}
	}
	
	
	//Check for comments
	if (document.frmNewsComments.comments.value == ""){
		errorMsg="err";
		  alert("Le commentaire est vide!");
   document.frmNewsComments.comments.style.backgroundColor = "#F3C200";
   	return false;
	}
	//Check the word length before submitting
	words = document.frmNewsComments.comments.value.split(' ');
	for (var loop = 0; loop <= words.length - 1; ++loop){
		if (words[loop].length >= 35){
			  alert("Dans le commentaire il y'a un mot qui depasse 35 caracteres!");
		errorMsgLong = "err";
			return false;
		}	
	}	
		
	//Check for HTML tags before submitting the form	
	for (var count = 0; count <= 7; ++count){
		if ((document.frmNewsComments.elements[count].value.indexOf("<", 0) >= 0) && (document.frmNewsComments.elements[count].value.indexOf(">", 0) >= 0)){
			errorMsgLong += "\n- HTML tags are not permitted, remove all HTML tags.";
		}			
	}
	
	//If there is aproblem with the form then display an error
	if ((errorMsg != "") || (errorMsgLong != "")){
		/*msg = "___________________________________________________________________\n\n";
		msg += "عفوا .. استكمل بيانات الحقول التالية\n";
		msg += "___________________________________________________________________\n\n";
		
		errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);*/
		return false;
	}
	
	return true;
}

//Function to count the number of characters in the description text box
function DescriptionCharCount() {
	document.frmNewsComments.countcharacters.value = document.frmNewsComments.comments.value.length;	
}

// Function to add the code for bold italic and underline, to the message
function AddMessageCode(code,promptText, InsertText) {

	if (code != "") {
		insertCode = prompt(promptText + "\n[" + code + "]xxx[/" + code + "]", InsertText);
			if ((insertCode != null) && (insertCode != "")){
				document.frmNewsComments.comments.value += "[" + code + "]" + insertCode + "[/"+ code + "] ";
			}
	}		
	document.frmNewsComments.comments.focus();
}


//Function to add the code to the message for the smileys
function AddSmileyIcon(iconCode) {	
		document.frmNewsComments.comments.value += iconCode + " ";
		document.frmNewsComments.comments.focus();
}

//Function to open pop up window
function openWin(theURL,winName,features) {
  	window.open(theURL,winName,features);
}


function word_count(text, wordcount)	{
	 text = text.replace(/^\s*|\s*$/g,''); //removes whitespace from front and end
	 var count_array = text.split(" ");
	 wordcount.value = count_array.length;
	 if(wordcount.value > 300 ) 
	 {
	 document.getElementById('Submit').disabled = 'disabled';
	 document.getElementById('msg').innerHTML='<span class="rouge">عذرا&nbsp;لقد تجاوزتم حد الكلمات المسموح 300</span>';
	 }
	else {
	document.getElementById('Submit').disabled = '';
	document.getElementById('msg').innerHTML='';
	}
	
}
function checkWordCount(c)	{
	if ( c != 'NaN' && c > 300 )
	{
		alert('Your submission cannot exceed 100 words');
		return false;
	}

}



