 /* needed because CSS hover doesn't work on touch screens */
function showmenu(menuitem){
    var submenus=document.getElementById(menuitem).getElementsByTagName('ul');
    if (submenus[0].style.display=="block") {
        submenus[0].style.display="";   /* now the pseudoclass hover in stylesheet again applies */
    } else {
    	submenus[0].style.display="block";
    } 
}

function rememberSettings () {	
	colourStart=document.cookie.indexOf('ywsColour' + '=');
	backgroundStart=document.cookie.indexOf('ywsBackground' + '=');
	fontStart=document.cookie.indexOf('ywsFont' + '=');
	fontSizeStart=document.cookie.indexOf('ywsFontSize' + '=');
		
	if (colourStart!=-1) {
		colourValueStart=colourStart + 10;
		colourValueEnd=document.cookie.indexOf(";",colourValueStart);
	    if (colourValueEnd==-1) {
	    	colourValueEnd=document.cookie.length;
	    }
	    if (document.styleSheets[0].cssRules) {
	    	document.styleSheets[0].cssRules[1].style.color=unescape(document.cookie.substring(colourValueStart,colourValueEnd));
		} else {
			if (document.styleSheets[0].rules) {
				document.styleSheets[0].rules[1].style.color=unescape(document.cookie.substring(colourValueStart,colourValueEnd));
			} else {
				alert('Sorry your browser doesn\'t seem to like JavaScript or JScript');
			}
		}	    
  	}
	if (backgroundStart!=-1) {
		backgroundValueStart=backgroundStart + 14;
		backgroundValueEnd=document.cookie.indexOf(";",backgroundValueStart);
	    if (backgroundValueEnd==-1) {
	    	backgroundValueEnd=document.cookie.length;
	    }
	    if (document.styleSheets[0].cssRules) {
	    	document.styleSheets[0].cssRules[1].style.backgroundColor=unescape(document.cookie.substring(backgroundValueStart,backgroundValueEnd));
		} else {
			if (document.styleSheets[0].rules) {
				document.styleSheets[0].rules[1].style.backgroundColor=unescape(document.cookie.substring(backgroundValueStart,backgroundValueEnd));
			} else {
				alert('Sorry your browser doesn\'t seem to like JavaScript or JScript');
			}
		}
	    
  	}
	if (fontStart!=-1) {
		fontValueStart=fontStart + 8;
		fontValueEnd=document.cookie.indexOf(";",fontValueStart);
	    if (fontValueEnd==-1) {
	    	fontValueEnd=document.cookie.length;
	    }
	    if (document.styleSheets[0].cssRules) {
	    	ddocument.styleSheets[0].cssRules[1].style.fontFamily=unescape(document.cookie.substring(fontValueStart,fontValueEnd));
		} else {
			if (document.styleSheets[0].rules) {
				document.styleSheets[0].rules[1].style.fontFamily=unescape(document.cookie.substring(fontValueStart,fontValueEnd));
			} else {
				alert('Sorry your browser doesn\'t seem to like JavaScript or JScript');
			}
		}
	    
  	}
	if (fontSizeStart!=-1) {
		fontSizeValueStart=fontSizeStart + 12;
		fontSizeValueEnd=document.cookie.indexOf(";",fontSizeValueStart);
	    if (fontSizeValueEnd==-1) {
	    	fontSizeValueEnd=document.cookie.length;
	    }
	    if (document.styleSheets[0].cssRules) {
	    	document.styleSheets[0].cssRules[1].style.fontSize=unescape(document.cookie.substring(fontSizeValueStart,fontSizeValueEnd));
		} else {
			if (document.styleSheets[0].rules) {
				document.styleSheets[0].rules[1].style.fontSize=unescape(document.cookie.substring(fontSizeValueStart,fontSizeValueEnd));
			} else {
				alert('Sorry your browser doesn\'t seem to like JavaScript or JScript');
			}
		}
	    
  	}
}

function setCookie (cookieName, cookieContent) {
	var expiry=new Date();
	expiry.setDate(expiry.getDate()+31);
	document.cookie=cookieName+ '=' +escape(cookieContent)+	';expires='+expiry.toUTCString();
}

function changeColour (colour) {
		
	if (document.styleSheets[0].cssRules) {
		document.styleSheets[0].cssRules[1].style.color=colour;
	} else {
		if (document.styleSheets[0].rules) {
			document.styleSheets[0].rules[1].style.color=colour;
		} else {
			alert('Sorry your browser doesn\'t seem to like JavaScript or JScript');
		}
	}
	setCookie('ywsColour', colour);
}

function changeBackground (colour) {
	if (document.styleSheets[0].cssRules) {
		document.styleSheets[0].cssRules[1].style.backgroundColor=colour;
	} else {
		if (document.styleSheets[0].rules) {
			document.styleSheets[0].rules[1].style.backgroundColor=colour
		} else {
			alert('Sorry your browser doesn\'t seem to like JavaScript or JScript');
		}
	}	
	setCookie('ywsBackground', colour);
}

function changeFont (font) {
	if (document.styleSheets[0].cssRules) {
		document.styleSheets[0].cssRules[1].style.fontFamily=font;
	} else {
		if (document.styleSheets[0].rules) {
			document.styleSheets[0].rules[1].style.fontFamily=font;
		} else {
			alert('Sorry your browser doesn\'t seem to like JavaScript or JScript');
		}
	}
	
	setCookie('ywsFont', font);
}

function changeFontSize (size) {
	if (document.styleSheets[0].cssRules) {
		document.styleSheets[0].cssRules[1].style.fontSize=size;
	} else {
		if (document.styleSheets[0].rules) {
			document.styleSheets[0].rules[1].style.fontSize=size;
		} else {
			alert('Sorry your browser doesn\'t seem to like JavaScript or JScript');
		}
	}
	
	setCookie('ywsFontSize', size);
}

function resetAppearance () {
	document.cookie = 'ywsColour =; expires=Thu, 01-Jan-70 00:00:01 GMT;';
	document.cookie = 'ywsBackground =; expires=Thu, 01-Jan-70 00:00:01 GMT;';
	document.cookie = 'ywsFont =; expires=Thu, 01-Jan-70 00:00:01 GMT;';
	document.cookie = 'ywsFontSize =; expires=Thu, 01-Jan-70 00:00:01 GMT;';
	document.location.reload();
}
