//       -------------  global variables  -----------------

//        ------------  functions -----------------
//------------------------------------------------------------------------//
//  ajGetCities
//		returns a list of cities for a selected state via ajax
//------------------------------------------------------------------------//
function ajGetCities(path,el,page)
{
	if(el.value == 'zz')
	{
		elCity = document.getElementById("divCities");
		elCity.innerHTML = "";
		return;
	}//
	tabId1 = "find-golf-deals_tab";
	tabEl1 = document.getElementById(tabId1);
	if(page == '' || page == "home.php" || page == "listedCourses.php")
  	{
		var cType = 1;
	}else if(page == "destinations.php"){
	  	var cType = 3;
	}else if(page == "drivingRanges.php" || "listedRanges.php"){
		var cType = 7;
	}// endif  
		elCity = document.getElementById("divCities");

	// get the xmlhttp object
		xmlhttp = getXmlHttp();

	// get the value for the selected index make sure it isn't the dafault 'select state' option
		selIndex = el.selectedIndex;
		selOpt = el.options[selIndex].value;

		getVars = 'action=cities&stateId='+selOpt+'&cType='+cType;

		var date = new Date();
		var timestamp = "&time="+date.getTime(); 
		var serverPage = path+'ajax.php?'+getVars+timestamp;
	// call the ajax page to run the query to get the cities for this state

		xmlhttp.open("GET",serverPage);
		xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{


			// get the options returned via ajax
				var rtnText = xmlhttp.responseText;
			// trim the return value an check for an empty return
				var rtnText = rtnText.replace(/^\s+|\s+$/g, '') ;


			// split the return string into seperate records and add them to the drop down list
				var arrRecords = rtnText.split(':');
				var i = 0;

				if(rtnText == ""){
					elCity = document.getElementById("divCities");
					elCity.innerHTML = '<div id="newSel"><label for="city">No Results Found.</label></div>';
					//fadeBg('newSel','#99cc33','#5d9731','1000');
				}else{
					elCity.innerHTML = '<div id="newSel"><dl><dt><label for="city" accesskey="#">Select Your City</label></dt><dd><select name="selCity" id="selCity"></select></dl></div>';

					//fadeBg('newSel','#99cc33','#5d9731','1000');
					//clear out the drop down list
						var listCities = document.getElementById("selCity");

				// insert the 'entire state' option
					firstOpt = document.createElement('option');
					if(el.id == 'state')
					{
						firstOpt.appendChild(document.createTextNode("-- select a city --"));
					}else{
						firstOpt.appendChild(document.createTextNode("-- Entire State --"));
					}// endif

					firstOpt.setAttribute('value','*');
					firstOpt.setAttribute('selected','selected');
					listCities.appendChild(firstOpt);

					for( var i = 0; i < arrRecords.length; i++ )
					{
						arrOpt = arrRecords[i].split('=');
						newOpt = document.createElement('option');
						newOpt.appendChild(document.createTextNode(arrOpt[1]));
						newOpt.setAttribute('value',arrOpt[0]);
						listCities.appendChild(newOpt);
					}// end for
				}// endif
		}//endif

	}//end onreadystatechange function
	xmlhttp.send(null);
}// end function ajGetCities

