/* LIBRARY SCRIPTS
 * Specific functionality
 * 1.0
 
 * SCRIPT CHANGES (Eg. Date (dd/mm/yyyy), Name (Tom.McCourt), Change (function name))
 *
 * 13/07/2007, Tom.McCourt, Created
------------------------------------------------------------*/

/* Load
------------------------------*/
Event.domLoad(function() {

		PopUp.hookup("overlay", 
			function() {
				return StaticPage.display(this);
			}
		);
		
		PopUp.hookup("feather", 
			function() {
				return StaticPage.displayFeather("feather-rating",this);
			}
		);
		
		MM_preloadImages(UrlUtils.absoluteWebPath("/images/default/en/lightbox/blank.gif"));
		
		//preloadImages();
		printerFrame();
		flickerFix();
		MiniSearch.init();
		MiniBasket.init();
		FormUtils.applyRichInterface();
		var bodyId = document.body.id;
		
		switch(bodyId) {
			case "home-page":
				//StoreSearch.init();
			break;
			case "list-page":
				MM_preloadImages(UrlUtils.absoluteWebPath("/images/default/en/site/buttons/featured_off.gif"));
				MM_preloadImages(UrlUtils.absoluteWebPath("/images/default/en/site/buttons/featured.gif"));
				FeaturedProducts.init();
				
				//function StyleTheLast() {						
				//var theItem = document.getElementById("products-list").lastChild;
				//theItem.className="lastli";	
				//}
				//StyleTheLast();
			break;
			case "category-page":
				FeaturedProducts.init();
			break;
			case "product-page":
				ProductInfo.init();
				Product.init();
				sIFR.replaceElement(named({sSelector: "#product-page h2", sFlashSrc: UrlUtils.absoluteWebPath("/styles/font/gill-sans-light.swf"), sColor: "#666666", sWmode: "transparent"}));
				sIFR.replaceElement(named({sSelector: "#product-page .variant-matrix h3", sFlashSrc: UrlUtils.absoluteWebPath("/styles/font/gill-sans-light.swf"), sColor: "#222222", sWmode: "transparent"}));
			break;
			case "bed-selector-page":
				BedSelector.init();
				
			break;
			case "basket-page":
				BasketDiscount.init();
			break;
			case "store-locator-page":
				var fo = new FlashObject("../../images/default/en/site/flash/GB_map.swf", "animationName", "285", "419", "8", "#FFFFFF");
				fo.addParam("allowScriptAccess", "sameDomain");
				fo.addParam("quality", "high");
				fo.addParam("scale", "noscale");
				fo.addParam("loop", "false");
				fo.write("locator-map");
			break;
			case "store-locator-details":
		
			break;	
		}
	}
);		

/* General
------------------------------*/
function printerFrame() {
var objBody = document.getElementsByTagName("body").item(0);
var objOverlay = document.createElement("iframe");
objOverlay.setAttribute('id','printerIframe');
objOverlay.setAttribute('name','printerIframe');
objOverlay.setAttribute('src',UrlUtils.absoluteWebPath("/secure.html"));
objBody.insertBefore(objOverlay, objBody.firstChild);
}

function flickerFix() {
	try {
		document.execCommand("BackgroundImageCache", false, true);
	} catch(e) {}
}

function preloadImages() {
	img = new Image();
	img.src = UrlUtils.absoluteWebPath("/images/default/en/lightbox/blank.gif");
	
	img = new Image();
	img.src = UrlUtils.absoluteWebPath("/images/default/en/lightbox/loading.gif");
	
	img = new Image();
	img.src = UrlUtils.absoluteWebPath("/images/default/en/lightbox/close.gif");
}


function convertToBoolean(property) {
	return (property == "true")
}

function confirmOrder() {
	// .NET problems with validation and adding in custom inline JS
	var button = document.getElementsByTagName("input");

	for (var i = 0, c = button.length, o; i < c; i++) {
		// Check for class name with either "submit-order-footer" or "submit-order"
		if (button[i].className.indexOf("submit-order") != -1) {
			// Save old click function
			o = button[i].onclick;
			
			// Add old and add our own
			button[i].onclick = function() {
				o();
				this.disabled = true;
			}
		}
	}
}

/* Product Information
 ------------------------------*/
var ProductInfo = {
	init : function() {
		var wrap = document.getElementById("product");
		if (wrap) {
			var divs = wrap.getElementsByTagName("div");
			for (var i = 0, c = divs.length; i < c; i++) {
				if (divs[i].className == "product-help") {
					divs[i].style.display = "none";
				}
			}
		}
	},
	toggle : function(id) {
		
		var el = document.getElementById(id);
		if(el && el.style.display== "" || el.style.display == "none"){
		
			// Hide select boxes as they will 'peek' through the image in IE
			selects = document.getElementsByTagName("select");
			
			for (i = 0; i != selects.length; i++)
			{
				selects[i].style.visibility = "hidden";
			}
			el.style.zIndex = 999;
		    el.style.opacity = 0;
			el.style.MozOpacity = 0;
			el.style.KhtmlOpacity = 0;
			
			opacity("overlay", 0, 65, 1000);
			pause(500, function()
			{
				opacity(id, 0, 100, 1000);	
			});
		    //Changed by Dennis to match live
		    //opacity(id, 0, 100, 1000); 
		    //document.getElementById("overlay").style.display="block";
		    document.getElementById("overlay").style.height="1126px";
		}
		else
		{
			// Hide select boxes as they will 'peek' through the image in IE
			selects = document.getElementsByTagName("select");
			for (i = 0; i != selects.length; i++) {
                selects[i].style.visibility = "visible";
			}
			//Changed by Dennis to match live
			//opacity("overlay", 65, 0, 1500);
			//opacity(id, 100, 0, 1500);
			document.getElementById("overlay").style.display="none";
			el.style.display="none";
			el.style.opacity = 0;
			el.style.MozOpacity = 0;
			el.style.KhtmlOpacity = 0;
		}
		
		return false;
	},
	toggleFeather : function(id) {
		alert('Feather');	
		return false;
	}
};

/* Product
 * Feather Rating
 ------------------------------*/
var FeatherRating = {
	item : null,
	init : function() {
		this.item = document.getElementById("feather-rating");
		if (!this.item) return;
		this.nameMouseoverFunction(this.item);
		this.nameMouseoutFunction(this.item);
	},
	nameMouseoverFunction : function(e) {
		e.onmouseover = function() {
			//FeatherRating.reset();
			MiniInfo.show("feather-rating-info", e.innerHTML, {direction: "left", position: false});
			MiniInfo.position("feather-rating", "feather-rating-info", {offsetX : 40, offsetY : 5});
		};
	},
	nameMouseoutFunction : function(e) {
		e.onmouseout = function() {
			MiniInfo.hide("feather-rating-info", true);
		};
	},
	reset : function() {
		clearTimeout(MiniInfo.timer);
		var item;
		item = document.getElementById("feather-rating-info");
		if (item) {
			item.style.display = "none";
		}
	}
};

