/*
 * http://kevin.vanzonneveld.net
 */
function is_string(val)
{
	return (typeof(val) == 'string');
} // function is_string

/*
 * http://kevin.vanzonneveld.net
 */
function is_object(val){
	if(val instanceof Array)
	{
		return false;
	}
	else
	{
		return (val !== null) && (typeof(val) == 'object');
	}
}

/* Get object by ID
 */
function wg_getbyid(id)
{
	if( is_string(id) )
	{
		return document.getElementById(id);
	}
	else if(is_object(id))
	{
		return id;
	}
	
	return null;
} // function wg_getbyid

/*
 */
function wg_remove(id)
{
	var elem = wg_getbyid(id);
	elem.parentNode.removeChild(id);
} // function wg_remove

/*
 */
function wg_add_event(id, ev, func)
{
	var obj = wg_getbyid(id);
	if(!obj)
	{
		return false;
	} // if
	
	if(obj.addEventListener)
	{
		obj.addEventListener(ev, func, true);
    } // if
    
	if(obj.attachEvent)
	{
		obj.attachEvent("on"+ev, func);
	} // if
	
	return true;
} // function wg_addevent

/*
 */
function wg_remove_event(id, ev, func)
{
	var obj = wg_getbyid(id);
	
	if ( obj.detachEvent )
	{
		obj.detachEvent('on'+ev, func);
	}
	else
	{
		obj.removeEventListener(ev, func, false);
	} // else
} // function wg_addevent

/* Set "display" property
 */
function wg_setdisplay(id, val)
{
	var elem = wg_getbyid(id);
	if(!elem)
	{
		return false;
	}
	
	elem.style.display = val;
	return true;
} // function wg_setdisplay

/* Set "visibility" property
 */
function wg_setvisibility(id, val)
{
	var elem = wg_getbyid(id);
	if(!elem)
	{
		return false;
	}
	
	elem.style.visibility = val;
	return true;
} // function wg_setvisibility

/* Set "class" property
 */
function wg_setclass(id, val)
{
	var elem = wg_getbyid(id);
	if(!elem)
	{
		return false;
	}
	
	elem.style.className = val;
	return true;
} // function wg_setclass

/* Set HTML inside block
 */
function wg_set_html(block_id, html_code)
{
	var obj = wg_getbyid(block_id);
	obj.innerHTML = html_code;
} // function wg_set_html

/* Append DIV block inside HTML element
 */
function wg_add_block(parent_id, class_name, id, html_code)
{
	var parent_obj = wg_getbyid(parent_id);
	if(!obj)
	{
		return false;
	} // if
	var obj = document.createElement('div');
	parent_obj.parentNode.appendChild(obj);
	
	if(class_name)
	{
		obj.setAttribute('class', class_name);
	} // if
	
	if(id)
	{
		obj.setAttribute('id', id);
	} // if
	
	if(html)
	{
		wg_set_html(obj, html_code)
	} // if
	
	return obj;
} // function wg_add_block

/*
 */
function load_image(url, w, h)
{
	var img = new Image(w, h);
	img.src = url;
	return img;
} // function load_image
