function $(id)
{
    if(document.getElementById(id))
        return document.getElementById(id)
    else
        return false;
}


// JavaScript Document
var commons = {
    /**
     * Reload all images
     */
    preloadImages : function()
    {
        var d = document;
        if (d.images)
        {
            if (!d.MM_p)
                d.MM_p = new Array();

            var i,j = d.MM_p.length,a = preloadImages.arguments;

            for (i = 0; i < a.length; i++)
            {
                if (a[i].indexOf("#") != 0)
                {
                    d.MM_p[j] = new Image;
                    d.MM_p[j++].src = a[i];
                }
            }
        }
    },

    /**
     * Unblur links
     */
    unblur: function()
    {
        this.blur();
    },

    /**
     * Blur links
     */
    blurLinks: function()
    {
        var links = document.getElementsByTagName("a");
        for ( var i = 0; i < links.length; i++)
        {
            links[i].onfocus = this.unblur;
        }
    },

    setPage: function(currentPage, pageClass)
    {
        if(typeof currentPage != "undefined" && currentPage != null)
            $(currentPage).className = pageClass;
    },

    focusElement: function(elmnt)
    {
        $(elmnt).focus();
    },

    viewPort: function()
    {
        // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
        if (typeof window.innerWidth != 'undefined')
            var viewPortWidth = window.innerWidth, viewPortHeight = window.innerHeight
        // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
        else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
            var viewPortHeight = document.documentElement.clientWidth, viewPortHeight = document.documentElement.clientHeight
        // older versions of IE
        else
            var viewPortWidth = document.getElementsByTagName('body')[0].clientWidth, viewPortHeight = document.getElementsByTagName('body')[0].clientHeight

        return viewPortWidth + "," + viewPortHeight;
        //var test=viewPort().split(","); -- Split
    }
}

var navigation = {

    /**
     * Get the full URL
     */
    url: function()
    {
        return window.location;
    },

    /**
     * Get part from the url
     * example:
     *  url:    http://localhost/main.do?action=list&type=1
     *  code:   alert(navigation.urlparts("action")); <- This will return "list"
     * @param name
     */
    urlparts: function( name )
    {
        name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
        var regexS = "[\\?&]"+name+"=([^&#]*)";
        var regex = new RegExp( regexS );
        var results = regex.exec( window.location.href );
        if( results == null )
            return false;
        else
            return decodeURIComponent(results[1]);
    },

    /**
     * Get the host.
     */
    host: function()
    {
        return window.location.protocol + "//" + window.location.host + "/";
    },

    /**
     * Show menu
     *
     * @param elmnt
     */
    showNav: function(elmnt)
    {
        elmnt.className = 'section nav';
    },

    /**
     * Hide menu
     *
     * @param elmnt
     */
    hideNav: function(elmnt)
    {
        elmnt.className = 'section';
    }
}

var messages = {

    /**
     * This method will call a popup that notifies for new messages.
     *
     * @param numberOfMessages
     */
    popup: function(numberOfMessages)
    {
        hs.htmlExpand(null, { objectType: 'ajax'} )
    },


    /**
     * This method will hide the popup.
     *
     */
    hide: function ()
    {

    }
}


var cookies = {
    /**
     * This method will check for a cookie.
     * If none is found will return null
     *
     * @param cookieName
     */

    get: function(cookieName)
    {
        if (document.cookie.length>0)
        {
            var c_start=document.cookie.indexOf(cookieName + "=");
            if (c_start!=-1)
            {
                c_start=c_start + cookieName.length+1;
                var c_end=document.cookie.indexOf(";",c_start);
                if (c_end==-1)
                    c_end=document.cookie.length;

                return unescape(document.cookie.substring(c_start,c_end));
            }
        }
        return null;
    },

    /**
     * This method is used to set cookies via javascript.
     *
     * @param cookieName
     * @param value
     * @param expiredays
     */
    set: function(cookieName,value,expiredays)
    {
        var exdate=new Date();
        exdate.setDate(exdate.getDate()+expiredays);
        document.cookie=cookieName+ "=" +escape(value)+
        ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());

    }
}

