function testHello(){
alert("hello!");
}


function ajaxFunction(command, parameter, parameter2)
{

var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari  
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if (xmlHttp.readyState<4){
        document.getElementById("ResponseDiv").innerHTML = "loading...";
        ShowHide("ResponseDiv",'show');
    }
    if(xmlHttp.readyState==4)
      {
        //alert("Response (in ajax.js) was: " + xmlHttp.responseText);
	DoSomethingWithResponse(command, xmlHttp.responseText,parameter);
        document.getElementById("ResponseDiv").innerHTML = "got response:" + xmlHttp.responseText;
        ShowHide("ResponseDiv",'hide');
      //document.myForm.time.value=xmlHttp.responseText;
      }
    }
  //change file to get based on command & parameter

  alert ("second area where we want to check the passed command: " + command);

  if (command=='login' || command=='logout' || command=='createuser'){
      if (command=='login'){
          document.getElementById("login_message").innerHTML = "Logging In";
      }
      alert("about to check login");
      xmlHttp.open('POST', 'checklogin.php');
xmlHttp.send("command=" + command + "&parameter=" + parameter);
  } else {
      xmlHttp.open('POST', 'myaction.php');
  }

  xmlHttp.setRequestHeader("Content-type",  "application/x-www-form-urlencoded");

  if (parameter2 === undefined ) {
      xmlHttp.send("command=" + command + "&parameter=" + parameter);
  } else {
      xmlHttp.send("command=" + command + "&parameter=" + parameter + "&parameter2=" + parameter2);
  }
}

function DoSomethingWithResponse(command, response,extraParameter){
  alert("Response was " + response + " and command was " + command);
  if (command == "1"){
    //Removed Picture
    picId = extraParameter;
    //alert("Removed Picture " + picId);
    ShowHide(picId,'hide');
  } else if (command == "2"){
    //Added Picture
    picId = extraParameter;
    //alert("Added Picture. response was " + response + "; extraparameter was : " + extraParameter);
    /*
    document.getElementById('AddPicIframe').src = "uploadpic.html";
    AddNewRow('imagelist',extraParameter, extraParameter,600,480);
    ShowHide("AddPicDiv","hide");
    */
    window.location.reload();
  } else if (command == "3"){
    //Removed License
    document.getElementById("num_licenses").innerHTML = response;
    ShowHide('RemoveLicenseDiv','hide');
    //alert("Removed license.");
  } else if (command == "4") {
    //Added License
    document.getElementById("num_licenses").innerHTML = response;
    ShowHide('BuyDiv','hide');
    //alert("Added license.");
  } else if (command == "5"){
    //Error
    alert("There was an error processing your request. Please reload this pageand try again.");
  } else if (command == "login"){
    //alert("Response was: " + response);
    if (response == "Success"){
        window.location.reload();
    } else {
        document.getElementById("login_message").innerHTML ="Login Failed. <a href='#' onClick='window.location.reload();'>Try Again</a>";

    }
  } else if (command=="logout"){
       if (response=="Successfully Logged Out"){
           window.location = "../";
       }
  } else if (command=="createuser"){
	document.getElementById("login_message").innerHTML = response;
  } else {
    alert("Did not recognize response:" + response);
  }
}

//Create Image Link (without it actually being a link
function CreateLink(myLocation, myResolutionX, myResolutionY){
   var myLink = "&lt;iframe src='" + myLocation + "' width=" + myResolutionX + " height=" + myResolutionY + "&gt";
   return myLink;
}

//Dynamically add a new row
function AddNewRow(tableRef, rowId, myLocation, myResolutionX, myResolutionY){
    var myTable = document.getElementById(tableRef);
    var tBody = myTable.getElementsByTagName('tbody')[0];
    var newTR = document.createElement('tr');
    newTR.setAttribute('id', rowId);
    var newTD1 = document.createElement('td');
    newTD1.innerHTML = CreateLink(myLocation, myResolutionX, myResolutionY);
    var newTD2 = document.createElement('td');
    newTD2.innerHTML = "<a href='#' onclick=\"ajaxFunction('1', '" + rowId + "');\"><img src='remove.png' border=0 title='Remove This Picture'></a>";



    newTR.appendChild (newTD1);
    newTR.appendChild (newTD2);
    tBody.appendChild(newTR);

} 
//command="show" or "hide"
function ShowHide(element_id, command){
    if (command=="hide"){
        document.getElementById(element_id).style.display = 'none';
        document.getElementById(element_id).style.visibility = 'hidden';
    } else if (command=="show"){
        document.getElementById(element_id).style.display = 'inline';
        document.getElementById(element_id).style.visibility = 'visible';
    } else {
        alert("Incorrect parameter 2 set in function ShowHide(element_id, command)");
    }
}