//------------------------------------------------------------------------//
//  ajGetGreenSaversCities
//		returns a list of cities for a selected state via ajax
//------------------------------------------------------------------------//
function ajGetGreenSaversCities(path,el)
{
	if(el.value == 'zz')
	{
		elCity = document.getElementById("divCities");
		elCity.innerHTML = "";
		return;
	}//
	tabId1 = "find-golf-deals_tab";
	tabEl1 = document.getElementById(tabId1);
	if(tabEl1.style.backgroundColor == "#cccccc")
  	{
	  	var cType = 3;
	}else{
		var cType = 1;
	}// endif
	   
		elCity = document.getElementById("divCities");
		elCity.innerHTML = '<div id="newSel" class="lime-fade"><dl><dt><label for="city" accesskey="#">Select Your City</label></dt><dd><select name="selCity" id="selCity"></select></dl>';

		fadeBg('newSel','#99cc33','#5d9731','1000');

	// get the xmlhttp object
		xmlhttp = getXmlHttp();

	// get the value for the selected index make sure it isn't the dafault 'select state' option
		selIndex = el.selectedIndex;
		selOpt = el.options[selIndex].value;

		getVars = 'action=greenSaverCities&stateId='+selOpt+'&cType='+cType;

		var date = new Date();
		var timestamp = "&time="+date.getTime(); 
		var serverPage = path+'ajax.php?'+getVars+timestamp;

	// call the ajax page to run the query to get the cities for this state

		xmlhttp.open("GET",serverPage);
		xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			//clear out the drop down list
				var listCities = document.getElementById("selCity");

			// insert the 'entire state' option
				firstOpt = document.createElement('option');
				if(el.id == 'state')
				{
					firstOpt.appendChild(document.createTextNode("-- select a city --"));
				}else{
					firstOpt.appendChild(document.createTextNode("-- Entire State --"));
				}// endif
				firstOpt.setAttribute('value','*');
				firstOpt.setAttribute('selected','selected');
				listCities.appendChild(firstOpt);

			// get the options returned via ajax
				var rtnText = xmlhttp.responseText;
			// trim the return value an check for an empty return
				var rtnText = rtnText.replace(/^\s+|\s+$/g, '') ;
				if(rtnText == "")
				{
					return;
				}// endif


			// split the return string into seperate records and add them to the drop down list
				var arrRecords = rtnText.split(':');
				var i = 0;
				for( var i = 0; i < arrRecords.length; i++ )
				{

					arrOpt = arrRecords[i].split('=');
					newOpt = document.createElement('option');
					newOpt.appendChild(document.createTextNode(arrOpt[1]));
					newOpt.setAttribute('value',arrOpt[0]);
					listCities.appendChild(newOpt);
				}// end for
		}//endif

	}//end onreadystatechange function
	xmlhttp.send(null);
}// end function ajGetCities

//------------------------------------------------------------------------//
//  ajGetCities2
//		returns a list of cities for a selected state via ajax
//------------------------------------------------------------------------//
function ajGetCities2(path,el)
{
		elCity = document.getElementById("cities");
		elCity.innerHTML = '<div id="newSel"><dl><dt><label for="city" accesskey="#">Course City</label></dt><dd><select name="selCities" id="selCities"></select></dl>';

		fadeBg('newSel','#99cc33','#5d9731','1000');
		//document.getElementById("newSel").style.backgroundColor = "#5d9731";

	// get the xmlhttp object
		xmlhttp = getXmlHttp();

	// get the value for the selected index make sure it isn't the dafault 'select state' option
		selIndex = el.selectedIndex;
		selOpt = el.options[selIndex].value;


	// call the ajax page to run the query to get the cities for this state
		var serverPage = path+'ajax.php?action=cities&stateId='+selOpt;

		//var objId = 'divAddResults';
		//var AddObj = document.getElementById(objId);
		xmlhttp.open("GET",serverPage);
		xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			//clear out the drop down list
				var listCities = document.getElementById("selCities");

			// insert the 'entire state' option
				firstOpt = document.createElement('option');
				if(el.id == 'state')
				{
					firstOpt.appendChild(document.createTextNode("-- select a city --"));
				}else{
					firstOpt.appendChild(document.createTextNode("-- Entire State --"));
				}// endif
				firstOpt.setAttribute('value','*');
				firstOpt.setAttribute('selected','selected');
				listCities.appendChild(firstOpt);

			// get the options returned via ajax
				var rtnText = xmlhttp.responseText;

			// trim the return value an check for an empty return
				var rtnText = rtnText.replace(/^\s+|\s+$/g, '') ;
				if(rtnText == "")
				{
					return;
				}// endif


			// split the return string into seperate records and add them to the drop down list
				var arrRecords = rtnText.split(':');
				var i = 0;
				for( var i = 0; i < arrRecords.length; i++ )
				{

					arrOpt = arrRecords[i].split('=');
					newOpt = document.createElement('option');
					newOpt.appendChild(document.createTextNode(arrOpt[1]));
					newOpt.setAttribute('value',arrOpt[0]);
					listCities.appendChild(newOpt);
				}// end for
		}//endif

	}//end onreadystatechange function
	xmlhttp.send(null);
}// end function ajGetCities


//------------------------------------------------------------------------//
//  clearDDL
//		clears the drop down list of all options
//------------------------------------------------------------------------//
function clearDDL(el)
{
	var ddl = document.getElementById(el);
	var i = 0;
	if(ddl.options.length>0)
	{
		for(i=ddl.options.length-1;i>=0;i--)
		{
			ddl.remove(i);
		}//end for
	}//endif
}// end function clearDDL 


