var IE = /*@cc_on!@*/false;

function clearField( field_name )
{
	document.getElementById( field_name ).value = '';
	document.getElementById( field_name ).style.backgroundColor = '';
}

function highlightFields( field_str )
{
	var fields = field_str.split(',');
	
	for( var i=0; i<fields.length; i++ )
	{
		highlightField( fields[i], '#F6F5CF' ); 
	}
	
}


function highlightField( field_name, field_color )
{
	document.getElementById( field_name ).style.backgroundColor = field_color;
}


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);
}	//end function

function validate_required_fields(frmName, strTextBoxes)
{
	var oForm = document.getElementById(frmName);
	
	//turn the comma separated list into an array
	var arrBoxes = strTextBoxes.split(",");
	
	error = 0;
	
	//loop thru each box and determine if the text value is empty
	for( var intCount = 0; intCount < arrBoxes.length; intCount++ )
	{
		arrBoxes[intCount] = arrBoxes[intCount].trim_spaces();
		
		//alert( "inCount: " + intCount + " - text box: -->" + arrBoxes[intCount] + "<--" );
		
		var strText = document.getElementById(arrBoxes[intCount]).value;
		
		if( strText.length == 0 )
		{
			error++;
			
		}	//end if
		
	}	//end for loop
	
	//if any errors, then user did not enter all the required fields
	if( error > 0 )
	{
		alert( "Please enter all the required fields." );
		
		valid = false;
		
	}	//end if
	
	else
	{
		valid = true;
		
	}	//end else
	
	return valid;
	
}	//end function

function pop_templates()
{
	window.open('pop_templates.php','admin_pop','width=600,height=400,scrollbars=yes,resizable=yes');	
}

//removes all spaces in a string
function removespaces() 
{
	return this.replace(/.*\S/,'');
	
}	//end function

//trims leading and trailing spaces
function trim_spaces() 
{
	return this.replace(/^\s+/,'').replace(/\s+$/,'');
	
}	//end function

function clear_image( field_id )
{
	document.getElementById( 'pg-' + field_id ).src = 'images/spacer.gif';
	document.getElementById( field_id ).value = '';
	document.getElementById( field_id + '_filename' ).value = '';
}

function clear_link( field_id )
{
	document.getElementById( field_id ).value = '';
	document.getElementById( field_id + '_text' ).innerHTML = '';
	document.getElementById( field_id + '_text' ).style.backgroundColor = '';
}

function isNumeric(text) {
	return /^([0-9]|\.)+$/.test(text);
}




//assigns a new function to string types
String.prototype.removespaces = removespaces;
String.prototype.trim_spaces = trim_spaces;


// Creates a google map
var googleMapID = 0;
function GoogleMap(id, lat, lng, zoom) {
	var mapID = id+"_"+googleMapID++;
	var lat = lat;
	var lng = lng;
	var zoom = zoom || 15;
	document.writeln('<div id="'+mapID+'" class="google_map"></div>');
	if(!GBrowserIsCompatible()) {
		$(mapID).innerHTML = '<p class="error">An error occured generating the google maps.</p>';
		return;
	}
	var map = new GMap2($(mapID));
	map.setCenter(new GLatLng(lat, lng), zoom);
	map.addControl(new GSmallMapControl());
	
	// To prevent memory leaks
	Event.observe(window, 'unload', function() {
		GUnload();
	});
	
	this.addPoint = function(lat, lng, text) {
		map.addOverlay(new GMarker(new GLatLng(lat, lng)))
		if(text) map.openInfoWindow(map.getCenter(), document.createTextNode(text));
	};

	this.centerAt = function(lat, lng, text) {
		map.setCenter(new GLatLng(lat, lng), zoom);
		if(text) map.openInfoWindow(map.getCenter(), document.createTextNode(text));
	};
}

function updateSearchInput() {
	var searchInput = $('searchbox');
	var defaultText = 'keyword(s)';
	   
	if(searchInput.value == '') {
		searchInput.value = defaultText;
		searchInput.addClassName('search_default');
	}
}

function clearSearchInput() {
	var searchInput = $('searchbox');
	var defaultText = 'keyword(s)';
	   
	if(searchInput.value == defaultText) {
		searchInput.value = '';
		searchInput.removeClassName('search_default');
	}
}
        

function setActive(idOrElem, className) {
	$$(className || '*').each(function(elem) {
		elem.removeClassName('active');
	});
	$(idOrElem).addClassName('active');
}

