var srchtxt = 'Search all products...';
var _gaq=_gaq||[];
window.addEvent('domready', function(){
	var srchfm = $('srchfm');
	var srch = srchfm.getElement('input');
	if(srch.value.trim() == '') srch.value = srchtxt;
	srch.addEvents({
		'focus' : function(){if(srch.value == srchtxt) srch.value = '';},
		'blur': function(){if(srch.value.trim() == '') srch.value = srchtxt; }
	});
	srchfm.addEvent('submit', function(){if (srch.value.trim() == '' || srch.value.trim() == srchtxt)	return false;});
	var ships = $$('div.ships');
	if (ships.length > 0){
		var shipImg = new Element('span', {'html':'In Stock', 'title': 'Product usually ships within 24 hours', 'style': 'cursor:help', 'events': {
			'click': function(){
				var myDiv = new Element('div', {'styles': {'padding': '5px', 'text-align':'center'}, 'html': 'This product usually ships within 24 hours of purchase.'});
				var showError = new pleromaPopup({
					height: 50,
					width: 400,
					data: myDiv,
					title: 'Product Shipping Information',
					overlay: true,
					clickOverlayClose: true
				});
			}}
		});
		ships.each(function(item){
			var clone = shipImg.clone().cloneEvents(shipImg).inject(item);
		});
	}
	var noships = $$('div.noships');
	if (noships.length > 0){
		var s = new Element('span', {'html':'4-10 Day<br />Shipping', 'title': 'Product usually ships within 4-10 days', 'style': 'cursor:help', 'events': {
			'click': function(){
				var myDiv = new Element('div', {'styles': {'padding': '5px', 'text-align':'center'}, 'html': 'This product usually ships within 4-10 days.<br /><br />Please <a href="'+base+'contact_us">contact us</a> if you require more detailed information.'});
				var showError = new pleromaPopup({
					height: 70, width: 400,
					data: myDiv, title: 'Product Shipping Information',
					overlay: true, clickOverlayClose: true
				});
			}}
		});
		noships.each(function(item){
			var clone = s.clone().cloneEvents(s).inject(item);
		});
	}
	var jsWarnings = $$('.jswarning');
	jsWarnings.each(function(item){item.destroy();});
	var tbls = $$('table.p');
	var maxLen = 180;
	tbls.each(function(item){
		var elid = item.id; var id = elid.replace(/p_/,'');
		var imglnk = item.getElement('td.pimg').addEvent('click', function(){pinfo(id);});
		imglnk.set('title', 'Click for more information');
		var descrBlock = item.getElement('td.pdescr');
		var descrElm = descrBlock.getElement('div.descr');
		var descrTxt = descrElm.innerHTML;
		if (descrTxt.length> maxLen) {
			descrTxt = descrTxt.substring(0, maxLen);
			descrTxt = descrTxt.replace(/\w+$/, '');
			descrTxt += '... ';
			descrElm.innerHTML = descrTxt;
		}
		lastChars = descrTxt.substring(descrTxt.length-4);
		if (lastChars == '... ') var moreInfo = new Element('a', {'class':'more', 'html': 'more details', 'href': 'javascript:;', events: ({'click': function(){pinfo(id)}})}).inject(descrElm);
		var h3 = descrBlock.getElement('h3');
		var titlelnk = new Element('span', {'html': h3.get('html'), events: {'click':function(){pinfo(id);}}}).inject(h3.empty());
		var choiceBlock = item.getElement('td.pchoice');
		var rrpTitle = item.getElement('div.rrp').set('title', 'Recommended Retail Price');
		var spTitle = item.getElement('div.sp');	if(spTitle) spTitle.set('title', 'Special Price');
		var rprTitle = item.getElement('div.rpr');	if(rprTitle) rprTitle.set('title', 'Your Reseller Price');
		var atclink = new Element('div', {'class': 'atc','title':'Add to Cart', events:({'click': function(){atc(id);}, 'mouseover': function(){hl(this);}, 'mouseout': function(){unhl(this);}})}).inject(choiceBlock);
		var atwlink = new Element('div', {'class': 'atw','title':'Add to Wishlist', events:({'click': function(){atw(id);}, 'mouseover': function(){hl(this);}, 'mouseout': function(){unhl(this);}})}).inject(choiceBlock);
		var pinfolink = new Element('div', {'class': 'pinfo','title':'More Details', events:({'click': function(){pinfo(id);}, 'mouseover': function(){hl(this);}, 'mouseout': function(){unhl(this);}})}).inject(choiceBlock);
	});
	
	$$('input.submitdisable').addEvent('click', function(el){ // Fix those annoying double-clickers
		var myForm = this.getParent('form');
		if(myForm){this.disabled=true;myForm.submit();}
	});
	
	/* Banner */
	$('b2').inject($('b1'), 'after');
	new banRol({el1:$('b1'),el2:$('b2')});
	
	
	
	$$('div.product_holder_small').each(function(item){
		var elid = item.id; var id = elid.replace(/p_/,'');
		var imglnk = item.getElement('div.img img');
		if (imglnk){
			imglnk.addEvent('click', function(){pinfo(id);});
			imglnk.setStyle('cursor','pointer');
			imglnk.set('title', 'Click for more information');
		}
		var des = item.getElement('p.descr');
		if (des){
			var descrTxt = des.get('html');
			if (descrTxt.length> maxLen) {
				descrTxt = descrTxt.substring(0, maxLen);
				descrTxt = descrTxt.replace(/\w+$/, '');
				descrTxt += '... ';
				des.set('html', descrTxt);
			}
			lastChars = descrTxt.substring(descrTxt.length-4);
			if (lastChars == '... ') var moreInfo = new Element('a', {'class':'more', 'html': 'more details', 'href': 'javascript:;', events: ({'click': function(){pinfo(id)}})}).inject(des);
		}
		var h3 = item.getElement('h3 a');
		var titlelnk = h3.addEvent('click', function(){pinfo(id); return false;});
		
		var choiceBlock = item.getElement('div.price');
		var rrpTitle = item.getElement('div.rrp').set('title', 'Recommended Retail Price');
		var spTitle = item.getElement('div.sp');	if(spTitle) spTitle.set('title', 'Special Price');
		var rprTitle = item.getElement('div.rpr');	if(rprTitle) rprTitle.set('title', 'Your Reseller Price');
		var atclink = new Element('div', {'class': 'atc','title':'Add to Cart', events:({'click': function(){atc(id);}, 'mouseover': function(){hl(this);}, 'mouseout': function(){unhl(this);}})}).inject(choiceBlock);
		var atwlink = new Element('div', {'class': 'atw','title':'Add to Wishlist', events:({'click': function(){atw(id);}, 'mouseover': function(){hl(this);}, 'mouseout': function(){unhl(this);}})}).inject(choiceBlock);
		var pinfolink = new Element('div', {'class': 'pinfo','title':'More Details', events:({'click': function(){pinfo(id);}, 'mouseover': function(){hl(this);}, 'mouseout': function(){unhl(this);}})}).inject(choiceBlock);
			
		var eheight = item.getHeight();
		var img = item.getElement('div.img img');
		var mar = (eheight - img.getHeight()) / 2;
		img.setStyle('margin-top',mar-10+'px');
	});
	
	$$('div.product_holder_large').each(function(item){
		var elid = item.id; var id = elid.replace(/p_/,'');
		var choiceBlock = item.getElement('div.price');
		var rrpTitle = item.getElement('div.rrp').set('title', 'Recommended Retail Price');
		var spTitle = item.getElement('div.sp');	if(spTitle) spTitle.set('title', 'Special Price');
		var rprTitle = item.getElement('div.rpr');	if(rprTitle) rprTitle.set('title', 'Your Reseller Price');
		var atclink = new Element('div', {'class': 'atc','title':'Add to Cart', events:({'click': function(){atc(id);}, 'mouseover': function(){hl(this);}, 'mouseout': function(){unhl(this);}})}).inject(choiceBlock);
		var atwlink = new Element('div', {'class': 'atw','title':'Add to Wishlist', events:({'click': function(){atw(id);}, 'mouseover': function(){hl(this);}, 'mouseout': function(){unhl(this);}})}).inject(choiceBlock);
		var pinfolink = new Element('div', {'class': 'pinfo','title':'More Details', events:({'click': function(){pinfo(id);}, 'mouseover': function(){hl(this);}, 'mouseout': function(){unhl(this);}})}).inject(choiceBlock);
		var eheight = item.getHeight();
		var img = item.getElement('div.img img');
		var mar = (eheight - img.getHeight()) / 2;
		img.setStyle('margin-top',mar-10+'px');
	});
	
});


