/* jScripts General Functions */


	var totaltracks;

	var totalprice;

	var pricepertrack;

	var id_array;

	var price_array;


function deleteRow(table,tableidentifier,tableid){
	var cfm = confirm('Are you sure you want to delete this?');

	if(!cfm){
		return false;
	}
	var url = "/include/ajaxFunctions.php";
	var dummy = new Date().getTime();	//	dummy value to avoid caching.
	var pars = "action=deleteRow&table=" + table + "&tableidentifier=" + tableidentifier + "&tableid=" + tableid + "&dummy=" + dummy;
	
	new Ajax.Request(url,{ 
			method:'post', 
			parameters: pars, 
			onComplete: hideRow("tbRow_"+tableid)
	});
	return false;
}


function deleteOptionImage(table,tableidentifier,tableid){
	var url = "/include/ajaxFunctions.php";
	var dummy = new Date().getTime();	//	dummy value to avoid caching.
	var pars = "action=deleteOptionImage&table=" + table + "&tableidentifier=" + tableidentifier + "&tableid=" + tableid +  "&dummy=" + dummy;
	
	new Ajax.Request(url,{ 
			method:'post', 
			parameters: pars, 
			onComplete: hideRow("tbRow_"+tableid)
	});

	return false;
}



function hideRow(rowid){	
	new Effect.Highlight(rowid, {startcolor:'#FF6666',duration: 0.5, queue:{position:'front', scope: 'deleterow'}});
	new Effect.Fade(rowid, {duration: 0.5,queue:{position:'end', scope: 'deleterow'}});	
}



function activate(table,tableidentifier,tableid){
	var url = "/include/ajaxFunctions.php";
	var dummy = new Date().getTime();	//	dummy value to avoid caching.
	var pars = "action=activate&table=" + table + "&tableidentifier=" + tableidentifier + "&tableid=" + tableid + "&dummy=" + dummy;
	
	new Ajax.Request(url,{ 
			method:'post', 
			parameters: pars, 
			onComplete: activateRow(table,tableidentifier,tableid)
	});
	return false;
}

function activateRow(table,tableidentifier,tableid){	
	var row = "tbRow_"+tableid;
	new Effect.Highlight(row, {startcolor:'#66CC66',duration: 0.7});
	$(row).className='active';  // change text color to indicate active
	$('tbRowAct_'+tableid).innerHTML = "<a href=\"#\" onclick=\"return deactivate('"+table+"','"+tableidentifier+"','"+tableid+"')\" title=\"active\"><img src=\"/admin/images/icons/active.gif\" border=\"0\"  /></a>";	  // switch avtive icon & link

}

function deactivate(table,tableidentifier,tableid){

	var url = "/include/ajaxFunctions.php";	
	var dummy = new Date().getTime();	//	dummy value to avoid caching.
	var pars = "action=deactivate&table=" + table + "&tableidentifier=" + tableidentifier + "&tableid=" + tableid + "&dummy=" + dummy;
	new Ajax.Request(url,{ 
			method:'post', 
			parameters: pars, 
			onComplete: deactivateRow(table,tableidentifier,tableid)
	});
		
	return false;
}

function deactivateRow(table,tableidentifier,tableid){	
	var row = "tbRow_"+tableid;
	new Effect.Highlight(row, {startcolor:'#c3c3c3',duration: 0.7});
	$(row).className='deactive';  // change text color to indicate active
	$('tbRowAct_'+tableid).innerHTML = "<a href=\"#\" onclick=\"return activate('"+table+"','"+tableidentifier+"','"+tableid+"')\" title=\"active\"><img src=\"/admin/images/icons/deactive.gif\" border=\"0\"  /></a>";	  // switch avtive icon & link

}


function feature(table,stockid,featuredid){
	var url = "/include/ajaxFunctions.php";
	var dummy = new Date().getTime();	//	dummy value to avoid caching.
	var pars = "action=feature&table=" + table + "&featuredid=" + featuredid + "&stockid=" + stockid + "&dummy=" + dummy;
	
	new Ajax.Request(url,{ 
			method:'post', 
			parameters: pars, 
			onComplete: featureRow(table,stockid,featuredid)
	});
	return false;
}

function featureRow(table,stockid,featuredid){	
	var row = "tbRow_"+stockid;
	new Effect.Highlight(row, {startcolor:'#c3c3c3',duration: 0.7});
	$('tbRowFeat_'+stockid).innerHTML = "<a href=\"#\" onclick=\"return unfeature('"+table+"','"+stockid+"','"+featuredid+"')\" title=\"active\"><img src=\"/admin/images/icons/featured.gif\" border=\"0\"  /></a>";	  // switch avtive icon & link
}

function unfeature(table,stockid,featuredid){
	var url = "/include/ajaxFunctions.php";
	var dummy = new Date().getTime();	//	dummy value to avoid caching.
	var pars = "action=unfeature&table=" + table + "&featuredid=" + featuredid + "&stockid=" + stockid + "&dummy=" + dummy;
	
	new Ajax.Request(url,{ 
			method:'post', 
			parameters: pars, 
			onComplete: unfeatureRow(table,stockid,featuredid)
	});
	return false;
}

