/**
 * Add Function to window.OnLoad
 *
 */
function addLoadEvent(func){if (window.addEventListener){window.addEventListener('load', func, false);return true;}else if (window.attachEvent){var result = window.attachEvent('onload', func);return result;}else{window['onload'] = func;}}

/**
 * Print Content
 *
 * @param string clauseBefore
 * @param string clauseAfter
 */
function printContent(clauseBefore, clauseAfter)
{
    setVisibleElement('_td', false);
    setVisibleElement('_div',false);
    setVisibleElement('_tr', false);

    if (clauseBefore) eval(clauseBefore);
    globalClauseAfter = clauseAfter;
    window.print();
    var t = setTimeout("visibleElements();",1000);
}

/**
 * Set Visible Elements After Print
 *
 */
function visibleElements()
{
    if (globalClauseAfter) eval(globalClauseAfter);
    setVisibleElement('_td', true);
    setVisibleElement('_tr', true);
    setVisibleElement('_div',true);
}

/**
 * Set Visible type of Element
 *
 * @param string idElement
 * @param boolean show
 */
function setVisibleElement(idElement, show)
{
    i = 1;
    while (obj = document.getElementById(idElement+i))
    {
      if (navigator.appName == 'Microsoft Internet Explorer')
      {
          if (!show) style = 'none';
          else style = 'block';
          obj.style.setAttribute('cssText', 'display:'+style, 0);
      }
      else
      {
          if (!show) style = 'none';
          else
              switch(idElement)
              {
                case '_div' : style = 'block'; break;
                case '_td'  : style = 'table-cell'; break;
                case '_tr'  : style = 'table-row'; break;
                default    : style = 'block';
              }
          obj.setAttribute('style', 'display:'+style);
      }
      i++;
    }
}

/**
 * Apply Class for Input element by Type
 *
 */
function applyClassInput(type, defaultClassName)
{
  var node_list = document.getElementsByTagName('input');
  for (var i = 0; i < node_list.length; i++) {
      var node = node_list[i];
      if (node.getAttribute('type') == type) {
          node.style.border = 'none';
          node.className += ' ' + defaultClassName;
      }
  }
}

function round(Money)
{
    Money = new Number(Money);


/*
  if(!isNaN(Money))
  {
        Money = Math.round(Money*100)/100;

        if (String(Money).split(".")[1])
        {
            if (String(Money).split(".")[1].length==1)
                Money = Money + "0";
        }
        else Money = Money + ".00";
  }
  else
  {
       alert('Incorrect money format!');
       return 0;
  }

*/

    return Money.toFixed(2);
}

function addslashes(str)
{
    str=str.replace(/\'/g,'\\\'');
    str=str.replace(/\"/g,'\\"');
    //str=str.replace(/\\/g,'\\\\');
    //str=str.replace(/\0/g,'\\0');
    return str;
}

function stripslashes(str)
{
    str=str.replace(/\\'/g,'\'');
    str=str.replace(/\\"/g,'"');
    str=str.replace(/\\\\/g,'\\');
    str=str.replace(/\\0/g,'\0');
    return str;
}


function loadScript(url){
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = url;
    document.getElementsByTagName('head')[0].appendChild(script);
}

function checkAllByNameAndFormName(state, theName, theFormName)
{
    if (document.getElementById(theFormName).length)
    {
        theLength = document.getElementById(theFormName).length;
        if (state)
        {
            for (i=0; i < theLength; i++)
            {
                if(document.getElementById(theFormName)[i].name == theName)
                    document.getElementById(theFormName)[i].checked = true;
            }
        }
        else
        {
            for (i=0; i < theLength; i++)
            {
                if(document.getElementById(theFormName)[i].name == theName)
                    document.getElementById(theFormName)[i].checked = false;
            }
        }
    }
}


function bookmarkPage(urlAddress, pageName) {

        if(window.sidebar){
            window.sidebar.addPanel(pageName, urlAddress, '');
        }
        else if (window.external) {
                window.external.AddFavorite(urlAddress,pageName)
        }
        else {
            alert("Sorry! Your browser doesn't support this function.  You can bookmark this page us using 'CRTL' and 'D'");
        }
}

