

// onbeforeunload="return 'If you continue, any unsaved data will be lost.';"
//window.onbeforeunload = function() {}

// GLOABL VARIABLES DECLAIR HERE
var ListingType='';
var ListingRegion='';
var ListingItinerary='';
var ListingMisc='';

var AJXC_Folder_Special = "ajax/";
var Output = "";
var LoadingProductType='';
var LoadingProductID='';
var ProductPartsArray = new Array();
var ProductTypeArray = new Array();

var KeyVal=0;
var Part_Number;
var Part_Cost;

// row_begin(clsname,onclicktxt,activerow)
// cell (data, ucls, uid, ucolspan, uwidth, uother)

/*
#############################################################################
initialize()
Initializes the page
#############################################################################
*/
function initialize() {
  var arid=getfreearid();
  current_divprefix[arid]='Listings';
  current_table[arid]='Listings';
  var newarid=getfreearid();
  current_parentarid[newarid]=arid;
  InitializePage(newarid, AJXC_listtables_tablename, 'TableName');
	LoadListings();
}

/*
#############################################################################
WriteInnerHTML()
Writes Information to a DIV
#############################################################################
*/
function WriteInnerHTML(p_DivID,p_htmlstr) {
	if (document.getElementById) {
		document.getElementById(p_DivID).innerHTML= p_htmlstr;
	} else {
		with (document.layers[p_DivID].document) {
			//open();
			//write(p_htmlstr);
			//close();
		}
	}
}

/*
#############################################################################
AddInnerHTML()
Adds Information to a DIV
#############################################################################
*/
function AddInnerHTML(p_DivID, p_htmlstr) {
	if (document.getElementById) {
		CurContent = document.getElementById(p_DivID).innerHTML;
		
		document.getElementById(p_DivID).innerHTML = CurContent + "\n" + p_htmlstr;
	} else {
		with (document.layers[p_DivID].document) {
			//open();
			//write(p_htmlstr);
			//close();
		}
	}
}

/*
#############################################################################
SearchArray()
Searches the array for a value
#############################################################################
*/
function SearchArray(NewArray, NewValue) {
	var returnval = "";
	for (i=0; i<NewArray.length; i++) {
		if (NewArray[i] == NewValue) {
			returnval=i;
			break;
		}
	}
	return returnval;
}

/*
#############################################################################
STEP 1-a1 - No ProductType set
GetProductTypes()
Gets list of product types from the database table 'Product_Type'
This list is only retrieved if 'ProductType' is blank when the configurator
loads.
#############################################################################
*/
function LoadListings() {
	
	var tmp;
	
	// First Search Option
	var SO1_Output = '';
	var SO1 = new Array();
	for (i=0; i<=20; i++) {
		eval("SO1[" + i + "] = document.SearchAJXForm[\"SO1[" + i + "]\"];");
	}

	for (i=0; i<=SO1.length; i++) {
		tmp = SO1[i];
		if (tmp != undefined) {
			if (tmp.checked == true) {
				if (SO1_Output != '') SO1_Output += AJXC_Delim_2
				SO1_Output += tmp.value;
			}
		}
	}
	
	// Second Search Option
	var SO2_Output = '';
	var SO2 = new Array();
	for (i=0; i<=20; i++) {
		eval("SO2[" + i + "] = document.SearchAJXForm[\"SO2[" + i + "]\"];");
	}

	for (i=0; i<=SO2.length; i++) {
		tmp = SO2[i];
		if (tmp != undefined) {
			if (tmp.checked == true) {
				if (SO2_Output != '') SO2_Output += AJXC_Delim_2
				SO2_Output += tmp.value;
			}
		}
	}
	
	// Third Search Option
	var SO3_Output = '';
	var SO3 = new Array();
	for (i=0; i<=20; i++) {
		eval("SO3[" + i + "] = document.SearchAJXForm[\"SO3[" + i + "]\"];");
	}
	
	for (i=0; i<=SO3.length; i++) {
		tmp = SO3[i];
		if (tmp != undefined) {
			if (tmp.checked == true) {
				if (SO3_Output != '') SO3_Output += AJXC_Delim_2
				SO3_Output += tmp.value;
			}
		}
	}
	
	if (ListingType == 'attractions') {
	  var data=ListingType + AJXC_Delim_1 + SO1_Output + AJXC_Delim_1 + SO2_Output + AJXC_Delim_1 + SO3_Output;
	}
	
	if (ListingType == 'lodging') {
	  var data=ListingType + AJXC_Delim_1 + SO1_Output + AJXC_Delim_1 + SO2_Output + AJXC_Delim_1 + SO3_Output;
	}
  var arid=1;
  //writetablepanels(arid);
  showloadinggif();
  compose_and_send_packet('load_listings.html', data, null, null, GetProductTypes_sub, arid, null, null, AJXC_Folder_Special);
	return false;
}