function unfeatureRow(table,stockid,featuredid){	
	var row = "tbRow_"+stockid;
	new Effect.Highlight(row, {startcolor:'#c3c3c3',duration: 0.7});
	$('tbRowFeat_'+stockid).innerHTML = "<a href=\"#\" onclick=\"return feature('"+table+"','"+stockid+"','"+featuredid+"')\" title=\"active\"><img src=\"/admin/images/icons/unfeatured.gif\" border=\"0\"  /></a>";	  // switch avtive icon & link
}

function showFrmResponse(){
	$('frmResponse').style.visibility = 'visible';
	new Effect.Highlight(row, {startcolor:'#CCCCCC',duration: 0.7});
}

function submitAjaxSearch(text, li) {
	document.location = "view.php?id="+li.id;
}

function updateArtistDropDown(type){
	var url = "/include/ajaxFunctions.php";
	var pars = "action=updateArtistDropDown&type=" + type;
	new Ajax.Request(url,{ 
			method:'post', 
			parameters: pars, 
			onComplete: updatedArtistDropDown
	});
}

function updatedArtistDropDown(http){
	$('artistdropdown').innerHTML = http.responseText;
	$('artistselect').style.visibility ="hidden";
}

function updateLabelDropDown(type){

	var url = "/include/ajaxFunctions.php";
	var pars = "action=updateLabelDropDown&type=" + type;
	new Ajax.Request(url,{ 
			method:'post', 
			parameters: pars, 
			onComplete: updatedLabelDropDown
	});
}

function updatedLabelDropDown(http){
	$('labeldropdown').innerHTML = http.responseText;
	$('labelselect').style.visibility ="hidden";
}

function updateFormatType(val){
	var url = "/include/ajaxFunctions.php";
	var pars = "action=updateFormatTypeDropDown&val=" + $(val).value;
	new Ajax.Request(url,{ 
			method:'post', 
			parameters: pars, 
			onComplete: updatedFormatType
	});
}

function updatedFormatType(http){
	$('formatTypeDropdown').innerHTML = http.responseText;
}

function updateFormatInfo(stockid){

	var url = "/include/ajaxFunctions.php";
	var pars = "action=updateFormatInfo&stockid=" + stockid;
	new Ajax.Request(url,{ 
			method:'post', 
			parameters: pars, 
			onComplete: updatedFormatInfo
	});

}

function updatedFormatInfo(http){
	$('stockFormat').innerHTML = http.responseText;
}

function addTracklistTrackId(text, li){
	$('searchTermID').value = li.id;
}

function addToTracklist(){
	if($('searchTermID').value ==""){
		$('addTracklistResponse').innerHTML == "Please select a track before adding to tracklist";
		return false;
	}else{
		$('addTracklistResponse').innerHTML =="";
	}
	var url = "/include/ajaxFunctions.php";
	var pars = "action=addToTracklist&track_id=" + $('searchTermID').value + "&format_id=" + $('format_id').value + "&disc_no=" + $('disc_no').value;
	new Ajax.Request(url,{ 
			method:'post', 
			parameters: pars, 
			onComplete: addedToTracklist
	});
			
}

function addedToTracklist(){
	var url = "/include/ajaxFunctions.php";
	var pars = "action=updateTracklist&format_id=" + $('format_id').value + "&disc_no=" + $('disc_no').value;;
	new Ajax.Request(url,{ 
			method:'post', 
			parameters: pars, 
			onComplete: updateTracklist
	});
			
}

function updateTracklist(http){
	$('showTracklisting').innerHTML = http.responseText;
	Sortable.destroy("tblRows");
	Sortable.create("tblRows",{
		tag:'tr',
		onUpdate: function(){
			new Ajax.Request("/include/ajaxFunctions.php",{
				method: "post",
				parameters: { action: 'sortable' ,table: 'tracklisting',tableidentifier: 'listing_id' ,data: Sortable.serialize("tblRows") }
			});
		}
	});
	$('searchTerm').value = "";
	$('searchTermID').value = "";

}

function chkEmail(){
	if($('customer_email').value == ''){
		$('val_email').innerHTML = "Need to enter an email address";
		return false
	}
	/*alert($('customer_email').value);*/
	var url = "/include/ajaxFunctions.php";
	var pars = "action=chkEmail&email=" + $('customer_email').value;
	new Ajax.Request(url,{ 
			method:'post', 
			parameters: pars, 
			onComplete: chkedEmail
	});
}

function chkedEmail(http){
	if(http.responseText==0){
		$('val_email').innerHTML = "";	
		$('butSubmit').disabled=false;
	}
	if(http.responseText>0){
		$('val_email').innerHTML = "Email address already used on this site";	
		$('butSubmit').disabled=true;
		
	}
}

