/****************************************************/
// Javascript Base Helper Functions
// @copyright Fonqi, 23. oct 2008 
/****************************************************/

function Base()
{
	
}

Base.ToggleElement = function(id)
{
    var hide = false;
	if(document.getElementById(id).style.display == "")
		hide = true;
	if(hide)
	{
		document.getElementById(id).style.display = "none";	
	}
	else
	{
		document.getElementById(id).style.display = "";
	}
}

Base.HideElement = function(id)
{
	document.getElementById(id).style.display = "none";
}

Base.DisplayElement = function(id, displayType)
{
	document.getElementById(id).style.display = displayType;
}

Base.Trace = function(message)
{
	var alertDiv = this.Get("tracerDiv");
	var alertsContainer = this.Get("alertsContainer");
	if(alertDiv==null)
	{
		alertDiv = document.createElement('div');	
		alertsContainer = document.createElement('div');
		var closeButton = document.createElement('a');
		closeButton.innerHTML = "X";
		closeButton.href = "javascript:Base.ToggleElement('alertsContainer')";
		closeButton.style.lineHeight = "0.6";
		closeButton.style.cursor = "pointer";
		closeButton.style.textDecoration ="none";
		closeButton.style.color ="#666";
		closeButton.style.border = "1px solid #666"
		closeButton.style.minWidth = "2px";
		closeButton.style.minHeight = "5px";
		closeButton.style.position = "absolute";
		closeButton.style.left= "2px";
		closeButton.style.top= "2px";		
		alertDiv.appendChild(closeButton);
		alertDiv.appendChild(alertsContainer);
		alertsContainer.setAttribute('id', "alertsContainer");
	}
	alertDiv.setAttribute('id', "tracerDiv");	
	alertsContainer.innerHTML += "<p>"+message+"</p>";
	alertDiv.style.position = "absolute";
	alertDiv.style.left = "2px";
	alertDiv.style.top = "2px";
	alertDiv.style.backgroundColor = "#CCC";
	alertDiv.style.padding = "2px";
	alertDiv.style.font = "11px arial, helvetica";
	alertDiv.style.border = "1px solid #999";
	alertDiv.style.minWidth = "100px";
	alertDiv.style.minHeight = "8px";
	alertDiv.style.opacity = "0.7";
	alertDiv.style.filter = "alpha(opacity=70)";
	alertDiv.style.zIndex = "9999";
	document.getElementsByTagName("body")[0].appendChild(alertDiv);	
}

Base.IsValueInArray = function(value, array)
{
    for(var i = 0;i<array.length;i++)
    {
        if(array[i] == value)
        {
            return true;
        }
    }
    return false;
}

Base.Get = function(id)
{
    return document.getElementById(id);
}

/*
Prints all properties in an object (and their current values)
*/
Base.Inspect = function(obj) 
{
	var str = "";
	for ( var prop in obj )
	{
		str += "prop: " + prop + " is " + obj[prop] + "<br />";
	}
	trace(str);
}

Base.Now = function()
{
	var date = new Date();
	var retur = date.getDate()+"-"+(date.getMonth()+1)+"-"+date.getFullYear() +" "+date.getHours()+":"+date.getMinutes();
	return retur;
}

Base.AttachEvent = function(evType, obj, fn)
{
	if (obj.addEventListener)
	{
		obj.addEventListener(evType, fn, false);
		return true;			
	}
	else if (obj.attachEvent)
	{
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	} 
	else
	{
		return false;
	}
}

Base.OnPageLoad = function(func) 
{
	Base.AttachEvent('load', window, func);
}

//Adds a stylesheet to the header
Base.AddScript = function(path, element)
{
    var scriptNode = document.createElement('script');
    scriptNode.type = 'text/javascript';
    scriptNode.src = path;
    element.appendChild(scriptNode);
}




/****************************************************/
