﻿//Set the Global Variables when things change
//Copyright 2007 CTTC All Rights Reserved
//Version: 1.0
var searchPage = 'findyourself.aspx?';
var baseURL = '/modules/';
var basesearchURL =  baseURL + 'findyourself.aspx?';
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;


function whichBrs() {
    var agt=navigator.userAgent.toLowerCase();
    if (agt.indexOf("opera") != -1) return 'Opera';
    if (agt.indexOf("staroffice") != -1) return 'Star Office';
    if (agt.indexOf("webtv") != -1) return 'WebTV';
    if (agt.indexOf("beonex") != -1) return 'Beonex';
    if (agt.indexOf("chimera") != -1) return 'Chimera';
    if (agt.indexOf("netpositive") != -1) return 'NetPositive';
    if (agt.indexOf("phoenix") != -1) return 'Phoenix';
    if (agt.indexOf("firefox") != -1) return 'Firefox';
    if (agt.indexOf("safari") != -1) return 'Safari';
    if (agt.indexOf("skipstone") != -1) return 'SkipStone';
    if (agt.indexOf("msie") != -1) return 'Internet Explorer';
    if (agt.indexOf("netscape") != -1) return 'Netscape';
    if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
    if (agt.indexOf('\/') != -1) {
    if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
    return navigator.userAgent.substr(0,agt.indexOf('\/'));}
    else return 'Netscape';} else if (agt.indexOf(' ') != -1)
    return navigator.userAgent.substr(0,agt.indexOf(' '));
    else return navigator.userAgent;
}

function textCityFocus(obj) {
	if (obj.value == "city or zip") {
		obj.value = "";
	}
}

function textCityBlur(obj) {
	if (obj.value === "") {
		obj.value = "city or zip";
	}
}

/*-------------------------------------------------------------------------
Grabs an Element (supports different browsers) - usage: e=grabElem('theId');
-------------------------------------------------------------------------*/
function grabElemement(theObj,theDoc)
{var p,i,foundObj;
if(!theDoc)theDoc=document;
if((p=theObj.indexOf("?"))>0&&parent.frames.length)
{theDoc=parent.frames[theObj.substring(p+1)].document;theObj=theObj.substring(0,p);}
if(!(foundObj=theDoc[theObj])&&theDoc.all)foundObj=theDoc.all[theObj];
for(i=0;!foundObj&&i<theDoc.forms.length; i++)foundObj=theDoc.forms[i][theObj];
for(i=0;!foundObj&&theDoc.layers&&i<theDoc.layers.length;i++)foundObj=findObj(theObj,theDoc.layers[i].document);
if(!foundObj&&document.getElementById) foundObj = document.getElementById(theObj);
return foundObj;}


function SearchTag(tagitem)
{
    window.location = basesearchURL + 'tag=' + tagitem;
    //alert(basesearchURL + 'tag=' + tagitem);
}

function SearchKeyword(keyword)
{
    window.location = basesearchURL + 'keyword=' + keyword;
    //alert(basesearchURL + 'keyword=' + keyword);
}

function getElement(id)
{
		    if(document.all)
		    {
		        return document.all[id];
		    }
		    else if(document.getElementById)
		    {
		        return document.getElementById(id);
		    }
		    else if(document.layers)
		    {
		        return document.layers[id];
		    }
		    else
		    {
		        alert('Problem returning object[' + id + ']');
		        return null;
		    }
		}
		
function toggleElementDisplay(e)
{
    var elment;
    if (isIE)
    {
        elment = document.getElementsByName(e);
        if (elment.style.display = "none")
        {
            elment.style.display = "block";
        }
        else
        {
            elment.style.display = "none";
        }
    }
    else
    {
        elment = grabElem(e);
        if(elment.style.display = 'none')
        {
            elment.style.display = 'block';
        }
        else
        {
            elment.style.display = 'none';
        }
     }
}
		
function hideElement(e)
{

    //grabElem(e).style.display="none";
    
     var el;
    if (isIE)
    {
        el = document.getElementById(e);
        el.style.display= "none";

    }
    else
    {
        grabElem(e).style.display = "none";
    }

}

