function ajaxRequest()
{
   try
   {
      var request = new XMLHttpRequest()
   }
   catch(e1)
   {
      try
      {
         request = new ActiveXObject("Msxml2.XMLHTTP")
      }
      catch(e2)
      {
         try
         {
            request = new ActiveXObject("Microsoft.XMLHTTP")
         }
         catch(e3) { request = false }
      }
   }
   return request
}

function AjaxLoadHtmlToDiv( url, divName, pageTitle )
{
    request = new ajaxRequest()
    request.open( "GET", url, true )
    request.onreadystatechange = function()
    {
        if( this.readyState == 4 )
        {
            if( this.status == 200 )
            {
                if( this.responseText != null )
                { 
                    document.getElementById( divName ).innerHTML = this.responseText
                    // change the page title
                    document.title = pageTitle;
                }
                else  document.getElementById( divName ).innerHTML = "Ajax error: no data received"
            }
            else  document.getElementById( divName ).innerHTML = "Ajax error loading " +url +" : " + this.statusText
        }
        else document.getElementById( divName ).innerHTML = 'Loading...';
    }
    request.send(null)
}

function AjaxLoadHtml( url, divName )
{
    request = new ajaxRequest()
    request.open( "GET", url, true )
    request.onreadystatechange = function()
    {
        if( this.readyState == 4 )
        {
            if( this.status == 200 )
            {
                if( this.responseText != null )
                { 
                    document.getElementById( divName ).innerHTML = this.responseText
                }
                else document.getElementById( divName ).innerHTML = "Ajax error: no data received"
            }
            else document.getElementById( divName ).innerHTML = "Ajax error loading " +url +" : " + this.statusText
        }
        else document.getElementById( divName ).innerHTML = 'Loading...';
    }
    request.send(null)
}

function AjaxLoadMainContent()
{
    url = "welcome.html";
    switch(location.hash)
    {
    case "#welcome":
        url = "welcome.html";
    break;
    case "#spinner":
        url = "spinner.php";
    break;
    case "#MDS":
        url = "spindles.php";
    break;
    case "#wishlist":
        url = "wishlist.php";
    break;
    case "#gallery":
        url = "gallery.html";
    break;
    case "#contact":
        url = "contact.html";
    break;
    }
    AjaxLoadHtmlToDiv( url, 'content', 'Almost Alien Ltd - Home of Alien Spinner' );
}

function ShowPopup( url, divID, show )
{
	if( show == true )
	{
		// Fill the div and make it visible
		AjaxLoadHtml( url, divID );
		document.getElementById( divID ).style.visibility = "visible";
	}
	else
	{
		// hide the div
		document.getElementById( divID ).style.visibility = "hidden";
	}
}

function HidePopup( divID )
{
	document.getElementById( divID ).style.visibility = "hidden";
}

function ShaftPopup() { ShowPopup( "MDSComponentDesc.php?component=1","descPopup", true ) }
function Whorl10Popup() { ShowPopup( "MDSComponentDesc.php?component=2","descPopup", true ) }
function Whorl8Popup() { ShowPopup( "MDSComponentDesc.php?component=3","descPopup", true ) }
function Whorl6Popup() { ShowPopup( "MDSComponentDesc.php?component=4","descPopup", true ) }

function HookPopup() { ShowPopup( "MDSComponentDesc.php?component=5","descPopup", true ) }
function BobbinPopup() { ShowPopup( "MDSComponentDesc.php?component=6","descPopup", true ) }
function BagPopup() { ShowPopup( "MDSComponentDesc.php?component=7","descPopup", true ) }

function ShowWishBox()
{
	ShowPopup( "wishRequest.html", "wishBox", true );
}

function SendWish()
{
	item = document.getElementById( "WishItem" ).value;
	desc = document.getElementById( "WishDescription" ).value;
	AjaxLoadHtml( "SendWish.php?item=" + item + "&description=" + desc, "content" );
	ShowPopup( "", "wishBox", false );
}

function popup(mylink, windowname)
{
	var href;
	if (typeof(mylink) == 'string')
		href=mylink;
	else
		href=mylink.href;
		window.open(href, windowname, 'width=600,height=500,scrollbars=yes');
	return false;
}

