cookies.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. function Set_Cookie( name, value, expires, path, domain, secure ) {
  2. // set time, it's in milliseconds
  3. var today = new Date();
  4. today.setTime( today.getTime() );
  5. // if the expires variable is set, make the correct expires time, the
  6. // current script below will set it for x number of days, to make it
  7. // for hours, delete * 24, for minutes, delete * 60 * 24
  8. if ( expires )
  9. {
  10. expires = expires * 1000 * 60 * 60 * 24;
  11. }
  12. //alert( 'today ' + today.toGMTString() );// this is for testing purpose only
  13. var expires_date = new Date( today.getTime() + (expires) );
  14. //alert('expires ' + expires_date.toGMTString());// this is for testing purposes only
  15. document.cookie = name + "=" +escape( value ) +
  16. ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
  17. ( ( path ) ? ";path=" + path : "" ) +
  18. ( ( domain ) ? ";domain=" + domain : "" ) +
  19. ( ( secure ) ? ";secure" : "" );
  20. }
  21. function Get_Cookie( name ) {
  22. var start = document.cookie.indexOf( name + "=" );
  23. var len = start + name.length + 1;
  24. if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
  25. {
  26. return null;
  27. }
  28. if ( start == -1 ) return null;
  29. var end = document.cookie.indexOf( ";", len );
  30. if ( end == -1 ) end = document.cookie.length;
  31. return unescape( document.cookie.substring( len, end ) );
  32. }
  33. var xmlHttp=null;
  34. var url=null
  35. function set_url(ref)
  36. {
  37. url=ref;
  38. }
  39. function mostrar_aviso()
  40. {
  41. document.getElementById("box").style.visibility="visible";
  42. }
  43. function ocultar_aviso()
  44. {
  45. document.getElementById("box").style.visibility="hidden";
  46. }
  47. function notificar()
  48. {
  49. vernuevos()
  50. setTimeout("notificar()",60000)
  51. }
  52. function vernuevos()
  53. {
  54. xmlHttp=GetXmlHttpObject(stateChanged)
  55. xmlHttp.open("GET", url , true)
  56. xmlHttp.send(null)
  57. }
  58. function stateChanged()
  59. {
  60. if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
  61. {
  62. document.getElementById("nuevos").innerHTML=xmlHttp.responseText
  63. if(Get_Cookie("nuevos")==null || xmlHttp.responseText-Get_Cookie("nuevos")>0 )
  64. {
  65. mostrar_aviso()
  66. setTimeout("ocultar_aviso()",7000);
  67. }
  68. Set_Cookie( "nuevos", xmlHttp.responseText, 0, "/",'','')
  69. }
  70. }
  71. function GetXmlHttpObject(handler)
  72. {
  73. var objXmlHttp=null
  74. if (navigator.userAgent.indexOf("Opera")>=0)
  75. {
  76. objXmlHttp=new XMLHttpRequest()
  77. objXmlHttp.onload=handler
  78. objXmlHttp.onerror=handler
  79. return objXmlHttp
  80. }
  81. if (navigator.userAgent.indexOf("MSIE")>=0)
  82. {
  83. var strName="Msxml2.XMLHTTP"
  84. if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
  85. {
  86. strName="Microsoft.XMLHTTP"
  87. }
  88. try
  89. {
  90. objXmlHttp=new ActiveXObject(strName)
  91. objXmlHttp.onreadystatechange=handler
  92. return objXmlHttp
  93. }
  94. catch(e)
  95. {
  96. alert("Error. Scripting for ActiveX might be disabled")
  97. return
  98. }
  99. }
  100. if (navigator.userAgent.indexOf("Mozilla")>=0)
  101. {
  102. objXmlHttp=new XMLHttpRequest()
  103. objXmlHttp.onload=handler
  104. objXmlHttp.onerror=handler
  105. return objXmlHttp
  106. }
  107. }