function showElement(e)
{
    var el;
    if (isIE)
    {
        el = document.getElementById(e);
         el.style.display = "block";
        //var de = document.all[e];
        //de.style.display = "block";
    }
    else
    {
        grabElem(e).style.display = "block";
    }
}

function flipElements(h,s)
{    
    showElement(s);
    hideElement(h);
}

//-------------------------------------------------------------------
// isInteger(value)
//   Returns true if value contains all digits
//-------------------------------------------------------------------
function isInteger(val)
{
	if (isBlank(val)){return false;}
	for(var i=0;i<val.length;i++){
		if(!isDigit(val.charAt(i))){return false;}
		}
	return true;
}
//-------------------------------------------------------------------
// isDigit(value)
//   Returns true if value is a 1-character digit
//-------------------------------------------------------------------
function isDigit(num) {
	if (num.length>1){return false;}
	var string="1234567890";
	if (string.indexOf(num)!=-1){return true;}
	return false;
	}
//-------------------------------------------------------------------
// setNullIfBlank(input_object)
//   Sets a form field to "" if it isBlank()
//-------------------------------------------------------------------
function setNullIfBlank(obj){if(isBlank(obj.value)){obj.value="";}}

//-------------------------------------------------------------------
// setFieldsToUpperCase(input_object)
//   Sets value of form field toUpperCase() for all fields passed
//-------------------------------------------------------------------
function setFieldsToUpperCase(){
	for(var i=0;i<arguments.length;i++) {
		arguments[i].value = arguments[i].value.toUpperCase();
		}
	}

//-------------------------------------------------------------------
// disallowBlank(input_object[,message[,true]])
//   Checks a form field for a blank value. Optionally alerts if 
//   blank and focuses
//-------------------------------------------------------------------
function disallowBlank(obj){
	var msg=(arguments.length>1)?arguments[1]:"";
	var dofocus=(arguments.length>2)?arguments[2]:false;
	if (isBlank(getInputValue(obj))){
		if(!isBlank(msg)){alert(msg);}
		if(dofocus){
			if (isArray(obj) && (typeof(obj.type)=="undefined")) {obj=obj[0];}
			if(obj.type=="text"||obj.type=="textarea"||obj.type=="password") { obj.select(); }
			obj.focus();
			}
		return true;
		}
	return false;
	}

//-------------------------------------------------------------------
// isBlank(value)
//   Returns true if value only contains spaces
//-------------------------------------------------------------------
function isBlank(val){
	if(val==null){return true;}
	for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
		}
	return true;
}

function scrollWin(x,y)
{ 
    window.scroll(x,y); 
}

function returnKey(e)
{
	var key;
	var keychar;
		
	if(window.event || !e.which) // IE
	{
		key = e.keyCode; // for IE, same as window.event.keyCode
	}
	else if(e) // netscape
	{
		key = e.which;
	}
	else
	{
		return key;
	}

	//keychar = String.fromCharCode(key);
	//keychar = keychar.toLowerCase();
	
	return key;
}

function ActivitySelection()
{
    document.forms[1].text_term.value = '';
}

function RegionSelection()
{
    document.forms[1].text_city.value = 'city or zip';
}
function CitySelection()
{
    document.forms[1].select_regions.selectedIndex = 0;
}

function onEnter(e)
{
    if (returnKey(e)  == 13)
    {
        ExecuteSearch();
    }
}
function onSearchEnter(e)
{
    if (returnKey(e)  == 13)
    {
        ExecuteBetaSearch(document.forms[1]);
        //ExecuteSearch();
    }
}

function onActivityEnter(e)
{
    if (returnKey(e)  == 13)
    {
        ExecuteActivitySearch();
    }
}

function onAccomodationsEnter(e)
{
    if (returnKey(e)  == 13)
    {
        ExecuteAccomodationsSearch();
    }
}

function onDestinationsEnter(e)
{
    if (returnKey(e)  == 13)
    {
        ExecuteDestinationsSearch();
    }
}

function onEventsEnter(e)
{
    if (returnKey(e)  == 13)
    {
        ExecuteEventsSearch();
    }
}
function onWineDineEnter(e)
{
    if (returnKey(e)  == 13)
    {
        ExecuteWineDineSearch();
    }
}

