//////////////////////////////////////////////////////////////////////////////
//
// straightforward javascript functions
//
//////////////////////////////////////////////////////////////////////////////

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

//////////////////////////////////////////////////////////////////////////////

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

//////////////////////////////////////////////////////////////////////////////

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//////////////////////////////////////////////////////////////////////////////

function openWindow(theURL, theName, width, height) {
        var w = window.open(theURL , ""+theName+"" ,"width=" + width + ",height="+ height + ",toolbar=0,directories=0,menubar=0,status=0,resizable=1,location=0,scrollbars=1,copyhistory=0,alwaysRaised=yes");
		w.focus();
}

//////////////////////////////////////////////////////////////////////////////

function FitPic() {
	var iWidth = 0, iHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		iWidth = window.innerWidth;
		iHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		iWidth = document.documentElement.clientWidth;
		iHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		iWidth = document.body.clientWidth;
		iHeight = document.body.clientHeight;
	}
	iWidth = (document.images[0].width - iWidth) + 60;
	iHeight = (document.images[0].height - iHeight) + 55;
	window.resizeBy(iWidth, iHeight);
	self.focus();
};

//////////////////////////////////////////////////////////////////////////////

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

//////////////////////////////////////////////////////////////////////////////

function validateEnquiryForm(random_code) {

	var name = document.forms.enquiry_form.name.value;
	var telephone = document.forms.enquiry_form.telephone.value;
	var email = document.forms.enquiry_form.email.value;
	var message = document.forms.enquiry_form.message.value;
	var enquiry_type = document.forms.enquiry_form.enquiry_type.value;
	var promo_code = document.forms.enquiry_form.promo_code.value;
	var entered_random_code = document.forms.enquiry_form.validation_code.value;
	
	// make sure any provided code is valid - we have to do everything in line like this because IE
	// has trouble passing the status value back from a separate function
	if( promo_code != '' ) {
	
		try {
			xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
			new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e) { /* do nothing */ }
	
		element = "code_validation";
		xmlhttp.onreadystatechange = triggered;
		xmlhttp.open("GET", "check_competition_code.php?code=" + promo_code, false);
		xmlhttp.send(null);
		status = xmlhttp.responseText;
//alert('msg = ' + status);

		if( status != '' ) {
			alert('Sorry, but there is a problem with that competition code.\n\n' + status );
			return false;
		} 
	} 
	
	if( name == '' ) {
		alert('Oops - you forgot to supply your name.');
		return false;
	} 
	
	if( (telephone == '') && (email == '') ) {
		alert('Oops - please supply either your telephone number\nor email address so that we can contact you.');
		return false;
	}
	
	if( email != '' ) {
		if( !echeck(email) ) {
			alert('Oops - please supply a valid email address.');
			return false;
		}
	} 
	
	if( message == '' ) {
		alert('Oops - you forgot to enter a message.');
		return false;
	} 
	
	if( enquiry_type == '0' ) {
		alert('Oops - please select an Enquiry Type.');
		return false;
	} 

	if( random_code != entered_random_code ) {
		alert('Oops - the random code you entered does not match the one displayed.');
		return false;
	} 
	
	return true;
}

//////////////////////////////////////////////////////////////////////////////

/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

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){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}

//////////////////////////////////////////////////////////////////////////////

function updateActivityCalendar() {

	var activity_id = document.forms.activityForm.activities.value;
	
	window.location = 'index.php?f=availability-Calendar&activity_id=' + activity_id;
}

//////////////////////////////////////////////////////////////////////////////

function updateAvailabilityForm() {

	var activity_id = document.forms.availability_add.activity.value;
	
	window.location = 'index.php?f=availability-Add&activity_id=' + activity_id;
}

//////////////////////////////////////////////////////////////////////////////

function checkTimeSlotForm(max_places) {

	var adults = parseInt(document.forms.tickets.adults.value);
	var under_18 = parseInt(document.forms.tickets.under_18.value);
	var under_12 = parseInt(document.forms.tickets.under_12.value);
	var total = adults + under_18 + under_12;
	var ratio = under_12 / adults;
	
	if( !total ) {
		alert('Please indicate how many spaces you require for this time slot.' );
		return false;
	
	} else if( total > max_places ) {
		alert('This time slot has ' + max_places + ' places available.\nYou have selected a total of ' + total + ' places.\n\nPlease amend your selection, or choose another time slot.' );
		return false;
	
	} else if( ratio > 2 ) {
		alert('For safety reasons, every two children under the age of 12\nmust be accompanied by at least one adult');
		return false;
	
	} else return true;
}