function swopTabs(stockid,format,formatid,stocktypeid){
	
	
	
	tabs = $('detailTabs');
	for(var i=1; i<tabs.getElementsByTagName("li").length+1;i++) {			
		var tabid = 'tab_'+i;
		$(tabid).className = '';
		$('link_'+i).className = '';
		if(i==formatid){
			$(tabid).className = 'active';
			$(tabid).className = 'active';
			$('link_'+i).className = 'white';
		}
	}

	var url = "/include/ajaxFunctions.php";
	var pars = "action=swopTabs&stockid=" + stockid + "&format="+ format + "&stocktypeid=" + stocktypeid;
	new Ajax.Request(url,{ 
			method:'post', 
			parameters: pars, 
			onComplete: swopedTabs
	});
	return false;

	new Effect.Fade($('detailFormat'), {duration: 0.5,queue:{position:'front', scope: 'fadeFormat'}});	
			
}


function swopedTabs(http){
	new Effect.Appear($('detailFormat'), {duration: 0.5,queue:{position:'end', scope: 'fadeFormat'}});
	$('detailFormat').innerHTML = http.responseText;
	eval(document.getElementById('trackTotals').innerHTML);
	var vars = fnGetVars();
	totaltracks  = vars[0];
	totalprice = vars[1];
	pricepertrack = vars[2];
	id_array=vars[3];
	price_array=vars[4];
	return false;

}


function set_pageitem(pageItem) {

	var url = "/include/ajaxFunctions.php";
	var pars = "action=setPageItem&value=" + $(pageItem).value;
	new Ajax.Request(url,{ 
			method:'post', 
			parameters: pars, 
			onComplete: show_set_pageitem
	});

}

function show_set_pageitem() {
	
	if($('firstpageurl')){
		document.location = $('firstpageurl').href;
	}else{
		document.location = window.location.href;
	}

}


function setOrderSucess(success){
	
	var url = "/include/ajaxFunctions.php";
	var pars = "action=setOrderSucess&value="+success;
	new Ajax.Request(url,{ 
			method:'post', 
			parameters: pars, 
			onSuccess: setOrderSucessDone
	});
}

function setOrderSucessDone(http){
	if(http.responseText == 'complete'){
		document.location = window.location.href;
	}
}

function setDigitalFormat(stockid,stocktypeid){

	var url = "/include/ajaxFunctions.php";
	var pars = "action=setDigitalFormat&format=" + $('formatSelect').value + "&stockid=" + stockid+ "&stocktypeid=" + stocktypeid;
	new Ajax.Request(url,{ 
				method:'post', 
				parameters: pars, 
				onComplete: digitalFormatSet
		});
	xHeight = document.getElementById("detailFormat").offsetHeight;
	document.getElementById("fixedHeight").style['height'] = xHeight+"px";
	//style="height:750px;"
	new  Effect.Fade($('detailFormat'), {duration: 1,queue:{position:'front', scope: 'fadeFormat'}});	
}

function digitalFormatSet(http){
	new Effect.Appear($('detailFormat'), {duration: 1,queue:{position:'end', scope: 'fadeFormat'}});
	
	$('detailFormat').innerHTML = http.responseText;	
	eval(document.getElementById('trackTotals').innerHTML);
	var vars = fnGetVars();
	totaltracks  = vars[0];
	totalprice = vars[1];
	pricepertrack = vars[2];
	id_array=vars[3];
	price_array=vars[4];
}

function deleteSample(trackid){
	ret = confirm('Are you sure you want to delete this sample?');
	if(!ret){ return false; }
	
	var url = "/include/ajaxFunctions.php";
	var pars = "action=deleteSample&trackid=" + trackid;
	new Ajax.Request(url,{ 
				method:'post', 
				parameters: pars, 
				onComplete: deletedSample
		});
	return false;
}

function deletedSample(http){
	if(http.responseText == 1){
		new Effect.Fade($('trackSample'), {duration: 0.5,queue:{position:'front', scope: 'deletesample'}});	
		new Effect.Appear($('track_sample'), {duration: 0.5,queue:{position:'end', scope: 'deletesample'}});
		$('newSample').value = 1;
	}	
}

function deleteMp3192(trackid){
	ret = confirm('Are you sure you want to delete this track?');
	if(!ret){ return false; }
	
	var url = "/include/ajaxFunctions.php";
	var pars = "action=deleteMp3192&trackid=" + trackid;
	new Ajax.Request(url,{ 
				method:'post', 
				parameters: pars, 
				onComplete: deletedMp3192
		});
	return false;
}

function deletedMp3192(http){
	if(http.responseText == 1){
		new Effect.Fade($('trackmp3192'), {duration: 0.5,queue:{position:'front', scope: 'deletesample'}});	
		new Effect.Appear($('track_mp3_192'), {duration: 0.5,queue:{position:'end', scope: 'deletesample'}});
		$('new192').value = 1;
	}	
}

function deleteMp3320(trackid){
	ret = confirm('Are you sure you want to delete this track?');
	if(!ret){ return false; }
	
	var url = "/include/ajaxFunctions.php";
	var pars = "action=deleteMp3320&trackid=" + trackid;
	new Ajax.Request(url,{ 
				method:'post', 
				parameters: pars, 
				onComplete: deletedMp3320
		});
	return false;
}

function deletedMp3320(http){
	if(http.responseText == 1){
		new Effect.Fade($('trackmp3320'), {duration: 0.5,queue:{position:'front', scope: 'deletesample'}});	
		new Effect.Appear($('track_mp3_320'), {duration: 0.5,queue:{position:'end', scope: 'deletesample'}});
		$('new320').value = 1;
	}	
}

