// JavaScript Document
var ajaxManager = $.manageAjax({manageType: 'queue', maxReq: 2, blockSameRequest: true}); 
	
function onload(){
	$.ajaxSetup({
	  url: 		"Request/request.php",
	  global: 	false,
	  type: 	"GET",
	  dataType:	'html'
	});
}

$( function(){
	onload();
});

var alpha_letters = ' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-';
var alpha_name = ' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzÊÔÛÈÉèéûîÎáçàêùú-\'';
var alpha_num = ' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzÊÔÛÈÉèéûîÎáçàêùú0123456789_-\'';
var alpha_numbers = '0123456789';
var alpha_tel = '0123456789+ ';
var alpha_special = '-';
var alpha_email='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@._-+';
var alpha_password='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@._-+$*&%';
var alpha_numlet='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.- ';
var alpha_vehicle	= ' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
function alpha(e,allow) {

var k;
//var evtobj=window.event? event : e;
k=document.all?parseInt(e.keyCode): parseInt(e.which);
//alert(k);
      if (k!=13 && k!=8 && k!=0){
            //alert(allow.indexOf(String.fromCharCode(k))!=-1);
            if ((e.ctrlKey==false) && (e.altKey==false)) {
                  return (allow.indexOf(String.fromCharCode(k).toUpperCase())!=-1);
            } else {
                  return true;
            }
      } else {
            return true;
      }
}

function isNumberKey(evt)
{
 var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57)) return false;
    return true;
}

function validateEmail(emailStr) 
{
	/* The following variable tells the rest of the function whether or not
	to verify that the address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */
	var checkTLD=1;
	/* The following is the list of known TLDs that an e-mail address must end with. */
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */
	var emailPat=/^(.+)@(.+)$/;
	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the address. 
	These characters include ( ) < > @ , ; : \ " . [ ] */
	var specialChars="\\(\\)><@,;:'\\\\\\\"\\.\\[\\]";
	/* The following string represents the range of characters allowed in a 
	username or domainname.  It really states which chars aren't allowed.*/
	var validChars="\[^\\s" + specialChars + "\]";
	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */
	var quotedUser="(\"[^\"]*\")";
	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	/* The following string represents an atom (basically a series of non-special characters.) */
	var atom=validChars + '+';
	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */
	var word="(" + atom + "|" + quotedUser + ")";
	// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	/* Finally, let's start trying to figure out if the supplied address is valid. */
	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) 
	{
		/* Too many/few @'s or something; basically, this address doesn't
		even fit the general mould of a valid e-mail address. */
		
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	// Start by checking that only basic ASCII characters are in the strings (0-127).
	for (i=0; i<user.length; i++) 
	{
		if (user.charCodeAt(i)>127) 
		{
			return false;
		}
	}
	for (i=0; i<domain.length; i++) 
	{
		if (domain.charCodeAt(i)>127) 
		{
			return false;
		}
	}
	// See if "user" is valid 
	if (user.match(userPat)==null) 
	{
		// user is not valid
		return false;
	}
	/* if the e-mail address is at an IP address (as opposed to a symbolic
	host name) make sure the IP address is valid. */
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) 
	{
		// this is an IP address
	
		for (var i=1;i<=4;i++) 
		{
			if (IPArray[i]>255) 
			{
				return false;
	   		}
		}
		return true;
	}
	// Domain is symbolic name.  Check if it's valid.
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) 
	{
		if (domArr[i].search(atomPat)==-1) 
		{
			return false;
	   	}
	}
	/* domain name seems valid, but now make sure that it ends in a
	known top-level domain (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */
	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) 
	{
		return false;
	}
	// Make sure there's a host name preceding the domain.
	if (len<2) 
	{
		return false;
	}
	// If we've gotten this far, everything's valid!
	return true;
}


/*Sending data function*/
function sendinfo(url, response){	
		//$("#test").html("<img src='img/loading.gif'>");	
		ajaxManager.add({ 
			cache:		true,		
			success: function(res, status) { 							
				eval(response)(res, status);
			}, 
			url:url			
		});
}

function changeimage(id, im){
	document.getElementById(id).src = im;
}

