﻿function 
Set_Cookie( name, value, expires, path, domain, secure ) 
{ 
  //it's in milliseconds 
  var today = new Date(); 
  today.setTime( today.getTime() ); 
  if (expires) { 
  expires = expires * 1000 * 60 * 60 * 24; 
  } 
  var expires_date = new Date( today.getTime() + (expires) ); 
  document.cookie = name + "=" +escape( value ) + ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + ( ( path ) ? ";path=" + path : "" ) + ( ( domain ) ? ";domain=" + domain : "" ) + ( ( secure ) ? ";secure" : "" ); 
}

function CookieExist(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 true; 
  } 
  return false; 
}

function TestCookieExist()
{ 
  Set_Cookie('TEST_COOKIES', 'value', 365, '/', '', '' );
  if (!CookieExist('TEST_COOKIES')) return false; 
  Set_Cookie('TEST_COOKIES', 'value', -1, '/', '', '' );

  return true; 
}

function TestCookieExistVisible(p_id)
{
  if (document.getElementById(p_id) && !TestCookieExist()){
    document.getElementById(p_id).style.display = 'block';
    }
  else if (document.getElementById(p_id) && TestCookieExist()){ 
    document.getElementById(p_id).style.display = 'none';
  }
}