// Historicus, Inc. Javascript utilities
// derived from DreamWeaver snippets.

// Example: <a href="#" onclick="MM_openBrWindow('test','module','status=yes,resizable=yes,width=900,height=700')">gdfghdfgh</a>
<!--
function openWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

var popUpWin=0;

function popUpWindow(URLStr, left, top, width, height)

{

  if(popUpWin)

  {

    if(!popUpWin.closed) popUpWin.close();

  }

  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');

}

function messageWindow(title, msg)

{

  var width="300", height="125";

  var left = (screen.width/2) - width/2;

  var top = (screen.height/2) - height/2;

  var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;

  var msgWindow = window.open("","msgWindow", styleStr);

  var head = '<head><title>'+title+'</title></head>';

  var body = '<center>'+msg+'<br><p><form><input type="button" value="   Done   " onClick="self.close()"></form>';

  msgWindow.document.write(head + body);

}
// Example:

// writeCookie("myCookie", "my name", 24);

// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.

function writeCookie(name, value, hours)

{

  var expire = "";

  if(hours != null)

  {

    expire = new Date((new Date()).getTime() + hours * 3600000);

    expire = "; expires=" + expire.toGMTString();

  }

  document.cookie = name + "=" + escape(value) + expire;

}

function browserRedirect()

{

  var ns4 = document.layers;

  var ns6 = document.getElementById && !document.all;

  var ie4 = document.all;

  

  if(ns4) URLStr = "1.html";

  else if(ns6) URLStr = "2.html";

  else if(ie4) URLStr = "3.html";

  else URLStr = "4.html";

  location = URLStr;

}

// Example:

// value1 = 3; value2 = 4;

// messageBox("text message %s and %s", value1, value2);

// this message box will display the text "text message 3 and 4"

function messageBox()

{

  var i, msg = "", argNum = 0, startPos;

  var args = messageBox.arguments;

  var numArgs = args.length;

  if(numArgs)

  {

    theStr = args[argNum++];

    startPos = 0;  endPos = theStr.indexOf("%s",startPos);

    if(endPos == -1) endPos = theStr.length;

    while(startPos < theStr.length)

    {

      msg += theStr.substring(startPos,endPos);

      if (argNum < numArgs) msg += args[argNum++];

      startPos = endPos+2;  endPos = theStr.indexOf("%s",startPos);

      if (endPos == -1) endPos = theStr.length;

    }

    if (!msg) msg = args[0];

  }

  alert(msg);

}


//Example: preloadImages('file.gif', 'http://www.x.com/y.gif');

function preloadImages()

{

  if(document.images)

  {

    if(!document.imageArray) document.imageArray = new Array();

    var i,j = document.imageArray.length, args = preloadImages.arguments;

    

    for(i=0; i<args.length; i++)

    {

      if (args[i].indexOf("#")!=0)

      {

        document.imageArray[j] = new Image;

        document.imageArray[j++].src = args[i];

      }

    }

  }

}


// Example:

// alert( readCookie("myCookie") );

function readCookie(name)

{

  var cookieValue = "";

  var search = name + "=";

  if(document.cookie.length > 0)

  { 

    offset = document.cookie.indexOf(search);

    if (offset != -1)

    { 

      offset += search.length;

      end = document.cookie.indexOf(";", offset);

      if (end == -1) end = document.cookie.length;

      cookieValue = unescape(document.cookie.substring(offset, end))

    }

  }

  return cookieValue;

}

