var prevIxTarg;
var curTRow;
var curRow;

var clTableName="classTablePri.html";
var sec=false;
var uQuery=window.location.href.split('?'); 
if ( uQuery.length>1) {
	if (uQuery[1]=='p=sec' ){
		sec=true;
		clTableName="classTableSec.html";
	} 
} 

var dsSched=new Spry.Data.HTMLDataSet(clTableName,"base"); 
var dsTitle=new Spry.Data.HTMLDataSet(clTableName,"title"); 
function setTitle() {
	dsTitle.addObserver(postLoad);
}

function postLoad(notType, notifier, data) { 
	if (notType!="onPostLoad") { return; }
  curTRow=dsTitle.getCurrentRow();
	if (!sec&&(curTRow['sessNew'].toUpperCase())=='YES') { 
		document.getElementById('clLinkPri').style.display='inline';
	}
	if (sec) { 
		document.getElementById('clLinkSec').style.display='inline';		
	}
}

function sortIxTable(a,target) {
  if (a=='Class' || a == 'Instructor') dsSched.sort([a,'DayCode','TimeCode'],'ascending'); 
	if (a=='TimeCode') dsSched.sort([a,'DayCode'],'ascending');  
	if (a=='DayCode')  dsSched.sort([a,'TimeCode'],'ascending'); 
	
	if (prevIxTarg!=target) { 
		target.className='headerSelect'; 
		if (prevIxTarg!= ull) { prevIxTarg.className='header'; };
		prevIxTarg=target; 
	}
}

function loadClass() {
	curRow=dsSched.getCurrentRow(); 
	var str=curRow['Enroll'].toLowerCase();
	if (str=='sign up') {
		document.getElementById('lightBox').style.visibility='visible';
		document.getElementById('sendForm').style.visibility='visible';
		document.getElementById('$Div').innerHTML='Select number of classes';
		var fld=document.forms[0].elements['rbSel']; 
		for (var i=0;i<fld.length;i++) { 
			fld[i].checked=false;
		}
		document.getElementById('sDiv').innerHTML=(curTRow['sessSession']);
 		document.getElementById('cDiv').innerHTML=(function(str) {var ix=str.search(/<span/i);if(ix!=-1){str=str.substring(0,ix)}return str;})(curRow['Class']); 
		document.getElementById('dDiv').innerHTML=(curRow['Day'])+'s';
		document.getElementById('tDiv').innerHTML=(curRow['Time']);
		document.getElementById('iDiv').innerHTML=(curRow['Instructor']);			
	}
}

function checkform() { 
	var rChoice=false;
  var fld=document.forms[0].elements['rbSel']; 
  for (var i=0;i<fld.length;i++) { 
		if (fld[i].checked) { rChoice = true; }
	}
	if (!rChoice) {
		alert("Please select the number of classes.")
		return (false);
	}
	document.getElementById('lightBox').style.visibility='hidden';
	document.getElementById('sendForm').style.visibility='hidden';
	return (true);
}

function paperform() {
	var chk=checkform();
	if (chk==false) { return; }
	var allcookies=document.cookie; 
	if (allcookies!="") {	
		var aCookie=allcookies.split(';'); 
		var theCookie=null;
		for (var i=0;i<aCookie.length;i++) {  
			var sA=aCookie[i].search('name=yogaseva') 
			if (sA!=-1) {
				theCookie=aCookie[i];
				var date=new Date();
				document.cookie=theCookie + ";expires=" + date.toGMTString() + ";" ; // get rid of it by expiring
			}
		}
	}
	var a=document.getElementById('sDiv').innerHTML;
	var b=document.getElementById('cDiv').innerHTML;
	var c=document.getElementById('dDiv').innerHTML;
	var d=document.getElementById('tDiv').innerHTML;
	var e=document.getElementById('iDiv').innerHTML;
	var g=document.getElementById('$Div').innerHTML;
	var fld=document.forms[0].elements['rbSel']; 
  for (var i=0;i<fld.length;i++) { 
  	if (fld[i].checked) { var f=fld[i].value; }
	}
	document.cookie = 'name=yogaseva/' + a + '/' + b + '/' + c + '/' + d + '/' + e + '/' + f+ '/' + g; 
	window.open('class_print.html','_blank','width=750,scrollbars=yes, menubar=yes, toolbar=no,resizable=yes');
}

function change(a) { 
	if (curRow['Cost']!='-1' ) {
		cost=curRow['Cost']*a;
		cost='$'+cost;
	} else { 
		switch(a) {
			case '12':
				cost='$120';
				break;
  		case '10':
				cost='$110';
				break;
			case '8':
				cost='$96';
				break;
			case '6':
				cost='$75';
				break; 
			case '1':
				cost='$15';
				break;
		}
	}
	document.getElementById('$Div').innerHTML=cost;
	document.forms[0].item_name.value=(curTRow['sessSession'])+' '+(curRow['Day'])+'s  '+(curRow['Time']);	
	document.forms[0].amount.value=cost.substring(1,cost.length)+'.00';	<!-- format for PayPal = xx.xx -->
	document.forms[0].os0.value=a+' class(es)';
}

function cancelIt() {
	var fld=document.forms[0].elements['rbSel']; 
	for (var i=0;i<fld.length;i++) { 
		fld[i].checked=false;
	}
	document.getElementById('$Div').innerHTML='Select number of classes';
	document.getElementById('lightBox').style.visibility='hidden';
	document.getElementById('sendForm').style.visibility='hidden';
}

var menuTop=-310;
var menuLeft=110;
var lbl;
function showPop(e,targ)  { 
	var posy=0;
	if (!e) var e=window.event;
	if (e.pageY) 	{
		posy=e.pageY;
	} else { 
		if (e.clientY) 	{
		posy=e.clientY + document.body.scrollTop+ document.documentElement.scrollTop;
		}
	}
		 
	var cursRow=dsSched.getCurrentRow();
	var x=(cursRow['Code']);
	lbl=document.getElementById(x);
	lbl.style.visibility='visible';
	lbl.style.top=posy + menuTop +'px';
	lbl.style.left=targ.offsetLeft + menuLeft + 'px';	
}

function hidePop() {	
 lbl.style.visibility='hidden';
}