function loadProducts(){
	var jsonReq = postJSON(base+'ascripts/slideshow.php', '', function(result){
		var x = new genGal({	title: 'Top 20',cssclass: 'top_20',	data: result.t, link: 'products/top_20'});	
		var y = new genGal({	title: 'Newsletter Releases',cssclass: 'newsletter_releases',	data: result.n, link: 'products/newsletter_releases'});	
		var y = new genGal({	title: 'Featured Products',cssclass: 'specials',	data: result.f, link: 'products/featured_products'});	
	});
}

var banRol = new Class({
	Implements: [Options, Events],
	options: {
		el1: false,
		el1_timer: 5000,
		el2: false,
		el2_timer: 10000
	},
	initialize: function(options){
		this.setOptions(options);
		if (!this.options.el1 || !this.options.el2) return false;
		this.initBan();
	},
	initBan: function(){
		this.switchView.delay(this.options.el1_timer, this);
	},
	switchView: function(){
		if (this.options.el2.getStyle('display') == 'block'){
			this.options.el2.setStyle('display', 'none');
			this.options.el1.setStyle('display', 'block');
			this.switchView.delay(this.options.el1_timer, this);
		} else {
			this.options.el2.setStyle('display', 'block');
			this.options.el1.setStyle('display', 'none');
			this.switchView.delay(this.options.el2_timer, this);
		}
	}
	
});

