/**
 * @(#)/views/library/lib_myshop.js
 * 
 * Copyright 2000-2011(c) MijnWinkel B.V.
 * 
 * Version 11.9.0 14-sep-2011
 */


function __onLoadPage(){}
function w(s){document.write(s)}
function hasMenu(s){return false}

function _i(v){return(v==null)?0:parseInt(v,10)}
function getElementOnId(n,d){
	var ref;
	if(d==null)d=document;
	if(d.layer)ref=layer[n];
	else if(d.all==null)ref=d.getElementById(n);
	else ref=d.all[n];
	return ref
}
function showDeliveryFields(n,ctl){
	var e=getElementOnId("delivery_fields");
	if(e!=null)e.style.display=(n)?"":"none";
	if(ctl){
		var e=_myshopEvent.events.MYSHOP_EVENT_ADDRESS_TYPE;
		if(_myshop.exist(e))cont=_myshop.trigger(e,ctl.value);
		
	}
}

function MyShopRemoveHTMLTags(htmlString){
    if(htmlString){
        var mydiv = document.createElement("div");
        mydiv.innerHTML = htmlString;
        if (document.all){return mydiv.innerText;} 
        else{return mydiv.textContent;}                           
    }
} 

function MyShopState(){
	var me=this,events=[],check=[];

	me.register=function(name,func){
		events[name]=func;
		check[name]=true;
	};
	me.trigger=function(name,value){
		return(events[name])?events[name](value):true;
	};
	me.exist=function(name){
		return check[name];
	};
}
var _myshop=new MyShopState(),_myshop_popup=null,_myshop_event_block=-1,_myshop_help,_myshop_part=-1;

function MyShopEvent(){
	var me=this;
	me.events={
		"MYSHOP_EVENT_NEXT":"on_next",
		"MYSHOP_EVENT_PREVIOUS":"on_previous",
		"MYSHOP_EVENT_BACK":"on_back",
		"MYSHOP_EVENT_GLOBALSEARCH":"on_globalsearch",
		"MYSHOP_EVENT_ADDRESS_TYPE":"on_address_type"
	};
	
	function register(n,f){
		if(n&&f)for(var k in me.events)if(me.events[k]==n){
			_myshop.register(n,f);
			break;
		}
	}
	
	me.onNext=function(f){register(me.events.MYSHOP_EVENT_NEXT,f)};
	me.onPrevious=function(f){register(me.events.MYSHOP_EVENT_PREVIOUS,f)};
	me.onBack=function(f){register(me.events.MYSHOP_EVENT_BACK,f)};
	me.onSearch=function(f){register(me.events.MYSHOP_EVENT_GLOBALSEARCH,f)};
	me.onAddressType=function(f){register(me.events.MYSHOP_EVENT_ADDRESS_TYPE,f)};
	
}
var _myshopEvent=new MyShopEvent(),_myshopJq,_myshopRelease=3;

function myshopEvent(){
	return _myshopEvent;  
}
	
function myshopConsole(s){
	if(true)try{if(self.console)console.log(s)}catch(e){}
}

