
/*
 * Show/hide a div
 */
function showHideDiv(show, divId) {
	if(show) {
		showDiv(divId);
	} else {
		hideDiv(divId);
	}
}

function showDiv(divId) {
	new Effect.BlindDown(divId, {duration:1});
}

function hideDiv(divId) {
	new Effect.BlindUp(divId, {duration:1});
}

/**
 * Move selected option form 'selectFrom' to 'selectTo'
 */
function move(selectFrom, selectTo) {
	if (selectFrom !== null || selectTo !== null) {
		for (i = selectFrom.length - 1; i >= 0; i--) {
			if (selectFrom.options[i].selected) {
				var option = new Option(selectFrom.options[i].text, selectFrom.options[i].value);
				selectTo.options[selectTo.length] = option;
				selectFrom[i] = null;
			}
		}
	}
}
/**
 * Select all option of this input select
 */
function selectAllOptions(inputSelect) {
	for (i = 0; inputSelect !== null && i < inputSelect.length; i++) {
		inputSelect.options[i].selected = true;
	}
}
function popup(link, name, w, h, options) {
	var l = 0;
	var t = 0;
	var maximize = !w || !h;
	if (screen && w && h) {
		l = (screen.width - w) / 2;
		t = (screen.height - h) / 2;
	}
	if (!options) {
		options = "directories=0,location=0,menubar=0,status=0,titlebar=0,toolbar=0,resizable=1,scrollbars=1";
	}
	var win = window.open(link, name, options + ",top=" + t + ",left=" + l + ",width=" + w + ",height=" + h);
	if(win) {
		win.focus();
		if (maximize) {
			win.resizeTo(screen.width, screen.height);
		}
	} else {
		alert('Vous devez autoriser les popups pour le site www.la-trame.com afin d\'accéder aux détails des praticiens.');
	}
	return win;
}
function closePopupAndRefreshOpener() {
	if (self.opener && !self.opener.closed) {
		self.opener.top.location.href = self.opener.top.location.href;
		self.opener.focus();
	}
	self.close();
}
function setCookie(name, value, expires, path, domain, secure) {
	document.cookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
}
function getCookie(name) {
	var prefix = name + "=";
	var start = document.cookie.indexOf(prefix);
	if (start == -1) {
		return null;
	}
	var end = document.cookie.indexOf(";", start + prefix.length);
	if (end == -1) {
		end = document.cookie.length;
	}
	var value = document.cookie.substring(start + prefix.length, end);
	return unescape(value);
}
function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}
function email(divId, name, domain, ext) {
	var mail = name + "@" + domain + "." + ext;
	$(divId).innerHTML = "<a href=\"mailto:" + unescape(mail) + "\">" + mail + "</a>";
}
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return [curleft, curtop];
}

/**
* http://www.openjs.com/articles/prevent_default_action/
*/
function stopEvent(e) {
   if(!e) var e = window.event;
   
   //e.cancelBubble is supported by IE - this will kill the bubbling process.
   e.cancelBubble = true;
   e.returnValue = false;

   //e.stopPropagation works only in Firefox.
   if (e.stopPropagation) {
      e.stopPropagation();
      e.preventDefault();
   }
   return false;
}
