// JavaScript Document
function popWin(theURL,winName,features) {

	window.open(theURL,winName,features);

}

function toggleBox(box) {

	elm = document.getElementById(box);
	
	if (elm.style.display == 'none') {
		elm.style.display = '';
	} else {
		elm.style.display = 'none';
	}

}

var timer;

function showSubMenu(menu) {
	clearTimeout(timer);
	hideAllSubMenus();
	var elm = document.getElementById(menu);
	elm.style.display = '';
}

function keepAlive() {
	clearTimeout(timer);	
}

function hideSubMenu(menu) {
	clearTimeout(timer);
	var elm = document.getElementById(menu);
	elm.style.display = 'none';
}

function hideAllSubMenus() {
	document.getElementById("fSub").style.display = 'none';
	document.getElementById("cSub").style.display = 'none';
}

function startTimeout(menu, tolen) {
	timer = setTimeout("hideSubMenu('"+menu+"')", tolen);
}

function dynamicSelect(id1, id2) {
	// Feature test to see if there is enough W3C DOM support
	if (document.getElementById && document.getElementsByTagName) {
		// Obtain references to both select boxes
		var sel1 = document.getElementById(id1);
		var sel2 = document.getElementById(id2);
		// Clone the dynamic select box
		var clone = sel2.cloneNode(true);
		var clone2 = document.getElementById("location").cloneNode(true);
		// Obtain references to all cloned options 
		var clonedOptions = clone.getElementsByTagName("option");
		var clonedOptions2 = clone2.getElementsByTagName("option");
		// Onload init: call a generic function to display the related options in the dynamic select box
		refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
		// Onchange of the main select box: call a generic function to display the related options in the dynamic select box
		sel1.onchange = function() {
			refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
			if (id1 == "region") {
				refreshDynamicSelectOptions(document.getElementById("sub_area"), document.getElementById("location"), clonedOptions2);
			}
		};
	}
}

function refreshDynamicSelectOptions(sel1, sel2, clonedOptions) {
	// Delete all options of the dynamic select box
	while (sel2.options.length) {
		sel2.remove(0);
	}
	// Create regular expression objects for "select" and the value of the selected option of the main select box as class names
	var pattern1 = /( |^)(select)( |$)/;
	var pattern2 = new RegExp("( |^)(" + sel1.options[sel1.selectedIndex].value + ")( |$)");
	// Iterate through all cloned options
	for (var i = 0; i < clonedOptions.length; i++) {
		// If the classname of a cloned option either equals "select" or equals the value of the selected option of the main select box
		if (clonedOptions[i].className.match(pattern1) || clonedOptions[i].className.match(pattern2)) {
			// Clone the option from the hidden option pool and append it to the dynamic select box
			sel2.appendChild(clonedOptions[i].cloneNode(true));
		}
	}
}

function changeForecast() {
	var forecast = document.getElementById("location").value;
	if (forecast != "select") {
		window.location = "http://www.swellinfo.com/surf-forecast/" + forecast + ".html";
	}
}
function changeForecastHome() {
	var forecast = document.getElementById("location_home").value;
	if (forecast != "select") {
		window.location = "http://www.swellinfo.com/surf-forecast/" + forecast + ".html";
	}
}

function surfob_on(id) {
	var ob = "userob"+id;
	var elm = document.getElementById(ob);
	elm.style.display = '';
}

function surfob_off(id) {
	var ob = "userob"+id;
	var elm = document.getElementById(ob);
	elm.style.display = 'none';
}

// Set the cookie

function Set_Cookie( name, value, expires, path, domain, secure ) {
	
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	
	// if the expires variable is set, make sure the correct
	// expires time, the current script below will set
	// it for x number of days, to make it for hours, 
	// delete * 24, for minutes delete 60 * 24
	
	
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) + ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + ( ( path ) ? ";path=" + path : "" ) + ( ( secure ) ? ";secure" : "" );

}

// Get the cookie
function Get_Cookie( name ) {

	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	
	if (start == -1) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end) );
}


function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" + ( ( path ) ? ";path=" + path : "") + ( ( domain ) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

google_ad_client = "pub-4783050002642937";
google_ad_width = 468; 
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
google_ad_channel ="";
google_color_border = ["336699","177497"];
google_color_link = ["0000FF","3D81EE"]; 
google_color_bg = ["FDFDDA","DBE4EA"];
google_color_text = ["000000","000000"];
google_color_url = ["008000","CC0000"];