
var path;
var wait;
var httpRequest;

function onLoad(chemin, cookie) {
	//if( !cookie ) {
		//showPopup('#PopupEcom');
	//}
	
	path = chemin;
	
	imageObject0 = new Image();
	imageObject1 = new Image();
	imageObject2 = new Image();
	imageObject3 = new Image();
	imageObject4 = new Image();
	imageObject5 = new Image();
	imageObject6 = new Image();
	imageObject7 = new Image();
	imageObject8 = new Image();
	imageObject9 = new Image();
	imageObject10 = new Image();
	imageObject11 = new Image();
	imageObject12 = new Image();
	imageObject13 = new Image();
	imageObject14 = new Image();
	imageObject15 = new Image();
	 
	images = new Array();
	images[0] = path + "images/menu/accueil_on.png";
	images[1] = path + "images/menu/solutions_on.png";
	images[2] = path + "images/menu/references_on.png";
	images[3] = path + "images/menu/chiffres_on.png";
	images[4] = path + "images/menu/entreprise_on.png";
	images[5] = path + "images/menu/contact_on.png";
	images[6] = path + "images/menu/infogest_on.png";
	images[7] = path + "images/popups/background.png";
	images[8] = path + "images/popups/popup.png";
	images[9] = path + "images/popups/infogest_title.png";
	images[10] = path + "images/popups/conseiller_title.png";
	images[11] = path + "images/popups/close.png";
	images[12] = path + "images/footer/viadeo_on.png";
	images[13] = path + "images/footer/linked_on.png";
	images[14] = path + "images/footer/twitter_on.png";
	images[15] = path + "images/footer/facebook_on.png";
	
	imageObject0.src = images[0];
	imageObject1.src = images[1];
	imageObject2.src = images[2];
	imageObject3.src = images[3];
	imageObject4.src = images[4];
	imageObject5.src = images[5];
	imageObject6.src = images[6];
	imageObject7.src = images[7];
	imageObject8.src = images[8];
	imageObject9.src = images[9];
	imageObject10.src = images[10];
	imageObject11.src = images[11];
	imageObject12.src = images[12];
	imageObject13.src = images[13];
	imageObject14.src = images[14];
	imageObject15.src = images[15];
	
    /*for( i=0; i<images.length; i++ ) {
    	imageObject.src = images[i];
    }*/
}

