function writeSessionCookie (cookieName, cookieValue) {
  if (testSessionCookie()) {
    document.cookie = escape(cookieName) + "=" + escape(cookieValue) + "; path=/";
    return true;
  }
  else return false;
}

function getCookieValue (cookieName) {
  var exp = new RegExp (escape(cookieName) + "=([^;]+)");
  if (exp.test (document.cookie + ";")) {
    exp.exec (document.cookie + ";");
    return unescape(RegExp.$1);
  }
  else return null;
}

function testSessionCookie () {
  document.cookie ="testSessionCookie=Enabled";
  if (getCookieValue ("testSessionCookie")=="Enabled")
    return true;
  else
    return false;
}

function setpageYOffset() 
{
  if (document.all) y = document.body.scrollTop; 
  else              y = window.pageYOffset; 
  writeSessionCookie("pageYOffset", y); 
}

function resetpageYOffset() 
{
  writeSessionCookie("pageYOffset", 0);
}

function scrollTopageYOffset() 
{
  if (testSessionCookie()) {
    var y = getCookieValue("pageYOffset");
    if (y != null) window.scrollTo(0,y); 
    writeSessionCookie("pageYOffset", y);
  }
}

function undoScrollTopageYOffset() 
{
  window.scrollTo(0,0);
}


function ldw_page_edit_image(file, w, h)
{
  if (file != "")
  {
    var nw = document.getElementById("image_width_text").value;
    if (nw <= 0 || isNaN(nw)) { nw = 0; document.getElementById("image_width_text").value =""; }
    var nh = document.getElementById("image_height_text").value;
    if (nh <= 0 || isNaN(nh)) { nh = 0;  document.getElementById("image_height_text").value =""; }
    
    if (nw == 0 && nh == 0) { nw = w; nh = h; }
    if (nw == 0 && nh > 0)  { nw = Math.round(nh*w/h); }
    if (nh == 0 && nw > 0)  { nh = Math.round(nw*h/w); }
  
    document.getElementById(file).width = nw; 
    document.getElementById("image_width").innerHTML = nw;
    document.getElementById(file).height = nh; 
    document.getElementById("image_height").innerHTML = nh;
  }
}