/*
 * History : 
 * 
 */

/*js functions of artist.asp;*/

/* required for upload progress stuff, if there is a FmeBottom then hide it and close it.*/
//var dummyWin = null;
//if(USER_LOGGED_IN.toLowerCase()=="true" && blnAllowEdit.toLowerCase() == "true") {dummyWin = window.open("/close.html", "FmeBottom", "width=10, height=10");}

function adjustLayout() {
	var intRCHeight = 0, intMCHeight = 0;
	intRCHeight = getHeight("RC");
	intMCHeight = getHeight("Content");
	var intMax = Math.max( intRCHeight, intMCHeight );
	setHeight( "RC", intMax );
	setHeight( "Content", intMax );
	showLayer("Footer");
}

function init() {
	addListener(window, "resize", adjustLayout, false);
	adjustLayout();
	setImageAttributes();
	var objForm=null;
	if(!(objForm=document.forms[1]))return;

	if(objForm.strTask.value=="Close Page") {
		//if(opener){opener.refresh();}
		//setTimeout("window.close();",1000);
	}
}
/*add listener before doing anyting else*/
addListener(window,"load",init,false);

function showPage(pageNumber) {
	var objForm=null;
	if(!(objForm=document.forms[1]))return;
	/* v.o.:I cannot change the ordering of the forms, 
	 * thus I send pageNumber from querystring. 
	 * XHTML Strict standards does not support 
	 * attribute "name" for the element FORM.  
	 * However, Client wants the script to be XHTML Strict. 
	 */
	doPost(objForm,"",scriptName+"?Page="+pageNumber);	
}

function shout() {
	//2004.09.16 - b.b. - added to check if user is a trial user
	
	if( USER_TRIAL.toLowerCase()== "true" ){
		alert("You are a trial user. You can not send message to this artist.");
		return;
	}
	
	//finished here
	
	
	if( USER_LOGGED_IN.toLowerCase() == "false" ) 
	{
		alert("You have to sign in before you send a comment.");
		self.location = "signin.asp";
	} 
	else 
	{
		var objForm=null;
		if(!(objForm=document.getElementById("shoutboardform")))
		{			
			return;
		}		
		
		var objComment = objForm.txtComments;
		objComment.value = objComment.value.trim();
		if( objComment.value == "" ) 
		{
		
			alert("Aren't you going to say something?");
			objComment.focus();
		} 
		else
		{ 
		
			doPost(objForm,"Send Comment");
		}
		
	}
}
/*document.open();document.write("hello");document.close();//works*/
/*function play(lngUserID,lngMediaID,intMediaType,blnPlayAll) {
	var intWidth = intPlayerWidth;
	var intHeight= intPlayerHeight;
	var strURL = "/mp3_player.asp?lngMediaID="+lngMediaID+"&lngUserID="+lngUserID+"&intMediaType="+intMediaType;
	var strName = "player";
	var strScroll = "no";
	createWindow(strURL, strName, intWidth, intHeight, strScroll);
}
*/

function download() {
	if( USER_LOGGED_IN.toLowerCase() == "false" ) {
		alert("You have to sign in before you can download trax.");
		self.location = "signin.asp";
	}
}

function deleteComment() {
	var objForm=null;
	if(!(objForm=document.forms[1]))return;
	doPost(objForm,"Delete Comment");
}
/*S.A.  Resource Adding*/
function downloadDocument()
{
    alert("You should be a user of this label for downloading documents.");
}

function deleteResource(lngDocumentID) {
	var objForm=null;
	if(!(objForm=document.forms['ResourceForm']))return;
	if(confirm("Are you sure you want to delete the selected item?")){
		objForm.lngDocumentID.value = lngDocumentID;
		doPost(objForm,"Delete Resource");
	}
}
/*S.A.  Resource Adding*/
function deleteTrack(lngTrackID) {
	var objForm=null;
	if(!(objForm=document.forms[1]))return;
	if(confirm("Are you sure you want to delete the selected item?")){
		objForm.lngTrackID.value = lngTrackID;
		doPost(objForm,"Delete Track");
	}
}

