﻿// JScript File
function ToDo() 
{
    alert("TODO: work in progress");
    return false;
}

function Logout() 
{
   document.forms[0].action = "User/LogoutForm.aspx";
   document.forms[0].submit();
}
function CreateElement(tag, name)
{
	//IE doesn't see the name attribute in the DOM unless you include it when the element is created.
	var field = document.createElement((document.all) ? ("<" + tag + " name=\"" + name + "\" />") : tag);
	field.setAttribute("name", name);
	return field;
}

function SubmitCommand(command) 
{
   var element=document.createElement("input");
   element.id = "command";
   element.name=element.id;
   element.type="hidden";
   element.value=command;
   document.forms[0].appendChild(element);
   document.forms[0].submit();
}

function SubmitCommand(command, value) 
{
   var element=document.createElement("input");
   element.id = command;
   element.name=element.id;
   element.type="hidden";
   element.value=value;
   document.forms[0].appendChild(element);
   document.forms[0].submit();
}

function SubmitCommandToUrl(command, value, url) 
{
   var element=document.createElement("input");
   element.id = command;
   element.name=element.id;
   element.type="hidden";
   element.value=value;
   document.forms[0].appendChild(element);
   document.forms[0].action = url;
   document.forms[0].submit();
}

function SubmitCommandsToUrl(command1, value1, command2, value2, url) 
{
   var element1=document.createElement("input");
   element1.id = command1;
   element1.name=element1.id;
   element1.type="hidden";
   element1.value=value1;
   
   var element2=document.createElement("input");
   element2.id = command2;
   element2.name=element2.id;
   element2.type="hidden";
   element2.value=value2;

   document.forms[0].appendChild(element1);
   document.forms[0].appendChild(element2);
   
   document.forms[0].action = url;
   document.forms[0].submit();
}

function SubmitToUrl(url, button) 
{
   button.disabled = true;
   document.forms[0].action = url;
   document.forms[0].submit();
}

function XmlToDom(xml) 
{
   if (document.implementation.createDocument)
   { 
      // Mozilla, create a new DOMParser 
      var parser = new DOMParser(); 
      var dom = parser.parseFromString(xml, "text/xml"); 
      return dom;
   }
   if (window.ActiveXObject)
   { 
      var dom = new ActiveXObject("Microsoft.XMLDOM") 
      dom.async="false"; 
      dom.loadXML(xml);   
      return dom;
   } 
   alert("Browser unable to load XML for Ajax");
}

function GetDocumentText(documentElement) 
{
   return (document.all) ? documentElement.text : documentElement.textContent;
}

function SetInnerText(span, text) {
   if(document.all) {
      span.innerText=text;
       return;
    }
    span.innerHTML = text=='' ?'&nbsp;' : text;
}

function AddItem(itemID, url, button) 
{   
    button.disabled = true;
    SubmitCommandToUrl('addItem',itemID, url); 
}

function AddDownloadItem(itemEnum, priceLevel, url, button) 
{   
    button.disabled = true;
    SubmitCommandsToUrl('addDownloadItem', itemEnum, 'priceLevel', priceLevel, url); 
}