
function selectCode(ID) {
	document.getElementById(ID).focus();
	document.getElementById(ID).select();
}


//Global utils script

function districtMe(div,divname,reg,regname,url1,url2,message){
	if(div > 0){
		var userSaid = confirm(message)
		if(userSaid == true){
			window.location=url2;
		}else{
			window.location=url1;
		}
	}else{
		alert(message);
	}
}

var totalDiapo = 0;
var curDiapo = 1;
var stateDiapo = 'play';
var diapoTimer = 5000;
var thisId = 'diapo_' + curDiapo;
var progressOn = false;

function initDiapo(numDiapo,sec,progOn){
	totalDiapo = numDiapo;
	progressOn = progOn;
	diapoTimer = sec * 1000;
	if(document.getElementById('diapoSwitch').className == 'zDiapoPause'){
		stateDiapo = 'stop';
	}else{
		stateDiapo = 'play';
		startDiapo();
	}
}
function switchDiapo(){
	if(document.getElementById('diapoSwitch').className == 'zDiapoPause'){
		document.getElementById('diapoSwitch').className = 'zDiapoPlay';
		setPercent();
		stateDiapo = 'play';
		startDiapo();
	}else{
		document.getElementById('diapoSwitch').className = 'zDiapoPause';
		stopDiapo();
	}
	
}
function startDiapo(){
	if(stateDiapo == 'play'){
		setTimeout("tryIncDiapo();",diapoTimer);
	}
}
function tryIncDiapo(){
	if(stateDiapo == 'play'){
		incDiapo();
	}
}
function stopDiapo(){
	stateDiapo = 'stop';
	document.getElementById('diapoSwitch').className = 'zDiapoPause';	
}
function incDiapo(){
	thisId = 'diapo_' + curDiapo;
	document.getElementById(thisId).className = 'diapoOff';
	curDiapo = curDiapo + 1;
	if(curDiapo > totalDiapo){
		curDiapo = 1;
	}
	incId = 'diapo_' + curDiapo;
	document.getElementById(incId).className = 'diapoOn';
	setPercent();
	startDiapo();
	
	
}

function decDiapo(){
	thisId = 'diapo_' + curDiapo;
	document.getElementById(thisId).className = 'diapoOff';

	curDiapo = curDiapo - 1;
	if(curDiapo == 0){
		curDiapo = totalDiapo;
	}
	decId = 'diapo_' + curDiapo;
	document.getElementById(decId).className = 'diapoOn';
	setPercent();
}

function setPercent(){
	if(progressOn){
		var thisPercent= curDiapo * 100 / totalDiapo * 2;
		document.getElementById('percentPlayer').style.width = thisPercent + 'px';
	}
}


function switchSearchBox(){

	if(document.getElementById('tabSearch').className == 'On2'){
		document.getElementById('tabSearch').className = 'Off2';
	}else{
		document.getElementById('tabSearch').className = 'On2';
	}
	if(document.getElementById('boxSearch').className == 'searchBoxOn'){
		document.getElementById('boxSearch').className = 'searchBoxOff';
	}else{
		document.getElementById('boxSearch').className = 'searchBoxOn';
	}
}
function switchAdminView(position){
	boxer = 'admbox_' + position;
	switcher = 'switch_' + position;
	currentState = document.getElementById(switcher).className;
	if (currentState == 'switchOn'){
		document.getElementById(switcher).className = 'switchOff';
		document.getElementById(boxer).style.display = 'block';
	}else{
		document.getElementById(switcher).className = 'switchOn';
		document.getElementById(boxer).style.display = 'none';
	}

}
function switchID(ID){
	if(document.getElementById(ID).className == 'on'){
		document.getElementById(ID).className = 'off';
	}else{
		document.getElementById(ID).className = 'on';
	}
}

lastMenuId = false;
function openMenuID(ID){
        if(lastMenuId){
                document.getElementById(lastMenuId).style.display = 'none';
                lastId = ID;
        }
        document.getElementById(ID).style.display = 'block';
}
function closeMenuID(ID){
	if (lastMenuId == ID) {
		lastId = false;
	}
	lastMenuId = ID;
        document.getElementById(lastMenuId).style.display = 'none';
}
var lastFtab = null;
var lastFbox = null;
var inBoxId = ''; // switchFilters, switchTab
var TabId = ''; // switchFilters, switchTab

