/**
 * 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;}}

/**
 * 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 __bookmark(title, url)
{
    if (window.sidebar) {
        // Firefox
        window.sidebar.addPanel(title, url, '');
    } else if (window.opera && window.print) {
        // Opera
        var t = document.createElement('a');
        t.setAttribute('rel', 'sidebar');
        t.setAttribute('href', url);
        t.setAttribute('title', title);
        //t.click();
    } else {
        // IE
        window.external.AddFavorite(url, title);
    }
    return false;
}

function doClipboard(rootUrl, txt) {
    alert(window.clipboardData);
    if(window.clipboardData) { // IE
        window.clipboardData.setData("Text", txt);
    }
    else { // не IE
        var fc = document.getElementById("flashCopier");
        if(!fc) { // Элемент с "flashCopier" не существует
            fc = document.createElement("div"); // создаем
            fc.id = "flashCopier"; // добавляем id
            document.body.appendChild(fc); // добавляем созданный элемент к <body>
        }
        fc.innerHTML = '<embed src="'+rootUrl+'flash/clipboard.swf" FlashVars="clipboard=' +
            encodeURIComponent(txt) +
            '" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    }
}
