pg={
	currScroll:false,
	prewScroll:function(){
		if(pg.currScroll!=false){
			this.scrollSet(pg.currScroll);
			pg.currScroll=false;
		}
	},
	scrollSet:function(setTo){
		if(setTo=='top') {
			$('content_left').scrollTop=0;
		} else if(setTo=='store') {
			pg.currScroll=$('content_left').scrollTop;
		} else {
			$('content_left').scrollTop=setTo;
		}
	},
	listing_loading:function(dothis,totres){
		if(dothis=='kill'){
			if($('listing_loader_part1')){
				d.body.removeChild($('listing_loader_part1'));
				d.body.removeChild($('listing_loader_part2'));
			}
		}else if(dothis=='step2'){
			inh='<h3>'+lg['Laddar']+' '+totres+' '+lg['Produkter'].toLowerCase()+'...</h3>';
			if($('listing_loader_text')){
				$('listing_loader_text').innerHTML=inh;
			}
		}else{
			if($('listing_loader_part1')){
				ndiv=$('listing_loader_part1');
			}else{
				cch=parseInt($('content_left').clientHeight);
				ccw=parseInt($('content_left').clientWidth);
				getLT=de.getpos($('content_left'));
				ndiv=d.createElement('div');
				ndiv.id='listing_loader_part1';
				ndiv.style.position='absolute';
				ndiv.style.background='#000';
				ndiv.style.top=getLT[1]+'px';
				ndiv.style.left=getLT[0]+'px';
				ndiv.style.width=ccw+'px';
				ndiv.style.height=cch+'px';
				de.changeopac('0.3',ndiv);
				d.body.appendChild(ndiv);
				ndiv=d.createElement('div');
				ndiv.id='listing_loader_part2';
				ndiv.style.position='absolute';
				ndiv.style.background='#000';
				ndiv.style.top=(getLT[1]+50)+'px';
				ndiv.style.left=(getLT[0]+273)+'px';
				ndiv.style.width='200px';
				ndiv.style.background='#fff';
				ndiv.align='center';
				ndiv.style.borderWidth='2px';
				ndiv.style.borderStyle='solid';
				ndiv.className='rounded color_border';
			}
			ndiv.innerHTML='<br><span id="listing_loader_text"><img src="http://images.tackar.com/trans.gif" class="imload"><br><br><h3>'+lg['Laddar']+' '+lg['Produkter'].toLowerCase()+'...</h3></span><br>';
			de.changeopac('0.9',ndiv);
			d.body.appendChild(ndiv);
		}
	},
	mlisting:function(call,where,clearpg,srch){
		this.listing_loading();
		if(!clearpg)clearpg='';
		if(!srch)srch='';
	// GET SEARCH LIMITS
		callextra='';
		if(srch){
			callextra+='&'+srch;
		}

	// ADMINISTRATION
		try{
			if($('adm_settings_taglisting').checked==true){
				callextra+='&adm_taglisting=1';
			}
		}catch(e){}


		if(clearpg)callextra+='&page=1';
		retfunc='pg.setmlisting';
		if(lst.newreturnto){
			retfunc=lst.newreturnto;
		}
		lst.newreturnto=false;
		jx.return_call('http://'+hostver+'prodview/listing.php?sid='+jx.sid()+''+call+callextra,retfunc,'','POST');
	},
	setmlisting:function(ret,byhash){
		pg.closemdetails(1);
		st.closeandclear();
		ot.orderend();
		if(hash.blockhash==false) {
			//hash.set('pg.setmlisting(\''+ret+'\',1)');
		}
		hash.blockhash=false;
		val__=jx.dataArray(unescape(ret));
		pg.closemdetails(1);
		st.closeandclear();
		ot.orderend();
		if(!byhash) {
			this.scrollSet('top');
		}
		if(val__[0]=='lucky'){
			this.details(val__[1]);
			pg.listing_loading('kill');
			return;
		}else if(val__[1]=='tags_match'){
			this.listby_tags(val__[2]);
			pg.listing_loading('kill');
			return;
		}else if(val__[0]=='color'){
			lst.filter_add('','flt_col_0a','color',val__[1],unescape(val__[2]));
			pg.listing_loading('kill');
			return;
		}else if(val__[0]=='nofilter'){
			lst.nofilters();
			pg.listing_loading('kill');
			return;
		}else if(val__[1]=='partner'){
			this.pageload('aboutx.php','_DID='+val__[2]);
			pg.listing_loading('kill');
			return;
		}
		lst.build(val__[2],val__[1],byhash);
		lst.filter_colors(val__[3]);
		lst.filter_tags(val__[4]);
		lst.filter_matchtags(val__[5]);
		lst.filter_kword(val__[6]);
		lst.filter_category(val__[7]);
	},
	listby_tags:function(tags,multimatch){
		if(!multimatch)multimatch='';
		lst.filter_clear();
		this.mlisting('','','','tags='+tags+';&multimatch='+multimatch);
	},
	load_cid:function(cid,cnam,suid,cdid){
		lst.filter_clear();
		//pg.mlisting('&amp;cid=114&amp;_DID=MjJDRjVCMUI2M0MzM0RFQUFDNEY2NkJDQTY3QzU5MjM=','x')
		if(!suid)suid='';
		if(!cdid)cdid='';
		call='cid='+cid+'|'+cnam+'|'+suid+'|'+cdid;
		pg.mlisting('','','',call);
	},
	pageload:function(page,ext){
		st.closeandclear();
		ot.orderend();
		supersrch.hide();
		if(!ext){
			ext='';
		}else ext+='&';
		jx.return_call(page+'?'+ext+'sid='+jx.sid(),'pg.setpageload','|pg.loader','POST');
	},
	mypage:function(pageId,pageNam){
		if(!pageId)pageId='';
		if(!pageNam)pageNam='';
		st.closeandclear();
		ot.orderend();
		supersrch.hide();
		//hash.set('pg.mypage(\''+pageId+'\',\''+pageNam+'\')');
		jx.return_call('/mypage.php?sid='+jx.sid()+'&id='+pageId+'&nam='+pageNam,'pg.setpageload','|pg.loader','POST');
	},
	setpageload:function(ret){
		hash.set('pg.setpageload(\''+ret+'\')');
		this.scrollSet('top');
		pg.closemdetails();
		st.closeandclear();
		ot.orderend();
		pg.clearall();
		lst.filter_onoff('none');
		$('maincore').style.display='block';
		$('maincore').innerHTML=unescape(ret);
	},
	loader:function(stop){
		if(stop==null) {
			try{
				getScrollT=de.scrWH();
				scrollT=getScrollT[2];
				de.changeopac(0.8,'loader');
				//$('loader').style.top=scrollT+'px';
				if(centerLoader){
					$('loader').style.left=(parseInt(getScrollT[0])/2-100)+'px';
				}
				$('loader').style.display='block';
				d.body.style.cursor='wait';
			}catch(e){}
		} else {
			try{
				$('loader').style.display='none';
				d.body.style.cursor='default';
			}catch(e){}
		}
	},
	settopic:function(txt){
		if(txt){
			$('topic').innerHTML='<h1>'+txt+'</h1>';
		}else{
			$('topic').innerHTML='';
		}
	},
	details:function(artnr,loadcol){
		if(!artnr)artnr='';
		if(!loadcol)loadcol='';

	// ADMINISTRATION
		callextra='';
		try{
			if($('adm_settings_tagbutton').checked==true){
				callextra+='&adm_tagbutton=1';
			}
		}catch(e){}

		jx.return_call('http://'+hostver+'prodview/details.php?sid='+jx.sid()+'&lang='+lang+'&PID='+artnr+'&ColID='+loadcol+callextra,'pg.details_set','|pg.loader','POST');
	},
	details_num:0,
	details_set:function(ret){
		this.scrollSet('store');

		st.closeandclear();
		ot.orderend();
		hash.set('pg.details_set(\''+ret+'\')');
		val=jx.dataArray(unescape(ret));
		/* Google analytics */ ga.send(val[2]);
		if(val[1]=='NEWITEM'){
			alert(lg['Denna produkt har ersatts med artikel']+' '+val[2]);
			pg.details(val[2]);
			return;
		} else if(val[1]==''){
			help.start('prod_dont_exist');
			return;
		}
		$('details').innerHTML=val[1];
		$('details').style.display='block';
		$('maincore').style.display='none';
		$('topic').style.display='none';
		// OpenMail?
		try{
			if(OpenMail.checkIfOpen()) {
				$('detail_openmail').style.display='block';
			} else $('detail_openmail').style.display='none';
		}catch(err){}
		this.listFilters=lst.filter_onoff('none');
		eval(val[3]);
		if(stst.backeditObj){
			stst.backedit_do(stst.backeditObj);
		}
		this.scrollSet('top');
	},
	clearall:function(){
		de.detail_close_all();
		$('maincore').style.display='none';
		$('topic').style.display='none';
	},
	closemdetails:function(blockfilter){
		try{gadget.slider.reset()}catch(e){}
		st.overmen_kill();
		st.closeandclear();
		//st.offerclose();
		de.detail_close_all();
		$('maincore').style.display='block';
		$('topic').style.display='block';
		if(!blockfilter){
			lst.filter_onoff('detailclose');
		}
		this.prewScroll();
	},
	randomprod:function(){
		jx.return_call('http://'+hostver+'randprod.php?lang=se','pg.randomprodset','');
	},
	randomprodset:function(ret){
		val=jx.dataArray(unescape(ret));
		$('randprod').onclick=function(){pg.details(val[2],'m')};
		$('randimg').src=val[1]+'&width=150&height=150&fullsize=0';
		$('randprodnfo').innerHTML='<small>'+val[4]+'</small><br><big><b>'+val[3]+'</b></big>&nbsp;&nbsp;&nbsp;<i>('+val[2]+')</i>';
		setTimeout('pg.randomprod()',10000);
	},
	mysettings:function(dep,opt){
		if(!opt)opt='';
		/* Google Analytics */ ga.send('Settings: '+dep);
		jx.return_call('http://'+hostver+'settings.php?sid='+jx.sid()+'&d='+dep+opt,'pg.setsettings','|pg.loader');
	},
	setsettings:function(ret){
		val=jx.dataArray(unescape(ret));
		de.popup(700,escape(val),20,null,true,lg['Inställningar']);
	},
	pop_info_page:function(did,pageid){
		jx.return_call('http://'+hostver+'_inc/xpage.php?sid='+jx.sid()+'&d='+did+'&p='+pageid,'pg.pop_info_page_ret','|pg.loader','POST');
	},
	pop_info_page_ret:function(ret){
		de.popup(550,unescape(ret),null,null,true);
	},
	act_offertxt:null,
	cssdata:function(clnam,txtcolor,txtsize,txtface,txtb,txti,txtu,txtheight,txtx,txty,bgcol,bgcolret,txtw,txth){
		sheet=d.styleSheets[d.styleSheets.length-1];
		ssRules=sheet.cssRules||sheet.rules;
		for(c=0;c<ssRules.length;c++){if(ssRules[c].selectorText=='.'+clnam){result=ssRules[c].style;break}}
		if(txtcolor!=null){
			result.color='#'+txtcolor;
			result.fontSize=txtsize+'px';
			result.fontFamily=txtface;
			result.fontWeight=txtb;
			result.fontStyle=txti;
			result.textDecoration=txtu;
			result.lineHeight=txtheight+'px';
		}else if(txtx&&txty){
			txty=de.replace(txty,'px','');
			txtx=de.replace(txtx,'px','');
			result.top=txty+'px';
			result.left=txtx+'px';
		}else if(bgcol){
			result[bgcolret]='#'+bgcol;
		}else if(bgcolret){
			return result[bgcolret];
		}else if(txtw&&txth){
			result.width=txtw+'px';
			result.height=txth+'px';
		}else{
			return Array(result.color,result.fontSize,result.fontFamily,result.fontWeight,result.fontStyle,result.textDecoration,result.lineHeight);
		}
	},
	setting_set_img_view:function(val){
		if(val!=null){
			jx.return_call('http://'+hostver+'_srch/cust.php?sid='+jx.sid()+'&a=setimgview&val='+val,'pg.noreturn','|pg.loader');
		}
	},
	setting_offerresetlang:function(){
		jx.return_call('http://'+hostver+'plugins/login/actions.php?sid='+jx.sid()+'&a=jx_updateofferlang','pg.setting_offerresetlang_ok','|pg.loader','POST');
	},
	setting_offerresetlang_ok:function(){pg.mysettings('offers')},
	setting_setoffercol:function(objId,ev,type){
		de.preventDefault(ev);
		pg.act_offertxt=objId;
		pg.setting_getoffertxt_show(ev,lg['Ändra färg']);
		$('offer_edit_text').style.display='none';
		$('offer_edit_color').style.display='block';
		$('chgcoltype').value=type;
		bgcol=de.rgbConvert(pg.cssdata(objId.className,null,null,null,null,null,null,null,null,null,null,type));
	// COLOR
		$('textcolor_bg').value='#'+bgcol;
		$('cp_view_bg').style.background='#'+bgcol;
	},
	setting_saveoffercol:function(){
		$('mess1').innerHTML='';
		bgcolor=$('textcolor_bg').value.toUpperCase();
		pg.cssdata(pg.act_offertxt.className,null,null,null,null,null,null,null,null,null,bgcolor,$('chgcoltype').value);
		$('offer_edit_color').style.display='none';
		pg.setting_setoffersave();
		pg.setting_getoffertxt_close();
	},
	setting_setofferbgcolor:function(col){
		$('textcolor_bg').value=col;
		$('cp_view_bg').style.background='#'+col;
	},
	setting_getoffertxt_close:function(){
		$('offereditor').style.display='none';
	},
	setting_getoffertxt_show:function(ev,topic){
		$('offereditor_topic').innerHTML='<h1>'+topic+'</h1>';
		tmp_currwhight=de.scrWH('in');
		getpageXY=de.pageXY(ev);
		currMX=getpageXY[0];
		currMY=getpageXY[1];
		//if(parseInt(currMY)+200>tmp_currwhight[1]){
		//	$('offereditor').style.top=(tmp_currwhight[1]-400)+'px';
		//}else $('offereditor').style.top=currMX+'px';
		$('offereditor').style.left='150px';
		$('offereditor').style.top='200px';
		$('offereditor').style.display='block';
	},
	setting_getoffertxt:function(objId,ev,spec){
		de.preventDefault(ev);
		pg.act_offertxt=objId;
		pg.setting_getoffertxt_show(ev,lg['Redigera text']);
		$('offer_edit_text').style.display='block';
		$('offer_edit_color').style.display='none';
		txt=objId.innerHTML;
		if(spec=='locked') {
			$('setoffertxt').disabled=true;
		} else if(spec=='object') {
			$('setoffertxt').disabled=true;
			txt='[object]';
		} else if(spec!=null) {
			pg.act_offertxtfld=spec;
			$('setoffertxt').disabled=false;
		} else {
			$('setoffertxt').disabled=false;
		}
		txt=de.replace(txt,'<br>','\n');
		txt=de.replace(txt,'<BR>','\n');
		$('setoffertxt').value=txt;
		$('mess1').innerHTML='';
		cssdata=pg.cssdata(objId.id);
		txtcolor=de.rgbConvert(cssdata[0]);
		txtsize=parseInt(cssdata[1]);
		txtface=cssdata[2].toLowerCase();
		txtb=cssdata[3];
		txti=cssdata[4];
		txtu=cssdata[5];
		txtheight=cssdata[6];
	// COLOR
		$('textcolor').value=txtcolor;
		$('cp_view').style.backgroundColor='#'+txtcolor;
	// BOLD
		if(txtb=='bold'){
			$('textb').style.border='1px inset gray';
		} else $('textb').style.border='1px outset gray';
	// ITALIC
		if(txti=='italic'){
			$('texti').style.border='1px inset gray';
		} else $('texti').style.border='1px outset gray';
	// UNDERLINE
		if(txtu=='underline'){
			$('textu').style.border='1px inset gray';
		} else $('textu').style.border='1px outset gray';
	// FONT SIZE
		list=$('textsize');
		for(i=0;i<list.options.length;i++) {
			if(list.options[i].value==txtsize) {
				list.options[i].selected=true;
			}
		}
	// FONT FACE
		list=$('textface');
		for(i=0;i<list.options.length;i++) {
			if(list.options[i].value==txtface) {
				list.options[i].selected=true;
			}
		}
	// LINE HEIGHT
		$('textheight').value=parseInt(txtheight);

	// SET RESULT
		editObj=$('setoffertxt');
		editObj.style.color=txtcolor;
		editObj.style.fontSize=(txtsize*1.5)+'px';
		editObj.style.fontFamily=txtface;
		editObj.style.fontWeight=txtb;
		editObj.style.fontStyle=txti;
		editObj.style.textDecoration=txtu;
		editObj.style.lineHeight=eval(parseInt(txtheight)*1.5)+'px';
		editObj.select();
	},
	setting_setoffercolor:function(col){
		$('cp_view').style.background='#'+col;
		$('textcolor').value=col;
		$('setoffertxt').style.color='#'+col;
	},
	setting_setofferstyle:function(set,ret) {
		if(set) {
			if($(set).style.border=='1px inset gray'||$(set).style.border=='gray 1px inset'){
				$(set).style.border='1px outset gray';
			} else {
				$(set).style.border='1px inset gray';
			}
		}
	// BOLD
		if($('textb').style.border=='1px inset gray'||$('textb').style.border=='gray 1px inset'){
			txtb='bold';
		} else txtb='normal';
	// ITALIC
		if($('texti').style.border=='1px inset gray'||$('texti').style.border=='gray 1px inset'){
			txti='italic';
		} else txti='normal';
	// UNDERLINE
		if($('textu').style.border=='1px inset gray'||$('textu').style.border=='gray 1px inset'){
			txtu='underline';
		} else txtu='none';
	// FONT SIZE
		txtsize=$('textsize').value;
	// FONT FACE
		txtface=$('textface').value;
	// FONT COLOR
		txtcolor=$('textcolor').value.toUpperCase();
	// FONT HEIGHT
		if($('textheight').value==''){
			txtheight=eval(parseInt(txtsize)+2);
		} else txtheight=$('textheight').value;

	// CHANGE LINE HEIGHT WITH FONT SIZE CHANGE
		if(ret=='setheight'){
			newLineHeight=eval(parseInt(txtsize)+2);
			$('textheight').value=newLineHeight;
			txtheight=newLineHeight;
		}

	// RETURN
		if(ret=='save'){
			pg.cssdata(pg.act_offertxt.id,txtcolor,txtsize,txtface,txtb,txti,txtu,txtheight);
			$('offer_edit_text').style.display='none';
		}
		editObj=$('setoffertxt');
		editObj.style.color=txtcolor;
		editObj.style.fontSize=(txtsize*1.5)+'px';
		editObj.style.fontFamily=txtface;
		editObj.style.fontWeight=txtb;
		editObj.style.fontStyle=txti;
		editObj.style.textDecoration=txtu;
		editObj.style.lineHeight=(txtheight*1.5)+'px';
	},
	setting_setoffertxt:function(){
		pg.setting_getoffertxt_close();
		if(pg.act_offertxt==null) {
			alert('Du måste välja en text');
			return;
		}
		objNam=pg.act_offertxt.id;
		txt=$('setoffertxt');
//		pg.setting_setofferstyle('',pg.act_offertxt);
		pg.setting_setofferstyle('','save');
		if(txt.disabled==true) {
			sendVal='objnam='+objNam+'&objtxt=';
			txt.disabled=false;
		} else {
			sndTxt=txt.value;
			sndTxt=de.replace(sndTxt,'+','[plus]');
			sendVal='objnam='+objNam+'&objtxt='+escape(sndTxt);
			if(txt.value=='')txt.value='[blank]';
			settxt=de.replace(txt.value,'\n','<br>');
			pg.act_offertxt.innerHTML=settxt;
		}
		txt.value='';
		pg.act_offertxt=null;
		jx.return_call('http://'+hostver+'plugins/login/actions.php?sid='+jx.sid()+'&a=jx_updateoffer&'+sendVal,'pg.setting_setoffersave','|pg.loader','POST');
	},
	setting_setoffersave:function(){
		$('mess1').innerHTML='';
		savecss='';
		savecsslogo='';
		sheet=null;
		for(i=0;i<d.styleSheets.length;i++){
			if(d.styleSheets[i].title=="css_settings"){
				sheet=d.styleSheets[i];
				break;
			}
		}
		r=sheet.cssRules||sheet.rules;
		savecss='';
		savecsslogo='';
		for(c=0;c<r.length;c++){
			if(r[c].cssText){
				t=r[c].cssText;
				if(r[c].selectorText.toLowerCase()=='.of_logo'){
					savecsslogo+=r[c].selectorText+'{';
					for(b=0;b<r[c].style.length;b++){
						savecsslogo+=r[c].style[b]+':'+r[c].style.getPropertyValue(r[c].style[b])+';';
					}
					savecsslogo+='}';
				}else{
					savecss+=r[c].selectorText+'{';
					for(b=0;b<r[c].style.length;b++){
						savecss+=r[c].style[b]+':'+r[c].style.getPropertyValue(r[c].style[b])+';';
					}
					savecss+='}';
				}
			}else{
				t=r[c].style.cssText;
				if(r[c].selectorText.toLowerCase()=='.of_logo'){
					nam=r[c].selectorText;
					val=t.toLowerCase()+';';
					savecsslogo+=nam+'{'+val+'}';
				}else{
					nam=r[c].selectorText;
					val=t.toLowerCase()+';';
					savecss+=nam+'{'+val+'}';
				}
			}
		}
		jx.return_call('http://'+hostver+'plugins/login/actions.php?sid='+jx.sid()+'&a=jx_updatecss&cssdata='+savecss+'&csslogo='+savecsslogo,'pg.setting_setoffersaveok','|pg.loader','POST');
	},
	setting_setoffersaveok:function(){
		messbox=$('mess1');
		messbox.innerHTML=lg['Ändringar sparade'];
		setTimeout('messbox.innerHTML=\'\'',3000);
	},
	setting_setoffergrid:function(objId){
		if(objId.checked==true){
			$('movearea').style.backgroundImage='url(\'_gfx/grid.gif\')';
		} else {
			$('movearea').style.backgroundImage='none';
		}
	},
	contest_send:function(){
		if($('contest_txt').value==''){
			alert('Please enter a text first!');
			return;
		}
		txt=escape($('contest_txt').value);
		jx.return_call('http://'+hostver+'feedback.php?sid='+jx.sid()+'&type=2&txt='+txt,'pg.contest_return','|pg.loader');
	},
	contest_return:function(){
		$('contest_txt').value='';
		$('contestwin').innerHTML='<br><h1 style="color:#0080CC;font-size:25px">'+lg['Tack']+'!</h1><br>';
	},
	feedback:function(){
		txt=escape($('feedback_txt').value);
		whereat=escape($('feedback_where').value);
		jx.return_call('http://'+hostver+'feedback.php?sid='+jx.sid()+'&type=1&txt='+txt+'&whereat='+whereat,'pg.feedbackok','|pg.loader');
	},
	feedbackok:function(){
		$('feedback_txt').value='';
		$('feedback_thx').innerHTML='Feedback saved';
		setTimeout('document.getElementById(\'feedback_thx\').innerHTML=\'\'',2000);
	},
	campopen:function(cid,artnr,where){
		jx.return_call('http://'+hostver+'_inc/ecamp_reg.php?cid='+cid,'pg.noreturn','','POST');
		pg.details(artnr,where);
	},
	partnerabout:function(xid){
		poploadSetWidth=750;
		poploadSetTop=40;
		useH=(de.scrWH('in')[1]-150);
		de.popload('aboutx.php?_DID='+escape(xid)+'&useH='+useH,true);
		/* Google Analytics */ //ga.send('Settings: '+dep);
	},
	noreturn:function(){} // USE THIS WHEN AJAX CALL DONT NEED A RETURN
};