function deleteWav(trackid){
	ret = confirm('Are you sure you want to delete this track?');
	if(!ret){ return false; }
	
	var url = "/include/ajaxFunctions.php";
	var pars = "action=deleteWav&trackid=" + trackid;
	new Ajax.Request(url,{ 
				method:'post', 
				parameters: pars, 
				onComplete: deletedWav
		});
	return false;
}

function deletedWav(http){
	if(http.responseText == 1){
		new Effect.Fade($('trackwav'), {duration: 0.5,queue:{position:'front', scope: 'deletesample'}});	
		new Effect.Appear($('track_wav'), {duration: 0.5,queue:{position:'end', scope: 'deletesample'}});
		$('newWav').value = 1;
	}	
}

function deleteImage(filename,section){
	ret = confirm('Are you sure you want to delete this image?');
	if(!ret){ return false; }
	
	var url = "/include/ajaxFunctions.php";
	var pars = "action=deleteImage&filename=" + filename + "&section="+section;
	new Ajax.Request(url,{ 
				method:'post', 
				parameters: pars, 
				onComplete: deletedImage
		});
	return false;
}

function deletedImage(){
	
	
		new Effect.Fade($('showImage'), {duration: 0.5});	

}

function set_orderitems() {

	var url = "/include/ajaxFunctions.php";
	var pars = "action=setOrderItem&value=" + $('orderItems').value;
	new Ajax.Request(url,{ 
			method:'post', 
			parameters: pars, 
			onComplete: show_set_orderitems
	});

}

function show_set_orderitems() {
	
	if($('firstpageurl')){
		document.location = $('firstpageurl').href;
	}else{
		document.location = window.location.href;
	}

}



function changeTop10Interval() {

	var url = "/include/ajaxFunctions.php";
	var pars = "action=changeTop10Interval&value=" + $('interval').value;
	new Ajax.Request(url,{ 
			method:'post', 
			parameters: pars, 
			onComplete: changedTop10Interval
	});

}

function changedTop10Interval() {
	document.location = window.location.href;
}

function chkSelected(){
	var ok = false;
	for(i=0; i<$('frmDownloadSelect').elements.length; i++){
		if($('frmDownloadSelect').elements[i].type=="checkbox"){
			if($('frmDownloadSelect').elements[i].checked==true){
				return true;
			}
		}
	}
	if(ok == false){
		$('systemMsg').innerHTML = 'Need to select at least one track to download';
		$('systemMsg').style.display = 'block';
		return false;
	}else{
		$('systemMsg').innerHTML = '';
		$('systemMsg').style.display = 'none';
	}
}

function chkArtistFrm(){
/*	var myText = tinyMCE.getContent('artist_name')
     if (myText == null || myText == ""){
		 $('val_artist_name').innerHTML = "Please enter an artist name";
     }else{
		if($('artist_id').value==null || $('artist_id').value==""){	//check if add
			// check that artist name isnt already in system
			var url = "/include/ajaxFunctions.php";
			var pars = "action=chkArtist&artist_name=" + myText;
			new Ajax.Request(url,{ 
					method:'post', 
					parameters: pars, 
					onComplete: chkedArtistFrm
			});
		}else{
			$('val_artist_name').innerHTML = "";
			submitArtist();
		}
	 }
*/
	if($('artist_name').value == ""){
		$('val_artist_name').innerHTML = "Please enter an artist name";
		return false;
	}else{
		if($('artist_id').value==null || $('artist_id').value==""){	//check if add
			// check that artist name isnt already in system
			var url = "/include/ajaxFunctions.php";
			var pars = "action=chkArtist&artist_name=" + $('artist_name').value;
			new Ajax.Request(url,{ 
					method:'post', 
					parameters: pars, 
					onComplete: chkedArtistFrm
			});
		}else{
			$('val_artist_name').innerHTML = "";
			submitArtist();
		}
	}
	return false;
}

function chkedArtistFrm(http){
	if($('artist_name').value.toUpperCase() == http.responseText.toUpperCase()){
		$('val_artist_name').innerHTML = "This artist is already entered";	
		return false;
	}else{
		$('val_artist_name').innerHTML = "";
		submitArtist();
		//return false;
	}	
}

function submitArtist(){
	//var artist_name2 = tinyMCE.getContent('artist_name');
	var artist_name2 = $('artist_name').value
	new Ajax.Updater('frmArtistResponse', '/admin/artist/save.php', 
		{	method:'post', 
			asynchronous:true, 
			parameters:Form.serialize($('artistForm'))+'&artist_name2='+artist_name2 , 
			onComplete:function(){
				$('frmArtistResponse').style.visibility = 'visible'; 
				new Effect.Highlight('frmArtistResponse',{startcolor:'#CCCCCC',duration: 0.7});
				if($('type')){
					updateArtistDropDown($('type'));
				}
			}
		});
		

	return true;

}

