//sortir des insuporables frames...
if (parent.frames.length!=0) parent.location.href=location.href;

/*
var interval = null;
var intW = null;
var Wnow = null;
var intH = null;
var Hnow = null;
var intX = null;
var Xnow = null;
var intY = null;
var Ynow = null;
var i = null;
var timer = null;
var myzoomedImage = null;
var mymask = null;
var OPnow = null;
var intOP = null;


function imageZoom(id){

    var myimage = document.getElementById(id);
    var PosX = findPosX(myimage);
    var PosY = findPosY(myimage);
    var Size = getSize();
    var ScrollXY = getScrollXY();
  
    var x,y;
    var test1 = document.body.scrollHeight;
    var test2 = document.body.offsetHeight
    if (test1 > test2) // all but Explorer Mac
    {
        x = document.body.scrollWidth;
        y = document.body.scrollHeight;
    }
    else // Explorer Mac;
         //would also work in Explorer 6 Strict, Mozilla and Safari
    {
        x = document.body.offsetWidth;
        y = document.body.offsetHeight;
    }
  
    var divWidth = 400;
    var divHeight = 300;
    var topPos = Size[1]/2 - divHeight/2 + ScrollXY[1];
    var leftPos = Size[0]/2 - divWidth/2 + ScrollXY[0];
    var id = "mask1";
    mymask = document.getElementById(id);
    //~ mymask.style.position = 'absolute';
    //~ mymask.style.top = '0px';
    //~ mymask.style.left = '0px';
    mymask.style.width = x+'px';
    mymask.style.height = y+'px';
    //~ mymask.style.backgroundColor = 'black';
    //~ mymask.style.zIndex = 20;
    //~ mymask.style.opacity = 0;
    //~ mymask.style.filter = 'alpha(opacity=0)';
    var op = 9;

  
    document.getElementById('maskimage').innerHTML = "<img id='zoomedImage' src='http://www.paroissedemorges.ch/IMG/batiments/ChapelleGlobal_Md.jpg' height='"+myimage.height+"px' width='"+myimage.width+"px' />";
    mymask.style.opacity = 0;
    mymask.style.filter = 'alpha(opacity= 0)';
    document.getElementById('mask0').style.display = "block";
  
    myzoomedImage = document.getElementById('zoomedImage');
    //~ myzoomedImage.style.position = 'absolute';
    myzoomedImage.style.top = PosY+'px';
    myzoomedImage.style.left = PosX+'px';
    //~ myzoomedImage.style.zIndex = 22;
    //myzoomedImage.style.backgroundColor = 'black';

    //var op = 10;
    //myzoomedImage.style.opacity = op/10;
    //myzoomedImage.style.filter = 'alpha(opacity=' + op*10 + ')';

    interval = 30;
    var duration = 210;
    intOP = op/interval;
    OPnow = 0.0;
    intW = (divWidth - myimage.width ) / interval;
    Wnow = myimage.width;
    intH = (divHeight - myimage.height ) / interval;
    Hnow = myimage.height;
    intX = (leftPos - PosX) / interval;
    Xnow = PosX;
    intY = (topPos - PosY) / interval;
    Ynow = PosY;

    i=0;
    timer = setInterval("zoomnow()", duration/interval);
}

function zoomnow(){
    if(i<interval){
        OPnow += intOP;
        Wnow += intW;
        Hnow += intH;
        Xnow += intX;
        Ynow += intY;
        //alert(Wnow+' '+Hnow);
        mymask.style.opacity = OPnow/10;
        mymask.style.filter = 'alpha(opacity=' + OPnow*10 + ')';
        myzoomedImage.style.left = Math.round(Xnow)+'px';
        myzoomedImage.style.top = Math.round(Ynow)+'px';
        myzoomedImage.style.width = Math.round(Wnow)+'px';
        myzoomedImage.style.height = Math.round(Hnow)+'px';
        i++;
    }else{clearInterval(timer);}
}


function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function setMask() {
  var Size = getSize();
  var ScrollXY = getScrollXY();
  var divHeight = 100;
  var topPos = Size[1]/2-divHeight/2 + ScrollXY[1];
  //var topPos = Size[1]/2;
  //alert('ScrollY = '+ScrollXY[1]+'SizeY = '+Size[1]+'topPos = '+topPos);
  var id = "mask";
  document.getElementById(id).style.position = 'absolute';
  //document.getElementById(id).style.top = topPos+'px';
  document.getElementById(id).style.top = '0px';
  document.getElementById(id).style.right = '0px';
  document.getElementById(id).style.width = '100%';
  //document.getElementById(id).style.height = divHeight+'px';
  document.getElementById(id).style.height = '100%';
  document.getElementById(id).style.backgroundColor = 'grey';
  document.getElementById(id).style.zIndex = 20;
  //document.getElementById(id).style.filters.alpha.opacity= 90;
  document.getElementById(id).style.MozOpacity= 0.5;
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function getSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  var mySize = [myWidth,myHeight];
  return mySize;
}
*/

 /* tab info area on details page */
