
var root;

//var root = "/dcfc/html_andy/";
//var root = "/dev/";

var win;

function windowOpen(url,attributes) {
	attributes += ',resizable=yes,scrollbars=yes,menubar=no,toolbar=no';
	window.open(root+url, null, attributes);
}

function clearField (field_id) {
	var f = document.getElementById(field_id);
	f.value = '';
}

function openAudioPlayer() {
	createCookie("audioplayerOpen", 1, 0);
	win = window.open(root+"audioplayer.php", null, "width=250,height=150,menubar=no,toolbar=no,top=100,left=200,location=no,resizable=no,scrollbars=no");
}

// @ starting_point is the place the song is up to in milliseconds
function popAudioPlayer(starting_point, current_song) {
	createCookie("audioplayerOpen", 1, 0);
	win = window.open(root+"audioplayer.php?starting_point="+starting_point+"&autoplay&current_song="+current_song, null, "width=250,height=150,menubar=no,toolbar=no,top=100,left=200,location=no,resizable=no,scrollbars=no");
}

function closeWindow() {
	eraseCookie("audioplayerOpen");
	window.close();
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function toggleVisibility(obj) {
	var el = document.getElementById(obj);
	el.style.display = (el.style.display != 'none' ? 'none' : '' );
}