function chkLabelFrm(){
	if($('label_name').value == ""){
		$('val_label_name').innerHTML = "Please enter an label name";
		return false;
	}else{
		// check that artist name isnt already in system
		var url = "/include/ajaxFunctions.php";
		var pars = "action=chkLabel&label_name=" + $('label_name').value;
		new Ajax.Request(url,{ 
				method:'post', 
				parameters: pars, 
				onComplete: chkedLabelFrm
		});
	}
	return false;
}

function chkedLabelFrm(http){
	if($('label_name').value.toUpperCase() == http.responseText.toUpperCase()){
		$('val_label_name').innerHTML = "This label is already entered";	
		return false;
	}else{
		$('val_label_name').innerHTML = "";
		submitLabel();
		//return false;
	}	
}

function submitLabel(){
	new Ajax.Updater('frmLabelResponse', '/admin/label/save.php', 
		{	method:'post',
		asynchronous:true, 
		parameters:Form.serialize($('labelForm')) , 
		onComplete:function(){
				$('frmLabelResponse').style.visibility = 'visible'; 
				new Effect.Highlight('frmLabelResponse',{startcolor:'#CCCCCC',duration: 0.7});
				if($('type')){
						updateLabelDropDown($('type'));
				}
			}
	});
	return true;
}


function  chkTrackForm(){
	if($('track_title').value == ""){
		$('val_track_title').innerHTML = "Please enter an track title";
		return false;
	}else{
		$('val_track_title').innerHTML = "";
	}
	if($('artistSelect').value == ""){
		$('val_artistSelect').innerHTML = "Please select an Artist";
		return false;
	}else{
		$('val_artistSelect').innerHTML = "";
	}
	if($('labelSelect').value == "0"){
		$('val_labelSelect').innerHTML = "Please select a label from the list or add new";
		return false;
	}else{
		$('val_labelSelect').innerHTML = "";
	}

	if($('track_territory_group_id').value == "0"){
		$('val_territorySelect').innerHTML = "Please select a territory from the list";
		return false;
	}else{
		$('val_territorySelect').innerHTML = "";
	}

	submitTrackForm();

}

function submitTrackForm(){
	var track_description2 = tinyMCE.getContent('track_desc');
	
	new Ajax.Updater('frmTrackResponse', '/admin/track/save.php',
		{method:'post', 
		asynchronous:true, 
		parameters:Form.serialize($('trackForm'))+'&track_description2='+track_description2 , 
		onComplete:function(){
					$('frmTrackResponse').style.visibility = 'visible'; 
					new Effect.Highlight('frmTrackResponse',{startcolor:'#CCCCCC',duration: 0.7})
					}
	}); 
}


function chkPressCategoryFrm(){
	if($('press_category_name').value == ""){
		$('frmPressCategoryResponse').innerHTML = "Please enter a category name";
		$('frmPressCategoryResponse').style.visibility = 'visible';
		new Effect.Highlight('frmPressCategoryResponse',{startcolor:'#CCCCCC',duration: 0.7});
		return false;
	}else{
		// check that category name isnt already in system
		var url = "/include/ajaxFunctions.php";
		var pars = "action=chkPressCategory&press_category_name=" + $('press_category_name').value;
		new Ajax.Request(url,{ 
				method:'post', 
				parameters: pars, 
				onComplete: chkedPressCategoryFrm
		});
	}
	return false;
}

function chkedPressCategoryFrm(http){
	if($('press_category_name').value.toUpperCase() == http.responseText.toUpperCase()){
		$('frmPressCategoryResponse').style.visibility = 'visible'; 
		$('frmPressCategoryResponse').innerHTML = "This category is already entered";
		new Effect.Highlight('frmPressCategoryResponse',{startcolor:'#CCCCCC',duration: 0.7});
		return false;
	}else{
		$('frmPressCategoryResponse').innerHTML = "";
		submitPressCategory();
		//return false;
	}	
}


function submitPressCategory(){
	new Ajax.Updater('frmPressCategoryResponse', '/admin/press/save.php', 
		{	method:'post',
		asynchronous:true, 
		parameters:Form.serialize($('add_cat_form')) , 
		onComplete:function(){
				$('frmPressCategoryResponse').style.visibility = 'visible'; 
				new Effect.Highlight('frmPressCategoryResponse',{startcolor:'#CCCCCC',duration: 0.7});
				//if($('type')){
						//updateLabelDropDown($('type'));
				//}
				setTimeout('document.location.reload();', 3000);
			}
	});
	return true;
}


function chkPressCategoryEditFrm(){
	if($('press_category_name').value == ""){
		$('val_press_category_name').innerHTML = "Please enter a name";
		return false;
	}else{
		// check that name isnt already in system
		var url = "/include/ajaxFunctions.php";
		var pars = "action=chkPressCategoryEdit&press_category_name=" + $('press_category_name').value + "&press_category_id=" + document.getElementById('press_category_id').value;
		new Ajax.Request(url,{ 
				method:'post', 
				parameters: pars, 
				onComplete: chkedPressCategoryEditFrm
		});
	}
	return false;
}

function chkedPressCategoryEditFrm(http){
	if($('press_category_name').value.toUpperCase() == http.responseText.toUpperCase()){
		$('val_press_category_name').innerHTML = "This name is already in use";	
		return false;
	}else{
		$('val_press_category_name').innerHTML = "";
		submitPressCategoryEdit();
		//return false;
	}	
}

