// preload commonly used images
if (document.images)
   {
    pic1 = new Image();
    pic1.src = "http://classifieds.vci.net/Images/view.gif";
    pic2 = new Image();
    pic2.src = "http://classifieds.vci.net/Images/button-printthisad.gif";
    pic3 = new Image();
    pic3.src = "http://classifieds.vci.net/Images/button-otheradsby.gif";
    pic4 = new Image();
    pic4.src = "http://classifieds.vci.net/Images/button-replytoad.gif";
    pic5 = new Image();
    pic5.src = "http://classifieds.vci.net/Images/button-sendalink.gif";
    pic6 = new Image();
    pic6.src = "http://classifieds.vci.net/Images/camera.gif";
    pic7 = new Image();
    pic7.src = "http://classifieds.vci.net/Images/bg-ad-title.jpg";
    pic8 = new Image();
    pic8.src = "http://classifieds.vci.net/Images/bg-category.jpg";
    pic9 = new Image();
    pic9.src = "http://classifieds.vci.net/Images/tr.gif";
    pic10 = new Image();
    pic10.src = "http://classifieds.vci.net/Images/tl.gif";
    pic11 = new Image();
    pic11.src = "http://classifieds.vci.net/Images/bl.gif";
    pic12 = new Image();
    pic12.src = "http://classifieds.vci.net/Images/br.gif";
   }

function GetCategory(cat)
  {
   document.getElementById("content").className = 'hidediv';
   document.getElementById("adlist").className = 'showdiv';
   FullMenu(cat);
  }

function ReDisplay()
  {
   document.getElementById("content").className = 'hidediv';
   document.getElementById("adlist").className = 'showdiv';
  }

function ReDisplaySearch()
  {
   document.getElementById("content").className = 'hidediv';
   document.getElementById("adlist").className = 'showdiv';
  }

function DisplayAd(id,returncat)
  {
   document.getElementById("adlist").className = 'hidediv';
   document.getElementById("content").className = 'showdiv';

   document.getElementById("content").innerHTML = "<center><BR><BR><BR><BR><font size=4><B>Retrieving Ad...</b></font></center>"
   url = "/ajax-getad.php?id=" + id + "&returncat=" + returncat
   new Ajax.Updater('content',url, { method:'get',asynchronous:true,onComplete:HideDivWait } )
   // scroll(0,0);
  }

function FullMenu(cat)
  {
   document.getElementById("adlist").innerHTML = "<center><BR><BR><BR><BR><B><font size=4>Retrieving Ads...</font></b></center>"
   url = "/ajax-getcat.php?getcategory=" + cat
   new Ajax.Updater('adlist',url, { method:'get',asynchronous:true,onComplete:HideDivWait } )
   // scroll(0,0)
  }

function GetAd(id,returncat)
  {
   document.getElementById("content").innerHTML = "<center><BR><BR><BR><BR><font size=4><B>Retrieving Ad...</b></font></center>"
   CenterDiv(600,300,"content");
   grayOut(true);
   // Element.show("content");
   url = "/ajax-getad.php?id=" + id + "&returncat=" + returncat
   new Ajax.Updater('content',url, { method:'get',asynchronous:true,onComplete:HideDivWait } )
  }

function ViewAdsBy(userid,returncat)
  {
   document.getElementById("adlist").className = 'showdiv';
   document.getElementById("content").className = 'hidediv';
   Element.hide("content");

   document.getElementById("adlist").innerHTML = "<center><BR><BR><BR><BR><font size=4><B>Retrieving Ads...</b></font></center>"
   url = "/ajax-viewadsby.php?userid=" + userid + "&returncat=OtherAdsBy";
   new Ajax.Updater('adlist',url, { method:'get',asynchronous:true,onComplete:HideDivWait } )
   grayOut(false);
   scroll(0,0);
  }

function HideDivWait()
  {
  }

function PreviewAd($who,$preview)
  {
   overlib($preview, CAPTION, $who, BGCOLOR, "#000000", CAPCOLOR,"#ffffff",CAPTIONFONT, "verdana", HAUTO, VAUTO, FGCOLOR, '#efefef',TEXTCOLOR,'#000000', WIDTH, 300, BORDER, 2, PADX,3,3, PADY,3,3);
  }

