// Google search engine global params. Default is empty. All localized by market.

// search engine google API engine
var gcsId = '005212292509289221305:qgxpdw2ykyu';
// name of the button search
var searchGoogleItemString = 'RECHERCHER';
// link to the input type button
var linkToSearchPage = '/search/index.xhtml';
// text if google gives no result
var noResult = "\n\n\n<div id = 'noResultToDisplay'>";
noResult +="<p>La recherche effectu&eacute;e n'a pas abouti.</p><p>Recommandations:</p>\n";
noResult +="<ul><li>Assurez-vous que tous les mots sont correctement orthographi&eacute;s.</li>\n";
noResult +="<li>Essayez d'autres mots.</li>\n";
noResult +="<li>Utilisez des termes plus g&eacute;n&eacute;raux.</li>\n"
noResult +="<li> Essayez de r&eacute;duire le nombre de mots dans la requ&ecirc;te.</li>\n"
noResult +="<li><a href='http://corporate.disneylandparis.fr/plan-du-site/index.xhtml'>Consultez le plan du site.</a></li>\n"
noResult +="</ul></div>";
//langauge of the search engine (this param is called in google seacrh component of menu html)
var googleSearchLanguage = "fr";
// Language for face book like
IsoLanguage = "fr_FR";
// Block J - Tab Management 
//Change Style
function findObj(n, d) { //v4.0
    var p,i,x;
    if(!d) d=document;
    if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document;
        n=n.substring(0,p);
    }
    if(!(x=d[n])&&d.all) x=d.all[n];
    for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
    if(!x && document.getElementById) x=document.getElementById(n);
    return x;
}

function changestyle(couche, style) {
    if (!(layer = findObj(couche))) return;
    layer.style.display = style;  
}

function changecolor(couche, name) {
    if (!(layer = findObj(couche))) return;
    layer.className = name;
  
}

function switchLine (nbTab, position, tabName){
    //	var tempTabName;
    tempTabName = tabName+'8';	
    if (nbTab>4){
        if (!(layer1 = findObj('line1'))) return;
        if (!(layer2 = findObj('line2'))) return;
        if (position<=4){
            layer1.style.top = '31px';
            layer2.style.top = '-31px';
            if (nbTab!=8){
                changecolor(tempTabName,'tabButtonVide3');	  				  			
            } 
	  		 		
        }	
        if (position>4){
            layer1.style.top = '0px'; 
            layer2.style.top = '0px';	  	  			
            if (nbTab!=8){
                changecolor(tempTabName,'tabButtonVide2');	  				  			
            }	  		
        }  			
    }	
}

function generateBlockJ (nbTab, position, divName, tabName){	
    var tempDivName;
    var tempTabName;   
    var tempLine;	
    if (position<=4){
        tempLine=8
        }else{
        tempLine=4
        } 
    for (var i=1; i<=nbTab; i++){
        tempDivName = divName + i;
        tempTabName = tabName + i;
        if (i != position){
            changestyle(tempDivName,'none');
            if (i== tempLine){ 
                changecolor(tempTabName,'tabButtonOff2');				
            }else{
                changecolor(tempTabName,'tabButtonOff');
            } 			
        }else{
            changestyle(tempDivName,'block');
            if (i== tempLine){
                changecolor(tempTabName,'tabButtonOn2');				
            }else{
                if(nbTab==4 && i==4){
                    changecolor(tempTabName,'tabButtonOn2');
                }else{
                    changecolor(tempTabName,'tabButtonOn');
                }
            } 	
            if(i!=1 && i!=5){
                tempTabName = tabName + (i-1);
                changecolor(tempTabName,'tabButtonOff3');				
            }
        }	
        if(nbTab==4 && i==4){
            changecolor(tempTabName,'tabButtonOff2');
            if (i == position){
                tempTabName = tabName + (i-1);
                changecolor(tempTabName,'tabButtonOff3');	
            }
        }
		
    }	
    switchLine (nbTab, position, tabName);	
}
// End Block J - Tab Management



var clear="http://www.disneylandparis.co.uk/Images/spacer.gif"; //path to clear.gif

document.write('<script type="text/javascript" id="ct" defer="defer" src="javascript:void(0)"><\/script>');


var ct=document.getElementById("ct");
ct.onreadystatechange=function(){
    if (msieVersion() == 6) { 
        pngfix();
    }
};