function submitPressCategoryEdit(){
	new Ajax.Updater('frmPressCategoryResponse', '/admin/press/save.php', 
		{	method:'post',
		asynchronous:true, 
		parameters:Form.serialize($('pressCategoryForm')) , 
		onComplete:function(){
				$('frmPressCategoryResponse').style.visibility = 'visible'; 
				new Effect.Highlight('frmPressCategoryResponse',{startcolor:'#CCCCCC',duration: 0.7});
			}
	});
	return true;
}




function chkPressFileFrm(){
	if($('press_file_title').value == ""){
		$('val_press_file_title').innerHTML = "Please enter a name";
		return false;
	}else{
		// check that name isnt already in system
		var url = "/include/ajaxFunctions.php";
		var pars = "action=chkPressFile&press_file_name=" + $('press_file_name').value + "&press_file_id=" + document.getElementById('press_file_id').value;
		new Ajax.Request(url,{ 
				method:'post', 
				parameters: pars, 
				onComplete: chkedPressFileFrm
		});
	}
	return false;
}

function chkedPressFileFrm(http){
	if($('press_file_title').value.toUpperCase() == http.responseText.toUpperCase()){
		$('val_press_file_title').innerHTML = "This name is already in use";	
		return false;
	}else{
		$('val_press_file_title').innerHTML = "";
		submitPressFile();
		//return false;
	}	
}

function submitPressFile(){
	$('pressFileForm').submit();
	new Ajax.Updater('frmPressFileResponse', '/admin/press/save-file.php', 
		{	method:'post',
		asynchronous:true, 
		parameters:Form.serialize($('pressFileForm')) , 
		onComplete:function(){
				$('frmPressFileResponse').style.visibility = 'visible'; 
				new Effect.Highlight('frmPressFileResponse',{startcolor:'#CCCCCC',duration: 0.7});
			}
	});
	return true;
}




function deletePDF(filename,section){
	ret = confirm('Are you sure you want to delete this pdf?');
	if(!ret){ return false; }
	
	var url = "/include/ajaxFunctions.php";
	var pars = "action=deletePDF&filename=" + filename + "&section="+section;
	new Ajax.Request(url,{ 
				method:'post', 
				parameters: pars, 
				onComplete: deletedPDF
		});
	return false;
}

function deletedPDF(){
	
	
		new Effect.Fade($('showPDF'), {duration: 0.5});	

}

document.getElementsByClassName = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;
if (myclass.test(classes)) retnode.push(elem[i]);
}
return retnode;
}; 

function showSubNav(parentID){
	arrSubNav = document.getElementsByClassName('subnav');
	for(var i=0; i<arrSubNav.length;i++) {			
		if(arrSubNav[i].id != 'subnav_'+parentID){
			new Effect.BlindUp ($(arrSubNav[i].id), {duration: 0.5});
		}
	}
		new Effect.BlindDown($('subnav_'+parentID), {duration: 0.5});
		$('t'+parentID).onclick = new Function("hideSubNav('" + parentID + "');return false;");
		return false;

}

function hideSubNav(parentID){
	$('t'+parentID).onclick = new Function("showSubNav('" + parentID + "');return false;");
	new Effect.BlindUp ($('subnav_'+parentID), {duration: 0.5});
}


function generatePassword(){
	var url = "/include/ajaxFunctions.php";
	var pars = "action=generatePassword";
	new Ajax.Request(url,{ 
				method:'post', 
				parameters: pars, 
				onComplete: generatedPassword
		});
	return false;
}

function generatedPassword(http){
	$('customer_password').value = http.responseText;
}

function copyCdTrklist(stockid,formatid,discno){
	var chk = confirm('Are you sure you want to add the CD tracklist to this: '+discno+'\nThis will remove any tracks already in the tracklist');
	if(!chk){
		return false;
	}
	
	var url = "/include/ajaxFunctions.php";
	var pars = "action=copyCdTracklist&stockid="+stockid+"&formatid="+formatid+"&discno="+discno;
	new Ajax.Request(url,{ 
				method:'post', 
				parameters: pars, 
				onComplete: copiedCdTrklist
		});
	return false;
}

function copiedCdTrklist(http){
	addedToTracklist();
	return false;
}

function deleteFormat(format_id){
	var chk = confirm('Are you sure you want to delete this format?');
	if(!chk){
		return false;
	}
	
	var url = "/include/ajaxFunctions.php";
	var pars = "action=deleteFormat&format_id="+format_id;
	new Ajax.Request(url,{ 
				method:'post', 
				parameters: pars, 
				onComplete: deletedFormat
		});
	return false;

}

function deletedFormat(http){
	hideRow($('row_'+http.responseText));
}


