//<![CDATA[

function go(selectField) {
	window.location = document.getElementById(selectField).value;	
}

function showMaestro() {
	if (document.getElementById('cardtype').value == 'Maestro') {
		document.getElementById('maestro').style.display = 'block';
	} else if (document.getElementById('cardtype').value == 'Solo') {
		document.getElementById('maestro').style.display = 'block';
	} else {
		document.getElementById('maestro').style.display = 'none';
	}
	return false;
}

function clearField(id, defaultText) {
	var thisElement = document.getElementById(id);
	var currentValue = thisElement.value;
	if (currentValue == defaultText) {
			thisElement.value = '';
	}
}

function gotoNewsletters() {
	var email = document.getElementById('mailinglistEmail').value;
	var address = site_root+'newsletters/?email='+email+'&add=add';
	window.location = address;
}

function disable() {
	button = this.getElementById('finalsubmit');
	button.value = "Processing your order...";
   	button.disabled=true;
   	return true;   
}

function notifyCart(cartURL, newSite) {
	if (!window.confirm('You have items in your shopping cart. If you want to complete your order, click "Cancel"')) {
		window.location = cartURL;
	} else {
		window.location = newSite;
	}
}

function showLayer(whichLayer) {
	if (document.getElementById) {
		document.getElementById(whichLayer).style.display='block';
	} else if (document.all) {
		document.all[whichLayer].style.display='block';
	} else if (document.layers) {
		document.layers[whichLayer].style.display='block';
	}	
	return false;
}

function hideLayer(whichLayer) {
	if (document.getElementById) {
		document.getElementById(whichLayer).style.display='none';
	} else if (document.all) {
		document.all[whichLayer].style.display='none';
	} else if (document.layers) {
		document.layers[whichLayer].style.display='none';
	}	
	return false;
}

function toggler(whichLayer) {
	if (document.getElementById) {		
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		if (style2.display == "none" || !style2.display) {
			style2.display = "block";
		} else {
			style2.display = "none";
		}
	} else if (document.all) {
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "none":"block";
	}
}

function toggleLive(whichLayer) {
	if (document.getElementById) {
		// this is the way the standards work
		var style2 = document.getElementById('live_'+whichLayer).style;
		if (style2.display == "none") {
			style2.display = "block";
			document.getElementById('showlive_'+whichLayer).innerHTML = '[-]';
		} else {
			style2.display = "none";
			document.getElementById('showlive_'+whichLayer).innerHTML = '[+]';
		}		
	} else if (document.all) {
		// this is the way old msie versions work
		var style2 = document.all['live_'+whichLayer].style;
		style2.display = style2.display? "none":"block";
	} else if (document.layers) {
		// this is the way nn4 works
		var style2 = document.layers['live_'+whichLayer].style;
		style2.display = style2.display? "none":"block";
	}
}

function popupnr(mylink, windowname, refocus) {
	var mywin, href;

	// Pause the movie on the main page if necessary
	//SendDataToFlashMovie()

	if (typeof(mylink) == 'string')
   		href=mylink;
	else
   		href=mylink.href;
		mywin = window.open('', windowname, 'width=340,height=450,scrollbars=no');

	// if we just opened the window
	if (
   		mywin.closed || 
  		 (! mywin.document.URL) || 
  		 (mywin.document.URL.indexOf("about") == 0)
   		)
   		mywin.location=href;
	else if (refocus)
   		mywin.focus();
		return false;
}

var xmlHttp
var offsetFiles = 0;

var listHttp

function clearSearch() {
	document.getElementById('filekeywords').value = '';
	fileLists('start');
}

function fileLists(direction) {
	listHttp=GetXmlHttpObject();
	
	if (listHttp==null) {
		alert ("You can't do this with your browser. Sorry.")
		return
	}
	
	// Get the vars
	keywords = document.getElementById('filekeywords').value;
	artistID = document.getElementById('listArtist').value;
	
	if (direction == 'forward') {
		offsetFiles += 8;
	} else if (direction == 'back') {
		offsetFiles -= 8;
	} else if (direction == 'start') {
		offsetFiles = 0;	
	}
	
	if (offsetFiles <= 0) {
		offsetFiles = 0;	
	}
	
	var url=site_root+"ajax_methods.php"
	url=url+"?offset="+offsetFiles
	url=url+"&method=getfiles"
	if (keywords != '') {
		url=url+"&keywords="+keywords	
	}
	
	if (artistID) {
		url=url+"&artistID="+artistID;	
	}
	
	//alert(url);
	listHttp.onreadystatechange=updateFileList; 
	listHttp.open("GET",url,true)
	listHttp.send(null)
}

function updateFileList() { 
	if (listHttp.readyState==4 || listHttp.readyState=="complete") { 
		document.getElementById("filelist").innerHTML=listHttp.responseText;
		return false;
	} 
} 

function addToPlaylist(fileID) {
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null) {
		alert ("You can't do this with your current browser. Sorry.")
		return
	}
	
	var url=site_root+"ajax_methods.php"
	url=url+"?playlist_file="+fileID
	url=url+"&method=playlist"
	url=url+"&sid="+Math.random()
	//alert(url);
	xmlHttp.onreadystatechange=updatePlaylist
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function removeFromPlaylist(fileID) {
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null) {
		alert ("You can't do this with your current browser. Sorry.")
		return
	}
	
	var url=site_root+"ajax_methods.php"
	url=url+"?playlist_file="+fileID
	url=url+"&method=playlist"
	url=url+"&remove=true"
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=updatePlaylist
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function clearPlaylist() {
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null) {
		alert ("You can't do this with your current browser. Sorry.")
		return
	}
	
	var url=site_root+"ajax_methods.php"
	url=url+"?method=clearplaylist"
	url=url+"&sid="+Math.random()
	//alert(url);
	xmlHttp.onreadystatechange=updatePlaylist 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function updatePlaylist() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		document.getElementById("user_playlist").innerHTML=xmlHttp.responseText;
		return false;
	} 
}