var genGal = new Class({
	Implements: [Options, Events],
	options: {
		title: 'no title',
		cssclass: '',
		data: false,
		curSel: -1,
		link: false
	},
	initialize: function(options){
		this.setOptions(options);
		if (this.options.data.length == 0) return false;
		this.initGal();
	},
	initGal: function(){
		var gal = new Element('div', {'class':'gal '+this.options.cssclass});
		this.h = new Element('h1').inject(gal);
		this.lnk = new Element('a', {'html': this.options.title, 'href': base+this.options.link, 'title': 'Click to view all '+this.options.title}).inject(this.h);
		var myTips = new Tips(this.lnk, {'text':''});
		myTips.addEvent('show', function(tip, hovered){ tip.setStyle('opacity', '0.7'); });
		
		this.l = new Element('div', {'class':'l', events:{
			'click': this.prevImg.bind(this),
			'mouseover': function(){this.setStyle('opacity', 1);},
			'mouseout': function(){this.setStyle('opacity', 0.5);}
		}}).inject(gal);
		this.i = new Element('div', {'class':'i', 'style':''}).inject(gal);
		this.r = new Element('div', {'class':'r', events:{
			'click': this.nextImg.bind(this),
			'mouseover': function(){this.setStyle('opacity', 1);},
			'mouseout': function(){this.setStyle('opacity', 0.5);}
		}}).inject(gal);
		this.l.setStyle('opacity', 0.5);
		this.r.setStyle('opacity', 0.5);
		this.t = new Element('a', {'class':'title'}).inject(gal);
		this.a = new Element('div', {'class':'author'}).inject(gal);
		this.nextImg();
		gal.inject($('galholder'));
	},
	
	nextImg: function(){
		var nextEl = this.options.curSel + 1;
		if (this.options.data[nextEl]) this.options.curSel = nextEl;
		else this.options.curSel = 0;
		this.displayImg();
	},
	prevImg: function(){
		var nextEl = this.options.curSel - 1;
		if (this.options.data[nextEl]) this.options.curSel = nextEl;
		else this.options.curSel = this.options.data.length -1;
		this.displayImg();
	},
	
	displayImg: function(){
		var mydata = this.options.data[this.options.curSel];
		if(mydata.i == 1) var img = base+'images/products/slide/'+mydata.r+'.jpg';
		else var img = base+'images/products/no_image.gif';
		this.i.setStyle('background','url('+img+') center center no-repeat');
		this.i.removeEvents('click');
		this.i.addEvent('click', function(){pinfo(mydata.r)});
		this.t.set('text', mydata.n);
		this.t.removeEvents('click');
		this.t.addEvent('click', function(){pinfo(mydata.r)});
		this.a.set('text', mydata.a);
	}
});


