/* FUNCTIONS:
 *
 * beginWindowHeader, endWindowHeader
 * beginWindowInput, endWindowInput
 *
 * DESCRIPTION:
 *
 * The following group of functions place common window
 * headers into a window necessary for displaying elementary
 * items into the window. Furthermore, the functions allow
 * users to place an input form with a specific name.
 *
 * EXAMPLES:
 *
 */
function newWindow(strWindowName, iWidth, iHeight, bResizable)
{
  var window_ThisWindow;

  if (bResizable == false)
  {
    window_ThisWindow = window.open('empty.html','newwindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width='+iWidth+',height='+iHeight);
  } else {
    window_ThisWindow = window.open('empty.html','newwindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width='+iWidth+',height='+iHeight);
  }
  return window_ThisWindow;
}

function beginWindowHeader(window_ThisWindow, strWindowTitle, strStylesheet)
{
  //the title and header window
  window_ThisWindow.document.clear();
  window_ThisWindow.document.open();
  window_ThisWindow.document.write("<html><head><title>");
  window_ThisWindow.document.write("" + strWindowTitle + "</title>");
  window_ThisWindow.document.write("<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>");
  window_ThisWindow.document.write("<link href='" + strStylesheet + "' rel='stylesheet' type='text/css'>");
  window_ThisWindow.document.write("</head>");
  window_ThisWindow.document.write("<body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'>");
}

function beginWindowInput(window_ThisWindow, strInputFormName)
{
  //the beginning of the form code
  window_ThisWindow.document.write("<form name='" + strInputFormName + "'>");
}

function endWindowInput(window_ThisWindow)
{
  //the ending code
  window_ThisWindow.document.write("</form>");
}

function endWindowHeader(window_ThisWindow)
{
  //the ending code
  window_ThisWindow.document.write("</body></html>");
}


/* FUNCTIONS:
 *
 * placeWindowAppletHeader, placeWindowAppletFooter,
 * placeWindowImage, placeWindowInputText,
 * placeWindowInputButton, placeWindowInputSelect,
 * placeWindowInputCheckbox, placeWindowInputRadio,
 * placeWindowInputVariable, placeWindowInputPassword,
 * placeWindowInputFile, placeWindowBinary
 *
 * DESCRIPTION:
 *
 * The following group of functions place very basic
 * web items into a window. These items have been tested
 * for functionality in common browsers and should be
 * approachable using the document object model.
 *
 * EXAMPLES:
 *
 */
function isJavaCompatible(window_ThisWindow)
{
  var java=new Object();
  java.installed=navigator.javaEnabled() ? true:false; 
  return java.installed
}
 
function placeWindowAppletHeader(window_ThisWindow, strClassFile, iWidth, iHeight)
{
  window_ThisWindow.document.write("<applet code='" + strClassFile + "' width='" + iWidth + "' height='" + iHeight + "'>");
}

function placeWindowAppletParameter(window_ThisWindow, strName, strValue)
{
  window_ThisWindow.document.write("<param name='" + strName + "' value='" + strValue + "'>");
}

function placeWindowAppletFooter(window_ThisWindow)
{
  window_ThisWindow.document.write("</applet>");
}

function placeWindowAlignedImage(window_ThisWindow, strImageFile, strImageName, iWidth, iHeight, strAlignment)
{
  if (iWidth <= 1)
  {
    iWidth = 1;
  }

  if (iHeight <= 1)
  {
    iHeight = 1;
  }
  window_ThisWindow.document.write("<img src='" + strImageFile + "' id='" + strImageName + "' width=" + iWidth + " height=" + iHeight + " border=0 align=" + strAlignment + ">");
}

function placeWindowImage(window_ThisWindow, strImageFile, strImageName, iWidth, iHeight)
{
  if (iWidth <= 1)
  {
    iWidth = 1;
  }

  if (iHeight <= 1)
  {
    iHeight = 1;
  }
  window_ThisWindow.document.write("<img src='" + strImageFile + "' id='" + strImageName + "' width=" + iWidth + " height=" + iHeight + " border=0>");
}

function placeWindowInputText(window_ThisWindow, strInputName, iWidth, iHeight, iMaximum, strClass)
{
  if (iWidth <= 1)
  {
    iWidth = 1;
  }

  if (iHeight <= 1)
  {
    window_ThisWindow.document.write("<input type='text' name='" + strInputName + "' maxlength='" + iMaximum + "' size='" + iWidth + "' class='" + strClass + "' onkeypress='if (event.keyCode == 13) return false'>");
  } else {
    window_ThisWindow.document.write("<textarea name='" + strInputName + "' rows='" + iHeight + "' cols='" + iWidth + "' class='" + strClass + "' wrap='true'></textarea>");
  }
}

function placeWindowInputPassword(window_ThisWindow, strInputName, iWidth, iMaximum, strClass)
{
  if (iWidth <= 1)
  {
    iWidth = 1;
  }
  window_ThisWindow.document.write("<input type='password' name='" + strInputName + "' maxlength='" + iMaximum + "' size='" + iWidth + "' class='" + strClass + "'>");
}