//------------------------------------------------------------------------//
//  getXmlHttp
//		gets the correct http object based on the browser
//------------------------------------------------------------------------//
function getXmlHttp()
{
// create a boolean variable to check for a valid internet explorer instance
		var xmlhttp = false;

	//Check if we are using IE
		try{
			// If the Javascript version is greater than 5
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			//alert("You are using Microsoft Internet Explorer.");
		}catch(e){
			// If not, then use the older active x object.
			try{
			//If we are using Internet Explorer.
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				//alert("You are using Microsoft Intenet Explorer");
			}catch(E){
				// else we musti be using a non-IE browser
				xmlhttp = false;
			}// end try-catch
		}// end try-catch

	//If we are using a nen-IE browser, create a javascript instance of the object
		if(!xmlhttp && typeof XMLHttpRequest != 'undefined')
		{
			xmlhttp = new XMLHttpRequest();
			//alert("You are not using Microsoft Internet Explorer");
		}//endif

		return xmlhttp;
}// end getXmlHttp function



//------------------------------------------------------------------------//
//  showDeal
//		expands or collapses the div for a golf deal
//------------------------------------------------------------------------//
function showDeal(path,id1,id2,id3,cpnId)
{

	el1 = window.document.getElementById(id1);
	el2 = window.document.getElementById(id2);
	el3 = window.document.getElementById(id3);

	// get the xmlhttp object
		xmlhttp = getXmlHttp();

	// call the ajax page to run the query to get the cities for this state
		var getVars = 'action=cpnDesc&cpnId='+cpnId;
		var date = new Date();
		var timestamp = "&time="+date.getTime(); 
		var serverPage = path+'ajax.php?'+getVars+timestamp;
		xmlhttp.open("Get",serverPage);
		xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			// get the options returned via ajax
				var rtnText = xmlhttp.responseText;

			// trim the return value an check for an empty return
				var rtnText = rtnText.replace(/^\s+|\s+$/g, '') ;
				var fullText = rtnText;

			if(el2.innerHTML == "more")
			{
				//el1.style.maxHeight = "none";
				el2.innerHTML = "less";
				el3.innerHTML = fullText;
			}else{
				//el1.style.maxHeight = "209px";
				el2.innerHTML = "more";
				el3.innerHTML = fullText.substring(0,159);
			}//endif
		}//endif

	}//end onreadystatechange function
	xmlhttp.send(null);




}// end showDeal function



//------------------------------------------------------------------------//
//  toHand
//		switch cursor to a hand
//------------------------------------------------------------------------//
function toHand(el)
{
	el.style.cursor = "pointer";
}// end toHand function


//------------------------------------------------------------------------//
//  ajDeletCoupon
//		deletes a coupon from the basket
//------------------------------------------------------------------------//
function ajDeleteCoupon(cuId)
{

	// get the xmlhttp object
		xmlhttp = getXmlHttp();

	// call the ajax page to run the query to get the cities for this state
		var serverPage = '../ajax.php?action=delBasketCoupon&id='+cuId;
		//var objId = 'divAddResults';
		//var AddObj = document.getElementById(objId);
		xmlhttp.open("GET",serverPage);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
			{
				// get the options returned via ajax
					var rtnText = xmlhttp.responseText;

				// trim the return value an check for an empty return
					var rtnText = rtnText.replace(/^\s+|\s+$/g, '') ;

				// refresh the window
					window.location.reload();
			}// endif
	}//end onreadystatechange function
	xmlhttp.send(null);

	return false;

}// end ajDeleteCoupon



//------------------------------------------------------------------------//
//  ajDeletCoupon
//		deletes a coupon from the basket
//------------------------------------------------------------------------//
function ajLogout(path)
{

	// get the xmlhttp object
		xmlhttp = getXmlHttp();

	// call the ajax page to run the query to get the cities for this state

		var getVars = 'action=logout';
		var date = new Date();
		var timestamp = "&time="+date.getTime(); 
		var serverPage = path+'ajax.php?'+getVars+timestamp;

		xmlhttp.open("GET",serverPage);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
			{
				// get the options returned via ajax
					var rtnText = xmlhttp.responseText;

				// trim the return value an check for an empty return
					var rtnText = rtnText.replace(/^\s+|\s+$/g, '') ;
					//alert(rtnText);
				// refresh the window
					homePage = path +"home.php";
					window.location = homePage;
			}// endif
	}//end onreadystatechange function
	xmlhttp.send(null);

}// end ajDeleteCoupon