// Update the search box with suggestions(array)
function updateSearchList(suggestions) {
	var popular_searches = $('popularsearches');
	var search_list = $('searchlist');
	
	var list = [];
	list.push('<li><b>Quick Click Matches:</b></li>');
	
	// No Search Preformed
	if(suggestions === undefined) {
		// Do Nothing
	}
	
	// Loading
	else if(suggestions == 'loading') {
		list.push('<li><img src="'+ROOT+'images/ajax-search-circles-black.gif"/></li>');
	}
	
	// Parse Results
	else if(suggestions.length > 0) {
		suggestions.each(function(suggestion){
			list.push('<li>');
			list.push('<a href="' + ROOT + suggestion.url + '">');
			list.push(suggestion.label);
			list.push('</a>');
			list.push('</li>');
		});
	}
	
	// No Results
	else {
		list.push('<li><i>No Results</i></li>');
	}
	
	search_list.innerHTML = list.join('');
	popular_searches.show();
	popular_searches.setOpacity(list.length > 1 ? .9 : 0);
}

function searchAjax(search_url) {
	var MIN_LENGTH = 3;
	var DEBOUNCE_TIMEOUT = 500;
	
	var bar = $('searchbox');
	if(bar == null) return;
	var debounceTimer;
	var globalOrderNumber = 0;
	bar.setAttribute("autocomplete", "off");
	bar.observe('keyup', function(event) {
		globalOrderNumber += 1;
		var orderNumber = globalOrderNumber;
		clearTimeout(debounceTimer);
		if(bar.value.length < MIN_LENGTH) {
			updateSearchList();
			return;
		}
		debounceTimer = setTimeout(function() {
			new Ajax.Request(search_url, {
				method: 'get',
				parameters: {
					ajax: 1,
					q: bar.value,
					unique: Math.random()
				},
				onCreate: function() {
					updateSearchList('loading');
				},
				onSuccess: function(http) {
					if(orderNumber != globalOrderNumber) return;
					var json = http.responseText.evalJSON();
					var results = [];
					for(var i = 0; i < json.result_count; i++) {
						results[i] = json.results[i];
					}
					updateSearchList(results);
				}
			});
		}, DEBOUNCE_TIMEOUT);
	});
}

if(Event != undefined) {
	Event.observe(window, 'load', function() {
		//searchAjax(ROOT+'search.php');
	});
}


function initClassToggle() {
	$$('input[name=type]').each(function(elem) {
		elem.observe('click', function() {
			setClassSpecificFields();
		});
	});
	setClassSpecificFields();
}

function setClassSpecificFields() {
	var state = $F('radio_class');
	if(state) {
		$$('.class_specific').each(function(elem) {
			elem.show();
		});
	} else {
		$$('.class_specific').each(function(elem) {
			elem.hide();
		});
	}
}
/***********************************************************
 * class name functions
 ***********************************************************/

function getClassName(element) {

	var className = (document.all && document.getElementById ? element.className : element.getAttribute("class"));
	return className;

}

function setClassName(element,style) {

	if( document.all && document.getElementById ) element.className=style;
	else element.setAttribute("class", style);

}

function startInterval(func, time) {
	func();
	return setInterval(func, time);
}

// Fix FOUT for font replacement (http://paulirish.com/2009/fighting-the-font-face-fout/)
(function(){
	// if firefox 3.5+, hide content till load (or 3 seconds) to prevent FOUT
	var d = document, e = d.documentElement, s = d.createElement('style');
	if(e.style.MozTransform === '') { // gecko 1.9.1 inference
		s.textContent = 'body{visibility:hidden}';
		e.firstChild.appendChild(s);
		var f = function(){s.parentNode && s.parentNode.removeChild(s);};
		addEventListener('load',f,false);
		setTimeout(f,3000);
	}
})();


