function EventManager(){window.onload=null;window.onunload=null;this.alterEventObject=function(e){};var registry={};var targetIdCount=0;function registryKey(id,type,fn){return id+'#'+type+'#'+fn;}
function isInRegistry(key){return registry[key]!=null;}
function invoke(key,evt){if(!isInRegistry(key))return null;if(window.eventManager){var _evt=window.eventManager.alterEventObject(evt);if(typeof(_evt)=='object')evt=_evt;var handler=registry[key];var scope=handler.scope;scope.__EventManager_Listener__=handler.listener;scope.__EventManager_Listener__(evt);scope.__EventManager_Listener__=null;return true;}else{return false;}}
function targetId(target){if(target==document)return"__EventManager_ID_document";if(target==window)return"__EventManager_ID_window";if(target+''==xmlhttp+'')return"__EventManager_ID_xmlhttp";try{var id=target.getAttribute('id')||target.uniqueID;if(id==null){id="__EventManager_ID_"+(targetIdCount++);target.setAttribute('id',id);}}catch(e){}
return id;}
this.isEventRegistered=function(target,type,listener){var key=registryKey(targetId(target),type,listener);return isInRegistry(key);}
this.addEvent=function(target,type,listener,scope,capture){var key,handler;key=registryKey(targetId(target),type,listener);scope=scope||target;if(isInRegistry(key))window.removeEvent(target,type,listener);handler={listener:listener,scope:scope,capture:capture,invoker:function(evt){invoke(key,evt);}};registry[key]=handler;if(target.addEventListener)target.addEventListener(type,handler.invoker,capture);else if(target.attachEvent)target.attachEvent('on'+type,handler.invoker);else return false;if(typeof(window.addOnUnload)=='function')window.addOnUnload(function(){window.removeEvent(target,type,listener);target=type=listener=null;});scope=null;return true;}
this.removeEvent=function(target,type,listener){var key,invoker,capture;key=registryKey(targetId(target),type,listener);if(!isInRegistry(key))return false;invoker=registry[key].invoker;capture=registry[key].capture;registry[key]=null;if(target.removeEventListener)target.removeEventListener(type,invoker,capture);else if(target.detachEvent)target.detachEvent("on"+type,invoker);else return false;return true;}
this.addOnResize=function(func){if(typeof(window.onresize)!='function')window.onresize=func;else{var oldResize=window.onresize;window.onresize=function(){oldResize();func();}}}
return this;}
EventManager.prototype=new Object;EventManager.prototype.constructor=EventManager;EventManager.superclass=Object.prototype;window.eventManager=new EventManager();window.EventManager=window.eventManager;function EventManager_CleanWindow(){window.onafterprint=null;window.onbeforeprint=null;window.onbeforeunload=null;window.onblur=null;window.ondragdrop=null;window.onerror=null;window.onfocus=null;window.onhelp=null;window.onload=null;window.onmove=null;window.onresize=null;window.onscroll=null;window.onunload=null;}
EventManager.instance=null;EventManager.getInstance=function(){if(!EventManager.instance)EventManager.instance=new EventManager();return EventManager.instance;}
window.addEvent=function(target,type,listener,scope,capture){if(window.eventManager)window.eventManager.addEvent(target,type,listener,scope,capture);else return false;}
window.removeEvent=function(target,type,listener){if(window.eventManager)window.eventManager.removeEvent(target,type,listener);else return false;}
window.isEventRegistered=function(target,type,listener){if(window.eventManager)return window.eventManager.isEventRegistered(target,type,listener);else return false;}
window.loadQueue=new Array();window.addOnLoad=window.addOnload=function Window_AddOnLoad(func){if(!(window.onload instanceof Function)){if(window.onload){var oldOnload=window.onload;window.loadQueue.push(function(){oldOnload});}
window.onload=Window_OnLoadQueue;}else if(window.onload!==Window_OnLoadQueue){loadQueue.push(window.onload);window.onload=Window_OnLoadQueue;}
var sz=window.loadQueue.length;window.loadQueue[sz]=func;}
function Window_OnLoadQueue(){for(var i=0;i<window.loadQueue.length;i++){var loadFunc=window.loadQueue[i];loadFunc();}}
window.onload=Window_OnLoadQueue;window.unloadQueue=new Array();function Window_OnUnloadQueue(){for(var i=0;i<window.unloadQueue.length;i++){var unloadFunc=window.unloadQueue[i];unloadFunc();}
if(typeof(GUnload)=='function')GUnload();window.onload=null;window.onunload=null;window.onresize=null;window.eventManager=null;window.EventManager=null;}
window.addOnunload=window.addOnUnLoad=window.addOnUnload=function Window_AddOnUnload(func){if(!(window.onunload instanceof Function)){if(window.onunload){var oldUnload=window.onunload;window.unloadQueue.push(function(){oldUnload});}
window.onunload=Window_OnUnloadQueue;}else if(window.onunload!==Window_OnUnloadQueue){window.unloadQueue.push(window.onunload);window.onunload=Window_OnUnloadQueue;}
window.unloadQueue.push(func);}
window.onunload=Window_OnUnloadQueue;window.addOnResize=function(func){if(window.eventManager)window.eventManager.addOnResize(func);else return false;}
if(typeof window.addOnUnload=='function')window.addOnUnload(EventManager_CleanWindow);var xmlhttp=null;try{xmlhttp=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){try{xmlhttp=new XMLHttpRequest();}catch(e){xmlhttp=null;}}}
var AJAX_REQUEST={DEBUG:false,DEFAULT_ASYNC:false,DEFAULT_METHOD:'POST',DEFAULT_URL:'rpcServer.php',MAX_REQUESTS:10,REQUEST_TIMEOUT:30000}
if(!window.ajax){window.ajax={NEXT_ID:0,COUNT:0,MAX_CONCURRENT:AJAX_REQUEST.MAX_REQUESTS};}
function AjaxRequest(method,url,async,requestTimeout,user,password){this.abort=function(){if(AJAX_REQUEST.DEBUG&&typeof(writeDebug)=='function')writeDebug('AjaxRequest.abort() called.');if(this.request&&this.busy){if(window.ajaxRequests&&window.ajaxTimers&&this.requestId>=0){if(AJAX_REQUEST.DEBUG&&typeof(writeDebug)=='function')writeDebug('abort(): clearing timeout: '+self.requestId+', timerId: '+window.ajaxTimers[self.requestId]);clearTimeout(window.ajaxTimers[this.requestId]);window.ajaxTimers[this.requestId]=null;window.ajaxRequests[this.requestId]=null;}
this.request.onreadystatechange=function(){};this.request.abort();this.request=null;this.busy=false;window.ajax.COUNT--;}}
this.send=function(){try{this.request=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{this.request=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){try{this.request=new XMLHttpRequest();}catch(e){this.request=null;}}}
if(this.request){var url=this.url;if(this.async&&this.callback){this.request.onreadystatechange=this.onStateChange;if(this.requestTimeout!=null&&this.timeout>0&&this.requestId==null){if(window.ajax.COUNT<window.ajax.MAX_CONCURRENT){this.requestId=window.ajax.NEXT_ID++;window.ajax.COUNT++;}else{alert('Too many concurrent ajax requests.');return false;}
if(AJAX_REQUEST.DEBUG&&typeof(writeDebug)=='function')writeDebug('XmlHttpRequest '+this.requestId+' setting timeout: '+this.requestTimeout);self.requestTimer=setTimeout(function(){self.abort();self.requestTimer=null;if(typeof(writeDebug)=='function')writeDebug('XmlHttpRequest '+self.requestId+' aborted.');},this.requestTimeout);}}
if(this.method=='POST'){this.request.open(this.method,this.url,this.async,this.user,this.password);this.request.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');this.busy=true;this.request.send(this.params.join('&'));}else{url=this.url+(this.params.length>0?'?'+this.params.join('&'):'');this.request.open(this.method,url,this.async,this.user,this.password);this.busy=true;this.request.send('');}
if(!this.async){this.busy=false;;return this.request.responseXML;}}}
this.setParameter=function(name,value){if(AJAX_REQUEST.DEBUG&&typeof(writeDebug)=='function')writeDebug('AjaxRequest.setParameter('+name+', '+value+') called.');this.params.push(name+'='+encodeURIComponent(value));}
this.setResponseType=function(ResponseType){this.ResponseType=(ResponseType=='html'?'html':'xml');}
this.setCallback=function(func){if(typeof(func)=='function')this.callback=func;else alert('Unable to set callback handler. Must be a function.');}
this.onStateChange=function(){if(self.request&&self.request.readyState&&self.request.readyState==4){if(self.requestTimer&&self.requestId){if(AJAX_REQUEST.DEBUG&&typeof(writeDebug)=='function')writeDebug('XmlHttpRequest '+this.requestId+' clearing timeout.');clearTimeout(self.requestTimer);self.requestTimer=null;self.requestId=null;}
self.busy=false;if(AJAX_REQUEST.DEBUG&&typeof(writeDebug)=='function')writeDebug('XmlHttpRequest.reponseText: '+self.request.responseText);if(self.ResponseType&&self.ResponseType=='html'){self.callback(self.request.responseText);}else{self.callback(self.request.responseXML);}}}
this.method=method||AJAX_REQUEST.DEFAULT_METHOD;this.url=url||AJAX_REQUEST.DEFAULT_URL;this.async=async||AJAX_REQUEST.DEFAULT_ASYNC;this.requestTimeout=requestTimeout||AJAX_REQUEST.REQUEST_TIMEOUT;this.user=user||null;this.password=password||null;this.callback=null;this.params=new Array;this.request=null;this.requestTimer=null;this.ResponseType='xml';var self=this;}
function submitSearchRequest(page_id,requestParams,vendorIds,st,sv){var keyword=document.getElementById('shopForInput').value;var ajax=new AjaxRequest('POST','/rpc_searchRequest.php',true,3000);ajax.setParameter('keyword',keyword);if(page_id){ajax.setParameter('page_id',page_id);}
if(requestParams){ajax.setParameter('requestParams',requestParams);}
if(vendorIds){ajax.setParameter('vendorIds',vendorIds);}
if(st){ajax.setParameter('st',st);}
if(sv){ajax.setParameter('sv',sv);}
var searchBar=document.getElementById('pgSiteSearch');if(searchBar&&searchBar.getElementsByTagName('select')[0]){var searchSelect=searchBar.getElementsByTagName('select')[0].value;ajax.setParameter('searchLocation',searchSelect);}
ajax.setCallback(getSearchAction);ajax.send();return false;}
function getSearchAction(xml){var search_action=xml.getElementsByTagName('search_action');var json=search_action[0].firstChild;var url=eval(json.firstChild.nodeValue);var a=document.createElement('a');if(!a.click){location.href=url;return url;}
else{a.setAttribute('href',url);a.style.display='none';document.body.appendChild(a);a.click();}}
