///////////////

function winPop(url,name,width,height)
{
 var width  = width;
 var height = height;
 var left   = (screen.width  - width)/4;
 var top    = (screen.height - height)/4;
 var params = 'width='+width+', height='+height;
 params += ', top='+top+', left='+left;
 params += ', directories=no';
 params += ', location=no';
 params += ', menubar=no';
 params += ', resizable=yes';
 params += ', scrollbars=yes';
 params += ', status=no';
 params += ', toolbar=no';
 newwin=window.open(url,name, params);
 if (window.focus) {newwin.focus()}
 return false;
}


function switchid(id){	
	hideallids();
	showDiv(id);
}

function hideallids(){
	//loop through the array and hide each element by id
	for (var i=0;i<ids.length;i++){
		hideDiv(ids[i]);
	}		  
}
function makeInput(id,type,name)
{	
	var Output = '<input type="' + type + '" value="" name="' + name + '" id="' + name + '" maxlength="100";" />';
	document.getElementById(id).innerHTML = Output;
	document.getElementById(name).focus();
}
function deleteInput(id)
{
	document.getElementById(id).innerHTML = '';
}

function addValue(idTO,idFROM)
{
	document.getElementById(idTO).value = document.getElementById(idFROM).value;
}

function showEdit(element,id)
{
	var Output = ' <a href="../pop.php?a=14&artistId=' + id +'" class="minilink">Edit Artist</a>';
	
	if(id > 0)
	document.getElementById(element).innerHTML = Output;
}
function hideEdit(element,id)
{
	document.getElementById(element).innerHTML = '';
}


function showDiv(id,display)
{

 display = (typeof display == 'undefined') ? 'block' : display;
	
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = display;
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = display;
		}
		else { // IE 4
			document.all.id.style.display = display;
		}
	}
}
function hideDiv(id)
{
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function replaceDiv(id, replaceId, display) {
	//safe function to show an element with a specified id
	
	 display = (typeof display == 'undefined') ? 'block' : display;

	
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = display;
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = display;
		}
		else { // IE 4
			document.all.id.style.display = display;
		}
	}
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(replaceId).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.replaceId.display = 'none';
		}
		else { // IE 4
			document.all.replaceId.style.display = 'none';
		}
	}
}

<!-- Adding an image to the TET EDIT window
function AddImage(imgSrc){
	var html = '<img src="' + imgSrc + '" width="' + document.form.width.value +'" heigth="auto" />';
	
	if(document.form.width.value == '' || document.form.width.value == ' ' || document.form.width.value == '  ' || document.form.width.value == '   '){
		var width = false;
	}
	else{
		var width = true;
	}
	
	if(width){
		window.opener.insertHTML(html);
		window.close();
	}
	else{
		alert('You need to fill in a width for your picture.');
	}
}

function scrollToBottom(){
		window.scrollTo(0, f_clientHeight());
	}
	

function submitForm() {
//make sure hidden and iframe values are in sync before submitting form
//updateRTE('newText'); //use this when syncing only 1 rich text editor ("rtel" is name of editor)
updateRTEs(); //uncomment and call this line instead if there are multiple rich text editors inside the form
//alert(document.addTrackInfo.trackInfo.value) //alert submitted value
return true; //Set to false to disable form submission, for easy debugging.
}

function writeDays(tot,inputId){
	var days;
	var dayId = 'day' + inputId;
	
	
	for(var i = 01; i <= tot; i++){
	
		if(i < 10)
			days = days + '<option value="0' + i + '" id="day0' + i + '_' + inputId + '">0' + i + '</option><br />';
		else
			days = days + '<option value="' + i + '" id="day' + i + '_' + inputId + '">' + i + '</option><br />';
	}
	
	// Insert inte the day select
	document.getElementById(dayId).innerHTML = days;
}

function copyLive(){
	document.getElementById('a').value = 19;		
}

function message(html){
	document.getElementById('message').style.top = f_scrollTop();
	
	
	// document.getElementById('messageBoard').innerHTML = html;
	showDiv('message');
}

function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function checkEmail(email) {	
	var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	
	if (!filter.test(email.value))
		return false;
	else
		return true;
}

function titleLenght(inputId,spanId,totLenght){
	var title = document.getElementById(inputId).value;
	document.getElementById(spanId).innerHTML = title.length + '/' + totLenght;
}

function hover(id,color){
		document.getElementById(id).style.background = color;
	}
function deHover(id,color){
	document.getElementById(id).style.background = color;
}

function submitFromUploadMp3(){
	var msg = '';
	var answer = true;
	
	if(document.upload.upFile.value == ''){
		msg = msg + 'No file \n'; 	
		answer = false;
	}
	if(document.upload.title.value == ''){
		msg = msg + 'No title \n'; 	
		answer = false;
	}
	if(document.upload.artist.value == ''){
		msg = msg + 'No artist \n'; 	
		answer = false;
	}
	
	if(!answer) alert(msg);
	
	if(answer)
		showDiv('loading');
	
	return answer;
}
