// PAGE ELEMENTS file
// builds a few page items
// copyrighted under CC Attribution License (see legal.php for more info)
var $hold_submenu = 0;
function show_submenu($id) // 4.1
{
	$sm = document.getElementById('sub_'+$id);
	$sm.style.visibility = "visible";
	$nav = document.getElementById('snb');
	if ($nav != undefined) $nav.style.visibility = "hidden";
	$o = document.fnavbar.menuopen.value
	document.fnavbar.menuopen.value = $o+$id+"*"
}
function hide_submenu()
{
	$hold_submenu = 0;
	setTimeout("close_all_subs()",1000);
	setTimeout("$menuclose=0",4000)
}
function hold_submenu()
{
	$hold_submenu=1;
}
function close_all_subs()
{
	var $menu = document.fnavbar.menuopen.value.split('*');
	if ($hold_submenu == 0)
	{
		for ($s=0; $s<=$menu.length; ++$s)
		{
			$sm = document.getElementById('sub_'+$menu[$s]);
			if ($sm != undefined) $sm.style.visibility = "hidden";
		}
		document.fnavbar.menuopen.value = "";
		$nav = document.getElementById('snb');
		if ($nav != undefined) 	$nav.style.visibility = "visible";
	}
}
function email_me()
{
	var m1="mai";			var m2="lto:"
	var me="tirdun";		var y="yahoo";
	var at="@";			var dc=".com";
	document.location.href = m1+m2+me+at+y+dc;
}
function show_subnav($indexlist)
{
	$buildindex = $indexlist.split(',');
	$returntext = '<div id="snb" class="subnavbar ct">';
	for ($i=0; $i<$buildindex.length; $i=$i+2)
	{
		$returntext += '<a href="#'+$buildindex[$i]+'" class="indexlink nobreak">'+$buildindex[$i+1]+'</a>';
		if (($i+2) < $buildindex.length) $returntext += ' <span class="subnav_divider">&middot;</span> '; 
	}
	$returntext += '</div>'
	document.write($returntext);
}
function sort_table($x,$y,$z)
{
	var $vararray = new Array();
	var $geturl = parent.location.href;
	var $startbreak=$geturl.indexOf('.php');
	var $splithref = $geturl.substring(0,$startbreak).split('/');
	var $thispage = $splithref[($splithref.length-1)]+'.php';
	var $breakpage = $geturl.indexOf($thispage);
	var $fullpage = $geturl.substring($breakpage,$geturl.length);
	if ($geturl.indexOf('sortby') > -1) // There are already vals after the page
	{
		$repsort = $fullpage.indexOf('sortby=');
		$newpage = $fullpage.substring(0,$repsort);
		$newpage += "&sortby="+$y;
		if ($z != undefined) $newpage += "&dir="+$z;
	} else {
		if ($geturl.indexOf("?") > -1)
		{
			$newpage = $fullpage+"&sortby="+$y;
			if ($z != undefined) $newpage += "&dir="+$z;
		} else {
			$newpage = $fullpage+"?sortby="+$y;
			if ($z != undefined) $newpage += "&dir="+$z;
		}
	}
	document.location.href = $newpage;
}
function get_drink($l,$t)
{
	document.write('<a href="whisky.php?show=whisky&id='+$l+'" class="whisky">'+$t+'</a>');
}
function show_icons()
{
	newwindow=window.open('iconsheet.php','iconwindow','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=400,height=400');
	newwindow.focus;

}
function show_disclaimer()
{
	var d = document.getElementById('disclaimer_out');
	d.style.display = "block";
}
function add_comment()
{
	var n = document.pwcomm.comment_name.value.toLowerCase();
	var c = document.pwcomm.comment_body.value.toLowerCase();
	if ((trim(n) != '') && (trim(c) != ''))
	{
		var pwcookie = document.cookie
		if ((!pwcookie) || (pwcookie=='pw_comm_cookie=none'))
		{
			show_disclaimer();
		}
		else
		{
			var linkcheck = 0;
			// var commstr = document.pwcomm.comment_body.value.toLowerCase()
			if (c.indexOf("a href") >=0) ++linkcheck;
			if (c.indexOf("[url =") >=0) ++linkcheck;
			if (c.indexOf("[link =") >=0) ++linkcheck;
			if (n.indexOf("a href") >=0) ++linkcheck;
			if (n.indexOf("[url =") >=0) ++linkcheck;
			if (n.indexOf("[link =") >=0) ++linkcheck;
			if (linkcheck == 0)
			{
				set_cookie();
				document.pwcomm.submit();
			} else {alert("Post cannot contain links")};	
		}
	}
	else 
	{
		alert("Cannot submit, missing required fields");
	}
}
function set_cookie()
{
	var deficon = document.pwcomm.comment_icon.value;
	var defname = document.pwcomm.comment_name.value;
	var xdate = new Date();
	xdate.setTime(xdate.getTime()+(730*24*60*60*1000));
	document.cookie =  'pw_comm_cookie=setcommcookie:'+defname+':'+deficon+';expires='+xdate.toGMTString()+' UTC; path=/'
}
function kill_cookie()
{
	document.cookie =  'pw_comm_cookie=none;-1;UTC; path=/'
}
function agree(gn)
{

	if (gn == "yes")
	{
		set_cookie();
	 	add_comment();
	} else {
		kill_cookie();
	}
	var d = document.getElementById('disclaimer_out');
	d.style.display = "none";
}
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}
function show_tip()
{
	alert("- Posts are not filtered for content as long as it's relevant to the whisky.\n- Page links are forbidden.\n- If you want to link internally to a whisky, use [[ID#,text]] as in [[1,Springbank!]].\n- Try not to get too fancy on internal links.\n- Enjoy");
}
function bottle_picker()
{
	$t = document.bp.type.value;
	$c = document.bp.cost.value;
	document.location.href = "whisky.php?show=pick&type="+$t+"&cost="+$c;
}
function setbottle($t,$c)
{
	document.bp.type.value = $t;
	document.bp.cost.value = $c;
}