function BeautifulAddressContainer(containers, lastRowContainers)
{
    var addrContainers = containers;
    var maxHeight = -1;
    
    for (var i = 0; i < addrContainers.length; i++)
    {
        var container = $get(addrContainers[i]);
        var height = container.clientHeight;
        if (height > maxHeight)
            maxHeight = height;
    }
    
    for (var i = 0; i < addrContainers.length; i++)
    {
        var heightDiff = maxHeight - $get(addrContainers[i]).clientHeight;
        if (heightDiff > 0)
        {
            var container = $get(lastRowContainers[i]);    
            container.style.height = (container.clientHeight + heightDiff) + 'px';
        }
    }
    
}

function switch_image(imgId, img)
{
    var image = $get(imgId);
    image.src = img;
}

function chechPressBirthDate(day, month, year, addProductid, panelDate)
{
    var vday = $get(day);
    var vmonth = $get(month);
    var vyear = $get(year);
    var link = $get(addProductid);
    var panel = $get(panelDate);
    
    if (vday.value == '' || vmonth.value == '' || vyear.value == '')
    {
        panel.className = 'HighLightError';   
        $get('pressErrorBirthday').style.display = '';         
        return false;
    }
    panel.className = '';
    link.href = link.href.replace('birthday=01/01/0001', 'birthday=' + vday.value + '/' + vmonth.value +  '/' + vyear.value);
    /*document.location = dest;*/
    return true;
}

function chechPressBirthDateSelectChange(day, month, year, imageId, panelDate)
{
    var vday = $get(day);
    var vmonth = $get(month);
    var vyear = $get(year);
    var img = $get(imageId);
    var panel = $get(panelDate);
    
    if (vday.value == '' || vmonth.value == '' || vyear.value == '')
    {
        img.className = 'add-cart-lock';
    }
    else
    {
        img.className = 'add-cart';
        panel.className = '';
        $get('pressErrorBirthday').style.display = 'none';
    }
}


function ResizeWindow(imageId)
{
    var img = $get(imageId);

       iWidth = img.width ;
       iHeight = img.height;
       if (Sys.Browser.agent == Sys.Browser.InternetExplorer)
       {
            top.resizeTo(iWidth + 8, iHeight + 33);
       }
       else
            top.resizeTo(iWidth + 8, iHeight + 50);
       
}

function UpdateElement( id )
{
    var e = document.getElementById( id );
    var f = document.getElementById( id + "2" );

    try
    {                
        if ( e != undefined && screen.availWidth < 1024 )
        {
            e.width = "75%";   
            e.className = "";    
           
            if ( f != undefined )
            {
				f.width = "75%";
				f.className = "";   
            }
        }    
    }
    catch(e){}
}

function js_pressbirth( url )
{
 var e = $( "#pressbirth_day" );
 var f = $( "#pressbirth_month" );
 var g = $( "#pressbirth_year" );

 document.location = url + "&birthday=" + e.val() + "/" + f.val() + "/" + g.val();
}
          
// =====================================================================================================

	var ns = document.getElementById && !document.all;

	function ietruebody()
	{
		return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
	}

// ====================================================================================================

	pop = "";

	if(!document.getElementById){
	  if(document.all)
	  {
		document.getElementById=function()
		{
			if ( typeof document.all[ arguments[ 0 ] ] != "undefined" )
			{
				return document.all[arguments[0]];
			}
			else
			{
				return null;
			}
		}
	  }
	  else if(document.layers)
	  {
		document.getElementById = function()
		{
			if ( typeof document[ arguments[ 0 ] ] != "undefined" )
			{
				return document[ arguments[ 0 ] ];
			}
			else
			{
				return null;
			}
		}
	  }
	}
	