function switchTab(id) {
	// display only current info box
	var tabs0 = new Array('aboutBlock','pricingBlock','mapsBlock','calBlock','formBlock');
	var tabs = new Array();
  var tabsCollection0 = new Array('aboutTab','pricingTab','mapsTab','calTab','formTab');
  var tabsCollection = new Array();

	for(i=0;i<tabs0.length;i++) {
    if(document.getElementById(tabs0[i])){
		  tabs.push(tabs0[i]);
		  tabsCollection.push(tabsCollection0[i]);
		}
	}

  
	
	for(i=0;i<tabs.length;i++) {
		  document.getElementById(tabs[i]).style.display = "none";
	}
	document.getElementById(id).style.display = "block";
	
	// set current tab to active, set the next one (if exists) to pastActive,
	// set last one to last
	
	// remove all classes
	for(i=0;i<tabsCollection.length;i++) {	
		  document.getElementById(tabsCollection[i]).className = "";		
	}
	
	// set which one is active
	for(i=0;i<tabs.length;i++) {
		if(tabs[i] == id) {
			document.getElementById(tabsCollection[i]).className = "active";
		}
	}
	// find out what the next one is, if any (grumble grumble no array.indexOf support)
	var activeIndexTab=-1;
	for(i=0;i<tabs.length;i++) {
		if(tabs[i] == id) {
			activeIndexTab = i;
		}
	}
	// set pastActive
	if((activeIndexTab != -1) && (activeIndexTab != tabs.length-1)) {
		document.getElementById(tabsCollection[activeIndexTab+1]).className = "pastActive";
	}
	// and set last
	var j;
	for(i=0;i<tabsCollection.length;i++) {
		if (document.getElementById(tabsCollection[i]).style.display != "none")
		{
			j = i;
		}	
	}
	document.getElementById(tabsCollection[j]).className += " last";
    

    if ((mapdisplayed == 0) && (id == 'mapsBlock')) {
		initMap();
        mapdisplayed = 1;
	}
	if(id == 'calBlock') {
		//var f = document.getElementById('califrame');
		var f = document.getElementsByTagName("iframe");
		//alert(f[0].src);
		f[0].src = f[0].src;

	}
    if ((formdisplayed == 0) && (id == 'formBlock')) {
        calendar1 = new Epoch('cal1','popup',document.getElementById('calendar1_container'),false);
        calendar2 = new Epoch('cal2','popup',document.getElementById('calendar2_container'),false);
            if (document.getElementById('calendar1_container').value == 'jj mm aaaa'){
                calendar1.setDate(new Date(),true);
                calendar2.setDate(new Date(),true);
            }
        formdisplayed = 1;
	}


}

//fonction pour ouvrir un lien dans une nouvelle fenetre pour les references bibliques
function popBU( myform, windowname){
	newWindow = window.open ('', windowname, 'width=550,height=550,toolbar=0,location=0,directories=0,status=0,menuBar=1,scrollBars=1,resizable=1,alwaysRaised=1' );
	myform.target=windowname;
	newWindow.focus();
	myform.submit();
}