/*
#############################################################################
STEP 1-a2 - No ProductType set
GetProductTypes_sub()
Processes the ProductType list retreived from the database and writes it to 
the screen
#############################################################################
*/
function GetProductTypes_sub(responsetext, arid){
	hideloading();
  if (!SplitResponse(responsetext)) {
    alert("Error: " + Resp_Data);
		hideloading();
    return;
  }
  jstoexecute=Array();
  table_begin();
  var splitdata = Resp_Data.split(AJXC_Delim_1);
  
  var ListingCount = splitdata[0];
  var ListingData = splitdata[1];
  
  WriteInnerHTML("Listing_Count", " " + ListingCount + " ");

  var ListingHTML = '';
  ListingHTML += '';
  
  var ListingSplit = ListingData.split(AJXC_Delim_3);
  for (i=0; i<=ListingSplit.length-2; i++) {
  	ListingInfoData = ListingSplit[i].split(AJXC_Delim_2);
  	
  	
  	// ATTRACTIONS LISTING
  	if (ListingType == 'attractions') {
			ListingHTML += '<div class="Listing_Wrapper">';
			ListingHTML += '	<div class="Listing_Title"><a href="/refer.html?id=' + ListingInfoData[2] + '">' + ListingInfoData[0] + '</a></div>';
			ListingHTML += '	<div class="Listing_Info_Wrapper">';
			ListingHTML += '		<div class="Listing_Description">' + ListingInfoData[5] + '</div>';
			ListingHTML += '		<div class="Listing_More_Info"><a href="details.html?id=' + ListingInfoData[2] + '">Click for more Info...</a></div>';
			ListingHTML += '	</div>';
			ListingHTML += '	<div class="Listing_Image">';
			ListingHTML += '		<a href="details.html?id=' + ListingInfoData[2] + '"><img src="/images/' + ListingType + 'photo/' + ListingInfoData[4] + '" border=0 alt="' + ListingInfoData[0] + '"></a>';
			ListingHTML += '	</div>';
			ListingHTML += '</div>';
			ListingHTML += '<div style="clear: both"></div>';
		}
		
  	if (ListingType == 'lodging') {
			ListingHTML += '<div class="Lodging_Wrapper">' + "\n"
			ListingHTML += '	<div class="Lodging_Info">' + "\n";
			ListingHTML += '		<a href="/refer.html?id=' + ListingInfoData[2] + '">' + ListingInfoData[0] + '</a><br>' + "\n";
			ListingHTML += '		' + ListingInfoData[5] + '<br>' + "\n";
			if (ListingInfoData[8]) ListingHTML += "		<b>Toll-Free:</b> " + ListingInfoData[8] + ' ';
			if (ListingInfoData[6]) ListingHTML += "		<b>Email:</b> see website";
			if (ListingInfoData[8] || ListingInfoData[6])ListingHTML += '<br>' + "\n";
			if (ListingInfoData[7]) ListingHTML += "Phone: " + ListingInfoData[7] + '<br>' + "\n";
			ListingHTML += '	</div>' + "\n";
			ListingHTML += '	<div class="Lodging_Rates">' + "\n";
			ListingHTML += "		Rates: <b>" + ListingInfoData[10] + "</b><br>\n";
			ListingHTML += "		Location: " + ListingInfoData[9] + "<br>\n";
			ListingHTML += "    <a href=\"/lodging/details.phtm?id=" + ListingInfoData[2] + "\">More Information</a><br>\n";
			ListingHTML += '	</div>' + "\n";
			ListingHTML += '</div>' + "\n";
		}
		
	}
  
  WriteInnerHTML("Listings_0_", ListingHTML);
}