//------------------------------------------------------------------------//
//  previewDeal
//		expands or collapses the div for a golf deal
//------------------------------------------------------------------------//
function previewDeal(id1,id2,id3)
{ 
	el1 = window.document.getElementById(id1);
	el2 = window.document.getElementById(id2);
	el3 = window.document.getElementById(id3);

			if(el1.style.maxHeight != "none")
			{
				el1.style.maxHeight = "none";
				el2.innerHTML = "less";
				el3.innerHTML = window.document.getElementById("description").value;
			}else{
				el1.style.maxHeight = "160px";
				el2.innerHTML = "more";
				el3.innerHTML = window.document.getElementById("description").value.substring(0,159);
			}//endif
}// end showDeal function



//------------------------------------------------------------------------//
//  loadPreview
//		expands or collapses the div for a golf deal
//------------------------------------------------------------------------//
function loadPreview(el1)
{
 
		switch(el1.id)
		{

			case "description":
				//el2 = window.document.getElementById("show1");
				el3 = window.document.getElementById("desc1");
				//var strMatch = "more";
				//var strDesc =  el2.innerHTML;
				//var matchPos1 = strDesc.search(strMatch);
				strStripped = el1.value.replace(/(<([^>]+)>)/ig,""); 
				//if(matchPos1 != -1)
				//{
					el3.innerHTML = strStripped;
				//}else{
				//	el3.innerHTML = strStripped;
				//}// endif
				break;

			case "regular-price":
				elPrice = window.document.getElementById("regular-price");
				dsPrice = window.document.getElementById("discount-price").value;
				rgPrice = elPrice.value;
				var dsNbr = parseFloat(dsPrice);
				var rgNbr = parseFloat(rgPrice);
				pctOff = (1- (dsNbr/rgNbr))*100;
				strPctOff = formatCurrency(pctOff);
				var arrPctOff = strPctOff.split('.');
				pctStr = "$"+formatCurrency(rgNbr - dsNbr)+" ("+arrPctOff[0]+"% )";
				window.document.getElementById("pctOff1").innerHTML = pctStr;
				break;

			case "discount-price":
				dsPrice = el1.value;
				rgPrice = window.document.getElementById("regular-price").value;

				price = formatCurrency(dsPrice);
				var arrPrice = price.split('.');
				dollars = arrPrice[0];
				cents = arrPrice[1];
				window.document.getElementById("dollar1").innerHTML = dollars;
				window.document.getElementById("cents1").innerHTML = cents;

				var dsNbr = parseFloat(dsPrice);
				var rgNbr = parseFloat(rgPrice);
				pctOff = (1- (dsNbr/rgNbr))*100;
				strPctOff = formatCurrency(pctOff);
				var arrPctOff = strPctOff.split('.');
				pctStr = " $"+formatCurrency(rgNbr - dsNbr)+" ("+arrPctOff[0]+"%)";
				window.document.getElementById("pctOff1").innerHTML = pctStr;
				break;

			case "title":
				strTitle = el1.value;
				window.document.getElementById("title1").innerHTML = strTitle;
				break;

			case "cart-included":
				strCart = el1.value;
				if(strCart == "y")
				{
					window.document.getElementById("cart1").innerHTML = "Cart Included";
				}else{
					window.document.getElementById("cart1").innerHTML = "Cart Not Included";
				}// endif
				break;

				case "price-type":
				strPrice = el1.value;
				if(strPrice == "person")
				{
					window.document.getElementById("priceType").innerHTML = "Price Per Person";
				}else if(strPrice == "package"){
					window.document.getElementById("priceType").innerHTML = "Package Price";
				}else if(strPrice == "starting"){
					window.document.getElementById("priceType").innerHTML = "Starting Price";
				}// endif
				break;

			case "players-required":
				strPlayers = el1.value;

				switch(strPlayers)
				{
					case "1":
						strResult = "1 Player Required";
						break;

					case "chooseplayers":
						strResult = "";
						break;

					case "3":
						strResult = "2 or 4 Players Required";
						break;

					case "5":
						strResult = "1 to 4 Players Required";
						break;

					case "6":
						strResult = "3 or 4 Players Required";
						break;

					default:
						strResult = strPlayers+" Players Required";
						break;

				}// end switch
				window.document.getElementById("player1").innerHTML = strResult;
				break;

			case "expiration-date":
				strDate = el1.value;
				var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul',
					'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
				d = new Date(strDate);
				if (d.getDate()) {
					document.getElementById('expiration1').innerHTML = (months[d.getMonth()]
						+ ' ' + d.getDate() + ', ' + d.getFullYear());
				}
				break;

			case "roundsInc":
				var myIndex = el1.selectedIndex;
				var myValue =  el1.options[myIndex].value;
				var myText = '';

				if(myValue == 'Unlimited')
				{
					myText = ' Golf';
				}else if(myValue == 1 ){
					myText = ' Round Included';
				}else{
					myText = ' Rounds Included';
				}//endif

				window.document.getElementById("rounds").innerHTML = myValue + myText;
				break;

			case "nightsInc":
				var myIndex = el1.selectedIndex;
				var myValue =  el1.options[myIndex].value;
				if(myValue <= 1)
				{
					myText = ' Night Included';
				}else{
					myText = ' Nights Included';
				}//endif

				window.document.getElementById("nights").innerHTML = myValue + myText;
				break;

			default:
				break;

		}// end switch

}// end loadPreview function