/* Bed Selector
 ------------------------------*/
 var BedSelector = {
	selector : null,
	init : function() {
		this.selector = document.getElementById("bed-selector");
		if (!this.selector) { return; }
		var select = this.selector.getElementsByTagName("select");
		for (var i = 0, c = select.length, submit; i < c; i++) {
			submit = select[i].parentNode.getElementsByTagName("input")[0];
			this.functionPostback(select[i], submit);
		}
	},
	functionPostback : function(e, submit) {
		Event.add(e, "change", function() {
			if (submit) BedSelector.postback(this, submit.id);
		}); 
	},
	// Fire as auto-submit
	postback : function(e, submit) {
		FormUtils.submit(submit);
	}
 };

/* Basket
 * Control basket
 ------------------------------*/
var FeaturedProducts = {
	items : null,
	init : function() {
	
		var wrap = document.getElementById("featured-products");
		if (!wrap) return;
		this.items = wrap.getElementsByTagName("li");
		for (var i = 0, c = this.items.length; i < c; i++) {

			var dt = this.items[i].getElementsByTagName("h3")[0];

			if(dt.nextSibling.nodeType == 3) {
				dd = dt.nextSibling.nextSibling;
			}
			else {
				dd = dt.nextSibling;
			}

			this.nameMouseoverFunction(dt, dd, i);
			this.nameMouseoutFunction(dt, dd, i);
			dt.id = "featured-title-" + i;
		}
	},
	nameMouseoverFunction : function(dt, dd, i) {
		dt.onmouseover = function() {
			FeaturedProducts.reset();
			MiniInfo.show("featured-info-" + i, dd.innerHTML, {direction: "top", position: false});
			MiniInfo.position("featured-title-" + i, "featured-info-" + i, {offsetX : 25, offsetY : 20});
		};
	},
	nameMouseoutFunction : function(dt, dd, i) {
		dt.onmouseout = function() {
			MiniInfo.hide("featured-info-" + i, true);
		};
	},
	reset : function() {
		clearTimeout(MiniInfo.timer);
		var item;
		for (var i = 0, c = this.items.length; i < c; i++) {
			item = document.getElementById("featured-info-" + i);
			if (item) {
				item.style.display = "none";
			}
		}
	}
};


/* Mini info
 * Utility to display information across the site
 * Options are {direction: "top|left", position: true|false, offsetX: num, offsetY: num}
 ------------------------------*/
var MiniInfo = {
	timer : null,
	create : function(infoId, content, options) {
		var info 		= document.createElement("div");
		var infoContent = document.createElement("div");
		var infoFooter 	= document.createElement("div");
		
		info.id					= infoId;
		infoContent.className = "mini-info-content";
		infoContent.innerHTML = content;
		infoFooter.className = "mini-info-footer";

		if (options.direction) {
			info.className = "mini-info-" + options.direction;
		} else {
			info.className = "mini-info-left";
		}
		
		info.appendChild(infoContent);
		info.appendChild(infoFooter);
		document.body.appendChild(info);
		
		if (options.position) {
			this.position(options.anchor, infoId, options);
		}
	},
	changeinfo : function(infoId, content) {
		var info = document.getElementById(infoId);
		info.className = "mini-info-content";
		info.innerHTML = content;
		info.className = "mini-info-footer";
	},
	show : function(infoId, content, options) {
		clearTimeout(this.timer);
		var info = document.getElementById(infoId);
		if (info) {
			info.style.display = "block";
			this.changeinfo(infoId, content);
		} else {
			this.create(infoId, content, options);
		}
	},
	hide : function(infoId, timer) {
		var info = document.getElementById(infoId);
		if (info) { 	
			if (timer) {
				var hideInfo = function() {
					var info = document.getElementById(infoId);
					info.style.display = "none";
				}
				this.timer = setTimeout(hideInfo, 500);
			} else {
				info.style.display = "none";
			}
		}
	},
	position: function(e, infoId, options) {
		infoId = document.getElementById(infoId);
		if (infoId) {
			var offsetX = 0;
			var offsetY = 0;
			if (options) {
				var offsetX = (options.offsetX) ? options.offsetX : 0;
				var offsetY = (options.offsetY) ? options.offsetY : 0;
			}
			Effects.position(infoId, {position: 'absolute', top: (Effects.getTop(e) + offsetY), left: (Effects.getLeft(e) + offsetX)});
		}
	}
};


/* MiniSearch
------------------------------*/
var MiniSearch = {
	search			: null,
	field			: null,
	defaultValue	: 'Enter a product or keyword',
	submit			: null,
	init : function() {
		if (!document.getElementById) { return true; }
		this.search = document.getElementById('mini-search');
		if (!this.search) { return; }
		this.field = this.search.getElementsByTagName('input')[0];
		this.submit = this.search.getElementsByTagName('input')[1];
		if (this.field) {
			this.field.value = this.defaultValue;
			this.field.onfocus = function() {
				if (this.value === MiniSearch.defaultValue) {
					this.value = '';
				}
			};
			this.field.onblur = function() {
				if (this.value === '') {
					this.value = MiniSearch.defaultValue;
				}
			};
		}
	}
};



/* MiniBasket
------------------------------*/
var MiniBasket = {
	basket : null,
	cookie : null,
	output : null,
	toggle : function() {
		if (!this.basket) { return true; }

		this.slider.toggle();

		return false;
	},
	init : function() {
		if (!document.getElementById) { return true; }
		this.basket = document.getElementById('mini-basket-info');
	},
	render : function() {
		if (!document.getElementById) { return; }
		var basket = document.getElementById("mini-basket");
		if (!basket) { return; }
		MiniBasket.output = basket.getElementsByTagName("a")[0];
		MiniBasket.cookie = eval("(" + Cookie.get("MiniBasket") + ")");
		if (MiniBasket.cookie == null || MiniBasket.cookie == "") {
			var newEM = document.createElement("em");
			var basketText = document.createTextNode("Basket");
			var emptyText = document.createTextNode(" 0 items, total:");
			var totalText = document.createTextNode("\u00A30");
		
			basketText = newEM.appendChild(basketText);
			totalText = newEM.appendChild(totalText);
			//oNewEM.createTextNode(" 0 items, total: \u00A30");
			
			emptyElement(MiniBasket.output);
			MiniBasket.output.appendChild(basketText + emptyText + totalText);
		} else {
			var nItems = MiniBasket.cookie.basket[0].totalitems;
			var strItems;
			if (nItems == "1") {
				strItems = "item";
			} else {
				strItems = "items";
			}
			
			if (nItems == "0" || "") {
				
				var oBasketEM = document.createElement('em'); 
				var basketWord = document.createTextNode("Basket");
				oBasketEM.appendChild(basketWord);
	
				var itemText = document.createTextNode(" 0 items, ");
				var basketText = document.createTextNode(" 0 items, total: ");
				
				var oCurrencyEM = document.createElement('em');
				var basketCurrency = document.createTextNode("\u00A30");
				oCurrencyEM.appendChild(basketCurrency);
				
				emptyElement(MiniBasket.output);
				MiniBasket.output.appendChild(oBasketEM);
				MiniBasket.output.appendChild(basketText);
				MiniBasket.output.appendChild(oCurrencyEM);
			} 
			else{

				var total = MiniBasket.cookie.basket[0].total.toString();

// total = total.substring(1);

				var text = document.createTextNode(nItems + " " + strItems + ", total: " + total );
				emptyElement(MiniBasket.output);
				MiniBasket.output.appendChild(text);
			}
		}
	}
};