// ====================================================================================================

	function js_popup(path, w, h) 
	{
		var popup;
		
		if (w > 0 && h > 0)
		{
			popup = window.open(path, "popup" + Math.ceil(Math.random() * 1000), 'left=' + ((screen.width - w) / 2) + ',top=' + ((screen.height - h) / 2 - 50) + ',resizable=yes,scrollbars=no,status=0,width=' + w + ',height=' + h);
		}
		else
		{
			popup = window.open(path, "popup" + Math.ceil(Math.random() * 1000), 'left=' + ((screen.width - w) / 2) + ',top=' + ((screen.height - h) / 2 - 50) + ',resizable=yes,scrollbars=no,status=0, width=200, height=200');
		}
		
		popup.focus();
	}		function js_popup(path, w, h, isScrollbar) 
	{
		var popup;
		var scrollBar = (isScrollbar == true) ? "yes" : "no";
		if (w > 0 && h > 0)
		{
			popup = window.open(path, "popup" + Math.ceil(Math.random() * 1000), 'left=' + ((screen.width - w) / 2) + ',top=' + ((screen.height - h) / 2 - 50) + ',resizable=yes,scrollbars='+scrollBar+',status=0,width=' + w + ',height=' + h);
		}
		else
		{
			popup = window.open(path, "popup" + Math.ceil(Math.random() * 1000), 'left=' + ((screen.width - w) / 2) + ',top=' + ((screen.height - h) / 2 - 50) + ',resizable=yes,scrollbars='+scrollBar+',status=0, width=200, height=200');
		}
		
		popup.focus();
	}		function js_popup2(path, w, h) 
	{
		var popup;
		
		if (w > 0 && h > 0)
		{
			popup = window.open(path, "popup" + Math.ceil(Math.random() * 1000), 'left=' + ((screen.width - w) / 2) + ',top=' + ((screen.height - h) / 2 - 50) + ',resizable=yes,scrollbars=yes,status=0,width=' + w + ',height=' + h);
		}
		else
		{
			popup = window.open(path, "popup" + Math.ceil(Math.random() * 1000), 'left=' + ((screen.width - w) / 2) + ',top=' + ((screen.height - h) / 2 - 50) + ',resizable=yes,scrollbars=yes,status=0, width=200, height=200');
		}
		
		popup.focus();
	}	
// ====================================================================================================
		var height0 = -1;
	var PASSEPARTOUT_NONE = "Pas de passepartout";
	var paint_image; 	var load_image;	var load_image_count = 10;    var _realSizeImage = 0;

	function js_paint_preload( image_url )
	{
		paint_image = new Image();
		paint_image.src = image_url;
		if (_realSizeImage === 0)
		{
		    _realSizeImage = $get('paint4').height;
		}
		paint_image.height = _realSizeImage;
		$get('div-paint4').style.height = _realSizeImage + 'px';
	}
	
	function js_paint_configure()
	{
		js_paint_init(); 
		js_paint_cadre( cadre_selected ); 

		if ( navigator.appVersion.indexOf( "MSIE" ) < 0 )
		{ 
			js_paint_passepartout( passepartout_selected );
		}
		//else
		//{
		//	load_image = setInterval( "js_paint_configureIE()", 500 );
		//}
	}
	
	function js_paint_configureIE()
	{
		var e = document.getElementById( "paint4" );

		if ( e )
		{
			if ( paint_image.complete )
			{
				load_image_count--;
				js_paint_passepartout( passepartout_selected );
				
				if ( e.width > 0 && load_image_count < 0 )
				{
					clearInterval( load_image );
				}
			}
		}
	}

// ====================================================================================================

	function js_paint_init(needInitImage)
	{
		var e = document.getElementById( "paint4" );
		var f = document.getElementById( "paint3" );
		var g = document.getElementById( "paint5" );
		
		if ( e )
		{
			var height = parseFloat( paint_image.height, 10 );
			
			f.width = 25;
			f.height = height;
			
			g.width = 25;
			g.height = height;
			
			if (needInitImage == 'true')
			    e.height = height;

			document.getElementById( "div-paint3" ).style.height = height + "px";
			document.getElementById( "div-paint5" ).style.height = height + "px";
		}
	}
	