//fontion pour ouvrir un lien dans une nouvelle fenetre (popup).
function popup(mylink) {
    if (! window.focus) return true;
    var href;
    if (typeof(mylink) == 'string')
       href=mylink;
    else
       href=mylink.href;
    window.open(href,'Contact','width=700,height=600,resizable=yes,scrollbars=yes');
    return false;
}


//fonction pour le menu lateral...
function swap_menu(id){

	var tmp1 = document.getElementById('indic_'+id);
	var tmp2 = document.getElementById('rubrique_'+id);
	var tmp3 = document.getElementById('article_'+id);
	if (tmp2.style.display == 'none'){//tmp1.innerHTML == '+&nbsp;'
		tmp1.innerHTML = '-&nbsp;';
		if (tmp2 != null){ tmp2.style.display = 'block';}
		if (tmp3 != null){ tmp3.style.display = 'block';}
	}else{
		tmp1.innerHTML = '+&nbsp;';
		if (tmp2 != null){ tmp2.style.display = 'none';}
		if (tmp3 != null){ tmp3.style.display = 'none';}
	}
}

function swap_div(id){
	var tmp = document.getElementById(id);
	tmp.style.visibility = (tmp.style.visibility != 'visible'?'visible':'hidden');
}

function swap_sidebar(){
	var side = document.getElementById('sidebar');
    var main = document.getElementById('mainbar');
	main.style.width = (side.style.display == 'block'?'90%':'70%');
    side.style.display = (side.style.display != 'block'?'block':'none');
}

//fonction pour XMLHttP
    var xmlhttp
    
    function urlDecode(str){
        str=str.replace(new RegExp('\\+','g'),' ');
        return unescape(str);
    }
    function loadXMLDoc(url, mail)
    {
    // code for Mozilla, etc.
    if (window.XMLHttpRequest)
      {
      xmlhttp=new XMLHttpRequest()
      xmlhttp.onreadystatechange=state_Change
      xmlhttp.open("GET",url+mail,true)
      xmlhttp.send(null)
      }
    // code for IE
    else if (window.ActiveXObject)
      {
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
        if (xmlhttp)
        {
        xmlhttp.onreadystatechange=state_Change
        xmlhttp.open("GET",url+mail,true)
        xmlhttp.send(null)
        }
      }
    }
    function state_Change(){
        // if xmlhttp shows "loaded"
        if (xmlhttp.readyState==4){
            // if "OK"
            if (xmlhttp.status==200){
                document.getElementById('resultats').innerHTML=xmlhttp.responseText
            }
            else{
                alert("Problem retrieving data:" + xmlhttp.statusText)
            }
        }
    }

function get_all_CC(){
	title=document.getElementById('title').value;
	auteur=document.getElementById('auteur').value;
	year=document.getElementById('year').value;
	url=document.getElementById('url').value;
	loadXMLDoc('getinfoCC.php3?title='+title+'&auteur='+auteur+'&year='+year+'&url=',url);
}

