/*
function getText(oNode) {
	var sText = "";
	
	for(var i=0; i<oNode.childNodes.length; i++) {
		if(oNode.childNodes[i].hasChildNodes()) {
			sText += getText(oNode.childNodes[i]);
		} else {
			sText += oNode.childNodes[i].nodeValue;
		}
	}

	return sText;
}
*/

function getRefToDivNest(divID, oDoc) {
	if (!oDoc) {
		oDoc = document;
	}
	if (document.layers) {
		if (oDoc.layers[divID]) {
			return oDoc.layers[divID];
		} else {
			for (var x = 0, y; !y && x<oDoc.layers.length; x++) {
				y = getRefToDivNest(divID, oDoc.layers[x].document);
			}
			return y;
		}
	}
	if (document.getElementById) {
		return document.getElementById(divID);
	}
	if (document.all) {
		return document.all[divID];
	}
	return document[divID];
}

function isArray(a) {
    return isObject(a) && a.constructor == Array;
}

function isBoolean(a) {
    return typeof a == 'boolean';
}

function isEmpty(o) {
    var i, v;
    if (isObject(o)) {
        for (i in o) {
            v = o[i];
            if (isUndefined(v) && isFunction(v)) {
                return false;
            }
        }
    }
    return true;
}

function isFunction(a) {
    return typeof a == 'function';
}

function isNull(a) {
    return a === null;
}

function isNumber(a) {
    return typeof a == 'number' && isFinite(a);
}

function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}

function isString(a) {
    return typeof a == 'string';
}

function isUndefined(a) {
    return typeof a == 'undefined';
} 

// Swap image
function swapImg(imgId, imgSrc) {
	if(document.all) {
		document.images(imgId).src = imgSrc;
	} else {
		document.getElementById(imgId).src = imgSrc;
	}
}

function tmt_winPrint(id){ 
	if(window.print()){
	var d=eval(id)==null||eval(id+".closed");
	if(!d){eval(id+".print()");}}
}

function tmt_winControl(id,c){ 
	var d=eval(id)==null||eval(id+".closed");
	if(!d){eval(id+"."+c);}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function getObj(name) {
	if (document.getElementById) {
		this.obj = document.getElementById(name);
	} else if (document.all) {
		this.obj = document.all[name];
	} else if (document.layers) {
		this.obj = document.layers[name];
	}

	return this.obj;
}

// Return value of group
function getRadio(form, groupName) {
	var group = document.forms[form].groupName;
	
	for(var i=0; i<group.length; i++) {
		if(sizeGroup[i].checked == true) {
			return sizeGroup[i].value;
		}
	}
}

// Submit form
function submitForm(action, form) {
	document.forms[form].action = action;
	document.forms[form].submit();
}

// Resets form
function resetForm(form) {
	document.forms[form].reset();
}

// TEXT UTILS
// Replace text in element
function replaceText(el, text) {
  if (el != null) {
    clearText(el);
    var newNode = document.createTextNode(text);
    el.appendChild(newNode);
  }
}

// Clear element
function clearText(el) {
  if (el != null) {
    if (el.childNodes) {
      for (var i = 0; i < el.childNodes.length; i++) {
        var childNode = el.childNodes[i];
        el.removeChild(childNode);
      }
    }
  }
}

// Get text in element
function getText(el) {
  var text = "";
  if (el != null) {
    if (el.childNodes) {
      for (var i = 0; i < el.childNodes.length; i++) {
        var childNode = el.childNodes[i];
        if (childNode.nodeValue != null) {
          text = text + childNode.nodeValue;
        }
      }
    }
  }
  return text;
}

// Remove nodes recursive
function deleteNode(elementId){
	var label = getObj(elementId);	
	
	if(label) {
		while(label.hasChildNodes()) { 
			label.removeChild(label.lastChild);
		}
	}
}

// Get variables in querystring
function getQSVars(URL) {
        var strURL = URL.toString();
        var strVars = "";
        if ((strURL.lastIndexOf('?') + 1) > 0) {
                strVars = strURL.substring((strURL.lastIndexOf('?') + 1), strURL.length);
        }

        return strVars;
}
