/**
 * @projectDescription Zawiera zestaw często uzywanych metod
 * 
 * @copyright 2007 Robert (nospor) Nodzewski
 * @author Robert Nodzewski (nospor at interia dot pl)
 * @license http://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License
 * @version 1.0
 */

/**
 * @classDescription Klasa zawiera zestaw często uzywanych metod
 * @constructor
 */
function Mixed(){
};

/**
 * Tworzy element DOM
 * 
 * @param {String} element Nazwa elementu, np. input
 * @param {Object} parent Rodzic, do którego dodać element
 * @param {String} content Wartość jaką wpisać w innerHTML lub value, w zależności od typu elementu 
 * @param {String} id Identyfikator elementu
 * @param {String} className Klasa elementu
 * @param {String} style Styl css elementu
 * @param {Boolean} asFirst Czy wstawić na początek, czy na koniec
 * @memberOf Mixed
 * @return {Object} Zwraca utworzony element 
 */
Mixed.createElement = function(element, parent, content, id, className, style, asFirst) {
	el = element;
	element=document.createElement(element);
	if (!asFirst) parent.appendChild(element);
	else parent.insertBefore(element, parent.firstChild);
	if (id) {element.id=id;element.name=id;};
	if (className) 
		element.className=className;
	if (style) 
		element.style.cssText = style;
	if (content) {
		if (el!='input') element.innerHTML=content;
		else			 element.value=content;	
	};
	return element;
};

/**
 * Wyszukuje współrzędne oraz wymiary obiektu
 * 
 * @param {String, Object} id obiektu, lub obiekt
 * @memberOf Mixed
 * @return {Object} Obiekt o właściwościach x,y,width,height
 */
Mixed.getPosition = function(obj) { 
	if (typeof obj == 'string')
		obj = document.getElementById(obj);
	x=0;y=0;w=0;h=0; 
	if (obj) {
		w=obj.offsetWidth;
		h=obj.offsetHeight;
	};

	while (obj!=null) { 
		sl = 0; st = 0;
		is_div = /^div$/i.test(obj.tagName);
		if (is_div && obj.scrollLeft)
			sl = obj.scrollLeft;
		if (is_div && obj.scrollTop)
			st = obj.scrollTop;		
		x+=(obj.offsetLeft - sl); 
		y+=(obj.offsetTop - st); 
		obj=obj.offsetParent; 
	};
	return {'x':x,'y':y,'width':w,'height':h};
};

/**
 * Pobiera roota z xml
 * 
 * @param {Object} obj Obiekt ajaxa
 * @param {String} rootName Nazwa roota
 * @return {DOM, null} Zwraca obiekt roota lub null jeśli brak
 */
Mixed.getRoot = function(obj, rootName){
	if (!obj || !obj.responseXML)
		return null;
	root = obj.responseXML.documentElement;
	if (!root)
		return null;
	if (root.tagName.toUpperCase() == rootName.toUpperCase())
		return root;	
	root = root.getElementsByTagName(rootName);
	if (!root || root.length == 0)
		return null;
	return root.item(0);		
};

/**
 * Pobiera text z elementu XML
 * 
 * @param {DOM} element Element, z którego chcemy pobrać tekst
 */
Mixed.getText = function(element){
	if (!element)
		return null;
	elText = element.text;
	if (!elText)
		elText = element.textContent;
	if (!elText)
		elText = '';
	return elText;
};