/*
This is a library of functions for sr.

we need:
x cookie save/load
check if logged in
check if any information to show (in featured area)
x writit
is a saved comment?
x background http call
*/


// color stuff
function setColor(clr,el)
{
        el.style.backgroundColor=clr;
}




// SAVE GET COOKIE

// borrowed from: http://www.netspade.com/articles/javascript/cookies.xml
// put these in the js, so we don't have to keep redl all this code; etc.
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}


// CALL HTTP IN BACKGROUND
var xmlhttp

function loadXMLDoc(url)
{
/*
   try {
    netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
   } catch (e) {
    alert("Permission UniversalBrowserRead denied.");
   }
*/

// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest()
  xmlhttp.onreadystatechange=xmlhttpChange
  xmlhttp.open("GET",url,true)
  xmlhttp.send(null)
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    if (xmlhttp)
    {
    xmlhttp.onreadystatechange=xmlhttpChange
    xmlhttp.open("GET",url,true)
    xmlhttp.send()
    }
  }
}

function xmlhttpChange()
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
  {
  // if "OK"
  if (xmlhttp.status==200)
    {
    // ...some code here...
    }
  else
    {
    alert("Problem retrieving XML data")
    }
  }
}


// WRITE TO A DIV
function writit(text,id)
{
        if (document.getElementById)
        {
               x = document.getElementById(id);
               x.innerHTML = '';
               x.innerHTML = text;
        }
        else if (document.all)
        {
               x = document.all[id];
               x.innerHTML = text;
        }
        else if (document.layers)
        {
               x = document.layers[id];
               // text2 = '<P CLASS="testclass">' + text + '</P>';
               // alert(text2)
               x.document.open();
               x.document.write(text); //(text2);
               x.document.close();

        }

}

// temporary hack until new version is loaded in.
function resize(id,newheight, newwidth)
{
        x = getobj(id)


        x.style.height = newheight;
        x.style.width = newwidth;


//  border: solid; border-width:1px; border-color:<? echo $back_lite; ?>;
}

// we are ending up with lots of duplicate functions...
function getobj(id)
{
        if (document.getElementById)
        {
               x = document.getElementById(id);
        }
        else if (document.all)
        {
               x = document.all[id];
        }
        else if (document.layers)
        {
               x = document.layers[id];
        }

        return x
}
