﻿function Browser()
{
    var ua, s, i;

    this.isIE    = false;  // Internet Explorer
    this.isOP    = false;  // Opera
    this.isNS    = false;  // Netscape
    this.isSI    = false;  // Safari
    this.version = null;

    ua = navigator.userAgent;

    s = "Opera";
    if ((i = ua.indexOf(s)) >= 0)
    {
        this.isOP = true;
        this.version = parseFloat(ua.substr(i + s.length));
        return;
    }

    s = "Netscape6/";
    if ((i = ua.indexOf(s)) >= 0)
    {
        this.isNS = true;
        this.version = parseFloat(ua.substr(i + s.length));
        return;
    }

    s = "Safari/";
    if ((i = ua.indexOf(s)) >= 0)
    {
        this.isSI = true;
        this.version = parseFloat(ua.substr(i + s.length));
        return;
    }  

    // Treat any other "Gecko" browser as Netscape 6.1.

    s = "Gecko";
    if ((i = ua.indexOf(s)) >= 0)
    {
        this.isNS = true;
        this.version = 6.1;
        return;
    }

    s = "MSIE";
    if ((i = ua.indexOf(s)))
    {
        this.isIE = true;
        this.version = parseFloat(ua.substr(i + s.length));
        return;
    }
}

function getCookieValue(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;
}

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}

function popupEditor(url, w, h, scrollbars)
{
    if (!w)
        w = 800;
        
    if (!h)    
        h = 600;
        
    if (!scrollbars)
        scrollbars = "yes";
        
    var w_avail = screen.availWidth;
    var h_avail = screen.availHeight;
    var top = Math.round ((h_avail - h) * .5);
    var left = Math.round ((w_avail - w) * .5);	
    var dialogAppearance = "width="+w+",height="+h+",left="+left+",top="+top+",resizable=" + scrollbars + ",scrollbars=" + scrollbars;					
    window.open(url,'Editor',dialogAppearance,null);
}	    

