/**
 * @author seubi
 */

YkeUI = {};

function YkeIsIe()
{
	var browserName=navigator.appName; 
	if (browserName=="Microsoft Internet Explorer")
		return true;
	else
		return false;
}

function YkeIsIe6OrOlder()
{
	if (typeof document.body.style.maxHeight != "undefined")
		return false;
	else
		return true;
}

function YkeClick()
{
	setTimeout('', 0);
}


YkeUI.Widgets = {};
YkeUI.Widgets.LoadingIndicator = function ()
{
	this.text = "Chargement en cours ...";
	this.className = "loadingIndicator";
	this.imgUrl = "yke/css/loadingSnake.gif";

	this.GetElement = function()
	{
		var div = document.createElement('div');	
		div.className = this.className;
		
		var img = document.createElement('img');
		img.src=this.imgUrl;
		
		var divimg = document.createElement('div');
		divimg.style.textAlign = 'center';
		divimg.appendChild(img);
		
		var divtxt = document.createElement('div');
		divtxt.style.textAlign = 'center';
		divtxt.appendChild(document.createTextNode(this.text));
		
		div.appendChild(divimg);
		div.appendChild(divtxt);
		
		return div;
	}
};

/*
 * 
 */
YkeUI.BindSelect = function(select, selectedID, arraySource, idPropName, textPropName, nullID, imageLoading, printNoChoice)
{
	select.style.display = "";
	imageLoading.style.display = "none";
	
	select.innerHTML = "";
	
	if(printNoChoice)
	{
		if(nullID != null)
		{
				var option = document.createElement("option");
				option.value = '-1';
				option.appendChild(document.createTextNode("(Aucun/Inconnu)"));
				select.appendChild(option);
		}
	}
	for(var i=0; i<arraySource.length; i++)
	{
		var value = arraySource[i][idPropName];
		var text = arraySource[i][textPropName];

		if(value != nullID)
		{
			var option = document.createElement("option");
			option.value = value;
			if(value == selectedID) option.selected = "selected";
			option.appendChild(document.createTextNode(text));
			select.appendChild(option);		
		}
	}	
}



Yke.UI = {};


Yke.UI.CreateElement = function(type, classname)
{
	var r = document.createElement(type);
	if(classname != null) r.className = classname;
	return r;
}
Yke.UI.AppendChild = function (parent, newChild)
{
	var success = false;
	try
	{
		if(parent.appendChild != null)
		{
			parent.appendChild(newChild);
			success = true;
		}
	}
	catch(e)
	{
	}
	return success;
}

$YCE = Yke.UI.CreateElement; // shorcut for createelement
$YAC = Yke.UI.AppendChild; // shortcut for append child
$CTN = function(text)
{
	return document.createTextNode(text);
}


Yke.UI.getAbsolutePosition = function (htmlElement)
{
	var ar = Position.cumulativeOffset(htmlElement);
	return {left: ar[0], top:ar[1]};
}

Yke.UI.getElementDimension = function (htmlElement)
{
	return {height: htmlElement.offsetHeight, width: htmlElement.offsetWidth};
}