function AdvSearch(form)
  {
   var searchcity = form.searchcity.options[form.searchcity.selectedIndex].value;
   var searchcategory = form.searchcategory.options[form.searchcategory.selectedIndex].value;
   var searchtext = form.searchtext.value;

   if ( searchcity == "All" & searchcategory == "All" & searchtext == "" )
      { alert("Please enter your search criteria"); form.searchtext.focus(); return(false) }
   
   document.getElementById("content").className = 'hidediv';
   document.getElementById("adlist").className = 'showdiv';
   document.getElementById("adlist").innerHTML = "<center><BR><BR><BR><BR><B><font size=4>Searching Ads...</font></b></center>";

   url = "ajax-search-test.php?searchcity=" + searchcity + "&searchcategory=" + searchcategory + "&searchtext=" + searchtext;
   new Ajax.Updater('adlist',url, { method:'get',asynchronous:true,onComplete:HideDivWait } )
  }


function CenterDiv(Xwidth,Yheight,divid)
  {
   // Get viewers current position on the screen
   var scrolledX, scrolledY;
   if ( self.pageYOffset )
      {
       scrolledX = self.pageXOffset;
       scrolledY = self.pageYOffset;
      }
   else if ( document.documentElement && document.documentElement.scrollTop )
      {
       scrolledX = document.documentElement.scrollLeft;
       scrolledY = document.documentElement.scrollTop;
      }
   else if ( document.body )
     {
      scrolledX = document.body.scrollLeft;
      scrolledY = document.body.scrollTop;
     }

   // Next, determine the coordinates of the center of browser's window
   var centerX, centerY;
   if ( self.innerHeight )
      {
       centerX = self.innerWidth;
       centerY = self.innerHeight;
      }
   else if ( document.documentElement && document.documentElement.clientHeight )
      {
       centerX = document.documentElement.clientWidth;
       centerY = document.documentElement.clientHeight;
      }
   else if ( document.body )
      {
       centerX = document.body.clientWidth;
       centerY = document.body.clientHeight;
      }

   var o=document.getElementById(divid);
   var r=o.style;
   r.position='absolute';
   r.top = scrolledY + "px";
   // r.left = "300px";
   r.left = ((centerX - Xwidth) / 2) + 'px'; 
   r.display = "block";
  }
 
function HideAd()
  {
   Element.hide("content");
   grayOut(false);
  }

function SaveFav(adid)
  {
   url = '/ajax-savefav.php?adid=' + adid;
   new Ajax.Request(url, { method:'get',asynchronous:true,onComplete:HideDivWait } )
   alert("This ad has been saved in your Favorites.");
  }


function grayOut(vis, options) {
  // Pass true to gray out screen, false to ungray
  // options are optional.  This is a JSON object with the following (optional) properties
  // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
  // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
  // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
  // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
  // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
  // in any order.  Pass only the properties you need to set.
  var options = options || {}; 
  var zindex = options.zindex || 50;
  var opacity = options.opacity || 70;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
  var dark=document.getElementById('darkenScreenObject');
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top='0px';                           // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
    tbody.appendChild(tnode);                            // Add it to the web page
    dark=document.getElementById('darkenScreenObject');  // Get the object.
  }
  if (vis) {
    // Calculate the page width and height 
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        var pageWidth = document.body.scrollWidth+'px';
        var pageHeight = document.body.scrollHeight+'px';
    } else if( document.body.offsetWidth ) {
      var pageWidth = document.body.offsetWidth+'px';
      var pageHeight = document.body.offsetHeight+'px';
    } else {
       var pageWidth='100%';
       var pageHeight='100%';
    }   
    //set the shader to cover the entire page and make it visible.
    dark.style.opacity=opaque;                      
    dark.style.MozOpacity=opaque;                   
    dark.style.filter='alpha(opacity='+opacity+')'; 
    dark.style.zIndex=zindex;        
    dark.style.backgroundColor=bgcolor;  
    dark.style.width= pageWidth;
    dark.style.height= pageHeight;
    dark.style.display='block';				 
  } else {
     dark.style.display='none';
  }
}
 
