

function simpleConnect(source,event,func){	
	if(source[event]==null){
		source[event]=func;	
	}else{
		var old=source[event];		
		source[event]=function(e){old(e);return func(e);};		
	}
}

if(window['console']==null){
	window['console']={debug:function(){}};
}

function G_includeCss(fileName){
	  var fileref=document.createElement("link");
	  fileref.setAttribute("rel", "stylesheet");
	  fileref.setAttribute("type", "text/css");
	  fileref.setAttribute("href", fileName);
	  var body=getBody();
	  body.appendChild(fileref);	  
}
function callbackslot4001(html){
	var ids="slot4001";	
	document.getElementById(ids).innerHTML=html;
}
function G_includeScript(src,onload){
	var script = document.createElement('script');
    script.src = src;   
    script.type = 'text/javascript'; 
    if(onload)
    	script.onload=onload;
    document.getElementsByTagName("body")[0].appendChild(script);
}
function G_includeCss(fileName,onload){
	  var fileref=document.createElement("link");
	  fileref.setAttribute("rel", "stylesheet");
	  fileref.setAttribute("type", "text/css");
	  fileref.setAttribute("href", fileName);
	  if(onload)
		  fileref.onload=onload;
	  document.getElementsByTagName("head")[0].appendChild(fileref);
}

function G_popupStr(code){
	if(!TINY)
		alert(code);
	TINY.box.show(code,0,0,0,1);
}
function G_popupDiv(div){	
	popupStr(ed(div).innerHTML);
}

function G_popupInfo(){
	G_includeCss("http://www.shoppytab.com/commons/css/tinybox.css");
	G_includeScript("http://www.shoppytab.com/commons/js/tinybox.js",function(){		
			G_open();
	});
}

function G_open(){
	var str="<iframe width='500' height='650' scrolling='no' src='http://www.shoppytab.com/widget-presentation' frameborder='0'></iframe>";
	G_popupStr(str);
}

function G_isIE(){
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);
	if(browser.indexOf("Explorer")>0)
		return true;
	return false;
}

var G_loadEngine_loaded=false;
function G_loadEngine(){
	if(G_loadEngine_loaded)
		return;	
	G_includeScript("http://localhost/Adinlive/jsengine/engine.jsp");
	G_includeScript("http://www.shoppytab.com/commons/js/utils.js");
	G_includeScript("http://www.shoppytab.com/commons/js/json.js");
	G_loadEngine_loaded=true;
}
function G_setCat(resultBox,key,cat){
	G_change(key,30,1000,cat);
	ed(resultBox).style.display="none";
}

function G_search(ids){
	
	//G_loadEngine();
	var mer=ed(ids.idmerchant);
	var merchant="";
	if(mer!=null)
		merchant=mer.value;
		
	var category=ed(ids.idcategory).value;
	var price=ed(ids.idprice).value;
	eval("price="+price);
	var min=price.min;
	var max=price.max;
	var brand=ed(ids.idbrand).value;
	var search="";
	if(merchant.length>0)
		search+=merchant+"+";
	if(brand.length>0)
		search+=brand;
	G_change(search,min,max,category,'kelkoo');
}
function G_searchCategory(event,input,resultBox){
	//G_loadEngine();
	var k=getKeyCode(event);
	if(k!=13)
		return;
	var keyword=input.value;
	ed(resultBox).innerHTML="";
	ed(resultBox).style.display="none";
	getCategories(keyword,function(categories){		
		var key=removequote(keyword);
		var html="<ul>";
		for(key in categories){
			var cat=categories[key];
			html+="<li>";
			html+="<a href=\"javascript:G_setCat('"+resultBox+"','"+key+"',"+cat.id+")\">"+cat.name+"</a>";
			html+="</li>";
		}
		html+="</ul>";
		ed(resultBox).style.display="inline";
		ed(resultBox).innerHTML=html;		
	});
	
}
function G_change(keyword,min,max,category,engine){
	console.debug(arguments);
	 var slot=document.getElementById("slot4001");
	 slot.innerHTML="<br><br><img src='http://www.shoppytab.com/static/images/wait.gif'></img>";
	 var script = "http://localhost/Adinlive/tojs.jsp?func=callbackslot4001&nb=12&page=getAd.jsp&id=4001&template=myshop&class=minishop&keyword="+keyword+"&category="+category+"&engine="+engine+"&min="+min+"&max="+max;
	 G_includeScript(script);
}

simpleConnect(window,"onload",function(){
	//G_loadEngine();
});