jQuery(function($) {
		var colRightOriginalFontSize = $('.col_right').css('font-size');
		var colMiddleOriginalFontSize = $('.col_right').css('font-size');

		var HMCcRFS_cookie = "HarrisonMC-cRFontSize";
		var HMCcMFS_cookie = "HarrisonMC-cMFontSize";

		var getSize;
		
		// if exists load saved value, otherwise store it
		if(getCookie(HMCcRFS_cookie) != null) {
			getSize = getCookie(HMCcRFS_cookie);
			$('.col_right').css({fontSize : getSize + (getSize.indexOf("px")!=-1 ? "" : "px")}); // IE fix for double "pxpx" error
		} else {
			setCookie(HMCcRFS_cookie, colRightOriginalFontSize);
		}
		if(getCookie(HMCcMFS_cookie) != null) {
			getSize = getCookie(HMCcMFS_cookie);
			$('.col_middle').css( {fontSize : getSize + (getSize.indexOf("px")!=-1 ? "" : "px")}); // IE fix for double "pxpx" error
		} else {
			setCookie(HMCcMFS_cookie, colMiddleOriginalFontSize);
		}

		$('a.increase_txt_size_button').click(function(){
			var colRightcurrentFontSize = $('.col_right').css('font-size');
			var colRightcurrentFontSizeNum = parseFloat(colRightcurrentFontSize, 10);
			var colRightnewFontSize = colRightcurrentFontSizeNum*1.2;
			$('.col_right').css('font-size', colRightnewFontSize);
			setCookie(HMCcRFS_cookie, colRightnewFontSize);

			var colMiddlecurrentFontSize = $('.col_middle').css('font-size');
			var colMiddlecurrentFontSizeNum = parseFloat(colMiddlecurrentFontSize, 10);
			var colMiddlenewFontSize = colMiddlecurrentFontSizeNum*1.2;
			$('.col_middle').css('font-size', colMiddlenewFontSize);
			setCookie(HMCcMFS_cookie, colMiddlenewFontSize);

			return false;
		});

		$('a.decrease_txt_size_button').click(function(){
			var colRightcurrentFontSize = $('.col_right').css('font-size');
			var colRightcurrentFontSizeNum = parseFloat(colRightcurrentFontSize, 10);
			var colRightnewFontSize = colRightcurrentFontSizeNum/1.2;
			$('.col_right').css('font-size', colRightnewFontSize);
			setCookie(HMCcRFS_cookie, colRightnewFontSize);

			var colMiddlecurrentFontSize = $('.col_middle').css('font-size');
			var colMiddlecurrentFontSizeNum = parseFloat(colMiddlecurrentFontSize, 10);
			var colMiddlenewFontSize = colMiddlecurrentFontSizeNum/1.2;
			$('.col_middle').css('font-size', colMiddlenewFontSize);
			setCookie(HMCcMFS_cookie, colMiddlenewFontSize);

			return false;
		});
});

function event_price_total(num_seats){
    var total = 0;
    var price1 = 0;
    var price2 = 0;
    var price3 = 0;
    var price4 = 0;
    var price5 = 0;

    if(num_seats == 1)
        {
            var seat1 = document.getElementById('seat1').value;
            price1 = document.getElementById('price1').value;
            total = seat1*price1;
        }
    if(num_seats == 2)
        {
            seat1 = document.getElementById('seat1').value;
            price1 = document.getElementById('price1').value;
            var seat2 = document.getElementById('seat2').value;
            price2 = document.getElementById('price2').value;
            total = seat1*price1 + seat2*price2;
        }
    if(num_seats == 3)
        {
            seat1 = document.getElementById('seat1').value;
            price1 = document.getElementById('price1').value;
            seat2 = document.getElementById('seat2').value;
            price2 = document.getElementById('price2').value;
            var seat3 = document.getElementById('seat3').value;
            price3 = document.getElementById('price3').value; 
            total = seat1*price1 + seat2*price2 + seat3*price3;
        }
    if(num_seats == 4)
        {
            seat1 = document.getElementById('seat1').value;
            price1 = document.getElementById('price1').value;
            seat2 = document.getElementById('seat2').value;
            price2 = document.getElementById('price2').value;
            seat3 = document.getElementById('seat3').value;
            price3 = document.getElementById('price3').value;
            var seat4 = document.getElementById('seat4').value;
            price4 = document.getElementById('price4').value;
            total = seat1*price1 + seat2*price2 + seat3*price3 + seat4*price4;
        }
    if(num_seats == 5)
        {
            seat1 = document.getElementById('seat1').value;
            price1 = document.getElementById('price1').value;
            seat2 = document.getElementById('seat2').value;
            price2 = document.getElementById('price2').value;
            seat3 = document.getElementById('seat3').value;
            price3 = document.getElementById('price3').value;
            seat4 = document.getElementById('seat4').value;
            price4 = document.getElementById('price4').value;
            var seat5 = document.getElementById('seat5').value;
            price5 = document.getElementById('price5').value;
            total = seat1*price1 + seat2*price2 + seat3*price3 + seat4*price4 + seat5*price5;
        }    

    if( total > 0 )
    	document.getElementById('price_total').value = total;


}