function switchFilters(id){
	inBoxId = 'Fbox_' + id;
	TabId = 'Ftab_' + id
	if (lastFbox != null && lastFbox != inBoxId) {
		var elementInBox = document.getElementById(lastFbox);
		if (elementInBox) {
			elementInBox.className = 'off';
		}
	}
	lastFbox = inBoxId;
	var inBox = document.getElementById(inBoxId);
	if (inBox) { inBox.className = 'on'; }

	if (lastFtab != null && lastFtab != TabId) {
		var elementTab = document.getElementById(lastFtab);
		if (elementTab) {
			elementTab.className = 'Off';
		}
	}

	lastFtab = TabId;
	var tab = document.getElementById(TabId);
	if (tab) { tab.className = 'On'; }
}

var last = null;
function switchEvents(id){
	if (last != null) {
		document.getElementById(last).style.display = 'none';
	}
	last = id;
	document.getElementById(id).style.display = 'block';
}
var lastTab = null;
var lastInBox = null;

function switchTab(id){
	inBoxId = 'box_' + id;
	TabId = 'tab_' + id
	if (lastInBox != null && lastInBox != inBoxId) {
		var elementInBox = document.getElementById(lastInBox);
		if (elementInBox) {
			elementInBox.className = 'off';
		}
	}
	lastInBox = inBoxId;
	var inBox = document.getElementById(inBoxId);
	if (inBox) { inBox.className = 'on'; }

	if (lastTab != null && lastTab != TabId) {
		var elementTab = document.getElementById(lastTab);
		if (elementTab) {
			elementTab.className = 'Off';
		}
	}

	lastTab = TabId;
	var tab = document.getElementById(TabId);
	if (tab) { tab.className = 'On'; }
}
function hideID(id){
	document.getElementById(id).style.display = 'none';
}
function showID(id){
	document.getElementById(id).style.display = 'block';
}
function insertEventAdress(_name,_street,_locality,_region,_pcode,_info,_country){
	document.forms['event']['__DIREventData_locationname'].value = _name;
	document.forms['event']['__DIREventData_locationstreet'].value = _street;
	document.forms['event']['__DIREventData_locationlocality'].value = _locality;
	document.forms['event']['__DIREventData_locationregion'].value = _region;
	document.forms['event']['__DIREventData_locationpcode'].value = _pcode;
	document.forms['event']['__DIREventData_locationcountry'].value = _country;
// 	document.forms['event']['__DIREventData_locationinfo'].value = _info;
}
function insertEventContact(_name,_phone,_email){
	document.forms['event']['__DIREventData_contactname'].value = _name;
	document.forms['event']['__DIREventData_contacttel'].value = _phone;
	document.forms['event']['__DIREventData_contactemail'].value = _email;
// 	document.forms['event']['__DIREventData_contactinfo'].value = _info;
}
var startTime = new Array(0,0,0);
var endTime = new Array(0,0,0);
var timerLimits = new Array(23,59,59);

var setStart = 0;
var setEnd = 0;

function setStartTime(hrs,min,sec){
	if(setStart == 0){
		startTime[0] = hrs;
		startTime[1] = min;
		startTime[2] = sec;
		setStart = 1;
	}
}