//------------------------------------------------------------------------//
//  displayPreview
//		display the preview coupon on the load of the page
//------------------------------------------------------------------------//
function displayPreview()
{

	window.document.getElementById("title1").innerHTML = window.document.getElementById("title").value;
	window.document.getElementById("desc1").innerHTML  = window.document.getElementById("description").value;

	if(window.document.getElementById("discount-price")){
	price = formatCurrency(window.document.getElementById("discount-price").value);
		var arrPrice = price.split('.');
		dollars = arrPrice[0];
		cents = arrPrice[1];
		if(window.document.getElementById("dollar1"))
		{
		window.document.getElementById("dollar1").innerHTML = dollars;
		window.document.getElementById("cents1").innerHTML = cents;
		}// emdif
	}// endif

	if(window.document.getElementById("discount-price")){
	dsPrice = window.document.getElementById("discount-price").value;
		rgPrice = window.document.getElementById("regular-price").value;
		var dsNbr = parseFloat(dsPrice);
		var rgNbr = parseFloat(rgPrice);
		pctOff = (1- (dsNbr/rgNbr))*100;
		strPctOff = formatCurrency(pctOff);
		var arrPctOff = strPctOff.split('.');
	}//endif

		if(window.document.getElementById("pctOff1"))
		{
			pctStr = " $"+formatCurrency(rgNbr - dsNbr)+" ("+arrPctOff[0]+"% )";
			window.document.getElementById("pctOff1").innerHTML = pctStr;
		}// endif

		if(window.document.getElementById("cart"))
		{
			strCart = window.document.getElementById("cart").value;
			if(strCart == "y")
			{
				window.document.getElementById("cart1").innerHTML = "Cart Included";
			}else{
				window.document.getElementById("cart1").innerHTML = "Cart Not Included";
			}// endif
		}// emdif

	if(window.document.getElementById("players"))
	{
		strPlayers = window.document.getElementById("players").value;
		switch(strPlayers)
		{
			case "1":
					strResult = "1 Player Required";
					break;

			case "chooseplayers":
				strResult = "";
				break;

			case "3":
				strResult = "2 or 4 Players Required";
				break;

			case "5":
				strResult = "1 to 4 Players Required";
				break;

			case "6":
				strResult = "3 or 4 Players Required";
				break;

			default:
				strResult = strPlayers+" Players Required";
				break;

		}// end switch
		if(window.document.getElementById("player1"))
		{
			window.document.getElementById("player1").innerHTML = strResult;
		}// endif
	}//endif
		strDate = window.document.getElementById("expiration-date").value;
		window.document.getElementById("expiration1").innerHTML = strDate;

	maxCount(50,'title','titleCount');
	maxCount(1000,'description','descCount');
}// end displayPreview function
//------------------------------------------------------------------------//
//  formatCurrency
//		adds a record to the basket
//------------------------------------------------------------------------//
function formatCurrency(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}
// end of function CurrencyFormatted()



//------------------------------------------------------------------------//
//  ajAddToBasket
//		adds a record to the basket
//------------------------------------------------------------------------//
function ajAddToBasket(cpnId)
{

	// get the xmlhttp object
		xmlhttp = getXmlHttp();

	// call the ajax page to run the query to get the cities for this state
		var getVars = 'action=addCoupon&cpnId='+cpnId;
		var date = new Date();
		var timestamp = "&time="+date.getTime(); 
		var serverPage = 'ajax.php?'+getVars+timestamp;
		xmlhttp.open("Get",serverPage);
		xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			// get the options returned via ajax
				var rtnText = xmlhttp.responseText;

			// trim the return value an check for an empty return
				var rtnText = rtnText.replace(/^\s+|\s+$/g, '') ;


				switch(rtnText)
				{

					case "success":
						alert("coupon added to basket");
						var confirmMsg = document.createElement("div");
						window.document.body.appendChild(confirmMsg);
						confirmMsg.innerText = "Coupon added to basket";
						confirmMsg.style.width = "200px";
						confirmMsg.style.height = "200px";
						confirmMsg.style.position = "absolute";
						confirmMsg.style.left = "300px";


						confirmMsg.style.left = fromLeft;
						alert("here");
						break;

					case "login":
						alert("Error:  You must log in to add a coupon to your basket");
						break;

					default:
						alert("coupon not added::"+rtnText+"::"+serverPage+"::"+getVars+"::");
						break;

				}// end switch

		}//endif

	}//end onreadystatechange function
	xmlhttp.send(null);

}// end ajAddToBasket function