function toggleDisplay(a){
  var e=document.getElementById(a);
  if(!e)return true;
  if(e.style.display=="none"){
    e.style.display="block"
  } else {
    e.style.display="none"
  }
  return true;
}

// JScript File
function grabparam( pname )
{
  pname = pname.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+pname+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function BuildMapPointQueryString()
{
                 //Query value
                return BuildQueryStringVars(baseURL + 'GEORSS.aspx?');
}

function BuildSearchResultsQuery()
{
                 //Query value
                return BuildQueryStringVars(baseURL + 'GoogleMap.aspx?'); 
}
function ExecuteBetaSearch(varForm)
{
    var vQuery = '';
    var isDirty = false;
    
    
    if (varForm.select_region.selectedIndex >= 1) {
        vQuery += 'chapter=' + varForm.select_region.options[varForm.select_region.selectedIndex].value + '&';
    }
   
   vQuery +=  'tab=' + varForm.select_activity.value + '&';
   
//    if (varForm.select_activity.selectedIndex >= 1)
//    {
//        vQuery +=  'activity=' + varForm.select_activity.options[varForm.select_activity.selectedIndex].value + '&';
//        vQuery +=  'tab=' + varForm.select_activity.options[varForm.select_activity.selectedIndex].value + '&';
//    }
    
    if (varForm.text_city.value.length >= 1)
    {
        if (isInteger(varForm.text_city.value))
        {
        vQuery += 'zip=' + varForm.text_city.value + '&';
        }
        else
        {
        vQuery += 'city=' + varForm.text_city.value + '&';
        }
    }
    
//    if (varForm.text_term.value.length >= 1)
//    {
//        vQuery += 'keyword=' + varForm.text_term.value + '&';
//    }
    
    //Now navigate to the search page with parameters
    //alert(basesearchURL + vQuery);
    window.location =  basesearchURL + vQuery;

}

function ExecuteSearch()
{
    var vQuery = '';
    var isDirty = false;
      
    if (document.forms[1].select_region.selectedIndex >= 1)
    {
        vQuery += 'chapter=' + document.forms[1].select_region.options[document.forms[1].select_region.selectedIndex].value + '&';
    }
   
    if (document.forms[1].select_activity.selectedIndex >= 1)
    {
        vQuery +=  'activity=' + document.forms[1].select_activity.options[document.forms[1].select_activity.selectedIndex].value + '&';
        vQuery +=  'tab=' + document.forms[1].select_activity.options[document.forms[1].select_activity.selectedIndex].value + '&';
    }
    
    if (document.forms[1].text_city.value.length >= 1)
    {
        if (isInteger(document.forms[1].text_city.value))
        {
        vQuery += 'zip=' + document.forms[1].text_city.value + '&';
        }
        else
        {
        vQuery += 'city=' + document.forms[1].text_city.value + '&';
        }
    }
    
    if (document.forms[1].text_term.value.length >= 1)
    {
        vQuery += 'keyword=' + document.forms[1].text_term.value + '&';
    }
    
    //Now navigate to the search page with parameters
    window.location =  basesearchURL + vQuery;

}
function ExecuteSearchByForm(frmIndex)
{
    var vQuery = '';
    var isDirty = false;
      
    if (document.forms[frmIndex].select_region.selectedIndex >= 1)
    {
        vQuery += 'chapter=' + document.forms[1].select_region.options[document.forms[frmIndex].select_region.selectedIndex].value + '&';
    }
   
    if (document.forms[frmIndex].select_activity.selectedIndex >= 1)
    {
        vQuery +=  'activity=' + document.forms[frmIndex].select_activity.options[document.forms[frmIndex].select_activity.selectedIndex].value + '&';
        vQuery +=  'tab=' + document.forms[frmIndex].select_activity.options[document.forms[frmIndex].select_activity.selectedIndex].value + '&';
    }
    
    if (document.forms[frmIndex].text_city.value.length >= 1)
    {
        if (isInteger(document.forms[frmIndex].text_city.value))
        {
        vQuery += 'zip=' + document.forms[frmIndex].text_city.value + '&';
        }
        else
        {
        vQuery += 'city=' + document.forms[frmIndex].text_city.value + '&';
        }
    }
    
    if (document.forms[frmIndex].text_term.value.length >= 1)
    {
        vQuery += 'keyword=' + document.forms[frmIndex].text_term.value + '&';
    }
    
    //Now navigate to the search page with parameters
    window.location =  basesearchURL + vQuery;


}
function ExecuteLargeSearch()
{
    var vQuery = '';
    var isDirty = false;
    var vSelectRegion = grabElem(select_region);
    if (vSelectRegion.selectedIndex >= 1)
    {
        vQuery += 'chapter=' + vSelectRegion.options[vSelectRegion.selectedIndex].value + '&';
    }
   var vSelectActivity = grabElem(select_activity);
    if (vSelectActivity.selectedIndex >= 1)
    {
        vQuery +=  'activity=' + vSelectActivity.options[vSelectActivity.selectedIndex].value + '&';
        vQuery +=  'tab=' + vSelectActivity.options[vSelectActivity.selectedIndex].value + '&';
    }
    var vTextCity = grabElem(text_city);
    if (vTextCity.value.length >= 1)
    {
        if (isInteger(vTextCity.value))
        {
        vQuery += 'zip=' + vTextCity.value + '&';
        }
        else
        {
        vQuery += 'city=' + vTextCity.value + '&';
        }
    }
    
    var vTextTerm = grabElem(text_term);
    
    if (vTextTerm.value.length >= 1)
    {
        vQuery += 'keyword=' + vTextTerm.value + '&';
    }
    
    //Now navigate to the search page with parameters
    window.location =  basesearchURL + vQuery;


}
function ExecuteActivitySearch()
{
    var vQuery = 'tab=tabform_activity&';
    var isDirty = false;
      
    if (document.tabsearchform.select_region.selectedIndex >= 1)
    {
        vQuery += 'chapter=' + document.tabsearchform.select_region.options[document.tabsearchform.select_region.selectedIndex].value + '&';
    }
   
    if (document.tabsearchform.select_activity.selectedIndex >= 1)
    {
        vQuery +=  'activity=' + document.tabsearchform.select_activity.options[document.tabsearchform.select_activity.selectedIndex].value + '&';
        //vQuery +=  'tag=' + document.tabsearchform.select_activity.options[document.tabsearchform.select_activity.selectedIndex].value + '&';
    }
    
    if (document.tabsearchform.text_city.value.length >= 1)
    {
        if (isInteger(document.tabsearchform.text_city.value))
        {
        vQuery += 'zip=' + document.tabsearchform.text_city.value + '&';
        }
        else
        {
        vQuery += 'city=' + document.tabsearchform.text_city.value + '&';
        }
    }
    
    if (document.tabsearchform.text_term.value.length >= 1)
    {
        vQuery += 'keyword=' + document.tabsearchform.text_term.value + '&';
    }
    
    //Now navigate to the search page with parameters
    ExecuteResultsAjaxQuery("tabform_activity",vQuery);
    //window.location =  basesearchURL + vQuery;

}

function ExecuteAccomodationsSearch()
{
    var vQuery = 'tab=tabform_accomodations&';
    var isDirty = false;
      
    if (document.tabsearchform.select_region.selectedIndex >= 1)
    {
        vQuery += 'chapter=' + document.tabsearchform.select_region.options[document.tabsearchform.select_region.selectedIndex].value + '&';
    }
   
    if (document.tabsearchform.select_accomodations.selectedIndex >= 1)
    {
        vQuery +=  'accomodations=' + document.tabsearchform.select_accomodations.options[document.tabsearchform.select_accomodations.selectedIndex].value + '&';
        //vQuery +=  'tag=' + document.tabsearchform.select_accomodations.options[document.tabsearchform.select_accomodations.selectedIndex].value + '&';
    }
    
    if (document.tabsearchform.text_city.value.length >= 1)
    {
        if (isInteger(document.tabsearchform.text_city.value))
        {
        vQuery += 'zip=' + document.tabsearchform.text_city.value + '&';
        }
        else
        {
        vQuery += 'city=' + document.tabsearchform.text_city.value + '&';
        }
    }
    
    if (document.tabsearchform.text_term.value.length >= 1)
    {
        vQuery += 'keyword=' + document.tabsearchform.text_term.value + '&';
    }
    
    //Now navigate to the search page with parameters
    ExecuteResultsAjaxQuery("tabform_destinations",vQuery);
    //window.location =  basesearchURL + vQuery;

}

function ExecuteDestinationsSearch()
{
    var vQuery = 'tab=tabform_destinations&';
    var isDirty = false;
      
    if (document.tabsearchform.select_region.selectedIndex >= 1)
    {
        vQuery += 'chapter=' + document.tabsearchform.select_region.options[document.tabsearchform.select_region.selectedIndex].value + '&';
    }
    
    if (document.tabsearchform.text_city.value.length >= 1)
    {
        if (isInteger(document.tabsearchform.text_city.value))
        {
        vQuery += 'zip=' + document.tabsearchform.text_city.value + '&';
        }
        else
        {
        vQuery += 'city=' + document.tabsearchform.text_city.value + '&';
        }
    }
    
    if (document.tabsearchform.text_term.value.length >= 1)
    {
        vQuery += 'keyword=' + document.tabsearchform.text_term.value + '&';
    }
    
    //Now navigate to the search page with parameters
    ExecuteResultsAjaxQuery("tabform_destinations",vQuery);
    //window.location =  basesearchURL + vQuery;

}

function ExecuteEventsSearch()
{
    var vQuery = 'tab=tabform_events&';
    var isDirty = false;
      
    if (document.tabsearchform.select_region.selectedIndex >= 1)
    {
        vQuery += 'chapter=' + document.tabsearchform.select_region.options[document.tabsearchform.select_region.selectedIndex].value + '&';
    }
    
    if (document.tabsearchform.select_events.selectedIndex >= 1)
    {
        vQuery += 'event=' + document.tabsearchform.select_events.options[document.tabsearchform.select_events.selectedIndex].value + '&';
        //vQuery += 'tag=' + document.tabsearchform.select_events.options[document.tabsearchform.select_events.selectedIndex].value + '&';
    }
    
    if (document.tabsearchform.text_term.value.length >= 1)
    {
        vQuery += 'keyword=' + document.tabsearchform.text_term.value + '&';
    }
    
    //Need to ad event types
    
    //Now navigate to the search page with parameters
    ExecuteResultsAjaxQuery("tabform_events",vQuery);
    //window.location =  basesearchURL + vQuery;

}
function ExecuteWineDineSearch()
{
    var vQuery = 'tab=tabform_winedine&';
    var isDirty = false;

    if (document.tabsearchform.select_region.selectedIndex >= 1)
    {
        vQuery += 'chapter=' + document.tabsearchform.select_region.options[document.tabsearchform.select_region.selectedIndex].value + '&';
    }
    
    if (document.tabsearchform.text_term.value.length >= 1)
    {
        if (isInteger(document.tabsearchform.text_term.value))
        {
        vQuery += 'zip=' + document.tabsearchform.text_term.value + '&';
        }
        else
        {
        vQuery += 'keyword=' + document.tabsearchform.text_term.value + '&';
        }
    }
    
    if (document.tabsearchform.select_establishments.selectedIndex >= 1)
    {
        vQuery += 'establishment=' + document.tabsearchform.select_establishments.options[document.tabsearchform.select_establishments.selectedIndex].value + '&';
        vQuery += 'tag=' + document.tabsearchform.select_establishments.options[document.tabsearchform.select_establishments.selectedIndex].value + '&';
    }
    
    //Now navigate to the search page with parameters
    ExecuteResultsAjaxQuery("tabform_winedine",vQuery);
    //window.location =  basesearchURL + vQuery;

}


function ExecuteResultsAjaxQuery(tabname,searchcriteria)
{
    var searchurl = 'searchresults.aspx?' + searchcriteria;
    GenerateAjaxRequest('searchresults_container',searchurl);
    
}
		
function GoToSearchPage(tabname)
{

    //Pass
    var qv = BuildQueryStringVars(basesearchURL);
    qv += 'tab=' +  tabname + '&';
    qv = qv.replace("undefined','");
	window.location = qv;
}

function GotoPage(pageparams,index)
{
    var qv = basesearchURL + pageparams + '&pagenumber=' + index;
    qv = qv.replace('undefined','');
    window.location = qv;
}

function ReloadAjaxPage(pageParameters,pageIndex)
{
    var qv = pageParameters + '&pagenumber=' + pageIndex;
    qv = qv.replace('undefined','');
    ExecuteResultsAjaxQuery('tabform_activity',qv);
    initLytebox();
}

function GotoLastPage()
{

    var qv = BuildQueryStringVars(basesearchURL);
    
    //Capture the pagenumber
    if (grabparam("pagesize").length >= 1)
    {
        qv += 'pagesize=' + grabparam("pagesize") + '&';
    }

    //Capture the pagenumber
    if (grabparam("pagenumber").length >= 1)
    {
        qv += 'pagenumber=' + grabparam("pagenumber") +  '&';
    }
    window.location = qv;
}


//Generate the URL results for the ajax query
function GenerateAjaxRequest(container, url) {
			var req = false;
			// For Safari, Firefox, and other non-MS browsers
			if (window.XMLHttpRequest)
			{
			try
			{
			req = new XMLHttpRequest();
			}
			catch (e)
			{
			req = false;
			}
			}
			else if (window.ActiveXObject)
			{
			// For Internet Explorer on Windows
			try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
			try {
			req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
			req = false;
			}
			}
			}
            
			//bod = GetForm("cttcBody");
			element = document.getElementById(container);

			//element = document.getElementById();

			if (!element) {
			alert("Bad id " + container +
			"passed to clientSideInclude." +
			"You need a div or span element " +
			"with this id in your page.");
			return;
			}

			if (req) {
				// Synchronous request, wait till we have it all
				req.open('GET', url, false);
				req.send(null);
				element.innerHTML = req.responseText;
			} else {
				element.innerHTML =
					"Sorry, your browser does not support " +
					"XMLHTTPRequest objects. This page requires " +
					"Internet Explorer 5 or better for Windows, " +
					"or Firefox for any system, or Safari. Other " +
					"compatible browsers may also exist.";
			}
			req.open('GET', "/modules/scripts/lytebox_source.js", false);
			req.send(null);
            initLytebox();
			
}



