// JavaScript Document
//Libary Function
function $(id) {
  return document.getElementById(id);
}

   function createXMLHttpRequest() {
      try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
      try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
      try { return new XMLHttpRequest(); } catch(e) {}
      alert("XMLHttpRequest not supported");
      return null;
}


function showlayer(id)
{
$(id).style.display = "block";
}


function hidelayer(id)
{
$(id).style.display = "none";
}

//End Libary Functions


function openWindow(src)
{
window.open(src,"_blank","height=345,width=375,status=no,toolbar=no,menubar=no,location=no",true); 
}

function ImageBorder(theImage)
{
		$(theImage).className = "imageBorder";
}

function ImageBorderOff(theImage)
{
		$(theImage).className = "largerText";

}

function populateKey()
{
$('key').value = getURL();	
}

function getURL()
{
test = location.href;

test= test.split("/");
str = "";
for(i=0;i<(test.length-1);i++)
{
	if(i == 0)
	str = test[i]+"/";
	else
	str = str + test[i] + "/";
}
return str;
}


function searchCheck(form)
{
if(form.search.value == "")
{
alert("You must specify a search parameter.");
form.search.focus();
return false;
}

populateKey();

}

<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function randomImg()
{
	//random*2+1
	var random_number = Math.round(Math.random() * 1);
	random_number++;
	//alert(random_number); //for testing
	
	var headImage = new Image(892,171);
	
	if(random_number == 1)
	{
	
	headImage.src = "images/head_1.jpg";
	document.images.headImg.src= headImage.src;
	}
	else if(random_number == 2)
	{
	headImage.src = "images/head_2.jpg";
	document.images.headImg.src= headImage.src;
	}
	else if(random_number == 3)
	{
	headImage.src = "images/head_3.jpg";
	document.images.headImg.src= headImage.src;
	}
}

//handles event gallery pops
function eventPop(_width,_height,imageURL)
{
params = "left=10,top=20,width="+_width+",height="+_height+",scrollbars=no";
window.open(imageURL,'_blank',params);	
}

function swapImage(imgsrc)
{
$('theImage').src = imgsrc;	
}


//handles gallery popups

function popupImage(_width,_height,imageURL)
{
URL = "../photo_pop.php?imageURL=" + imageURL;
params = "'width="+_width+",height="+_height+",scrollbars=no'";
window.open(URL,'_blank',params);	
}

//adjusts document length to proper size
function adjustheight()
{
	
var browserName=navigator.appName; 
var platformOS =navigator.platform;
var checkOS = platformOS.indexOf('Mac');
var checkOS = checkOS * 1;	
	
if(checkOS != -1) // a mac
{
	
}
	
var browserName=navigator.appName; 
if (browserName=="Netscape") //also works with firefox, fixes spacing issue with firefox
{ 
window.moveTo(200,200);
window.resizeTo(700,520); //add to compensate for toolbar
}
else
{
 var ua = window.navigator.appVersion;
 //alert(ua);
//alert(ua.charAt(22));
ua= ua.charAt(22);

	if(ua == "6")
	{
	window.moveTo(200,200);
	window.resizeTo(700,520); //add to compensate for toolbar
	}
	else if(ua == "7")
	{
	window.moveTo(200,200);
	window.resizeTo(700,540); //add to compensate for toolbar
	}
}	
}


/*AJAX CALLS*/
   //this get function encodes the form values into URIs which can be sent as Post Vars to the PHP page
   function get(obj,temp) {
  
  name = "name" + temp;
  stars = "stars" + temp;
  comments = "comments" + temp; 
  id = "id" + temp; 
  goFlag = false;
  
  if($(name).value == "")
  {
	alert("Please enter a valid name.");
	$(name).focus();
	return;
  }
 
  if($(comments).value == "")
  {
	alert("Please enter a valid comment.");
	$(comments).focus();
	return;
  } 
  else
  goFlag = true;
  
  	if(goFlag)
  	{
  button = "button" + temp;
  $(button).disabled = true;
  $(button).value = "Processing Review...";		
		
	var poststr = "name=" + encodeURI( $(name).value ) + "&stars=" + encodeURI( $(stars).value ) 
	+ "&comments=" + encodeURI( $(comments).value ) + "&id=" + encodeURI( $(id).value );
   	makePOSTRequest('submit_review.php', poststr, temp);
  	}
  
   }
   
   theId = null;
   function makePOSTRequest(url, parameters, tempid) {
      http_request = false;
      theId = tempid;	
	http_request = createXMLHttpRequest();
      
	  if (http_request.overrideMimeType)
            http_request.overrideMimeType('text/html');
	  
	  //build body for Form Post
      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
			ratingform = "ratingform"+theId;	
			hidelayer(ratingform);
			
			  name = "name" + theId;
 			 stars = "stars" + theId;
  			comments = "comments" + theId; 
			
$(name).value = "";
$(comments).value = "";

starsTD = "starsTD" + theId;
$(starsTD).innerHTML = result;
			//alert("Thanks! Your review has been processed.");	
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   

//==-==-== Utility Function to determine if email is valid ==-==-==
function isEmail(sText)
{

var whereisAT = sText.indexOf('@');

if(whereisAT == -1)
return false;
   
var whereisDOT = sText.indexOf('.');  

if(whereisDOT == -1)
return false;

//else return true
return true;
}

//==-==-==MAIL FORM AJAX FUNCTIONS==-==-==

function mailFormProcess()
{

var goflag = false;

	if($('name').value == "")
	{
	alert("Please enter a valid name.");
	$('name').focus();
	return;
	}

	if($('email').value == "")
	{
	alert("Please enter a valid email.");
	$('email').focus();
	}
	else if($('email').value != "")
	{
	testme = isEmail($('email').value);
		if(!testme)
		{
		alert("Please enter a valid email.");
		$('email').focus();
		return;
		}
		else
		goflag = true;
	}
	
	if(goflag)
	sendMail();

}

//==-==-==After form has been checked for validity, encode POST values==-==-==
function sendMail() 
{
  
$('mailSubmit').disabled = true;
$('mailSubmit').value = "Sending Email...";
var poststr = "name=" + encodeURI($('name').value) + "&email=" + encodeURI($('email').value);
sendMail_Process('addtoMailingList.php', poststr);
}
 
//==-==-==The POST Parameters are Encoded so send the Email==-==-== 
function sendMail_Process(url, parameters) 
{
http_request = createXMLHttpRequest();
      
if(http_request.overrideMimeType)
http_request.overrideMimeType('text/html');
	  
	  //build body for Form Post
      http_request.onreadystatechange = sendMail_Response;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
}

//==-==-==-Response from the Server with fail or success message==-==-==
function sendMail_Response() 
{
	if (http_request.readyState == 4) 
	{
		if (http_request.status == 200) 
		{
		$('name').value = "";
		$('email').value = "";
		$('mailSubmit').disabled = false;
		$('mailSubmit').value = "Add me to the List!";			
		//alert(http_request.responseText);
		result = http_request.responseText;
		//alert(result);
		alert("Thanks! Your email has been successfully submitted.");	
		} 
		else 
		alert('There was a problem with the request.');
	}
}
   