/*function showhideespacevis(act, id, root){
		if(act == 'show'){
			$(id).show(600);
			$(root).html('<a href="javascript:;" class="active" onclick="showhideespacevis(\'hide\',\'#sousmenu\', \'#espvisiteur\');">Espace visiteurs</a>')
		}
		else{
			$(id).hide(600);
			$(root).html('<a href="javascript:;" onclick="showhideespacevis(\'show\',\'#sousmenu\', \'#espvisiteur\');">Espace visiteurs</a>')
		}
		return false;
}*/

function showhidesousmenu(act, id, root, texte){
		$("#sousmenu1").slideUp(600);
		$("#espvisiteur").html('<a href="javascript:;" onclick="showhidesousmenu(\'show\',\'#sousmenu1\', \'#espvisiteur\', \'Espace visiteurs\');">Espace visiteurs</a>')
		$("#sousmenu2").slideUp(600);
		$("#conf").html('<a href="javascript:;" onclick="showhidesousmenu(\'show\',\'#sousmenu2\', \'#conf\', \'Conférences\');">Conférences</a>')
		$("#sousmenu3").slideUp(600);
		$("#ateliers").html('<a href="javascript:;" onclick="showhidesousmenu(\'show\',\'#sousmenu3\', \'#ateliers\', \'Ateliers\');">Ateliers</a>')
		$("#sousmenu4").slideUp(600);
		$("#hallexpo").html('<a href="javascript:;" onclick="showhidesousmenu(\'show\',\'#sousmenu4\', \'#hallexpo\', \'Hall d&rsquo;exposition\');">Hall d\'exposition</a>')
		$("#sousmenu5").slideUp(600);
		$("#infop").html('<a href="javascript:;" onclick="showhidesousmenu(\'show\',\'#sousmenu5\', \'#infop\', \'Infos Pratiques\');">Infos Pratiques</a>')
		$("#sousmenu6").slideUp(600);
		$("#archive2010").html('<a href="javascript:;" onclick="showhidesousmenu(\'show\',\'#sousmenu6\', \'#archive2010\', \'Archives 2010\');">Archives 2010</a>')
		$("#espexposm").slideUp(600);
		$("#espexpo").html('<a href="javascript:;" onclick="showhidemnuspcl(\'show\',\'#espexposm\', \'#espexpo\', \'Espace exposants\');">Espace exposants</a>')
		$("#esppressesm").slideUp(600);
		$("#esppresse").html('<a href="javascript:;" onclick="showhidesousmenu(\'show\',\'#esppressesm\', \'#esppresse\', \'Espace presse\');">Espace presse</a>')
		
		if(act == 'show'){
			$(id).slideDown(600);
			$(root).html('<a href="javascript:;" class="active" onclick="showhidesousmenu(\'hide\',\''+id+'\', \''+root+'\', \''+texte+'\');">'+texte+'</a>')
		}
		else{
			$(id).slideUp(600);
			$(root).html('<a href="javascript:;" onclick="showhidesousmenu(\'show\',\''+id+'\', \''+root+'\', \''+texte+'\');">'+texte+'</a>')
		}
		return false;
}