var statusMessage = new Class({
	Implements: [Options, Events],
	options: {
		timeout: 2500,
		overlay: true,
		data: new Element('div')
	},
	initialize: function(options){
		this.setOptions(options);
		this.popup();
		window.addEvents({ 'resize': this.centerItems.bind(this), 'scroll': this.centerItems.bind(this) });
	},
	popup: function (){
		if (this.options.overlay){
			this.overlay = new Element('div').setProperty('id', 'overlay').injectInside(document.body);
			this.overlay.setStyles({opacity: '0.3'});
			this.overlay.setStyles({top: Window.getScrollTop()+'px', left: 0, height: Window.getHeight()+'px', width: Window.getWidth() + Window.getScrollLeft()+'px'});
		}
		this.messageBox = new Element('div').setProperty('class', 'messagebox').injectInside(document.body);
		/* SET THE CONTENT */
		var dataType = typeof (this.options.data);
		if (dataType == 'object'){
			this.options.data.inject(this.messageBox);
		}
		else { this.messageBox.set('html', this.options.data);}
		/* Center item */
		var myWinWidth = Window.getWidth() + Window.getScrollLeft();
		if (this.messageBox){
			var marLeft = (myWinWidth / 2) - (this.messageBox.getWidth() / 2);
			var topMar = Window.getScrollTop() + (Window.getHeight() / 2) - (this.messageBox.getHeight() / 2);
			this.messageBox.setStyles({'left': marLeft+'px', 'top': topMar+'px'});
		}
		var myChain = new Chain(this);
		myChain.chain(
			function(){ if(this.options.overlay) this.overlay.fade('out'); this.messageBox.fade('out') }.bind(this),
			function(){ 
				if(this.options.overlay) this.overlay.destroy(); 
				this.messageBox.destroy();
				window.removeEvent('resize', this.centerItems.bind(this));
				window.removeEvent('scroll', this.centerItems.bind(this));
			}.bind(this)
		);
		window.setTimeout(function(){myChain.callChain()}, this.options.timeout);
		window.setTimeout(function(){myChain.callChain()}, (this.options.timeout + 1500));
	},
	centerItems: function(){
		var myWinWidth = Window.getWidth() + Window.getScrollLeft();
		if (this.overlay) this.overlay.setStyles({top: Window.getScrollTop()+'px', height: Window.getHeight()+'px', width: myWinWidth+'px'});
		if (this.messageBox){
			var marLeft = (myWinWidth / 2) - (this.messageBox.getWidth() / 2);
			var topMar = Window.getScrollTop() + (Window.getHeight() / 2) - (this.messageBox.getHeight() / 2);
			this.messageBox.setStyles({'left': marLeft+'px', 'top': topMar+'px'});
		}
	}
});

