(function () {
var HTML5 = [
  "article",
  "aside",
  "audio",
  "bb",
  "canvas",
  "command",
  "datagrid",
  "datalist",
  "details",
  "dialog",
  "eventsource",
  "figure",
  "footer",
  "header",
  "menu",
  "meter",
  "nav",
  "output",
  "progress",
  "rp",
  "rt",
  "ruby",
  "section",
  "source",
  "time",
  "video"
];
for (var el = HTML5.length; el--;)
  document.createElement(HTML5[el]);
})();


/* input[placeholder] */
function inputPlaceholder(evt)
{
  switch (evt.type)
  {
    case "blur":
      if (!evt.target.value)
        evt.target.value = evt.target.getAttribute("placeholder")
      break;
    case "focus":
      if (evt.target.value === evt.target.getAttribute('placeholder'))
        evt.target.value = ''
      break;
  }
}


function toggleCollapse(event)
{
  $(this).siblings().removeClass("expanded");
  $(this).toggleClass("expanded");
}


$(document).ready(function ondomready () {
  $("#benefits > *").click(toggleCollapse);
  $("h2:empty").remove()
  
  if (!jQuery.browser.safari)
  {
    $("input[placeholder]").attr("value", function() { return $(this).attr("placeholder") });
    $("input[placeholder]").focus(inputPlaceholder);
    $("input[placeholder]").blur(inputPlaceholder);
  }
})

/* ----------------------------------------------------------------------- */

/* input[placeholder] end */
function setClass(id,classname,focusElement)
{
  if(typeof(id) == "object")
    id.className = classname;
  else
    document.getElementById(id).className = classname;
  if(focusElement)
    document.getElementById(focusElement).focus();
}

function singleChoice(el, classname)
{
    var siblings = el.parentNode.childNodes;
    for( var i = 0; i < siblings.length;i++)
    {   
        var sibling = siblings[i];
        if(sibling.nodeType == 1 && sibling.className.indexOf(classname) != -1)
            sibling.className = sibling.className.replace(classname, "");
    }
    setClass(el, el.className + ' chosen');
}

function markDownload(el)
{
  var href = el.getAttribute("href", 2);
  tools.send("/files/mark-download.aspx?href="+href);
  return true;
}


var xmlhttp = null;

var tools = 
{
  initXml:function(xmlString) 
  {
    if(window.DOMParser) //Mozilla
    {
      var parser = new DOMParser();
      var xml = parser.parseFromString(xmlString,'text/xml');
    }
    else //IE
    {
      var xml = new ActiveXObject('Msxml.DOMDocument');
      xml.async = false;
      xml.loadXML(xmlString);
    }
    return xml;
  },
  //send the xml to the server
  send:function(href, xml, handler)
  {
    //if(xml)
    //    alert("sending:"+href+"\n"+xml.xml);
    
    if (window.XMLHttpRequest) //Mozilla, etc.
      xmlhttp=new XMLHttpRequest();
    else if (window.ActiveXObject) //IE5, 6
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    
    //extra shop update value test
    if(xml && xml.documentElement.name == "value" && (href.indexOf("shop/updateusers") != -1 || href.indexOf("shop/updatedomains") != -1|| href.indexOf("shop/updateitem_20") != -1))
    {
     if(!tools.isNumber((xml.DocumentElement.text|xml.DocumentElement.textContent)))
       return;
    }        
    if (xmlhttp != null)
    {
      var me = this;
      if(handler) 
        xmlhttp.onreadystatechange= handler;
      xmlhttp.open("post",href,true)
      if(!xml) 
        xml = tools.initXml("<dummy/>");
      xmlhttp.send(xml);  
    }
  },
  //convert a string to an element
  getElement:function(html)
  {
    if(html == "") return new Array();
    var div = document.createElement('div');
    div.innerHTML = html;
    return div.childNodes[0];
  },
  
  isNumber:function(number)
  {
    return  /^-?\d+$/.test(number);
  }
}

