//-----------------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------
// Validation Functions section
//----------------------------------
function ckNumber(ev) {
//----------------------------------
   // Initialize local variables
   var tmpstr = ev.value
   var l = tmpstr.length
	
	if (ev == null)
   {
   		return;
   }
   ev.value = parseInt(ev.value);
   if (isNaN(tmpstr) == true)
   {
      	alert("Error: Input must be numeric");
      	ev.select()
      	ev.focus()
      	return;
	}
}
//part of check email
//----------------------------------
function echeck(str) {
//----------------------------------
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail Address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail Address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

 		 return true					
	}
//----------------------------------
function ckEmail(ev){
//----------------------------------	
	var emailID=ev;
	
	if ((emailID.value==null)||(emailID.value=="")){
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }
 //Checks to ensure a user has entered a value in a mandatory form field
//----------------------------------
function validEntry(fieldName) {
//----------------------------------
//alert(fieldName.name);
	if (fieldName.value == "") {
		alert("Field cannot be empty.")
		focus(fieldName.name);
	}
}
//content overlay functions
/***********************************************
* Drop Down/ Overlapping Content- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
//----------------------------------
function getposOffset(overlay, offsettype){
//----------------------------------
	var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
	var parentEl=overlay.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}
//----------------------------------
function overlay(curobj, subobjstr, opt_position){
//----------------------------------
	if (document.getElementById){
		var subobj=document.getElementById(subobjstr)
		subobj.style.display=(subobj.style.display!="block")? "block" : "none"
		var xpos=getposOffset(curobj, "left")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)? -(subobj.offsetWidth-curobj.offsetWidth) : 0) 
		var ypos=getposOffset(curobj, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? curobj.offsetHeight : 0)
		subobj.style.left=xpos+"px"
		subobj.style.top=ypos+"px"
		return false
	}
	else
		return true
}
//----------------------------------
function overlayclose(subobj){
//----------------------------------
	document.getElementById(subobj).style.display="none"
}

//-----------------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------
	/************************************************************************************************************
	(C) www.dhtmlgoodies.com, November 2005
	
	This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	
	
	Terms of use:
	You are free to use this script as long as the copyright message is kept intact. However, you may not
	redistribute, sell or repost it without our permission. 
	
	Thank you!
	
	www.dhtmlgoodies.com
	Alf Magne Kalleland
	
	************************************************************************************************************/	
	var slideshow2_noFading = false;
	var slideshow2_timeBetweenSlides = 10000;	// Amount of time between each image(1000 = 1 second)
	var slideshow2_fadingSpeed = 10;	// Speed of fading	(Lower value = faster)
	
	var slideshow2_galleryContainer;	// Reference to the gallery div
	var slideshow2_galleryWidth;	// Width of gallery
	var slideshow2_galleryHeight;	// Height of galery
	var slideshow2_slideIndex = -1;	// Index of current image shown
	var slideshow2_slideIndexNext = false;	// Index of next image shown
	var slideshow2_imageDivs = new Array();	// Array of image divs(Created dynamically)
	var slideshow2_currentOpacity = 100;	// Initial opacity
	var slideshow2_imagesInGallery = false;	// Number of images in gallery
	var Opera = navigator.userAgent.indexOf('Opera')>=0?true:false;
	function createParentDivs(imageIndex)
	{
		if(imageIndex==slideshow2_imagesInGallery){			
			showGallery();
		}else{
			var imgObj = document.getElementById('galleryImage' + imageIndex);	
			if(Opera)imgObj.style.position = 'static';
			slideshow2_imageDivs[slideshow2_imageDivs.length] =  imgObj;
			imgObj.style.visibility = 'hidden';	
			imageIndex++;
			createParentDivs(imageIndex);	
		}		
	}
	
	function showGallery()
	{
		if(slideshow2_slideIndex==-1)
			slideshow2_slideIndex=0; 
		else 
			slideshow2_slideIndex++;	// Index of next image to show
		
		if(slideshow2_slideIndex==slideshow2_imageDivs.length)
			slideshow2_slideIndex=0;
			slideshow2_slideIndexNext = slideshow2_slideIndex+1;	// Index of the next next image
		if(slideshow2_slideIndexNext==slideshow2_imageDivs.length)
			slideshow2_slideIndexNext = 0;
		
		slideshow2_currentOpacity=100;	// Reset current opacity

		// Displaying image divs
		slideshow2_imageDivs[slideshow2_slideIndex].style.visibility = 'visible';
		if(Opera)slideshow2_imageDivs[slideshow2_slideIndex].style.display = 'inline';
		if(navigator.userAgent.indexOf('Opera')<0){
			slideshow2_imageDivs[slideshow2_slideIndexNext].style.visibility = 'visible';
		}
		
		if(document.all){	// IE rules
			slideshow2_imageDivs[slideshow2_slideIndex].style.filter = 'alpha(opacity=100)';
			slideshow2_imageDivs[slideshow2_slideIndexNext].style.filter = 'alpha(opacity=1)';
		}else{
			slideshow2_imageDivs[slideshow2_slideIndex].style.opacity = 0.99;	// Can't use 1 and 0 because of screen flickering in FF
			slideshow2_imageDivs[slideshow2_slideIndexNext].style.opacity = 0.01;
		}		
		

		setTimeout('revealImage()',slideshow2_timeBetweenSlides);		
	}
	
	function revealImage()
	{
		if(slideshow2_noFading){
			slideshow2_imageDivs[slideshow2_slideIndex].style.visibility = 'hidden';
			if(Opera)slideshow2_imageDivs[slideshow2_slideIndex].style.display = 'none';
			showGallery();
			return;
		}
		slideshow2_currentOpacity--;
		if(document.all){
			slideshow2_imageDivs[slideshow2_slideIndex].style.filter = 'alpha(opacity='+slideshow2_currentOpacity+')';
			slideshow2_imageDivs[slideshow2_slideIndexNext].style.filter = 'alpha(opacity='+(100-slideshow2_currentOpacity)+')';
		}else{
			slideshow2_imageDivs[slideshow2_slideIndex].style.opacity = Math.max(0.01,slideshow2_currentOpacity/100);	// Can't use 1 and 0 because of screen flickering in FF
			slideshow2_imageDivs[slideshow2_slideIndexNext].style.opacity = Math.min(0.99,(1 - (slideshow2_currentOpacity/100)));
		}
		if(slideshow2_currentOpacity>0){
			setTimeout('revealImage()',slideshow2_fadingSpeed);
		}else{
			slideshow2_imageDivs[slideshow2_slideIndex].style.visibility = 'hidden';	
			if(Opera)slideshow2_imageDivs[slideshow2_slideIndex].style.display = 'none';		
			showGallery();
		}
	}
	
	function initImageGallery()
	{
		slideshow2_galleryContainer = document.getElementById('imageSlideshowHolder');
		slideshow2_galleryWidth = slideshow2_galleryContainer.clientWidth;
		slideshow2_galleryHeight = slideshow2_galleryContainer.clientHeight;
		galleryImgArray = slideshow2_galleryContainer.getElementsByTagName('IMG');
		for(var no=0;no<galleryImgArray.length;no++){
			galleryImgArray[no].id = 'galleryImage' + no;
		}
		slideshow2_imagesInGallery = galleryImgArray.length;
		createParentDivs(0);		
		
	}


//Create new catalog class ---------------------------------------------------
//--------------------------------------------------------------------------
var Catalog = new function() {  
	this.form = null;
	this.button = null;
	this.mPassTotDiv = null;
	this.mPassTotHid = null;
	this.jCouponTotDiv = null;
	this.jCouponTotHid = null;
	this.cCouponTotDiv = null;
	this.cCouponTotHid = null;
	//get grand total elements
	this.grandTotalDiv = null;
	this.grandTotalHid = null;
	//concession selection holder
	this.concessHolderDiv = null;
	this.concessPrice = null;
	//prices
	this.mPassPrice = 0.00;
	this.jCouponPrice = 0.00;
	this.cCouponCornSm = 0.00;
	this.cCouponCornMd = 0.00;
	this.cCouponCornLg = 0.00;
	this.cCouponPopSm = 0.00;
	this.cCouponPopMd = 0.00;
	this.cCouponPopLg = 0.00;
	//quanties
	this.mPassQuant = null;
	this.jCouponQuant = null;
	this.cCouponQuant0 = null;
	this.rowCount = 1; //one is built when form loads
	this.validCount = new Array();
		
	//-------------------------------
	this.init = function() {
	//-------------------------------
		var self = Catalog;
		self.form = document.getElementById('maxCatalogForm');
		if(self.form){
			self.button = document.getElementById('catalogSubmitButton');
			self.submitComment = document.getElementById('submitComment');
			//get total elements
			self.mPassTotDiv = document.getElementById('mPassTotDiv');
			self.mPassTotHid = document.getElementById('mPassTotHid');
			self.jCouponTotDiv = document.getElementById('jCouponTotDiv');
			self.jCouponTotHid = document.getElementById('jCouponTotHid');
			self.cCouponTotDiv = document.getElementById('cCouponTotDiv');
			self.cCouponTotHid = document.getElementById('cCouponTotHid');
			//get grand total elements
			self.grandTotalDiv = document.getElementById('grandTotalDiv');
			self.grandTotalHid = document.getElementById('grandTotalHid');
			//get concession selection holder
			self.concessHolderDiv = document.getElementById('concessionHolder');
			self.concessPriceDiv = document.getElementById('concessPrice');
			//prices
			self.mPassPrice = document.getElementById('mPassPrice');
			self.jCouponPrice = document.getElementById('jCouponPrice');
			self.cCouponCornSm = document.getElementById('cCouponCornSm');
			self.cCouponCornMd = document.getElementById('cCouponCornMd');
			self.cCouponCornLg = document.getElementById('cCouponCornLg');
			self.cCouponPopSm = document.getElementById('cCouponPopSm');
			self.cCouponPopMd = document.getElementById('cCouponPopMd');
			self.cCouponPopLg = document.getElementById('cCouponPopLg');
			//starting quantities
			self.mPassQuant = document.getElementById('mPassQuant');
			self.jCouponQuant = document.getElementById('jCouponQuant');
			self.cCouponQuant0 = document.getElementById('cCouponQuant0');
			//user
			self.jsBrowser = document.getElementById('jsBrowser');
			self.jsOS = document.getElementById('jsOS');
			self.jsBrowser.value = BrowserDetect.browser+' '+BrowserDetect.version;
			self.jsOS.value = BrowserDetect.OS;
		
			
			self.buildConcessionGroup(true);
			self.toggleEnabled(false);	
			self.form.onsubmit = function() { return false; };
		}
		else{
			//alert('aborting');
			return;
		}
		//alert(self.form.innerHTML);
	};

	//-------------------------------
	this.buildConcessionGroup = function(buildIt){
	//-------------------------------
		var self = Catalog;
		
		if(buildIt){
			var id = self.rowCount;
			//alert('build for id: '+id);
			var nextConcessionDiv = document.createElement('div');
			nextConcessionDiv.id = 'concession'+id;
			if(document.all && typeof window.opera == 'undefined'){ //IE
				nextConcessionDiv.onmouseover =new Function("Catalog.overRow(this)");
				nextConcessionDiv.onmouseout =new Function("Catalog.outRow(this)");
				nextConcessionDiv.className = "concession";
			}
			else{
				nextConcessionDiv.setAttribute("onmouseover","Catalog.overRow(this)");
				nextConcessionDiv.setAttribute("onmouseout","Catalog.outRow(this)");
				nextConcessionDiv.setAttribute("class","concession");
			}
				
			self.concessHolderDiv.appendChild(nextConcessionDiv);
			
			//var itemSelect = document.createElement('select');
			var itemSelect = createNamedElement('select','cCoupon_type_'+id);
			itemSelect.id = 'concessionItem'+id;
			if(document.all && typeof window.opera == 'undefined') //IE
				itemSelect.onchange =new Function("Catalog.cItemSelect(this)");
			else	//others
				itemSelect.setAttribute("onchange","Catalog.cItemSelect(this)");
			var items = new Array(new Array('','Choose Item'),new Array('popcorn','Popcorn'),new Array('soda','Soda'));
			self.buildSelectOptions(itemSelect,items,items.length);
			nextConcessionDiv.appendChild(itemSelect);
			nextConcessionDiv.appendChild(document.createTextNode(' '));
			
			//var sizeSelect = document.createElement('select');
			var sizeSelect = createNamedElement('select','cCoupon_size_'+id);
			sizeSelect.id = 'concessionSize'+id;
			if(document.all && typeof window.opera == 'undefined') //IE
				sizeSelect.onchange =new Function("Catalog.cItemSelect(this)");
			else	//others
				sizeSelect.setAttribute("onchange","Catalog.cItemSelect(this)");
			var sizes = new Array(new Array('','Choose Size'),new Array('small','Small'),new Array('medium','Medium'),new Array('large','Large'));
			self.buildSelectOptions(sizeSelect,sizes,sizes.length);
			nextConcessionDiv.appendChild(sizeSelect);
			nextConcessionDiv.appendChild(document.createTextNode(' Quantity:'));
			
			//var quantity = document.createElement('input');
			var quantity = createNamedElement('input','cCoupon_quant_'+id);
			quantity.id = 'cCouponQuant'+id;
			quantity.value = 0;
			quantity.size="3";
			quantity.maxlength="3";
			if(document.all && typeof window.opera == 'undefined')
				quantity.onblur =new Function("ckNumber(this);Catalog.cItemQuant(this)");
			else
				quantity.setAttribute('onblur',"ckNumber(this);Catalog.cItemQuant(this)");
			nextConcessionDiv.appendChild(quantity);
			
			self.disableEnableQuant(true,id);
			self.rowCount++;
			//alert(self.concessHolderDiv.innerHTML);
		}
	};
	
	//-------------------------------
	this.buildSelectOptions = function(selectName,obj,arrayLength){
	//-------------------------------
		var self = Catalog;
		for(var i=0; i<arrayLength; i++){		
			//alert('createing option: ');
			var option = document.createElement("option");
			option.value = obj[i][0];
			option.text = obj[i][1];
			if(i==0)
				option.setAttribute('selected','selected');
			var elOptOld = selectName.options[i];  
			try {
				// standards compliant; doesn't work in IE
				selectName.add(option, elOptOld); 
			}
			catch(ex) {
				// IE only
				selectName.add(option, i); 
			}
		}
		return;
	};
	//-----------------------------------
	this.overRow = function(divObj){
	//-----------------------------------
		var self = Catalog;
		var itemId = null;
		var price = null;
		divObj.style.background = '#FFFF99';
		itemId = self.getIdKey(divObj);
		price = self.cItemPrice(itemId);
		if(price > 0)
			self.displaySelectedPrice(formatCurrency(price));
		
	};
	//-----------------------------------
	this.outRow = function(divObj){
	//-----------------------------------
		var self = Catalog;
		divObj.style.background = '#FFFFFF';
		self.displaySelectedPrice('Select an item and size to see price.');
	};
	//--------------------------------
	this.cItemSelect = function(obj){
	//--------------------------------
		var self = Catalog;
		itemId = self.getIdKey(obj);
		price = self.cItemPrice(itemId);
		if(price > 0){
			self.disableEnableQuant(false,itemId);
			
			//check if need to create new coupon line
			self.validCount[itemId] = true;			
			//count trues
			var trues = 0;
			for(var i=0; i<self.rowCount; i++){
				if(self.validCount[i])
					trues++;
			}
			//alert('Valid: '+trues+', #rows: '+self.rowCount);
			if(trues == self.rowCount && self.rowCount < 6){
				self.buildConcessionGroup(true);
			}
		}
		else{
			self.validCount[itemId] = false;
			self.disableEnableQuant(true,itemId);
		}
	};
	
	//--------------------------------
	this.cItemQuant = function(obj){
	//--------------------------------
		var self = Catalog;
		itemId = self.getIdKey(obj);
		price = self.cItemPrice(itemId);
		//valid item and quantity
		if(price > 0 && obj.value > -1){
			self.updateTotal(price);
			self.updateGrandTotal()
		}
		else
			obj.value = 0;
	};
	//-------------------------------
	this.disableEnableQuant = function(disable,id){
	//-------------------------------
		var self = Catalog;
		var curQuant = document.getElementById('cCouponQuant'+id);
		//alert('inside enableDisable');
		if(disable){
			curQuant.value = 0;
			curQuant.disabled = true;
		}
		else{			
			curQuant.disabled = false;
			self.updateTotal(price);
			self.updateGrandTotal();
		}
	}
	//--------------------------------
	this.updateTotal2 = function(obj){
	//--------------------------------
		var self = Catalog;
		var itemTotal = 0
		//alert('obj: '+obj.id+', mPass: '+self.mPassQuant.id+', jPass: '+self.jCouponQuant.id);
		
		//movie pass
		if(obj.id == self.mPassQuant.id){
			if(obj.value == ""){
				obj.value = 0;
				return;
			}
			if(self.mPassQuant.value > -1){
				//alert('processing mpass');
				itemTotal = parseInt(self.mPassQuant.value) * parseFloat(self.mPassPrice.value);
				//alert('price: '+self.mPassPrice.value+', quant: '+self.mPassQuant.value+', coupon Total:' +itemTotal);
				//display to user
				if (self.mPassTotDiv.firstChild){
					self.mPassTotDiv.removeChild(self.mPassTotDiv.firstChild);
				}
				self.mPassTotDiv.appendChild(document.createTextNode(formatCurrency(itemTotal)));
				self.mPassTotHid.value = itemTotal;
				self.updateGrandTotal()
			}
		}
		//java pass
		else if(obj.id == self.jCouponQuant.id){
			if(obj.value == ""){
				obj.value = 0;
				return;
			}
			if(self.mPassQuant.value > -1){
				//alert('processing jcoupon');
				itemTotal = parseInt(self.jCouponQuant.value) * parseFloat(self.jCouponPrice.value);			
				//display to user
				if (self.jCouponTotDiv.firstChild){
					self.jCouponTotDiv.removeChild(self.jCouponTotDiv.firstChild);
				}
				self.jCouponTotDiv.appendChild(document.createTextNode(formatCurrency(itemTotal)));				
				self.jCouponTotHid.value = itemTotal;
				self.updateGrandTotal()
			}
		}
	};
	//-------------------------------
	this.updateTotal = function(price){
	//-------------------------------
		var self = Catalog;	
		var itemId = null;
		var price = 0;
		var curQuant = new Array();
		var curTotal = new Array();
		var couponTotal = 0;
		
		for(var i=0; i<self.rowCount; i++){
			curQuant[i] = document.getElementById('cCouponQuant'+i);
			price = self.cItemPrice(i);
			curTotal[i] = (parseInt(curQuant[i].value) * parseFloat(price));
			couponTotal += parseFloat(curTotal[i]);
			//alert('price: '+price+', quant: '+curQuant[i].value+', coupon Total:' +couponTotal);
		}
		
		var curDiv = document.getElementById('cCouponTotDiv');
		var curHid = document.getElementById('cCouponTotHid');	
		
		if (curDiv.firstChild) {
			curDiv.removeChild(curDiv.firstChild);
		}
		curDiv.appendChild(document.createTextNode(formatCurrency(couponTotal)));
		curHid.value = couponTotal;
		
	};
	//--------------------------------
	this.getIdKey = function(obj){
	//--------------------------------
		var self = Catalog;
		var objId = null;
		var searchItem1 = null;
		var searchItem2 = null;
		var searchItem3 = null;
		var searchItemDiv = null;

		//get fields for item
		searchItem1 = obj.id.search(/cCouponQuant/i);
		searchItem2 = obj.id.search(/concessionSize/i);
		searchItem3 = obj.id.search(/concessionItem/i);
		searchItemDiv = obj.id.search(/concession/i);
		//alert('quant: '+searchItem1+', Size: '+searchItem2+', Item: '+searchItem3+', div: '+searchItemDiv);
		
		if(parseInt(searchItem1) != -1){
			objId = obj.id.replace(/cCouponQuant/,'');
			//alert('using quant');
		} else if(parseInt(searchItem2) != -1){
			objId = obj.id.replace(/concessionSize/,'');
			//alert('using size');
		} else if(parseInt(searchItem3) != -1){
			objId = obj.id.replace(/concessionItem/,'');
			//alert('using item');
		} else if(parseInt(searchItemDiv) != -1){
			objId = obj.id.replace(/concession/,'');
			//alert('using div');
		} else {
			alert('Invalid Selection.');
		}
		return objId;		
	};
	
	//-------------------------------
	this.toggleEnabled = function(able) {
	//-------------------------------
		var self = Catalog;	
		//alert('inside toggle button');
		if (able) {
			self.button.disabled = false;
			self.button.className = 'inputButtonActive';
			self.enabled = true;
			self.button.onclick = self.submitData;

		}
		else {
			self.button.onclick = null;
			self.button.disabled = true;
			self.button.className = 'inputButtonDisabled';
			self.enabled = false;
		}
	};
	//----------------------------------
	this.cItemPrice = function(id){
	//----------------------------------
		var self = Catalog;
		//alert('objID: '+id);
		var curItem = document.getElementById('concessionItem'+id);
		var curSize = document.getElementById('concessionSize'+id);
		var curQuant = document.getElementById('cCouponQuant'+id);
		var curPrice = 0;
		//alert('itemValue: '+curItem.value);
		//alert('SizeValue: '+curSize.value);
		//alert('quantValue: '+curQuant.value);
		
		//make sure a size and type is set
		if(curItem.value != '' && curSize.value != ''){
			if(curItem.value == 'popcorn'){
				if(curSize.value == 'small')
					curPrice = self.cCouponCornSm.value;
				if(curSize.value == 'medium')
					curPrice = self.cCouponCornMd.value;
				if(curSize.value == 'large')
					curPrice = self.cCouponCornLg.value;
			}
			else if(curItem.value == 'soda'){
				if(curSize.value == 'small')
					curPrice = self.cCouponPopSm.value;
				if(curSize.value == 'medium')
					curPrice = self.cCouponPopMd.value;
				if(curSize.value == 'large')
					curPrice = self.cCouponPopLg.value;
			}
		}
		
		return curPrice;
	};
	//----------------------------------
	this.displaySelectedPrice = function(curPrice){
	//----------------------------------
		var self = Catalog;
		if (self.concessPriceDiv.firstChild) {
			self.concessPriceDiv.removeChild(self.concessPriceDiv.firstChild);
		}	
		self.concessPriceDiv.appendChild(document.createTextNode(curPrice));
	};
	//only ran on quantity fields
	
	
	//-------------------------------
	this.submitData = function(){
	//-------------------------------
		var self = Catalog;
		//alert('In submit data');
		TimeOnPage.getLogoffTime();
		self.form.submit();
	};
	//-------------------------------
	this.updateGrandTotal = function(){
	//-------------------------------
		var self = Catalog;
		//alert('inside update gtotal');
		//add up individual item totals
		var grandTotal = parseFloat(self.mPassTotHid.value) + parseFloat(self.jCouponTotHid.value) + parseFloat(self.cCouponTotHid.value);
		if (self.grandTotalDiv.firstChild) {
			self.grandTotalDiv.removeChild(self.grandTotalDiv.firstChild);
		}
		self.grandTotalDiv.appendChild(document.createTextNode(formatCurrency(grandTotal)));
		self.grandTotalHid.value = grandTotal;
		//enough to enable checkout?
		if(grandTotal >= 10){
			self.toggleEnabled(true);
			self.updateCheckoutText(true);
		}
		else{
			self.toggleEnabled(false);
			self.updateCheckoutText(false);
		}
	};
	//-----------------------------------
	this.updateCheckoutText = function(update){
	//-----------------------------------	
		var self = Catalog;
		while (self.submitComment.firstChild) {
			self.submitComment.removeChild(self.submitComment.firstChild);
		}
		if(update){
			self.submitComment.appendChild(document.createTextNode('You will be redirected to PayPal to securely process the transaction.'));
		}
		else{
			self.submitComment.appendChild(document.createTextNode('Button will enable once order total reaches $10.'));
		}
		var lnBrk = document.createElement('br');
		self.submitComment.appendChild(lnBrk);
		self.submitComment.appendChild(document.createTextNode('All major credit cards accepted.'));
	   
	};

}
//-----------------------------------------------------
//-----------------------------------------------------  
function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}
//------------------------------------------------------
function createNamedElement(type, name) {
	var element;
	try {
		element = document.createElement('<'+type+' name="'+name+'">');
	} 
	catch (e) { }
	
	if (!element || !element.name) { // Not in IE, then
		element = document.createElement(type)
		element.name = name;
	}
	return element;
}
//---------------------------------------------------------------
//	time on page
//---------------------------------------------------------------
var TimeOnPage = new function() {
	this.onHours = " ";
	this.onMinutes = " ";
	this.onSeconds = " ";
	this.offHours = 0;
	this.offMinutes = 0;
	this.offSeconds = 0;
	this.logSeconds = 0;
	this.logMinutes = 0;
	this.logHours = 0;
	this.OnTimeValue = " ";
	this.OffTimeValue = " ";
	this.PageTimeValue = " ";
	//---------------------------
	this.init = function(){
	//---------------------------	
		var self = TimeOnPage;
		
		self.getLogonTime();
		//alert('time: '+self.OnTimeValue);
	};
	//---------------------------
	this.getLogonTime = function() {
		var self = TimeOnPage;
		var now = new Date();
		var ampm = (now.getHours() >= 12) ? " P.M." : " A.M."
		var Hours = now.getHours();
		Hours = ((Hours > 12) ? Hours - 12 : Hours);
		var Minutes = ((now.getMinutes() < 10) ? ":0" : ":") + now.getMinutes();
		var Seconds = ((now.getSeconds() < 10) ? ":0" : ":") + now.getSeconds();
		self.OnTimeValue =(" "
		+ Hours
		+ Minutes
		+ Seconds
		+ " "
		+ ampm);
		self.onHours = now.getHours();
		self.onMinutes = now.getMinutes();
		self.onSeconds = now.getSeconds();  
	};
	this.getLogoffTime = function() {
		var self = TimeOnPage;
		var now = new Date();
		var ampm = (now.getHours() >= 12) ? " P.M." : " A.M."
		var Hours = now.getHours();
		Hours = ((Hours > 12) ? Hours - 12 : Hours);
		var Minutes = ((now.getMinutes() < 10) ? ":0" : ":") + now.getMinutes();
		var Seconds = ((now.getSeconds() < 10) ? ":0" : ":") + now.getSeconds();
		self.OffTimeValue =(" "
		+ Hours
		+ Minutes
		+ Seconds
		+ " "
		+ ampm);
		self.offHours = now.getHours();
		self.offMinutes = now.getMinutes();
		self.offSeconds = now.getSeconds();
		self.timer(); 
	};
	this.timer = function() { 
		var self = TimeOnPage;
		if (self.offSeconds >= self.onSeconds) { 
			self.logSeconds = self.offSeconds - self.onSeconds; }
		else {
			self.offMinutes -= 1;
			self.logSeconds = (self.offSeconds + 60) - self.onSeconds;      
		}
		if (self.offMinutes >= self.onMinutes) { 
			self.logMinutes = self.offMinutes - self.onMinutes; }
		else {
			self.offHours -= 1;
			self.logMinutes = (self.offMinutes + 60) - self.onMinutes;
		}
		self.logHours = self.offHours - self.onHours;
		self.logHours =  ((self.logHours < 10) ? "0" : ":") + self.logHours;
		self.logMinutes = ((self.logMinutes < 10) ? ":0" : ":") + self.logMinutes;
		self.logSeconds = ((self.logSeconds < 10) ? ":0" : ":") +self.logSeconds;
		self.PageTimeValue =(" "
		+ self.logHours
		+ self.logMinutes
		+ self.logSeconds);
		self.displayTimes();
		
	};
	this.displayTimes = function() {
		var self = TimeOnPage;
		//alert('time: '+self.OffTimeValue);
		var jsTime = document.getElementById('jsTime');
		//alert(jsTime.id);
		//alert(self.PageTimeValue);
		jsTime.value = self.PageTimeValue;
	};
}
//---------------------------------------------------------------------------------
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();