
    var Utils = {};
    Object.extend(Utils, {
		Ajax:{},
		Element:{},
		Form:{},
		Document:{},
		StyleSheet:{},
		Cookie:{}

    });
    
	Object.extend(Utils.Ajax, {
		webServiceCaller:function()
		{
			var obj = arguments[0];
			var randomNum = new Date().getTime();
			
			var request = new Ajax.Request(obj.url+"?"+"datetime="+randomNum, {
				method:		obj.method, 
				parameters:	obj.parameters,
				postBody:   obj.postBody,
				onLoading:	obj.onLoading,
				onComplete:	obj.onComplete,
				onSuccess:	obj.onSuccess
			});
			
			return request;
		}
				  
	});
   
	Object.extend(Utils.Element, {
		emptyNode:function(node)
		{
		    if(node && node.hasChildNodes())
		    {
			    try
			    {
			        while(node.hasChildNodes())
			        {
			            node.removeChild(node.childNodes[0]);
			        }
			    }
			    catch(error){}
			}
		},
		
		getDirectAncestorByClassName:function(startNode, className)
		{
		    var nodeFind = null;
		    
		    $A(startNode.ancestors()).each(function(ancestor){
		        if(ancestor.hasClassName(className))
		        {
		            nodeFind = ancestor;
		            throw $break;
		        }
		    });
		    		    
		    //-> RETURN NODE
		    return nodeFind;
		
		},
        
		getDirectAncestorById:function(startNode, id)
		{
		    var nodeFind = null;
		    
		    $A(startNode.ancestors()).each(function(ancestor){
		        if(ancestor.id == id)
		        {
		            nodeFind = ancestor;
		            throw $break;
		        }
		    });
		    		    
		    //-> RETURN NODE
		    return nodeFind;
		
		}				  
	});
	
	
   	Object.extend(Utils.Form, {
		Element:
		{
            getOptionIndexByValue:function(combo, value)
            {
                var index = null;
                $A(combo.options).each(function(option, i){
                    if(option.value == String(value))
                    {
                       index = i;
                       throw $break;
                    }
                }); 
                
                return index; 
            }
            
	
		}
		        
	});
   
	Object.extend(Utils.Document, {
	
        viewportWidth:function()
        {
            if (Prototype.Browser.Opera) return document.body.clientWidth;
            return document.documentElement.clientWidth;
        },

        viewportHeight:function()
        {
            if(Prototype.Browser.Opera) return document.body.clientHeight;
            if(Prototype.Browser.WebKit) return this.innerHeight;
            return document.documentElement.clientHeight;
        },

        viewportSize:function()
        {
            return {'height':this.viewportHeight(), 'width':this.viewportWidth()};
        },

        getScrollLeft: function()
        {
            return this.pageXOffset || document.documentElement.scrollLeft;
        },

        getScrollTop:function()
        {
            return this.pageYOffset || document.documentElement.scrollTop;
        },

        getScrollOffsets:function()
        {
            return {'left':this.getScrollLeft(), 'top':this.getScrollTop()}
        },
	
		getPageSize:function()
		{
	        var xScroll, yScroll;
        	
	        if(window.innerHeight && window.scrollMaxY)
	        {	
		        xScroll = window.innerWidth + window.scrollMaxX;
		        yScroll = window.innerHeight + window.scrollMaxY;
	        }
	        else
	        {
	            if(document.body.scrollHeight > document.body.offsetHeight)
	            {
	                // all but Explorer Mac
		            xScroll = document.body.scrollWidth;
		            yScroll = document.body.scrollHeight;
	            }
	            else
	            {   // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		            xScroll = document.body.offsetWidth;
		            yScroll = document.body.offsetHeight;
	            }
	        }
        	
	        var windowWidth, windowHeight;

	        if (self.innerHeight) {	// all except Explorer
		        if(document.documentElement.clientWidth){
			        windowWidth = document.documentElement.clientWidth; 
		        } else {
			        windowWidth = self.innerWidth;
		        }
		        windowHeight = self.innerHeight;
	        } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		        windowWidth = document.documentElement.clientWidth;
		        windowHeight = document.documentElement.clientHeight;
	        } else if (document.body) { // other Explorers
		        windowWidth = document.body.clientWidth;
		        windowHeight = document.body.clientHeight;
	        }	
        	
	        // For small pages with total height less then height of the viewport
		    pageHeight = (yScroll < windowHeight)?windowHeight:yScroll;

	        // For small pages with total width less then width of the viewport
		    pageWidth = (xScroll < windowWidth)?xScroll:windowWidth;		

	        arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight) 
	        return arrayPageSize;

		}
				  
	});
	
	
   	Object.extend(Utils.StyleSheet, {

        setActiveStyleSheet:function(title)
        {
            var i, a, main;
            for(i=0; (a = document.getElementsByTagName("link")[i]); i++)
            {
                if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title"))
                {
                    a.disabled = true;
                    if(a.getAttribute("title") == title) a.disabled = false;
                }
            }
        },
        
        getActiveStyleSheet:function() 
        {
            var i, a;
            for(i=0; (a = document.getElementsByTagName("link")[i]); i++)
            {
                if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
            }
            
            return null;
        },
        
        getPreferredStyleSheet:function()
        {
            var i, a;
            for(i=0; (a = document.getElementsByTagName("link")[i]); i++)
            {
                if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title"))
                {
                    return a.getAttribute("title");
                }
            }
            
            return null;
        }
	
		        
	});
	
   	Object.extend(Utils.Cookie, {

        create:function(name, value, days)
        {
            if(days)
            {
                var date = new Date();
                date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
                var expires = "; expires=" + date.toGMTString();
            }
            
            else expires = "";
            document.cookie = name + "=" + value + expires + "; path=/";
        },

        read:function(name)
        {
            var nameEQ = name + "=";
            var ca = document.cookie.split(';');
            for(var i=0; i < ca.length; i++)
            {
                var c = ca[i];
                while(c.charAt(0) == ' ') c = c.substring(1, c.length);
                if(c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
            }
            return null;
        },
        
        erase:function(name)
        {
	        this.createCookie(name, "", -1);
        }      
	
		        
	});