function setEndTime(hrs,min,sec){
	if(setEnd == 0){
		endTime[0] = hrs;
		endTime[1] = min;
		endTime[2] = sec;
		setEnd = 1;
	}
}
function incTimer(timer,part){
	if(timer == 'end'){
		if(endTime[part] == timerLimits[part]){
			endTime[part] = 0;
		}else{
			endTime[part] = endTime[part] + 1;
		}
	}
	if(timer == 'start'){
		if(startTime[part] == timerLimits[part]){
			startTime[part] = 0;
		}else{
			startTime[part] = startTime[part] + 1;
		}
	}
}
function decTimer(timer,part){
	if(timer == 'end'){
		if(endTime[part] == 0){
			endTime[part] = timerLimits[part];
		}else{
			endTime[part] = endTime[part] - 1;
		}
	}
	if(timer == 'start'){
		if(startTime[part] == 0){
			startTime[part] = timerLimits[part];
		}else{
			startTime[part] = startTime[part] - 1;
		}
	}
}
function setElementTimer(formulaire,element,timer){
	if(timer == 'end'){
		hrs = endTime[0];
		if(hrs < 10){
			hrs='0'+hrs;
		}
		min = endTime[1];
		if(min < 10){
			min='0'+min;
		}
		sec = endTime[2];
		if(sec < 10){
			sec='0'+sec;
		}
		timerString = hrs+':'+min+':'+sec;
		document.forms[formulaire][element].value = timerString;
	}
	if(timer == 'start'){
		hrs = startTime[0];
		if(hrs < 10){
			hrs='0'+hrs;
		}
		min = startTime[1];
		if(min < 10){
			min='0'+min;
		}
		sec = startTime[2];
		if(sec < 10){
			sec='0'+sec;
		}
		timerString = hrs+':'+min+':'+sec;
		document.forms[formulaire][element].value = timerString;
	}
}
var NS =false;
var IE = false;

if (window.ActiveXObject){ //ActiveX
	IE=true;
}
if(window.XMLHttpRequest){ //GEKO
	NS=true;
}


/*if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;
var xp = 0;
var yp = 0;
function getMouseXY(e) {

	if (IE) { // grab the x-y pos.s if browser is IE
		tempX = event.clientX+ document.body.scrollLeft;
		tempY = event.clientY+ document.body.scrollTop;
	}
	else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
	}
	return true;
}*/

function moveOut(id){
    var object = document.getElementById(id).style;
	object.top = '-1000px';
	object.left ='-1000px';
}
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;;
        }

    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }

}
//Action check! ask realy act?
function didYouMean(url,what){
	var userSaid = confirm(what)
	if(userSaid == true){
		window.location=url;
	}else{
		alert("Opération annulée!");
	}
}
//checkSwitch Functions
function checkSwitch(conteneur,element,formulaire){
	if(document.forms[formulaire][element].checked  ==  true ){
		document.getElementById(conteneur).style.display = 'block';
	}else{
		document.getElementById(conteneur).style.display = 'none';
	}
}
//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

/*function showPopUpNote(id){
	document.getElementById(id).style.top = tempY+-40+'px';
	document.getElementById(id).style.left = tempX+30+'px';
	opacity(id, 0, 90, 1000);
	
}*/

function hidePopUpNote(id){
	opacity(id, 90, 0, 500);
	setTimeout("moveOut('"+id+"')",100);
}



var map = null;
var geocoder = null;

function showAddress(address,sname) {
	if (GBrowserIsCompatible()) {
		geocoder = new GClientGeocoder();
		if (geocoder) {
			geocoder.getLatLng(
				address,
				function(point) {
					if (!point) {
						alert("Google map ne peut pas trouver l´adresse de "+sname+" ! "+address+".");
					} else {
						map = new GMap2(document.getElementById("google_map"));
						map.addControl(new GSmallMapControl());
						map.addControl(new GMapTypeControl());
						map.setCenter(point, 13);
						var marker = new GMarker(point);
						map.addOverlay(marker);
						marker.openInfoWindowHtml("<strong>"+sname+"</strong><br/>"+address);
					}
				}
        		);
		}
	}
}
function getCenter(){
	if(IE){
		return document.body.offsetWidth;
	}
	if(NS){
		return window.innerWidth;
	}
	return 0;
}

var lastOpenMenuId = false;

function openMenu(menu_id,xOpt){
	if(lastOpenMenuId == menu_id){
		closeMenu(lastOpenMenuId);
	}else{
		if(lastOpenMenuId){
			closeMenu(lastOpenMenuId);
		}
		document.getElementById(menu_id).style.left = (tempX + xOpt) + 'px';
		document.getElementById(menu_id).style.top = '31px';
		lastOpenMenuId = menu_id;
	}
}
function closeMenu(menu_id){
	document.getElementById(menu_id).style.top = '-1000px';
	lastOpenMenuId = false;
}

