function showPopin(){
	$("a.popinLink").click(function(){
		showOpacDiv();
		$("#opacDiv").after("<div id=\"insidePopinContent\" class=\"popin\"></div>");
		$.ajax({
			type:"GET",
			url:this.href,
			success:function(msg) {
				$("#insidePopinContent").append(msg);
				miseEnFormePopin();
				if (typeof document.body.style.maxHeight === "undefined") {
					$("select").css("visibility","hidden");
				}
				 var windowsHeight = getWindowHeight();
				$("#mainContainer").css("height", windowsHeight+"px");
				$("#mainContainer").css("overflow","hidden");
				intitClosePopin();
				}
			});
		return false;
	});
}

function miseEnFormePopin(){
	tmp = $("#insidePopinContent .popinContent").clone();
	$("#insidePopinContent").empty();
	$("#insidePopinContent").append(tmp);
}

function intitClosePopin(){
	$('#insidePopinContent a.closePopin').click(function(){
		$('#insidePopinContent').remove();
		$('#opacDiv').css("display","none");
		if (typeof document.body.style.maxHeight === "undefined") {
			$("select").css("visibility","visible");
		}
		$("#mainContainer").css("height", "auto");
		$("#mainContainer").css("overflow","");
		return false;
	});

}
function closePopin(){
	$('#popinContainer a.closePopin').click(function(){
		$('#popinContainer').hide();
		$('#opacDiv').hide();
		if (typeof document.body.style.maxHeight === "undefined") {
			$("select").css("visibility","visible");
		}
		$("#mainContainer").css("height", "auto");
		$("#mainContainer").css("overflow","");
		return false;
	});

}

function intitPopinPanier(){
	$('#opacDiv').hide();
	var idPopinPanier = document.getElementById("popinContainer");
	if(idPopinPanier){
		$('#popinContainer').show();
		showOpacDiv();
		if (typeof document.body.style.maxHeight === "undefined") {
			$("select").css("visibility","hidden");
		}
		 var windowsHeight = getWindowHeight();
		$("#mainContainer").css("height", windowsHeight+"px");
		$("#mainContainer").css("overflow","hidden");	
		closePopin();
	
		}
	
}

function showOpacDiv(){
	var windowsHeight = getWindowHeight();
	if (typeof document.body.style.maxHeight === "undefined") {
		$('#opacDiv').css("height",windowsHeight+"px");
	}
	$('#opacDiv').show();	
}

function getWindowHeight() {

    var windowHeight=0;
	
    if (typeof(window.innerHeight)=='number') {
        windowHeight=window.innerHeight;
    }
    else {
     if (document.documentElement&&
       document.documentElement.clientHeight) {
         windowHeight = document.documentElement.clientHeight;
    }

    else {

     if (document.body&&document.body.clientHeight) {
         windowHeight=document.body.clientHeight;
      }
     }
    }
    return windowHeight;
}

$(document).ready(function(){
	showPopin();
	intitPopinPanier();
});


