
var nrOptions = 1;

function addRecordingFields(nrToAdd)
{
	prnt = FIDO.$('recordingFields');
	elm = FIDO.$('recordingfields1').cloneNode(true);
		
	var newOptions = (parseInt(nrToAdd)+parseInt(nrOptions));
	//alert(newOptions);
	for (var i = parseInt(nrOptions); i < newOptions; i++)
	{
		//elm id's aanpassen
		elm.id = "recordingfields"+(i+1);
		elm.firstChild.firstChild.firstChild.nextSibling.id = "recnr"+(i+1);
		elm.firstChild.firstChild.firstChild.nextSibling.name = "recnr"+(i+1);
		elm.firstChild.firstChild.firstChild.nextSibling.innerHTML = (i+1);
		elm.firstChild.firstChild.nextSibling.firstChild.nextSibling.firstChild.id = "recording"+(i+1);
		elm.firstChild.firstChild.nextSibling.firstChild.nextSibling.firstChild.name = "recording"+(i+1);
		elm.firstChild.firstChild.nextSibling.nextSibling.firstChild.nextSibling.firstChild.id = "stage"+(i+1);
		elm.firstChild.firstChild.nextSibling.nextSibling.firstChild.nextSibling.firstChild.name = "stage"+(i+1);
		elm.firstChild.firstChild.nextSibling.nextSibling.nextSibling.firstChild.nextSibling.firstChild.id = "recording_date"+(i+1);
		elm.firstChild.firstChild.nextSibling.nextSibling.nextSibling.firstChild.nextSibling.firstChild.name = "recording_date"+(i+1);
		elm.firstChild.firstChild.nextSibling.nextSibling.nextSibling.nextSibling.firstChild.nextSibling.firstChild.id = "starting_time"+(i+1);
		elm.firstChild.firstChild.nextSibling.nextSibling.nextSibling.nextSibling.firstChild.nextSibling.firstChild.name = "starting_time"+(i+1);

		// toevoegen 
		prnt.appendChild(elm);
	}
	
	//x aantal opties aangemaakt
	FIDO.ajaxCall('calc', 'saveNrRecordings', newOptions);
}

function deleteRecordingFields(nrToDel)
{
	prnt = FIDO.$('recordingFields');
	elm = FIDO.$('recordingfields'+nrOptions);
	prnt.removeChild(elm); 
	
	var newOptions = (parseInt(nrOptions)-parseInt(nrToDel));
	
	//x aantal opties verwijderd
	FIDO.ajaxCall('calc', 'saveNrRecordings', newOptions);
}

function saveNrRecordings_Result(retval)
{
	retval = FIDO.checkAjaxReturn(retval);
	nrOptions = retval;
}

function sendArtist(related_id, artist)
{
	window.opener.document.forms["addalias"].alias.value = unescape(artist);
	window.opener.document.forms["addalias"].related_id.value = related_id;
	window.close();
}

function sendProjectname(related_id, artist)
{
	window.opener.document.forms["addrelease"].alias.value = unescape(artist);
	window.opener.document.forms["addrelease"].related_id.value = related_id;
	window.close();
}

function sendLabel(related_id, label)
{
	var curVal = window.opener.document.forms["addrelease"].labels.value;
	if (curVal.length > 0)
	{
		curVal += "; ";
	}
	window.opener.document.forms["addrelease"].labels.value = curVal + unescape(label);
	
	curVal = window.opener.document.forms["addrelease"].labelids.value;
	if (curVal.length > 0)
	{
		curVal += "; ";
	}
	window.opener.document.forms["addrelease"].labelids.value = curVal + related_id;
	window.close();
}

function sendFileLabel(related_id, label)
{
	var curVal = window.opener.document.forms["fileUploadForm"].labelvals.value;
	if (curVal.length > 0)
	{
		curVal += "; ";
	}
	window.opener.document.forms["fileUploadForm"].labelvals.value = curVal + unescape(label);
	
	curVal = window.opener.document.forms["fileUploadForm"].labelids.value;
	if (curVal.length > 0)
	{
		curVal += "; ";
	}
	window.opener.document.forms["fileUploadForm"].labelids.value = curVal + related_id;
	window.close();
}

