// JavaScript Document
/***************************/

//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;
}


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;
}
var popUpWin = 0;
function popDirections(course)
{
	var width = 680;
	var height = 575;
	var top = 10;
	var left = 10;
  
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }

	popUpWin = open('enews.cfm?email='+emailAddress, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=1,resizable=1,copyhistory=0,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
	
}

function popWindow(url)
{
	var width = 680;
	var height = 575;
	var top = 10;
	var left = 10;
  
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }

	popUpWin = open(url, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=1,resizable=1,copyhistory=0,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
	
}

function popVideoTour()
{
	var width = 750;
	var height = 484;
	var top = 10;
	var left = 10;
	
  
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }

	popUpWin = open('http://golfatpar.com/aerialVideoTour.htm', 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=0,resizable=0,copyhistory=0,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
	
}

/*************************************************************/
//AJAX weather handler
var numRec = 0;
function getWeatherByZip(zipcode,divElementID)
{
	var xmlHttp;
		try
		{    // Firefox, Opera 8.0+, Safari    
			xmlHttp=new XMLHttpRequest();
		}
		catch (e)
		{    // Internet Explorer    
			try
			{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
				try
				{
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e)
				{
					document.location = 'weather.cfm';
				}
			}
		}
		//nothing was caught, proceed
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{
				if(xmlHttp.responseText.indexOf("error") != -1)//try again
				{
					numRec++;
					
					if(numRec == 3)//enough, call it quits!
					{
						//alert(numRec);
					document.getElementById(divElementID).innerHTML="<span class='weatherError'>Sorry, weather data is unavailable at this time. Please check back later.</span>";
					}
					else
					{
						var queryURL = 'CFHandlers/getWeather.cfm?zip='+zipcode;
						xmlHttp.open("GET",queryURL,true);
						xmlHttp.send(null);
					}
				}
				else
				{
					//alert(numRec);
					document.getElementById(divElementID).innerHTML=xmlHttp.responseText;
				}
				
			}
		}
		
		var queryURL = 'CFHandlers/getWeather.cfm?zip='+zipcode;
		xmlHttp.open("GET",queryURL,true);
		xmlHttp.send(null);
}


