﻿//_____________________________________________________________________________
// Module : common.js
//
// GESTION DE VARIABLES GLOBALES, FONCTIONS GENERIQUES ...
//
// version  : 1.0
//
//_____________________________________________________________________________
//
  var toggle = true;    // Variable utilisée par SwapImage() (module météo)
  myImage = new Image();

//_____________________________________________________________________________
//
//___________ SwapImage : Module Météo _____________________
function SwapImage(imgA,imgB,timing){
	if(toggle)
	{
		$(imgA).setStyle({
		    'display': 'none'
	    });
	    $(imgB).setStyle({
		    'display': ''
	    });
	}
	else
	{
		$(imgB).setStyle({
		    'display': 'none'
	    });
	    $(imgA).setStyle({
		    'display': ''
	    });
	}
	
	toggle = !toggle;
	setTimeout("SwapImage('" + imgA +"','"+ imgB +"',"+timing+")",timing);
}

function ReplaceAddRemove(container, replaceText, withText) 
{
    container.innerHTML = "" + container.innerHTML.Replace(replaceText,withText);
}

function showOrHide(what) 
{ 
    if (document.getElementById)  
    { 
        var style2 =document.getElementById(what).style; 
        style2.display =style2.display="block"? "none":"block"; 
    } 
    else if (document.all) 
    { 
        var style2 =document.all[what].style; 
        style2.display = style2.display="block"? "none":"block";  
    } 
    else if (document.layers) 
    { 
        var style2 =document.layers[what].style; 
        style2.display = style2.display="block"?"none":"block" 
    } 
}



function displaySearch(blockName,resize, color)
{
	var blockSearchDisplay = $(blockName).style.display;
	var linkup = $('search_up_link');
	if (blockSearchDisplay == 'none')
	{
		//$('search_new').hide();
		if (linkup)
		    linkup.remove();
		    
		    if(color != null)
		    {
		        Effect.toggle('search_new' + color, 'appear', { duration: 0.1 });
		    }
		    else
		    {
		        Effect.toggle('search_new', 'appear', { duration: 0.1 });
		    }
		    
		    var upLink = '<a href="#" id="search_up_link" onclick="displaySearch(\'' + blockName + '\',false); return false;">'
			              + '<img src="/v_images/search_up.gif" alt="up" width="14px" height="8px" /></a>';
			
			if(color != null)
		    {
			    $('search_title' + color).insert(upLink, 'after');
			}
			else
			{
			    $('search_title').insert(upLink, 'after');
			}
			
		    Effect.toggle(blockName, 'blind', { duration: 1.5, afterFinish: Reposition });
		    if(resize != null)
		    {
		        if (resize == true)
		        {
		            var TIMEOUT_DELAY = 1700;
		            setTimeout ("resizeMap2()",TIMEOUT_DELAY);
		        }
    		    
		    }
		    
		    if(color == null)
		    {
		        moveGMap();
		    }
	}
	else
	{
		if (linkup)
		    linkup.remove();
		//$('search_up_link').remove();
		var upLink = '<a href="#" id="search_up_link">'
			+ '<img src="" alt="" width="14px" height="8px" /></a>';
		$('search_title').insert(upLink, 'after');
		$(blockName).hide();
		//Effect.toggle('block_search', 'slide', { duration: 1 });
		$('search_new').show();
	    var box_position = document.getElementById('box_position');
	    if (box_position)
	        Reposition();
		//Effect.toggle('search_new', 'slide', { duration: 1, afterFinish: Reposition });
		//Effect.Opacity('search_new', { from: 0, to: 1.0, duration: 5 });
	}
}

function noPostBack(sNewFormAction)
{
    $('aspnetForm').action = sNewFormAction;
    $('__VIEWSTATE').name = 'NOVIEWSTATE';
    //$('__VIEWSTATE').remove();
}

