//
//
//
var tipHeader = "Welcome!"
var tipText = "To view magnified area click and drag inside the image. To move the magnification area hold down the button and drag around.";

//  Cookies
//
var cookieExpire = "Mon, 22 Jan 2080 00:00:01 UTC";
//
function setCookie(AName, AValue, AExp) {
  var str = AName+"="+AValue+";Path=/;"
  if (AExp) str += "Expires="+AExp;
  document.cookie = str;
}

//
function getCookie(AName) {
  var ret = "";
  var str = document.cookie;

  var pos = str.indexOf(AName+"=")
  if (pos>=0) {
    var pos1=str.indexOf(";",pos);
    if (pos1<0) pos1=document.cookie.length;
    ret = str.substring(pos+AName.length+1,pos1);
  }
  return ret;
}

//
//
//
function showTip(AShow) {

    var hideTip = getCookie("donotshow");
    
    AShow = AShow | (hideTip != "YES");
    if (AShow) { // check cookie

        var tipBgElement = document.createElement("div");
        tipBgElement.id = "divTipBg";
        tipBgElement.style.visibility="hidden";
        tipBgElement.style.filter ="Alpha(opacity=70)";
        tipBgElement.style.backgroundColor="#333399"; 
        tipBgElement.style.border="2px outset blue";
        tipBgElement.style.position="absolute";
        tipBgElement.style.width="400px";
        tipBgElement.style.height="100px";
        
        var tipFgElement = document.createElement("div");
        tipFgElement.id = "divTipFg";
        tipFgElement.style.visibility="hidden";
        tipFgElement.style.color="white"; 
        tipFgElement.style.padding="12px";
        tipFgElement.style.position="absolute";
        tipFgElement.style.width="400px";
        tipFgElement.style.height="100px";

        tipFgElement.appendChild(document.createTextNode(tipText));

        var anyelm1 = document.createElement("p");

        var anyelm = document.createElement("input");
        anyelm.type = "checkbox";
        anyelm.id = "donotshow";

        anyelm1.appendChild(anyelm);
        anyelm1.appendChild(document.createTextNode(" Do not show this message again."));

        tipFgElement.appendChild(anyelm1);

        anyelm1 = document.createElement("center");

        anyelm = document.createElement("button");
        anyelm.onclick = closeTip;
        anyelm.style.width = "54px";
        anyelm.style.backgroundColor = "#3399FF";
        anyelm.style.border = "1px solid white";

        anyelm.appendChild(document.createTextNode("Close"));
        anyelm1.appendChild(anyelm);
        tipFgElement.appendChild(anyelm1);


        var body = document.getElementsByTagName("body")[0];
        body.appendChild(tipBgElement);
        body.appendChild(tipFgElement);

        // size
        document.getElementById('divTipBg').style.pixelHeight = document.getElementById('divTipFg').offsetHeight;

        var l = (document.body.offsetWidth - document.getElementById('divTipFg').offsetWidth) / 2;
        var t = (document.body.offsetHeight - document.getElementById('divTipFg').offsetHeight) / 3;

        document.getElementById('divTipBg').style.posLeft = l;
        document.getElementById('divTipFg').style.posLeft = l;

        document.getElementById('divTipBg').style.posTop = t;
        document.getElementById('divTipFg').style.posTop = t;

        document.getElementById('divTipFg').style.visibility = 'visible';
        document.getElementById('divTipBg').style.visibility = 'visible';
    }
}

function closeTip() {

    document.getElementById('divTipFg').style.visibility = 'hidden';
    document.getElementById('divTipBg').style.visibility = 'hidden';
    
    if (document.getElementById('donotshow'))
      if(document.getElementById('donotshow').checked)
        setCookie("donotshow","YES", cookieExpire);
    else
      setCookie("donotshow","YES");

      //setCookie("donotshow","NO", cookieExpire);

}

//
// for HELP WINDOW
//
function setCheckTip(AParent, AElement) {

    AParent.style.display = 'block';
    //document.form1.style.display = 'block';

    var hideTip = getCookie("donotshow");
    if (hideTip != "YES") {
      AElement.checked = true;
      // document.form1.showtip.checked=true;
    }
}

function saveValue(AElement) {
    if (AElement.checked)
        setCookie("donotshow","NO", cookieExpire);
    else
        setCookie("donotshow","YES", cookieExpire);

    window.close();
}