/* StoreSearch
------------------------------
var StoreSearch = {
	search			: null,
	field			: null,
	defaultValue	: "",
	submit			: null,
	init : function() {
		if (!document.getElementById) { return true; }
		this.search = document.getElementById('store-search');
		if (!this.search) { return; }
		this.field = this.search.getElementsByTagName('input')[0];
		this.defaultValue = this.field.value;
		if (this.field) {
			this.field.value = this.defaultValue;
			this.field.onfocus = function() {
				if (this.value === StoreSearch.defaultValue) {
					this.value = "";
				}
			};
			this.field.onblur = function() {
				if (this.value === "") {
					this.value = StoreSearch.defaultValue;
				}
			};
		}
	}
};
*/
/* Basket
------------------------------*/
var Basket = {
	ajax : new Ajax(),
	add : function(e, args, qty, vid) {
		if (!document.getElementById) { return }
		
		this.ajax.set(e, args, "content");
		var qty = document.getElementById(qty);
		if (qty) {
			qty = qty.value;
			this.ajax.addParam("qty", qty);
		}
		
		var vid = document.getElementById(vid);
		if (vid) {
			vid = vid.value;
			this.ajax.addParam("vid", vid);
		}
		
		var guarantee = FormUtils.getOption("rdGuarantee");
		if (guarantee) {
			this.ajax.addParam("rdGuarantee",guarantee);
		}
		
		var disposal = FormUtils.getOption("rdDisposal");
		if (disposal) {
			this.ajax.addParam("rdDisposal",disposal);
		}
		
		this.ajax.complete = function() {
			var t = document.createTextNode(this.req.responseText);
			
			MiniBasket.render();
			
			// Omniture tag
			Omniture.basketAdd(args.cid, args.pid, new Boolean(json.products[0].scOpen));
			
			var json = this.toJson();
			
			var pid = json.products[0].vid, productData, message;
			if (pid) {
				productData = eval("ProductData.p" + pid);
				message = productData.name + " has been added to your basket with options " + productData.size + ", " + productData.base + ", " + productData.draw;
			} 
			else {
				pid = json.products[0].pid;	
				productData = eval("ProductData.p" + pid);
				message = productData.name + " has been added to your basket";
			}
			
			//* Options are {direction: "top|left", position: true|false, offsetX: num, offsetY: num}
			MiniInfo.show("add-basket-status", message, {direction: "top", position: false});
			MiniInfo.position("add-to-basket", "add-basket-status", {offsetX : -28, offsetY : 30});
		}
		this.ajax.get();
		return false;
	},
	removeItem : function(item) {
	
	},
	updateItemQuantity : function(item, qty) {
	
	},
	update : function(e) {
		
		var basketQty = FormUtils.collect("basket");
		
		this.ajax.method = "Post";
		this.ajax.set(e, basketQty, "content");
		this.ajax.addParam("ajax", "true");
		this.ajax.addParam("cmd", "update");
		
		this.ajax.complete = function() {
			alert(this.req.responseText);
		}
		
		this.ajax.get();
		return false;
	}
};

/* BasketDiscount
------------------------------*/
var BasketDiscount = {
	code			: null,
	field			: null,
	defaultValue	: 'Enter a media code',
	submit			: null,
	init : function() {
	
		if (!document.getElementById) { return true; }
	
		this.code = document.getElementById('basket-discount');
	
		if (!this.code) { return; }
	
		this.field = this.code.getElementsByTagName('input')[0];
		this.submit = this.code.getElementsByTagName('input')[1];
	
		if (this.field) {
			this.field.value = this.defaultValue;
			this.field.onfocus = function() {
				if (this.value == BasketDiscount.defaultValue) {
					this.value = '';
				}
			};
			this.field.onblur = function() {
				if (this.value == '') {
					this.value = BasketDiscount.defaultValue;
				}
			};
		}
	}
};
/* Paragon */ 