function chkTerritoryGroupFrm(){
	if($('territory_group_name').value == ""){
		$('frmTerritoryGroupResponse').innerHTML = "Please enter a territory name";
		$('frmTerritoryGroupResponse').style.visibility = 'visible';
		new Effect.Highlight('frmTerritoryGroupResponse',{startcolor:'#CCCCCC',duration: 0.7});
		return false;
	}else{
		// check that category name isnt already in system
		var url = "/include/ajaxFunctions.php";
		var pars = "action=chkTerritoryGroup&territory_group_name=" + $('territory_group_name').value;
		new Ajax.Request(url,{ 
				method:'post', 
				parameters: pars, 
				onComplete: chkedTerritoryGroupFrm
		});
	}
	return false;
}

function chkedTerritoryGroupFrm(http){
	if($('territory_group_name').value.toUpperCase() == http.responseText.toUpperCase()){
		$('frmTerritoryGroupResponse').style.visibility = 'visible'; 
		$('frmTerritoryGroupResponse').innerHTML = "This group is already entered";
		new Effect.Highlight('frmTerritoryGroupResponse',{startcolor:'#CCCCCC',duration: 0.7});
		return false;
	}else{
		$('frmTerritoryGroupResponse').innerHTML = "";
		$('frmTerritoryGroupResponse').style.visibility = 'hidden'; 
		submitTerritoryGroup();
		//return false;
	}	
}

function submitTerritoryGroup(){
	new Ajax.Updater('frmTerritoryGroupResponse', '/admin/territory/save-group.php', 
		{	method:'post',
		asynchronous:true, 
		parameters:Form.serialize($('add_ter_group_form')) , 
		onComplete:function(){
				$('frmTerritoryGroupResponse').style.visibility = 'visible'; 
				new Effect.Highlight('frmTerritoryGroupResponse',{startcolor:'#CCCCCC',duration: 0.7});
				//if($('type')){
						//updateLabelDropDown($('type'));
				//}
				setTimeout('document.location.reload();', 2000);
			}
	});
	return true;
}


function SubmitMailingList(){

	new Ajax.Updater('mailListResponse', '/pages/components/mailing-list-submit.php', 
		{	method:'post', 
			asynchronous:true, 
			parameters:Form.serialize($('frmJoinMail')) , 
			onComplete:function(http){
				$('mailListResponse').innerHTML = http.responseText;		
				$('mailListResponse').style.visibility = 'visible'; 
			}
		});
		
	return false;
}




//================================== Cart Vouchers ==================================//
function fnLoadVouchers(){
	var voucherCode =""
	if(document.getElementById("voucher").value != ""){
		 voucherCode = "&voucher="+document.getElementById("voucher").value;
	}
	var url = "/include/ajaxFunctions.php";
	var pars = "action=getVoucher"+voucherCode;
	new Ajax.Request(url,{ 
				method:'post', 
				parameters: pars, 
				onComplete: loadVouchers
		});
	return false;
}

function loadVouchers(http){
	document.getElementById("voucherBox").innerHTML = http.responseText;
	//reload totals box
	var url = "/include/ajaxFunctions.php";
	var pars = "action=updateTotals";
	new Ajax.Request(url,{ 
				method:'post', 
				parameters: pars, 
				onComplete: loadTotals
		});
	return false;	
}

function fnRemoveVoucher(name,value){	
	$vars = "&"+name+"="+value;
	var url = "/include/ajaxFunctions.php";
	var pars = "action=removeVoucher"+$vars;
	if(value > ''){
		new Ajax.Request(url,{ 
					method:'post', 
					parameters: pars, 
					onComplete: fnLoadVouchers
			});
	}
	return false;
}

function loadTotals(http){
	if( http.responseText == "empty"){
		window.location='/cart-view/';
	}else{
		document.getElementById("totalsBox").innerHTML = http.responseText;
		var row = "totalsRow";
		new Effect.Highlight(row, {startcolor:'#BCD22E',endcolor:'#4D4D4D',duration: 0.7});
	}
	//update basket
	var url = "/include/ajaxFunctions.php";
	var pars = "action=editCart"
	new Ajax.Request(url,{ 
				method:'post', 
				parameters: pars, 
				onComplete: updateCart
		});
	return false;	
}

function updateCart(http){
		document.getElementById("cartBox").innerHTML = http.responseText;
		var row = "cartRow";
		new Effect.Highlight(row, {startcolor:'#BCD22E',endcolor:'#4D4D4D',duration: 0.7});
	return false;	
}

//================================== Cart Digital ==================================//
//variable to pass to updateDigital to see which album to leave expanded on page reload
var stock_open;
function fnUpdateDigital(name,value){
	$vars = "&"+name+"="+value;
	var url = "/include/ajaxFunctions.php";
	var pars = "action=editDigital"+$vars;
	stock_open = value;
	new Ajax.Request(url,{ 
				method:'post', 
				parameters: pars, 
				onComplete: updateDigital
		});
	return false;
}

function fnUpdateDigitalMultiple(str){
	var url = "/include/ajaxFunctions.php";
	var pars = "action=editDigital"+str;
	new Ajax.Request(url,{ 
				method:'post', 
				parameters: pars, 
				onComplete: updateDigital
		});
	return false;
}

function updateDigital(http){
	var url = "/include/ajaxFunctions.php";
	var pars = "action=updateDigital&open="+stock_open;
	new Ajax.Request(url,{ 
				method:'post', 
				parameters: pars, 
				onComplete: loadDigital
		});
	return false;	
}