var pleromaPopup = new Class({
	Implements: [Options, Events],
	options: {
		fullscreen: false,
		overlay: false,
		clickOverlayClose: false,
		width: 400,
		height: 200,
		popupTopHeight: 30,
		popupBottomHeight: 15,
		closeButton: true,
		centerpopup: true,
		title: false,
		data: new Element('div')
	},
	
	initialize: function(options){
		this.setOptions(options);
		this.drawPopup();
	},
	
	drawPopup: function(){
		if(this.options.overlay) this.createOverlay();
		this.popup();
		window.addEvents({ 'resize': this.centerItems.bind(this), 'scroll': this.centerItems.bind(this) });
	},
	
	createOverlay: function(){
		this.overlay = new Element('div').setProperty('id', 'overlay').injectInside(document.body);
		this.overlay.setStyles({opacity: '0.3'});
		this.overlay.setStyles({top: Window.getScrollTop()+'px', left: 0, height: Window.getHeight()+'px', width: Window.getWidth() + Window.getScrollLeft()+'px'});
	},
	
	positionOverlay: function() {
		if(this.overlay) 
			this.overlay.setStyles({top: Window.getScrollTop()+'px', height: Window.getHeight()+'px', width: (Window.getWidth() + Window.getScrollLeft())+'px'});
	},
	
	popup: function (){
		var popupTopHeight = this.options.popupTopHeight;
		var popupBottomHeight = this.options.popupBottomHeight;
		this.infobox = new Element('div').setProperty('class', 'popupbox').injectInside(document.body);
		this.infobox.setStyles({'height': this.options.height+28+'px', 'width': this.options.width+'px'});
		if (this.options.title){
			//~ var title = new Element('h1', {'class':'popuptitle', 'html': this.options.title}).inject(this.infobox);
			var title = new Element('div', {'class':'dragbar', 'html': this.options.title}).inject(this.infobox);
			if (this.options.closeButton){
				var closeButton = new Element('div', {'class':'closepopup', 'html': 'CLOSE', 'title': 'Click to close', events: ({'click': this.destruct.bind(this)})}).inject(title, 'top');
			}
		}
		
		/* Center initial popup */
		var myWinWidth = Window.getWidth() + Window.getScrollLeft();
		if ( (this.infobox) && (this.options.centerpopup) ){
			var marLeft = (myWinWidth / 2) - (this.infobox.getWidth() / 2);
			var topMar = Window.getScrollTop() + (Window.getHeight() / 2) - (this.infobox.getHeight() / 2);
			this.infobox.setStyles({'left': marLeft+'px', 'top': topMar+'px'});
		}
		/* SET THE CONTENT */
		var dataType = typeof (this.options.data);
		if (dataType == 'object'){
			this.options.data.inject(this.infobox);
		}
		else { this.infobox.set('html', this.options.data);}
		if (this.options.clickOverlayClose) {
			this.overlay.addEvents({ 'click': this.destruct.bind(this)});
			this.overlay.setStyles({'cursor': 'pointer'});
		}
	},
	
	destruct: function(){
		if (this.overlay) this.overlay.destroy();
		if (this.infobox) this.infobox.destroy();
		window.removeEvent('resize', this.centerItems.bind(this));
		window.removeEvent('scroll', this.centerItems.bind(this));
		slideshow = true; // if there was a slideshow, resume
	},
	
	centerItems: function(){
		var myWinWidth = Window.getWidth() + Window.getScrollLeft();
		if (this.overlay) this.overlay.setStyles({top: Window.getScrollTop()+'px', height: Window.getHeight()+'px', width: myWinWidth+'px'});
		if ( (this.infobox) && (this.options.centerpopup) ){
			var marLeft = (myWinWidth / 2) - (this.infobox.getWidth() / 2);
			var topMar = Window.getScrollTop() + (Window.getHeight() / 2) - (this.infobox.getHeight() / 2);
			this.infobox.setStyles({'left': marLeft+'px', 'top': topMar+'px'});
		}
	}
	
});

function postJSON(myurl, mydata, func){
	dispAjax();
	var myRequest = new Request({method: 'post', url: myurl,
		onSuccess: function(response){
			hideAjax();
			/* Check if data is pure JSON */
			var result = $try(function(){ 
				return myObject = JSON.decode(response);},function(){ return false;}
			);
			if (result){ func(result);}
			else{errorMsg(response);}
		},
		onFailure: function(response){errorMsg('Error retrieving data from '+myurl);}
	}).send(mydata);
}

function dispAjax(){
	var ajaxLoaderOverlay = new Element('div').setProperty('id', 'ajaxLoaderOverlay').injectInside(document.body);
	$('ajaxLoaderOverlay').setStyles({top: Window.getScrollTop()+'px', left: 0, height: Window.getHeight()+'px', width: Window.getWidth() + Window.getScrollLeft()+'px'});
}
function hideAjax(){
	if ($('ajaxLoaderOverlay')) $('ajaxLoaderOverlay').destroy();
}