function showhidemnuspcl(act, id, root, texte){
		$("#sousmenu1").slideUp(600);
		$("#espvisiteur").html('<a href="javascript:;" onclick="showhidesousmenu(\'show\',\'#sousmenu1\', \'#espvisiteur\', \'Espace visiteurs\');">Espace visiteurs</a>')
		$("#sousmenu2").slideUp(600);
		$("#conf").html('<a href="javascript:;" onclick="showhidesousmenu(\'show\',\'#sousmenu2\', \'#conf\', \'Conférences\');">Conférences</a>')
		$("#sousmenu3").slideUp(600);
		$("#ateliers").html('<a href="javascript:;" onclick="showhidesousmenu(\'show\',\'#sousmenu3\', \'#ateliers\', \'Ateliers\');">Ateliers</a>')
		$("#sousmenu4").slideUp(600);
		$("#hallexpo").html('<a href="javascript:;" onclick="showhidesousmenu(\'show\',\'#sousmenu4\', \'#hallexpo\', \'Hall d&rsquo;exposition\');">Hall d\'exposition</a>')
		$("#sousmenu5").slideUp(600);
		$("#infop").html('<a href="javascript:;" onclick="showhidesousmenu(\'show\',\'#sousmenu5\', \'#infop\', \'Infos Pratiques\');">Infos Pratiques</a>')
		$("#sousmenu6").slideUp(600);
		$("#archive2010").html('<a href="javascript:;" onclick="showhidesousmenu(\'show\',\'#sousmenu6\', \'#archive2010\', \'Archives 2010\');">Archives 2010</a>')
		$("#espexposm").slideUp(600);
		$("#espexpo").html('<a href="javascript:;" onclick="showhidemnuspcl(\'show\',\'#espexposm\', \'#espexpo\', \'Espace exposants\');">Espace exposants</a>')
		$("#esppressesm").slideUp(600);
		$("#esppresse").html('<a href="javascript:;" onclick="showhidesousmenu(\'show\',\'#esppressesm\', \'#esppresse\', \'Espace presse\');">Espace presse</a>')
		
		if(act == 'show'){
			$(id).slideDown(600);
			$(root).html('<a href="javascript:;" class="active" onclick="showhidesousmenu(\'hide\',\''+id+'\', \''+root+'\', \''+texte+'\');">'+texte+'</a>')
		}
		else{
			$(id).slideUp(600);
			$(root).html('<a href="javascript:;" onclick="showhidesousmenu(\'show\',\''+id+'\', \''+root+'\', \''+texte+'\');">'+texte+'</a>')
		}
		return false;
}

function showinscrirelogin(par){
	$('#inscrire-login').slideDown(500);
	//$(par).focus();	
}
function hideinscrirelogin(){
	$('#inscrire-login').slideUp(500);
	document.forminscrire.reset();
	document.formlogin.reset();
}

function showhidenews(act){
	if(act == 'show'){
			$("#regnews").slideDown(600);
			$("#regtexte").html('<a href="javascript:;" onclick="showhidenews(\'hide\');">Inscrivez-vous</a><br /> &agrave; notre newsletter')
	}
	else{
		$("#regnews").slideUp(600);
		$("#regtexte").html('<a href="javascript:;" onclick="showhidenews(\'show\');">Inscrivez-vous</a><br /> &agrave; notre newsletter')
	}
	return false;
}
function validnews(){
	if($("#newstxtbox").val() != ''){
		if(!validateEmail($("#newstxtbox").val())){
			alert('Adresse email invalide.');
			$("#newstxtbox").focus();
			return false;
		}
		else{
			$("#newsok").html('<img src="img/newsload.gif" \>');
			var eml = $("#newstxtbox").val();
			var url = 'requete.php?task=newsletter&eml='+eml;
			sendinfo(url, "callnewsletter");
			return false;
		}
	}
	else {
		alert('Veuillez entrer votre adresse email');
		$("#newstxtbox").focus();
		return false;	
	}
	return false;
}

function callnewsletter(res, status){	
	if(res == 1){
		alert('Votre inscription a bien été pris en compte.  Merci de votre participation.');
	}
	else if(res == 2){
		alert('Désolé, cette adresse email est déja inscrits.');
	}
	else {
		alert('Désolé, une erreur s\est produit.  Merci de réessayer.');
	}
	$("#newsok").html('[OK]');
}

function confdelete(){
	if(confirm('Effacer le formulaire ?')){
		return true;
	}
	else{
		return false;
	}
}

