var ims=new Array;var nbims=0;
function preload(imname)	{	ims[nbims]=new Image(); ims[nbims++].src="Data/Img/"+imname;}
function preloadImg(imname)	{	ims[nbims]=new Image(); ims[nbims++].src=imname;}	

var toto0=-136;
var toto=toto0;
var animationAngle=0;
var chupaRolover=false;
var chupAilleursOver=false;
var chupAilleursDelay=0;
var sIsPageCinema=false;
var sIsPageLoisirs=false;
var userLogged=false;
var sUnlockParam="";

// ------------------------------------------------
// updateFaves
// ------------------------------------------------
function updateFaves()
{
	var chk = $('#userFaves input:checkbox');
	var tagsId="";
	var sep="";
	for (i=0;i<chk.length;i++)
	{
		if ($(chk[i]).is(":checked"))
		{
			tagsId+=(sep+$(chk[i]).attr('id'));
			sep=";";
		}
	}
	
	$("#fave").attr('value', tagsId);
}

// ------------------------------------------------
// loginMessageShow
// ------------------------------------------------
function loginMessageShow()
{
	$("#loginAndInfoBox").css({zIndex:1000,position:"absolute",top:394,left:6,width:247,height:265});
	$("#loginAndInfoBox").fadeIn("fast");
}

// ------------------------------------------------
// loginUserLogged
// ------------------------------------------------
function loginUserLogged(first)
{
	if( first)
		$("#userBox").css({"opacity":"0","left":0,"display":"block"}).animate({"opacity":1,"left":16},400);
}

// ------------------------------------------------
// focusSearchInput
// search box
// ------------------------------------------------
function focusSearchInput(obj,m)
{
	if(obj)
	{ 
		if(m)
		{	obj.value="";
			//obj.style.background="#DFE0CC";			
		}
		else
		{	//obj.style.background="#ffffff";			
		}
	}
}


// $(document).ready(onDomInit);

/*
// ------------------------------------------------
// onDomInit
// ------------------------------------------------
function onDomInit()
{
	$("#loginAndInfoBox").css({opacity:"1",display:"none"});

	if(sIsPageCinema)
	{
		InitCinema();
	}
	
	if (sIsPageLoisirs)
	{
		Loisirs.init();
	}
}
*/


// ------------------------------------------------
// infosUserFormSubmit
// used on pageMonCompte.php
// ------------------------------------------------
function infosUserFormSubmit(formName)
{
	err = infosUserCheck(formName);
	if (err==null)
		SubmitForm(formName);
	else
		$("#errorMessageInfos").html(err);
}

// ------------------------------------------------
// infosUserCheck
// ------------------------------------------------
function infosUserCheck(formName)
{
	var o;
	var strError="";

	if (o = getObj(formName))
	{
	
	// Code Postal
	if (o.postalCode.value.length == 0 || o.postalCode.value.length < 5)
		strError += "- Le code postal est invalide, il doit comporter 5 chiffres.<br />";
	else
	{
		var e = /[0-9]{5}/g;		
		if ( e.test(o.postalCode.value) == false)
			strError += "- Le code ne doit comporter que des chiffres.<br />";
	}
	
	// Rubriques
	var chk = $('#userFaves input:checkbox');
	var isChecked = false;
	for (i=0;i<chk.length;i++)
	{
		if ($(chk[i]).is(":checked"))
		{
			isChecked = true;
			break;
		}	
	}
	if (isChecked == false)
		strError += "- Une rubrique au moins doit être cochée.<br />";
	}
	
	return (strError != "" ) ? strError : null;
}

// ------------------------------------------------
// sendFormCreateUser
// ------------------------------------------------
function sendFormCreateUser()
{	var o;
	var strError=null;
	if( o=getObj('FormCreateUser'))
	{	
		// Password check
		if(o.usrPsswd.value.length<2)
			strError = " - Vous devez entrer un mot de passe suffisamment long<br />";
		else 
		if( o.usrPsswd.value != o.usrPsswdConfirm.value)
			strError = "- Les deux champs de saisie diffèrent. Veuillez vérifier les mots de passe.<br />";

		// Infos
		strErrorInfos = infosUserCheck('FormCreateUser');
		
		// Submit if no error
		if (strError == null && strErrorInfos == null)		
		{
			o.userpsswd.value = hex_md5(o.usrPsswd.value)
			//alert(o.userpsswd.value);	
			o.submit();
		}
	}

	if(strError || strErrorInfos)
	{
		$("#errorMessage").html((strError ? strError : "") + (strErrorInfos ? strErrorInfos : "") );
	}
}


// ------------------------------------------------
// Evenements
// ------------------------------------------------
function showEventCommentsList()
{
	$('#articleCommentsDiv').slideToggle("slow");
}


// ------------------------------------------------
// emptyTextedit
// plugged on the onfocus event of the te
// ------------------------------------------------
function emptyTextedit(te)
{	te.value="";
	te.onfocus=function(){};		// avoid erasing the content next time
}



/* Blog in admin*/

// ------------------------------------------------
// blogSeeLocationCombo
// ------------------------------------------------
function blogSeeLocationCombo(id)
{
	RQSiteAdminAjaxCall("action=getComboLocation",cbBlogSeeLocationCombo)

}

