
      //--------------------------
      //-- The HTTP Object request
      //--------------------------

        function getHTTPObject(){
          var requestObject = false;
            if (window.XMLHttpRequest)
              {
                requestObject = new XMLHttpRequest();
              }
               else if (window.ActiveXObject)
              {
                try
                  {
                    //-- IE 6
                      requestObject = new ActiveXObject("Msxml2.XMLHTTP");
                  }

                catch(e)
                  {
                    try
                      {
                        //-- IE 5
                          requestObject = new ActiveXObject("Microsoft.XMLHTTP");
                      }

                    catch(e)
                      {
                        //-- Can't find it
                          requestObject = false;
                      }
                  }
                }

              return requestObject;
          }
	
      //----------------
      //-- Load the data
      //----------------

        function loadData(file, currentElement, elementName)
          {
            var loadImg = document.createElement('img');
                loadImg.setAttribute( 'src', 'loading.gif' );
                loadImg.setAttribute( 'id', 'loading' );
                loadImg.className = 'loading';

            $(currentElement + 'Div').appendChild( loadImg );

            var request = getHTTPObject();
	    if (request)
              {
                request.onreadystatechange = function(){displayResponse(request, currentElement, elementName);};
                request.open("GET",file,true);
                request.send(null);
              }
            }

      //-----------------------
      //-- Display the response
      //-----------------------

        function displayResponse(request, currentElement, elementName)
          {
            if (request.readyState == 4)
              {
                if (request.status == 200 || request.status == 304 || request.status == 0)
                  {
                    $( currentElement + 'Div').removeChild( $( 'loading' ) );

                    var xmlDump = request.responseXML;
                    gElements = xmlDump.getElementsByTagName("item");

                    if( elementName && elementName != '' )
                      addSelect( elementName );
                    else
                      updateFilm();
                  }
                else
                  {
                    $( 'loading' ).setAttribute( 'src', 'error.png' );
                    alert('There was an error loading the XML file!');
                    setTimeout("$( '" + currentElement + "Div').removeChild( $( 'loading' ) )", 1500);
                  }
              }
          }

      //-----------------------------
      //-- Prototype-style $ function
      //-----------------------------
        function $( element )
          {
            return document.getElementById( element );
          }

      //----------------
      //-- Add a zipcode
      //----------------

        function addZip()
          {

            //-- Remove all children for the theater element

              if ( $( 'theaterDiv') )
                if ( $( 'theaterDiv').hasChildNodes() )
                  while ( $( 'theaterDiv').childNodes.length >= 1 )
                    $( 'theaterDiv').removeChild( $( 'theaterDiv').firstChild );

            //-- Remove all children for the film element

              if ( $( 'theaterDiv') )
                if ( $( 'filmDiv').hasChildNodes() )
                  while ( $( 'filmDiv').childNodes.length >= 1 )
                    $( 'filmDiv').removeChild( $( 'filmDiv').firstChild );

            //-- Slide out the film info

              slideOut();

            //-- Ask the user for the zip
              var newZip = prompt("Please enter a five digit zip");

            //-- Validate the zip

              var valid = true;

              if(newZip)
                for (var i=0; i < newZip.length; i++)
                  if("1234567890".indexOf(newZip.substr(i, 1)) == "-1")
                    valid = false;

              if($('zipTitle')) $('zipSelect').value = 'zipTitle';

              var zipLen = 0;
              if(newZip) zipLen = newZip.length;

              if( $('z' + newZip) )
                {
                  $('zipSelect').value = newZip;
                  alert('Your zip is already added');
                  loadData( 'ajax.php?zip=' + $('zipSelect').value, 'zip', 'theater' );
                }
              else if( zipLen != 5 && zipLen > 0 )
                alert('Your zip must be 5 digits long');
              else if( valid == false )
                alert('Your zip must contain only numbers');
              else if( newZip )
                {
                  //-- Save as a cookie
                    zipCookie = GetCookie('zip');
                    if(! GetCookie('zip')) zipCookie = '';
                    zipCookie = zipCookie + newZip + '.';
                    SetCookie('zip', zipCookie, expiry);

                  //-- Add title if there isn't one
                    if(! $('zipTitle'))
                      {
                        var newZipElement = document.createElement('option');
                            newZipElement.setAttribute('value', 'zipTitle');
                            newZipElement.setAttribute('id', 'zipTitle');
                            newZipElement.appendChild( document.createTextNode( 'Your Zips' ) );
                            newZipElement.className = 'selectTitle';
                        $('zipSelect').insertBefore( newZipElement , $('zipSpace') );
                      }


                  //-- Create the element
                    var newZipElement = document.createElement('option');
                        newZipElement.setAttribute('value', newZip);
                        newZipElement.setAttribute('id', 'z' + newZip);
                        newZipElement.appendChild( document.createTextNode( newZip ) );
                        newZipElement.className = 'selectOption';

                    $('zipSelect').insertBefore( newZipElement , $('zipSpace') );

                  //-- Select the added zip
                    $('zipSelect').value = newZip;

                  //-- Remove the cover and onclick event
                    $('zipCover').style.display = 'none';
                    $('zipSelect').onclick = function(e){};

                  //-- Load data for the zip
                    loadData( 'ajax.php?zip=' + $('zipSelect').value, 'zip', 'theater' );
                }        
          }

      //-------------------
      //-- Add a select box
      //-------------------

        function addSelect( elementName )
          {

            //-- Create the element

              var newSelect = document.createElement( 'select' );
                  newSelect.setAttribute('id', elementName + 'Select');

              var title = document.createElement( 'option' );
                  title.className = 'selectTitle';
                  title.appendChild( document.createTextNode( 'Pick a ' + elementName ) );

              newSelect.appendChild( title );


              for(i = 0; i < gElements.length; i++)
                {


                  var option = document.createElement( 'option' );

                      option.setAttribute( 'value', gElements.item(i).getElementsByTagName(elementName.substr(0,1) + "id")[0].firstChild.nodeValue );

                      option.className = 'selectOption' ;

                      option.appendChild( document.createTextNode( gElements.item(i).getElementsByTagName( elementName )[0].firstChild.nodeValue ) );

                  newSelect.appendChild( option );

                }

            //-- Remove all children for this element

              if ( $( elementName + 'Div').hasChildNodes() )
                while ( $( elementName + 'Div').childNodes.length >= 1 )
                  $( elementName + 'Div').removeChild( $( elementName + 'Div').firstChild );

            //-- Remove all children for the film areas

              if ( $( 'filmDiv').hasChildNodes() )
                while ( $( 'filmDiv').childNodes.length >= 1 )
                  $( 'filmDiv').removeChild( $( 'filmDiv').firstChild );

              slideOut();

            //-- Add new element

              $( elementName + 'Div').appendChild( newSelect );

            //-- What's next?

            //-- Add support for onchange for this element

              $( elementName + 'Select').onchange = function(e)
                {

                  if( elementName == 'theater')
                    nextElementName = 'film';
                  else
                    nextElementName = '';

                  var extra = '';
                  if($('filmSelect')) extra =  '&zid=' + $('zipSelect').value + '&film=' + $('filmSelect').value + '&tid=' + $('theaterSelect').value;

                  loadData( 'ajax.php?' + elementName + '=' + $( elementName + 'Select' ).value + extra, elementName, nextElementName );
                };
          }

      //--------------------------
      //-- Update info about the film
      //--------------------------

        function updateFilm()
          {

            //-- Remove current info
              if ( $( 'infoDiv').hasChildNodes() )
                while ( $( 'infoDiv').childNodes.length >= 1 )
                  $( 'infoDiv').removeChild( $( 'infoDiv').firstChild );

            //-- Add info title

              var title = gElements.item(0).getElementsByTagName('title').item(0).firstChild;

              var addClass = false;

              if( title.nodeValue.length <= 18 )
                addClass = 'titleBig';
              else if( title.nodeValue.length <= 36 )
                addClass = 'titleMedium';
              else
                addClass = 'titleSmall';

              var iTitle = document.createElement('h2');
                  iTitle.appendChild( document.createTextNode( title.nodeValue ) );
                  iTitle.className = addClass;


              $('infoDiv').appendChild(iTitle);


              //-- Add Release date

                //var iYear = document.createElement('div');
                //    iYear.appendChild( document.createTextNode( 'Theatrical Release' ) );
                //    iYear.className = 'iT';

                var iYearV = document.createElement('div');
                    iYearV.appendChild( document.createTextNode( 'Release Date: ' + gElements.item(0).getElementsByTagName('theatricalrelease')[0].firstChild.nodeValue ) );
                    iYearV.className = 'details';

                //iDiv.appendChild(iYear);
                $('infoDiv').appendChild(iYearV);


            //-- Add info image
              var iImage = document.createElement('img');
                  iImage.setAttribute( 'src', gElements.item(0).getElementsByTagName('image')[0].firstChild.nodeValue );
                  iImage.setAttribute( 'alt', title.data );
                  iImage.className = 'iImage';

              $('infoDiv').appendChild(iImage);

            //-- Add info sidebar
              var iDiv = document.createElement('div');
              $('infoDiv').appendChild(iDiv);
              iDiv.className = 'iDiv';

              //-- Add Director

                var iDrct = document.createElement('div');
                    iDrct.appendChild( document.createTextNode( 'Director' ) );
                    iDrct.className = 'iT';

                var iDrctV = document.createElement('div');
                    iDrctV.appendChild( document.createTextNode( gElements[0].getElementsByTagName('director')[0].firstChild.nodeValue ) );
                    iDrctV.className = 'iV';


                iDiv.appendChild(iDrct);
                iDiv.appendChild(iDrctV);

              //-- Add Rating

                var iRate = document.createElement('div');
                    iRate.appendChild( document.createTextNode( 'Rating' ) );
                    iRate.className = 'iT';

                var iRateV = document.createElement('div');
                    iRateV.appendChild( document.createTextNode( gElements.item(0).getElementsByTagName('rated')[0].firstChild.nodeValue ) );
                    iRateV.className = 'iV';

                iDiv.appendChild(iRate);
                iDiv.appendChild(iRateV);

              //-- Add Genre

                var iGnre = document.createElement('div');
                    iGnre.appendChild( document.createTextNode( 'Genre' ) );
                    iGnre.className = 'iT';

                var iGnreV = document.createElement('div');
                    iGnreV.appendChild( document.createTextNode( gElements.item(0).getElementsByTagName('genre')[0].firstChild.nodeValue ) );
                    iGnreV.className = 'iV';

                iDiv.appendChild(iGnre);
                iDiv.appendChild(iGnreV);

              //-- Add Runtime
                if(gElements.item(0).getElementsByTagName('runtime')[0].firstChild.nodeValue != null)
                {

                  var iRntm = document.createElement('div');
                      iRntm.appendChild( document.createTextNode( 'Runtime' ) );
                      iRntm.className = 'iT';

                  var iRntmV = document.createElement('div');
                      iRntmV.appendChild( document.createTextNode( gElements.item(0).getElementsByTagName('runtime')[0].firstChild.nodeValue ) );
                      iRntmV.className = 'iV';

                  iDiv.appendChild(iRntm);
                  iDiv.appendChild(iRntmV);
                }

              //-- Add Critics Rating

                //var iCrtR = document.createElement('div');
                //    iCrtR.appendChild( document.createTextNode( 'Critics Rating' ) );
                //    iCrtR.className = 'iT';

                //var iCrtRV = document.createElement('div');
                //    iCrtRV.appendChild( document.createTextNode( gElements.item(0).getElementsByTagName('criticrating')[0].firstChild.nodeValue ) );
                //    iCrtRV.className = 'iV';

                //iDiv.appendChild(iCrtR);
                //iDiv.appendChild(iCrtRV);

              //-- Add Fans Rating

                //var iFanR = document.createElement('div');
                //    iFanR.appendChild( document.createTextNode( 'Fans Rating' ) );
                //    iFanR.className = 'iT';

                //var iFanRV = document.createElement('div');
                //    iFanRV.appendChild( document.createTextNode( gElements.item(0).getElementsByTagName('fanrating')[0].firstChild.nodeValue ) );
                //    iFanRV.className = 'iV';

                //iDiv.appendChild(iFanR);
                //iDiv.appendChild(iFanRV);

            //-- Add main info
              var iBody = document.createElement('div');
              $('infoDiv').appendChild(iBody);

              //-- Add Synopsis

                var iSyns = document.createElement('div');
                    iSyns.appendChild( document.createTextNode( gElements.item(0).getElementsByTagName('synopsis')[0].firstChild.nodeValue ) );
                    iSyns.className = 'infoSynopsis';

                iBody.appendChild( iSyns );

              //-- Add Cast

                var iCstT = document.createElement('div');
                    iCstT.appendChild( document.createTextNode( 'Cast' ) );
                    iCstT.className = 'infoTheater';

                iBody.appendChild( iCstT );

                var iCast = document.createElement('div');
                    iCast.appendChild( document.createTextNode( gElements.item(0).getElementsByTagName('starring')[0].firstChild.nodeValue ) );
                    iCast.className = 'infoTime';

                iBody.appendChild( iCast );

              //-- Add Ratings

                var iFanR = document.createElement('font');
                    iFanR.style.color = 'green';
                    iFanR.appendChild( document.createTextNode( gElements.item(0).getElementsByTagName('allcritics')[0].firstChild.nodeValue + '% ' ) );
                var iCrtR = document.createElement('font');
                    iCrtR.style.color = 'green';
                    iCrtR.appendChild( document.createTextNode(  gElements.item(0).getElementsByTagName('rtusers')[0].firstChild.nodeValue + '%' ) );

                var iRtng = document.createElement('div');
                    iRtng.appendChild( document.createTextNode( 'Critics Rating: ' ) );
                    iRtng.appendChild( iFanR );
                    iRtng.appendChild( document.createTextNode( '| Fan Rating: ' ) );
                    iRtng.appendChild( iCrtR );
                    iRtng.className = 'infoTheater';

                iBody.appendChild( iRtng );

                var iConi = document.createElement('div');
                    iConi.appendChild( document.createTextNode( 'Consensus: ' + gElements.item(0).getElementsByTagName('consensus')[0].firstChild.nodeValue ) );
                    iConi.className = 'infoTime';

                iBody.appendChild( iConi );


              //-- Add Theater Name
                /**
                var iThtr = document.createElement('div');
                    iThtr.appendChild( document.createTextNode( gElements.item(0).getElementsByTagName('theater')[0].firstChild.nodeValue ) );
                    iThtr.className = 'infoTheater';

                iBody.appendChild( iThtr );

                var iThii = document.createElement('div');
                    iThii.appendChild( document.createTextNode( gElements.item(0).getElementsByTagName('tinfo')[0].firstChild.nodeValue ) );
                    iThii.className = 'infoTime';

                iBody.appendChild( iThii );
                */

              //-- Theater Info

                var iThin = document.createElement('div');
                    iThin.appendChild( document.createTextNode( gElements.item(0).getElementsByTagName('date')[0].firstChild.nodeValue ) );
                    iThin.className = 'infoTheater';

                iBody.appendChild( iThin );

              //-- Add Times

                var iTime = document.createElement('div');
                    iTime.appendChild( document.createTextNode( gElements.item(0).getElementsByTagName('times')[0].firstChild.nodeValue ) );
                    iTime.className = 'infoTime';

                iBody.appendChild( iTime );

                iBody.className = 'iBody';

            //-- Slide the div in!

              slideIn();
          }

      //-----------------------------
      //-- Slide in and out functions
      //-----------------------------

        var slider = false;

        count = -440;
        direction = false;

        function hide( )
          {
            $('infoDiv').style.top = '-440px';
            //$('slider').style.height = '0px';
          }

        function slideIn( )
          {
            clearInterval ( slider );
            slider = setInterval ( "slide('in')", 5 );
          }

        function slideOut( )
          {
            clearInterval ( slider );
            slider = setInterval ( "slide('out')", 5 );
          }

        function slide( direction )
          {
            if( direction == 'in' )
              count = count+5;
            else if( direction == 'out' )
              count = count-5;

            $('infoDiv').style.top = count + 'px';
            //$('slider').style.height = (440 + count) + 'px';

            if(direction == 'in' && count >= 0)
              {
                count = 0;
                $('infoDiv').style.top = '0px';
                //$('slider').style.height = '440px';
                clearInterval ( slider );
                slider = false;
              }
               else if(direction == 'out' && count <= -440)
              {
                count = -440;
                $('infoDiv').style.top = '-440px';
                //$('slider').style.height = '0px';

                clearInterval ( slider );
                slider = false;

                if ( $( 'infoDiv').hasChildNodes() )
                  while ( $( 'infoDiv').childNodes.length >= 1 )
                    $( 'infoDiv').removeChild( $( 'infoDiv').firstChild );
              }
          }

      //---------------------------
      //-- Do when the window loads
      //---------------------------

        window.onload = function()
          {

            //-- Hide the info box

              hide( );

            //-- Hide the submit button

              if($('zipSubmit'))
                $('zipSubmit').style.display = 'none';

            //-- Prompt for zip if there aren't any yet

              $('zipCover').onclick = function(e)
                {
                  addZip();
                };

            //-- Prompt for zip if there aren't any yet (IE)

              $('zipSelect').onclick = function(e)
                {
                  addZip();
                };

            //-- Add support for onchange for the zip
              $('zipSelect').onchange = function(e)
                {
                  if( $('zipSelect').value == 'zipAdd' )
                    addZip();
                  else if( $('zipSelect').value == 'zipClear' )
                    {
                      DeleteCookie('zip');
                      if ( $( 'zipSelect').hasChildNodes() )
                        for ( i=$( 'zipSelect').childNodes.length - 1;i>=0;i-- )
                          if($( 'zipSelect').childNodes.item(i).className == 'selectOption' || $( 'zipSelect').childNodes.item(i).className == 'selectTitle')
                            $( 'zipSelect').removeChild( $( 'zipSelect').childNodes.item(i) );

                      alert('All zips were removed from the list and your browsers cookies');
                      $('zipCover').style.display = 'block';
                      $('zipSelect').value = 'zipAdd';
                      $('zipSelect').onclick = function(e)
                        {
                          addZip();
                        };
                    }
                  else
                    loadData( 'ajax.php?zip=' + $('zipSelect').value, 'zip', 'theater' );
                };

            //-- Add zips that are saved as cookies
              var zips = GetCookie('zip');
              if(GetCookie('zip'))
                {
                  var newZipElement = document.createElement('option');
                      newZipElement.setAttribute('value', 'zipTitle');
                      newZipElement.setAttribute('id', 'zipTitle');
                      newZipElement.appendChild( document.createTextNode( 'Your Zips' ) );
                      newZipElement.className = 'selectTitle';

                  $('zipSelect').insertBefore( newZipElement , $('zipSpace') );
                  $('zipSelect').value = "zipTitle";

                  var split = zips.split(".");
                  for(i=0;i<(split.length - 1);i++)
                     {

                      //-- Create the element
                        var newZipElement = document.createElement('option');
                            newZipElement.setAttribute('value', split[i]);
                            newZipElement.setAttribute('id', 'z' + split[i]);
                            newZipElement.appendChild( document.createTextNode( split[i] ) );
                            newZipElement.className = 'selectOption';

                        $('zipSelect').insertBefore( newZipElement , $('zipSpace') );
                    }
                }

            //-- Show cover if there's saved zip's

              if( $('zipSelect').childNodes.length <= 3)
                {
                  $('zipCover').style.display = 'block';
                  $('zipSelect').onclick = function(e)
                    {
                      addZip();
                    };
                }
               else
                {
                  $('zipCover').style.display = 'none';
                  $('zipSelect').onclick = function(e){};
                }


          };