var isInternetExplorer = (document.all ? true : false);


function applyParams(obj, params)
{
	for (var id in params)
	{
		obj[id] = params[id];
	}
}

function applyStyle(element, obj)
{
	try
	{
		if (obj.length != undefined)
		{
			var styles = new Object();
		
			for (var i=0; i<obj.length; i++)
			{
				if (obj[i] != undefined)
				{
					for (var j in obj[i])
					{
						styles[j] = obj[i][j];
					}
				}
			}
			
			obj = styles;
		}
	}
	catch (ex)
	{
	
	}

	for (var i in obj)
	{
		var us = i.indexOf("_");		
	
		if (us > 0)
		{
			var browser = i.substr(0, us);
			if ((browser == "ie" && !isInternetExplorer) || (browser == "moz" && isInternetExplorer))
			{
				continue;
			}
			
			if (browser == "ie" || browser == "moz")
			{
				var value = obj[i];
				i = i.substr(us + 1);
				obj[i] = value;
			}
			
		}

		if (i == "opacity")
		{
			var opacity = parseInt_wd(obj[i]);
			
			if (isInternetExplorer)
			{
				element.style.filter = "alpha(opacity=" + opacity + ")";
			}
			else
			{
				element.style.opacity = (opacity / 100);
			}
			continue;
		}
		
		if (i == "cssFloat" && element.style[i] == undefined)
		{
			obj["styleFloat"] = obj["cssFloat"];
			i = "styleFloat";
		}
		
		if (typeof(element.style[i]) == "string" || typeof(element.style[i]) == "number")
		{
			try
			{
				element.style[i] = obj[i];
			}
			catch (ex)
			{
			}
		}
	}
}

function setCenterPos(element)
{
	var dims = getDimensions(element);
	var w = dims.width / 2;
	var h = dims.height / 2;
	
	element.style.left = "50%";
	element.style.top = "50%";

	element.style.marginLeft = "-" + w + "px";
	element.style.marginTop = "-" + h + "px";
}

function mergeStyles()
{
	var mObj = new Object();

	for (var i=0; i<arguments.length; i++)
	{
		if (arguments[i] != undefined)
		{
			for (var j in arguments[i])
			{
				var type = typeof(arguments[i][j]);
				if (j == "length" || (type != "number" && type != "string"))
					continue;

				try
				{
					mObj[j] = arguments[i][j];
				}
				catch (ex) 
				{ }
			}
		}
	}

	return mObj;
}

function getDimensions(element)
{
	return { width: getWidth(element), height: getHeight(element) };
}

function getWidth(element)
{
	var w = parseInt(element.offsetWidth);
	var s = element.style;
	if (w == 0 && parseInt(s.width) > 0)
	{
		w = parseInt_wd(s.width);
		/*if (s.borderLeftWidth) w -= parseInt_wd(s.borderLeftWidth);
		if (s.borderRightWidth) w -= parseInt_wd(s.borderRightWidth);
		if (s.paddingLeft) w -= parseInt_wd(s.paddingLeft);
		if (s.paddingRight) w -= parseInt_wd(s.paddingRight);
		if (s.marginLeft) w -= parseInt_wd(s.marginLeft);
		if (s.marginRight) w -= parseInt_wd(s.marginRight);*/
	}
	return w;
}

function getHeight(element)
{
	var h = parseInt(element.offsetHeight);	
	var s = element.style;
	if (h == 0 && parseInt(s.height) > 0)
	{
		h = parseInt_wd(s.height);
		/*if (s.borderTopWidth) h -= parseInt_wd(s.borderTopWidth);
		if (s.borderBottomWidth) h -= parseInt_wd(s.borderBottomWidth);
		if (s.paddingTop) h -= parseInt_wd(s.paddingTop);
		if (s.paddingBottom) h -= parseInt_wd(s.paddingBottom);
		if (s.marginTop) h -= parseInt_wd(s.marginTop);
		if (s.marginBottom) h -= parseInt_wd(s.marginBottom);*/		

	}	
	return h;
}

function calcRealWidth(element, w, inside, ignoreMargins)
{
	var s = element.style;
	if (inside == undefined) inside = false;
	if (ignoreMargins == undefined) ignoreMargins = false;
	if (w == undefined) w = s.width;
	w = parseInt_wd(w);

	if (inside)
	{
		w -= parseInt_wd(s.borderLeftWidth);
		w -= parseInt_wd(s.borderRightWidth);
		w -= parseInt_wd(s.paddingLeft);
		w -= parseInt_wd(s.paddingRight);
	}
	else
	{
		w += parseInt_wd(s.borderLeftWidth);
		w += parseInt_wd(s.borderRightWidth);
		w += parseInt_wd(s.paddingLeft);
		w += parseInt_wd(s.paddingRight);
	}
	
	if (!ignoreMargins)
	{
		if (inside)
		{
			w -= parseInt_wd(s.marginLeft);
			w -= parseInt_wd(s.marginRight);
		}
		else
		{
			w += parseInt_wd(s.marginLeft);
			w += parseInt_wd(s.marginRight);
		}
	}
	
	return w;

}