var geocoder;
function SetLatitudeAndLongitude(fieldLatitude, fieldLongitude, address) {
    fieldLatitude.value = '';
    fieldLongitude.value = '';
    
    try {
        geocoder = new GClientGeocoder();
        // Retrieve location information, pass it to addToMap()
        geocoder.getLocations(address, function(response) {
            try {
                // Retrieve the object 
                place = response.Placemark[0];
                // Retrieve the latitude and longitude
                fieldLatitude.value = place.Point.coordinates[0];
                fieldLongitude.value = place.Point.coordinates[1];
            } catch (ex) {}
        }
        );
    } catch (e) { }
}

/***************** Shader Manager for Ajax *******************************/

function showShader(top, left){
  var oBody   = document.body;
  var oShader = $('shader');
  var wx=oBody.offsetWidth,wy=oBody.offsetHeight;
  if(oShader)
  {
  if(browser.isKonqueror){wx=window.innerWidth;wy=window.innerHeight;}
  { // shader
    var oOpacity=document.createElement('div');
    oOpacity.id='opacity';
    setStyles(oOpacity,'background:#000;opacity:.3;position:absolute;top:0;left:0;zIndex:2;width:'+(wx+10)+'px;height:'+(wy+10)+'px');
    oShader.appendChild(oOpacity);
  }
  { // img loader
		var oLoader=document.createElement('div');
		oLoader.id='loader';
		oLoader.setAttribute('align','center');
		setStyles(oLoader,'position:absolute;top:'+top+';left:'+left+';width:100%;height:100%;');
    {
      var img=document.createElement('img');
      img.src= '../images/wait.gif';
      img.align='center';
      oLoader.appendChild(img);
    }
		oShader.appendChild(oLoader);
  }
  }
}

function hideShader(){
//    var oShader = document.getElementById('shader');
//    oShader.parentNode.removeChild(oShader);
    var oOpacity= document.getElementById('opacity');
    var oLoader = document.getElementById('loader');
    oOpacity.parentNode.removeChild(oOpacity);
    oLoader.parentNode.removeChild(oLoader);
}

function Browser(){
	var ua=navigator.userAgent;
	this.isOpera=ua.indexOf('Opera')>=0;
	this.isIE=ua.indexOf('MSIE')>=0&&!this.isOpera;
  this.isSafari=ua.indexOf('Safari')>=0;
  this.isKonqueror=ua.indexOf('KHTML')>=0&&!this.isSafari;
}

function setStyles(el,str){
	var styles=str.split(';');
	for(i=0; i<styles.length; i++){
		var parts=styles[i].split(':');
		var selector=parts[0],value=parts[1];
		switch(selector){
			case 'opacity':{
				if(browser.isIE)el.style.filter='alpha(opacity='+(value*100)+')';
				else if(browser.isOpera)el.style.background='url("<?=$BACKEND_SERVER_PATH?>/themes/<?=$theme?>/images/menu/opacity.5.gif")';
				else if(browser.isKonqueror)el.style.background='url("<?=$BACKEND_SERVER_PATH?>/themes/<?=$theme?>/images/menu/opacity.5.gif")';
				else el.style.opacity=value;
			}
			default:{
				el.style[selector]=value;
			}
		}
	}
}


function moveGMap()
{
    var myIFrame = window.parent.document.getElementById ("ctl00_Search1_IFrame_Maps");
        
    if (myIFrame == null)
    {
        var myIFrame = $("ctl00_SearchPro1_IFrame_Maps");
    }
    
     myIFrame.contentWindow.map.checkResize();
	        
    myIFrame.contentWindow.map.panBy (new myIFrame.contentWindow.GSize(1,1));
}


function initSizeMap()
{
	$("GoogleMap_Div").setStyle({
		'width': '291px',
		'height': '183px'
	});
}