var Delivery =
{
	ajaxOutput : "",
	checkSelection: function (radiobuttonlist, deliverydatespanel)
	{
	
		var ddp = document.getElementById(deliverydatespanel); 
		var radoObjList = ddp.getElementsByTagName('input');
		
		if(radoObjList.length > 0) 
		{
			for(var i=0;i<radoObjList.length;i++)  
			{           
				if(radoObjList[i].type=="radio")   
				{                 
					if(radoObjList[i].checked) 
					{  
						if(Delivery.checkInstructionsMaxLength())
						{
							return true;   
						}
						else
						{
							return false;
						}
					}   
				}  
			}
			document.getElementById('delivery-msg').style.display='block'; 
			return false;
			
		}
		else // radio buttons not showing - non paragon order
		{
			return true;  
		}
						
	},
	
	checkInstructionsMaxLength: function ()
	{
		// if user keeps pressing doen keys after exceeding character limit and manages to press continue we deal with it here
		var charCount = document.getElementById('ucDelivery_mltbFurtherInformation').value; 
		document.getElementById('instructions-msg').style.display='none'; 
		if(charCount.length > 1 && charCount.length > 150) 
		{
			document.getElementById('instructions-msg').style.display='block'; 
			document.getElementById('ucDelivery_mltbFurtherInformation').value = document.getElementById('ucDelivery_mltbFurtherInformation').value.substring(0,150);
			return false;						
		}
		return true;
	},
	
	showSwirl: function (rb_delivery_address_no, divButtonDeliveryDate, divChooseDeliveryDate2, bnContinue, bnDeliveryDateQuery )
	{		
//		if (typeof(Page_ClientValidate) == 'function')
//		{
///			Page_ClientValidate(); 
//			if(Page_IsValid == false)
//			{ return false;
			
//			}
//		}
		
		
		
		var ddlTitles = document.getElementById('DefaultMode_newContentRegion_ucAddress_ddlTitles').value;
		var txtFirstName =  document.getElementById('DefaultMode_newContentRegion_ucAddress_txtFirstName').value; 
		var txtLastName = document.getElementById('DefaultMode_newContentRegion_ucAddress_txtLastName').value;
		var txtEmailAddress = document.getElementById('DefaultMode_newContentRegion_ucAddress_txtEmailAddress').value;
		var txtPhone = document.getElementById('DefaultMode_newContentRegion_ucAddress_txtPhone').value;
		var txtPhone2 = document.getElementById('DefaultMode_newContentRegion_ucAddress_txtPhone2').value;
		var txtPhone3 = document.getElementById('DefaultMode_newContentRegion_ucAddress_txtPhone3').value;

		var txtLine1 = '';
		var txtLine2 = '';
		var txtLine3 = '';
		var txtCity = '';
		var txtRegion = '';
		var txtPostCode = '';

		if(document.getElementById('DefaultMode_newContentRegion_ucAddress_ucAddressCardHolder_txtLine1')!= null )
		{
			txtLine1 = document.getElementById('DefaultMode_newContentRegion_ucAddress_ucAddressCardHolder_txtLine1').value;
			txtLine2 = document.getElementById('DefaultMode_newContentRegion_ucAddress_ucAddressCardHolder_txtLine2').value;
			txtLine3 = document.getElementById('DefaultMode_newContentRegion_ucAddress_ucAddressCardHolder_txtLine3').value;
			txtCity = document.getElementById('DefaultMode_newContentRegion_ucAddress_ucAddressCardHolder_txtCity').value;
			txtRegion = document.getElementById('DefaultMode_newContentRegion_ucAddress_ucAddressCardHolder_txtRegion').value;
			txtPostCode = document.getElementById('DefaultMode_newContentRegion_ucAddress_ucAddressCardHolder_txtPostCode').value;
		}

		if( document.getElementById(rb_delivery_address_no).checked == true)
		{
			if(document.getElementById('DefaultMode_newContentRegion_ucAddress_ucAddressDelivery_txtLine1')!= null )
			{
				txtLine1 = document.getElementById('DefaultMode_newContentRegion_ucAddress_ucAddressDelivery_txtLine1').value;
				txtLine2 = document.getElementById('DefaultMode_newContentRegion_ucAddress_ucAddressDelivery_txtLine2').value;
				txtLine3 = document.getElementById('DefaultMode_newContentRegion_ucAddress_ucAddressDelivery_txtLine3').value;
				txtCity = document.getElementById('DefaultMode_newContentRegion_ucAddress_ucAddressDelivery_txtCity').value;
				txtRegion = document.getElementById('DefaultMode_newContentRegion_ucAddress_ucAddressDelivery_txtRegion').value;
				txtPostCode = document.getElementById('DefaultMode_newContentRegion_ucAddress_ucAddressDelivery_txtPostCode').value;
			}
			else
			{
				txtLine1 = '';
				//prompt fail below
			}
		}
		
		if(ddlTitles.length > 0 && txtFirstName.length > 0 &&  txtLastName.length > 0 &&  txtEmailAddress.length > 0 &&  txtPhone.length > 0 &&  txtLine1.length > 0 &&  txtCity.length > 0 &&  txtPostCode.length > 0)
		{
			Delivery.getDeliveryDates(divButtonDeliveryDate,divChooseDeliveryDate2, ddlTitles,txtFirstName,txtLastName,txtEmailAddress,txtPhone,txtPhone2,txtPhone3,txtLine1,txtLine2,txtLine3,txtCity,txtRegion,txtPostCode, bnContinue);
			document.getElementById('swirl-and-search').style.display = 'block';
			document.getElementById(bnDeliveryDateQuery).style.opacity =0.4;
			document.getElementById(bnDeliveryDateQuery).style.filter ='alpha(opacity=40)';
			
			//document.getElementById('<%=bnDeliveryDateQuery.ClientID %>').onclick='';
			document.getElementById(bnDeliveryDateQuery).disabled = true;
			
			return false;
		}
		// drop through and do server side validation 
		return true;	
	},	
	
	
	/* Special instruction character limit */ 

	ismaxlength: function (objTxtCtrl,nLength)	{		
		if (objTxtCtrl.getAttribute && objTxtCtrl.value.length>nLength)
 	                objTxtCtrl.value=objTxtCtrl.value.substring(0,nLength)
 	                
 	       var currentLength = new Number(objTxtCtrl.value.length);
 	       var maximumLength = new Number(nLength);
 	             
 	     if(document.all)

 	            document.getElementById('lblCaption').innerText=(maximumLength - currentLength) +' of '+nLength+' characters remaining';
 	       else
 	            document.getElementById('lblCaption').textContent=(maximumLength - currentLength) +' of '+nLength+' characters remaining';   
 	},
 	        
	getDeliveryDates : function(control, resultsControl ,ddlTitles,txtFirstName,txtLastName,txtEmailAddress,txtPhone,txtPhone2,txtPhone3,txtLine1,txtLine2,txtLine3,txtCity,txtRegion,txtPostCode,button)
	{

		this.ajaxOutput = resultsControl;
		var url =  window.location.protocol + '//' + window.location.host + '/ajax/deliverydates.aspx';
		var ajax = new Ajax(url, {"ajax": "true"}, this.ajaxOutput);
		ajax.method = ajax.postMethod;
		ajax.addParam("ddlTitles=" + ddlTitles);
		ajax.addParam("txtFirstName=" + txtFirstName);
		ajax.addParam("txtLastName=" + txtLastName);
		ajax.addParam("txtEmailAddress=" + txtEmailAddress);
		ajax.addParam("txtPhone=" + txtPhone);
		ajax.addParam("txtPhone2=" + txtPhone2);
		ajax.addParam("txtPhone3=" + txtPhone3);
		ajax.addParam("txtLine1=" + txtLine1);
		ajax.addParam("txtLine2=" + txtLine2);
		ajax.addParam("txtLine3=" + txtLine3);
		ajax.addParam("txtCity=" + txtCity);
		ajax.addParam("txtRegion=" + txtRegion);
		ajax.addParam("txtPostCode=" + txtPostCode);
		
		ajax.complete = function() { 
			
			this.output.innerHTML = unescape(this.response);
			
			// show results
			document.getElementById(resultsControl).style.display = 'block';	
			// hide check delivery dates button 	
			document.getElementById(control).style.display = 'none';
			// show button 
			document.getElementById(button).style.display = 'block';
			
			// remove swirl and searching in preparation for reshowing
			document.getElementById('swirl-and-search').style.display='none';
			document.getElementById('DefaultMode_newContentRegion_ucAddress_bnDeliveryDateQuery').style.opacity =100;
			document.getElementById('DefaultMode_newContentRegion_ucAddress_bnDeliveryDateQuery').style.filter ='alpha(opacity=100)';
			document.getElementById('DefaultMode_newContentRegion_ucAddress_bnDeliveryDateQuery').disabled = false;
			// not working 
				
			};
		//ajax.busy = function() {
		//	AjaxUtils.freeze();
		//};

		ajax.fallback = function() { 
			document.getElementById(button).style.display = 'block';
			document.getElementById('swirl-and-search').style.display='none';
			};
		ajax.timeout = function() { 
			document.getElementById(button).style.display = 'block';	
			document.getElementById('swirl-and-search').style.display='none';		
		};		
		ajax.fail = function() { 
		;
			document.getElementById(button).style.display = 'block';
			document.getElementById('swirl-and-search').style.display='none';
		};

		ajax.get();
		return false;
	
	}
}