// ====================================================================================================

	function js_paint_format_load( id, pPassPartoutID )
	{
		var e = document.getElementById( "paint-format" );
		var check = " checked=\"checked\" ";
		var content = ["<table cellpadding=\"0\" cellspacing=\"0\" class=\"block-paint-format\">"];
		
		disponibilite_selected = id;
		format_selected = "";
		
		for( var format in Formats[ id ] )
		{
		    content.push("<tr>",
		    "<td class=\"width-paint-0\">",
		    "<input type=\"radio\" name=\"Format\" value=\"", format, "\" onclick=\"js_paint_cadre_load( '", id, "', '", format, "', '", pPassPartoutID, "' )\" ", check, " />",
		    "</td>",
		    "<td class=\"width-paint-1\">", js_paint_format_rectange( format ), "</td>",
		    "<td class=\"width-paint-2\">&nbsp;</td>",
		    "<td class=\"width-paint-3\">",  format, "</td>",
		    "</tr>");
			
		    if ( format_selected == "" )
		    {
			    format_selected = format;
			    check = "";
		    }
		}
		
		content.push("</table><br />");
		
		e.innerHTML = content.join('');
		
		js_paint_cadre_load( id, format_selected, pPassPartoutID );
		js_help();
	}

	// ----------------------------------------------------------------------------------------------------

	function js_paint_format_rectange( format )
	{
		var start = format.indexOf( "x" );
		var width = Math.floor( parseFloat( format.substr( 0, start ), 10 ) / 3 );
		var height = Math.floor( parseFloat( format.substr( start + 1, format.indexOf( " ", start ) - start - 1 ), 10 ) / 3 );
		
		return "<div class=\"block-paint-format-rectangle\" style=\"width:" + width + "px;height:" + height + "px\"></div>";
	}

// ====================================================================================================

	function js_paint_cadre_load( id, format, pPassPartoutID)
	{
		var e = document.getElementById( "paint-cadre" );
		var content = ["<table cellpadding=\"0\" cellspacing=\"1\" class=\"block-paint-border\">"];
		var check = " checked=\"checked\" ";
						
		format_selected = format;
		cadre_selected = "0";
		
		for( cadre in Formats[ id ][ format_selected ] )
		{
			content.push("<tr>",
			"<td class=\"width-paint-0\">",
			"<input type=\"radio\" name=\"Cadre\" value=\"", cadre, "\" onclick=\"js_paint_cadre( '", cadre, "', '", pPassPartoutID, "' )\" ", check, " />",
			"</td>",
			"<td class=\"width-paint-1\">", js_paint_cadre_image( cadre, Formats[ id ][ format_selected ][ cadre ][ 0 ] ), "</td>",
			"<td class=\"width-paint-2\">", js_paint_cadre_image_zoom( cadre, Formats[ id ][ format_selected ][ cadre ][ 0 ] ), "</td>",
			"<td class=\"width-paitn-3\">", Formats[ id ][ format_selected ][ cadre ][ 0 ], "</td>",
			"</tr>");
			
			check = "";
		}
		
		content.push("</table><br />");
		
		e.innerHTML = content.join('');
		
		js_paint_cadre( cadre_selected, pPassPartoutID);
		js_paint_passepartout_load(pPassPartoutID);
	}

	// ----------------------------------------------------------------------------------------------------

    

	function js_paint_cadre( id, pPassPartoutID)
	{
		if ( document.getElementById( "paint0" ) )
		{
			var e = document.getElementById( "paint4" );
			var f = document.getElementById( "pp_0" );
			var g = null;
			if (pPassPartoutID != null)
			    g = document.getElementById(pPassPartoutID);
			var h = document.getElementById( "pp_0" );
			var path = ["http://", host, "/App_Themes/common/images/paint/border/"].join('');

			cadre_selected = id;
			
			if ( id != "0" )
			{	
				id = id.toLowerCase();
				
				var paint0 = [path, id, "_top_left.gif"].join('');
				var paint1 = [path, id, "_top.gif"].join('');
				var paint2 = [path, id, "_top_right.gif"].join('');
				var paint3 = [path, id, "_left.gif"].join('');
				var paint5 = [path, id, "_right.gif"].join('');
				var paint6 = [path, id, "_bottom_left.gif"].join('');
				var paint7 = [path, id, "_bottom.gif"].join('');
				var paint8 = [path, id, "_bottom_right.gif"].join('');
			
				document.getElementById( "paint0" ).src = paint0;
				document.getElementById( "paint1" ).src = paint1;
				document.getElementById( "paint2" ).src = paint2;
				document.getElementById( "paint3" ).src = paint3;
				document.getElementById( "paint5" ).src = paint5;
				document.getElementById( "paint6" ).src = paint6;
				document.getElementById( "paint7" ).src = paint7;
				document.getElementById( "paint8" ).src = paint8;
				
				if ( Formats[ disponibilite_selected ][ format_selected ][ cadre_selected ][ 2 ] && Formats[ disponibilite_selected ][ format_selected ][ cadre_selected ][ 4 ] )
				{
					g.style.display = "block";
				}
			}
			else
			{
				path = ["http://", host, "/App_Themes/common/images/none.gif"].join('');

				document.getElementById( "paint0" ).src = path;
				document.getElementById( "paint1" ).src = path;
				document.getElementById( "paint2" ).src = path;
				document.getElementById( "paint3" ).src = path;
				document.getElementById( "paint5" ).src = path;
				document.getElementById( "paint6" ).src = path;
				document.getElementById( "paint7" ).src = path;
				document.getElementById( "paint8" ).src = path;
				
				if (g != null)
				    g.style.display = "none";
				
				if ( h )
				{
					h.checked = true;
				}
				
				passepartout_selected = PASSEPARTOUT_NONE;
				js_paint_passepartout( passepartout_selected );
			}
			
			if ( f && f.checked )
			{
				js_paint_init();
			}
			else
			{
			    js_paint_init('false');
			}
			
			js_description();
		}
	}

	// ----------------------------------------------------------------------------------------------------

	function js_paint_cadre_image( reference, nom )
	{
		var path = "/App_Themes/common/images/paint" ;
		var image = "<a href=\"javascript: js_popup( '" + path + "/preview/" + reference + ".jpg', 620, 620 )\">";

		image += "<img src=\"" + path + "/thumbs/" + reference  + ".gif\" alt=\"" + reference + "\" border=\"0\" />";
		image += "</a>";
		
		return image;
	}

	// ----------------------------------------------------------------------------------------------------

	function js_paint_cadre_image_zoom( reference, nom )
	{
		if ( reference != "0" )
		{
			var image = "<a href=\"javascript: js_popup( '/App_Themes/common/images/paint/preview/" + reference + ".jpg', 620, 620 )\">";
			image += "<img src=\"/App_Themes/" + pid + "/images/pict_zoom.gif\" alt=\"" + reference + "\" border=\"0\" />";
			image += "</a>";
			
			return image;
		}
		
		return "";
	}

