// JavaScript Document
var footerOverride = false;


function getElementsByClassName(classname, node)  {
    if(!node) node = document.getElementsByTagName("body")[0];
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}

function show(id) {
	if (document.getElementById) {
		var d = document.getElementById("smenu"+id);
		
		for (var i = 2; i<=10; i++) {
			if (document.getElementById("smenu"+i)) {
				document.getElementById("smenu"+i).style.display='none';
				document.getElementById("plusminus"+i).innerHTML="+";
				}
			}
			
		if (d) {
			d.style.display="block";
			document.getElementById("plusminus"+id).innerHTML="-";
		}
	}
}

function addStylesheet() {
	var mycodes = document.getElementById("stylecode").innerHTML.toLowerCase();
	if (mycodes.indexOf("narrow") > 0) { 
		if (document.getElementById) {
			var l=document.createElementNS("http://www.w3.org/1999/xhtml","link");
			l.setAttribute("rel", "stylesheet");
			l.setAttribute("type", "text/css");
			l.setAttribute("href", "includes/SC_narrow.css");
			l.setAttribute("media", "screen");
			document.getElementsByTagName("head")[0].appendChild(l);
		}
	}
	if (mycodes.indexOf("plainh2") > 0) { 
		if (document.getElementById) {
			var l=document.createElementNS("http://www.w3.org/1999/xhtml","link");
			l.setAttribute("rel", "stylesheet");
			l.setAttribute("type", "text/css");
			l.setAttribute("href", "includes/SC_plainH2.css");
			l.setAttribute("media", "screen");
			document.getElementsByTagName("head")[0].appendChild(l);
		}
	}
	if (mycodes.indexOf("salzburg") > 0) { 
		if (document.getElementById) {
			document.getElementById("footer").style.backgroundImage = 'url("images/footer_cityscape7.jpg")';
			footerOverride = true;
		}
	}
	if (mycodes.indexOf("kyoto") > 0) { 
		if (document.getElementById) {
			document.getElementById("footer").style.backgroundImage = 'url("images/footer_cityscape9.jpg")';
			footerOverride = true;
		}
	}
	if (mycodes.indexOf("macau") > 0) { 
		if (document.getElementById) {
			document.getElementById("footer").style.backgroundImage = 'url("images/footer_cityscape10.jpg")';
			footerOverride = true;
		}
	}
	if (mycodes.indexOf("wales") > 0) { 
		if (document.getElementById) {
			document.getElementById("footer").style.backgroundImage = 'url("images/footer_cityscape11.jpg")';
			footerOverride = true;
		}
	}
	if (mycodes.indexOf("forest") > 0) { 
		if (document.getElementById) {
			document.getElementById("footer").style.backgroundImage = 'url("images/footer_cityscape12.jpg")';
			footerOverride = true;
		}
	}
	if (mycodes.indexOf("sushi") > 0) { 
		if (document.getElementById) {
			document.getElementById("footer").style.backgroundImage = 'url("images/footer_sushi.jpg")';
			footerOverride = true;
		}
	}
}

function cookieLinks_init() {	
	var AO = document.getElementById('AO_Link');
	var DA = document.getElementById('DA_Link');
	
	// If these links exist, customize them to match the cookie setting with makeLink()
	
	if (AO) {
		var ALink = makeLink('ApplyOnline');
		if (ALink) {
			AO.href = ALink;
		}
	}
	if (DA) {
		var DLink = makeLink('DownloadApplication');
		if (DLink) {
			DA.href = DLink;
		}
	}		
}
// This function is called when the page is loaded.
function init() {
	show();	 //Collapse the expanded menu
	addStylesheet();   //Read style codes and apply sheets
	// Check for cookie-controlled links
	cookieLinks_init();
}