/* Address
------------------------------*/
var Address = {
	ajaxOutput : "",
	submit : null,
	init : function() {
		// Hide submit button
		var wrap = document.getElementById("profile-set-address");
		if (wrap) {
			var buttons = wrap.getElementsByTagName("input");
			for (var i = 0, c = buttons.length, n = 0; i < c; i++) {
				if (buttons[i].getAttribute("type") == "image") {
					n++;
					if (n == 2) {
						this.submit = buttons[i];
						this.submit.style.display = "none";
						break;
					}
				}
			}
		}
		
	},
	toggleSubmit : function() {
		if (this.submit) {
			this.submit.style.display = (this.submit.style.display == "none") ? "inline" : "none";
		} 
	},
	reset : function(addressControl, e, url) {
	
		this.ajaxOutput = "dynamic_" + addressControl;

		var ajax = new Ajax(url, {"ajax": "true", "action": "look"}, this.ajaxOutput);
		ajax.method = ajax.postMethod;
		
		ajax.complete = function() { 
			this.output.innerHTML = unescape(this.response);
			AjaxUtils.freeze();
			Address.init();
		};
		ajax.busy = function() {
			AjaxUtils.freeze();
		};

		ajax.addParam("addressControl=" + addressControl);

		ajax.get();
		return false;
	},
	getAddress : function(addressControl, e, url, houseNumber, postcode, countryDropDown, action, source) {
		
		this.ajaxOutput = "dynamic_" + addressControl;
		var dd = document.getElementById(countryDropDown);
		if (dd) {
			var countryCode = dd.options[dd.selectedIndex].value;
			var country = document.getElementById("country-code");
			if (country) {
				country.setAttribute("value", countryCode);
			}
			else {
				var countryField = document.createElement("input");
				countryField.setAttribute("type", "hidden");
				countryField.setAttribute("id", "country-code");
				countryField.setAttribute("value", countryCode);
				document.body.appendChild(countryField);
			}
		}
		
		var postcodeValue = document.getElementById(postcode).value;
		var houseNumberValue = document.getElementById(houseNumber).value;

		var ajax = new Ajax(url, {"ajax": "true", "action": action, "source": source}, this.ajaxOutput);
		ajax.method = ajax.postMethod;
		
		ajax.complete = function() { 
			this.output.innerHTML = unescape(this.response);
			AjaxUtils.freeze();
			Address.toggleSubmit();
		};
		ajax.busy = function() {
			AjaxUtils.freeze();
		};

		ajax.addParam(postcode + "=" + postcodeValue);
		ajax.addParam(houseNumber + "=" + houseNumberValue);
		ajax.addParam("addressControl=" + addressControl);

		ajax.get();
		return false;
	},
	selectAddress : function(addressControl,url, selectAddressListBox, countryDropDown, action, source) {
	
		this.ajaxOutput = "dynamic_" + addressControl;
				
		var ajax = new Ajax(url, {"ajax": "true", "action": action, "source": source}, this.ajaxOutput);
		ajax.method = ajax.postMethod;
		
		ajax.complete = function() {
			this.output.innerHTML = unescape(this.req.responseText);
		};
		
		var country = document.getElementById("country-code")
		if (country) {
			ajax.addParam(countryDropDown + "=" + country.value);
		}
		
		var lb = document.getElementById(selectAddressListBox);
		var lbIdx = lb.selectedIndex;
		var selectAddressValue = lb.options[lbIdx].value;
		ajax.addParam(selectAddressListBox + '=' + selectAddressValue);
		ajax.addParam("addressControl=" + addressControl);
		
		ajax.get(); // Send Ajax request and get the Json
		return false;
	},
	selectAddressByTable : function(addressControl, url, address, countryDropDown, action, source) {
	
		this.ajaxOutput = "dynamic_" + addressControl;
		
		var ajax = new Ajax(url, {"ajax": "true", "action": action, "source": source}, this.ajaxOutput);
		ajax.method = ajax.postMethod;
		
		ajax.complete = function() { 
			this.output.innerHTML = unescape(this.req.responseText);
			Address.toggleSubmit();
		};
		
		var country = document.getElementById("country-code")
		if (country) {
			ajax.addParam(countryDropDown + "=" + country.value);
		}

		ajax.addParam("Address=" + address);
		ajax.addParam("addressControl=" + addressControl);
		ajax.get();
		return false;
	},
	selectCountry : function(url, countryDropDown, action, source) {
		
		var dd = document.getElementById(countryDropDown);
		var countryCode = dd.options[dd.selectedIndex].value;
		
		var selectCountry = new Ajax(url, {"ajax": "true", "action": action, "source": source}, this.ajaxOutput);
		ajax.method = ajax.postMethod;
		
		ajax.complete = function() {
			this.output.innerHTML = unescape(this.response);
		};
		
		var inputs = document.getElementsByTagName("input");
		
		for (var i=0; i<inputs.length; i++) {
			var inputType = inputs[i].getAttribute('type');
			var inputId	= inputs[i].getAttribute('id');
			var inputValue = inputs[i].value;
			if (inputType != 'hidden'
					&& inputId != null && inputId.length > 0
					&& inputValue != null && inputValue.length > 0) {
				ajax.addParam(inputId + '=' + inputValue);
			}
		}
		
		var dropDowns = document.getElementsByTagName('select');
		
		for (var i=0; i<dropDowns.length; i++) {
			var dropDownId = dropDowns[i].getAttribute('id');
			if (dropDownId != countryDropDown) {
				var ddIdx = dropDowns[i].selectedIndex;
				var ddValue = dropDowns[i].options[ddIdx].value;
				var ddText = dropDowns[i].options[ddIdx].text;
				ajax.addParam(dropDownId + '=' + ddIdx + "|" + ddValue + "|" + ddText);
			}
		}

		ajax.addParam(countryDropDown + "=" + countryCode);

		ajax.get();
		return false;
	},
	manualEdit : function(addressControl, url, countryDropDown, action, source) {
		
		this.ajaxOutput = "dynamic_" + addressControl;
		var ajax = new Ajax(url, {"ajax": "true", "action": action, "source": source}, this.ajaxOutput);
		ajax.method = ajax.postMethod;
		
		ajax.complete = function() {
			this.output.innerHTML = unescape(this.response);
			Address.toggleSubmit();
		};

		var dd = document.getElementById(countryDropDown);
		if (dd != null)	{
			var ddIdx = dd.selectedIndex;
			var countryCode = dd.options[ddIdx].value;
			manualEdit.addParam(countryDropDown + '=' + countryCode);
		}

		ajax.addParam("addressControl=" + addressControl);
		
		ajax.get(); // Send Ajax request and get the Json
		return false;
	},
	clear : function(addressControl, url, countryDropDown, action, source) {
		
		this.ajaxOutput = "dynamic_" + addressControl;
		var ajax = new Ajax(url, {"ajax": "true", "action": action, "source": source}, this.ajaxOutput);
		ajax.method = ajax.postMethod;
		
		ajax.complete = function() {
			this.output.innerHTML = unescape(this.response);
			Address.toggleSubmit();
		};

		ajax.addParam("addressControl=" + addressControl);
		
		ajax.get(); // Send Ajax request and get the Json
		return false;
	}
};