var sdate = false;
var edate = false;
var DatesArray = false;
var trigger = 'start';
var passCounter = 0;
function setDatesArray(table){
	DatesArray= table;
}
function dateFormat(pdate){
	day = pdate.substr(6,2);
	month = pdate.substr(4,2);
	year = pdate.substr(0,4);
	return year+'-'+month+'-'+day
}
function DisplayPeriod(){
	if(trigger == 'end'){
		document.forms['fperiod']['sdate'].value = dateFormat(sdate);
		document.forms['fperiod']['edate'].value = dateFormat(sdate);
	}else{
		document.forms['fperiod']['sdate'].value = dateFormat(sdate);
		document.forms['fperiod']['edate'].value = dateFormat(edate);
	}
	javascript:document.forms['fperiod'].submit();
}
function setLastPeriod(){
	if(sdate){
		endp = DatesArray.findIndex(sdate) + 6;
		if(endp < DatesArray.length){
			setPeriod(DatesArray[endp]);
		}else{
			setPeriod(DatesArray[(DatesArray.length -1)]);
		}
	}
}
function setPeriod(pdate){
	if(!sdate & !edate){
		sdate = pdate;
		for(i=0; i < DatesArray.length ;i++){
			entity = 'cell'+DatesArray[i];
			id = DatesArray[i];
			if(id == sdate){
				document.getElementById(entity).className = 'in';
			}
			else{
				document.getElementById(entity).className = 'normal';
			}
		}
	}
	else if(sdate & !edate){
		if(sdate < pdate | sdate == pdate){
			edate = pdate
		}
		else if(sdate > pdate){
			edate = sdate;
			sdate = pdate;
		}
		for(i=0; i < DatesArray.length ;i++){
			entity = 'cell'+DatesArray[i];
			id = DatesArray[i];
			if(id < sdate | id > edate){
				document.getElementById(entity).className = 'normal';
			}
			else{
				document.getElementById(entity).className = 'in';
			}
		}
	}
	else if(sdate & pdate){
		if(trigger == 'start'){
			sdate = pdate;
			for(i=0; i < DatesArray.length ;i++){
				entity = 'cell'+DatesArray[i];
				id = DatesArray[i];
				if(id == sdate){
					document.getElementById(entity).className = 'in';
				}
				else{
					document.getElementById(entity).className = 'normal';
				}
			}
		}else{
			if(pdate < sdate){
				edate = sdate;
				sdate = pdate;
				
			}else{
				edate = pdate;
			}
			for(i=0; i < DatesArray.length ;i++){
				entity = 'cell'+DatesArray[i];
				id = DatesArray[i];
				if(id < sdate | id > edate){
					document.getElementById(entity).className = 'normal';
				}
				else{
					document.getElementById(entity).className = 'in';
				}
			}
		}

	}

	if (trigger == 'start'){
		trigger = 'end';
	}
	else if (trigger == 'end'){
		trigger = 'start';
		passCounter = passCounter + 1;
	}
	if(passCounter > 1){
		DisplayPeriod();
	}
}

Array.prototype.findIndex = function(value){
	var ctr = "";
	for (var i=0; i < this.length; i++) {
		if (this[i] == value) {
		return i;
		}
	}
	return ctr;
};
var fontElement='contenu_central';





function setFontSize(size){
	var expDate=  new Date();
	expDate.setDate(expDate.getDate()+300);
	document.cookie="fontSizePx"+ "=" + escape(size) + ";expires=" + expDate.toGMTString();
	setCookiesFontSize();
}

function setCookiesFontSize(){
	var myName = 'fontSizePx';
	if (document.cookie.length > 0){
		c_start = document.cookie.indexOf(myName + "=");
		if (c_start!=-1) {
			c_start=c_start + myName.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			document.getElementById(fontElement).style.fontSize = document.cookie.substring(c_start,c_end);
		}
	}
}

