// JavaScript Document

// ROLLOVER
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//

function NameDiv(id){
	if(document.all){ doc = document.all[id]; }
	if(document.getElementById){ doc = document.getElementById(id);}
	return doc;
}

function CheckMove(obj, dec){
	var nItems = $$('#List li').length;
	x = NameDiv(obj).style.left;
	x = x.replace("px","");
	if(x==""){x=0;}
	//alert(x);
	//alert("Fin : "+(dec*(nItems-4))+" - X : "+x);
	if(x/dec==Math.round(x/dec) && ( x >= (dec*(nItems-4)) || (x<0 && dec >0) ) ){ new Effect.Move (obj,{ x: dec, y: 0, mode: 'relative'}); }

}

function MoveReacts(obj, dec){
	var nItems = $$('#List li').length;
	x = NameDiv(obj).style.left;
	x = x.replace("px","");
	if(x==""){x=0;}
	//alert(x);
	//alert("Fin : "+(dec*(nItems-4))+" - X : "+x);
	if(x/dec==Math.round(x/dec) && ( x >= (dec*(nItems-3)) || (x<0 && dec >0) ) ){ new Effect.Move (obj,{ x: dec, y: 0, mode: 'relative'}); }

}

function SetObjDisplay(id, prop){
	NameDiv(id);
	doc.style.display=prop;
}

function SetObjCss(id, cssName){
	NameDiv(id);
	doc.className=cssName;
}

/** Systeme vote **/
function HilightStars(id){
	var NbStars = 5;

	for(i=1; i<=NbStars; i++){
		if(i<=id){
			SetObjCss("star"+i, "on")
		} else {
			SetObjCss("star"+i, "")
		}
	}
}


var id;
function Showrub(id) {
	for (var i = 3; i<=4; i++) {
		if (NameDiv('ssrub'+i) ) {
			doc.style.visibility = 'hidden';
			SetObjCss("Btn"+i, "");
		}
	}

	if (NameDiv(id)) {
		doc.style.visibility = 'visible';
	}
}

function Showmenu(id) {
	for (var i = 2; i<=4; i++) {
		if (NameDiv('Rub'+i) ) {
			doc.style.visibility = 'hidden';
			SetObjCss("Btn"+i, "");
		}
	}

	if (NameDiv(id)) {
		doc.style.visibility = 'visible';
	}
}

var tmp;
var tmp2;
function StartTO(id){
	tmp=window.setTimeout("Showrub(id)",50);
	tmp2=window.setTimeout("Showmenu(id)",50);
}

function KillTO(){
	window.clearTimeout(tmp);
	window.clearTimeout(tmp2);
}

/* bookmark */
function addBookmark(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
}
else if(document.all)// ie
window.external.AddFavorite(url, title);
}


/* Popup */


function getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight
	arrayPageSize = new Array(w,h)
	return arrayPageSize;
}

function resizemask(){
	var fsize=getPageSize();
	var popupHeight = $('Popup').getHeight();
	var popupWidth = $('Popup').getWidth();
	$('Popup').setStyle({
	  left:(fsize[0]/2-popupWidth/2)+"px",
	  top:(fsize[1]/2-popupHeight/2)+"px"
	});
	$('Mask').setStyle({
		width:fsize[0]+"px",
		height:fsize[1]+"px"
	});
}
/*
		function ShowPopup() {
			resizemask();
			$('Mask').show();
			$('Popup').show();
			//window.document.body.style.overflow = "hidden";
		}

		function HidePopup() {
			$('Mask').hide();
			$('Popup').hide();
			//window.document.body.style.overflow = "visible";
		}

*/

function ShowPopup(){
	resizemask();
	SetObjDisplay('Mask', 'block');
	SetObjDisplay('Popup', 'block');
}

function HidePopup(){
	resizemask();
	SetObjDisplay('Mask', 'none');
	SetObjDisplay('Popup', 'none');
}


/* activation checkbox adresses */
function Swapcheckbox(id) {
	for (var i = 1; i<=nItems; i++) {
	}
}

function addFriend(id){
	_popupaddamies.show();
	if($('btn_addfriend'))
		$('btn_addfriend').addClassName("disabled");
	new Ajax.Request(
		'includes/php/process.php',{
			parameters:{action:'addFriend',id:id},
			method:'post',
			onSuccess:function(){
				_popupaddamies.show();
			}
		}
	);
	//addFriend=function(a){};
}



function AddFavorite(id){
	if($('btn-addFav'))
		$('btn-addFav').remove();
	new Ajax.Request(
		'includes/php/process.php',{
			parameters:{action:'addFavConseil',id:id},
			method:'post',
			onSuccess:function(){
					_popupaddfav.show();

			}
		}
	);
}


function checkMail(str) {
	var verif = /^[a-zA-Z0-9\-\_]{1,}[a-zA-Z0-9\.\-\_]*[a-zA-Z0-9\-\_]{1,}@[a-zA-Z0-9]{1,}[a-zA-Z0-9\.\-\_]*[a-zA-Z0-9]{1,}[.][a-zA-Z]{2,4}$/;
	if(verif.test(str)) return true;
	else return false;
}


function openMessengerConfig(siteUrl){
	var callBackUrl = siteUrl+'wml.callback.php';
	var helpUrl 	= siteUrl+'conditions_utilisation.html';
	var url 		= 'http://settings.messenger.live.com/applications/websignup.aspx?mkt=fr-FR&returnurl='+callBackUrl+'&privacyurl='+helpUrl;
	var win 		= window.open(url,"messengerConfig","menubar=no, status=no, scrollbars=no, menubar=no, width=800, height=600");
	win.moveTo(screen.width/2-400, screen.height/2-300);
	win.focus();
}

function hideSelect(){
	if($('jour')){
		$('jour').hide();
	}
	if($('mois')){
		$('mois').hide();
	}
	if($('annee')){
		$('annee').hide();
	}
}

function showSelect(){
	if($('jour')){
		$('jour').show();
	}
	if($('mois')){
		$('mois').show();
	}
	if($('annee')){
		$('annee').show();
	}
}

oListOfAdress=null;
function LoadListOfAddr(c,id)
{
	var strQuery="?mode="+c+"&id="+id+"&start=0&limit=4";
	if(oListOfAdress==null)
	{
	  oListOfAdress = new ajaxpagination(
	  {
      objName:'oListOfAdress',
      nbitems:0,
      itembypage:4,
      url:"adressejson.php",
      evalresult:true,
      updatediv:'cntAdressList',
      paginationdiv:'',
      queryparams:strQuery
    });
  }
  else
  {
    oListOfAdress.setQueryParams(strQuery);
    oListOfAdress.setPage(0);
  }
}



/* EXPRIMEZ VOTRE STYLE */

var layer = new Array();
layer[0] = "mystyle-step1";
layer[1] = "mystyle-step2";
layer[2] = "mystyle-step3";

function inilayer(id){
	for(i=0; i<layer.length; i++){
		if(id==layer[i]){
			$(layer[i]).show();
		} else{
			$(layer[i]).hide();
		}
	}
}
