var doc_loc = escape(document.location.href);
var doc_title = escape(document.title);
var sldWidth = largeur_fenetre();
var sldHeight = hauteur_fenetre();
var lastTab = 1;

if (top.location != self.location) {
	top.location = self.location.href
}

function switchTab(tab){
	$('tab_'+lastTab).className = '';
	$('tab_'+tab).className = 'active';
	$('tab_'+lastTab+'_c').style.display = 'none';
	$('tab_'+tab+'_c').style.display = '';
	lastTab = tab;
}

function go(url, target) {
	if (target == '_blank' || target == 'blank') {
		window.open(encodeURI(url));
	} else {
		window.location.href = encodeURI(url);
	}
}

function closeWindow() {
	window.close();
}

function setCookie(nom, valeur) {
	var argv = setCookie.arguments;
	var argc = setCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = nom + "=" + escape(valeur) + ((expires == null) ? "": ("; expires=" + expires.toGMTString())) + ((path == null) ? "": ("; path=" + path)) + ((domain == null) ? "": ("; domain=" + domain)) + ((secure == true) ? "; secure": "");
}

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf(";", offset);
	if (endstr == -1) endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function readCookie(nom) {
	var arg = nom + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) return getCookieVal(j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

function popcenter(page, largeur, hauteur, options) {
	var top = (sldHeight - hauteur) / 2;
	var left = (sldWidth - largeur) / 2;
	window.open(page, "", "top=" + top + ",left=" + left + ",width=" + largeur + ",height=" + hauteur + "," + options);
}

function show(layerName) {
	$(layerName).style.display = '';
}

function hide(layerName) {
	$(layerName).style.display = 'none';
}

function largeur_fenetre() {
	if (window.innerWidth) {
		return window.innerWidth;
	} else if (document.body && document.body.offsetWidth) {
		return document.body.offsetWidth;
	} else {
		return 0;
	}
}

function hauteur_fenetre() {
	if (window.innerHeight) {
		return window.innerHeight;
	} else if (document.body && document.body.offsetHeight) {
		return document.body.offsetHeight;
	} else {
		return 0;
	}
}

function ajaxGet(request, divId) {
	new Ajax.Request(encodeURI(request), {
		method: 'get',
		onSuccess: function(updating) {
			$(divId).update(updating.responseText);
			new Effect.Highlight(divId);
		},
		onFailure: function(errmess) {
			$(divId).update('error!').setStyle({
				color: 'red'
			});
		}
	});
}

function ajaxCall(action, params) {
	new Ajax.Request('traitement.php', {
		method: 'post',
		postBody: 'action=' + action + '&' + params,
		encoding: 'utf-8',
		onSuccess: function(updating) {
			return true;
		},
		onFailure: function(errmess) {
			//alert('Erreur ! AjaxCall Refuse de repondre.');
			return false;
		}
	});
}

function setHelp(elem,value){
	var elem = $(elem);
	if (elem != null) {
		new Effect.Fade(elem,{duration:0.5,afterFinish:function(updateval){elem.update(value);}});
		new Effect.Appear(elem,{queue:'end',duration:0.5});
	}
}

function saveStar(event) {	
	new Ajax.Request('traitement.php', {
			parameters: event.memo,
			//onSuccess: function(message) {alert('Merci pour ton vote!');},
			onFailure: function(errmess) {alert('Erreur ! Ajax Refuse de repondre.');}
		}
	);
  var indicator = event.findElement('.starbox').down('.indicator'),
  restore = indicator.innerHTML;
  indicator.update('<div class="small red">Merci pour ton vote !</div>');
  (function() { indicator.update(restore) }).delay(2);
}

window.onload = function() {
	document.observe('starbox:rated', saveStar);
	document.observe('dom:loaded', function() {
		$('vote').observe('starbox:rated', saveStar);
	});
	$('Gsearchbox').observe('click', function(event){
		if(Event.element(event).value == 'Recherche'){
			Event.element(event).value = '';
		}
		Event.element(event).style.color = '#737C85';
	});

}