function MyShop(){
	var POPUP_NAME="myshoporderpopup";
	var me=this,_location=null,_target=null,_width="440",_height="280",_msg="",_quantity=null,_formName="data",_leave=false,_item=null;
	var _hasQuery=false,_onload=null,_validated=false,_scrollPos=false,_clearSelection=false;
	var MAX_SEARCH_FIELD=30;
	me.version=3;
	me.valid=true;
	
	function i(v){return(v==null)?0:parseInt(v,10)}

	function clearSelection(id){
		var n=0,c,index,last,selection="";
		if(!isNaN(id)){
			last=i(id);
			index=last+1;
			while(index<MAX_SEARCH_FIELD){
				c=getElementOnId("myshp_search_field_"+index);
				if(c){
					if(c.value)c.value="";
				}else break;
				c=getElementOnId("myshp_search_field_max_"+index);
				if(c&&c.value)c.value="";
				index++
			}
			selection=getSelection(last);
		}
		index=0;
		while(index<MAX_SEARCH_FIELD){
			c=getElementOnId("myshp_search_field_menu_"+index);
			if(c)c.value="";
			else break;
			index++
		}
		return selection;
	}
	function getSelection(last){
		var index=0,c,selection="",sep="";
		for(index=0;index<=last;index++){
			c=getElementOnId("myshp_search_field_"+index);
			if(c&&c.value){
				selection+=sep;
				selection+=encodeURIComponent(c.name)+"="+encodeURIComponent(c.value);
				sep="&";
			}
			c=getElementOnId("myshp_search_field_max_"+index);
			if(c&&c.value){
				selection+=sep;
				selection+=encodeURIComponent(c.name)+"="+encodeURIComponent(c.value);
				sep="&";
			}
		}
		var f=getData();
		if(f){
			c=f["_globalsearch"];
			if(c&&c.value!='')selection+=sep+"_globalsearch="+encodeURIComponent(c.value);
		}
		if(selection!=""&&f["m"])f["m"].value="0";
		
		return selection;
	}
	
	function showMessage(s){
		var bodyId=document.getElementsByTagName("body")[0];
		if(bodyId){
			
			var msg=document.createElement('div');
			msg.setAttribute('class', 'myshp_message myshp_upload');
			var l=(getDocumentWidth()-300)*0.5,t=(screen.height-80)*0.3;
			msg.setAttribute('style', 'background-color:yellow;position:absolute;top:'+t+'px;left:'+l+'px;width:300px;height:80px;text-align:center;border:3px black solid;');
			msg.appendChild(document.createElement('br'));
			msg.appendChild(document.createTextNode(s));
			msg.appendChild(document.createElement('br'));
			msg.appendChild(document.createElement('br'));
			var img=document.createElement('img');
			img.setAttribute('src', '/views/loading/loading.gif');
			img.setAttribute('style', 'width:212px;height:16;');
			msg.appendChild(img);
			bodyId.appendChild(msg);
		}
	}
	
	function getDocumentWidth(){
		var e=document.documentElement;
		return(e&&e.offsetWidth&&e.offsetWidth>0)?e.offsetWidth:document.body.offsetWidth;
	}
	
	function endsWith(s,n){
		var i=0,ret=false;
		if(s){
			i=s.length-1;
			ret=(s.indexOf(n)==i);
		}
		return ret;
	}
	function trim(v){
		if(v==null)v='';
		else v=''+v;
		return(v=='')?v:v.replace(/^\s+|\s+$|&nbsp;|&#160;/gi,'');
	}
	function encode(v,from,to){
		if(v==null)v='';
		else v=''+v;
		return(v=='')?v:v.replace(new RegExp(from,"g"),to);
	}
	function getData(frm){
		f=document.forms[_formName];
		if(!f&&frm)f=document.forms[frm];
		return f;
	} 
	
	me.data=getData;

	me.reload=function(){
		_leave=true;
		var f=getData();
		if(f){
			f.action=(_location)?_location:f["this"].value;
			f.target="_self";
			f.submit();
		} 
		else window.location.reload();
	};

	me.help=function(shopId,lang,title){
		if(_myshop_help)try{
			_myshop_help.close();
		}catch(e){}
		if(!lang)lang="nl";
		_myshop_help=window.open('http://www.mijnwinkel.nl/help/frame.html?page=hkassa_'+lang+'.html&language='+lang+'&_vid='+shopId,title,"height=450px,width=400px,left=10px,top=10px",true);
	};
	
	me.focus=function(c){
		try{
			if((typeof c != "undefined")){
				if((typeof c) == "string")c=getData()[c];
				if(c)c.focus();
			}
		}catch(e){}
	};
	
	
	
	function isValid(a,id){
		var oke=true,f=getData();
		if(f&&("add"==a||(_myshopRelease==3&&_caller&&"change_update"==a))&&!_validated&&id){
			_validated=true;
			var q=f[get("i")+".quantity"];
			if(q||hasOrderFields()){
				oke=me.validate(id,((q)?q.value:"1")).valid;
				if(!oke){
					_location=null;
					cont=false;
					me.focus(q);
				}
			}
		}
		return oke;
	}
	
	function hasOrderFields(){
		var n=0,oke=false,f=getData(),index=get("i");
		if(f){
			for(;n<20;n++){
				oke=f["text"+n]||f[index+"text"+n];
				if(oke)break;
			}
		}
		return oke||hasOrderUploadFields();
	}
	
	function hasOrderUploadFields(){
		var n=0,oke=false,f=getData(),index=get("i");
		if(f){
			for(;n<20;n++){
				oke=f["upload"+n]||f[index+"upload"+n];
				if(oke)break;
			}
		}
		return oke;
	}
	
	
	var _caller=null;
	me.caller=function(caller){
		// arguments.callee.caller.toString()
		_caller=caller;
		return me;
	};
	me.c=me.caller;
	
	me.sp=function(e){
		if(!e)e=window.event;
		if(e.cancelBubble)e.cancelBubble=true;
		if(e.stopPropagation)e.stopPropagation();
		
		return me;
	};
	
	me.ssp=function(){
		_scrollPos=true;
		return me;
	};
	
	me.cs=function(e){
		_clearSelection=true;
		me.sp(e);
		return me;
	};
	
	
	me.action=function(a,id,next){
		_leave=true;
		var f=getData(),useLocation=false,selection="",aa,thisUri=true,multiPart=false;;
		if(f&&a){
			aa=f.action;
			
			var delay=false,cont=true;
			if(f["a"])f["a"].value=a;

			// default location and target
			
			if(!("change"==a||"remove"==a||"start_add"==a||"add"==a||"add-related"==a)){
				f.target="_self";
				if(_myshop_popup){
					try{_myshop_popup.close()}catch(e){}
					_myshop_popup=null;
				}
			}
				
			
			if("orderdirect"==a){
				if(_quantity!=null)id=_quantity;
				
				if(id){
					if(isNaN(id))id=id.value;
					_location+="&quantity="+encodeURIComponent(id);
					id=""; 
				}
				f.action=_location;
				f.method="post";
			}
			else if("favorite-add"==a||"favorite-remove"==a){
				if(f["id"])f["id"].value=id;
				saveScrollPos(f);
				f.method="post";
				
			}
			else if("change_update"==a||"change"==a||"remove"==a||"start-register"==a||"start_add"==a||"add"==a||"add-related"==a||"add-related-basket"==a){
				var checkId=id;
				if("change_update"==a){
					if(f["id"])f["id"].value=id;
					if(f["product_id"])checkId=f["product_id"].value;
				}
				
				if(isValid(a,checkId)){
					if(_location)f.action=_location+((endsWith(_location,"?"))?"":"&")+"jid="+(new Date()).getTime();
					f.method="post";
					if("start_add"==a)f["a"].value="";
					multiPart=("add"==a&&hasOrderUploadFields());
					
				}else cont=clear();
				
			}
			else if("continue_shopping"==a){
				useLocation=true;
				if(_myshopRelease==3)f.method="post";
				else f.method="get";
				/* clear the catalog id the url should specify the catalog */
				var ctl=f["cid"];
				if(ctl)ctl.value="";
				f.action=_location;
				if(_target)f.target=_target;
			}
			else if("cancel"==a){
				cont=false;
				try{window.close()}catch(e){};
			}
			else if("change_update"==a){
				if(f["id"])f["id"].value=id;
			}
			else if("select_shipping"==a){
				f.action=f["this"].value;
				delay=false;
			}
			else if("selection"==a){
				f.method="post";
				if(f["id"]&&_caller)f["id"].value=decodeURIComponent(_caller.name);
				if(_myshop_part==5&&f["this"])f.action=f["this"].value;
				saveScrollPos(f);
			}
			else if("show_error"==a){
				cont=false;
				if(self.myshopShowError)myshopShowError();
			}
			else if("search"==a){
				// reset seach action
				if(f["p"])f["p"].value="0";
				if(f['myshp_input_search'])f["_globalsearch"].value=f["myshp_input_search"].value;
				f.method="post";
				thisUri=false;
				
				if(("1"==get("range","0"))){
					/* clear the action to keep the active menu selection */
					if(f["a"])f["a"].value="";
					selection=getSelection(MAX_SEARCH_FIELD);
				}
				else{
					if(f["this"])f.action=f["this"].value;
					selection=clearSelection(0);
				}
			}
			else if("globalsearch"==a){
				var search=_myshopEvent.events.MYSHOP_EVENT_GLOBALSEARCH;
				if(_myshop.exist(search))cont=_myshop.trigger(search);
				if(cont){
					if(f["p"])f["p"].value=0;
					f.method="post";
					thisUri=false;
					f.action=f["this"].value;
					if(id)f["_globalsearch"].value="";
					else if(f["myshp_search_field_globalsearch"])f["_globalsearch"].value=f["myshp_search_field_globalsearch"].value;
					clearSelection(id);
					selection=getSelection(MAX_SEARCH_FIELD);
				}
			}
			else if("prev"==a){
				var prev=_myshopEvent.events.MYSHOP_EVENT_PREVIOUS;
				if(_myshop.exist(prev))cont=_myshop.trigger(prev);
					
				if(cont){
					clear();
					if(_location)f.action=_location;
					f.method="post";
				}
			}
			else if("back"==a){
				var back=_myshopEvent.events.MYSHOP_EVENT_BACK;
				if(_myshop.exist(back))cont=_myshop.trigger(back);
				if(cont){
					f.method="post";
					if(_location)f.action=_location;
				}
			}
			else if("previous"==a){
				var prev=_myshopEvent.events.MYSHOP_EVENT_PREVIOUS;
				if(_myshop.exist(prev))cont=_myshop.trigger(prev);
					
				if(cont){
					if(f["p"])f["p"].value=get("p");
					f.method="post";
					if(_location)f.action=_location;
					selection=getSelection(MAX_SEARCH_FIELD);
				}
			}
			else if("goto"==a){
				if(_scrollPos)saveScrollPos(f);
				clear();
				thisUri=false;
				if(f["p"])f["p"].value=get("p");
				f.method="post";
				selection=getSelection(MAX_SEARCH_FIELD);
				if(_location)f.action=_location;
				
			}
			
			if("next"==a){
				if(self._myshop){
					if(_myshop.exist("lock_next")){
						_myshop.trigger("lock_next");
						cont=false;
					}
					else _myshop.register("lock_next", function(){alert("Processing, one moment please ...");return false});
				}
				if(cont){
					clear();	
					var next=_myshopEvent.events.MYSHOP_EVENT_NEXT;
					if(_myshop.exist(next))cont=_myshop.trigger(next);
						
					if(cont){
						if(f["p"])f["p"].value=get("p");
						
						f.method="post";
						if(_clearSelection)clearSelection(0);
						else selection=getSelection(MAX_SEARCH_FIELD);
						if(_location)f.action=_location;
						
						if(f["coupon_n"]&&f["coupon_n_current"]&&trim(f["coupon_n"].value)!=""&&f["coupon_n"].value!=f["coupon_n_current"].value){
							if(f["a"])f["a"].value="coupon_n";
							f.action=f["this"].value;
						}
						else{
							if(self._myshop)cont=_myshop.trigger("on_next_page");
						}
					}
				}
			}
			
			if(cont){
				
				if(id&&f["id"])f["id"].value=decodeURIComponent(id);
				if(next&&f["next"])f["next"].value=next;

				if(multiPart){
					f.encoding='multipart/form-data';
					f.action+=((endsWith(f.action,"?"))?"":"&")+(new Remote()).fields(f,"this","url_rpc").getQueryString();
					showMessage("  Loading documents, one moment please ...");
					//alert(f.action);
				}

				
				if(_myshop_popup){
					f.target=POPUP_NAME;
					_target=POPUP_NAME;
					try{_myshop_popup.focus()}catch(e){};
				}
				else if(_target)f.target=_target;
				else f.target="_self";
	
				var done=false;
				if(_hasQuery&&useLocation&&(!_target)){
					document.location=f.action;
					done=true;
				}
				else if(_hasQuery)f.method="post";
				
				if(selection!=""){
					if(thisUri)f.action="?"+selection;
					else{
						var start=f.action.indexOf("?");
						
						if(start!=-1){
							var qs=new QueryString("?"+selection),qsAction=new QueryString(f.action.substring(start));
							for(var n=0;n<qsAction.keys.length;n++){
								var key=qsAction.keys[n];
								if(!qs.exist(key))qs.set(key,qsAction.get(key));
							}
							var s=qs.getQueryString();
							if(endsWith(s,"&"))s=s.substring(0,s.length-1);
							f.action=f.action.substring(0,start+1)+encode(s,"%3A",":");
						}
						else f.action=f.action+"?"+selection;
						
					}
				}
				if(!done){
					if(delay)window.setTimeout("myshop().submitPage();",10);
					else f.submit();
				}
			}
			
			f.action=aa;
		}
		return false;
	};
	me.a=me.action;
	
	function endsWith(s,chr){
		return(s&&s!="")?s.lastIndexOf(chr)==(s.length-1):false;
	}
	
	function saveScrollPos(f){
		if(f&&f["xy"]){
			var xy="";
			try{
				if(document.all){
					if(document.documentElement)xy=document.documentElement.scrollLeft+';'+document.documentElement.scrollTop;
					else xy=document.body.scrollLeft+';'+document.body.scrollTop;
				}
				else xy=window.pageXOffset+';'+(window.pageYOffset);
			}
			catch(e){};
			f["xy"].value=xy;
		}
	}
	
	function clear(){
		if(_caller&&_caller.href)_caller.href="javascript:void(0);";
		
		return false; 
	}
	
	me.open=function(){
		clear();
		window.open(_location,'_self');
		return false;
	};
	
	me.submitPage=function(action,method){
		_leave=true;
		var f=getData();
		if(f){
			if(trim(action)!='')f.action=action;
			if(method){
				method=trim(method).toLowerCase();
				if(method=="get")f.method="get";
				else if(method=="post")f.method="post";
			}
			f.submit();
		}
	};
	
	me.r=function(v){
		_myshopRelease=v;
		return me;
	};
	
	me.showExtraImage=function(el,i,count){
		var e=getElementOnId("myshp_info_image_large_"+i),n;
		if(e){
			e.style.display="";
			for(n=count;n>0;n--){
				if(n!=i){
					e=getElementOnId("myshp_info_image_large_"+n);
					if(e)e.style.display="none";
				}
			}
			e=getElementOnId("myshp_info_image_large");
			if(e)e.style.display="none";
		}
		return false;
	};
	
	me.init=function(part,scroll){
		_myshop_part=part;
		var f=getData(),v;
		if(f){
			try{
				var i=0,l=f.length;
				for(;i<l;i++){
					var type=""+f[i].type;
					if(type.toLowerCase()=="textarea"){
						var s=""+f[i].value;
						s=trim(s);
						if(s.charAt(0)<32&&s.length<2)s="";
						f[i].value=s;
					}
				}
			}
			catch(e){}
		}
		if(self.myshopDynamicSizing)myshopDynamicSizing(part);
		if(scroll)me.scroll();
		var c=getElementOnId("myshp_basket_value_count_id");
		if(c){
			try{
				var wod=window.opener.document,cc;
				if(wod){
					cc=wod.getElementById("basket_value_count");
					if(cc)cc.innerHTML=c.innerHTML;
				}
			}catch(e){};
		}
		
		if(part==1){
			_myshopJq=(window.jQuery)?window.jQuery:null;
			if(_myshopJq){
				_myshopJq(function(){
					var n,list=_myshopJq('a[class^=myshp_zoom]');
					if(list)for(n=list.length-1;n>=0;n--)_myshopJq(list[n]).jqzoom(((self.jqZoomOptions)?jqZoomOptions:{zoomType:'custom',zoomTypeWidth:90,zoomTypeHeight:90,zoomWidth:350,zoomHeight:350,title:false}));
				});
				_myshopJq(function(){
					var n,list=_myshopJq('a[class^=myshp_link]');
					if(list)for(n=list.length-1;n>=0;n--)_myshopJq(list[n]).lightBox(((self.jqLightBoxOptions)?jqLightBoxOptions:null));
				});
			}
		}
		return me;
	};
	
	me.trigger=function(id){
		clear();
		if(!_myshopJq)_myshopJq=(window.jQuery)?window.jQuery:null;
		if(id&&_myshopJq){
			var item=getElementOnId(id);
			if(item)_myshopJq(item).trigger('click');
		}
		return me;
	}
	
	
	me.scroll=function(){
		var f=getData('myshp_form_sitemap');
		
		if(f&&f['xy']){
			var l=f['xy'].value.split(';');
			if(l.length>1){
				addLoadEvent( function(){
					var f=getData('myshp_form_sitemap'),l=f['xy'].value.split(';');
					if(l.length>1)window.scrollTo(l[0],l[1])
					f['xy'].value="";
				});
			}
		}
		return me;
	};
	
	
	function addLoadEvent(func){
	  _onload=window.onload;
	  if(typeof window.onload!='function')window.onload=func;
	  else window.onload=function(){
		  if(_onload)_onload();
		  func();
	  };
	}
	
	
	me.popup=function(l,w,h){
		_location=l;
		var r=(isValid(get("a"),get('id')))?me:new MyShopVoid();
		if(r.valid){
			if(_myshop_popup)try{
				_myshop_popup.close();
				_myshop_popup=null;
			}catch(e){};
			
			if(w)_width=w;
			if(h)_height=h;
				
			var settings="location=0,directories=0,toolbar=no,resizable=no,status=no,scrollbars=1,menubar=no,width=";
			settings+=_width+",height="+_height+",left="+((screen.width-_width)*0.5)+",top="+((screen.height-_height)*0.4);
			_myshop_popup=window.open("/views/clear.html",POPUP_NAME,settings);
		}
		return r;
	};

	var _list=[];
	me.set=function(n,v){
		if(f&&f[n])f[n].value=v;
		_list[n]=v;
		return me;
	};
	me.s=function(n,v){
		var f=getData();
		var argl=me.s.arguments;
		if(argl){
			l=argl.length;
			if(l>2)for(i=0;i<l;i+=2)try{
				me.set(argl[i],argl[i+1]);
			}catch(e){}
			else me.set(n,v);
		}else me.set(n,v);
		return me;
	};
	
	function get(n,def){
		var r=_list[n];
		return(r)?r:def;
	}

	me.duplicate=function(formName,from,to){
		var f=getData(),v=me.get(from,formName);
		if(f&&f[to])f[to].value=v;
		return me;
	};

	me.get=function(n,formName){
		var f=(formName)?document.forms[formName]:getData(),value="";
		if(f&&f[n])value=f[n].value;
		return value;
	};
	
	me.form=function(n){
		_formName=n;
		return me;
	};
	me.f=me.form;
	
	me.location=function(l,t){
		
		if((typeof l)=="object"&&l.href){
			l=l.href;
		}
		
		_hasQuery=false;
		if(l&&l!='?'){
			_location=l;
			_hasQuery=(l.indexOf('?')!=-1);
		}
		else _location=null;
		
		
		if(trim(t)!="")_target=t;
		
		if(_myshop_popup)try{_myshop_popup.close()}catch(e){};
		_myshop_popup=null;
		
		return me;
	};
	me.l=me.location;
	
	me.confirm=function(id){
		var c=getElementOnId(id),msg;
		return confirm((c)?MyShopRemoveHTMLTags(c.innerHTML):id)?me:new MyShopVoid();
	};
	
	function getAttr(c,n){
		var v="";
		try{v=c.getAttribute(n)}
		catch(e){}
		return v
	}
	
	me.oke=false;
	
	function callbackValidate(doc){
		var valid=true;
		if(doc){
			var i=0,pairs=doc.getElementsByTagName('pair');
			if(pairs){
				for(;i<pairs.length;i++){
					alert(pairs[i].firstChild.nodeValue);
					var n=getAttr(pairs[i],"key");
					if(n)window.setTimeout("myshop().focus('"+n+"');",10);
					valid=false;
				}
			}
		}
		me.oke=valid;
		return valid;
	}
	
	
	me.validate=function(product,quantity){
		if(quantity){
			_quantity=(isNaN(quantity))?quantity.value:quantity;
			var f=getData();
			if(f)f["id"].value=_quantity;
		}
		me.oke=true;
		return (new Remote(false).request("validate",callbackValidate,"product",decodeURIComponent(product)))?me:new MyShopVoid();
	};

	me.order=function(product,quantity){
		var f=getData();
		if(f)f["id"].value=product;
		me.oke=true;
		return (new Remote(false).request("order",callbackValidate,"quantity",decodeURIComponent(quantity)))?me:new MyShopVoid();
	};

	
	me.load=function(lib,callback){
		var headId=document.getElementsByTagName("head")[0],loaded=false;
		if(headId){
			var newScript=document.createElement('script');
			newScript.type='text/javascript';
			newScript.onload=callback;
			newScript.src=lib;
			headId.appendChild(newScript);
			loaded=true;
		}
		return loaded;
	};
	
	me.keypress=function(e,action,bubble,a,id,next){
		if(!e)e=window.event;
		if(!bubble)bubble=false;
		if(e.keyCode==13&&action){
			try{action(a,id,next)}
			catch(e){};
		}
		return(bubble||e.keyCode!=13);
	}
	
	me.checked=function(n,state){
		var c=getElementOnId(n);
		if(c)c.checked=state;
		return me
	};

	
	/* remote interface */
	
	function QueryString(s){
		var me=this,_p=[],_n=[];
		me.set=function(k,v){
			var b=false,l=_n.length,i=0;
			for(;i<l;i++)if(_n[i]==k){
				b=true;
				break;
			}
			if(!b)_n[l]=k;
			_p[k]=v
		};
		me.get=function(k){return(_p[k]==null)?"":_p[k]};
		me.exist=function(k){return _p[k]!=null};
		me.getQueryString=function(){
			var s="",i=0;
			for(;i<_n.length;i++)s+=encodeURIComponent(_n[i])+"="+encodeURIComponent(_p[_n[i]])+"&";
			return s;
		};
		if(s!=null&&s!=""){
			var list=s.substr(1).split("&"),l=list.length,i=0;
			for(;i<l;i++){
				var v=list[i].split("=");
				if(v.length>1)me.set(decodeURIComponent(v[0]),decodeURIComponent(v[1]));
			}
		}
		me.keys=_n;
	}

	function Remote(async){
		if(async==null)async=true;
		var me=this,_req=null,_callback=null;
		function val(f,i){
			var v=f[i].value;
			if(v!=null&&v!="")v=v.replace("+","%2b");
			return v
		}
		me.fields=function(f){
			var q=new QueryString(),argl=me.fields.arguments;
			if(f){
				var exclude=[];
				if(argl){
					l=argl.length;
					for(i=1;i<l;i++)exclude[argl[i]]=1;
				}
				for(var i=f.length-1;i>=0;i--){
					var n=f[i].name;
					if(!exclude[n])q.set(n,val(f,i));
				}
			}
			return q;
		}
		
		me.request=function(type,cb){
			var f=getData(),i=0,l,argl=me.request.arguments,activex=null,q=new QueryString(),result=false;
			if(cb&&f){
				l=f.length;
				for(;i<l;i++)q.set(f[i].name,val(f,i));
				l=argl.length;
				for(i=2;i<l;i+=2)q.set(argl[i],argl[i+1]);
				q.set('type',type);
				qs=q.getQueryString();
				_callback=cb;
				if(window.XMLHttpRequest)_req=new XMLHttpRequest();
			    else if(window.ActiveXObject){
			        activex="Microsoft.XMLHTTP";
			        _req=new ActiveXObject("Msxml2.XMLHTTP");
			        if(!_req)_req=new ActiveXObject(activex);
			    }
				if(_req&&f["url_rpc"].value){
			        if(async)_req.onreadystatechange=processReqChange;
			        _req.open('POST',f["url_rpc"].value+"?jid="+(new Date()).getTime(),async);
		            _req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
					_req.send(qs);
					if(!async)result=processReqChange();
			    }else result=_callback(null);
			}
			return result;
		};

		function processReqChange(){
			var result=false;
	    	if(_req.readyState==4){
		        if(_req.status==200){
					var doc=_req.responseXML.documentElement;
					// alert(_req.responseText);
					if(!doc){
						var xmlTxt=_req.responseText;
						if(typeof DOMParser!="undefined")doc=(new DOMParser()).parseFromString(xmlTxt,"text/xml");
						else if(typeof ActiveXObject!="undefined"){
							doc=new ActiveXObject("Microsoft.XMLDOM");
							if(doc){
								doc.async=false;
								doc.loadXML(xmlTxt);
							}
						}
						if(doc)doc=doc.documentElement;
					}
					if(doc)result=_callback(doc);
				}else result=_callback(null);
	        }
	    	return result;
	    }
	}
	
}
function MyShopVoid(){
	var me=this;
	me.version=3;
	me.valid=false;
	
	me.oke=false;
	
	function myself(){return me}
	function clear(){
		if(_caller&&_caller.href)_caller.href="javascript:void(0);"
		return false
	}

	me.action=clear;
	me.a=clear;
	me.open=clear;
	me.trigger=clear;
	
	var _caller=null;
	me.caller=function(caller){
		_caller=caller;
		return me
	};
	me.c=me.caller;
	me.keypress=function(e){
		if(!e)e=window.event;
		return(e.keyCode!=13)
	};
	me.reload=function(){};
	me.submitPage=function(){};
	
	me.location=myself;
	me.l=myself;
	me.popup=myself;
	me.confirm=myself;
	me.set=myself;
	me.duplicate=myself;
	me.validate=myself;
	me.form=myself;
	me.f=myself;
	me.checked=myself;
	me.get=myself;
	me.scroll=myself;
	me.init=myself;
	me.item=myself;
	me.sp=myself;
	me.ssp=myself;
	me.cs=myself;
	me.r=myself;

}

function myshop(block){
	var blocked=false;
	if(block==null)block="yes";
	
	if(block=="yes"){
		var now=new Date().getTime();
		blocked=true
		if(_myshop_event_block==-1){
			blocked=false;
			_myshop_event_block=now;
		}
		else if((Math.abs(now-_myshop_event_block))>500){
			_myshop_event_block=-1;
			blocked=false;
		}
	}
	return(blocked)?new MyShopVoid():new MyShop();
}











