window.onload = initAll;
window.onbeforeunload = noOrphan;

var req = getRequest();
var num = 0;
var timer;
var el = 0;
var url;
var myWindow = null;

function initAll()
{
	if(req)
	{
	getData();
	}

allLinks = document.getElementsByTagName("a");
	for(x=0; x<allLinks.length; x++)
	{
	if(allLinks[x].className == "newin")
	{
	allLinks[x].onclick = myNewWindow;
	}
	}

}


/* ------------- Make Request ------------------------------------------------ */

function getRequest()
{
	try
	{
	req = new XMLHttpRequest();
	}
	catch(err1)
	{
		try
		{
		req = new ActiveXObject("Msxml2.XMLHTTP");	
		}
		catch(err2)
		{
			try
			{
			req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(err3)
			{
			req = false;
			}
		}
	}
return req;
}

/* ------------------------- Picture Page ----------------------- */
function getData()
{
var url = "picpage4.html";
req.open("GET", url, true);
req.onreadystatechange = useResponse;
req.send(null);
timer = setTimeout("getData()", 5000);
return false;
}

function useResponse()
{

var imgDiv = document.createElement("div");

if(req.readyState == 4)
{
	if(req.status == 200)
	{
	imgDiv.innerHTML = req.responseText;

	var allImg = imgDiv.getElementsByTagName("A");

	if( num == allImg.length)
	{
	num = 0;
	}
document.getElementById('pic').innerHTML = allImg[num].innerHTML;

num++
	}
}
}

/* ------------------------- Page One ---------------------------- */

function getData1()
{
url = this.href;



	if(url == "http://sacguy.com/AFS_1/hrsloc.html")
	{
stopPics();
document.getElementById('pic').innerHTML = "<a href='http://maps.google.com/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=Auto+Finance,+3333+Fulton+Avenue,+Sacramento,+CA&amp;aq=&amp;sll=38.581572,-121.4944&amp;sspn=0.267845,0.441513&amp;ie=UTF8&amp;hq=Auto+Finance,&amp;hnear=3333+Fulton+Ave,+Sacramento,+California+95821&amp;ll=38.626437,-121.401854&amp;spn=0.006295,0.006295' style='color:#0000FF;text-align:left'><iframe width='300' height='146' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=Auto+Finance,+3333+Fulton+Avenue,+Sacramento,+CA&amp;aq=&amp;sll=38.581572,-121.4944&amp;sspn=0.267845,0.441513&amp;ie=UTF8&amp;hq=Auto+Finance,&amp;hnear=3333+Fulton+Ave,+Sacramento,+California+95821&amp;ll=38.626437,-121.401854&amp;spn=0.006295,0.006295&amp;output=embed'></iframe></a>";
	}

	if(url == "http://sacguy.com/AFS_1/required.html")
	{
stopPics();
document.getElementById('pic').innerHTML = "<img src='images/camaro1.png' width='300' height='146' /> ";
	}

}



/* ------------------------- Directions ------------------ */

function getData2(str)
{
el = parseInt(str);

req.open("GET", "gethere.html", true);
req.onreadystatechange = useResponse2;
req.send(null);
return false;
}


/* ----------------------- Use Response 2 ----------------------------- */
function useResponse2()
{
var textDiv = document.createElement("div");

if(req.readyState == 4)
{
	if(req.status == 200)
	{
	textDiv.innerHTML = req.responseText;

	var allText = textDiv.getElementsByTagName("A");

	document.getElementById('loc').innerHTML = allText[el].innerHTML;
	}



}
}


/* ------------------------ New Window --------------- */

function myNewWindow()
{
myWindow = window.open(this.href, "winName", "location=yes,toolbar=yes,menubar=yes,scrollbars=yes,statusbar=yes,width=400,height=400,left=600,top=150");

myWindow.focus();
return false;
}



function noOrphan()
{
if(myWindow != null && !myWindow.closed)
{
myWindow.close();
}}

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */



