
// JavaScript Document
/**********
* Copyright 2007 Gregg B Larson
* All Rights reserved
***********/

function tabcontrol(tctrl){
		this.tabcreator = tctrl;
		this.ssLabel = document.createElement('label');
		this.ssLabel.innerHTML = "Spacing";
		
		//the Spacing dropdown
		this.selSpace = document.createElement('select');
		this.selSpace.name = "selSpace";
		this.selSpace.id = "selSpace";
		this.selSpace.options[1] = new Option("1", "2",false);
		this.selSpace.options[2] = new Option("2", "3",true);
		this.selSpace.options[2].selected = true;
		this.selSpace.options[3] = new Option("3", "4",false);
		this.selSpace.options[4] = new Option("4", "5",false);
		this.selSpace.options[5] = new Option("5", "6",false);
		
	//Clipboard button
		this.btnForum = document.createElement('input');
		this.btnForum.value = "Format for Forums";
		this.btnForum.type = "button";
		this.btnForum.id = "btnForum";
		this.btnForum.title = "Format tab to be used in forums like phpbb or vbulletin.";
		this.btnForum.name = "btnForum";
		
		this.chkForum = document.createElement('input');
	this.chkForum.type = 'checkbox';
	this.chkForum.name = 'ForumFormat';
	this.chkForum.id = 'ForumFormat';
	this.chkForum.defaultChecked = false;
	this.chkForum.value = 'Format for Forums';
	this.chkForum.title = "Format tab to be used in forums like phpbb or vbulletin.";
	
	this.spanlabel = document.createElement('span');
		this.spanlabel.id="lbltiming";
		this.spanlabel.innerHTML = "Forum Format";

		
		//Clipboard button
		this.btnClipboard = document.createElement('input');
		this.btnClipboard.value = "Copy Tab to Clipboard";
		this.btnClipboard.type = "button";
		this.btnClipboard.id = "btnClipboard";
		this.btnClipboard.title = "If you are using IE, it will copy to the clipboard, for everyone else, it will highlight it and you have to manually copy it.";
		this.btnClipboard.name = "btnClipboard";

				//btnEmail
		this.btnEmail = document.createElement('input');
		this.btnEmail.type = "button";
		this.btnEmail.id = "btnEmail";
		this.btnEmail.value = "Email Tab";
		this.btnEmail.title = "Email the tab.";
		this.btnEmail.name = "btnEmail";
		
		//btnClear
		this.btnClear = document.createElement('input');
		this.btnClear.type = "button";
		this.btnClear.id = "btnClear";
		this.btnClear.value = "Start Over";
		this.btnClear.title = "Click here to start over with a new tab.";
		this.btnClear.name = "btnClear";
			
		//btnRF
		this.btnRF = document.createElement('input');
		this.btnRF.type = "button";
		this.btnRF.id = "btnRF";
		this.btnRF.value = "Refresh Fretboard";
		this.btnRF.title = "clear data";
		this.btnRF.name = "btnRF";	
				
		//btnsave
		this.btnsave = document.createElement('input');
		this.btnsave.type = "button";
		this.btnsave.id = "btnsave";
		this.btnsave.value = "Save";
		this.btnsave.title = "save your tab as a cookie";
		this.btnsave.name = "btnsave";	
						
		//btnrecall
		this.btnrecall = document.createElement('input');
		this.btnrecall.type = "button";
		this.btnrecall.id = "btnrecall";
		this.btnrecall.value = "Load";
		this.btnrecall.title = "Use this to retrieve the tab you saved";
		this.btnrecall.name = "btnrecall";	
		
		//btnAddRow
		this.btnAddRow = document.createElement('input');
		this.btnAddRow.type = "button";
		this.btnAddRow.id = "btnAddRow";
		this.btnAddRow.value = "New Row";
		this.btnAddRow.title = "Add another Row to the tab.  Note: You will not be able to edit the tab after this action.";
		this.btnAddRow.name = "btnAddRow";	
		
		//btnPlayback
		this.btnPlayback = document.createElement('input');
		this.btnPlayback.type = "button";
		this.btnPlayback.id = "btnPlayback";
		this.btnPlayback.value = "Numbering";
		this.btnPlayback.title = "Show the sequence to play the tab";
		this.btnPlayback.name = "btnPlayback";	
		
		//btnFacebook
		this.btnFacebook = document.createElement('input');
		this.btnFacebook.type = "button";
		this.btnFacebook.id = "btnFacebook";
		this.btnFacebook.value = "Post to Facebook";
		this.btnFacebook.title = "Post your tab to facebook";
		this.btnFacebook.name = "btnFacebook";
		
		//help link
		this.helplink = document.createElement('a');
		this.helplink.setAttribute('class', 'help');
		this.helplink.setAttribute('target', 'help');
		this.helplink.setAttribute('href', 'http://blog.guitartabcreator.com/2010/02/using-tab-controls.html');
		this.helplink.innerHTML = "help";
		

		this.allbuttons = function(div){
			this.div = div;
			//put em all in the div
			this.div.appendChild(this.ssLabel);
			this.div.appendChild(this.selSpace);
			this.div.appendChild(this.btnClipboard);
			this.div.appendChild(this.chkForum);
			this.div.appendChild(this.spanlabel);		
			this.div.appendChild(this.btnClear);
			//this.div.appendChild(this.btnRF);
			this.div.appendChild(this.btnsave);
			this.div.appendChild(this.btnrecall);
			this.div.appendChild(this.btnEmail);
			this.div.appendChild(this.btnAddRow);
			this.div.appendChild(this.btnPlayback);
			this.div.appendChild(this.btnFacebook);
			this.div.appendChild(this.helplink);
	
			//these are the event captures for each control
			
			Event.observe($(this.btnFacebook), 'click', function(event){
				callPublish('',null,null);
				return false;
			}.bindAsEventListener(this.tabcreator));
			
			
			//changes to the Spacing
			Event.observe($(this.selSpace), 'change', function(event){
				 this.Spacing = Event.element(event).value;
				 this.printtab(0);
			}.bindAsEventListener(this.tabcreator));
			
			//press the clipboard
			Event.observe($(this.btnClipboard), 'click', function(event){
				  if (this.tabout.createTextRange) 
				  {
					var range = this.tabout.createTextRange();
					if (range && BodyLoaded==1)
					  range.execCommand('Copy');
				  } else 
				  {
					var flashcopier = 'flashcopier';
					if(!document.getElementById(flashcopier)) {
					  var divholder = document.createElement('div');
					  divholder.id = flashcopier;
					  document.body.appendChild(divholder);
					}
					document.getElementById(flashcopier).innerHTML = '';
					var divinfo = '<embed src="_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(this.tabout.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
					document.getElementById(flashcopier).innerHTML = divinfo;
				  }
			}.bindAsEventListener(this.tabcreator));
			
			//StartOver
			Event.observe($(this.btnClear), 'click', function(event){
				if(confirm("Continuing will delete your current work.  Are you sure you want to continue?")){									
				 	this.SO();
				}
			}.bindAsEventListener(this.tabcreator));
			
			Event.observe($(this.btnEmail), 'click', function(event){
				 this.email();
			}.bindAsEventListener(this.tabcreator));
			//save tab to harddrive
			Event.observe($(this.btnsave), 'click', function(event){
				 this.savetab();
			}.bindAsEventListener(this.tabcreator));
			
			//retrieve tab from HD
			Event.observe($(this.btnrecall), 'click', function(event){
				 this.recall();
			}.bindAsEventListener(this.tabcreator));
			
			//respond to format forum check
			Event.observe($(this.chkForum), 'click', function(event){
				 this.formatForum();
			}.bindAsEventListener(this.tabcreator));
			
			//add row
			Event.observe($(this.btnAddRow), 'click', function(event){
				if(confirm("You will not be able to go back and edit the previous line.  Are you sure you want to continue?")){		
				 this.NL();
				}
			}.bindAsEventListener(this.tabcreator));
			
			//show numbers 
			Event.observe($(this.btnPlayback), 'click', function(event){
				 this.InitializeTimer();
			}.bindAsEventListener(this.tabcreator));
		}
		
}

