		google.load('search','1'); 
	function init(qq)
	{ 
	 var g=google.search; 
	 var s=new g.WebSearch; 
	 s.setResultSetSize(g.Search.LARGE_RESULTSET); 
	 s.setSearchCompleteCallback(s,parseResults,[]); 
	 s.execute(qq); 
	} 
	
	function initimage(qq)
	{ 
	 var g=google.search; 
	 var s=new g.ImageSearch; 
	 s.setResultSetSize(g.Search.LARGE_RESULTSET); 
	 s.setSearchCompleteCallback(s,parseResultsimage,[]); 
	 s.execute(qq); 
	}
	
	function initvideo(qq)
	{ 
	 var g=google.search; 
	 var s=new g.VideoSearch; 
	 s.setResultSetSize(g.Search.LARGE_RESULTSET); 
	 s.setSearchCompleteCallback(s,parseResultsvideo,[]); 
	 s.execute(qq); 
	} 

	function initblog(qq)
	{ 
	 var g=google.search; 
	 var s=new g.BlogSearch; 
	 s.setResultSetSize(g.Search.LARGE_RESULTSET); 
	 s.setSearchCompleteCallback(s,parseResultsBlog,[]); 
	 s.execute(qq); 
	} 
	
	function initnews(qq)
	{ 
	 var g=google.search; 
	 var s=new g.NewsSearch; 
	 s.setResultSetSize(g.Search.LARGE_RESULTSET); 
	 s.setSearchCompleteCallback(s,parseResultsNews,[]); 
	 s.execute(qq); 
	} 
	
	
	


	function parseResults()
	{ 
		var r=this.results; 
		var h=document.getElementById('searchcontrol'); 
		var finalresult = '';
		if(r.length<1)
		{
	    	document.getElementById('Panel1').innerHTML = '<br /><br /><h3>No results found</h3>';
		}
		else
		{ 
	         for(var a=0;a<r.length;a++)
	         { 
		        var b=r[a];  //alert(b.html);url
		        //alert(b.unescapedUrl );   //alert(b.url );   //alert(b.visibleUrl );   //alert(b.title );
		        //alert(b.titleNoFormatting ); //alert(b.content );    //alert(b.cacheUrl ); 
        		
        		
		        var ss0 = '<table><tr><td align="left" valign="top" > <a href="' + b.unescapedUrl + '" > <img  width="50"  height="50"  src="http://open.thumbshots.org/image.pxf?url='  + b.unescapedUrl +  ' border="0" onload="if (this.width>50) this.border=1; " > </a> </td><td>';
		        var ss1 = '<table class="SearchResultsTable" ><tr><td class="SearchResultsHeader" >';
		        var ss2 = '<a href="' + b.unescapedUrl + '" >' + b.title +'</a></td></tr><tr>';
		        var ss3 = '<td  class="SearchResultsText" >' + b.content + '</td></tr></table>';
		        var ss4 = '</td></tr></table>';
        		
		        //finalresult = finalresult + ss1 + ss2 + ss3;
		        finalresult = finalresult + ss0 + ss1 + ss2 + ss3 + ss4; 
        	  
	         } 
	            document.getElementById('Panel1').innerHTML = finalresult;
	    }
	} 
	
	
	function parseResultsimage()
	{ 
		var r=this.results; 
		var h=document.getElementById('searchcontrol'); 
		var finalresult = '';
		var counter = 0;
		
		finalresult = '<table><tr>';
	 for(var a=0;a<r.length;a++)
	 { 
		if(counter<4)finalresult = finalresult  + '<td>';
		else finalresult = finalresult  + '</tr><tr><td>';        
		
		
		var b=r[a];  //alert(b.html);url
		
		var ss0 = '<div><table border=1> <tr><td align=left  width=100 ><a href="' + b.originalContextUrl  + '" > ' + b.titleNoFormatting  + '</a></td></tr>';
		var ss1 = '<tr><td align=left  width=100 ><a href="' + b.unescapedUrl + '" ><img width='+ b.tbWidth + 'height=' + b.tbHeight + ' src="' + b.tbUrl  + '" /></a></td></tr></table></div>' ; 
	
		
		finalresult = finalresult + ss0 + ss1 ;
		
		
		if(counter<4) finalresult = finalresult  + '</td>';
		else {finalresult = finalresult  + '</td>'; counter=0;}
		counter = counter+1;
	  
	 } 
	 document.getElementById('Panel1').innerHTML = finalresult;
	 
	  
	} 
	
	
	
	function parseResultsvideo()
	{ 
		var r=this.results; 
		var h=document.getElementById('searchcontrol'); 
		var finalresult = '';
		var counter = 0;
	 finalresult = '<table><tr>';
	 for(var a=0;a<r.length;a++)
	 { 
		if(counter<3)finalresult = finalresult  + '<td>';
		else finalresult = finalresult  + '</tr><tr><td>';        
		
		
		var b=r[a];  //alert(b.html);url
		
		var ss0 = '<div><table border=1> <tr><td align=center  ><a href="' + b.url   + '" > ' + b.titleNoFormatting   + '</a></td></tr>';
		var ss1 = '<tr><td align=center  ><a href="' + b.playUrl  + '" ><img width='+ b.tbWidth + 'height=' + b.tbHeight + ' src="' + b.tbUrl  + '" /></a></td></tr>';
		var ss2 = '<tr><td align=center  >' + b.published + '</td></tr>';
		var ss3 = '<tr><td align=center   >' + b.publisher + '</td></tr>';
		var ss4 = '<tr><td align=center   >' + b.duration  + '</td></tr></table></div>' ; 
	
		
		finalresult = finalresult + ss0 + ss1 +ss2 + ss3+ ss4;
		
		
		if(counter<3) finalresult = finalresult  + '</td>';
		else {finalresult = finalresult  + '</td>'; counter=0;}
		counter = counter+1;
	  
	 } 
	 document.getElementById('Panel1').innerHTML = finalresult;
	 
	}
	
	
	function parseResultsBlog()
	{ 
 
	 
		
		var r=this.results; 
		var h=document.getElementById('searchcontrol'); 
		var finalresult = '';
	 for(var a=0;a<r.length;a++)
	 { 
		var b=r[a];  //alert(b.html);url
		//alert(b.unescapedUrl );   //alert(b.url );   //alert(b.visibleUrl );   //alert(b.title );
		//alert(b.titleNoFormatting ); //alert(b.content );    //alert(b.cacheUrl ); 
		
		
		var ss0 = '<table><tr><td align="left" valign="top" > <a href="' + b.postUrl + '" > <img  width="50"  height="50"  src="http://open.thumbshots.org/image.pxf?url='  + b.blogUrl +  ' border="0" onload="if (this.width>50) this.border=1; " > </a> </td><td>';
		var ss1 = '<table class="SearchResultsTable" ><tr><td class="SearchResultsHeader" >';
		var ss2 = '<a href="' + b.postUrl + '" >' + b.title +'</a></td></tr><tr>';
		var ss3 = '<td  class="SearchResultsText" >' + b.content + '--' + b.author + '--' + b.publishedDate  + '</td></tr><tr></table>';
		var ss4 = '</td></tr></table>';
		
		//finalresult = finalresult + ss1 + ss2 + ss3;
		finalresult = finalresult + ss0 + ss1 + ss2 + ss3 + ss4 ;
	  
	 } 
	 document.getElementById('Panel1').innerHTML = finalresult;

	 
	}
	
	
	
	function parseResultsNews()
	{ 
 
	 
		
		var r=this.results; 
		var h=document.getElementById('searchcontrol'); 
		var finalresult = '';
	 for(var a=0;a<r.length;a++)
	 { 
		var b=r[a];  //alert(b.html);url
 	
		
		/*
.title  Supplies the title of the news story returned as a search result 
.titleNoFormatting  Supplies the title, but unlike .title, this property is stripped of html markup (e.g., <b>, <i>, etc.) 
.unescapedUrl  Supplies the raw URL of the result 
.url  Supplies an escaped version of the above URL 
.clusterUrl  When a news result has a set of related stories, this URL is available and non-null. In this situation, the URL points to a landing page that points to all of the related stories. 
.content  Supplies a snippet of content from the news story associated with this search result. 
.publisher  Supplies the name of the publisher of the news story. 
.location  Contains the location of the news story. This is a list of locations in most specific to least specific order where the components are seperated by ",". Note, there may only be one element in the list... A typical value for this property is "Edinburgh,Scotland,UK" or possibly "USA". 
.publishedDate */

		var ss0 = '<table><tr><td align="left" valign="top" > <a href="' + b.unescapedUrl + '" > <img  width="50"  height="50"  src="http://open.thumbshots.org/image.pxf?url=' + b.url + ' border="0" onload="if (this.width>50) this.border=1; " > </a> </td><td>';
		var ss1 = '<table class="SearchResultsTable" ><tr><td class="SearchResultsHeader" >';
		var ss2 = '<a href="' + b.unescapedUrl + '" >' + b.title + '</a></td></tr><tr>';
		var ss3 = '<td  class="SearchResultsText" >' + b.content + '--' + b.publisher + '--' + b.location + '--' + b.publishedDate  + '</td></tr><tr></table>';
		var ss4 = '</td></tr></table>';
		
		//finalresult = finalresult + ss1 + ss2 + ss3;
		finalresult = finalresult + ss0 + ss1 + ss2 + ss3 + ss4 ;
	  
	 } 
	 document.getElementById('Panel1').innerHTML = finalresult;

	 
	}
	
	
function pagestarted() 
{
    document.form1.TypePad.focus();
    var targetElement = document.getElementById("TypePad");
     
    if(targetElement.value.length > 0)
    {
        if(document.getElementById("chkGoogle").checked)
        {
            if(document.getElementById("radsearchWeb").checked)
            {
                init(targetElement.value);
            }
            else if(document.getElementById("radsearchImages").checked)
            {
                initimage(targetElement.value);
            }
            else if(document.getElementById("radsearchVideo").checked)
            {
                initvideo(targetElement.value);
            }
            else if(document.getElementById("radsearchBlogs").checked)
            {
                initblog(targetElement.value);
            }
            else if(document.getElementById("radsearchNews").checked)
            {
                initnews(targetElement.value);
            } 
        
        }
    }
    
}

function watchchanges()
{
    var bt = document.getElementById('btnSearch');
    var targetElement = document.getElementById('TypePad');
    if (bt)
    {		    
        if(targetElement.value.length > 0)
        {
	        bt.click(); 
        }
    }
}
