/**
* create resuable drop-down select object
*/
var selectAndGo = {
	jumpTo:function() {
		var id = this.id
		var element = YAHOO.util.Dom.get(id);
		var choice = element.selectedIndex;
		var url = element.options[choice].value;
		document.location.href = url;
	}
}

/**
 * for use with the county/town select box
 */
var townSelectAndGo = {
    jumpTo:function() {
        var id = this.id
        var element = YAHOO.util.Dom.get(id);
        var choice = element.selectedIndex;
        var url = element.options[choice].value;
        if (url.match(/attraction-([0-9]+?)-(.*?)$/)) {
          var matches = url.match(/(.*?)\/attraction-([0-9]+)-(.*?)$/);
          document.location.href = matches[1] + '/places-to-go/' + matches[2] + '/' + matches[3];
        } else {
          document.location.href = url;
        }
    }
}

/** 
 * Expects a form input text element and resets that elements value property
 */
function clearText(element)
{
  element.value = '';
}


/**
* General in-page map functions
*/
function showHideEl(id, link, show_text, hide_text) {
    var el = document.getElementById(id);
    if (!el) {
        return;
    }
    if ("none" == el.style.display) {
        el.style.display = "block";
        link.innerHTML = hide_text;
    } else {
        el.style.display = "none";
        link.innerHTML = show_text;
    }
    link.blur();
}

function showHideMap(link, prefix) {
    var map = document.getElementById(prefix + "mapiframe");
    if ("View " + prefix +"map" == link.innerHTML && updated_map) {
        map.src = original_map;
        updated_map = false;
    }
    showHideEl(prefix + "map", link, "View "+prefix+" map", "Hide "+prefix+" map");
}
// used to keep original map
var updated_map = false;
var original_map = '';

function updateMapLink(link, prefix) {
    var map = document.getElementById(prefix+"mapiframe");
    if (!updated_map) {
        original_map = map.src;
        updated_map = true;
    }
    map.src = link;
    var hider = document.getElementById(prefix+"mapshow");
    hider.innerHTML = "Hide "+prefix+" map";
    hider.focus();
    hider.blur();
    map.parentNode.style.display = "block";
}

// Cookie management functions (from quirksmode)
function createCookie(name,value,days, path) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path="+path;
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function eraseCookie(name, path) {
    createCookie(name,"",-1);
}