//////////////////////////////////////////////////////////////////////////////

function checkBasketUpdateForm() {

	var num_slots = parseInt(document.forms.summary.numSlots.value);

	for( var i=0; i<num_slots; i++ ) {
		var adults = parseInt(document.forms.summary['adults_' + i].value);
		var under_18 = parseInt(document.forms.summary['under_18_' + i].value);
		var under_12 = parseInt(document.forms.summary['under_12_' + i].value);
		var max_places = parseInt(document.forms.summary['maxPlaces_' + i].value);
		var slot_details = document.forms.summary['slotDetails_' + i].value;
		var total = adults + under_18 + under_12;
		var ratio = under_12 / adults;
		if( !total && !document.forms.summary['delete_slot_' + i].checked ) {
			alert(slot_details + '\n\nPlease indicate how many spaces you require for this time slot, or check \'delete\'.' );
			return false;
		
		} else if( total > max_places ) {
			alert(slot_details + '\n\nThis time slot has ' + max_places + ' places available.\nYou have selected a total of ' + total + ' places.\n\nPlease amend your selection.' );
			return false;
		
		} else if( ratio > 2 ) {
			alert(slot_details + '\n\nFor safety reasons, every two children under the age of 12\nmust be accompanied by at least one adult');
			return false;
		} 
	}

	// make sure any provided code is valid - we have to do everything in line like this because IE
	// has trouble passing the status value back from a separate function
	var promo_code = document.forms.summary.promo_code.value;
	if( promo_code != '' ) {
	
		try {
			xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
			new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e) { /* do nothing */ }
	
		element = "code_validation";
		xmlhttp.onreadystatechange = triggered;
		xmlhttp.open("GET", "check_promo_code.php?code=" + promo_code, false);
		xmlhttp.send(null);
		status = xmlhttp.responseText;
//alert('msg = ' + status);

		if( status != '' ) {
			alert('Sorry, but there is a problem with that promo code.\n\n' + status );
			return false;
		} 
	} 
	
	return true;
}

//////////////////////////////////////////////////////////////////////////////

function checkOverlappedActivities(activitiesOverlapped) {

	var proceed = true;
	
	if(activitiesOverlapped) proceed = confirm("You are about to book two different activities starting at the same time.\n\nClick OK if this is correct, or Cancel if you wish to change one of the bookings.");
	
	return proceed;
}

//////////////////////////////////////////////////////////////////////////////

function checkNumberOfActivities(numActivities) {

	var proceed = true;
	
	if(numActivities > 1) proceed = confirm("You are about to book more than one activity.\n\nClick OK if you are happy that you have enough time between activities, or Cancel if you wish to change one of the bookings.");
	
	return proceed;
}

//////////////////////////////////////////////////////////////////////////////

function checkCustomerForm() {

	var first_name = document.forms.customer.first_name.value;
	var last_name = document.forms.customer.last_name.value;
	var address1 = document.forms.customer.address1.value;
	var address2 = document.forms.customer.address2.value;
	var town = document.forms.customer.town.value;
	var county = document.forms.customer.county.value;
	var postcode = document.forms.customer.postcode.value;
	var country = document.forms.customer.country.value;
	var telephone = document.forms.customer.telephone.value;
	var mobile = document.forms.customer.mobile.value;
	var email = document.forms.customer.email.value;
	
	if( 
		(first_name == '') ||
		(last_name == '') ||
		(address1 == '') ||
		(town == '') ||
		(county == '') ||
		(postcode == '') ||
		(country == '') ||
		(email == '') ) {
		alert('Please fill in all required fields.');
		return false;

	} else if( (telephone == '') && (mobile == '') ) {
		alert('Please supply either your telephone number or mobile number.');
		return false;
	
	} else if( !document.forms.customer.terms.checked ) {
		alert('Please indicate that you agree to the booking terms.');
		return false;

	} else return true;
}

//////////////////////////////////////////////////////////////////////////////

function loadURL(destination, elementID) {
	
	try {
		xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
		new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch (e) { /* do nothing */ }
	
	element = elementID;
	xmlhttp.onreadystatechange = triggered;
	xmlhttp.open("GET", destination, true);
	xmlhttp.send(null);
}

//////////////////////////////////////////////////////////////////////////////

function triggered() {
  	if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
    
		if( xmlhttp.responseText && (xmlhttp.responseText !='') ) {
			try {	
				document.getElementById(element).innerHTML = xmlhttp.responseText;
			}
			catch(e) {
				// IE fails unless we wrap the string in another element.
				var wrappingDiv = document.createElement('div');
				wrappingDiv.innerHTML = xmlhttp.responseText;
				document.getElementById(element).appendChild(wrappingDiv);
			}
		}
	}
}