function initMap() {
    if (GBrowserIsCompatible()) {

        var baseIcon = new GIcon();
        //baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
        baseIcon.iconSize = new GSize(35, 35);//20 34
        //baseIcon.shadowSize = new GSize(37, 34);
        baseIcon.iconAnchor = new GPoint(17, 17);//9 34
        baseIcon.infoWindowAnchor = new GPoint(17, 17);//9 2
        //baseIcon.ShadowAnchor = new GPoint(35, 35);//18 25

        // Creates a marker whose info window displays the desired html content
        function createMarker(point, html, label, type) {
        
            var icon = new GIcon(baseIcon);
            icon.image = "./IMG/png/"+type+".png";
            //icon.image = "./IMG/gif/eglise.gif";
            var marker = new GMarker(point, {icon:icon,title:label});

            GEvent.addListener(marker, "click", function() {
                marker.openInfoWindowHtml(html);
            });

            return marker;
        }
        
        // ==================================================
        // A function to create a tabbed marker and set up the event window
        // This version accepts a variable number of tabs, passed in the arrays htmls[] and labels[]
        function createTabbedMarker(point,htmls,labels,type,title, tid) {
            var icon = new GIcon(baseIcon);
            icon.image = "./IMG/png/"+type+".png";
            var marker = new GMarker(point,{icon:icon,title:title});
            GEvent.addListener(marker, "click", function() {
              // adjust the width so that the info window is large enough for this many tabs
              if (htmls.length > 2) {
                htmls[0] = '<div style="width:'+htmls.length*88+'px">' + htmls[0] + '</div>';
              }
              var tabs = [];
              for (var i=0; i<htmls.length; i++) {
                tabs.push(new GInfoWindowTab(labels[i],htmls[i]));
              }
              marker.openInfoWindowTabsHtml(tabs);
            });
            
            if(document.getElementById(tid+"div")){
            GEvent.addDomListener(document.getElementById(tid+"div"), "mouseover", function() {
              // adjust the width so that the info window is large enough for this many tabs
              if (htmls.length > 2) {
                htmls[0] = '<div style="width:'+htmls.length*88+'px">' + htmls[0] + '</div>';
              }
              var tabs = [];
              for (var i=0; i<htmls.length; i++) {
                tabs.push(new GInfoWindowTab(labels[i],htmls[i]));
              }
              marker.openInfoWindowTabsHtml(tabs);
            });}
            return marker;
        }
        // ==================================================    
        
        function makeHTML(label, tid, picURL, picURLmedium, adress, url, id){
            var html ='<div><div style="margin: 0 0 5px 5px; position: static; border-bottom:thin solid black; font-size:12px; font-weight: bold;">'+label+'</div><div style="margin: 5px; position: static; float: left; clear: none;"><a href="'+picURLmedium+'" onclick="myLightbox.start(this); return false;" rel="lightbox['+tid+']"><img id="imagemap'+id+'" style="border: 0px solid ;max-height:90px" alt="" src="'+picURL+'"></a></div><div style="margin: 5px; position: static; float: left; clear: right;font-size:10px;">'+adress+'</div><div style="margin: 5px; position: static; clear: both;font-size:10px;"><a href="'+url+'">Acc&eacute;der &agrave; cette salle</a></div></div>';
           return html;
        }


        var map = new GMap2(document.getElementById("map"));
        map.enableContinuousZoom();
        map.enableDoubleClickZoom();
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl(true));
        map.addControl(new GScaleControl());
        map.addControl(new GOverviewMapControl());
        map.setCenter(new GLatLng(mylat, mylon), myzoom);

        //~ GEvent.addListener(map, "moveend", function() {
          //~ var center = map.getCenter();
          //~ document.getElementById("message").innerHTML = center.toString();
        //~ });

        GDownloadUrl('data.xml', function(data, responseCode) {
            var xml = GXml.parse(data);
            var mainmarkers = xml.getElementsByTagName("markers");
            var markers = mainmarkers[0].getElementsByTagName("marker");
            for (var i = 0; i < markers.length; i++) {
                var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
                                        parseFloat(markers[i].getAttribute("lng")));
                var title = markers[i].getAttribute("title");
                var tid = markers[i].getAttribute("tid");
                //var picURL = markers[i].getAttribute("picURL");
                var adress = unescape(markers[i].getAttribute("adress"));
                var url = markers[i].getAttribute("url");
                var type = markers[i].getAttribute("type");

                var htmls = [];
                var labels = [];
                var tabs = markers[i].getElementsByTagName("tab");
                for (var j = 0; j < tabs.length; j++) {
                    labels[j] = tabs[j].getAttribute("lab");
                    var picURL = tabs[j].getAttribute("picURL");
                    var picURLmedium = tabs[j].getAttribute("picURLmedium");
                    var id = tabs[j].getAttribute("id");
                    htmls[j] = makeHTML (title, tid, picURL, picURLmedium, adress, url, id);
                }



                //map.addOverlay(createMarker(point,html, label, type));

                map.addOverlay(createTabbedMarker(point,htmls,labels,type,title,tid));
            }
        });

    }
}