function deleteVideo(lngVideoID) {
	var objForm=null;
	if(!(objForm=document.forms[1]))return;
	if(confirm("Are you sure you want to delete the selected video?")){
		objForm.lngVideoID.value = lngVideoID;
		doPost(objForm,"Delete Video");
	}
}

function deletePicture() {
	var objForm=null;
	if(!(objForm=document.forms[1]))return;	
	if(confirm("Are you sure you want to remove your picture?"))
		doPost(objForm,"Delete Picture");
}

function deleteShout(lngShoutID) {
	
	var objForm=null;
	if(!(objForm=document.forms[1]))return;
	if(confirm("Are you sure you want to delete the selected shout?")) {
		objForm.lngShoutID.value = lngShoutID;
		doPost(objForm,"Delete Shout");
	}
}

function deleteBlog(lngBlogID) {
	var objForm=null;
	if(!(objForm=document.forms[1]))return;
	objForm.lngBlogID.value = lngBlogID;
	doPost(objForm,"Delete Blog");
}

function moveUp(intIndex,objForm) {
	var arSortOrder = objForm.sngSortOrder;	
	if( arSortOrder.length ) {
		var intMaxIndex = arSortOrder.length-1;
		if( intIndex == 0 ) swap(arSortOrder,intMaxIndex,0);
		else swap(arSortOrder,intIndex,intIndex-1);
	}
	doPost(objForm,"Sort Items");
}

function moveDown(intIndex,objForm) {
	var arSortOrder = objForm.sngSortOrder;
	if( arSortOrder.length ) {
		var intMaxIndex = arSortOrder.length-1;
		if( intIndex == intMaxIndex ) swap(arSortOrder,intMaxIndex,0);
		else swap(arSortOrder,intIndex,intIndex+1);
	}
	doPost(objForm,"Sort Items");
}

function swap(arSort,intIndexA,intIndexB){
	var objA = arSort[intIndexA];
	var objB = arSort[intIndexB];
	objA.value=objA.value^objB.value;
	objB.value=objA.value^objB.value;
	objA.value=objA.value^objB.value;
}

function setImageAttributes() {
	var image=null;
	if(!(image=getObject("UploadImage")))return;
	var lyrPreview=getObject("Preview");
	//if(image.style) {image.style.visibility = "hidden";}
	if(lyrPreview.style) {lyrPreview.style.display="none";lyrPreview.style.visibility = "hidden";}
	
	var objDim=getDimension(image);
	var width=objDim.getWidth();
	var height=objDim.getHeight();
	/*v.o.:the two lines below are for divide by zero exception*/
	width=((width<=0)?-1:width);
	height=((height<=0)?-1:height);	

	var resizedWidth = 180;
	var resizedHeight = 180;
	var resizedRatio = resizedWidth/resizedHeight;
	var actualRatio = width/height;

	if (actualRatio > resizedRatio) { if (width > resizedWidth) image.width = resizedWidth; } 
	else { if (height > resizedHeight) image.height = resizedHeight; }

	if(lyrPreview.style) {lyrPreview.style.display = "block";lyrPreview.style.visibility = "visible";}	
}

function sendChangesToPublisher() {
	var objForm=null;
	if(!(objForm=document.forms[1]))return;
	doPost(objForm,"Send Changes To Publisher")
}

function sendBack() {
	var objForm=null;
	if(!(objForm=document.forms[1]))return;
	doPost(objForm,"Send Back");
}

function goLive() {
	var objForm=null;
	if(!(objForm=document.forms[1]))return;
	doPost(objForm,"Go Live");
}