// ====================================================================================================

	function js_description()
	{
	    var e = $(".actualPrice span");
	    var f = $(".block-paint-description span")[0];
	    var delay = $(".dispo span");
		
		f.innerHTML = js_ucfirst( disponibilite_selected );
		delay.html(Formats[ disponibilite_selected ][ format_selected ][ cadre_selected ][ 5 ]);
		
		var sum = js_getPriceSmall(Formats[ disponibilite_selected ][ format_selected ][ cadre_selected ][ 1 ]); // MOT add cofinoga
				
		if ( cadre_selected != "0" )
		{
			f.innerHTML += ", Cadre " + Formats[ disponibilite_selected ][ format_selected ][ cadre_selected ][ 0 ];
		}
		else
		{
			f.innerHTML += ", " + Formats[ disponibilite_selected ][ format_selected ][ cadre_selected ][ 0 ];
		}
		
		if ( Formats[ disponibilite_selected ][ format_selected ][ cadre_selected ][ 2 ] )
		{
			if ( Formats[ disponibilite_selected ][ format_selected ][ cadre_selected ][ 4 ] )
			{
			    if (passepartout_selected != null && passepartout_selected != "" 
				    && PassePartouts[ format_selected ][ passepartout_selected ][ 0 ])
				{
					f.innerHTML += ", " + PassePartouts[ format_selected ][ passepartout_selected ][ 0 ];
				}
				
				e.html(js_getPrice( parseFloat( Formats[ disponibilite_selected ][ format_selected ][ cadre_selected ][ 1 ], 10 ) + parseFloat( PassePartouts[ format_selected ][ passepartout_selected ][ 1 ], 10 ) ));
				sum = js_getPriceSmall(parseFloat(Formats[ disponibilite_selected ][ format_selected ][ cadre_selected ][ 1 ], 10) + parseFloat(PassePartouts[ format_selected ][ passepartout_selected ][ 1 ], 10));
			}
			else
			{
				e.html(js_getPrice( Formats[ disponibilite_selected ][ format_selected ][ cadre_selected ][ 1 ] ));
				sum = js_getPriceSmall(Formats[ disponibilite_selected ][ format_selected ][ cadre_selected ][ 1 ]);
			}
		}
		else
		{
			e.html(js_getPrice( Formats[ disponibilite_selected ][ format_selected ][ cadre_selected ][ 1 ] ));
			sum = js_getPriceSmall(Formats[ disponibilite_selected ][ format_selected ][ cadre_selected ][ 1 ]);
		}
		
		f.innerHTML += ", " + format_selected;
		if (sum >= 90) document.getElementById('divCofinoga').style.display = 'block'; 
		else document.getElementById('divCofinoga').style.display = 'none'; 
	}
	
	// ----------------------------------------------------------------------------------------------------
	function js_getPriceSmall( f )
	{
		f = f + "";
		
		var pos = f.indexOf( '.' );
		var pos2 = f.indexOf( ',' );
		
		if ( pos > 0 && ( pos + 4 ) <= f.length )
		{
			f = f.substr( 0, pos + 4 );
		}
		else if ( pos2 > 0 && ( pos2 + 4 ) <= f.length )
		{
			f = f.substr( 0, pos2 + 4 );
		}
		
		f = ( Math.round( parseFloat( f ) * 100 ) / 100 ) + "";
		
		if ( pos > -1 && ( f.substr( pos ).length - 1 ) < 2 )
		{
			f += '0';
		}
		else if ( pos2 > -1 && ( f.substr( pos2 ).length - 1 ) < 2 )
		{
			f += '0';
		}
		else if ( pos < 0 && pos2 < 0 )
		{
			f += ".00";
		}
				
		return f;
	}

	// ----------------------------------------------------------------------------------------------------

	function js_ucfirst( text )
	{
		text = text.substr( 0, 1 ).toUpperCase() + text.substr( 1 );
		return text;
	}
	
	// ----------------------------------------------------------------------------------------------------

	function js_getPrice( f )
	{
		f = f + "";
		
		var pos = f.indexOf( '.' );
		var pos2 = f.indexOf( ',' );
		
		if ( pos > 0 && ( pos + 4 ) <= f.length )
		{
			f = f.substr( 0, pos + 4 );
		}
		else if ( pos2 > 0 && ( pos2 + 4 ) <= f.length )
		{
			f = f.substr( 0, pos2 + 4 );
		}
		
		f = ( Math.round( parseFloat( f ) * 100 ) / 100 ) + "";
		
		if ( pos > -1 && ( f.substr( pos ).length - 1 ) < 2 )
		{
			f += '0';
		}
		else if ( pos2 > -1 && ( f.substr( pos2 ).length - 1 ) < 2 )
		{
			f += '0';
		}
		else if ( pos < 0 && pos2 < 0 )
		{
			f += ".00";
		}
				
		return f + "&euro;";
	}
		
