/*
  FusionWare Plug-in for osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com
  
  Copyright (c) 2009 FusionWare Integration Corp.

  Released under the GNU General Public License
 
This program has been added by FusionWare Integration Corp. to allow osCommerce to link to almost any 
commercial point-of-sale (POS) system through a standardized Web Services interface.  The web services 
interface provides a layer of abstraction that provides several significant benefits:

1.	It allows you to change your POS system without having to change the web.
2.	It allows you to change your web store software without having to change the interface to your POS 
system.
3.	It allows other systems, intranet or extranet based, to leverage these interfaces.
4.	It provides a single point of access to your POS system that can be more easily secured and 
controlled.

In particular, this modified version of osCommerce will:

-	Expose a MySQL stored procedure that can be used to update the osCommerce products from the POS 
system.
-	Push any new users into the POS system, retrieving a unique identifier from the POS system.
-	Retrieve QOH from the POS system whenever this field is accessed by osCommerce.
-	Send order information to the POS system, then invoke the POS system to process the order.
-	Provide several maintenance procedures to allow users to keep the POS system and the osCommerce web 
in sync.

Contact FusionWare Integration Corp. for a copy of the source code for these changes at:
Web: http://www.fwic.net
Phone: +1-604-777-4254
Email: info@fwic.net

FusionWare Integration Corp. Change Log:
Developer	Change Date	Description
G.Ashley	2009-09-01	Created to include content from the Ted Brown Music legacy web site
*/
// JavaScript Document
// this function opens a window without any toolbars
function open_win(url,width,height) {
	window.open(url,'new_window',"toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width="+width+", height="+height);
	//window.open(theURL,winName,features);
}
function myFocus(element) {
   if (element.value == element.defaultValue) {
     element.value = '';
   }
 }
function myBlur(element) {
   if (element.value == '') {
     element.value = element.defaultValue;
   }
}
function pleaseWait(table,row,cell) {
	var x=document.getElementById(table).rows[row].cells;
	x[cell].innerHTML="Please Wait...";
}
function repeatDay(element) {
	if (element.checked) {
		var x=document.getElementById("repeat").rows["0"].cells;
		x["1"].innerHTML="&nbsp;&nbsp;&nbsp;Please choose the repeat day.&nbsp;&nbsp;&nbsp;<select name=\"repeat_day\" class=\"inputfield\" size=\"1\"><option>- select -</option><option value=\"0\">Sunday</option><option value=\"1\">Monday</option><option value=\"2\">Tuesday</option><option value=\"3\">Wednesday</option><option value=\"4\">Thursday</option><option value=\"5\">Friday</option><option value=\"6\">Saturday</option></select>";
	} else {
		var x=document.getElementById("repeat").rows["0"].cells;
		x["1"].innerHTML="&nbsp;";
	}
}
function registerInfo(element) {
	if (element.checked) {
		var x=document.getElementById("registerTable").rows["0"].cells;
		x["0"].innerHTML="<img src=\"images/spacer.gif\" width=\"100%\" height=\"5\"><table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" id='registerInfo'><tr><td align=\"right\" class=\"pagetext\" width='150'>Price:&nbsp;&nbsp;</td><td align=\"left\" class=\"pagetext\"><input type=\"text\" name='price' class='inputfield' size='20'><span class='required'>&nbsp;*</span</td></tr><tr><td colspan='2'><img src=\"images/spacer.gif\" width=\"100%\" height=\"5\"></td></tr><tr><td align=\"right\" class=\"pagetext\" width='150'>Organizer Email:&nbsp;&nbsp;</td><td align=\"left\" class=\"pagetext\"><input type=\"text\" name='oemail' class='inputfield' size='40'><span class='required'>&nbsp;*</span</td></tr><tr><td colspan='2'><img src=\"images/spacer.gif\" width=\"100%\" height=\"5\"></td></tr><tr><td align=\"right\" class=\"pagetext\" width='150'>Processor Email:&nbsp;&nbsp;</td><td align=\"left\" class=\"pagetext\"><input type=\"text\" name='pemail' class='inputfield' size='40'><span class='required'>&nbsp;*</span</td></tr><tr><td colspan='2'><img src='images/spacer.gif' width='100%' height='10'></td></tr><tr><td align='left' colspan='2' class='pagetext'>These fields will already be included on the registration forms.</td></tr><tr><td>&nbsp;</td><td align='left' class='pagetext'>First Name, Last Name, Phone Number, Address, City, State, Zip, Email</td></tr><tr><td colspan='2'><img src='images/spacer.gif' width='100%' height='10'></td></tr><tr><td align='left' colspan='2' class='pagetext'>Would you like to add more information fields?</td></tr><tr><td>&nbsp;</td><td align='left' class='pagetext'><a href='javascript:addField()'><b>add field</b></a>&nbsp;&nbsp;&nbsp;<a href='javascript:removeField()'><b>remove field</b></a></td></tr></table>";
	} else {
		var x=document.getElementById("registerTable").rows["0"].cells;
		x["0"].innerHTML="<img src=\"images/spacer.gif\" width=\"100%\" height=\"5\">";
	}
}
function addField(row)
{
  var tbl = document.getElementById('registerInfo');
  var lastRow = tbl.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration = lastRow - 1;

$(row).up().up().insert({before:"<tr><td align='right' class='pagetext'>Info Field:&nbsp;&nbsp;</td><td align='left' class='pagetext'>Name:&nbsp;<input type='text' name='field_name[]' id='field_name"+iteration+"' size='30' class='inputfield'>&nbsp;&nbsp;&nbsp;Size:&nbsp;<input type='text' name='size[]' id='size"+iteration+"' size='20' class='inputfield'>&nbsp;&nbsp;&nbsp;Required?&nbsp;<select name='requ[]' id='requ"+iteration+"' class='inputfield'><option>yes</option><option>no</option></select></td></tr>"});
}
function removeField()
{
  var tbl = document.getElementById('registerInfo');
  var lastRow = tbl.rows.length;
  if (lastRow > 4) tbl.deleteRow(lastRow - 2);
}
function doNav(theUrl) {
	document.location.href = theUrl;
}
function viewDiv(div) {
	document.getElementById(div).style.display="block";
}