function errorMsg(msg){
	var myDiv = new Element('div', {'styles': {'overflow':'auto', 'height': '300px', 'padding': '5px'}, 'html': msg});
	var showError = new pleromaPopup({
		height: 310,
		width: 730,
		data: myDiv,
		title: 'Server Error',
		overlay: true,
		clickOverlayClose: true
	});
}



function pinfo(item, disabld){
	var myData = postJSON(base+'ascripts/product_info.php', 'ref='+item, function(result, disabled){
		slideshow = false;
		var table = new Element('table', {'id': 'displayProduct'});
		var tbody = new Element('tbody').inject(table);
		var myRow = new Element('tr').inject(tbody);
		var imgtd = new Element('td', {'class': 'pimage', 'html': '<img src="'+base+'images/loading.gif" /> Loading image'}).inject(myRow);
		if (result.im == 0) var showImage = 'no_image.gif';
		else showImage = result.ir+'.jpg';
		/* Check is alternate image root has been defined */
		/*if (typeof(imgRoot) == 'undefined') var theImage = base+'images/products/large/'+showImage;
		else var theImage = imgRoot+'large/'+showImage;*/
		var theImage = base+'images/products/large/'+showImage;
		var myImage = new Asset.image(theImage, {onload: function(){
			imgtd.empty();
			myImage.inject(imgtd);
			var imageHeight = myImage.getHeight();
			var imageWidth = myImage.getWidth();
			if ((imageHeight > 300) || (imageWidth > 300) ){
				if (imageWidth > imageHeight){
					myImage.set('width', '300');
					myImage.set('height', 300 / imageWidth * imageHeight);
				} else {
					myImage.set('height', '300');
					myImage.set('width', 300 / imageHeight * imageWidth);
				}
			}
		}});
		var descrTD = new Element('td', {'class': 'pdescr'}).inject(myRow);
		var descr = new Element('div', {'class': 'descr'}).inject(descrTD);
		var code = new Element('h3', {'html': 'Code: '+result.ic}).inject(descr);
		var title = new Element('h1', {'html': result.sn}).inject(descr);
		var author = new Element('h3', {'html': 'Author: '+result.sa}).inject(descr);
		if (result.pub)
			var pub = new Element('h3', {'html': 'Publisher: '+result.pub}).inject(descr);
		
		if((result.specq) && (!result.rpr) ){
			if (result.specq == 1) var special = new Element('div', {'class':'special', 'html': 'Product on special - only $'+result.specp+' per item'}).inject(descr);
			else var special = new Element('div', {'class':'special', 'html': 'Product on special - order at least '+result.specq+' of these items and pay only '+result.specp+' per item'}).inject(descr);
		}
		var notes = new Element('div', {'html': result.notes}).inject(descr);
		
		var pchoice = new Element('td', {'class': 'pchoice'}).inject(myRow);
		var rrp = new Element('div', {'class':'rrp', 'title':'Recommended Retail Price', 'html': result.rrp}).inject(pchoice);
		if (result.rpr) var rpr = new Element('div', {'class':'rpr', 'title':'Your Reseller Price', 'html': result.rpr}).inject(pchoice);
		else if (result.specp) var specp = new Element('div', {'class':'sp', 'title':'Special Price', 'html': result.specp}).inject(pchoice);
		if (typeof(disabld) == 'undefined'){
			var atcDiag = new Element('div', {'class':'atc', 'title':'Add to Cart', 'events': {'click': function(){atc(result.ir)}}}).inject(pchoice);
			var atwDiag = new Element('div', {'class':'atw', 'title':'Add to Wishlist', 'events': {'click': function(){atw(result.ir)}}}).inject(pchoice);
		}
		
		var showProduct = new pleromaPopup({
			height: 310,
			width: 730,
			data: table,
			title: 'Product Details',
			overlay: true,
			clickOverlayClose: true
		});
		_gaq.push(['_trackEvent', 'Product Click', result.sn]);
	});
}



