JSLib.Shop = {

    updateArticleList : function(articlelistid,formid,progressid,page) {
	var articlelist=document.getElementById(articlelistid);
	var f=document.getElementById(formid);
	var p=document.getElementById(progressid);
	var pi=document.getElementById(progressid+"ind");
	p.style.left=JSLib.Core.getLeft(articlelist)+"px";
	p.style.top=JSLib.Core.getTop(articlelist)+"px";
	p.style.width=JSLib.Core.getWidth(articlelist)+"px";
	p.style.height=JSLib.Core.getHeight(articlelist)+"px";
	p.style.display="block";
	pi.style.display="block";
	pi.style.top=(JSLib.Core.getTop(articlelist)+(JSLib.Core.getHeight(articlelist)-JSLib.Core.getHeight(pi))/3)+"px";
	pi.style.left=(JSLib.Core.getLeft(articlelist)+(JSLib.Core.getWidth(articlelist)-JSLib.Core.getWidth(pi))/2)+"px";
	
	
	if(page) f.elements.articlelistpage.value=page;
	var formdata=new Array();
	for(var i=0;i<f.elements.length;i++) {
	    var el=f.elements.item(i);
	    formdata[i]=encodeURIComponent(el.name)+"="+encodeURIComponent(el.value);
	}
	articlelist.areq=JSLib.AjaxFactory.createRequest();
	articlelist.areq.setURL(f.action);
	articlelist.areq.setMethod("POST");
	articlelist.areq.setParams(formdata);
	articlelist.areq.registerCompletionListener(JSLib.Shop.handleUpdateArticleList,articlelist);
	articlelist.areq.execute();
    },

    handleUpdateArticleList : function(articlelist) {
	articlelist.innerHTML=articlelist.areq.getContent();
    },

    toggleArticleDetails : function(detailid) {
	var detailel=document.getElementById(detailid);
	var detailhideel=document.getElementById(detailid+"h");
	if(JSLib.Core.hasClass(detailel,"detailshidden")) {
	    JSLib.Core.removeClass(detailel,"detailshidden");
	    try {
		detailhideel.style.display="table-cell";
	    } catch(ex) {
		detailhideel.style.display="block";
	    }
	} else {
	    JSLib.Core.addClass(detailel,"detailshidden");
	    detailhideel.style.display="none";
	}
    },

    showTT : function(tt) {
	var ttbox=tt.nextSibling;
	ttbox.style.display="block";
	ttbox.style.top=(JSLib.Core.getTop(tt)-JSLib.Core.getHeight(ttbox)-2)+"px";
	ttbox.style.left=(JSLib.Core.getLeft(tt)+JSLib.Core.getWidth(tt)+2)+"px";
	
    },

    hideTT : function(tt) {
	var ttbox=tt.nextSibling;
	ttbox.style.display="none";
    },

    checkNumericInput : function(field) {
	var oldvalue=field.value;
	setTimeout(function(){
		var value=field.value;
		var havedecsep=false;
		var match=true;
		var i=0;
		if(value.length>0 && value.charCodeAt(0)==45) i++;
		for(;i<value.length;i++) {
		    var c=value.charCodeAt(i);
		    if(c>=48 && c<=57) continue;
		    if(c==46 && !havedecsep) {
			havedecsep=true;
			continue;
		    }
		    match=false;
		    break;
		}
		if(!match) field.value=oldvalue;
	},0);
    }

}