function loadDigital(http){
	document.getElementById("digitalBox").innerHTML = http.responseText;
	if(http.responseText != ""){
		var row = "digitalRow";
		new Effect.Highlight(row, {startcolor:'#BCD22E',endcolor:'#4D4D4D',duration: 0.7});
	}
	//reload totals box
	var url = "/include/ajaxFunctions.php";
	var pars = "action=updateTotals";
	new Ajax.Request(url,{ 
				method:'post', 
				parameters: pars, 
				onComplete: loadTotals
		});
	return false;	
}
//================================== Cart CD ==================================//
function fnUpdateCD(name,value){
	if(value > '' && !isNaN(value)){
		$vars = "&"+name+"="+value;
		var url = "/include/ajaxFunctions.php";
		var pars = "action=editCD"+$vars;
		new Ajax.Request(url,{ 
					method:'post', 
					parameters: pars, 
					onComplete: updateCD
			});
	}
	return false;
}

function updateCD(http){
	var url = "/include/ajaxFunctions.php";
	var pars = "action=updateCD";
	new Ajax.Request(url,{ 
				method:'post', 
				parameters: pars, 
				onComplete: loadCD
		});
	return false;	
}

function loadCD(http){
	document.getElementById("cdBox").innerHTML = http.responseText;
	if(http.responseText != ""){
		var row = "cdRow";
		new Effect.Highlight(row, {startcolor:'#BCD22E',endcolor:'#4D4D4D',duration: 0.7});
	}
	//reload totals box
	var url = "/include/ajaxFunctions.php";
	var pars = "action=updateTotals";
	new Ajax.Request(url,{ 
				method:'post', 
				parameters: pars, 
				onComplete: loadTotals
		});
	return false;	
}
//================================== Cart Merchandise  ==================================//

function fnUpdateOnEnter(e,name,value){ //e is event object passed from function invocation
	var characterCode //literal character code will be stored in this variable
	
	if(e && e.which){ //if which property of event object is supported (NN4)
	e = e
	characterCode = e.which //character code is contained in NN4's which property
	}
	else{
	e = event
	characterCode = e.keyCode //character code is contained in IE's keyCode property
	}
	if(characterCode == 13){ 
	fnUpdateMerch(name,value);
	}
return false 
}

function fnUpdateMerch(name,value){
	if(value > '' && !isNaN(value)){
		$vars = "&"+name+"="+value;
		var url = "/include/ajaxFunctions.php";
		var pars = "action=editMerch"+$vars;
		new Ajax.Request(url,{ 
					method:'post', 
					parameters: pars, 
					onComplete: updateMerch
			});
	}
return false;
}

function updateMerch(http){
	var url = "/include/ajaxFunctions.php";
	var pars = "action=updateMerch";
	new Ajax.Request(url,{ 
				method:'post', 
				parameters: pars, 
				onComplete: loadMerch
		});
	return false;	
}

function loadMerch(http){
	document.getElementById("merchBox").innerHTML = http.responseText;
	if(http.responseText != ""){
		var row = "merchRow";
		new Effect.Highlight(row, {startcolor:'#BCD22E',endcolor:'#4D4D4D',duration: 0.7});
	}
	//reload totals box
	var url = "/include/ajaxFunctions.php";
	var pars = "action=updateTotals";
	new Ajax.Request(url,{ 
				method:'post', 
				parameters: pars, 
				onComplete: loadTotals
		});
	return false;	
}



//================================== Cart Postage  ==================================//
function fnUpdatePostage(item){
	 $postageMethod = "&post_method="+item.value;
	//reload totals box
	var url = "/include/ajaxFunctions.php";
	var pars = "action=updateTotals"+ $postageMethod ;
	new Ajax.Request(url,{ 
				method:'post', 
				parameters: pars, 
				onComplete: loadTotals
		});
	return false;	
}


//================================== Cart Postage  ==================================//

function setTrackPrice(listingID,curPrice,currency){
	shwCUr = (currency=='usa')?currency+'_':'';

	$('price_'+shwCUr+listingID).innerHTML = "<form id=\"setTrackPrice_"+listingID+"\" action=\"\" method=\"\" onsubmit=\"return submitTrackPrice('"+listingID+"','"+currency+"');\"><input type=\"hidden\" name=\"currency\" value=\""+currency+"\"><input type=\"hidden\" name=\"listingid\" value=\""+listingID+"\"><input id=\"update_"+listingID+"\" type=\"text\" name=\"price\" value=\""+curPrice+"\" style=\"width:50px;\" /> <input type=\"submit\" value=\">>\" /></form>"; 

	return false;
}

function submitTrackPrice(trackID,cur){
	shwCUr = (cur=='usa')?cur+'_':'';

	new Ajax.Updater('price_'+shwCUr+trackID, '/admin/release/update-track-price.php', 
		{	method:'post', 
			asynchronous:true, 
			parameters:Form.serialize($('setTrackPrice_'+trackID)), 
			onComplete:function(){
				new Effect.Highlight('update_'+trackID,{startcolor:'#66CC66',duration: 0.7});
			}
		});
		
	return false;
}