/* Popup Overlay */
function createOverlay(){
	var overlay = new Element('div').setProperty('id', 'overlay').injectInside(document.body);
	$('overlay').setStyles({opacity: '0.2'});
	$('overlay').setStyles({top: Window.getScrollTop()+'px', left: 0, height: Window.getHeight()+'px', width: Window.getWidth() + Window.getScrollLeft()+'px'});
}


/* Divert to login screen */
function login(){
	var holder = new Element('div');
	var Q = new Element('div', {'styles':{'padding':'10px'}, 'html': '<b>You need to first log into your account to use this feature.</b><br />'+
		'<ul><li><a href="'+base+'login">Click here</a> to <b>Log In</b><br /><br /></li><li>or <a href="'+base+'create_account">Click here</a> to create a <b>new account</b></li></ul> '}).inject(holder);
	var btnholder = new Element('div', {'styles':{'text-align':'center', 'padding-top':'10px'}}).inject(holder);
	var cancel = new Element('input', {
		'type':'button', 
		'value':'No thanks', 
		'class': 'button no',
		'events': {'click': function(){gotoLogin.destruct();}}
	}).inject(btnholder);
	var gotoLogin = new pleromaPopup({
		height: 180,
		width: 350,
		data: holder,
		overlay: true,
		closeButton: false,
		clickOverlayClose: true
	});
}

/* Confirm logout */
function logout(url){
	var agree = confirm('Are you sure you want to log out of this website?');
	if (agree) {
		location.href = url;
	}
}

function checkbrowser(){
	if (typeof document.body.style.maxHeight == "undefined"){
		var IE6Warning = '<h3>Did you know that your Internet Explorer is out of date?</h3>';
		var infoMsg = 'In order to use this site\'s features such as the shopping cart, we recommend that you upgrade to a newer version or other web browser. A list of the most popular web browsers can be found below. <br />We recommend <b>Mozilla Firefox</b>.';
		var browsers = [["Firefox 3+","browser_firefox.gif","http:\/\/www.mozilla.com\/firefox\/"],["Internet Explorer 7+","browser_ie.gif","http:\/\/www.microsoft.com\/windows\/Internet-explorer\/default.aspx"],["Chrome 2.0+","browser_chrome.gif","http:\/\/www.google.com\/chrome"],["Opera 9.5+","browser_opera.gif","http:\/\/www.opera.com\/download\/"],["Safari 3+","browser_safari.gif","http:\/\/www.apple.com\/safari\/download\/\""]];
		var myDiv = new Element('div', {'styles': {'overflow':'auto', 'height': '300px', 'padding': '5px'}, 'html': IE6Warning+'<p>'+infoMsg+'</p>'});
		browsers.each(function(item){
			var dlLink = new Element('div', {
				'class':'dlbrowser',
				'html': '<a href="'+item[2]+'" target="_blank"><img src="'+base+'includes/ie6/'+item[1]+'" /></a><br />'+item[0]
			}).inject(myDiv);
		})
		var showError = new pleromaPopup({
			height: 260,
			width: 730,
			data: myDiv,
			title: 'Please Upgrade Your Browser',
			overlay: true,
			clickOverlayClose: true
		});
	}
}


function hl(elm){elm.setStyle('opacity', '0.7');}
function unhl(elm){elm.setStyle('opacity', '1');}

function showCartImportantInfo(){
	var myData = postJSON(base+'ascripts/important_info.php', 'base='+base, function(result){
		var myDiv = new Element('div', {'styles': {'overflow':'auto', 'height': '300px', 'padding': '5px'}, 'html': result.html});
		var showProduct = new pleromaPopup({
			height: 310,
			width: 730,
			data: myDiv,
			title: 'Important Information',
			overlay: true,
			clickOverlayClose: true
		});
	});
}


function mailingList(){
	var myIframe = new Element('iframe',{'src':'http://www.epostie.co.nz/subscribe/pleroma','style':'border:none;height: 420px;width:600px;'});
	var showProduct = new pleromaPopup({
		width: 604,
		height: 420,
		data: myIframe,
		title: 'Sign Up To Our Newsletter',
		overlay: true,
		clickOverlayClose: true
	});
}