/* Basket
------------------------------*/
var Basket = {
	ajax : new Ajax(),
	add : function(e, args, qty, vid) {
		if (!document.getElementById) { return }
		
		this.ajax.set(e, args, "content");
		
		var qty = document.getElementById(qty);
		if (qty) {
			qty = qty.value;
			this.ajax.addParam("qty", qty);
		}
		
		var vid = document.getElementById(vid);
		if (vid) {
			vid = vid.value;
			this.ajax.addParam("vid", vid);
		}
		
		var guarantee = FormUtils.getOption("rdGuarantee");
		if (guarantee) {
			this.ajax.addParam("rdGuarantee",guarantee);
		}
		
		var disposal = FormUtils.getOption("rdDisposal");
		if (disposal) {
			this.ajax.addParam("rdDisposal",disposal);
		}
		
		this.ajax.complete = function() {
			var t = document.createTextNode(this.req.responseText);
			//this.output.appendChild(t);
			MiniBasket.render();
		
			// Omniture tag
			if (typeof(Omniture) != "undefined")
				Omniture.basketAdd(args.cid, args.pid, json.products[0].vid, new Boolean(json.products[0].scOpen));
		
			var json = this.toJson();
			
			var pid = json.products[0].vid, productData, message;
			if (pid) {
				productData = eval("ProductData.p" + pid);
				message = productData.name + " has been added to your basket with options " + productData.size + ", " + productData.base + ", " + productData.draw;
			} 
			else {
				pid = json.products[0].pid;	
				productData = eval("ProductData.p" + pid);
				message = productData.name + " has been added to your basket";
			}
			
			//* Options are {direction: "top|left", position: true|false, offsetX: num, offsetY: num}
			MiniInfo.show("add-basket-status", message, {direction: "top", position: false});
			MiniInfo.position("add-to-basket", "add-basket-status", {offsetX : -28, offsetY : 30});
		}
		this.ajax.get();
		return false;
	},
	removeItem : function(item) {
	
	},
	updateItemQuantity : function(item, qty) {
	
	},
	update : function(e) {
		
		var basketQty = FormUtils.collect("basket");
		
		this.ajax.method = ajax.postMethod;
		this.ajax.set(e, basketQty, "content");
		this.ajax.addParam("ajax", "true");
		this.ajax.addParam("cmd", "update");
		
		this.ajax.complete = function() {
			alert(this.req.responseText);
		}
		
		this.ajax.get();
		return false;
	}
};

