$(document).ready(function () {
    var switchLink = window.location.toString();
    if (switchLink.indexOf('http') >= 0) {
        switchLink = switchLink.replace('http://', '');
        switchLink = switchLink.replace('https://', '');
        switchLink = switchLink.substring(switchLink.indexOf('/'), switchLink.length);
    }
    switch (switchLink) {
        case '/where-to-stay/': case '/what-to-do/': case '/what-to-see/': case '/where-to-eat/': case '/make-plans/':
            switchLink = '/#' + switchLink;
            break;
    }
    $('.OurMobileSite').attr('href', switchLink);
    $('.OurMobileSite').click(function () {
        var cookieDate = new Date('01/18/2038');
        setCookie('mobile', 'true', cookieDate, '/');
    });
});

function setCookie(name, value, expires_date, path, domain, secure) {
    document.cookie = name + "=" + escape(value) +
	((expires_date) ? ";expires=" + expires_date.toGMTString() : "") +
	((path) ? ";path=" + path : "") +
	((domain) ? ";domain=" + domain : "") +
	((secure) ? ";secure" : "");
}
function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

var popwin;

function popwindow(url, height, width) {

	var name = "form" ;
	var str = "height=" + height + ",innerHeight=" + height ;
	var strn = "'toolbar=no,scrollbars=no,resizable=no'" ;
	str += ",width=" + width + ",innerWidth=" + width ;

	if ( window.screen ) {
		var ah = screen.availHeight - 30 ;
		var aw = screen.availWidth - 10 ;
		var xc = ( aw - width ) / 2 ;
		var yc = ( ah - height ) / 2 ;
	
		str += ",left=" + xc + ",screenX=" + xc ;
		str += ",top=" + yc + ",screenY=" + yc ;
	}       
	popwin = window.open( url, name, str, strn) ;
}

function Debug(str,showDebug) {
    if (showDebug) {
        var DebugConsoleID = "debugconsole";
        var DebugConsole = getElement(DebugConsoleID);
        var iframe = getElement("iframe");
        if (!DebugConsole) {
            DebugConsole = document.createElement('textarea');
            DebugConsole.setAttribute('id', DebugConsoleID);
            DebugConsole.setAttribute('style', 'width:98%;height:400px;margin:5px;');
            DebugConsole.innerHTML = 'console created\n';
            if (iframe) {
                iframe.appendChild(DebugConsole);
            }
            else {
                document.body.appendChild(DebugConsole);
            }
        }
        if (DebugConsole) {
            DebugConsole.innerHTML += str + '\n';
            DebugConsole.scrollTop = DebugConsole.scrollHeight;
        }
        else {
            alert(str);
        }
    }
}

function searchSubmit(name){
    var keywords = getElement(name);
    var returnFalse = false;
	if(keywords){
	    if (!keywords.value || keywords.value == '' || keywords.value == 'Search') {
	        returnFalse = true;
		}
	}
	else{
	    returnFalse = true;
	}
	if (returnFalse) {
	    alert('Please enter a search term.');
	    var searchBox = getElement('searchkeywords');
	    if (searchBox) {
	        searchBox.focus();
	        searchBox.text = '';
	    }
	    return false;
	}
}

function searchFocus(o) {
	if (o.value == "Search") { o.value = ""; }
	else if (o.value == "") { o.value = "Search"; }
}

function jssearch(value) {
	if (value != "" && value != "Search") {
		location.href = "/search/?searchkeywords=" + escape(value);
	}
}

function entersearch(value, e) {
	var KeyID = (window.event) ? event.keyCode : e.keyCode;
	if (KeyID == 13 && value != "" && value != "Search") { jssearch(value); }
}

function getElement(name) {
	var o1 = null;
	if(document.all) {
		o1 = document.all(name);
	}
	else if(document.getElementById) {
		o1 = document.getElementById(name);
	}
	return o1;
}
function showElement(name,displaytype) {
	if(displaytype==undefined){displaytype='';}
	var o1 = null;
	if(document.all) {
		o1 = document.all(name);
	}
	else if(document.getElementById) {
		o1 = document.getElementById(name);
	}
	if(o1!=null) {
		o1.style.display = displaytype;
	}
}
function hideElement(name) {
	var o1 = null;
	if(document.all) {
		o1 = document.all(name);
	}
	else if(document.getElementById) {
		o1 = document.getElementById(name);
	}
	if(o1!=null) {
		o1.style.display = "none";
	}
}
function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
function TACFeaturedEvent(CurrentPage,PageCount,NextOrPrev){
	
	alert("CurrentPage = " + CurrentPage);
	
	var NextPage;
	var PrevPage;
	
	if(getElement("FeaturedEvent" + (CurrentPage + 1))){
		NextPage = CurrentPage + 1;
	}
	else{
		NextPage = 1;	
	}
	
	if(getElement("FeaturedEvent" + (CurrentPage - 1))){
		PrevPage = CurrentPage - 1;
	}
	else{
		PrevPage = PageCount;
	}	
	
	switch(NextOrPrev)
	{
		case "next":
		{
			alert("show " + NextPage);
			hideElement("FeaturedEvent" + CurrentPage);
			showElement("FeaturedEvent" + NextPage);
			break;
		}
		case "prev":
		{
			alert("show " + PrevPage);
			hideElement("FeaturedEvent" + CurrentPage);
			showElement("FeaturedEvent" + PrevPage);
			break;
		}
	}	
}