//////////////////////////////////////////////////////////////////////////////

function displayPromotionType(mode, id) {

	var type = document.forms.promo_form.promotion_type.value;
	window.location = 'index.php?f=promotion-' + mode + '&type=' + type + '&id=' + id;
}

//////////////////////////////////////////////////////////////////////////////

function checkCmsBookingForm() {

	var num_slots = parseInt(document.forms.cms_booking_form.num_time_slots.value);

	var customer_first_name = document.forms.cms_booking_form.customer_first_name.value;
	var customer_last_name = document.forms.cms_booking_form.customer_last_name.value;
	if( (customer_first_name == '') || (customer_last_name == '') ) {
		alert('Please enter the customer\'s name');
		return false;
	}

	var customer_telephone = document.forms.cms_booking_form.customer_telephone.value;
	var customer_mobile = document.forms.cms_booking_form.customer_mobile.value;
	var customer_email = document.forms.cms_booking_form.customer_email.value;
	if( (customer_telephone == '') && (customer_mobile == '') && (customer_email == '') ) {
		alert('Please enter at least one method of contacting the customer - \n\nTelephone, Mobile, or Email');
		return false;
	}
	
	if( !num_slots ) {
		var activity = document.forms.cms_booking_form.new_activity.value;
		if( activity == '0' ) {
			alert('Please select an Activity');
			return false;
		}
		var num_adults = parseFloat(document.forms.cms_booking_form.new_activity_num_adults.value);
		var num_under_18 = parseFloat(document.forms.cms_booking_form.new_activity_num_under_18.value);
		var num_under_12 = parseFloat(document.forms.cms_booking_form.new_activity_num_under_12.value);
		var num_people = num_adults + num_under_18 + num_under_12;
		if( !num_people ) {
			alert('Please indicate how many people are being booked onto this Activity');
			return false;
		}
	}

	var voucher_code = document.forms.cms_booking_form.voucher_code.value;
	var amount_paid_by_voucher = parseFloat(document.forms.cms_booking_form.amount_paid_by_voucher.value);
	if( amount_paid_by_voucher && ( voucher_code == '' ) ) {
		alert('Please enter a voucher code');
		return false;
	
	} else if( voucher_code != '' ) {
		
		if( !amount_paid_by_voucher ) {
			alert('Please enter the amount paid by voucher');
			return false;
		}

		var booking_id = parseInt(document.forms.cms_booking_form.id.value);

		element = "blank";
		try {
			xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
			new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e) { /* do nothing */ }
	
		xmlhttp.onreadystatechange = triggered;
		xmlhttp.open("GET", 'index.php?f=booking-CheckVoucherCode&code=' + voucher_code + '&value=' + amount_paid_by_voucher + '&booking_id=' + booking_id, false);
		xmlhttp.send(null);
		var response = xmlhttp.responseText;
		if( response != 'ok' ) {
			alert(response);
			return false;
		}
	}

	var payment_status = document.forms.cms_booking_form.payment_status.value;
	if( payment_status == '' ) {
		alert('Please select a Payment Status');
		return false;
	}
	
	if( payment_status == 'deposit_paid' ) {
		var deposit_amount = parseFloat(document.forms.cms_booking_form.deposit_amount.value);
		if( deposit_amount <= 0 ) {
			alert('Please enter a Deposit Amount');
			return false;
		}

		var deposit_date_today = document.forms.cms_booking_form.deposit_date_today.checked;
		var deposit_year = document.forms.cms_booking_form.deposit_date_Year.value;
		var deposit_month = document.forms.cms_booking_form.deposit_date_Month.value;
		var deposit_day = document.forms.cms_booking_form.deposit_date_Day.value;
		if( !deposit_date_today && ((deposit_year == '') || (deposit_month == '') || (deposit_day == '')) ) {
			alert('Please enter the date when the deposit was paid');
			return false;
		}

		var amount_paid_by_cash = parseFloat(document.forms.cms_booking_form.amount_paid_by_cash.value);
		var amount_paid_by_cheque = parseFloat(document.forms.cms_booking_form.amount_paid_by_cheque.value);
		var amount_paid_by_card = parseFloat(document.forms.cms_booking_form.amount_paid_by_card.value);
		var amount_paid_by_voucher = parseFloat(document.forms.cms_booking_form.amount_paid_by_voucher.value);
		if( (amount_paid_by_cash <= 0) && (amount_paid_by_cheque <= 0) && (amount_paid_by_card <= 0) && (amount_paid_by_voucher <= 0) ) {
			alert('Please enter an amount in the appropriate payment method');
			return false;
		}

	} else if( payment_status == 'paid' ) {
		var subtotal = 0;
		var adults = 0;
		var under_18 = 0;
		var under_12 = 0;
		var adults_price = 0;
		var under_18_price = 0;
		// work out the value of all time slots
		for( var i=0; i<num_slots; i++ ) {
			if( document.forms.cms_booking_form['activities_' + i].value != '0' ) {
				adults = parseInt(document.forms.cms_booking_form['num_adults_' + i].value);
				under_18 = parseInt(document.forms.cms_booking_form['num_under_18_' + i].value);
				under_12 = parseInt(document.forms.cms_booking_form['num_under_12_' + i].value);
				adults_price = parseFloat(document.forms.cms_booking_form['price_adult_' + i].value);
				under_18_price = parseFloat(document.forms.cms_booking_form['price_under_18_' + i].value);
				subtotal += (adults * adults_price) + (under_18 * under_18_price) + (under_12 * under_18_price);
			}
		}
		if( document.forms.cms_booking_form['new_activity'].value != '0' ) {
			adults = parseInt(document.forms.cms_booking_form['new_activity_num_adults'].value);
			under_18 = parseInt(document.forms.cms_booking_form['new_activity_num_under_18'].value);
			under_12 = parseInt(document.forms.cms_booking_form['new_activity_num_under_12'].value);
			adults_price = parseFloat(document.forms.cms_booking_form['new_activity_price_adult'].value);
			under_18_price = parseFloat(document.forms.cms_booking_form['new_activity_price_under_18'].value);
			subtotal += (adults * adults_price) + (under_18 * under_18_price) + (under_12 * under_18_price);
		}
		var discount = parseFloat(document.forms.cms_booking_form.discount.value);
		var total = subtotal - discount;
		var amount_paid_by_cash = parseFloat(document.forms.cms_booking_form.amount_paid_by_cash.value);
		var amount_paid_by_cheque = parseFloat(document.forms.cms_booking_form.amount_paid_by_cheque.value);
		var amount_paid_by_card = parseFloat(document.forms.cms_booking_form.amount_paid_by_card.value);
		var amount_paid_by_voucher = parseFloat(document.forms.cms_booking_form.amount_paid_by_voucher.value);
		var amount_paid = amount_paid_by_cash + amount_paid_by_cheque + amount_paid_by_card + amount_paid_by_voucher;
		if( amount_paid != total  ) {
			alert('The amounts paid do not match the Booking Total\n\nAmount Paid = £' + amount_paid + '\nBooking Total = £' + total );
			return false;
		}

		var payment_date_today = document.forms.cms_booking_form.payment_date_today.checked;
		var payment_year = document.forms.cms_booking_form.payment_date_Year.value;
		var payment_month = document.forms.cms_booking_form.payment_date_Month.value;
		var payment_day = document.forms.cms_booking_form.payment_date_Day.value;
		if( !payment_date_today && ((payment_year == '') || (payment_month == '') || (payment_day == '')) ) {
			alert('Please enter the date when the balance was paid');
			return false;
		}
	
	} else return true;
}

