// look for section and item from a string in URL format and fire up scrollTo() if they exist
function readUrl(searchString){
	var section = '';
	var item = '';
	var scroll = '';

	// strip off the leading '?'
	searchString = searchString.substring(1);
	// add to array
	var urlVars = searchString.split("&");
	//loop through array
	for (i = 0; i < urlVars.length; i++)
	{
		//find 'sec' element, set display to block
		if (urlVars[i].search('sec') != -1){
			var sec = urlVars[i].split('=');
			section = document.getElementById(sec[1]);
			if (section.style.display != 'block')
				section.style.display = 'block';
		}
		//find 'item' element
		if (urlVars[i].search('item') != -1){
			var it = urlVars[i].split('=');
			item = document.getElementById(it[1]);
		}
		//find 'scroll' value
		if (urlVars[i].search('scroll') != -1){
			var sc = urlVars[i].split('=');
			scroll = sc[1];
		}
	}
	if (section || item || scroll)
		scrollToItem(section,item,scroll);
}

//scroll to 'item' if exists, otherwise to 'section'
function scrollToItem(section,item,scroll){
	if (section != '' || item != '' || scroll != ''){
		if (item){
			window.scrollTo(0,item.offsetTop - 120);
			item.style.backgroundImage = 'url(images/plate_darker_bg.jpg)';
		}
		else{
			if (scroll)
				window.scrollTo(0,scroll);
			else
				window.scrollTo(0,section.offsetTop - 100);
		}
	}
}

// get the cross-browser scroll position
function getScroll(){
	var scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
	}
	else if( document.body && ( document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
	}
	else if( document.documentElement && ( document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
	}
	return scrOfY;
}

// set a cookie 'c_name' with 'value' to expire 'expiredays' from now
function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

// return the value of cookie 'c_name'
function getCookie(c_name){
	if (document.cookie.length>0){
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1){
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
				return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

// delete cookie 'c_name' by setting it to having expired
function deleteCookie(c_name){
	var cookie_date = new Date ( );  // current date & time
	cookie_date.setTime ( cookie_date.getTime() - 1 );
	document.cookie = c_name += "=; expires=" + cookie_date.toGMTString();
}