function hideDiv(div) {
	document.getElementById(div).style.display="none";
}
function changeCursor(tableRow, highLight) {
	if (highLight) {
		tableRow.style.cursor="pointer";
	}
}
function deleteUser(id) {
	if(confirm('Are you sure you want to delete this user?')) {
		doNav('admin_users.php?action=process&section=delete&id='+id);
	}
}
function deleteTeacher(id) {
	if(confirm('Are you sure you want to delete this teacher?')) {
		doNav('admin_lessons.php?action=process&section=delete&id='+id);
	}
}
function deleteEmail(id) {
	if(confirm('Are you sure you want to delete this email from the mailing list?')) {
		doNav('admin_mailinglist.php?action=process&section=delete&id='+id);
	}
}
function selectAll(ids) {
	var ids = ids.split(" ");
	if(document.getElementById('selectall').checked == true) {
		var idcount = ids.length;
		for(i=0;i<idcount;i++) {
			document.getElementById('list'+ids[i]).checked = true;
		}
	} else if(document.getElementById('selectall').checked == false) {
		var idcount = ids.length;
		for(i=0;i<idcount;i++) {
			document.getElementById('list'+ids[i]).checked = false;	
		}
	}
}
function accountHover(tableRow, highLight) {
	if (highLight) {
		tableRow.className = "accounthover";
		tableRow.style.cursor="pointer";
	} else {
		tableRow.className = "account";
	}
}
function deleteGallery(id) {
	var remove = confirm('This will delete this gallery as well as all photos and categories within this gallery.  This action is unrecoverable. Are you sure you want to delete this gallery?');
	if(remove == true) {
		doNav('admin_photos.php?action=process&section=deletecat&catid='+id);	
	}
}
function deletePhoto(catid,id) {
	var remove = confirm('You are about to delete this photo from the database.  This action is unrecoverable. Are you sure you want to delete this photo?');
	if(remove == true) {
		doNav('admin_photos.php?action=process&section=deletephoto&catid='+catid+'&id='+id);	
	}
}
function openPhoto(id) {
	var w = document.viewport.getWidth();
	var start = w/2;
	var left = start - 350;
	new Effect.Move('loadingFrame',{x:left,y:0,mode:'absolute',duration:0});
	new Effect.SlideDown('loadingFrame',{duration:.5});
	new Ajax.Request('ajax_largeimage.php?id='+id,
		 {
			method:'get',
			onSuccess: function(text){
			  var response = text.responseText || "no response text";
			  document.getElementById('largePhotoPlaceholder').innerHTML = response;
				var w = document.viewport.getWidth();
				var start = w/2;
				var left = start - 350;
				new Effect.Move('largePhotoFrame',{x:left,y:0,mode:'absolute',duration:0});
			  document.getElementById('img'+id).onload = function() {
			    new Effect.SlideUp('loadingFrame',{duration:.5});
				new Effect.SlideDown('largePhotoFrame',{queue:'end'}); 
			  }
			},
			onFailure: function(){ 
				alert('Something went wrong...')
				new Effect.SlideUp('loadingFrame');
			}
		  });
}
function closePhoto() {
	new Effect.SlideUp('largePhotoFrame');	
}
function deleteBox(id) {
	var remove = confirm('You are about to delete this box from the database.  This action is unrecoverable. Are you sure you want to delete this box?');
	if(remove == true) {
		doNav('admin_boxes.php?action=process&section=delete&id='+id);	
	}
}
function deleteRental(id) {
	var remove = confirm('You are about to delete this rental application from the database.  This action is unrecoverable. Are you sure you want to delete this rental application?');
	if(remove == true) {
		doNav('tbm_admin_rentals.php?action=process&section=delete&id='+id);
	}
}
function linkTracker(id) {
	doNav('linktracker.php?id='+id);
	return false;
}
function popUp(url,width,height) {
	window.open(url, '" + id + "', 'toolbar=1,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=0,width='+width+',height='+height);
	return false;
}