function savePlaylist() {
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null) {
		alert ("You can't do this with your current browser. Sorry.")
		return
	}
	
	// Get the vars
	yourname = document.getElementById('yourname').value;
	listname = document.getElementById('listname').value;
	
	var url=site_root+"ajax_methods.php"
	url=url+"?method=savelist"
	url=url+"&listname="+listname
	url=url+"&yourname="+yourname
	url=url+"&sid="+Math.random()
	//alert(url);
	xmlHttp.onreadystatechange=updatePlaylist
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function updatePlaylist() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		document.getElementById("user_playlist").innerHTML=xmlHttp.responseText;
		return false;
	} 
}

function updateStatus() {
	statusHttp=GetXmlHttpObject();
	
	if (statusHttp==null) {
		alert ("You can't do this with your current browser. Sorry.")
		return
	}
	
	statusMessage = encodeURIComponent(document.getElementById('site_status').value);
	
	var url=site_root+"ajax_methods.php"
	url=url+"?method=status"
	url=url+"&statusMessage="+statusMessage

	statusHttp.onreadystatechange=statusChanged 
	statusHttp.open("GET",url,true)
	statusHttp.send(null)
}

function updateStatusEnter(evt) {
	
	var keyCode = null;
	if ( evt.which ) {
		keyCode = evt.which;
	} else if( evt.keyCode ) {
		keyCode = evt.keyCode;
	}
	
	if ( 13 == keyCode ) {
		document.getElementById('site_status').blur();
		return false;
	}
	return true;
}

function statusChanged() {
	if (statusHttp.readyState==4 || statusHttp.readyState=="complete") {
		document.getElementById("sDate").innerHTML='Updated 1 minute ago';
		return true;
	} 
}

function GetXmlHttpObject() { 
	var objXMLHttp=null
	if (window.XMLHttpRequest) {
		objXMLHttp=new XMLHttpRequest()
	} else if (window.ActiveXObject) {
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
} 

function popUp(strURL,strType,strHeight,strWidth,winName) {
	var strOptions="";
	if (strType=="console") strOptions="resizable,height="+strHeight+",width="+strWidth;
	if (strType=="fixed") strOptions="status,height="+strHeight+",width="+strWidth;
	if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth;
	window.open(strURL, winName, strOptions);
	return false;
}

function updateOpener(url) {
	window.opener.location = url;
}

function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}

function SendDataToFlashMovie() {
     document.getElementById("flashPlayer").SetVariable("/jsUpdate", "Hello world");
}

function submitForm() {
	document.checkout.submit();	
}

function showMoreLive(i) {
	toggler('live_'+i);
	
	togImg = document.getElementById('livetoggle_'+i);
	
	if (togImg.src == site_root+'resources/sitewide/purple_plus.gif') {
		togImg.src = site_root+'resources/sitewide/purple_minus.gif';
	} else {
		togImg.src = site_root+'resources/sitewide/purple_plus.gif';
	}
	
	return false;
}

// JW Media player scripts
function getUpdate(typ,pr1,pr2,swf) {

};

function thisMovie(swf) {
	return document.getElementById(swf);
};

function sendEvent(swf,typ,prm) { 
  	thisMovie(swf).sendEvent(typ,prm); 
};

function getLength(swf) { 
  var len = thisMovie(swf).getLength();
};

function addItem(swf,obj,idx) { 
  thisMovie(swf).addItem(obj,idx); 
};

function removeItem(swf,idx) { 
  thisMovie(swf).removeItem(idx); 
};

function itemData(swf,idx) { 
  var obj = thisMovie(swf).itemData(idx); 
};

// This function sends a file to the player to load
function loadFile(swf,obj) { 
	sendEvent(swf, 'LOAD', obj); 
	// Now play it
	sendEvent(swf, 'PLAY');
};

// This function opens the popup list player
function popUpPlayer(swf, url) {
	sendEvent('jsMovieControl', 'stop', 0);
	var mediaplayer = window.open(url, 'mediaplayer', "resizable,height=415,width=320");
	mediaplayer.focus();
}

// Sends people to get their custom RSS
/*
var arSelected = new Array(); 
function getMultiple(ob) { 
	while (ob.selectedIndex != -1) { if (ob.selectedIndex != 0) arSelected.push(ob.options[ob.selectedIndex].value); ob.options[ob.selectedIndex].selected = false; 
} // You can use the arSelected array for further processing. }
*/
function getCustomRSS() {
	var city = document.getElementById('livecity').value;
	var ob = document.getElementById('liveartists');
	var country = document.getElementById('livecountry').value;
	selected = new Array(); 
	for (var i = 0; i < ob.options.length; i++) if (ob.options[i].selected) selected.push(ob.options[i].value);
	var artists;
	artists = selected.join('-');
	window.location = site_root+'rss/index.php?livedates=true&country='+country+'&artists='+artists+'&city='+city;
	return false;
}

function publishingSubmit() {
	
	$('submitemail').disabled = 1;
	
	var myRequest = new Request({
					url: site_root+'pubdownload.php',
					method: 'post',
					onComplete: function(response) { $('emailPubPanel').set('html', response); },
					data: $('publishingForm').toQueryString() 
				});

	myRequest.send();


}

//]]>
