﻿

function CheckCooki(divlayer, id, url, width, height, left, top, name, value)
{
    if(GetPopCookie(name) != value) 
    {
        OpenLayer(divlayer, id, url, width, height, left, top);
    
    }   
}

function OpenPopUp(id, url, width, height, left, top, name, value)
{
    if(GetPopCookie(name) != value) 
    {        
        ViewPopup(id, url, width, height, left, top);
    }   
}


function CheckClose(divlayer, id, domain, name, value, addDate, ch )
{
    if( ch == true)
    {
        MakeCooki( domain, name, value, addDate);
    }
    
    ClosePop(divlayer, id)
}

// open 
function OpenLayer(divlayer, id, url, width, height, left, top)
{
    if( document.getElementById(id) == null)
    {        
        var popLayer = document.getElementById(divlayer);
        var PopDiv = document.createElement('DIV');
        
        PopDiv.className = 'popdiv';
        PopDiv.id = id;
        popLayer.appendChild( PopDiv);
        
        var iframe = document.createElement('IFRAME');
        iframe.style.backgroundColor = '#FFFFFF';
        iframe.style.border='0px';				
        iframe.style.position = 'absolute';				
        iframe.style.top = '0px';
        iframe.style.left = '0px';
        iframe.style.width = width + 'px'; 
        iframe.style.height = height  + 'px';	
        iframe.style.zIndex = 1000;				
        iframe.frameBorder = 0;
        iframe.src = url;
    	
        PopDiv.appendChild(iframe);				
        
        
        PopDiv.style.width =  width + 'px';
        PopDiv.style.height = height  + 'px';		
        PopDiv.style.left =  left + 'px';
        PopDiv.style.top = top  + 'px';
        PopDiv.style.zIndex = 1000;
        PopDiv.style.position = 'absolute';				                
    }            
}        
//close
function ClosePop(divlayer, id)
{
    var PopDiv = document.getElementById(id);            
    if( PopDiv != null)
    {
        document.getElementById(divlayer).removeChild(PopDiv);
    }            
}

function GetPopCookie( name )
{
     var nameOfCookie = name + "=";
     var x = 0;
     while ( x <= document.cookie.length ) {
          var y = (x+nameOfCookie.length);
          if ( document.cookie.substring( x, y ) == nameOfCookie ) {
               if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
                    endOfCookie = document.cookie.length;
          return unescape( document.cookie.substring( y, endOfCookie ) );
     }
          x = document.cookie.indexOf( " ", x ) + 1;
          if ( x == 0 )
               break;
     }
     return "";
}

function MakeCooki( domain, name, value, addDate)
{    
    var expireDate = new Date();
    expireDate.setDate( expireDate.getDate() + addDate);
    document.cookie = name + "=" + escape( value ) + "; path=/; domain=" + domain + " ; expires=" + expireDate.toGMTString() + ";";  
}

function ViewPopup(id, url, width, height, left, top)
{ 
    var openoption = "width=" + width + ",height=" + height + ",left=" + left + ",top=" + top + ",toolbar=no,status=no,scrollbars=no,resizable=no";
    wndPop=window.open(url, id, openoption );
}

function FocusPopup()
{
    try
    {
        wndPop.focus();
    }
    catch(e)
    { }
}

