function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
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 Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
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 Get_Cookie( check_name ) {
       // first we'll split this cookie up into name/value pairs
        // note: document.cookie only returns name=value, not the other components
        var a_all_cookies = document.cookie.split( ';' );
        var a_temp_cookie = '';
        var cookie_name = '';
        var cookie_value = '';
        var b_cookie_found = false; // set boolean t/f default f

        for ( i = 0; i < a_all_cookies.length; i++ )
        {
                // now we'll split apart each name=value pair
                a_temp_cookie = a_all_cookies[i].split( '=' );


                // and trim left/right whitespace while we're at it
                cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

                // if the extracted name matches passed check_name
                if ( cookie_name == check_name )
                {
                        b_cookie_found = true;
                        // we need to handle case where cookie has no value but exists (no = sign, that is):
                        if ( a_temp_cookie.length > 1 )
                        {
                                cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
                        }
                        // note that in cases where cookie is initialized but no value, null is returned
                        return cookie_value;
                        break;
                }
                a_temp_cookie = null;
                cookie_name = '';
        }
        if ( !b_cookie_found )
        {
                return null;
        }
}
// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

/* script to assign rating START */
/* Updated February 7th, 2007 */

function $(o) { return((typeof(o)=='object'?o:document).getElementById(o)); }
function $S(o) { return($(o).style); }
function agent(v) { return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); }
function abPos(o) { var o=(typeof(o)=='object'?o:$(o)), z={X:0,Y:0}; while(o!=null) { z.X+=o.offsetLeft; z.Y+=o.offsetTop; o=o.offsetParent; }; return(z); }
function XY(e,v) { var o=agent('msie')?{'X':event.clientX+document.body.scrollLeft,'Y':event.clientY+document.body.scrollTop}:{'X':e.pageX,'Y':e.pageY}; return(v?o[v]:o); }

var star={

    /* Mouse Events */

    'cur':function(e,o) { if(star.stop) { star.stop=0;

        document.onmousemove=function(e) { var n=star.num;

            var p=abPos($('star'+n)), x=XY(e), oX=x.X-p.X, oY=x.Y-p.Y; star.num=o.id.substr(4);

            if(oX<1 || oX>84 || oY<0 || oY>19) { star.stop=1; star.revert(); }
         else {

                $S('starCur'+n).width=oX+'px';
                $S('starUser'+n).color='#111';
                v=Math.round(oX/84*100);
                q="";
               if(v>1&&v<=20) { q=" = Hated it"; }
                if(v>20&&v<=40) { q=" = Didn't like it"; }
                if(v>40&&v<=60) { q=" = Liked it"; }
                if(v>60&&v<=80) { q=" = Really liked it"; }
                if(v>80&&v<=100) { q=" = Loved it"; }
                if(v>1) {
                $('starUser'+n).innerHTML=Math.round(oX/84*100)+'%'+q;
                } else {
                $('starUser'+n).innerHTML="";
                }
            }
        };
    } },
    'update':function(e,o, ip, cook, id) { var n=star.num, v=parseInt($('starUser'+n).innerHTML);
        n=o.id.substr(4); $('starCur'+n).title=v;
        /* n is post id */
        Set_Cookie('tmfId'+id, v, 30, '/', '', '');
        oldip=Get_Cookie('ip'+id);
        /* alert(oldip); */
       Set_Cookie('ip'+id,ip,30, '/', '', '');

        req=new XMLHttpRequest();
/*
req.onreadystatechange=function()
    {
    if(req.readyState==4)
      {
      document.getElementById("testdiv").innerHTML=req.responseText;
      }
    }
*/

req.open('GET','star_insert.php?vote='+v+'&tmfId='+n+'&ip='+ip+'&cook='+cook+'&oldip='+oldip,false); req.send(null);
    },
    'revert':function() { var n=star.num, v=parseInt($('starCur'+n).title);

        $S('starCur'+n).width=Math.round(v*84/100)+'px';

        v=Math.round(v);
        q="";
        if(v>1&&v<=20) { q=" = Hated it"; }
        if(v>20&&v<=40) { q=" = Didn't like it"; }
        if(v>40&&v<=60) { q=" = Liked it"; }
        if(v>60&&v<=80) { q=" = Really liked it"; }
        if(v>80&&v<=100) { q=" = Loved it"; }
        if(v>1) {
        $('starUser'+n).innerHTML=(v>0?Math.round(v)+'%'+q:'');
        } else {
        $('starUser'+n).innerHTML=("");
        }
        $('starUser'+n).style.color='#888';

        document.onmousemove='';

    },
   /* Data */

    'stop':1,

    'num':0

};

/* script to assign rating END */


function ajaxFunction(velement, vmethod, vscript)
{

var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      document.getElementById(velement).innerHTML=xmlHttp.responseText;
	//alert(xmlHttp.responseText);
      }
    }
  xmlHttp.open(vmethod,vscript,true);
  xmlHttp.send(null);
  }
