String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}
String.prototype.startsWith = function (a) {
	return a && (this.substring(0,a.length)==a);
}

var popped=-1;
var wto=null;
function popProduct(i){
	if(wto!=null){window.clearTimeout(wto);wto=null;}
	if(popped==i){return;}
	popped=i;
	var p=products[i];
	var h="";
	var pComp=p.comp.trim();
	var pAva=p.availableIn.trim();
	h+="<div id='ppin'>";
	if(p.image>0){
		h+="<div><img src='../main/"+p.image+".image' border='0' style='float:right;margin:2px;'/></div>";
	}
	h+="<h3>"+p.title;
	if (p.price>0) {
		h+=" "+p.priceForm;
	}
	h+="</h3>";
	h+="<div>"+p.description+"</div>";
	if (pComp.length>0){
		h+="<div style='margin-top:5px;'><b><i>Composition:</i></b> "+pComp+"</div>";
	}
	if (pAva.length>0){
		h+="<div style='margin-top:5px;'><b><i>Available In:</i></b> "+pAva+"</div>";
	}
	h+="</div>";
	if (p.price>0) {
		h+="<form id='ppfrm' onsubmit='return buy();'>";
		h+="<input type='hidden' name='buyId' value='"+p.id+"'/>";
		h+=" Quantity: <input type='text' name='buyQty' size='4' value='1'/>";
		if (pComp.length>0 || pAva.length > 0) {
			h+=" In:";
		}
		h+=" " + sel(pComp,"buyComp");
		h+=" " + sel(pAva,"buyStyle");
		h+=" <input type='image' src='../img/buy.gif' align='absmiddle'/>";
		h+="</form>";
	}
	h+="<div id='ppcls'><a href='#' onclick='unpop();'>Close</a></div>";
	$('ppout').innerHTML=h;
	$('ppout').style.display='block';
	__foc("buyQty");
}
function buy() {
	var p=Form.serialize('ppfrm');
	new Ajax.Updater('hwelcome', '../dhtml/catalog_add.action',{postBody:p, onComplete:reallyUnpop});
	return false;
}
function unpop(){
	wto=window.setTimeout(reallyUnpop,500);
}
function popPage(a) {
	new Ajax.Updater('ppout', a,{onComplete:reallyPop});
	return false;
}
function reallyPop() {
	$('ppout').style.display='block';
}
function reallyUnpop(){
	wto=null;
	popped=-1;
	$('ppout').style.display='none';
}
function showProducts(path) {
	var h="",i,p;
	for(i=0;i<products.length;i++){
		p=products[i];
		if (!p.path.startsWith(path)){continue;}
		h+="<div class='photo'";
		h+=" style='height:150px;width:125px;margin-bottom:2px;margin-right:2px;float:left;cursor:pointer;'";
		h+=" onmouseover=\"this.className='hphoto'\" onmouseout=\"this.className='photo'\"";
		h+=" onclick='popProduct("+i+");'>";
		h+="<div class='photoinner' style='height:145px;width:120px;'>";
		if(p.image>0){
			h+="<img src='../main/"+p.image+".thumb' border='0'/>";
		}
		h+="<div class='pttl'>"+p.title+"</div>";
		if (p.price>0) {
			h+="<div>"+p.priceForm+"</div>";
		}
		h+="</div></div>";
	}
	$("pwin").innerHTML=h;
}
function showCategories() {
	var h="<h3>Categories</h3>",i,c,ii;
	var ll=-1;
	for(i=0;i<categories.length;i++){
		c=categories[i];
		for(ii=ll;ii<c.level;ii++){
			h+="<ul class='tree'>";
		}
		for(ii=c.level;ii<ll;ii++){
			h+="</ul>";
		}
		h+="<li><a href='#' onclick=\"showProducts('"+c.path+"');return false;\">"+c.title+"</a></li>";
		ll=c.level;
	}
	for(ii=0;ii<ll;ii++){
		h+="</ul>";
	}
	$("pcat").innerHTML=h;
}
function sel(a, id){
	if (a.length==0) {
		return "<input type='hidden' name='"+id+"' value=''/>";
	}
	var os=a.split(",");
	var h="<select name='"+id+"'>";
	var i,o;
	for (i=0;i<os.length;i++){
		o=os[i].trim();
		h+="<option value=\""+o+"\">"+o+"</option>";
	}
	h+="</select>";
	return h;
}

var __ss=[];

function startSlideShow(i,d) {
	var si={};
	__ss[i]=si;
	si.id=i;
	si.ndx=0;
	si.next=$('issimg_'+i+'_0');
	continueSlideShow(i);
	window.setInterval('continueSlideShow(' + i + ');', d);
}
function continueSlideShow(i) {
	var si=__ss[i];
	if(si.current) {
		si.current.style.display='none';
	}
	if(si.next) {
		si.next.style.display='inline';
	}
	si.current=si.next;
	si.ndx++;
	si.next=$('issimg_'+i+'_'+si.ndx);
	if(!si.next){
		si.ndx=0;
		si.next=$('issimg_'+i+'_'+si.ndx);
	}
}

function startBlockShow(i,d) {
	var si={};
	__ss[i]=si;
	si.id=i;
	si.ndx=0;
	si.next=$('issblk_'+i+'_0');
	continueBlockShow(i);
	window.setInterval('continueBlockShow(' + i + ');', d);
}
function continueBlockShow(i) {
	var si=__ss[i];
	if(si.current) {
		si.current.style.display='none';
	}
	if(si.next) {
		si.next.style.display='block';
	}
	si.current=si.next;
	si.ndx++;
	si.next=$('issblk_'+i+'_'+si.ndx);
	if(!si.next){
		si.ndx=0;
		si.next=$('issblk_'+i+'_'+si.ndx);
	}
} 
 