function resizeMap() {
    if(window.map.getSize().height != 350 && window.map.getSize().width != 790)
	{
        var myIFrame = window.parent.document.getElementById ("ctl00_Search1_IFrame_Maps");
        
        if (myIFrame == null)
        {
            var myIFrame = $("ctl00_SearchPro1_IFrame_Maps");
        }
        
        mySize = new myIFrame.contentWindow.GSize(790, 350);
        
        if (myIFrame.contentWindow.map.getSize().height != 350 && myIFrame.contentWindow.map.getSize().width != 790) {
            
            myIFrame.contentWindow.size = mySize;
            myIFrame.setStyle({
                'width': '790px',
                'height': '350px'
            });

            myIFrame.contentWindow.document.getElementById("GoogleMap_Div").style.width = '790px';
            myIFrame.contentWindow.document.getElementById("GoogleMap_Div").style.height = '350px';
            myIFrame.contentWindow.document.getElementById("GoogleMap_Div").style.border = '2px';
            
            window.parent.document.getElementById ("block_search_form").style.height = '400px';
	        window.parent.document.getElementById ("linkResizeUp").style.display = 'none';
	        window.parent.document.getElementById ("linkResizeDown").style.display ='';
	        
	        window.map.checkResize();
            window.map.panBy (new GSize(270,120));
        }
      }
    }

function resizeMap2() {

        var myIFrame = $("ctl00_Search1_IFrame_Maps");
        
        if (myIFrame == null)
        {
            var myIFrame = $("ctl00_SearchPro1_IFrame_Maps");
        }
        mySize = new myIFrame.contentWindow.GSize(790, 350);
        
        myIFrame.contentWindow.map.checkResize();
        
        if (myIFrame.contentWindow.map.getSize().height != 350 && myIFrame.contentWindow.map.getSize().width != 790) {

            myIFrame.contentWindow.size = mySize;

            myIFrame.setStyle({
                'width': '790px',
                'height': '350px'
            });

            myIFrame.contentWindow.document.getElementById("GoogleMap_Div").style.width = '790px';
            myIFrame.contentWindow.document.getElementById("GoogleMap_Div").style.height = '350px';
            myIFrame.contentWindow.document.getElementById("GoogleMap_Div").style.border = '2px';
            
            $("block_search_form").style.height = '400px';
	        $("linkResizeUp").style.display = 'none';
	        $("linkResizeDown").style.display ='';
	        
	        myIFrame.contentWindow.map.panBy (new myIFrame.contentWindow.GSize(270,120));
	        
        }
    }

    function resizeMap3() {

        var myIFrame = $("ctl00_Search1_IFrame_Maps");
        
        if (myIFrame == null)
        {
            var myIFrame = $("ctl00_SearchPro1_IFrame_Maps");
        }

        mySize = new myIFrame.contentWindow.GSize(790, 350);

        if (myIFrame.contentWindow.map.getSize().height == 350 && myIFrame.contentWindow.map.getSize().width == 790) {

            myIFrame.contentWindow.map.size = mySize;

            myIFrame.setStyle({
                'width': '291px',
                'height': '183px'
            });

            myIFrame.contentWindow.document.getElementById("GoogleMap_Div").style.width = '291px';
            myIFrame.contentWindow.document.getElementById("GoogleMap_Div").style.height = '183px';
            myIFrame.contentWindow.document.getElementById("GoogleMap_Div").style.border = '2px';
            
            $("block_search_form").style.height = '50px';
	        $("linkResizeUp").style.display = '';
	        $("linkResizeDown").style.display ='none';
	        
	        myIFrame.contentWindow.map.checkResize();
	        
            myIFrame.contentWindow.map.panBy (new myIFrame.contentWindow.GSize(-270,-120));
	        
        }
    }


function deleteContent (inputObj)
{
    if (inputObj.value == inputObj.title)
    {
        inputObj.value = "";
    }
}

function ReloadDefaultContent (inputObj)
{
    if (inputObj.value == "")
    {
        inputObj.value = inputObj.title;
    }
}