pngfix=function(){
    var els=document.getElementsByTagName('*'),ip=/\.png/i,al="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='",i=els.length,uels=new Array(),c=0;
    while(i-->0){
        if(els[i].className.match(/unitPng/)){
            uels[c]=els[i];
            c++;
        }
    }
    if(uels.length==0)pfx(els);else pfx(uels);
    function pfx(els){
        i=els.length;
        while(i-->0){
            var el=els[i],es=el.style,elc=el.currentStyle,elb=elc.backgroundImage;
            if(el.src&&el.src.match(ip)&&!es.filter){
                es.height=el.height;
                es.width=el.width;
                es.filter=al+el.src+"',sizingMethod='crop')";
                el.src=clear;
            }else{
                if(elb.match(ip)){
                    var path=elb.split('"'),rep=(elc.backgroundRepeat=='no-repeat')?'crop':'scale',elkids=el.getElementsByTagName('*'),j=elkids.length;
                    es.filter=al+path[1]+"',sizingMethod='"+rep+"')";
                    es.height=el.clientHeight+'px';
                    es.backgroundImage='none';
                    if(j!=0){
                        if(elc.position!="absolute")es.position='static';
                        while(j-->0)if(!elkids[j].style.position)elkids[j].style.position="relative";
                    }
                }
            }
        }
    }
};



/***********************
       Forms utils 
***********************/

function optionYearPlus2(selectName, selectId, firstValue){		
    currentYear = new Date().getFullYear();
	
    document.write("<select name='"+selectName+"' id='"+selectId+"'>");
    document.write("<option>"+firstValue+"</option>");	
    document.write("<option value='2006'>"+currentYear+"</option>");
    document.write("<option value='2006'>"+(currentYear+1)+"</option>");
    document.write("<option value='2006'>"+(currentYear+2)+"</option>");	
    document.write("</select>");							
}	 

function optionLast90Year(selectName, selectId, firstValue){		
    currentYear = new Date().getFullYear();
    last90 = currentYear-90;
	
    document.write("<select name='"+selectName+"' id='"+selectId+"'>");
    document.write("<option>"+firstValue+"</option>");
    for (var i=currentYear; i>last90; i--) {
        document.write("<option value='"+i+"'>"+i+"</option>");
    }	
    document.write("</select>");	
}	

function optionDRPOpenYear(selectName, selectId, firstValue){		
    currentYear = new Date().getFullYear();
    DRPOpen = 1992;
    document.write("<select name='"+selectName+"' id='"+selectId+"'>");
    document.write("<option>"+firstValue+"</option>");	
    for (var i=currentYear; i>=DRPOpen; i--) {
        document.write("<option value='"+i+"'>"+i+"</option>");
    }	
    document.write("</select>");						
}	 




/***********************
       Footer utils 
***********************/

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 msieVersion() {
    var ua = window.navigator.userAgent;
    var msie = ua.indexOf ( "MSIE " );
    if ( msie > 0 ) {
        return parseInt (ua.substring (msie+5, ua.indexOf (".", msie )));
    }
    else {
        return 0;
    }
}


function ShowHide(id,imgId,path,styleName){
    if(document.getElementById(id).style.display=="block")
    {
        changestyle(id, "none");
        document.getElementById(imgId).src = path+styleName+"-f-hidden.gif";
    }else{
        changestyle(id, "block");
        document.getElementById(imgId).src = path+styleName+"-f-visble.gif";
    }
}


// Fonction gestion investor-relations

function  chooseIndicator(nbItem, currentItem, itemName, itemImage , classLight, classDark){		

    for (var i=1; i<=nbItem; i++){
        if (i == currentItem){
            document.getElementById(itemName+currentItem).className = classLight; 	
            document.getElementById(itemImage+currentItem).style.display = 'block';
        }else{
            document.getElementById(itemName+i).className= classDark; 	
            document.getElementById(itemImage+i).style.display = 'none';			
        }
    }
}

function zoomIndicator(objetImage, status){
    var posX = findPosX(document.getElementById('referentiel'))-100;
    var posY = findPosY(document.getElementById('referentiel'))-50;
    if (status){
        document.getElementById(objetImage).style.position = 'absolute';
        document.getElementById(objetImage).style.left = posX+"px";		
        document.getElementById(objetImage).style.top = posY+"px";			
        document.getElementById(objetImage).className = 'Display';		
    }else{
        document.getElementById(objetImage).className = 'NoDisplay';
    }
}

/***********************
       Browser detection 
***********************/

