﻿// Feb 2009 - initial common JS contains ajaxGet for AJAX calls to rGet.asp
// as in: ajaxGet('ajax2', '{SiteLinkName}', 'Panel170')  

// 02/21/09 moved toggle, toggleTab and selectCat functions to from /site/togglerow.js to this common.js file
// 04/26/11 added Google Analytics for Regent Cruise Destinations
// 05/10/11 removed Google Analytics, code now resides in rsSites.IncludeHTMLHeader fields

function ajaxGet(field, site, type)
  {
  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)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      document.getElementById(field).innerHTML=xmlHttp.responseText;
      }
    }          
  var page = "rGet.asp?Site=" + site + "&Type=" + type
  //	alert ('Launching call to ' + page);    
  xmlHttp.open("GET",page,true);
  xmlHttp.send(null);
  }

function toggle(row) 
{
//	alert (document.getElementById("lastToggle").value);
//	alert ('Toggle:' + row);
//	alert ('TitleRow='+'title'+row);

	var lastRow = document.getElementById("lastToggle")	;
	var prevRow = document.getElementById(lastRow.value);
	var thisRow = document.getElementById(row);
	var titleRow = document.getElementById('title'+row);
	var linkRow = document.getElementById('link'+row);

	if (thisRow.style.display=="none")							// if row is hidden
	{
		thisRow.style.display="";							// show the row
		titleRow.className="PriceTableCellBold";			// and hilite Departure Date above shown row
		linkRow.style.fontWeight="bold";					// and bold the link
		
							// turn lastToggle off if not 'none' (uninitialized) and not the same as the row just turned on
		if (document.getElementById("lastToggle").value!='none' && document.getElementById("lastToggle").value!=row )
		{	
			prevRow.style.display="none";					// hide the row
			titleRow = document.getElementById('title'+lastRow.value);
			titleRow.className="PriceTableCell";			// and un-hilite Departure Date above last row
			linkRow = document.getElementById('link'+lastRow.value);
			linkRow.style.fontWeight="normal";				// and un-bold the link
		}
	}
	else														// else, if row is shown
	{
		thisRow.style.display="none";							// hide the row
		titleRow.className="PriceTableCell";					// and un-hilite Departure Date above hidden row
		linkRow.style.fontWeight="normal";						// and un-bold the link		
	}
	document.getElementById("lastToggle").value=row;					// then store this row in 'lastToggle'
}

function toggleTab(row) 
{
//	alert (document.getElementById("lastTab").value);
//	alert ('Tab:' + row);
//	alert ('TitleRow='+'title'+row);

	var lastRow = document.getElementById("lastTab")	;
	var prevRow = document.getElementById(lastRow.value);
	var thisRow = document.getElementById(row);
	var linkRow = document.getElementById('link'+row);

	if (thisRow.style.display=="none")							// if row is hidden
	{
		thisRow.style.display="";								// show the row
		linkRow.className="selected";							// and hilite Departure Date above shown row

		
		// turn lastTab off if not 'none' (uninitialized) and not the same as the row just turned on
		if (document.getElementById("lastTab").value!='none' && document.getElementById("lastTab").value!=row )
		{	
			prevRow.style.display="none";						// hide the row
			linkRow = document.getElementById('link'+lastRow.value);
			linkRow.className="not-selected";					// and un-hilite tab
		}
	}
	else														// else, if row is shown
	{
		thisRow.style.display="none";							// hide the row
		linkRow.className="not-selected";						// and un-hilite Departure Date above hidden row
	}
	document.getElementById("lastTab").value=row;				// then store this row in 'lastToggle'
}

function selectCat(id)	// brings PriceID in from Date/Price form "More Info" click
{
	// window.frames("frame1").document.forms("form1").elements("FirstName1").value = "Randy";
	// accesses the category list on the request form which is located within the frame1
	// matches the PriceID that is passed in, selects that entry and toggles to the request form
	
	//	initial IE code: var theCat = window.frames("frame1").document.forms("form1").elements("Category1");	
	
	// replaced by FF and IE code:
	var innerFrameDoc = window.frames['frame1'].document;
	var innerFrameForm = innerFrameDoc.forms['form1'];
	var theCat = innerFrameForm.elements['Category1'];

	var i = 1;
//					substring from position 0 to the position of '|' for PriceID  (12345| November 12, xxxx)
	while (id!=theCat.options[i].value.substring(0,theCat.options[i].value.indexOf("|")) && i<theCat.length-1)	// loop until we find the PriceID/Category in the list
	{
	  i++;
	}
	theCat.selectedIndex=i;										// select this category
	toggleTab('cellq');											// toggle to the quote request
}