function Reposition()
    {
        var repere = document.getElementById("ad_table");
        var offsetPub = 0;
        if (repere)
        {
            var posY = findYPosition(repere);
            var box_position = document.getElementById("box_position");
            if ((box_position != 'undefined') && (box_position != null))
            {
                if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
                { 
                
                    if($("block_pub").style.display == "block")
                    {
                            offsetPub = 50;
                    }
                    
                    var heightTotal = findYPosition(box_position.parentNode);
                    heightTotal += box_position.offsetHeight + 24;
                    box_position.style.position = 'absolute';
                    box_position.style.top = posY - 12+ offsetPub;
                    
                    box_position.parentNode.style.height = (heightTotal) + "px";
                }
                else
                {
                    if($("block_pub").style.display == "block")
                    {
                        offsetPub = 150;
                    }
                    box_position.style.paddingTop = "" + (repere.offsetTop - 12- offsetPub) + "px";
                }
                box_position.style.display = "block";
            }
        }
    }
    
    function findYPosition( oElement ) 
    {
        if (typeof( oElement.offsetParent ) != 'undefined' ) 
        {
            for (posY = 0; oElement; oElement = oElement.offsetParent ) 
            {
                posY += oElement.offsetTop;
            }
            return posY;
        } 
        else 
        {
            return oElement.y;
        }
    }

    if (window.attachEvent)
        window.attachEvent("onload", Reposition) //invoke function
    Reposition();

    function InitXslXml(id,xsl,xml)
    {               
	    try {
	      var xmlContent= "";var xmlDoc;var xslStylesheet;var xslDoc;
	      if (window.DOMParser)
	      {// load the xslt file
	          
		      var myXMLHTTPRequest = new XMLHttpRequest();
		      myXMLHTTPRequest.open("GET", xsl, false); myXMLHTTPRequest.send(null);		      
              xslStylesheet = myXMLHTTPRequest.responseXML;              
              //var serializer = new XMLSerializer(); var sResult = serializer.serializeToString(xslStylesheet);
              //Output object take object xsl
              var xsltProcessor = new XSLTProcessor(); xsltProcessor.importStylesheet(xslStylesheet);
              //Take xml data from id
	          try 
	          { xmlContent = document.getElementById(xml).innerHTML; 
	            parser=new DOMParser(); xmlDoc=parser.parseFromString(xmlContent,"text/xml");  
	          } catch (e) {}
              if (xmlContent == "") {document.getElementById(id).innerHTML = "<BR/>";return;} 
              //transform data	 deserialize xml doc to string and extract string result
              resultDocument = xsltProcessor.transformToDocument(xmlDoc);
		      serializer = new XMLSerializer(); sResult = serializer.serializeToString(resultDocument);
              if (sResult.indexOf("<transformiix:result") > -1) {sResult = sResult.substring(sResult.indexOf(">") + 1, sResult.lastIndexOf("<"));}
              //display data
              var target = document.getElementById(id); target.innerHTML = sResult;
		      
	      // ActiveX pour Internet Explorer
	      } else if (window.ActiveXObject) { 	        
            //create xml objects
		    try {xmlDoc = new ActiveXObject('MSXML2.DOMDocument');} catch (e) {xmlDoc = new ActiveXObject('Microsoft.XMLDOM');}
		    try {xslDoc = new ActiveXObject('MSXML2.DOMDocument');} catch (e) {xslDoc = new ActiveXObject('Microsoft.XMLDOM');}
            //Take xml data from id
	        try { xmlContent = document.getElementById(xml).innerHTML; } catch (e) {}
            if (xmlContent == "") {document.getElementById(id).innerHTML = "<BR/>";return;} 
            //load xml objects
		    xmlDoc.async = false; xmlDoc.loadXML(xmlContent);		    
		    xslDoc.async = false; xslDoc.load(xsl);
            //display data
		    var target = document.getElementById(id); target.innerHTML = xmlDoc.transformNode(xslDoc);
	      }
	    } catch (e) {
	      return e;
	    }
    }