var fade = {
    duration: 1400,
    steps: 30,
    delay: 2000,
    stop: 0,
    currentOpacity: 0,

    stopTheFade: function(elmnt)
    {
        this.stop=elmnt;
    },

    getCurrentOpacity: function(elmnt)
    {
        var element = $(elmnt);
        if(!isNaN(element.style.opacity) && element.style.opacity != ("" || null))
            this.currentOpacity = parseInt(element.style.opacity);
        else if(!isNaN(element.style.MozOpacity) && element.style.MozOpacity != ("" || null))
            this.currentOpacity = parseInt(element.style.MozOpacity);
        else if(!isNaN(element.style.KhtmlOpacity) && element.style.KhtmlOpacity != ("" || null))
            this.currentOpacity = parseInt(element.style.KhtmlOpacity);
        else if(!isNaN(element.style.filter) && element.style.filter != ("" || null))
            this.currentOpacity = parseInt(element.style.filter);
        else
            this.currentOpacity = 0;

        if(isNaN(this.currentOpacity))
            this.currentOpacity = 0;
        //alert(this.currentOpacity)
    },

    setOpacity: function(elmnt,level)
    {
        var element = $(elmnt);
        element.style.opacity = level;
        element.style.MozOpacity = level;
        element.style.KhtmlOpacity = level;
        element.style.filter = "alpha(opacity=" + (level * 100) + ");";
    },


    In: function(elmnt, repeat, timeout)
    {
        fade.getCurrentOpacity(elmnt);
        for (var i = parseInt(this.currentOpacity); i <= 1; i += (1 / this.steps))
        {
            setTimeout("fade.setOpacity('"+elmnt+"','" + i + "')", i * this.duration);
        }
        if(repeat == "once" && this.stop != elmnt)
            setTimeout("fade.Out('"+elmnt+"', false)", (timeout ? timeout : this.delay));
        else if(repeat == "true" && this.stop != elmnt)
            setTimeout("fade.Out('"+elmnt+"', true)", this.delay);
    },

    Out: function(elmnt, repeat)
    {
        //fade.getCurrentOpacity(elmnt);
        for (var i = 0; i <= 1; i += (1 / this.steps))
        {
            setTimeout("fade.setOpacity('"+elmnt+"', '" + (1 - i) + "')", i * this.duration);
        }
        if(repeat && this.stop != elmnt)
            setTimeout("fade.In('"+elmnt+"', true)", this.duration);
        if(this.stop == elmnt)
            fade.In(elmnt, true);
    }
}

var manageStyles = {
    setCss: function()
    {
        var matchIe7 = /MSIE 7.0/gi;
        var matchIe6 = /MSIE 6.0/gi;
        var matchIe5 = /MSIE 5.0/gi;

        if(compatability.userAgent().match(matchIe6) || compatability.userAgent().match(matchIe5))
        {
            document.write('<link rel="stylesheet" type"text/css" href="css/style-jpg.css">');
            this.style = true;
        }
        else
        {
            document.write('<link rel="stylesheet" type="text/css" href="css/style.css">');
            if(compatability.userAgent().match(matchIe7))
                document.write('<link rel="stylesheet" type="text/css" href="css/ie7.css">');
        }
    },

    changeSection: function ()
    {
        if(this.style)
        {
            if($("mainSecGuest"))
            {
                var guest = new Array();
                    guest[0] = "mainSecGuest";
                    guest[1] = "mainSecGuest1";
                    guest[2] = "mainSecGuest2";
                    guest[3] = "mainSecGuest3";

                for(var i=0; i < guest.length ; i++ )
                {
                    if(i == 0)
                    {
                        document.getElementById(guest[i]).className="section";
                    }
                    else
                    {
                        document.getElementById(guest[i]).className="section"+i;
                    }
                }
            }
        }
    }

}