songcentral.songFormControls=Class.create
(
	{
		initialize: function()
		{
			$('songForm').reset();
			if ($F('genre_0')>0) $('parent_id_'+$F('genre_0')).blindDown({duration:0.6});
			$('genre_0').observe
			(
				'change',
				this.show_subGenre
			).observe
			(
				'on:valueChange',
				this.show_subGenre
			);
			return;
		},
/*
		show_subGenre: function()
		{
			var effectDuration=0.6;
			$$('fieldset.subgenre').invoke
			(
				'blindUp',
				{duration:effectDuration}
			);
			if ($F(this) && !$('parent_id_'+$F(this)).visible())
			{
				(function()
				{
					try
					{
						$('parent_id_'+$F(this)).blindDown({duration:effectDuration});
					}
					catch(e){}
				}.bind(this)).delay(effectDuration+0.2);
			}
			return;
		}
*/
		show_subGenre: function() {
			var effectDuration=0.6;
			$$('fieldset.subgenre').each
			(function(element) {
				if(element.visible()) {
					element.blindUp({duration:effectDuration});
					return; //... because should only be one element visible at a time.
				}
			});
			if ($F(this) > 0 && !$('parent_id_'+$F(this)).visible()) $('parent_id_'+$F(this)).blindDown({duration:effectDuration});
			return;
		}
	}
);
songcentral.subscription=Class.create
(
	{
		config:
		{
			price_selects: []
		},
		initialize: function(config)
		{
			//Set config.
			this.config=Object.extend(this.config,config);
			$('membership_subscription').reset();
			this.config.price_selects.collect
			(
				function(element)
				{
					return $(element);
				}
			).each
			(
				function(element)
				{
					element.observe('click',this.setSlectionResult);
					if (element.checked)
					{
						this.setSlectionResult.bind(element)();
					}
					return;
				}.bind(this)
			);
			return;
		},
		setSlectionResult: function()
		{
			var idNum = this.value;
			var idFee = 'subscpn_fee_L'+idNum;
			if ($(idFee))
			{
				var fPrice = $(idFee).innerHTML;
				if ($('pp_a3')) $('pp_a3').value=fPrice;
			}
			$$('tr.selected').each(function(item)
			{
				item.removeClassName('selected');
			});
			var priceTblRow = 'Subscpn_L'+idNum;
			if ($(priceTblRow))
			{
				$(priceTblRow).addClassName('selected');
			}
		}
	}
);
songcentral.purchase=Class.create
(
	{
		config:
		{
			price_selects: [],
			currentStatus: false,
			paypal:
			{
				form:null,
				qtyDefault:false,
				qtyInput:null,
				inputMsg:null,
				btnSubmit:null
			}
		},
		initialize: function(config)
		{
			//Set config.
			this.config=Object.extend(this.config,config);
			$('songfiles_purchase').reset();
			this.config.paypal.form=$('paypalWidget');
			if(this.config.paypal.form)
			{
				this.config.paypal.qtyInput=this.config.paypal.form.down('#paypalQuantity');
				this.config.paypal.btnSubmit=this.config.paypal.form.down('#paypalSubmitBtn');
				this.config.paypal.inputMsg=this.config.paypal.form.down('#paypalInputMsg');
				if(this.config.paypal.qtyInput && Object.isFunction(this.config.paypal.qtyInput.getValue))
				{
					this.config.paypal.qtyDefault=this.config.paypal.qtyInput.getValue();
					this.config.paypal.qtyInput.setValue('0');
					if(this.config.paypal.inputMsg)
					{
						this.config.paypal.inputMsg.removeClassName('hidden');
					}
					this.config.paypal.qtyInput.observe('change',this.onPayPalInputChange.bind(this));
				}
				this.config.paypal.form.observe('submit',this.onPayPalSubmit.bind(this));
			}
			this.config.price_selects.collect
			(
				function(element)
				{
					return $(element);
				}
			).each
			(
				function(element)
				{
					element.observe('click',this.setSlectionResult.bind(this,element));
					if (element.checked)
					{
						this.setSlectionResult(element);
					}
					return;
				}.bind(this)
			);
			return;
		},
		onPayPalInputChange: function(event)
		{
			if(this.config.paypal.qtyInput && Object.isFunction(this.config.paypal.qtyInput.getValue))
			{
				var qty=this.config.paypal.qtyInput.getValue();
				if(!(qty-0))
				{
					if(this.config.paypal.inputMsg && this.config.paypal.inputMsg.hasClassName('hidden'))
					{
						this.config.paypal.inputMsg.removeClassName('hidden');
					}
				}
				else
				{
					if(this.config.paypal.inputMsg && !this.config.paypal.inputMsg.hasClassName('hidden'))
					{
						this.config.paypal.inputMsg.addClassName('hidden');
					}
				}
			}
		},
		onPayPalSubmit: function(event)
		{
			if(this.config.paypal.qtyInput && Object.isFunction(this.config.paypal.qtyInput.getValue))
			{
				var qty=this.config.paypal.qtyInput.getValue();
				if(!(qty-0))
				{
					alert('You must first enter a token-quantity before submitting to PayPal!');
					Event.stop(event);
					return false;
				}
			}
			return true;
		},
		getPurchaseWarningsList: function(idNum)
		{
			var warningItems=[];
			var versionStatus=this.config.currentStatus;
			if(idNum==1)
			{
				if(versionStatus.showcase_duedays>0)
				{
					if(versionStatus.showcase_type==2)
					{
						warningItems.push($('warning_service_1_1'));
					}
					else
					{
						warningItems.push($('warning_service_1_2'));
					}
				}
				if(!versionStatus.version_hassound)
				{
					warningItems.push($('warning_service_1_3'));
				}
			}
			else if(idNum==2)
			{
				warningItems.push($('warning_service_2_0'));
				if(versionStatus)
				{
					if(versionStatus.showcase_duedays>0)
					{
						warningItems.push($('warning_service_2_2'));
					}
				}
				if(!versionStatus.version_haslyrics)
				{
					warningItems.push($('warning_service_2_3'));
				}
			}
			return warningItems;
		},
		setSlectionResult: function(element)
		{
			var idNum = element.value;
			var idFee = 'service_fee_'+idNum;
			if ($(idFee))
			{
				var fPrice = $(idFee).innerHTML;
				if(idNum==1)
				{
					var versionStatus=this.config.currentStatus;
					if(versionStatus && versionStatus.showcase_duedays>0 && versionStatus.showcase_type==2)
					{
						//...then user already has an existing showcase for lyrics only. Therefore adjust fPrice to the difference between two services.
						fPrice=fPrice-$('service_fee_2').innerHTML;
					}
				}
				if ($('trans_qty')) $('trans_qty').value=(0-fPrice);
				if (!Object.isUndefined(this.config) && this.config.paypal.qtyInput)
				{
					this.config.paypal.qtyInput.value=fPrice;
				}
				if(this.config.paypal.inputMsg && !this.config.paypal.inputMsg.hasClassName('hidden'))
				{
					this.config.paypal.inputMsg.addClassName('hidden');
				}
			}
			$$('tr.selected').each(function(item)
			{
				item.removeClassName('selected');
			});
			var priceTblRow = 'Service_L'+idNum;
			if ($(priceTblRow))
			{
				$(priceTblRow).addClassName('selected');
			}
			var theFootNote = 'service_foot_'+idNum;//(idNum==2?1:idNum);
			$$('ul.serviceFootnote').each(function(item)
			{
				if(item != theFootNote) item.hide();
			});
			if ($(theFootNote))
			{
				$(theFootNote).show();
			}
			var itemsList=this.getPurchaseWarningsList(idNum);
			var theWarnings_ul = 'warning_service_'+idNum;//(idNum==2?1:idNum);
			$$('ul.serviceWarnings').each(function(item)
			{
				if(item != theWarnings_ul) item.hide();
			});
			if(!itemsList.length)
			{
				$('service_warnings').hide();
			}
			else
			{
				$('service_warnings').show(); 	//... is the (div) wrapper for ALL warnings
				$(theWarnings_ul).show(); 		//... is the UL containing warning messages related to the selected service
				$(theWarnings_ul).select('li').each
				(
					function(item)
					{
						if (itemsList.in_array(item))
						{
							item.show();
						}
						else
						{
							item.hide();
						}
						return;
					}//.bind(this)
				)
			}
		}
	}
);
songcentral.reviewAdmin=Class.create
(
	{
		initialize: function()
		{
			$('reviewAdmin').reset();
			//Disable input elements related to reviewer's response.
			$$('#reviewResponse input, #reviewResponse textarea').each(function(item)
			{
				item.disabled=true;
			});
			if ($F('send_email_reviewer')) $('emailReviewer').blindDown({duration:0.6});
			if ($F('send_email_customer')) $('emailCustomer').blindDown({duration:0.6});
			$('send_email_reviewer').observe
			(
				'change',
				this.toggle_email_reviewer
			).observe
			(
				'on:valueChange',
				this.toggle_email_reviewer
			);
			$('send_email_customer').observe
			(
				'change',
				this.toggle_email_customer
			).observe
			(
				'on:valueChange',
				this.toggle_email_customer
			);
		},
		toggle_email_reviewer: function()
		{
			if ($F(this))
			{
				$('emailReviewer').blindDown({duration:0.2});
			}
			else
			{
				$('emailReviewer').blindUp({duration:0.2});
			}
			return;
		},
		toggle_email_customer: function()
		{
			if ($F(this))
			{
				$('emailCustomer').blindDown({duration:0.2});
			}
			else
			{
				$('emailCustomer').blindUp({duration:0.2});
			}
			return;
		}
	}
);
songcentral.composer=Class.create
(
	{
		initialize: function()
		{
			$('membership_composer').reset();
			[$('isUnder18_0'),$('isUnder18_1')].invoke
			(
				'observe',
				'click',
				this.changeIsUnder18Slection
			);
			[$('cat_id_10_11'),$('cat_id_10_12')].invoke
			(
				'observe',
				'click',
				this.changeProArtistSlection
			);
/*
			[$('cat_id_12_13'),$('cat_id_12_14')].invoke
			(
				'observe',
				'click',
				this.iAm
			);
*/
			// Hide following elements that don't have the right (show) values.
//			if ($('cat_id_12_14') && $F('cat_id_12_14')!=14) $('proArtist_singer').hide();	//in_idSongWriter
//			if ($('cat_id_12_13') && $F('cat_id_12_13')!=13) $('proArtist_songWriter').hide();//in_idSongWriter
			if ($('cat_id_10_12') && $F('cat_id_10_12')!=12) $('proArtist_iAm').hide();		//in_idProfessional
			if ($('isUnder18_1') && $F('isUnder18_1')!=1) $('under18_iAm').hide();
			return;
		},
		changeIsUnder18Slection: function()
		{
			if ($F(this)==1)
			{
				$('under18_iAm').blindDown({duration:0.2});
			}
			else
			{
				$('under18_iAm').blindUp({duration:0.2});
			}
			return;
		},
		changeProArtistSlection: function()
		{
			if ($F(this)==12) //this.value==12 || 
			{
				$('proArtist_iAm').blindDown({duration:0.2});
			}
			else
			{
				$('proArtist_iAm').blindUp({duration:0.2});
			}
			return;
		},
		iAm: function()
		{
			if (this.identify()=='cat_id_12_13') //in_idSongWriter
			{
				if ($F(this)==13) //this.value==13 || 
				{
					$('proArtist_songWriter').blindDown({duration:0.2});
				}
				else
				{
					$('proArtist_songWriter').blindUp({duration:0.2});
				}
			}
			else if (this.identify()=='cat_id_12_14') //in_idSinger
			{
				if ($F(this)==14) //this.value==14 || 
				{
					$('proArtist_singer').blindDown({duration:0.2});
				}
				else
				{
					$('proArtist_singer').blindUp({duration:0.2});
				}
			}
			return;
		}
	}
);
songcentral.changeLogin=Class.create
(
	{
		initialize: function()
		{
			$('account_changelogin').reset();
			[$('change_email_1')].invoke
			(
				'observe',
				'click',
				this.changeEmailSlection
			);
			[$('change_password_1')].invoke
			(
				'observe',
				'click',
				this.changePasswordSlection
			);
			// Hide following elements if they don't have the right (show) values.
			if ($('change_email_1') && $F('change_email_1')!=1) $('change_email_group').hide();
			if ($('change_password_1') && $F('change_password_1')!=1) $('change_password_group').hide();
			return;
		},
		changeEmailSlection: function()
		{
			if ($F(this)==1)
			{
				$('change_email_group').blindDown({duration:0.2});
			}
			else
			{
				$('change_email_group').blindUp({duration:0.2});
			}
			return;
		},
		changePasswordSlection: function()
		{
			if ($F(this)==1)
			{
				$('change_password_group').blindDown({duration:0.2});
			}
			else
			{
				$('change_password_group').blindUp({duration:0.2});
			}
			return;
		}
	}
);
songcentral.tender=Class.create
(
	{
		initialize: function()
		{
			$('tenderForm').reset();
			[$('tender_deadline')].invoke
			(
				'observe',
				'change',
				this.changeDeadlineDate
			);
			[$('tenderstatus_id')].invoke
			(
				'observe',
				'change',
				this.changeStatus
			);
			// Disable in-appropriate status selections.
			return;
		},
		changeDeadlineDate: function()
		{
			magicDate(this);
			return;
		},
		changeStatus: function()
		{
			var col_4=this.up('li').next();
			if(this.value==-9)
			{
				col_4.update('<blink><b class="standout">NB: This tender will NOT be visible in your tenders list once you have submitted this status-value choice!</b></blink>');
			}
			else if(!col_4.empty())
			{
				col_4.update('');
			}
			return;
		}
	}
);