/* StaticPage
------------------------------*/
var StaticPage = {
	ajax : new Ajax(),
	init: function() {
		if (!document.getElementsByTagName){ return; }
	},
	display : function(e) {
	
		if (!document.getElementById) { return }
		
		var objOverlay = document.getElementById('overlay');
		
		// set height of Overlay to take up whole page and show
		objOverlay.style.height = (arrayPageSize[1] + 'px');
	
		//objOverlay.style.display = 'block';
		selects = document.getElementsByTagName("select");
		
		//go through all select elements and hide them as they peak through layer
        for (i = 0; i != selects.length; i++) {
                selects[i].style.visibility = "hidden";
                selects[i].style.display = "none"; 
        }
		
		this.ajax.set(e, {"ajax": "true"});
		this.ajax.complete = function() {
			StaticPage.render(this.req.responseText.replace("content","static-content"));
		}
		
		this.ajax.get();
		return false;
	},
	displayFeather : function(id,e) {
	
		if (!document.getElementById) { return }
		
		var objOverlay = document.getElementById('overlay');
		
		// set height of Overlay to take up whole page and show
		objOverlay.style.height = (arrayPageSize[1] + 'px');
		//objOverlay.style.display = 'block';
	
		//go through all select elements and hide them as they peak through layer
		selects = document.getElementsByTagName("select");
        for (i = 0; i != selects.length; i++) {
                selects[i].style.visibility = "hidden";
        }
		
		this.ajax.set(e, {"ajax": "true"});
		this.ajax.complete = function() {
			StaticPage.renderAjaxResponse(id,this.req.responseText.replace("content","EPI-content"));
		}
		
		this.ajax.get();
		return false;
	},
	render: function(content) {
		// Modify the page class so that printing the overlay works in IE7
		addClass(document.body, "overlay-print");
		
		var staticText = document.getElementById("static-text");
            
        if (staticText) {
                document.body.removeChild(staticText);
        }
        
        //Create a static text element
        var container = document.createElement("div");
        container.style.opacity = (0 / 100);
		container.style.MozOpacity = (0 / 100);
		container.style.KhtmlOpacity = (0 / 100);
		container.id = "static-text";
        container.innerHTML = content;
                            
        //Create a close button to the overlay
        var a = document.createElement("a");
        a.id = "close-static-text";
        a.href = "#";
        a.innerHTML = "Close";
        
        Event.add(a, "click", function() {
			var objOverlay = document.getElementById("overlay"); 
			objOverlay.style.opacity = 0;
			objOverlay.style.MozOpacity = 0;
			objOverlay.style.KhtmlOpacity = 0;
			//objOverlay.style.display="none";
			StaticPage.close("static-text");
        });
                
        //Add the close button to the container
        container.appendChild(a);
        document.body.appendChild(container);
		changeOpac(0, 'static-text');

		var content = document.getElementById('static-content');
		var h1 = content.getElementsByTagName('h1').item(0);
		
		//Create a top close button to the overlay
        var closea = document.createElement("a");
        closea.id = "close-static-text";
        closea.href = "#";
        closea.i
        nnerHTML = "Close";
        closea.onclick = function () {hideLightbox(); return false;}
        
        Event.add(closea, "click", function() {
			StaticPage.close("static-text") 
        });
		
		content.insertBefore(closea,h1);
		
		//Create a top Print button to the overlay
        var printa = document.createElement("a");
        printa.id = "print-static-text";
        printa.href = "#";
        printa.innerHTML = "Print";
        
        Event.add(printa, "click", function() {
			printPage(); 
			//printURL("http://dreams.devserver.02/Dreams/en-gb/Info/Help/About-Jobs/");
        });
		
		content.insertBefore(printa,h1);
		
		//container.style.display = "none"
		opacity("overlay", 0, 65, 1000);
		opacity('static-text', 0, 100, 1000);
		

			
	},
	renderAjaxResponse: function(id,content) {
		var EPIText = document.getElementById("EPI-text");
                   
        if (EPIText) {
			document.body.removeChild(EPIText);
        }
            
        //Create a static text element
        var container = document.createElement("div");
        container.id = "EPI-text";
        container.style.opacity = (0 / 100);
		container.style.MozOpacity = (0 / 100);
		container.style.KhtmlOpacity = (0 / 100);
		container.style.display ="none";
        container.innerHTML = content;
            
        //Create a close button to the overlay
        var a = document.createElement("a");
        a.id = "close-static-text";
        a.href = "#";
        a.innerHTML = "Close";
            
        Event.add(a, "click", function() {
			StaticPage.close("EPI-text") 
        });
                  
        //Add the close button to the container
        container.appendChild(a);
            
        document.body.appendChild(container);
          
        //position the container relevant to the parent object
        var coors =findPos(id);
		var box = document.getElementById('body');
		
		opacity('overlay', 0, 65, 1000);
		pause(500, function() {
			opacity('EPI-text', 0, 100, 1000);	
		});
	},
	close: function(id) {
	
		// Remove the page class so that print is returned to normal on the page
		removeClass(document.body, "overlay-print");
		
	    var el = document.getElementById(id);
        document.body.removeChild(el);
        
        if(document.getElementById('overlay')){
            object=document.getElementById('overlay').style;        
			object.opacity = 0;
			object.MozOpacity = 0;
			object.KhtmlOpacity = 0;
			object.display = "none";
        }
        
        object=document.getElementById('overlay').style;        
		object.opacity = 0;
		object.MozOpacity = 0;
		object.KhtmlOpacity = 0;
		
		//go through all select elements and make them visible;
		for (i = 0; i != selects.length; i++) {
			selects[i].style.visibility = "visible";
			selects[i].style.display = "block"; 
		}
		
        return false;
     
		object=document.getElementById('overlay').style;        
		object.opacity = 0;
		object.MozOpacity = 0;
		object.KhtmlOpacity = 0;
	}
};

function confirmPayment(s1, s2, callback) {
	s1 = document.getElementById(s1);
	s2 = document.getElementById(s2);
	if (typeof(Page_ClientValidate) == "function") {
		if (Page_ClientValidate()) { 
			s1.disabled = true;
			s2.disabled = true;
			if (typeof(callback) == "function") {
				callback.call();
			}
			return true;
		} else {
			s1.disabled = false;
			s2.disabled = false;	
			return false;
		}
	}
	
	
}



/**
 * FlashObject fix
 *
 */
if(typeof com == "undefined") var com = new Object();
if(typeof com.deconcept == "undefined") com.deconcept = new Object();
if(typeof com.deconcept.util == "undefined") com.deconcept.util = new Object();
if(typeof com.deconcept.FlashObjectUtil == "undefined") com.deconcept.FlashObjectUtil = new Object();

