﻿(function(){
    
	var e=null,
		a=window,
		k="sitesearch",
		r=	a.googleSearchResizeIframe 
			|| a.googleSearchPath 
			&& a.googleSearchPath=="/cse" 
			&& typeof a.googleSearchResizeIframe=="undefined",
		p,
		o,
		l;
	function s(c,b,i,m){
		var f={},
			g=c.split(i),
			d=0;
			for(;d<g.length;d++){
				var h=g[d],
					n=h.indexOf(b);
				if(n>0){
					var j=h.substring(0,n);
						j=m?j.toUpperCase():j.toLowerCase();
					var u=h.substring(n+1,h.length);
					f[j]=u}
			}
			return f
	}
	
	function v(){
		var c=document.location.search;
		
		if(c.length<1)
			return"";
		
		/*In questo modo tutta questa roba non deve essere in URL*/
		c = c + "&cx=018349227309607587275:xhsakc0afpo&cof=FORID:9&ie=UTF-8&sa=Search";
		
		c=c.substring(1,c.length);
		var b=s(c,"=","&",false);
		if(a.googleSearchQueryString!="q"&&b[a.googleSearchQueryString]){
			b.q=b[a.googleSearchQueryString];
			delete b[a.googleSearchQueryString]
		}
		if(b.cof){
			var i=s(decodeURIComponent(b.cof),":",";",true),
				m=i.FORID;
			if(m)
				p=parseInt(m,10)
		}
		var f=document.getElementById(a.googleSearchFormName);
		if(f){
			if(f.q&&b.q&&(!b.ie||b.ie.toLowerCase()=="utf-8"))
				f.q.value=decodeURIComponent(b.q.replace(/\+/g," "));
			if(f[k]){
				var g=0;
				for(;g<f[k].length;g++)
					f[k][g].checked=b[k]==e&&f[k][g].value==""?true:f[k][g].value==b[k]?true:false}
		}
		var d="";
		for(var h in b)
			d+="&"+h+"="+b[h];
			return d.substring(1,d.length)
	}
	
	function q(c,b){
	    
		return b?"&"+c+"="+encodeURIComponent(b):""
	}
	
	function t(c,b){
		return c?Math.max(c,b):b
	}
	
	function w(){
		var c="http://";
		c+=a.googleSearchDomain?a.googleSearchDomain:"www.google.com";
		c+=a.googleSearchPath?a.googleSearchPath:"/custom";
		c+="?";
		if(a.googleSearchQueryString)
			a.googleSearchQueryString=a.googleSearchQueryString.toLowerCase();
			
		//Qui chiama la funzione v
		c+=v();
		c+=q("ad","w"+o);c+=q("num",l);
		c+=q("adtest",a.googleAdtest);
		
		if(r){
			var b=a.location.href,
				i=b.indexOf("#");
			if(i!=-1)
				b=b.substring(0,i);
			c+=q("rurl",b)
		}
		return c
	}
	
	function x(){
		(o=a.googleSearchNumAds)||(o=9);
		l=(l=a.googleNumSearchResults)?Math.min(l,20):10;
		var c={};
		c[9]=795;
		c[10]=795;
		c[11]=500;
		var b={};
		b[9]=300+90*l;
		b[10]=300+50*Math.min(o,4)+90*l;
		b[11]=300+50*o+90*l;
		//Chiama la W
		var i=w();
		if(!a.googleSearchFrameborder)
		    a.googleSearchFrameborder="0";
		
		var m=document.getElementById("cse-search-results");
		
		if(m&&c[p]){
		    
			var f=t(a.googleSearchFrameWidth,c[p]),
				g=t(a.googleSearchFrameHeight,b[p]),
				d=document.createElement("iframe"),
				h={name:"googleSearchFrame",
					src:i,
					frameBorder:a.googleSearchFrameborder,
						width:f,
						height:g,
						marginWidth:"0",
						marginHeight:"0",
						hspace:"0",
						vspace:"0",
						allowTransparency:"true",
						scrolling:"no"
					};
				for(var n in h)
					d.setAttribute(n,h[n]);
				m.appendChild(d);
				d.attachEvent?d.attachEvent("onload",function(){window.scrollTo(0,0)}):d.addEventListener("load",function(){window.scrollTo(0,0)},false);
				r&&a.setInterval(
					function(){
						if(a.location.hash&&a.location.hash!="#"){
							var j=a.location.hash.substring(1)+"px";
							if(d.height!=j&& j!="0px")
								d.height=j
						}
					},10)
		}
		a.googleSearchIframeName=e;
		a.googleSearchFormName=e;
		a.googleSearchResizeIframe=e;
		a.googleSearchQueryString=e;
		a.googleSearchDomain=e;
		a.googleSearchPath=e;
		a.googleSearchFrameborder=e;
		a.googleSearchFrameWidth=e;
		a.googleSearchFrameHeight=e;
		a.googleSearchNumAds=e;
		a.googleNumSearchResults=e;
		a.googleAdtest=e
	}
	x()
})();