function popupSave(objects) {
	var script = "";
	var radio = false;
	var parameters = "";
	
	for( var i=0; i<objects.length; i++ ) { 	
		if( objects[i].type == "radio" ) {
			if( objects[i].elt.checked == true ) {
				radio = true;
				parameters += "civilite=" + objects[i].elt.value;
			}
		}
	}
		
	if( radio == false ) {
		showErrorPopup("Veuillez indiquer votre Civilité");
		return false
	}
	
	for( var i=0; i<objects.length; i++ ) {	
		if( objects[i].type == "text" ) {
			if( objects[i].elt.value != "" ) {
				parameters += "&" + objects[i].elt.name + "=" + objects[i].elt.value;
			} else {
				showErrorPopup(objects[i].msg);
				return false
			}
		}
		
		if( objects[i].type == "phone" ) {
			if( objects[i].elt.value.length != 0 ) {
				parameters += "&" + objects[i].elt.name + "=" + objects[i].elt.value;
			} else {
				showErrorPopup(objects[i].msg);
				return false
			}
		}
	}
	
	if( window.XMLHttpRequest ) {
		httpRequest = new XMLHttpRequest();
	} else {
		httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	script = path + "include/fonctions/conseiller.php?" + parameters;

	httpRequest.open('GET', script, true);
	httpRequest.send(parameters);
	
	for( var i=0; i<objects.length; i++ ) { 	
		if( objects[i].type == "radio" ) {
			objects[i].elt.checked = false;
		} else {
			objects[i].elt.value = "";
		}
	}
	
	$("#PopupInformation").fadeIn("slow");
	wait = setInterval("closePopup('#PopupInformation')", 4000);
	
	window.document.getElementById("PopupConseiller").style.display = "none";
	window.document.getElementById("PopupMessage").innerHTML = "Votre demande a bien été prise en compte, un conseiller va vous rappeler très prochainement !";
}

function showErrorPopup(message) { 
	wait = setInterval("hideErrorPopup()", 1000);
	window.document.getElementById("EnvoyerPopup").style.display = "none";
	window.document.getElementById("ErreurPopup").innerHTML = message;
	$("#ErreurPopup").fadeIn("slow");
}

function hideErrorPopup() {
	clearInterval(wait);
	window.document.getElementById("ErreurPopup").style.display = "none";
	$("#EnvoyerPopup").fadeIn("slow");
}

function contactSave(objects) {
	var script = "";
	var radio = false;
	var parameters = "";
	var newsletter = 1;
	
	for( var i=0; i<objects.length; i++ ) { 	
		if( objects[i].type == "radio" ) {
			if( objects[i].elt.checked == true ) {
				radio = true;
				parameters += "civilite=" + objects[i].elt.value;
			}
		}
	}
	
	if( radio == false ) {
		showError("Veuillez indiquer votre Civilité");
		return false
	}
	
	for( var i=0; i<objects.length; i++ ) {	
		if( objects[i].type == "text" ) {
			if( objects[i].elt.value != "" ) {
				parameters += "&" + objects[i].elt.name + "=" + objects[i].elt.value;
			} else {
				showError(objects[i].msg);
				return false
			}
		}
	}
	
	if( window.document.getElementById("non").checked == true ) {
		newsletter = 0;
	}
	
	parameters += "&newsletter=" + newsletter;
	
	if( window.document.getElementById("telephone").value != "" ) {
		parameters += "&telephone=" + window.document.getElementById("telephone").value;
	}
	
	if( window.document.getElementById("message").value != "" ) {
		parameters += "&message=" + window.document.getElementById("message").value.replace(/\n/g,"<br/>");
	}
	
	if( window.XMLHttpRequest ) {
		httpRequest = new XMLHttpRequest();
	} else {
		httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	script = "../include/fonctions/contact.php?" + parameters;
	
	httpRequest.open('GET', script, true);
	httpRequest.send(parameters);
	
	for( var i=0; i<objects.length; i++ ) { 	
		if( objects[i].type == "radio" ) {
			objects[i].elt.checked = false;
		} else {
			objects[i].elt.value = "";
		}
	}
	
	window.document.getElementById("oui").checked = true;
	window.document.getElementById("telephone").value = "";
	window.document.getElementById("message").value = "";
		
	var scrollTop = $(window).scrollTop();
	$('html,body').stop().animate({scrollTop: 0}, 'slow');
	
	showPopup("#PopupInformation");
	wait = setInterval("closePopup('#PopupInformation')", 4000);
	window.document.getElementById("PopupMessage").innerHTML = "Votre demande a bien été prise en compte, nous vous recontacterons très prochainement !";	
}

function membreSave(objects) {
	var script = "";
	var radio = false;
	var parameters = "";
	var newsletter = 1;
	
	for( var i=0; i<objects.length; i++ ) { 	
		if( objects[i].type == "radio" ) {
			if( objects[i].elt.checked == true ) {
				radio = true;
				parameters += "civilite=" + objects[i].elt.value;
			}
		}
	}
	
	if( radio == false ) {
		showError("Veuillez indiquer votre Civilité");
		return false
	}
	
	for( var i=0; i<objects.length; i++ ) {	
		if( objects[i].type == "text" ) {
			if( objects[i].elt.value != "" ) {
				parameters += "&" + objects[i].elt.name + "=" + objects[i].elt.value;
			} else {
				showError(objects[i].msg);
				return false
			}
		}
	}
	
	if( window.document.getElementById("non").checked == true ) {
		newsletter = 0;
	}
	
	parameters += "&newsletter=" + newsletter;
	
	if( window.document.getElementById("fonction").value != "" ) {
		parameters += "&fonction=" + window.document.getElementById("fonction").value;
	}
	
	if( window.document.getElementById("entreprise").value != "" ) {
		parameters += "&entreprise=" + window.document.getElementById("entreprise").value;
	}
	
	if( window.document.getElementById("activite").value != "" ) {
		parameters += "&activite=" + window.document.getElementById("activite").value;
	}
	
	if( window.document.getElementById("adresse").value != "" ) {
		parameters += "&adresse=" + window.document.getElementById("adresse").value;
	}
	
	if( window.document.getElementById("adresse").value != "" && window.document.getElementById("complement").value != "" ) {
		parameters += " - " + window.document.getElementById("complement").value;
	}
	
	if( window.document.getElementById("postal").value != "" ) {
		parameters += "&ville=" + window.document.getElementById("postal").value;
	}
	
	if( window.document.getElementById("postal").value != "" && window.document.getElementById("ville").value != "" ) {
		parameters += " - " + window.document.getElementById("ville").value;
	}
	
	if( window.document.getElementById("pays").value != "" ) {
		parameters += "&pays=" + window.document.getElementById("pays").value;
	}
	
	if( window.document.getElementById("telephone").value != "" ) {
		parameters += "&telephone=" + window.document.getElementById("telephone").value;
	}
	
	parameters += "&interet=";
	
	if( window.document.getElementById("interet1").checked == true ) {
		parameters += " | " + window.document.getElementById("interet1").value;
	}
	
	if( window.document.getElementById("interet2").checked == true ) {
		parameters += " | " + window.document.getElementById("interet2").value;
	}
	
	if( window.document.getElementById("interet3").checked == true ) {
		parameters += " | " + window.document.getElementById("interet3").value;
	}
	
	if( window.document.getElementById("interet4").checked == true ) {
		parameters += " | " + window.document.getElementById("interet4").value;
	}
	
	if( window.document.getElementById("interet5").checked == true ) {
		parameters += " | " + window.document.getElementById("interet5").value;
	}
	
	if( window.document.getElementById("interet6").checked == true ) {
		parameters += " | " + window.document.getElementById("interet6").value;
	}
	
	if( window.document.getElementById("interet7").checked == true ) {
		parameters += " | " + window.document.getElementById("interet7").value;
	}
	
	if( window.document.getElementById("interet8").checked == true ) {
		parameters += " | " + window.document.getElementById("interet8").value;
	}
	
	if( window.document.getElementById("interet9").checked == true ) {
		parameters += " | " + window.document.getElementById("interet9").value;
	}
	
	if( window.document.getElementById("interet10").checked == true ) {
		parameters += " | " + window.document.getElementById("interet10").value;
	}
	
	if( window.document.getElementById("interet11").checked == true ) {
		parameters += " | " + window.document.getElementById("interet11").value;
	}
	
	if( window.document.getElementById("interet12").checked == true ) {
		parameters += " | " + window.document.getElementById("interet12").value;
	}
	
	if( window.document.getElementById("interet13").value != "" ) {
		parameters += " | " + window.document.getElementById("interet13").value;
	}
	
	if( window.document.getElementById("message").value != "" ) {
		parameters += "&message=" + window.document.getElementById("message").value.replace(/\n/g,"<br/>");
	}
	
	if( window.XMLHttpRequest ) {
		httpRequest = new XMLHttpRequest();
	} else {
		httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	script = "../include/fonctions/membre.php?" + parameters;
	
	httpRequest.open('GET', script, true);
	httpRequest.send(parameters);
	
	for( var i=0; i<objects.length; i++ ) { 	
		if( objects[i].type == "radio" ) {
			objects[i].elt.checked = false;
		} else {
			objects[i].elt.value = "";
		}
	}
	
	window.document.getElementById("oui").checked = true;
	window.document.getElementById("fonction").value = "";
	window.document.getElementById("entreprise").value = "";
	window.document.getElementById("activite").value = "";
	window.document.getElementById("adresse").value = "";
	window.document.getElementById("complement").value = "";
	window.document.getElementById("postal").value = "";
	window.document.getElementById("ville").value = "";
	window.document.getElementById("pays").value = "";
	window.document.getElementById("telephone").value = "";
	window.document.getElementById("interet1").checked = false;
	window.document.getElementById("interet2").checked = false;
	window.document.getElementById("interet3").checked = false;
	window.document.getElementById("interet4").checked = false;
	window.document.getElementById("interet5").checked = false;
	window.document.getElementById("interet6").checked = false;
	window.document.getElementById("interet7").checked = false;
	window.document.getElementById("interet8").checked = false;
	window.document.getElementById("interet9").checked = false;
	window.document.getElementById("interet10").checked = false;
	window.document.getElementById("interet11").checked = false;
	window.document.getElementById("interet12").checked = false;
	window.document.getElementById("interet13").value = "";
	window.document.getElementById("message").value = "";
	
	var scrollTop = $(window).scrollTop();
	$('html,body').stop().animate({scrollTop: 0}, 'slow');
	
	showPopup("#PopupInformation");
	wait = setInterval("closePopup('#PopupInformation')", 4000);
	window.document.getElementById("PopupMessage").innerHTML = "Votre inscription a bien été prise en compte, vous faites maintenant parti du Club My Infogest !";
}

function showError(message) { 
	wait = setInterval("hideError()", 1000);
	window.document.getElementById("Erreur").innerHTML = message;
	$("#Erreur").fadeIn("slow");
}

function hideError() {
	clearInterval(wait);
	$("#Erreur").fadeOut("slow");
}

function isValidEmail( $str )
{ 
	var $isValid = true;
	
	$str = $str + '';
	
	//
	if ($str.indexOf("@") == -1) {
		$isValid = false;
	}
	// 
	var $array = new Array();
	$array = $str.split("@");
	//
	if ( $array.length != 2 )
	{
		$isValid = false;
		return $isValid;
	}
	
	if ($array[0] == "") {
		$isValid = false;
	}
	if ($array[1].indexOf(".") == -1) {
		$isValid = false;
	}
	// 
	var $array2 = new Array();
	$array2 = $array[1].split(".");
	//
	if ($array2[0] == "") {
		$isValid = false;
	}
	if ($array2[1] == "") {
		$isValid = false;
	}
	// 
	return $isValid;
}

function addFlash(fichier, largeur, hauteur) {
	document.write('<object type="application/x-shockwave-flash" data="'+fichier+'" width="'+largeur+'" height="'+hauteur+'" id="Flash">');
	document.write('	<param name="movie" value="'+fichier+'" />');
	document.write('	<param name="quality" value="high" />');
	document.write('	<param name="scale" value="noscale" />');
	document.write('	<param name="loop" value="false" />');
	document.write('	<param name="menu" value="false" />');
	document.write('	<param name="quality" value="high" />');
	document.write('	<param name="bgcolor" value="#FFFFFF" />');
	document.write('	<param name="wmode" value="transparent" />');
	document.write('	<param name="embed" value="transparent" />');
	document.write('	<param name="allowFullScreen" value="true" />');
	document.write(' 	<embed src="'+fichier+'" quality="high" width="'+largeur+'" height="'+hauteur+'" scale="noscale" menu="false" wmode="transparent"></embed>');
	document.write('</object>');	
}

var nom;
var path;
var over = false;

function mouseOver(nom, chemin) {
	name = nom;
	path = chemin;
	
	if( over == false ) {
		over = true;
  		$("#Submenu").fadeIn("fast");
		document.getElementById(name).style.backgroundImage = "url(" + path + "images/menu/" + name.toLowerCase() + "_on.png)";
	}	
}

function mouseOut(name) {
	if( over == true ) {
		over = false;
		temporisation = setTimeout(checkOut, 10);
	}
}

function overflowOver() {
	over = true;
}

function checkOut() {
	if( over == false ) {
		clearTimeout(temporisation);
		$("#Submenu").fadeOut("fast");		
		document.getElementById(name).style.backgroundImage = "url(" + path + "images/menu/" + name.toLowerCase() + "_off.png)";	
	}
}

function supprLettre(evenement) { 
	var IE5 = false; 

	if( !evenement ) var e = window.event; 
	if( evenement.keyCode ) { 
		IE5 = true; code = evenement.keyCode;
	} else if( evenement.which ) code = evenement.which; 

	if( code < 48 || code > 57 ) { 
		if( IE5 ) evenement.returnValue = false; 
		else evenement.preventDefault(); 
	} 
} 

function addOther() { 
	if( document.getElementById("Autre").style.display == "none" ) {
		document.getElementById("Autre").style.display = "block";
	} else {
		document.getElementById("Autre").value = "";
		document.getElementById("Autre").style.display = "none";		
	}
}

function callPopup(nom) {
	window.open("./popups/plan_" + nom + ".php", "test", "toolbar=no, status=yes, scrollbars=yes, resizable=no, width=500, height=900" );
}

function showPopup(nom) {
	if( detectIE6() ) {
		tags = document.getElementsByTagName("select");
	
		for( i=0; i<tags.length; i++ ) {
			tags.item(i).style.visibility = "hidden";
		}
	}
		
	maskPage();
	
	window.document.body.style.overflow = "hidden"; 
	//window.document.getElementById(nom).style.display = "block";
	//window.document.getElementById("Mask").style.display = "block";
	$("#Mask").fadeIn("slow");
	$(nom).show(1000);
}

function maskPage() {
	var object = document.getElementById("Mask").style;
	
	var winY = getScrollY();
	var winL = 2000;
	
	if( window.innerHeight ) winH = window.innerHeight;
	if( document.body ) winH = document.body.clientHeight;
	if( document.documentElement ) winH = document.documentElement.clientHeight;

	if( getBrowserCodeName() == "IE" ) { 
		object.width = winL;
		object.height = winH + winY;
	} else if( getBrowserCodeName() == "NS6" || getBrowserCodeName() == "NS" ) {
		object.width = winL + "px"; 
		object.height = (winH + winY) + "px";
	}
}

function getScrollY() {
  	scrOfY = 0;
  	if( typeof(window.pageYOffset) == "number" ) {
    	scrOfY = window.pageYOffset;
  	} else if( document.body && (document.body.scrollTop) ) {
    	scrOfY = document.body.scrollTop;
  	} else if( document.documentElement && (document.documentElement.scrollTop) ) {
    	scrOfY = document.documentElement.scrollTop;
  	}
  	return scrOfY;
}

function detectIE6(){
	var IE6 = false

	var strChUserAgent = navigator.userAgent;
	var intSplitStart = strChUserAgent.indexOf("(",0);
	var intSplitEnd = strChUserAgent.indexOf(")",0);
	var strChMid = strChUserAgent.substring(intSplitStart, intSplitEnd);

	if(strChMid.indexOf("MSIE 6") != -1) IE6 = true;

	return IE6;
}

function getBrowserCodeName() {
	var name = null;
	if( document.getElementById && !document.all ) {
		name = "NS6";
	} else if( document.all ) {
		name = "IE";
	} else if( navigator.appName == "Netscape" && navigator.appVersion.charAt( 0 ) == "4" ) {
		name = "NS";
	} else if( navigator.userAgent.indexOf("Mac") != -1 ) {
		name = "MAC";
	}
	return name;
}

function closePopup(nom) {
	if( detectIE6() ) {
		tags = document.getElementsByTagName("select");
		
		for( i=0; i<tags.length; i++ ){
			tags.item( i ).style.visibility = "visible";
		}
	}
	
	window.document.body.style.overflow = "visible";
	$("#Mask").fadeOut("slow");
	clearInterval(wait);
	$(nom).hide(1000);
}

$(document).ready( function() {
	$("div.MenuBody1").each(function(){
    	$(this).css("height", $(this).height() + "px");
    });
	$("div.MenuBody2").each(function(){
    	$(this).css("height", $(this).height() + "px");
    });
	$("div.MenuBody3").each(function(){
    	$(this).css("height", $(this).height() + "px");
    });
	$("div.MenuBody4").each(function(){
    	$(this).css("height", $(this).height() + "px");
    });

  	$("div.MenuPanel").children("div.MenuHeader1").mouseup(function(){
   		var body = $(this).parent().children("div.MenuBody1");
    	if(body.is(":hidden"))
      		body.slideDown();
    	else
      		body.slideUp();
  	});
	$("div.MenuPanel").children("div.MenuHeader2").mouseup(function(){
   		var body = $(this).parent().children("div.MenuBody2");
    	if(body.is(":hidden"))
      		body.slideDown();
    	else
      		body.slideUp();
  	});
	$("div.MenuPanel").children("div.MenuHeader3").mouseup(function(){
   		var body = $(this).parent().children("div.MenuBody3");
    	if(body.is(":hidden"))
      		body.slideDown();
    	else
      		body.slideUp();
  	});
	$("div.MenuPanel").children("div.MenuHeader4").mouseup(function(){
   		var body = $(this).parent().children("div.MenuBody4");
    	if(body.is(":hidden"))
      		body.slideDown();
    	else
      		body.slideUp();
  	});
});

var i=2;
var j=1;

function addInputFile() {	
	document.getElementById("InputFile").innerHTML = document.getElementById("InputFile").innerHTML + "<br/><input id=\"Article\" name=\"Image" + i + "\" type=\"file\">";
	i++;
}

function addImageFormat() {	
	var input = document.forms['AddArticle'].elements['Message'];
	var start = input.selectionStart;
    var end = input.selectionEnd;
	
	if( j < i ) {
		input.focus();
    	input.value = input.value.substr(0, start) + "<img src=\"images/articles/#url" + j + "#\" name=\"\" alt=\"\" border=\"0\" />" + input.value.substr(end);
		j++;
	}
}

function addMessageFormat(format) {	
	var input = document.forms['AddArticle'].elements['Message'];
	var start = input.selectionStart;
    var end = input.selectionEnd;
	var position;
	
	switch(format) {
		case "Gras": 
			var debut = "<strong>";
			var fin = "</strong>";
			break;
		case "Annotation": 
			var debut = "<div align=\"center\"><i>";
			var fin = "</i></div>";
			break;
		case "Lien": 
			var debut = "<a href=\"#\" target=\"_blank\">";
			var fin = "</a>";
			break;
	}
	
	input.focus(); 
	input.value = input.value.substr(0, start) + debut + fin + input.value.substr(end);
    
	position = start + debut.length;
	input.selectionStart = position;
    input.selectionEnd = position;
}

function checkForm() {
	var formulaire = document.forms['AddArticle'];	
	if( formulaire.elements['Titre'].value == "" ) {
		window.document.getElementById("AddArticleTitre").style.visibility ="visible";
		window.document.getElementById("AddArticleCategorie").style.visibility ="hidden";
		return false;
	} else if( formulaire.elements['Categorie'].value == "" ) {
		window.document.getElementById("AddArticleTitre").style.visibility ="hidden";
		window.document.getElementById("AddArticleCategorie").style.visibility ="visible";
		return false;
	} else {
		return true;
	}
}