function validinscription(){
	var valid = true;

	if(($("#civ1").attr('checked') == false) && ($("#civ2").attr('checked') == false) && ($("#civ3").attr('checked') == false) && ($("#civ4").attr('checked') == false)){
		jAlert('Veuillez cocher votre civilite', 'Bellaplastie - Inscription en ligne');
		$("#civ1").focus();
		valid = false;
		return false;
	}
	
	if($("#nom").val() == ""){		
		jAlert('Veuillez entrer votre nom', 'Bellaplastie - Inscription en ligne');
		$("#txtnom").focus();
		valid = false;
		return false;
	}
	
	if($("#txtprenom").val() == ""){
		jAlert('Veuillez entrer votre prénom', 'Bellaplastie - Inscription en ligne');
		$("#txtprenom").focus();
		valid = false;
		return false;
	}
	
	/*if($("#txtadr1").val() == ""){
		jAlert('Veuillez entrer votre adresse', 'Bellaplastie - Inscription en ligne');
		$("#txtadr1").focus();
		valid = false;
		return false;
	}*/
	
	if($("#txtcp").val() == ""){
		jAlert('Veuillez entrer votre code postal', 'Bellaplastie - Inscription en ligne');
		$("#txtcp").focus();
		valid = false;
		return false;
	}
	
	if($("#txtville").val() == ""){
		jAlert('Veuillez entrer votre ville', 'Bellaplastie - Inscription en ligne');
		$("#txtville").focus();
		valid = false;
		return false;
	}
	
	if($("#txtmail").val() == ""){
		jAlert('Veuillez entrer votre email', 'Bellaplastie - Inscription en ligne');
		$("#txtmail").focus();
		valid = false;
		return false;
	}
	
	if(!validateEmail($("#txtmail").val())){
		jAlert('Adresse email est invalide.  Merci de vérifier.', 'Bellaplastie - Inscription en ligne');
		$("#txtmail").focus();
		valid = false;
		return false;
	}
	
	if(($("#sam").attr('checked') == false) && ($("#dim").attr('checked') == false) && ($("#sametdim").attr('checked') == false)){
		jAlert('Veuillez cocher le jour que vous vous renderez au salon', 'Bellaplastie - Inscription en ligne');
		$("#sam").focus();
		valid = false;
		return false;
	}
	
	if(valid){
		return true;
	}
}

function loadpage(pg){
	if(!pg == ''){		
		var load = window.open(pg,'','scrollbars=1,menubar=1,height=1024,width=768,resizable=yes,toolbar=1,location=no,status=no');	
	}
	else{
		return false;	
	}
}
function showhidedetails(opt, btn, toshow){
	$("#list1").slideUp(600);
	$("#btnlist1").html('<img src="img/plus.png" width="16" height="18" onclick="showhidedetails(\'show\', \'#btnlist1\', \'#list1\');" onmouseover="this.src=\'img/plus_hover.png\'" onmouseout="this.src=\'img/plus.png\'" style="cursor:pointer;" />');
	$("#list2").slideUp(600);
	$("#btnlist2").html('<img src="img/plus.png" width="16" height="18" onclick="showhidedetails(\'show\', \'#btnlist2\', \'#list2\');" onmouseover="this.src=\'img/plus_hover.png\'" onmouseout="this.src=\'img/plus.png\'" style="cursor:pointer;" />');
	$("#list3").slideUp(600);
	$("#btnlist3").html('<img src="img/plus.png" width="16" height="18" onclick="showhidedetails(\'show\', \'#btnlist3\', \'#list3\');" onmouseover="this.src=\'img/plus_hover.png\'" onmouseout="this.src=\'img/plus.png\'" style="cursor:pointer;" />');
	$("#list4").slideUp(600);
	$("#btnlist4").html('<img src="img/plus.png" width="16" height="18" onclick="showhidedetails(\'show\', \'#btnlist4\', \'#list4\');" onmouseover="this.src=\'img/plus_hover.png\'" onmouseout="this.src=\'img/plus.png\'" style="cursor:pointer;" />');
	$("#list5").slideUp(600);
	$("#btnlist5").html('<img src="img/plus.png" width="16" height="18" onclick="showhidedetails(\'show\', \'#btnlist5\', \'#list5\');" onmouseover="this.src=\'img/plus_hover.png\'" onmouseout="this.src=\'img/plus.png\'" style="cursor:pointer;" />');
	if(opt == 'show'){
		$(toshow).slideDown(600);
		$(btn).html('<img src="img/plus.png" width="16" height="18" onclick="showhidedetails(\'hide\', \''+btn+'\', \''+toshow+'\');" onmouseover="this.src=\'img/plus_hover.png\'" onmouseout="this.src=\'img/plus.png\'" style="cursor:pointer;" />');	
	}
	else{
		$(toshow).slideUp(600);
		$(btn).html('<img src="img/plus.png" width="16" height="18" onclick="showhidedetails(\'show\', \''+btn+'\', \''+toshow+'\');" onmouseover="this.src=\'img/plus_hover.png\'" onmouseout="this.src=\'img/plus.png\'" style="cursor:pointer;" />');	
	}
}