function calcRealHeight(element, h, inside, ignoreMargins)
{
	var s = element.style;
	if (inside == undefined) inside = false;
	if (ignoreMargins == undefined) ignoreMargins = false;
	if (h == undefined) h = s.height;
	h = parseInt_wd(h);

	if (inside)
	{
		h -= parseInt_wd(s.borderTopWidth);
		h -= parseInt_wd(s.borderBottomWidth);
		h -= parseInt_wd(s.paddingTop);
		h -= parseInt_wd(s.paddingBottom);
	}
	else
	{
		h += parseInt_wd(s.borderTopWidth);
		h += parseInt_wd(s.borderBottomWidth);
		h += parseInt_wd(s.paddingTop);
		h += parseInt_wd(s.paddingBottom);
	}
	
	if (!ignoreMargins)
	{
		if (inside)
		{
			h -= parseInt_wd(s.marginTop);
			h -= parseInt_wd(s.marginBottom);
		}
		else
		{
			h += parseInt_wd(s.marginTop);
			h += parseInt_wd(s.marginBottom);
		}
	}
	
	return h;

}

function calcRealSize(element, w, h, inside, ignoreMargins)
{
	return { 
		width: calcRealWidth(element, w, inside, ignoreMargins), 
		height: calcRealHeight(element, h, inside, ignoreMargins) 
		};
}

function setSize(element, w, h)
{
	if (typeof(w) == "object")
	{
		h = w.height;
		w = w.width;
	}

	element.style.width = parseInt_wd(w) + "px";
	element.style.height = parseInt_wd(h) + "px";
}

function setPos(element, left, top)
{
	if (typeof(left) == "object")
	{
		top = left.top;
		left = left.left;
	}

	element.style.left = parseInt_wd(left) + "px";
	element.style.top = parseInt_wd(top) + "px";
}

function getPos(element)
{
	var left = 0;
	var top = 0;

	var curElement = element;
	
	while (curElement != null)
	{
		left += curElement.offsetLeft;
		top += curElement.offsetTop;
		curElement = curElement.offsetParent;
	}
	
	return { left: left, top: top };
}

function setOpacity(element, opacity)
{
	if (document.all)
	{
		element.style.filter = "alpha(opacity=" + opacity + ")";
	}
	else
	{
		element.style.MozOpacity = opacity / 100;
	}
}


function parseInt_wd(obj, defaultVal)
{
	if (defaultVal == undefined)
		defaultVal = 0;
		
	var val = parseInt(obj);
	if (isNaN(val))
		val = defaultVal;
		
	return val;
}

function disableSelection(target)
{
	if (typeof target.onselectstart!="undefined") // IE
		target.onselectstart=function(){return false}
	else if (typeof target.style.MozUserSelect!="undefined") // Firefox
		target.style.MozUserSelect="none"
	else // Other browsers
		target.onmousedown=function(){return false}

	target.style.cursor = "default"
}

function getElementsByClassName(className, nodes)
{
	var foundNodes = new Array();
	if (nodes == undefined) nodes = document.childNodes;

	for (var i=0; i<nodes.length; i++)
	{
		var n = nodes[i];

		if (n.className == className)
			foundNodes.push(n);
	
		if (n.childNodes.length > 0)
			foundNodes = foundNodes.concat(getElementsByClassName(className, n.childNodes));
	}
	
	
	return foundNodes;
}

function gotoAnchor(id)
{
	top.location.href = "#" + id; 
}

function changeColorImage(image,id){
	document.getElementById('colorimage').setAttribute("src",image);
	BigImg = document.getElementById('source_big_'+id).rel;
	document.getElementById('thumbImg').setAttribute("href",BigImg);
}

/**
	GOOGLE MAP
**/
    function initialize() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map_canvas"))
        var gLat = new GLatLng(48.632157,2.398624)
        map.setCenter(gLat, 8);
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        
	 	var marker = new GMarker(gLat);
		
		/*var markerText = "<b>Locafontaine</b><br /><p>2 Avenue Ambroise Croizat</p><p>91031 (RIS ORANGIS)</p><p>Evry cedex - France</p>";*/
		var markerText = '<p style="text-align:left"><span style="width: 20px; display: block;float:left">&nbsp;</span><b>Locafontaine</b></p><p style="text-align:left"><img alt="Num&eacute;ro Vert" src="/img/icon/phone.png"/>&nbsp;<span>Num&eacute;ro Vert </span>: 0 800 400 418</p>'+
		'<p style="text-align:left"><img alt="Service Commercial" src="/img/icon/user_suit.png"/>&nbsp;<span>Service Commercial </span>: 01 60 79 71 79</p>'+
		'<p style="text-align:left"><img alt="Fax" src="/img/icon/telephone.png"/>&nbsp;<span>Fax </span>: 01 60 79 18 26</p>'+
		'<p style="text-align:left"><img alt="E-mail" src="/img/icon/email.png"/>&nbsp;<span>E-mail </span><a href="mailto:info@loca-fontaine.fr">info@loca-fontaine.fr</a></p>';
		
	  	GEvent.addListener(marker, "click", function() {
	    	marker.openInfoWindowHtml(markerText);
	  	});
	  	 
        map.addOverlay(marker);
        marker.openInfoWindowHtml(markerText);
      }
    }
    
function DisplayMail(Server, Login, Display){  
    if ((Display.length == 0) || (Display.indexOf('@')+1)) {  
    document.write('<a href=' + '"mai' + 'lto:' + Login + '@' + Server + '">' + Login + '@' + Server + '<\/a>'); }  
    else  {  
    document.write('<a href=' + '"mai' + 'lto:' + Login + '@' + Server + '">' + Display + '<\/a>'); }  
}