function importTrack(lngTrackID, intTrackCount) {
	var objForm=null;
	if(!(objForm=document.forms[1]))return;

	var blnConfirm = true;
	if(intTrackCount>=5) {
		var strConfirm  = "You can have at most -5- featured trax on your home page.\n";
			strConfirm += "If you import this track, the bottommost featured track on your ";
			strConfirm += "home page will be released.\n";
			strConfirm += "Are you sure this is what you want to do?";
			blnConfirm = confirm(strConfirm);
	}
	if(blnConfirm) {
		objForm.lngTrackID.value=lngTrackID;
		doPost(objForm,"Import Track");
	}
}


function changePageStatus2(objCheck) {
	var objForm = objCheck.form;
		
	if(objCheck.checked) {
		if(confirm("Are you sure you want to block this page?\nThis will make the page totally inaccessible to everyone except publishers and the page artist." )){
			objForm.intPageBlocked.value = 1;
			doPost(objForm,"Change Page Status");
		}
	}
	else {
		if(confirm("Are you sure you want to make this page live?")){
			objForm.intPageBlocked.value = 0;
			doPost(objForm,"Change Page Status");
		}
	}
}


function changePageStatus(objCheck) {
	var objForm=null;
	if(!(objForm=document.forms[2]))return;
		
	var intCurrentState = parseInt( objForm.intCurrentState.value ); 
	var objStatus1 = objForm.intPageBlocked[0];
	var objStatus2 = objForm.intPageBlocked[1];
	//alert( intCurrentState );
	if( intCurrentState == 0 && objCheck == objStatus2 ) {
		if(confirm("Are you sure you want to block this page?\nThis will make the page totally inaccessible to everyone except publishers and the page artist." )){
			doPost(objForm,"Change Page Status");
		} else {
			objForm.intPageBlocked[0].checked=true;
		}
	} else if( intCurrentState == 1 && objCheck == objStatus1 ) {
		if(confirm("Are you sure you want to make this page live?")){
			doPost(objForm,"Change Page Status");
		} else {
			objForm.intPageBlocked[1].checked=true;
		}
	}
}

function  deleteRequest(LicenseID, TrackID, SiteID){
	var objForm=null;
	if(!(objForm=document.forms['FrmPublisherComment']))return;

	if(confirm("Are you sure you want to reject this request?")){
		objForm.RejectedLicenseID.value = LicenseID;
		objForm.RejectedTrackID.value = TrackID;
		objForm.RejectedSiteID.value = SiteID;
	
		doPost(objForm,"Delete License Request");
	}
}

function  deleteLicense(LicenseID){
	var objForm=null;
	if(!(objForm=document.forms['FrmPublisherComment']))return;

	if(confirm("Are you sure you want to delete this rejected request?")){
		objForm.DeleteLicenseID.value = LicenseID;
	
		doPost(objForm,"Delete License");
	}
}

function whatIsThisMessage(){
	var temp = confirm('This is Request to Licensing for your Track. If you agree with this request click "Yes" and you will yield consent.');
	return;
}

function  acceptLicense(task, LicenseID, TrackID, SiteID, RequiredPoints){
	var objForm=null;
	if(!(objForm=document.getElementById('LicenseForm1'))) return;

	objForm.requestState.value = task;
	objForm.LicenseID.value = LicenseID;
	objForm.TrackID.value = TrackID;
	objForm.SiteID.value = SiteID;
	objForm.RequiredPoints.value = RequiredPoints;
	objForm.submit();
	//doPost(objForm,"AcceptLicense");
}

function SortBlog(type)
{
	var objForm=null;
	if(!(objForm=document.forms['FrmPublisherComment']))return;

	objForm.BlogSortDirection.value = type;
	
	doPost(objForm,"");
}

function tellUs()
{
	var objForm=null;
	if(!(objForm=document.getElementById('shoutboardform'))) return;//document.forms[6])) return;
	doPost(objForm,"Tell Us");
	alert ("Thanks, we will check this out. You can contact us at members@numu.org.uk");
}

var FrmPaging=null;
function showPagerPage(pageNumber) {
	var objForm=FrmPaging;
	if(!objForm)return;
	objForm.Page.value=pageNumber;
	doPost(objForm);	
}

