function getCookie(name, allcookies) {
	name += "=";
	var pos = allcookies.indexOf(name);
	if (pos == -1) return false;
	var start = pos + name.length;
	var end = allcookies.indexOf(";", start);
	if (end == -1) end = allcookies.length;
	var value = allcookies.substring(start, end);
	return unescape(value);
}

function getTagIdx(section, tagStr) {
	if (!tagStr || tagStr.length < 8) {
		return 0;
	}	else {
		return tagStr.charAt(section);
	}
}

function launchArtscape(collectionlist, root) {
	if (!root) root = '../';
	var url = root + 'artscape/index.php'
	if (collectionlist) url += "?collections=" + collectionlist;
	openArtscapeWindow(url);
	return false;
}
launchArtlinks = launchArtscape;

function launchArtscapeFromConnections(collectionlist) {
	launchArtscape(collectionlist);
	window.close();
}

function loadArtscapeSet(setid, root) {
	if (!root) root = '../';
	var url = root + 'artscape/index.php'
	if (setid) url += "?setID=" + setid;
	openArtscapeWindow(url);
	return false;
}

function searchArtscape(root) {
	if (!root) root = '../';
	var keywords = "";
	if (document.gs && document.gs.q && document.gs.q.value && document.gs.q.value != "") {
		keywords = document.gs.q.value;
	} 
	var url = root + 'artscape/index.php?keywords=' + escape(keywords);
	openArtscapeWindow(url);
	return false;
}

searchArtlinks = searchArtscape;

function openArtscapeWindow(url) {
	if (window.screen && window.screen.width && window.screen.width <= 800) {
		artscapeWindow = window.open(url,'artscape','width=790,height=565,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes');
	} else {	
		artscapeWindow = window.open(url,'artscape','width=883,height=732,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0');
	}
	artscapeWindow.focus();
}

function launchConnections() {
	connectionsWindow = window.open('../connections/connections.php','connections','width=730,height=450,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0');
	connectionsWindow.focus();
	return false;
}

function buyAmazon(URL,NAME) {
amznwin=window.open(URL,NAME,'location=yes,scrollbars=yes,status=yes,toolbar=yes,resizable=yes,width=380,height=450,screenX=10,screenY=10,top=10,left=10');
amznwin.focus();}

function launchExperience() {
	document.location="../visit/";
}

function swapImage(strElement, objImage) {	
// this function swaps the image identified by strElement for a new one preloaded as objImage
	if (document.images && objImage && objImage.src && objImage.src != "") {
		if (document.images[strElement]) {
			document.images[strElement].src = objImage.src;
		}
	}
}

