// JavaScript Document
var googleWindow = 0;
var popUpWin=0;
var theWindow2 = 0;
var qWindow = 0;

/***************************/
function emailCheck(email)
{
	var re = new RegExp("^[A-Za-z0-9_-]+[A-Za-z0-9_\.\-]*[A-Za-z0-9_-]+@[A-Za-z0-9_-]+[A-Za-z0-9\.-]*\\.[a-zA-Z]{2,4}$","i");
	
	if(!re.test(email))
	{
		return false;
	}
	else return true;
}
//use the following var to remember an image's original src value
//the imageRoll function will constantly update this value, allowing the imageOut function to use its current value
var imageSourceValue = '';
function imageRoll(imageObject)
{
	//store the current src value
	imageSourceValue = imageObject.src;
	//grab the directory from the src attribute
	var folderIndex = imageObject.src.lastIndexOf("/");
	var theDirectory = imageObject.src.substring(0,folderIndex+1);//returns the DIR in the form http://domain.com/folder
	//test for image file type, jpg v. gif
	var theFileType = imageObject.src.substring(imageObject.src.length-3);//grab the last 3 characters, they represent the file type

	imageObject.src=theDirectory+imageObject.name+'-on.'+theFileType;
}
function imageOut(imageObject)
{
	//retrieve the original image src attribute
	imageObject.src = imageSourceValue;
}


// google pop up window
function popListingDetails(id,cat)
{
  if(theWindow2)
  {
    if(!theWindow2.closed) theWindow2.close();
  }

	theWindow2 = open('popListingDetails.cfm?id='+id+'&category='+cat, 'theWindow2', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=1,resizable=yes,copyhistory=yes,width=900,height=600,left=10,top=10,screenX=10,screenY=10');
}
//nextPage is used by the google map display pages to show the next block of listings
function nextPage(pageNum)
{
	var theLocation = new String(document.location)
	var varCheck = theLocation.indexOf("?");
	var placeholder = theLocation.indexOf("currentPage=");
	if(varCheck == -1)//there were no URL vars, so append currentpage and load new url
	{
		document.location = document.location+"?currentPage="+pageNum;
	}
	else if(placeholder != -1)//there was already a currentPage var , get rid of it and reload w/ new page num.
	{
		var tmpLocation = theLocation.slice(0,placeholder);
		document.location = tmpLocation+"currentPage="+pageNum;
	}
	else
	{
		document.location = document.location+"&currentPage="+pageNum;
	}
}
function directionsSubmit(){
	if(document.forms[0].saddr.value != ""){document.forms[0].submit();}else{alert("Please enter your starting address!");}
}
//******************************************************
function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();

  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function popTheQuestion()
{
	var width = 775;
	var height = 450;
	var left = 25;
	var top = left;
	if(qWindow)
  {
    if(!qWindow.closed) qWindow.close();

  }
  qWindow = open('ask.cfm', 'qWindow', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function mapDisplay(cat)
{
	var left = 10;
	var top = 10;
	var width = 1015;
	var height = 700;
	 if(googleWindow)
	  {
		if(!googleWindow.closed) googleWindow.close();
	  }

//first, open a new window

  googleWindow = open('googleMap.cfm?searchCategory='+cat, 'newGoogleWindow', 'toolbar=1,location=no,directories=no,status=no,menubar=no,scrollbars=1,resizable=0,copyhistory=1,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
  //now submit to that new window
}
function popSubscribe()
{
	var width = 775;
	var height = 450;
	var left = 25;
	var top = left;
	if(qWindow)
  {
    if(!qWindow.closed) qWindow.close();

  }
  qWindow = open('questionSubscribe.cfm', 'qWindow', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function popComment(theID)
{
	var width = 775;
	var height = 450;
	var left = 25;
	var top = left;
	if(qWindow)
  {
    if(!qWindow.closed) qWindow.close();

  }
  qWindow = open('submitComment.cfm?id='+theID, 'qWindow', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}
var subscribeWin = 0;
function subscriptionCheck()
{

	var width = 775;
	var height = 450;
	var left = 25;
	var top = left;
	if(qWindow)
  {
    if(!subscribeWin.closed) subscribeWin.close();

  }
  
	var re = new RegExp("^[A-Za-z0-9_-]+[A-Za-z0-9_\.\-]*[A-Za-z0-9_-]+@[A-Za-z0-9_-]+[A-Za-z0-9\.-]*\\.[a-zA-Z]{2,4}$","i");
	
	if(!re.test(document.subscribeForm.email.value))
	{
		alert('Your email address is invalid!');
		//return false;
	}
	else
	{
		subscribeWin = open('questionSubscribe.cfm', 'subscribeWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
		//document.subscribeForm.action = 'questionSubscribe.cfm';
		document.subscribeForm.target = 'subscribeWin';
		document.subscribeForm.submit();
	}
	
}

var seeSomething = 0;

function popSeeSomething()
{
	var width = 775;
	var height = 450;
	var left = 25;
	var top = left;
	if(seeSomething)
  {
    if(!seeSomething.closed) seeSomething.close();

  }
  seeSomething = open('seeSomethingWeMissed.cfm', 'seeSomething', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function popBusinessGoogleMap()
{
	var left = 10;
	var top = 10;
	var width = 1015;
	var height = 700;
	 if(googleWindow)
	  {
		if(!googleWindow.closed) googleWindow.close();
	  }

//first, open a new window

  googleWindow = open('infrastructureMaps.cfm', 'newGoogleWindow', 'toolbar=1,location=no,directories=no,status=no,menubar=no,scrollbars=1,resizable=0,copyhistory=1,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
  //now submit to that new window
}