//////////////////////////////////////////////////////////////////////////////

function updateActivityPrice() {

	var activity = document.forms.cms_booking_form.new_activity.value;

	if( activity == '0' ) {
		document.forms.cms_booking_form['new_activity_price_adult'].value = '0.00';
		document.forms.cms_booking_form['new_activity_price_under_18'].value = '0.00';
	
	} else {
		var year = document.forms.cms_booking_form.new_activity_date_Year.value;
		var month = document.forms.cms_booking_form.new_activity_date_Month.value;
		var day = document.forms.cms_booking_form.new_activity_date_Day.value;
		var date = year + '-' + month + '-' + day;

		element = "blank";
		try {
			xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
			new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e) { /* do nothing */ }
	
		xmlhttp.onreadystatechange = triggered;
		xmlhttp.open("GET", 'index.php?f=booking-UpdateSlotPrices&activity=' + activity + '&date=' + date, false);
		xmlhttp.send(null);
		response = xmlhttp.responseText;
		var prices = response.split('_');
		document.forms.cms_booking_form['new_activity_price_adult'].value = prices[0];
		document.forms.cms_booking_form['new_activity_price_under_18'].value = prices[1];
	}
}

//////////////////////////////////////////////////////////////////////////////

function checkCmsVoucherForm() {

	var value = parseFloat(document.forms.cms_voucher_form.value.value);
	if( !value  ) {
		alert('Please enter a Voucher Value');
		return false;
	}

	var amount_paid_by_cash = parseFloat(document.forms.cms_voucher_form.amount_paid_by_cash.value);
	var amount_paid_by_cheque = parseFloat(document.forms.cms_voucher_form.amount_paid_by_cheque.value);
	var amount_paid_by_card = parseFloat(document.forms.cms_voucher_form.amount_paid_by_card.value);
	var amount_paid = amount_paid_by_cash + amount_paid_by_cheque + amount_paid_by_card;
	if( amount_paid != value  ) {
		alert('The amounts paid do not match the Voucher Value\n\nAmount Paid = £' + amount_paid );
		return false;
	}
}

