﻿function LoadPopup(page, name, attributes)
{
    this.Page = page;
    this.Name = name;
    this.Attributes = attributes;
    
    var cookieName = this.Name;
    
    this.load = function()
    {
        /*if (this.readCookie(cookieName) == null)
        {
            this.open();
        }*/
    },
    this.open = function()
    {
        window.open(this.Page, this.Name, this.Attributes);
        this.createCookie(cookieName, "open"); 
    },
    this.close = function()
    {
        if (this.readCookie(cookieName) == "open")
        {
            this.deleteCookie(cookieName);
            this.createCookie(cookieName, "closed");
        } 
    },
    this.createCookie = 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 var expires = "";
	    document.cookie = name+"="+value+expires+"; path=/";  
    },
    this.readCookie = 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;
    },
    this.deleteCookie = function(name)
    {
        this.createCookie(name,"", -1);
    }
}