function placeWindowInputButton(window_ThisWindow, strInputName, strButtonFunction, strButtonImage, iWidth, iHeight, strClass)
{
  var strRegexpOne = /.*\.jpg/;
  var strRegexpTwo = /.*\.gif/;
  var strRegexpThree = /.*\.bmp/;
  var strRegexpFour = /.*\.png/;
  var strFunctionString;

  if (strButtonFunction != null)
  {
    strFunctionString = "' onclick='opener." + strButtonFunction;
  } else {
    strFunctionString = '';
  }

  if (iWidth <= 1)
  {
    iWidth = 1;
  }

  if (iHeight <= 1)
  {
    iHeight = 1;
  }

  if (strButtonImage.match(strRegexpOne) != null || strButtonImage.match(strRegexpTwo) != null
      || strButtonImage.match(strRegexpThree) != null || strButtonImage.match(strRegexpFour) != null)
  {
    window_ThisWindow.document.write("<input type='image' name='" + strInputName + "' src='" + strButtonImage + strFunctionString + "' width='" + iWidth + "' height='" + iHeight + "' >");
  } else {
    window_ThisWindow.document.write("<input type='submit' name='" + strInputName + "' value='" + strButtonImage + strFunctionString + "' width='" + iWidth + "' height='" + iHeight + "' >");
  }
}

function placeWindowInputSelect(window_ThisWindow, strInputName, bMultipleSelect, strValuesNames, iWidth, iHeight, strClass)
{
  if (iWidth <= 1)
  {
    iWidth = 1;
  }

  if (iHeight <= 1)
  {
    iHeight = 1;
  }

  iWidth = iWidth*12;

  if (bMultipleSelect == false)
  {
    window_ThisWindow.document.write("<select name='" + strInputName + "' style='width:" + iWidth + "' size='" + iHeight + "'>");
  }
  if (bMultipleSelect == true)
  {
    window_ThisWindow.document.write("<select name='" + strInputName + "' style='width:" + iWidth + "' size='" + iHeight + "' multiple='yes'>");
  }

  for (var iIndex = 0; iIndex < strValuesNames.length; iIndex++)
  {
    window_ThisWindow.document.write("<option value='" + strValuesNames[iIndex][0] + "'>" + strValuesNames[iIndex][1] + "</option>");
  }

  window_ThisWindow.document.write("</select>");
}

function placeWindowInputCheckbox(window_ThisWindow, strInputName, strValue)
{
  window_ThisWindow.document.write("<input type='checkbox' name='" + strInputName + "' value='" + strValue + "'>");
}

function placeWindowInputRadio(window_ThisWindow, strInputName, strValue)
{
  window_ThisWindow.document.write("<input type='radio' name='" + strInputName + "' value='" + strValue + "'>");
}

function placeWindowInputVariable(window_ThisWindow, strInputName, strValue)
{
  window_ThisWindow.document.write("<input type='hidden' name='" + strInputName + "' value='" + strValue + "'>");
}

function placeWindowInputHyperlink(window_ThisWindow, strInputName, strValue, strClass)
{
  window_ThisWindow.document.write("<a href='" + strValue + "' class='" + strClass + "'>" + strInputName + "</a>");
}

function placeWindowInputFile(window_ThisWindow, strInputName, strValue, strClass)
{
  window_ThisWindow.document.write("<input type='file' name='" + strInputName + "' value='" + strValue + "' strClass='" + strClass + "'>");
}

function placeWindowTable(window_ThisWindow, aoTableObjects, strClass)
{
}



/* FUNCTIONS:
 *
 * clearWindowObject, addWindowObjectValue
 * getWindowObjectValue, setWindowObjectValue
 * getWindowObjectPointer
 *
 * DESCRIPTION:
 *
 * The following group of dynamic functions realise
 * realtime functions against arbitrary
 * window input or form objects. When these
 * functions are called the corresponding input
 * object passed to the function will change
 * depending to the functions settings.
 *
 * EXAMPLES:
 *
 */
function deleteWindowObjects(window_ThisWindow, strFormName)
{
  for (var iIndex = 0; iIndex < window_ThisWindow.document.forms[strFornName].legth; iIndex++)
  {
    window_ThisWindow.document.forms[strFormName][iIndex] = null;
  }
}

function deleteWindowObject(window_ThisWindow, strFormName, strObjectName)
{
  window_ThisWindow.document.forms[strFormName][strObjectName] = null;
}

function clearWindowObject(window_ThisWindow, strFormName, strObjectName)
{
  with(window_ThisWindow.document.forms[strFormName][strObjectName])
  {
    if (tagName.toLowerCase() == 'select')
    {
      for (var iIndex = (length-1); iIndex >= 0; iIndex--)
      {
        options[iIndex] = null;
      }
    }

    if (typeof type.toLowerCase()  != 'undefined')
    {

      if (type.toLowerCase() == 'text')
        value = '';
      if (type.toLowerCase() == 'textarea')
        value = '';
      if (type.toLowerCase() == 'password')
         value = '';
      if (type.toLowerCase() == 'hidden')
        value = '';

      if (type.toLowerCase() == 'radio')
        value = '';
      if (type.toLowerCase() == 'submit')
        value = '';
      if (type.toLowerCase() == 'checkbox')
        value = '';
    }

  }
}

