window.onload = function(e) {
	externalLinks();
	InitializeTimer();
	preloadImages();
	}

function preloadImages()	{
	var pic1= new Image(300, 250); 
	pic1.src="/images/ads/camo-flex-logo.jpg";
	var pic2= new Image(300, 250);
	pic2.src="/images/ads/lone-logo.jpg";
	}


var secs;
var timerID = null;
var timerRunning = false;
var delay = 1000;
var ad_index = 0;
var ads = new Array();

ads[0] = new Array('TA21-300X250.swf', 'fenixlight.com/newping.asp', 'f');
ads[1] = new Array('lone-logo.jpg', 'lonewolfstands.com', 'i');
ads[2] = new Array('camo-flex-logo.jpg', 'camoflex.net', 'i');

function InitializeTimer()	{
    // Set the length of the timer, in seconds
	
    secs = 7;
    StopTheClock();
    StartTheTimer();
	}

function StopTheClock()	{
	
    if(timerRunning)
        clearTimeout(timerID);
    timerRunning = false;
	}

function StartTheTimer()	 {
	
    if (secs == 0)	 {
        StopTheClock();
		ad_index++;
		secs = 7;
        self.status = secs;
        timerRunning = true;
        timerID = self.setTimeout("StartTheTimer()", delay);
	//	alert(ad_index);
		ad_rotator();
		}
    else	{
		ad_rotator();
        self.status = secs;
        secs = secs - 1;
        timerRunning = true;
        timerID = self.setTimeout("StartTheTimer()", delay);
		}
	
	}

function ad_rotator()	{

	if (secs == 7)	{

		if (ad_index < 3)	{

			if (ads[ad_index][2] == 'i')	{
				document.getElementById('rotate_ad').innerHTML = "<a href='http://" + ads[ad_index][1] + "' target='_blank'><img src='/images/ads/" + ads[ad_index][0] + "' width='300' height='250' alt='advertisement' style='margin-left: 6px; border: 1px solid #000;' /></a>";
				}
			else	{
				document.getElementById('rotate_ad').innerHTML = write_flash('TA21-300X250.swf');
				}
			
			}
		else	{
			ad_index = 0;
			}
		
		}
	
	
	}

function write_flash(file_name)	{
	flash = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0' width='300' height='250' quality='high' style='display: block; margin-left: 6px; border: 1px solid #000;'>";
	flash += "<param name=movie value='/images/ads/" + file_name + "'>";
	flash += "<param name=quality value='high'>";
	flash += "<embed src='/images/ads/" + file_name + "' quality='high' width='300' height='250' align='left' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed>";
	flash += "</object>";

	return flash;
	}

function filterAnimal(animalCategoryID)	{
	var categories = new Array(1,2,3,4,5);
	
	for(var i = 0; i < categories.length; i++)	{
		if (animalCategoryID != categories[i])	{
			document.getElementById("animalCategory" + categories[i]).style.display = 'none';
			}
		else	{
			document.getElementById("animalCategory" + categories[i]).style.display = 'block';
			}
		}
	
	}
     
function filterExtraAnimal(animalCategoryID)	{ // used in the sign up form because there are two animal lists
	var categories = new Array(1,2,3,4,5);
	
	for(var i = 0; i < categories.length; i++)	{
		if (animalCategoryID != categories[i])	{
			document.getElementById("ex_animalCategory" + categories[i]).style.display = 'none';
			}
		else	{
			document.getElementById("ex_animalCategory" + categories[i]).style.display = 'block';
			}
		}
	
	}
		  
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&	anchor.getAttribute("class") == "out") {
		anchor.target = "_blank";
		}
	}
}

function change_animal_sort_order(type, url)    {
   http = getHTTPObject();

   http.onreadystatechange = function()    {
       if (http.readyState == 4) {
           
		   if (http.responseText == 'done')    {
			location.href = "/" + url;
			}
		}
	}

   variables = "sort=" + type;

   http.open('POST', 'set_animal_sort.php', true);
   http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   http.setRequestHeader("Content-length", variables.length);
   http.setRequestHeader("Connection", "close");
   http.send(variables);
   }

function change_animal_review_sort_order(type, url)    {
   http = getHTTPObject();

   http.onreadystatechange = function()    {
       if (http.readyState == 4) {
           
		   if (http.responseText == 'done')    {
			location.href = "/" + url;
			}
		}
	}

   variables = "sort=" + type;

   http.open('POST', 'set_animal_review_sort.php', true);
   http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   http.setRequestHeader("Content-length", variables.length);
   http.setRequestHeader("Connection", "close");
   http.send(variables);
   }

function change_sort_order(type, url)    {
   http = getHTTPObject();

   http.onreadystatechange = function()    {
       if (http.readyState == 4) {
           
		   if (http.responseText == 'done')    {
			location.href = "/" + url;
			}
		}
	}

   variables = "sort=" + type;

   http.open('POST', 'set_sort.php', true);
   http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   http.setRequestHeader("Content-length", variables.length);
   http.setRequestHeader("Connection", "close");
   http.send(variables);
   }

function change_review_sort_order(type, url)    {
   http = getHTTPObject();

   http.onreadystatechange = function()    {
       if (http.readyState == 4) {
           
		   if (http.responseText == 'done')    {
			location.href = "/" + url;
			}
		}
	}

   variables = "sort=" + type;

   http.open('POST', 'set_review_sort.php', true);
   http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   http.setRequestHeader("Content-length", variables.length);
   http.setRequestHeader("Connection", "close");
   http.send(variables);
   }


function getHTTPObject() {
 var xmlhttp;
 /*@cc_on
 @if (@_jscript_version >= 5)
   try {
     xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
   } catch (e) {
     try {
       xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
     } catch (E) {
       xmlhttp = false;
     }
   }
 @else
 xmlhttp = false;
 @end @*/
 if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
   try {
     xmlhttp = new XMLHttpRequest();
   } catch (e) {
     xmlhttp = false;
   }
 }
 return xmlhttp;
} 