com.deconcept.FlashObject = function(swf, id, w, h, ver, c, useExpressInstall, quality, redirectUrl, detectKey) {
	this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
	this.skipDetect = com.deconcept.util.getRequestParameter(this.DETECT_KEY);
	this.params = new Object();
	this.variables = new Object();
	this.attributes = new Array();

	if(swf) this.setAttribute('swf', swf);
	if(id) this.setAttribute('id', id);
	if(w) this.setAttribute('width', w);
	if(h) this.setAttribute('height', h);
	if(ver) this.setAttribute('version', new com.deconcept.PlayerVersion(ver.toString().split(".")));
	if(c) this.addParam('bgcolor', c);
	var q = quality ? quality : 'high';
	this.addParam('quality', q);
	this.setAttribute('redirectUrl', '');
	if(redirectUrl) this.setAttribute('redirectUrl', redirectUrl);
	if(useExpressInstall) {
		// check to see if we need to do an express install
		var expressInstallReqVer = new com.deconcept.PlayerVersion([6,0,65]);
		var installedVer = com.deconcept.FlashObjectUtil.getPlayerVersion();
	
		if (installedVer.versionIsValid(expressInstallReqVer) && !installedVer.versionIsValid(this.getAttribute('version'))) {
			this.setAttribute('doExpressInstall', true);
		}
	} else {
		this.setAttribute('doExpressInstall', false);
	}
}
com.deconcept.FlashObject.prototype.setAttribute = function(name, value){
	this.attributes[name] = value;
}
com.deconcept.FlashObject.prototype.getAttribute = function(name){
	return this.attributes[name];
}
com.deconcept.FlashObject.prototype.getAttributes = function(){
	return this.attributes;
}
com.deconcept.FlashObject.prototype.addParam = function(name, value){
	this.params[name] = value;
}
com.deconcept.FlashObject.prototype.getParams = function(){
	return this.params;
}
com.deconcept.FlashObject.prototype.getParam = function(name){
	return this.params[name];
}
com.deconcept.FlashObject.prototype.addVariable = function(name, value){
	this.variables[name] = value;
}
com.deconcept.FlashObject.prototype.getVariable = function(name){
	return this.variables[name];
}
com.deconcept.FlashObject.prototype.getVariables = function(){
	return this.variables;
}
com.deconcept.FlashObject.prototype.getParamTags = function(){
   var paramTags = ""; var key; var params = this.getParams();
   for(key in params) {
        paramTags += '<param name="' + key + '" value="' + params[key] + '" />';
    }
   return paramTags;
}
com.deconcept.FlashObject.prototype.getVariablePairs = function(){
	var variablePairs = new Array();
	var key;
	var variables = this.getVariables();
	for(key in variables){
		variablePairs.push(key +"="+ variables[key]);
	}
	return variablePairs;
}
com.deconcept.FlashObject.prototype.getHTML = function() {
    var flashHTML = "";
    if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
        if (this.getAttribute("doExpressInstall")) { this.addVariable("MMplayerType", "PlugIn"); }
        flashHTML += '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" id="'+ this.getAttribute('id') + '" name="'+ this.getAttribute('id') +'"';
		var params = this.getParams();
        for(var key in params){ flashHTML += ' '+ key +'="'+ params[key] +'"'; }
		pairs = this.getVariablePairs().join("&");
        if (pairs.length > 0){ flashHTML += ' flashvars="'+ pairs +'"'; }
        flashHTML += '></embed>';
    } else { // PC IE
        if (this.getAttribute("doExpressInstall")) { this.addVariable("MMplayerType", "ActiveX"); }
        flashHTML += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" id="'+ this.getAttribute('id') +'">';
        flashHTML += '<param name="movie" value="' + this.getAttribute('swf') + '" />';
		var tags = this.getParamTags();
        if(tags.length > 0){ flashHTML += tags; }
		var pairs = this.getVariablePairs().join("&");
        if(pairs.length > 0){ flashHTML += '<param name="flashvars" value="'+ pairs +'" />'; }
        flashHTML += '</object>';
    }
    return flashHTML;
}
com.deconcept.FlashObject.prototype.write = function(elementId){
	if(this.skipDetect || this.getAttribute('doExpressInstall') || com.deconcept.FlashObjectUtil.getPlayerVersion().versionIsValid(this.getAttribute('version'))){
		if(document.getElementById){
		   if (this.getAttribute('doExpressInstall')) {
		      this.addVariable("MMredirectURL", escape(window.location));
		      document.title = document.title.slice(0, 47) + " - Flash Player Installation";
		      this.addVariable("MMdoctitle", document.title);
		   }
			document.getElementById(elementId).innerHTML = this.getHTML();
		}
	}else{
		if(this.getAttribute('redirectUrl') != "") {
			document.location.replace(this.getAttribute('redirectUrl'));
		}
	}
}
/* ---- detection functions ---- */
com.deconcept.FlashObjectUtil.getPlayerVersion = function(){
   var PlayerVersion = new com.deconcept.PlayerVersion(0,0,0);
	if(navigator.plugins && navigator.mimeTypes.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			PlayerVersion = new com.deconcept.PlayerVersion(x.description.replace(/([a-z]|[A-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}else if (window.ActiveXObject){
	   try {
   	   var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
   		PlayerVersion = new com.deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
	   } catch (e) {}
	}
	return PlayerVersion;
}
com.deconcept.PlayerVersion = function(arrVersion){
	this.major = parseInt(arrVersion[0]) || 0;
	this.minor = parseInt(arrVersion[1]) || 0;
	this.rev = parseInt(arrVersion[2]) || 0;
}
com.deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
	if(this.major < fv.major) return false;
	if(this.major > fv.major) return true;
	if(this.minor < fv.minor) return false;
	if(this.minor > fv.minor) return true;
	if(this.rev < fv.rev) return false;
	return true;
}
/* ---- get value of query string param ---- */
com.deconcept.util.getRequestParameter = function(param){
	var q = document.location.search || document.location.href.hash;
	if(q){
		var startIndex = q.indexOf(param +"=");
		var endIndex = (q.indexOf("&", startIndex) > -1) ? q.indexOf("&", startIndex) : q.length;
		if (q.length > 1 && startIndex > -1) {
			return q.substring(q.indexOf("=", startIndex)+1, endIndex);
		}
	}
	return "";
}

/* add Array.push if needed (ie5) */
if (Array.prototype.push == null) { Array.prototype.push = function(item) { this[this.length] = item; return this.length; }}

/* add some aliases for ease of use / backwards compatibility */
var getQueryParamValue = com.deconcept.util.getRequestParameter;
var FlashObject = com.deconcept.FlashObject;

/*
end flash object fix
*/


var Fx = {
	// e (object) - element to change
	// o (int) - percentage of opacity
	opacity: function(e, o) {
		e.style.opacity			= (o / 100);
		e.style.MozOpacity		= (o / 100);
		e.style.KhtmlOpacity	= (o / 100);
		e.style.filter			= "alpha(opacity=" + o + ")";
	}
};

/* Easing
------------------------------*/
// e (object) - reference to element to fade
// easing (array) - {"interval": 2, "start": 100, "stop": 0}
// method (function) - what to call on every iteration
// callback (function) - what to call when the easing has finished
function Easing(e, easing, method, callback) {
	// Default easing values (can use global easing settings)
	this.easing				= {};
	this.easing.easing		= 0.2;
	this.easing.interval	= 20;
	this.easing.start		= 100;
	this.easing.stop		= 0;
	this.easing.now			= this.easing.start;

	// Initialise the settings
	this.set(e, easing, method, callback);
}
// Setup or change the settings
Easing.prototype.set = function(e, easing, method, callback) {
	this.e			= e;
	this.method		= method;
	this.callback	= callback;
	this.timer		= null;
	this.wait		= null;
	this.setEasing(easing);
};
// Setup or change the easing settings
Easing.prototype.setEasing = function(easing) {
	this.reset();
	for (var i in easing) {
		this.easing[i] = easing[i];
	}
};
// Change the callback
Easing.prototype.setCallback = function(callback) {	
	this.reset();
	this.callback = callback;
};
// Reset any easing elements
Easing.prototype.reset = function() {	
	clearInterval(this.timer);
};
// Setup the easing
Easing.prototype.start = function() {
	// Set up initial values
	this.easing.now = this.easing.start;

	// Use a closure for intervals
	var o = this;
	this.timer = setInterval(function() { o.ease(); }, this.easing.interval);
};
// Perform the easing
Easing.prototype.ease = function() {
	this.easing.now += (this.easing.stop - this.easing.now) * this.easing.easing;
	//var debug = document.getElementById("debug");
	//debug.innerHTML += this.easing.now + "<br />";
	if (Math.abs(this.easing.stop - this.easing.now) < 1) {
		// Finalise the easing 
		this.easing.now = this.easing.stop;
		if (typeof(this.method) == "function") { 
			this.method.call(this);
		}

		// End the easing
		this.stop();
		return;
	} else {
		// Use the method 
		if (typeof(this.method) == "function") { 
			this.method.call(this);
		}
	}
};
// Stop the effect
Easing.prototype.stop = function() {
	// Stop the interval
	clearInterval(this.timer);

	// Fire the callback if there is one
	if (typeof(this.callback) == "function") { 
		this.callback.call(this);
	}

	// Clear the callback to stop infinate loop
	this.callback = null;
};
// Delay before effect
Easing.prototype.delay = function(callback, delay) {
	// Use a closure for timeout
	var o = this;
	this.wait = setTimeout(function() { callback.call(o); }, delay * 1000);
};
