﻿
function popup(popId , bCookie)
{
   $me = $('#'+popId);
   
    
   if( bCookie && ( getCookie(popId) == 'false' ) ) 
        return;
        
   if( $me.length > 0 )
   {
       var width = $me.attr('width');
       var height = $me.attr('height');
       var top = $me.attr('top');
       var left = $me.attr('left');
   
        $me.find('.bottom .button.close').click(function(){
            setCookie( popId,'false',0 )
            var $popup = $(this).parent().parent().parent(); 
            $popup.fadeOut(300); 
        });
        $me.find('.bottom .button.closeDay').click(function(){
            setCookie( popId,'false',1 )
            var $popup = $(this).parent().parent().parent(); 
            $popup.fadeOut(300); 
        });
   
   
        $me.css('top',top).css('left',left); 
        $me.width(width).height(height);
        if( left == '50%' )
        $me.css( 'margin-left',(-1 * (width/2) ) ) ;
        //$me.slideDown(500);
        //$me.css('display','block'); 
        $me.fadeIn(1000); 
        
   }
   
}  

function modal(modalId, bCookie)
{
   $me = $('#'+modalId);
   if( bCookie && ( getCookie(modalId) == 'false' ) ) 
        return;
        
   if( $me.length > 0 )
   {
       //var width = $me.attr('width');
       //var height = $me.attr('height');
       //var bottom = $me.attr('bottom');
       //var right = $me.attr('right');
   
       $me.find('.close').click(function(){
           setCookie( modalId,'false', '0' )
           var $modal = $(this).parent(); 
           $modal.hide(); 
       });
       $me.show();    
   }
}
   
function setCookie(name, value , expires)
{
    var path = "/";  
    var domain = "";  

    var cookie = name + "=" + escape(value);
    
    if(expires != 0){
        var today = new Date();
        today.setDate(today.getDate() + expires );
        cookie += "; expires="+today.toGMTString();
    }
    
    cookie += "; path=" + path ;
    
    document.cookie = cookie ;
}


function getCookie(name)
{
    var sCookieName = name + "=";
    var i = 0;
    var j;
    var endOfCookie;

    while ( i <= document.cookie.length )
    {
        j = (i+sCookieName.length);

        if ( document.cookie.substring(i,j) == sCookieName ){
            if ( (endOfCookie=document.cookie.indexOf( ";", j )) == -1 ){
                endOfCookie = document.cookie.length;
            }
            return unescape( document.cookie.substring( j, endOfCookie ) );
        }

        i = document.cookie.indexOf( " ", i ) + 1;
        if (i == 0){
            break;
        }
    }
    return "";
 }