var BrowserDetect = {
    init: function () {
        this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
        this.version = this.searchVersion(navigator.userAgent)
        || this.searchVersion(navigator.appVersion)
        || "an unknown version";
        this.OS = this.searchString(this.dataOS) || "an unknown OS";
    },
    searchString: function (data) {
        for (var i=0;i<data.length;i++)	{
            var dataString = data[i].string;
            var dataProp = data[i].prop;
            this.versionSearchString = data[i].versionSearch || data[i].identity;
            if (dataString) {
                if (dataString.indexOf(data[i].subString) != -1)
                    return data[i].identity;
            }
            else if (dataProp)
                return data[i].identity;
        }
    },
    searchVersion: function (dataString) {
        var index = dataString.indexOf(this.versionSearchString);
        if (index == -1) return;
        return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
    },
    dataBrowser: [
    {
        string: navigator.userAgent,
        subString: "OmniWeb",
        versionSearch: "OmniWeb/",
        identity: "OmniWeb"
    },
    {
        string: navigator.vendor,
        subString: "Apple",
        identity: "Safari"
    },
    {
        prop: window.opera,
        identity: "Opera"
    },
    {
        string: navigator.vendor,
        subString: "iCab",
        identity: "iCab"
    },
    {
        string: navigator.vendor,
        subString: "KDE",
        identity: "Konqueror"
    },
    {
        string: navigator.userAgent,
        subString: "Firefox",
        identity: "Firefox"
    },
    {
        string: navigator.vendor,
        subString: "Camino",
        identity: "Camino"
    },
    {		// for newer Netscapes (6+)
        string: navigator.userAgent,
        subString: "Netscape",
        identity: "Netscape"
    },
    {
        string: navigator.userAgent,
        subString: "MSIE",
        identity: "Explorer",
        versionSearch: "MSIE"
    },
    {
        string: navigator.userAgent,
        subString: "Gecko",
        identity: "Mozilla",
        versionSearch: "rv"
    },
    { 		// for older Netscapes (4-)
        string: navigator.userAgent,
        subString: "Mozilla",
        identity: "Netscape",
        versionSearch: "Mozilla"
    }
    ],
    dataOS : [
    {
        string: navigator.platform,
        subString: "Win",
        identity: "Windows"
    },
    {
        string: navigator.platform,
        subString: "Mac",
        identity: "Mac"
    },
    {
        string: navigator.platform,
        subString: "Linux",
        identity: "Linux"
    }
    ]

};
BrowserDetect.init();

function openPrint(dns){
    printPage=window.open(document.location.href+'?print', 'print', 'width=540,height=600,scrollbars=yes');
}


function checkPrint(dns){
    if(document.location.href.indexOf('?print')!=-1){
        document.getElementById('print').href=dns+'print.css';
        window.print();
    }
}

/**********************           CHANGE WEBSITE SELECT        **************************/
/******These methods enable to display a select menu in the footer for changing website********/
/***********************************************************************************/

function changeHttpValue(httpValue) {
    var i = httpValue.selectedIndex;
    if(i > 0)     {                  
        window.open(httpValue.options[i].value,'External','');
    }
}            
function changeSite() {               
    Event.observe($('changeSite'),'change',function(){
        changeHttpValue(this);
    });               
}


function deleteFirstSep() {
    if (document.getElementById('menuFooter')) {
        var  menuFooter = document.getElementById('menuFooter');      
        var spanMenuFooter = menuFooter.getElementsByTagName('span');              
        spanMenuFooter[0].style.backgroundImage = "none";
    }
}

/*
function displayGoogleSearchField() {  
    var html='';
    html = "<form onsubmit='return submitQueryGsc()' action='' class='gsc-submit-form'>"
    +"<input name='q'  id='query-input' onfocus='' class='gsc-search-field'"
    +"onblur='inputBlurGcs();' autocomplete='off'></input>"
    +"<button type='submit'  class='gsc-search-button'><div class='gsc-search-button-div'>"+searchGoogleItemString+"</div></button>"
    +"</form>";
    $('searchButtonId').innerHTML=html;
}
*/

function displayGoogleSearchField() {  
    var html='';
    html = "<form onsubmit='return submitQueryGsc()' action='' class='gsc-submit-form'>"
    +"<input name='q'  id='query-input' class='gsc-search-field' autocomplete='off'></input>"
    +"<button type='submit'  class='gsc-search-button'><div class='gsc-search-button-div'>"+searchGoogleItemString+"</div></button>"
    +"</form>";
    $('searchButtonId').innerHTML=html;
}



function inputFocusGcs() {
    document.getElementById('query-input').style['background'] = '';
}

function inputBlurGcs() {
    var queryInput = document.getElementById('query-input');
    if (!queryInput.value) {
        queryInput.style['background'] = '';
    } else {
        if ($$('table.gcsc-branding')) {
            $$('table.gcsc-branding').each(function(elmt, i) { 
                elmt.hide();
            });                    
        }

    }
}

function initGsc() {
    google.search.CustomSearchControl.attachAutoCompletion(
        gcsId
        );
    inputBlurGcs();
}

function submitQueryGsc() {    
    window.location = linkToSearchPage+'?q='
    + encodeURIComponent(
        document.getElementById('query-input').value);
    return false;
}