function setWindowObjectPosition(window_ThisWindow, strFormName, strObjectName, iPositionX, iPositionY)
{
  //oFormNameObjectName = eval("window_ThisWindow.document." + strFormName + "." + strObjectName);
  window_ThisWindow.document.forms[strFormName][strObjectName].style.position = "absolute";
  window_ThisWindow.document.forms[strFormName][strObjectName].style.left = iPositionX;
  window_ThisWindow.document.forms[strFormName][strObjectName].style.top = iPositionY;
}

function setWindowObjectValue(window_ThisWindow, strFormName, strObjectName, strValue)
{
  oFormNameObjectName = eval("window_ThisWindow.document." + strFormName + "." + strObjectName);

  iNumberOfArguments = arguments.length;

  if (iNumberOfArguments == 5)
  {
    strArgument = arguments[4];
  }

  strIndex = strArgument;

  //Internet Explorer specific
  if (oFormNameObjectName.tagName.toLowerCase() == 'select')
  {
    //get the index name and number
    var strName = oFormNameObjectName.options[strIndex].innerText;
    var iNewIndex = oFormNameObjectName.options[strIndex].index;

    //clear the object
    oFormNameObjectName.options[strIndex] = null;

    //insert a new object
    var oOption = window_ThisWindow.document.createElement("OPTION");
    oFormNameObjectName.options.add(oOption, iNewIndex);
    oOption.innerText = strName;
    oOption.value = strValue;
  }

  with(window_ThisWindow.document.forms[strFormName][strObjectName])
  {
    if (typeof type.toLowerCase() != 'undefined')
    {
      if (type.toLowerCase() == 'text')
          value = strValue;
      if (type.toLowerCase() == 'password')
          value = strValue;
      if (type.toLowerCase() == 'hidden')
          value = strValue;

      if (type.toLowerCase() == 'radio')
          value = strValue;
      if (type.toLowerCase() == 'checkbox')
          value = strValue;
      if (type.toLowerCase() == 'submit')
          value = strValue;

      if (type.toLowerCase() == 'textarea')
          value = strValue;
    }
  }

}

function addWindowObjectValue(window_ThisWindow, strFormName, strObjectName, strValue)
{
  oFormNameObjectName = eval("window_ThisWindow.document." + strFormName + "." + strObjectName);

  iNumberOfArguments = arguments.length;

  if (iNumberOfArguments == 5)
  {
    strArgument = arguments[4];
  }

  strIndex = strArgument;

  //Internet Explorer specific
  if (oFormNameObjectName.tagName.toLowerCase() == 'select')
  {
    //create and insert a new object
    var oOption = window_ThisWindow.document.createElement("OPTION");
    oFormNameObjectName.options.add(oOption, strIndex);
    oOption.innerText = strName;
    oOption.value = strValue;
  }

  with(window_ThisWindow.document.forms[strFormName][strObjectName])
  {
    if (typeof type.toLowerCase() != 'undefined')
    {
      if (type.toLowerCase() == 'text')
        value += strValue;
      if (type.toLowerCase() == 'password')
        value += strValue;
      if (type.toLowerCase() == 'hidden')
        value += strValue;

      if (type.toLowerCase() == 'radio')
        value += strValue;
      if (type.toLowerCase() == 'checkbox')
        value += strValue;
      if (type.toLowerCase() == 'button')
        value += strValue;

      //add window object value at startIndex
      if (type.toLowerCase() == 'textarea')
        value += strValue;
    }

  }

}

function getWindowObjectValue(window_ThisWindow, strFormName, strObjectName)
{
  oFormNameObjectName = eval("window_ThisWindow.document." + strFormName + "." + strObjectName);

  iNumberOfArguments = arguments.length;

  if (iNumberOfArguments == 5)
  {
    strArgument = arguments[4];
  }

  strIndex = strArgument;

  //Internet Explorer specific
  if (oFormNameObjectName.tagName.toLowerCase() == 'select')
  {
    //get the index value
    return oFormNameObjectName.options[strIndex].value;
  }

  with(window_ThisWindow.document.forms[strFormName][strObjectName])
  {
    if (typeof type.toLowerCase() != 'undefined')
    {
      if (type.toLowerCase() == 'text')
        return value;
      if (type.toLowerCase() == 'password')
        return value;
      if (type.toLowerCase() == 'hidden')
        return value;

      if (type.toLowerCase() == 'radio')
        return value;
      if (type.toLowerCase() == 'checkbox')
        return value;
      if (type.toLowerCase() == 'button')
        return value;

      if (type.toLowerCase() == 'textarea')
        return value;
    }
  }

}

//test with all window objects
function getWindowObject(window_ThisWindow, strFormName, strObjectName)
{
  return window_ThisWindow.document.oFormNameObjectName;
}

