/*
 * @author         Dennis Milandt
 * Date created:   2008/05/30 12:00
 * Date revised:   2008/11/10 19:24
*/

var Utils = {	
    
    // Get object from id
    getObj:function(elementId)
    {
        return document.getElementById(elementId);
    },

    // Popup window
    popUp:function(url, windowName, width, height, extraParameters)
    {	
        var str='height='+height+',width='+width+','+extraParameters;
	    if(parseInt(navigator.appVersion)>3)
		    str += ',left=' + (screen.width -width)/2 + ',top=' + parseInt((screen.height -h)/3);			
	    return this.window.open(url, windowName, str);			
    },	

    // Sorts any listbox
    sortListBox:function(objListbox)
    {
	    var x;
	    var temparr = new Array(objListbox.options.length);
	    for(x = 0; x < objListbox.options.length; x++)
		    temparr[x] = objListbox.options[x].value + "||" + objListbox.options[x].text + "||" + objListbox.options[x].className;
	    temparr.sort();
	    for (x = 0; x < temparr.length; x++)
	    {
		    optionArr = temparr[x].split("||")
		    objListbox.options[x] = new Option(optionArr[1],optionArr[0]);	
		    objListbox.options[x].className = optionArr[2];
	    }
    },

    // Create a cookie
    createCookie:function(cookieName, value, daysToExpire)
    {
	    if (daysToExpire)
	    {
		    var date = new Date();
		    date.setTime(date.getTime() + (daysToExpire * 24 * 60 * 60 * 1000));
		    var expires = "; expires=" + date.toGMTString();
	    }
	    else 
	        var expires = "";
	    document.cookie = cookieName + "=" + value + expires + "; path=/";
    },

    // Read a cookie
    readCookie:function(cookieName)
    {
	    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;
    },

    // Delete a cookie
    deleteCookie:function(cookieName)
    {
	    createCookie(cookieName, "", -1);
    },

    // Get absolute left for an object
    getAbsLeft:function(object) { 
        var iY = 0; 
        if(object)
            while(object.offsetParent){ 
	            iY += parseInt(object.offsetLeft);
	            object = object.offsetParent;  
            } 
        return iY;
    },
    
    // Get absolute top for object
    getAbsTop:function(object) {  
	    var iX = 0; 
	    if(object)
		    while(object.offsetParent){ 
			    iX += parseInt(object.offsetTop);  
			    object = object.offsetParent;  
		    } 
	    return iX
    }
};

// Trims a string
String.prototype.trim = function() 
{
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.trimLeft = function() 
{
	return this.replace(/^\s+/,"");
}
String.prototype.trimRight = function() 
{
	return this.replace(/\s+$/,"");
}

// Reverse a string
String.prototype.reverse = function()
{
	var splitext = this.split("");
	var revertext = splitext.reverse();
	var reversed = revertext.join("");
	return reversed;
}