// ------------------------------------------------
// cbBlogSeeLocationCombo
// ------------------------------------------------
function cbBlogSeeLocationCombo(message,isOk)
{
	$("#inputPlaceDiv").show();
	var cb
	if( cb = getObj("place"))
	{	
		cb.options.length=0;
		eval(message);
	}


}

// ------------------------------------------------
// alaUneCategorie
// ------------------------------------------------
function alaUneCategorie(cat,id)
{
	if( cat && id)
		RQSiteAdminAjaxCall("action=setALaUneCat&cat="+cat+"&id="+id,cbAlaUneCategorie);
	
}

// ------------------------------------------------
// cbAlaUneCategorie
// ------------------------------------------------
function cbAlaUneCategorie(message,isErr)
{
	if( (!isErr) && message=='ok')
	{
		window.setTimeout(refreshListBlog,100);
		$('#btnALaUneCategory').after("<b id=\"btnALaUneCategory\" style=\"float:right;\">A la Une de la catégorie</b>");
		$('a#btnALaUneCategory').hide();
	}
}

// ------------------------------------------------
// refreshListBlog
// ------------------------------------------------
function refreshListBlog()
{
		blogAdminPostCalendarAction('refreshList');
}

// ------------------------------------------------
// alaUneGenerale
// ------------------------------------------------
function alaUneGenerale(id)
{
	if( id)
		RQSiteAdminAjaxCall("action=setALaUneGenerale&id="+id,cbAlaUneGenerale);
	
}

// ------------------------------------------------
// cbAlaUneGenerale
// ------------------------------------------------
function cbAlaUneGenerale(message,isErr)
{
	if( (!isErr) && message=='ok')
	{
		window.setTimeout(refreshListBlog,100);
		$('#btnALaUneGenerale').after("<b id=\"btnALaUneGenerale\" style=\"float:right;\">Une Globale</b>");
		$('a#btnALaUneGenerale').hide();
	}
}



/* ------  front Calendar navigation  ---------- */


// ------------------------------------------------
// CalendarNavMonth
// ------------------------------------------------
function CalendarNavMonth(year,month)
{
	//RQAjaxCall('Custom/myAjax.php?action=calendarNav&year='+year+'&month='+month,cbCalendarNav);
	var params = 'action=calendarNav&year='+year+'&month='+month+sUnlockParam;
	RQAjaxCallPlugin('Evenements',params,cbCalendarNav);
}


// ------------------------------------------------
// cbCalendarNav
// ------------------------------------------------
function cbCalendarNav(message,isErr)
{
	if(!isErr)
	{	eval(message);
	}
	else
		alert("error");
}



// ------------------------------------------------
// myshowBBCodeInfo
// ------------------------------------------------
function myshowBBCodeInfo()
{
	$("#BBCodeInfo").slideToggle("fast");
}

/* ------  Password  ---------- */


// ------------------------------------------------
// forgottenPasswordClick
// ------------------------------------------------
function forgottenPasswordClick()
{
	$("#loginBox").html("<div class=\"label\" id=\"boxMessage\">Entrez votre email</div>"+"<div id='forgottenFormDiv'><form id='formForgottenPsswd' method='post' onSubmit='postForgottenPsswdForm();return false;' enctype='multipart/form-data' action='#'><input name='email' size=\"20\" id='emailPsswdForgotten' /><input type='hidden' name='action' value='forgotPassword' /></form>"+"<a href='javascript:postForgottenPsswdForm();'>Envoyer</a></div>");
}

// ------------------------------------------------
// postForgottenPsswdForm
// ------------------------------------------------
function postForgottenPsswdForm()
{	var o,email;
	if( o=getObj("formForgottenPsswd"))
	{
		expreg = new RegExp("^([a-zA-Z0-9_\.\-]+)@([a-zA-Z0-9_\.\-]+)\.([a-zA-Z]+)$", "g");
		email = RQGetVariableValue('email');
		if( email.length<1)
		{
			$("#boxMessage").hide().html("Veuillez saisir votre email").fadeIn("slow");
		}
		else if( expreg.test(email))
		{
			var url='async.php?code='+sRqSessionCode+'&module='+"UserLogin";
			RQAjaxPost(url,'formForgottenPsswd',cbPasswdForgottenPost);			
		}
		else
		{
			$("#boxMessage").hide().html("format d'email incorrect. Réeesayez").fadeIn("slow");
		}
	}
}

// ------------------------------------------------
// cbPasswdForgottenPost
// ------------------------------------------------
function cbPasswdForgottenPost(message,isErr)
{
	if(!isErr)
	{
		eval(message);
	}
}

// ------------------------------------------------
// bonPlanNotLogged
// ------------------------------------------------
function bonPlanNotLogged()
{
	alert("Pour accéder aux Bons Plans il vous faut vous identifier, ou créer un compte gratuitement.");
}

// ------------------------------------------------
// printBonPlan
// ------------------------------------------------
function printBonPlan(id)
{
	popup('print'+id,sURL_SITE+'async.php?module=ListBonsPlans&action=print&id='+id,800,600,"yes");

}