var activeMenu = 0;
var mnFlag = 0;

function smn_show(id)
{
	var d = document.getElementById(id);
	for (var i = 0; i<=3; i++)
	{
		if ((document.getElementById('subnav'+i).className.indexOf("show") != -1) && (mnFlag == 0) && (i > 0))
		{
			activeMenu = i;
			mnFlag = 1;
		}
		if (document.getElementById('subnav'+i))
		{
			document.getElementById('subnav'+i).style.display='none';
		}
	}
	if (d) {d.style.display='block';}
}

function smn_hide()
{
	for (var i = 0; i<=3; i++)
	{
		if (document.getElementById('subnav'+i))
		{
			document.getElementById('subnav'+i).style.display='none';
		}
	}
	document.getElementById('subnav'+activeMenu).style.display='block';
}

var composer = 0;
var performingartist = 0;
var producer = 0;
var author = 0;
var arranger = 0;
var songwriter = 0;
var caller;

function cloneBox(obj)
{
	rel = document.getElementById(obj+'_0');
	appendto = document.getElementById(obj+'s');
	mycopy = rel.cloneNode(true);
	mycopy.id = obj+'_'+(eval(obj + "+=1;"));
	mycopy.getAttributeNode('name').nodeValue = mycopy.id;
	mycopy.options[0].selected = true;
	delbtn = document.getElementById(obj+'_0_del');
	btncopy = delbtn.cloneNode(true);
	btncopy.id = mycopy.id+'_del';
	appendto.appendChild(mycopy);
	appendto.appendChild(btncopy);
}

function removeBox(obj, obj_id)
{
	removefrom = document.getElementById(obj+'s');
	removefrom.removeChild(document.getElementById(obj_id));
	curelm = obj_id.substring(0, (obj_id.length-4));
	removefrom.removeChild(document.getElementById(curelm));
}

function sendContributor(related_id, contributor)
{
	ref = eval("window.opener.document.forms['"+window.opener.caller.form.name+"']."+window.opener.caller.id);
	if (document.all)
	{
		doc = ref.document;
		opt = doc.createElement('OPTION');
		opt.value = related_id;
		opt.text = unescape(contributor);
		ref.options.add(opt, ref.options.length);
	}
	else
	{
		ref.options[ref.options.length] = new Option(unescape(contributor), related_id);
	}
	//select the new option
	ref.options[ref.options.length-1].selected = true;
	window.close();
}

function addOptionToBox(obj, wUrl)
{
	nr = obj.options[obj.selectedIndex].value;
	if (nr == 0)
	{
		caller = obj;
		window.open(wUrl, 'selectcontributor', 'toolbar=no,scrollbars=yes,width=800,height=600');
	}
}

function uploadFile(obj)
{
	if (confirm('Are you sure the track information and the mp3 file is correct? You are not authorized to change the information after uploading.'))
	{
		return true;
	}
	else
	{
		obj.submitBT.disabled=false;
		return false;
	}
}

// mediaplayer functions

function thisMovie(swf)
{
	if(navigator.appName.indexOf("Microsoft") != -1)
	{
		return window[swf];
	}
	else
	{
    	return document[swf];
	}
};

function sendEvent(swf,typ,prm)
{ 
	thisMovie(swf).sendEvent(typ,prm); 
};

function getUpdate(typ,pr1,pr2,swf) {};

function loadFile(swf,obj)
{ 
	thisMovie(swf).loadFile(obj); 
};

function listenmp3(swf,obj)
{
	loadFile(swf,obj)
	//sendEvent(swf, 'playpause');
//  sendEvent(swf, 'playitem, 1');
	//room for more functions
};

function stopmp3(swf)
{
	sendEvent(swf, 'stop');
};

