//if string is empty
function isEmpty( inputStr ) { if ( null == inputStr || "" == inputStr ) { return true; } return false; }

var Dom = {
	
	//get element
	get: function(el) {
		if (typeof el === 'string') {
			return document.getElementById(el);
		}else {
			return el;
		}
	}

	//add element to DOM
	,add: function(el, dest) {
		var el = this.get(el);
		var dest = this.get(dest);
		dest.appendChild(el);
	}

	//remove element from DOM
	,remove: function(el) {
		var el = this.get(el);
		el.parentNode.removeChild(el);
	}
	
	,getFirstChild: function(el){
		var firstChild = el.firstChild;
		while(firstChild != null && firstChild.nodeType == 3){ // skip TextNodes
			firstChild = firstChild.nextSibling;
		}
		return firstChild;
	}
	
	,getNextSibling: function(el){
		var nextSib = el.nextSibling;
		while(nextSib != null && nextSib.nodeType == 3){ // skip TextNodes
			nextSib = nextSib.nextSibling;
		}
		return nextSib;
	}
	
	,getPreviousSibling: function(el){
		var nextSib = el.previousSibling;
		while(nextSib != null && nextSib.nodeType == 3){ // skip TextNodes
			nextSib = nextSib.previousSibling;
		}
		return nextSib;
	}
	
	,getElementsByClass: function(searchClass,node,tag){
		var classElements = new Array();
		if ( node == null )
			node = document;
		if ( tag == null )
			tag = '*';
		var els = node.getElementsByTagName(tag);
		var elsLen = els.length;
		var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
		for (i = 0, j = 0; i < elsLen; i++) {
			if ( pattern.test(els[i].className) ) {
				classElements[j] = els[i];
				j++;
			}
		}
		return classElements;
	}
	,getDocumentHeight: function(){
		var D = document;
	    return Math.max(
	        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
	        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
	        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
	    );
	}
	,hasClassName: function(el, strClass){
		
		if (el.className){
	
			// the classes are just a space separated list, so first get the list
			var arrList = el.className.split(' ');
			
			// get uppercase class for comparison purposes
			var strClassUpper = strClass.toUpperCase();
			
			// find all instances and remove them
			for (var i = 0; i < arrList.length; i++){
			
				// if class found
				if (arrList[i].toUpperCase() == strClassUpper){
					// we found it
					return true;
				}
			}
		}
		
		// if we got here then the class name is not there
		return false;	
	}
	
	,addClassName: function(el, strClass, blnMayAlreadyExist){
		// if there is a class
		if (el.className){
		
			// the classes are just a space separated list, so first get the list
			var arrList = el.className.split(' ');
			
			// if the new class name may already exist in list
			if (blnMayAlreadyExist){
			
				// get uppercase class for comparison purposes
				var strClassUpper = strClass.toUpperCase();
				
				// find all instances and remove them
				for (var i = 0; i < arrList.length; i++){
				
					// if class found
					if (arrList[i].toUpperCase() == strClassUpper){
					
						// remove array item
						arrList.splice(i, 1);
						
						// decrement loop counter as we have adjusted the array's contents
						i--;
					}
				}
			}
			
			// add the new class to end of list
			arrList[arrList.length] = strClass;
			
			// add the new class to beginning of list
			//arrList.splice(0, 0, strClass);
			
			// assign modified class name attribute
			el.className = arrList.join(' ');
		
		}else{
			// assign modified class name attribute      
			el.className = strClass;
		}
	}
	
	,removeClassName: function(el, strClass){
		
		if (el.className){
	  
		  // the classes are just a space separated list, so first get the list
		  var arrList = el.className.split(' ');
		
		  // get uppercase class for comparison purposes
		  var strClassUpper = strClass.toUpperCase();
		
		  // find all instances and remove them
		  for( var i = 0; i < arrList.length; i++ ){
		
		     if( arrList[i].toUpperCase() == strClassUpper ){
		
		        // remove array item
		        arrList.splice(i, 1);
		
		        // decrement loop counter as we have adjusted the array's contents
		        i--;
		     }
		     
		  }
		  el.className = arrList.join(' ');
		}
		
	}
};

// ======================================================================================================================================================================================================================================================================= 
// ! currentYPos
// 
// Description : Gets current y positioning relative to where the window is scrolled to 
// ======================================================================================================================================================================================================================================================================= 
// 
function getCurrentYPos(){
		
		if (self.pageYOffset){return self.pageYOffset;}
	    if (document.documentElement && document.documentElement.scrollTop) {
	        return document.documentElement.scrollTop;
	    }
	
	    if (this.getBodyEl().scrollTop) { return this.getBodyEl().scrollTop; }
	    return 0;
		
}

// ======================================================================================================================================================================================================================================================================= 
// ! getElYPos
// 
// Description : Gets referenced elements y coord positioning
// 
// Arguments:
// el                - referenced element 
// ======================================================================================================================================================================================================================================================================= 
// 
function getElYPos(el){

    if (el == null) { return 0; }
    var y = el.offsetTop;
    var node = el;
    while (node.offsetParent && node.offsetParent != getBodyEl()) {
        node = node.offsetParent;
        y += node.offsetTop;
    } 
    
    return y;
}


// ======================================================================================================================================================================================================================================================================= 
// ! GetBodyEl
// 
// Description : returns body element  
// ======================================================================================================================================================================================================================================================================= 
// 	
function getBodyEl(){

	var bel = document.getElementsByTagName("body");
	if (bel != null && bel.length > 0){ 
		return bel[0];
	}
	
	return document.body;
}

/** A AJAXConnection class  */
function AJAXConnection(name) {    
    this.className = 'AJAXConnection';
    //alert(this.className + ' ' + name);
    
    /** Default construtor
     *
     * name - div name
     */
    {    
        this.name = name;
    }

    this.xmlhttpPost = function (strURL, functionObj) {
        var xmlHttpReq = false;
        var self = this;
        // Mozilla/Safari
        if (window.XMLHttpRequest) {
            self.xmlHttpReq = new XMLHttpRequest();
            if (self.xmlHttpReq.overrideMimeType) {
                self.xmlHttpReq.overrideMimeType('text/xml');
                // See note below about this line
            }
        // IE
        } else if (window.ActiveXObject) { // IE
            try {
                self.xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
            }
        }
        if (!self.xmlHttpReq) {
            alert('ERROR AJAX:( Cannot create an XMLHTTP instance');
            return false;
        }    
        self.xmlHttpReq.open('GET', strURL, true);
        self.xmlHttpReq.setRequestHeader('Content-Type',
            'application/x-www-form-urlencoded');
        self.xmlHttpReq.onreadystatechange = function() { 
            _callBackFunction(self.xmlHttpReq, functionObj); 
        };
        self.xmlHttpReq.send("");
    }
    
    _callBackFunction = function (http_request, functionObj) {
        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
            	functionObj(http_request.responseText);
            } else {
                alert('ERROR: AJAX request status = ' + http_request.status);
            }
        }
	}
}
/*
var Event = {
	add: function(){
		if(window.addEventListener){
			return function(el, type, fn) {
				Dom.get(el).addEventListener(type, fn, false);
				};
		}else if(window.attachEvent){
			return function(el, type, fn){
					var f = function(){
						fn.call(Dom.get(el), window.event);
					};
				Dom.get(el).attachEvent('on' + type, f);
				};
		}
	}()
};
*/




