jQuery.noConflict();

//added to fix IE9 Ajax Issue
if(Sarissa._SARISSA_IS_IE && parseFloat(navigator.appVersion.substring(navigator.appVersion.indexOf("MSIE")+5)) >=9) {
	window.XMLSerializer = function(){};
	window.XMLSerializer.prototype.serializeToString=function(oNode){return oNode.xml;}
}

/** Standard popup window open
 * The first parameter will be the new URL.
 * Subsequent parameters will be (if supplied) the width and height.
 * If not specified the width and height will be 955 and 755 respectively.
 */
function openWin()
{
	var url, width=955, height=750, screenX=0, screenY=0, toolbar="no", menubar="no", scrollbars="yes", resizable="yes";
	var args = arguments;

	url = args[0];
	if (args.length>1)
	{
		width=args[1];
	}
	if (args.length>2)
	{
		height=args[2];
	}

	window.open (url, '_blank', 'width='+width+',height='+height+',screenX='+screenX+',screenY='+screenY+',scrollbars='+scrollbars+',toolbar='+toolbar+',menubar='+menubar+',resizable='+resizable);

	return false;
}

/* Function getAdSpot calls Dart's ad for ETF depending of the language received by parameter. */
function getAdSpot(site, language, tile, width, height) {

	if (language != undefined && language != "") {
		var zone = language.toLowerCase() == "fr" ? "french" : "_default";
			//alert("AdSpot(" + site + ", " + zone + ", " + tile + ", " + width + ", " + height + ");");
		AdSpot(site, zone, tile, width, height);
	}
}

// retenir les etats des categories collapsible, ceux qui sont open.
var summaryOpened = {};

function initSummaryCollapsible(){
	jQuery(".collapsible").collapsible({
		iconOpen: '',
		iconClose: '',
		visible: false
	});
}


(function($){
	/* Popup for send mail to a friend */
	window.openEmailPopup = function() {
		openModalDialog('modalEmail', {
			width: 830, 
			height: 700, 
			onLoad: function(){
				// This dialog has a different close position
				$('#cboxClose').css('top', 120);
			}
		});
	}
	
	/* Popup that ask to login */
	window.openLoginDialog = function() {
		if (loggedIn) {
			return true;
		} else {
			window.openModalDialog('modalDialog');
			return false;
		}
	}
	
	
	/* Generic modal */
    window.closeModalDialog = function() {
        setTimeout(function(){
            $('#cboxClose').click();
        }, 1);
    }
    
    window.openModalDialog = function(idDialog, options) {
        var selectorDialog = "#" + idDialog;
        
        // Extend options
        var opts = $.extend(true, {
        	initialWidth: 240,
        	initialHeight: 80,
            innerWidth: 380,
            speed: 250,
            open: true,
            close: "",
            inline: true,
            overlayClose: true,
            href: selectorDialog,
            onCleanup: function() {
                /* Colorbox remet l'element a sa place mais ne le cache pas */
                $(selectorDialog).hide();
                
                // Reset close position
                $('#cboxClose').css('top', 10);
            }
        }, options);

        // Show our dialog
        $(selectorDialog).show();
        $(selectorDialog).colorbox(opts);
        
        
        /**
         * Ad hoc patch: 
         * Colorbox add a live click event and when we click on an input, it bug (auto blur and resize).
         * I think this happen only when we use inline because we don't have that problem with ajax. 
         * We remove this event because it's not useful anyway.
         */
        $('.cboxElement').die();
    }
})(jQuery);