//---------------------------------------------------------------------//
//-   topForm:                                                        
//-             place form on top of home.php page                            
//---------------------------------------------------------------------//
function topForm(el)
{ 
	tabId1 = "find-golf-deals_tab";
	tabId2 = "find-golf-destinations_tab";
	tabEl1 = document.getElementById(tabId1);
	tabEl2 = document.getElementById(tabId2);
	if(el == tabEl1)
   {
	   tabEl1.style.backgroundColor = "#5d9731";
	   tabEl2.style.backgroundColor = "#cccccc";
	   document.findgolfdeal.Stype.value = "Deals";
   }else{	   
	   tabEl1.style.backgroundColor = "#cccccc";
	   tabEl2.style.backgroundColor = "#5d9731";
	   document.findgolfdeal.Stype.value = "Destinations";
   }//endif


}// end topForm function



//---------------------------------------------------------------------//
//-   maxCount:                                                        
//-             limit input to the maximum # of characters	                            
//---------------------------------------------------------------------//
function maxCount(maxChars, inputId, messageId)
{
	input = document.getElementById(inputId);
	message = document.getElementById(messageId);
	if (input.value.length > maxChars)
	{
		input.value = input.value.substring(0, maxChars);
		message.innerHTML = maxChars;
		message.style.color = 'red';
	} else {
		message.innerHTML = input.value.length;
		message.style.color = '';
	}
} // end maxCount function



//---------------------------------------------------------------------//
//-   ajChangeStatus:                                                        
//-             change a coupon to/from active/inactive	                            
//---------------------------------------------------------------------//
function ajChangeStatus(path, el, chgState, cpnId) {

	// get the xmlhttp object
	xmlhttp = getXmlHttp();

	// call the ajax page to run the query to get the cities for this state
	var getVars = 'action=chgState&newState=' + chgState + '&cpnId=' + cpnId;
	
	// if activating, check to see if we should send emails
	if (chgState == 'a') {
		var sendEmail = confirm('Would you also like an email sent to users '
			+ 'who have requested notifications of your course updates?');
		if (sendEmail)
			getVars += '&sendAlerts=true';
	}

	var date = new Date();
	var timestamp = "&time=" + date.getTime(); 
	var serverPage = path + 'ajax.php?' + getVars + timestamp;
	xmlhttp.open("Get", serverPage);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			// get the options returned via ajax
			var rtnText = xmlhttp.responseText;

			// trim the return value an check for an empty return
			var rtnText = rtnText.replace(/^\s+|\s+$/g, '');

			switch (rtnText) {
				case "a":
					// refresh the window
					window.location.reload();
					break;

				case "d":
					// refresh the window
					window.location.reload();
					break;

				case "Can't determine coupon type":
					alert(rtnText);
					break;

				case "Can't determine number of active coupons":
					alert(rtnText);
					break;

				case "Can't change coupon status":
					alert(rtnText);
					break;

				default:
					alert(rtnText);
					break;

			}
		}
	};
	xmlhttp.send(null);
	return false;
} // end ajChangeStatus function


//---------------------------------------------------------------------//
//-   ajDeleteCourseCoupon:                                                        
//-             delete a course's coupon                          
//---------------------------------------------------------------------//
function ajDeleteCourseCoupon(path,cpnId)
{

	// get the xmlhttp object
		xmlhttp = getXmlHttp();

		var answer = confirm("Delete this coupon?");

		if(! answer)
		{
			return false;
		}// endif

	// call the ajax page to run the query to get the cities for this state
		var getVars = 'action=deleteCourseCoupon&cpnId='+cpnId;
		var date = new Date();
		var timestamp = "&time="+date.getTime(); 
		var serverPage = path+'ajax.php?'+getVars+timestamp;
		xmlhttp.open("Get",serverPage);
		xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			// get the options returned via ajax
				var rtnText = xmlhttp.responseText;

			// trim the return value an check for an empty return
				var rtnText = rtnText.replace(/^\s+|\s+$/g, '') ;

				switch(rtnText)
				{
					case "success":
						// refresh the window
						window.location.reload();
						break;
				}// end switch
		}//endif
	}//end onreadystatechange function
	xmlhttp.send(null);
} // end ajChangeStatus function


