/*======================================================================*\
|| Standard Javascript functions used in LDM                              ||
\*======================================================================*/

function ldm_show(object, k, n) {
	for (var i=1; i <= n; i++) {
		obj = fetch_object(object+i);
		if (i==k) {
			obj.style.display = '';
		}
		else {
			obj.style.display = 'none';
		}
	}
}

function ldm_textLimit(field, maxlen) {
	if (field.value.length > maxlen) {
		field.value = field.value.substring(0, maxlen);
	}
}

function ldm_textDOI(field) {
	field.value = field.value.replace(/[^a-zA-Z0-9-_]+/g, "");
}

/*
function ldm_popup(URL) {
	window.open(URL, 'player', 'width=$links_defaults[musicbox_standalone_width],height=$links_defaults[musicbox_standalone_height],toolbar=no,personalbar=no,location=no,directories=no,statusbar=no,menubar=no,status=no,resizable=yes,left=60,screenX=60,top=100,screenY=100');
}
*/

var childW = null;

var musicbox_standalone_width = '400px';
var musicbox_standalone_height = '255px';

/*
function ldm_popup(URL) {
	childW = window.open(URL, 'player', 'width=$links_defaults[musicbox_standalone_width],height=$links_defaults[musicbox_standalone_height],toolbar=no,personalbar=no,location=no,directories=no,statusbar=no,menubar=no,status=no,resizable=yes,left=60,screenX=60,top=100,screenY=100');
}
*/

function openPlayer(URL) {
	childW = window.open(URL, 'player', 'width='+musicbox_standalone_width+',height='+musicbox_standalone_height+',toolbar=no,personalbar=no,location=no,directories=no,statusbar=yes,menubar=no,status=yes,resizable=yes,left=60,screenX=60,top=100,screenY=100');
}

/*
function ldm_popup(URL) {
	childW = window.open(URL, 'player', 'width=$links_defaults[musicbox_standalone_width],height=$links_defaults[musicbox_standalone_height],toolbar=no,personalbar=no,location=no,directories=no,statusbar=no,menubar=no,status=no,resizable=yes,left=60,screenX=60,top=100,screenY=100');
}
*/
function ldm_popup_all() {
	if (childW && childW.open && !childW.closed) {
		// window is open
	} else {
		childW = window.open('', 'player', 'width='+musicbox_standalone_width+',height='+musicbox_standalone_height+',toolbar=no,personalbar=no,location=no,directories=no,statusbar=yes,menubar=no,status=yes,resizable=yes,left=60,screenX=60,top=100,screenY=100');
	}
}

function openPlayerDefault() {
	if (childW && childW.open && !childW.closed) {
		// window is open
	} else {
		childW = window.open('', 'player', 'width='+musicbox_standalone_width+',height='+musicbox_standalone_height+',toolbar=no,personalbar=no,location=no,directories=no,statusbar=yes,menubar=no,status=yes,resizable=yes,left=60,screenX=60,top=100,screenY=100');
	}
}

function openPlayerPm() {
	openPlayerDefault();
}

function openPlayerMember() {
	openPlayerDefault();
}


function openPlayerMyFavs() {
	openPlayerDefault();
}




function ldm_popup(urlTrack, Artist, Title, LinkId) {
	if (childW && childW.open && !childW.closed) {
		if (childW.document.getElementById('Flashplayer')) {
			childW.wimpy_loadAndPlay('local_stream.php?action=stream' + urlTrack, Artist, Title, LinkId)
		} else {
			childW.location.href = 'local_links.php?action=play' + urlTrack;
			// childW.location.href = urlTrack;
		}
	} else {
		openPlayer('local_links.php?action=play'+urlTrack);
	}
}

function ldm_resize_area(rows, cols, id) {
	var area = fetch_object(id);
	if (typeof area.orig_rows == 'undefined') {
		area.orig_rows = area.rows;
		area.orig_cols = area.cols;
	}

	var newrows = area.rows + rows;
	var newcols = area.cols + cols;

	if (newrows >= area.orig_rows && newcols >= area.orig_cols) {
		area.rows = newrows;
		area.cols = newcols;
	}

	return false;
}

function ldm_size_style(height, width, id) {
	var myobj = fetch_object(id);
	myobj.style.height = height;
	myobj.style.width = width;
	return false;
}

function ldm_noenter() {
	return !(window.event && window.event.keyCode == 13);
}

function ldm_toggle_all_revert(formobj)
{
	setto = formobj.allbox.checked;
	is_revert = "";
	for (var i =0; i < formobj.elements.length; i++)
	{
		var elm = formobj.elements[i];
		elm_re = new RegExp("^.+_revert$");
		is_revert = elm.name.replace(elm_re, 'revert');
		if (is_revert == "revert")
		{
			elm.checked = setto;
		}
	}
}

function ldm_enable_field(fieldid, settingid)
{
	setto = document.getElementById(settingid).checked;
	document.getElementById(fieldid).disabled = !setto;
}

if (location.search.substring(1)=="focuswin") {
	window.focus();
}