function BuildQueryStringVars(baseURL)
{
                 //Query value
                var qv =  baseURL;

                //Capture tab
                if (grabparam("tab").length >= 1)
                {
                qv += 'tab=' + grabparam("tab") + '&';
                }
                
                //Capture city name
                if (grabparam("chapter").length >= 1)
                {
                qv += 'chapter=' + grabparam("chapter") + '&';
                }
                
                //Capture city name
                if (grabparam("city").length >= 1)
                {
                qv += 'city=' + grabparam("city") + '&';
                }
                
                //Capture zip code
                if (grabparam("zip").length >= 1)
                {
                qv += 'zip=' + grabparam("zip") + '&';
                } 
                
                //Capture tag     
                
                if (grabparam("activity").length >= 1)
                {
                qv += 'activity=' + grabparam("activity") + '&';
                }
                    
                if (grabparam("tag").length >= 1)
                {
                qv += 'tag=' + grabparam("tag") + '&';
                }

                if (grabparam("keyword").length >= 1 && grabparam("keyword") != 'keyword&')
                {
                qv += 'keyword=' + grabparam("keyword") + '&';
                }
                
                //Capture term
                if (grabparam("term").length >= 1 && grabparam("keyword") != 'keyword')
                {
                qv += 'keyword=' + grabparam("term") +  '&';
                }
                
                //Capture the pagenumber
                if (grabparam("pagesize").length >= 1)
                {
                qv += 'pagesize=' + grabparam("pagesize") +  '&';
                }
                
                //Capture the pagenumber
                if (grabparam("pagenumber").length >= 1)
                {
                qv += 'pagenumber=' + grabparam("pagenumber") +  '&';
                }
                
                //alert(qv);
                return qv;
}