//---------------------------------------------------------------------//
//-   ajBasketCID:                                                        
//-             get the id's for the coupons in the basket                        
//---------------------------------------------------------------------//
function ajBasketCID(path)
{

	// get the xmlhttp object
		xmlhttp = getXmlHttp();

	// call the ajax page to run the query to get the cities for this state
		var getVars = 'action=getBasketCID';
		var date = new Date();
		var timestamp = "&time="+date.getTime(); 
		var serverPage = path+'ajax.php?'+getVars+timestamp;
		xmlhttp.open("Get",serverPage);
		xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			// get the options returned via ajax
				var rtnText = xmlhttp.responseText;

			// trim the return value an check for an empty return
				var rtnText = rtnText.replace(/^\s+|\s+$/g, '') ;

			// split the return string into seperate records and add them to the drop down list
				var arrBasketId = rtnText.split(':');

				var i = 0;
				for( var i = 0; i < arrBasketId.length; i++ )
				{
					urlStr = "printCoupon.php?coupon="+arrBasketId[i];
					window.open(urlStr,'_blank');
				}// end for
		}//endif
	}//end onreadystatechange function
	xmlhttp.send(null);
} // end ajBasketCID function

//---------------------------------------------------------------------//
//-   fadeIn:                                                        
//-             fade in the inserted html                            
//---------------------------------------------------------------------//
 /*************************************************************
* NLB Background Color Fader v1.0
* Author: Justin Barlow - www.netlobo.com
*
* Description:
* The Background Color Fader allows you to gradually fade the
* background of any HTML element.
*
* Usage:
* Call the Background Color Fader as follows:
*   NLBfadeBg( elementId, startBgColor, endBgColor, fadeTime );
*
* Description of Parameters
*   elementId - The id of the element you wish to fade the
*             background of.
*   startBgColor - The background color you wish to start the
*             fade from.
*   endBgColor - The background color you want to fade to.
*   fadeTime - The duration of the fade in milliseconds.
*************************************************************/