//////////////////////////////////////////////////////////////////////////////

// @name      The Fade Anything Technique
// @namespace http://www.axentric.com/aside/fat/
// @version   1.0-RC1
// @author    Adam Michela

var Fat = {
	make_hex : function (r,g,b) 
	{
		r = r.toString(16); if (r.length == 1) r = '0' + r;
		g = g.toString(16); if (g.length == 1) g = '0' + g;
		b = b.toString(16); if (b.length == 1) b = '0' + b;
		return "#" + r + g + b;
	},
	fade_all : function ()
	{
		var a = document.getElementsByTagName("*");
		for (var i = 0; i < a.length; i++) 
		{
			var o = a[i];
			var r = /fade-?(\w{3,6})?/.exec(o.className);
			if (r)
			{
				if (!r[1]) r[1] = "";
				if (o.id) Fat.fade_element(o.id,null,null,"#"+r[1]);
			}
		}
	},
	fade_element : function (id, fps, duration, from, to) 
	{
		if (!fps) fps = 30;
		if (!duration) duration = 3000;
		if (!from || from=="#") from = "#FFFFCC";
		if (!to) to = this.get_bgcolor(id);
		
		var frames = Math.round(fps * (duration / 1000));
		var interval = duration / frames;
		var delay = interval;
		var frame = 0;
		
		if (from.length < 7) from += from.substr(1,3);
		if (to.length < 7) to += to.substr(1,3);
		
		var rf = parseInt(from.substr(1,2),16);
		var gf = parseInt(from.substr(3,2),16);
		var bf = parseInt(from.substr(5,2),16);
		var rt = parseInt(to.substr(1,2),16);
		var gt = parseInt(to.substr(3,2),16);
		var bt = parseInt(to.substr(5,2),16);
		
		var r,g,b,h;
		while (frame < frames)
		{
			r = Math.floor(rf * ((frames-frame)/frames) + rt * (frame/frames));
			g = Math.floor(gf * ((frames-frame)/frames) + gt * (frame/frames));
			b = Math.floor(bf * ((frames-frame)/frames) + bt * (frame/frames));
			h = this.make_hex(r,g,b);
		
			setTimeout("Fat.set_bgcolor('"+id+"','"+h+"')", delay);

			frame++;
			delay = interval * frame; 
		}
		setTimeout("Fat.set_bgcolor('"+id+"','"+to+"')", delay);
	},
	set_bgcolor : function (id, c)
	{
		var o = document.getElementById(id);
		o.style.backgroundColor = c;
	},
	get_bgcolor : function (id)
	{
		var o = document.getElementById(id);
		while(o)
		{
			var c;
			if (window.getComputedStyle) c = window.getComputedStyle(o,null).getPropertyValue("background-color");
			if (o.currentStyle) c = o.currentStyle.backgroundColor;
			if ((c != "" && c != "transparent") || o.tagName == "BODY") { break; }
			o = o.parentNode;
		}
		if (c == undefined || c == "" || c == "transparent") c = "#FFFFFF";
		var rgb = c.match(/rgb\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/);
		if (rgb) c = this.make_hex(parseInt(rgb[1]),parseInt(rgb[2]),parseInt(rgb[3]));
		return c;
	}
}

//////////////////////////////////////////////////////////////////////////////
