﻿var onLoadCallbacks = [];
var _oltimer;

function $(id,doc)
{   
    doc = typeof(doc) == 'undefined' || doc == null ? document : doc;
	return doc.getElementById(id);
}

function addEvent(o, evType, f, capture) {
	if(o == null) return false;
	if(o.addEventListener) {
		o.addEventListener(evType, f, capture);
		return true;
	} else if (o.attachEvent) {
		var r = o.attachEvent("on" + evType, f);
		return r;
	} else {
		try{ o["on" + evType] = f; }catch(e){}
	}
}
	

function removeEvent(o, evType, f, capture) {
	if(o == null) return false;
	if(o.removeEventListener) {
		o.removeEventListener(evType, f, capture);
		return true;
	} else if (o.detachEvent) {
		o.detachEvent("on" + evType, f);
	} else {
		try{ o["on" + evType] = function(){}; }catch(e){}
	}
}


function __olinit() {
	
	// quit if this function has already been called
	if (arguments.callee.done) return;

	// flag this function so we don't do the same thing twice
	arguments.callee.done = true;

	// kill the timer
	if (_oltimer) clearInterval(_oltimer);
    
    for (var x =0; x< onLoadCallbacks.length;x++)
    {
	    if (typeof(onLoadCallbacks[x]) == "function")
	    {
		    onLoadCallbacks[x]();
	    }
	}
	// do stuff
}

function addOnLoadHandler(func)
{

	onLoadCallbacks.push(func);
	/* for Mozilla/Opera9 */
	if (document.addEventListener) {
		document.addEventListener("DOMContentLoaded", __olinit, false);
	}

	/* for Internet Explorer */
	/*@cc_on @*/
	/*@if (@_win32)
		document.write("<script id=__ie_onload defer src=javascript:void(0)></script>");
		var script = document.getElementById("__ie_onload");
		script.onreadystatechange = function() {
			if (this.readyState == "complete") {
				__olinit(); // call the onload handler
			}
		};
	/*@end @*/

	/* for Safari */
	if (/WebKit/i.test(navigator.userAgent)) { // sniff
		 _oltimer = setInterval(function() {
			if (/loaded|complete/.test(document.readyState)) {
				__olinit(); // call the onload handler
			}
		}, 10);
	}

	/* for other browsers */
	window.onload = __olinit;
}

function globalHideSelectElements()
{

	var d = document.getElementsByTagName("select");
	for (var x =0; x < d.length; x++)
	{
	   
	    
		d[x].setAttribute("unhide","1");
		
		d[x].style.visibility = 'hidden';
	}
	
}
function globalRestoreSelectElements()
{
	var d = document.getElementsByTagName("select");
	for (var x =0; x < d.length; x++)
	{
		if (d[x].attributes["unhide"] != null && d[x].attributes["unhide"].value =="1" )
	    {
		    d[x].style.visibility = 'visible';
		}
		
	}
}


function ToggleDivVisibility(id)
{
    var dv = document.getElementById(id);
    
    dv.style.display = dv.style.display == 'none' ? 'block' : 'none';
    
}




//Tags stuff

var ClientTags = {
    
    Tags : '',
    Append : function(tags)
    {
        
        ClientTags.Tags+= tags;
        
    }
}