var nlbFade_hextable = [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' ]; // used for RGB to Hex and Hex to RGB conversions

function fadeBg( elementId, startBgColor, endBgColor, fadeTime )
{

	var timeBetweenSteps = Math.round( Math.max( fadeTime / 300, 30 ) );
	var startBgColorRGB = hexToRGB( startBgColor );
	var endBgColorRGB = hexToRGB( endBgColor );
	var diffRGB = new Array( );
	for( var i = 0; i < 3; i++ )
	{
		diffRGB[i] = endBgColorRGB[i] - startBgColorRGB[i];
	}// endfor
	var steps = Math.ceil( fadeTime / timeBetweenSteps );
	var nlbFade_s = new Array( );
	for( var i = 1; i <= steps; i++ )
	{
		var changes = new Array( );
		for( var j = 0; j < diffRGB.length; j++ )
			changes[j] = startBgColorRGB[j] + Math.round( ( diffRGB[j] / steps ) * i );
		if( i == steps )
			nlbFade_s[i - 1] = setTimeout( 'document.getElementById("'+elementId+'").style.backgroundColor = "'+endBgColor+'";', timeBetweenSteps*(i-1) );
		else
			nlbFade_s[i - 1] = setTimeout( 'document.getElementById("'+elementId+'").style.backgroundColor = "'+RGBToHex( changes )+'";', timeBetweenSteps*(i-1) );
	}//endfor

}// end function NLBfadeBg

function hexToRGB( hexVal )
{
	hexVal = hexVal.toUpperCase( );
	if( hexVal.substring( 0, 1 ) == '#' )
		hexVal = hexVal.substring( 1 );
	var hexArray = new Array( );
	var rgbArray = new Array( );
	hexArray[0] = hexVal.substring( 0, 2 );
	hexArray[1] = hexVal.substring( 2, 4 );
	hexArray[2] = hexVal.substring( 4, 6 );
	for( var k = 0; k < hexArray.length; k++ )
	{
		var num = hexArray[k];
		var res = 0;
		var j = 0;
		for( var i = num.length - 1; i >= 0; i-- )
			res += parseInt( nlbFade_hextable.indexOf( num.charAt( i ) ) ) * Math.pow( 16, j++ );
		rgbArray[k] = res;
	}
	return rgbArray;
}

function RGBToHex( rgbArray )
{
	var retval = new Array( );
	for( var j = 0; j < rgbArray.length; j++ )
	{
		var result = new Array( );
		var val = rgbArray[j];
		var i = 0;
		while( val > 16 )
		{
			result[i++] = val%16;
			val = Math.floor( val/16 );
		}
		result[i++] = val%16;
		var out = '';
		for( var k = result.length - 1; k >= 0; k-- )
			out += nlbFade_hextable[result[k]];
		retval[j] = padLeft( out, '0', 2 );
	}
	out = '#';
	for( var i = 0; i < retval.length; i++ )
		out += retval[i];
	return out;
}
if (!Array.prototype.indexOf) {
	Array.prototype.indexOf = function( val, fromIndex ) {
		if( typeof( fromIndex ) != 'number' ) fromIndex = 0;
		for( var index = fromIndex, len = this.length; index < len; index++ )
			if( this[index] == val ) return index;
		return -1;
	}
}

function padLeft( string, character, paddedWidth )
{
	if( string.length >= paddedWidth )
		return string;
	else
	{
		while( string.length < paddedWidth )
			string = character + string;
	}
	return string;
}




//---------------------------------------------------------------------//
//-   ajPrintNow:                                                        
//-             print a coupon now                            
//---------------------------------------------------------------------//
function ajPrintNow(cpnId)
{

	// get the xmlhttp object
		xmlhttp = getXmlHttp();

	// call the ajax page to run the query to get the cities for this state
		var getVars = 'action=checkLogin';
		var date = new Date();
		var timestamp = "&time="+date.getTime(); 
		var serverPage = 'ajax.php?'+getVars+timestamp;
		xmlhttp.open("Get",serverPage);
		xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			// get the options returned via ajax
				var rtnText = xmlhttp.responseText;

			// trim the return value an check for an empty return
				var rtnText = rtnText.replace(/^\s+|\s+$/g, '') ;


				switch(rtnText)
				{

					case "yes":
						locString = "basket/printCoupon.php?coupon=" + cpnId;
						printPage = locString;
						window.location = printPage;
						break;

					case "no":
						alert("Error:  You must log in to print a coupon.");
						break;

				}// end switch

		}//endif

	}//end onreadystatechange function
	xmlhttp.send(null);

	return;

}// end function

//---------------------------------------------------------------------//
//-   ajPrintDestinationNow:                                                        
//-             print a destination now                            
//---------------------------------------------------------------------//
function ajPrintDestinationNow(href_in)
{
	// get the xmlhttp object
		xmlhttp = getXmlHttp();

	// call the ajax page to run the query to get the cities for this state
		var getVars = 'action=checkLogin';
		var date = new Date();
		var timestamp = "&time="+date.getTime(); 
		var serverPage = 'ajax.php?'+getVars+timestamp;
		xmlhttp.open("Get",serverPage);
		xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		{
			// get the options returned via ajax
				var rtnText = xmlhttp.responseText;

			// trim the return value an check for an empty return
				var rtnText = rtnText.replace(/^\s+|\s+$/g, '') ;


				switch(rtnText)
				{
					case "yes":
						window.open(href_in);
						//return false;
						break;

					case "no":
						alert("Error:  You must log in to access the offer");
						return false;
						break;

				}// end switch*/

		}//endif

	}//end onreadystatechange function
	xmlhttp.send(null); 
	return false;

}// end function


function countCoupon(cpnId,userId,courseId)
{
	// get the xmlhttp object
		xmlhttp = getXmlHttp();

		var getVars = 'action=countCpn&cpnId='+cpnId+'&courseId='+courseId+'&userId='+userId;
		var date = new Date();
		var timestamp = "&time="+date.getTime(); 
		var serverPage = 'ajax.php?'+getVars+timestamp;
		xmlhttp.open("Get",serverPage);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
			{

					// get the options returned via ajax
						var rtnText = xmlhttp.responseText;

					// trim the return value an check for an empty return
							var rtnText = rtnText.replace(/^\s+|\s+$/g, '') ;

				}// endif
		}// end function

		xmlhttp.send(null);
}// end countCoupon function

function runOpacity(el)
{
	theobj = window.document.getElementById(el);
	theobj.style.filter='progid:DXImageTransform.Microsoft.Alpha(Opacity=' + opacity + ')';
	theobj.style.opacity=value;
}// end runOpacity function