// ====================================================================================================
	
	function js_order()
	{
		var e = document.getElementById( "ctl00_PHCenter_ProductFilePaint1_productCartPaint1_HLAddCart" );
		var delay = $("#ctl00_PHCenter_ProductFilePaint1_productCartPaint1_LDelayNumeric");
		
		var reference = paint_reference + "-" + Formats[ disponibilite_selected ][ format_selected ][ cadre_selected ][ 3 ];
		
		if ( Formats[ disponibilite_selected ][ format_selected ][ cadre_selected ][ 2 ] && Formats[ disponibilite_selected ][ format_selected ][ cadre_selected ][ 4 ] )
		{
			reference += "-" + PassePartouts[ format_selected ][ passepartout_selected ][ 2 ];
		}
		
		if ( url.indexOf( "&reference_add=" ) < 0 )
		{
			url += "&reference_add=" + reference;
		}
		else
		{
			url = url.replace( "&reference_add=" + paint_configuration, "&reference_add=" + reference );
		}
		url += "&delay=" + delay.html();
		paint_configuration = reference;
		
		location = url;
	}
	
	// ----------------------------------------------------------------------------------------------------

	function js_help()
	{
	    return;
		var e = document.getElementById( "ctl00_PHCenter_ProductFilePaint1_HLHelp0" );
		var f = document.getElementById( "ctl00_PHCenter_ProductFilePaint1_HLHelp1" );
		var path = ["javascript: js_popup2( 'http://", host, "/module/help/Message.aspx?id="].join();

		switch( disponibilite_selected )
		{
			case "estampe":
				f.href = path + "paintestampe";
				break;

			case "photo":
				f.href = path + "paintphoto";
				break;

			case "reproduction sur toile":
				f.href = path + "painttoile";
				break;
		}

		f.href += "&pid=" + pid+ "&donnee_appel=" + donnee_appel + "&chapsid=" + chapsid + "', 700, 500)";
		e.href = f.href;
	}