// JavaScript Document
		
		var aValue;
		var content;
		var pag ;

function get_query()
	{
		
		var querystring = String(location.search);
		aValue1 = querystring.substring(querystring.indexOf("t=") + 2,querystring.length);
   		aValue = aValue1.replace(/%20/g," ");
		if(aValue!=='')
		{
	 	 	document.getElementById("s_query").value= aValue;
	  		
			document.getElementById('main_widget').style.display='none';
			
			document.getElementById('result_main').style.display='';
			
			document.getElementById('loading_img').style.display='';
			
			webSearch.execute(aValue);
	  		imageSearch.execute(aValue);
			videoSearch.execute(aValue);
	  		newsSearch.execute(aValue);
	  		blogSearch.execute(aValue);
			wikiSearch.execute(aValue);
			answerSearch.execute(aValue);
			get_value();
		}
		else
		{
				document.getElementById('main_widget').style.display='';
		}
	
	}


function get_value()
	{
		aValue=document.getElementById('s_query').value;
	}


function execute_all()
	{
	      document.getElementById('main_widget').style.display='none';
		  document.getElementById('result_main').style.display='';
		  document.getElementById('pagination').style.display='BLOCK';
		  document.getElementById('loading_img').style.display='';
		  
		  obj_main.r.innerHTML = '';
		  obj_web.pingSearch();
		  obj_product.pingSearch();
	}


var obj_main=
			{
				
				init:function()
				
				{
					
					//Google initialization Here
					google.load('search', '1');
					searchControl = new GSearchControl();
	  				searchControl.setResultSetSize(google.search.Search.LARGE_RESULTSET);
	  				searchControl.setLinkTarget(google.search.Search.LINK_TARGET_BLANK ); 
		
					webSearch = new google.search.WebSearch();
					imageSearch = new google.search.ImageSearch();
					videoSearch = new google.search.VideoSearch();
					newsSearch =new google.search.NewsSearch();
					blogSearch = new google.search.BlogSearch();
					wikiSearch = new google.search.WebSearch();
					answerSearch = new google.search.WebSearch();
		
					wikiSearch.setQueryAddition("Wikipedia");
					//wikiSearch.setSiteRestriction('www.wikipedia.org');
					answerSearch.setQueryAddition("answer yahoo");
					
					searchControl.addSearcher(webSearch);
					searchControl.addSearcher(imageSearch);
					searchControl.addSearcher(videoSearch);
					searchControl.addSearcher(newsSearch);
					searchControl.addSearcher(blogSearch);
					searchControl.addSearcher(wikiSearch);
					searchControl.addSearcher(answerSearch);
					
					webSearch.setSearchCompleteCallback(this,execute_all,null);
					imageSearch.setSearchCompleteCallback(this,searchComplete_image,null);
					videoSearch.setSearchCompleteCallback(this,searchComplete_video,null);
					newsSearch.setSearchCompleteCallback(this,searchComplete_news,null);
					blogSearch.setSearchCompleteCallback(this,searchComplete_blog,null);
					wikiSearch.setSearchCompleteCallback(this,searchComplete_wiki,null);
					answerSearch.setSearchCompleteCallback(this,searchComplete_ans,null);
					
					
					var drawOptions = new GdrawOptions();
					drawOptions.setDrawMode(GSearchControl.DRAW_MODE_EXPAND);
					drawOptions.setInput(document.getElementById('s_query'));
					searchControl.draw(document.getElementById("result_blog"), drawOptions);
					document.getElementById('result_blog').innerHTML='';
					
					//get_query();
					
					//Getting the division elements
    				obj_main.s_query = document.getElementById('s_query');
    				obj_main.r = document.getElementById('result_web');
    								
					get_query();
					
					obj_main.page=0;
					pag = new YAHOO.widget.Paginator({ 
	    					rowsPerPage : 10, 
	    					totalRecords: 50, 
	    					containers  : 'pagination' 
						}); 
					pag.render();
					
					
					
				},
				handlePagination:function(state)
				{
					
					if (state.page==1)
						{
							obj_main.page=0;
						}
						else
						{
							obj_main.page = state.page*10+1;
						}
						pag.setState(state);
						obj_web.pingSearch();
				}
				
			}

var obj_keydown=
					
			{
					kd:function(e)
					{
										
					 	var s_query=obj_web.s_query;
						var key_code;
						// make it work on FF and IE
						if (!e) e = event;
						
						
						if(navigator.appName=='Netscape')
						{
						   if (!e)
						   e = document.event;
						   key_code=e.which;
						   
						}
						
						else
						key_code=e.keyCode;
						
						
						if (s_query == null)
							s_query = document.getElementById('s_query');
						
						if (key_code == 27)
						{
							
							obj_web.r.innerHTML = '';
							
							document.getElementById('main_widget').style.display='';
							
							document.getElementById('result_main').style.display='none';
							
							document.getElementById('pagination').style.display='none';
							
							obj_main.s_query.value='';
				
						}
						
						
						else if(key_code==34||key_code==33||key_code==38||key_code==40||key_code==9||key_code==16||key_code==17||key_code==18||key_code==20||key_code==9)
						{	
						   window.focus();
						}
						else
						{
						 s_query.focus();
						}
					
				}
			}


var obj_web = 
		{
			init : function()
			{
					obj_web.s_query = document.getElementById('s_query');
    				obj_web.r = document.getElementById('result_web');
					obj_web.uri="http://api.search.live.net/json.aspx?JsonType=callback&JsonCallback=obj_web.pongSearch&sources=web&web.Count=10";
					obj_web.AppId = "&Appid=C9A85B01B3E0DA0DB11CA3FEC849CFAE2C17725C";
			},
			
			pingSearch: function()
			{
				if (obj_web.s_query.value)
    				{
						//obj_web.s = document.getElementsByTagName('script')[4];
						obj_web.s = document.createElement('script');
						
						var search_query = "&query=" + document.getElementById("s_query").value;
						var fullUri = obj_web.uri + obj_web.AppId + search_query+ "&web.Offset="+obj_main.page;
						obj_web.s.type ='text/javascript';
						obj_web.s.charset ='utf-8';
						obj_web.s.setAttribute("src",fullUri);
						document.getElementsByTagName('head')[0].appendChild(obj_web.s);
						
					}
			
			},
			pongSearch : function(results)
  			{
					obj_main.r.innerHTML = '';
					page_id=1;
    				var contentlbl = document.createElement('div');
		  			contentlbl.innerHTML='Web Result By Bing';
		  			contentlbl.className="result";
										
					var contentimg=document.createElement('img');
		  			contentimg.align="right";
		  			contentimg.valign="middle";
		  			contentimg.src="./Style/images/logo_bing.png";
					
          			obj_main.r.appendChild(contentlbl);
					obj_main.r.appendChild(contentimg);
					
					
					
					var result = null;
					//var parent = document.getElementById('resultList');
					var parent =document.createElement('div');
					//parent.innerHTML='';
					var child = null;
					var displayUrl=null;
					var cache= null;
					
					if(results.SearchResponse.Web.Results)
					{
						for (var i = 0; i < results.SearchResponse.Web.Results.length; i++) 
						{
							result = results.SearchResponse.Web.Results[i];
							
							var child = document.createElement('a');
							var desc =document.createElement('div');
							var title=document.createElement('div');
							displayUrl = document.createElement('div');
							displayUrl.style.color="green";
							cache=document.createElement('a');
							
							child.href=result.Url;
							child.target="_blank";
							
							title.innerHTML=result.Title;
							desc.innerHTML=result.Description;
							displayUrl.innerHTML=result.DisplayUrl;
							cache.href=result.CacheUrl;
							cache.target="_blank";
							cache.innerHTML='Chached Page'
							cache.style.color="grey";
							child.appendChild(title);
							parent.appendChild(child);
							parent.appendChild(desc);
							parent.appendChild(displayUrl);
							parent.appendChild(cache);
							
							
						}
						var loading=document.getElementById('loading_img');
						loading.style.display='none';
						obj_main.r.appendChild(parent);
						pag.subscribe('changeRequest',obj_main.handlePagination);
						
					}
					  else
					{
						var loading=document.getElementById('loading_img');
						loading.style.display='none';
						var child=document.createElement('div');
						child.innerHTML='No standard web pages containing all your search terms were found.<br/>Suggestions:<ul><li>Make sure all words are spelled correctly.</li><li>Try different keywords.</li><li>Try more general keywords.</li><li>Try fewer keywords.</li></ul>';  
						obj_main.r.appendChild(child);
					  }
						
				}
					
				
		}
		
var obj_product =
		{
			
  				init : function()
  				{
    				obj_product.s_query = document.getElementById('s_query');
    				obj_product.r = document.getElementById('result_products');
    			},
  				pingSearch : function()
  				{
    				get_value();
					if (aValue)
    				{
      				
					obj_product.s = document.createElement('script');
      				obj_product.s.charset ='utf-8';
					obj_product.s.src ='http://shopping.yahooapis.com/ShoppingService/V3/productSearch?appid=3A5VaOnV34Hl0E_oUb5cTwaCmGds3hd491TqZvo3bqO_DJXnLyZBnFTuhWw_rZ6r1sKY&output=json&results=4&callback=obj_product.pongSearch&query='+aValue;
      				document.getElementsByTagName('head')[0].appendChild(obj_product.s);
					}
  				},
  				
				
				pongSearch : function(z)
  				{
    				obj_product.r.innerHTML = '';
					var table = document.createElement('table');
					var lblimage = document.createElement('div');
					lblimage.innerHTML='shopping';
		  			lblimage.className="result";
					obj_product.r.appendChild(lblimage);
					
					var j=0;		
					
					if(z.Products.Product)
					{
							for (var i = 1; i<z.Products.__ATTRIBUTES.totalResultsReturned ; i++)
									{
										
										var newImg=document.createElement('img');
										var a = document.createElement('a');
										var title = document.createElement('a');
										var h_w = document.createElement('div');
										
										if(i%4==0||j==0)
										{
											var myRow = table.insertRow(j);
											j++;
						
										}
										
										var myCell1 = myRow.insertCell(0);
										
										
										var table1 =document.createElement('table');
										var myRow1 = table1.insertRow(0);
										var myRow2 = table1.insertRow(1);
										
										myRow1.align="center";
										myRow2.align="center";
					
										var myCell11 = myRow1.insertCell(0);
										var myCell12 = myRow2.insertCell(0);
										
										if(z.Products.Product[i].__ATTRIBUTES.type=='Catalog')
										
										{
											a.href = z.Products.Product[i].Catalog.Url;
											a.target="_BLANK";
											
											if(z.Products.Product[i].Catalog.Thumbnail)
											{
												var img_src = z.Products.Product[i].Catalog.Thumbnail.Url;
											}
											else if(z.Products.Product[i].Catalog.ListImage)
											{
												var img_src = z.Products.Product[i].Catalog.ListImage.Url;
											}
											else if(z.Products.Product[i].Catalog.GridImage)
											{
												var img_src = z.Products.Product[i].Catalog.GridImage.Url;
											}
											newImg.src = img_src;
											newImg.height="89";
											newImg.width="86";
											newImg.className="Myimg";
											a.appendChild(newImg);
											
											h_w.innerHTML= "$"+z.Products.Product[i].Catalog.PriceFrom+" - $"+z.Products.Product[i].Catalog.PriceTo;
											
											var test =document.createElement('div');
											
											if(z.Products.Product[i].Catalog.Brand)
											test.innerHTML=z.Products.Product[i].Catalog.Brand;
											
											else
											test.innerHTML="Click Image";
											
											myCell11.appendChild(a);
											myCell12.appendChild(test);
											//myCell12.appendChild(title);
											myCell12.appendChild(h_w);
											
											myCell1.appendChild(table1);							
										}
										
										else if(z.Products.Product[i].__ATTRIBUTES.type=='Offer')
										
										{
											a.href = z.Products.Product[i].Offer.Url;
											a.target="_BLANK";
											
											if(z.Products.Product[i].Offer.Thumbnail)
											{
												var img_src = z.Products.Product[i].Offer.Thumbnail.Url;
											}
											
											else if(z.Products.Product[i].Offer.ListImage)
											{
												var img_src = z.Products.Product[i].Offer.ListImage.Url;
											}
											else if(z.Products.Product[i].Offer.GridImage)
											{
												var img_src = z.Products.Product[i].Offer.GridImage.Url;
											} 
											newImg.src = img_src;
											newImg.height="89";
											newImg.width="86";
											newImg.className="Myimg";
											a.appendChild(newImg);
											
											title.innerHTML=z.Products.Product[i].Offer.ProductName.substring(0,15);;
											h_w.innerHTML= "$"+z.Products.Product[i].Offer.Price;
											
											
											myCell11.appendChild(a);
											
											myCell12.appendChild(title);
											myCell12.appendChild(h_w);
											myCell12.align="center";
											myCell1.appendChild(table1);							
										}
								
								}
								
							}
						var see_more=document.createElement('a');
						see_more.innerHTML="See more";
						get_value();
						see_more.href='Yahoo/Products/default.html?t='+aValue;
						
						obj_product.r.appendChild(table);
						obj_product.r.appendChild(see_more);
						
						
					},
  
		};		
		
   	function searchComplete_wiki() 
    {
      // Check that we got results
      if (wikiSearch.results && wikiSearch.results.length > 0) 
      {
          // Grab our content div, clear it.
          var contentDiv = document.getElementById('result_wiki');
          contentDiv.innerHTML = '';
		  var contentlbl = document.createElement('div');
		  contentlbl.innerHTML='Wikipedia Result';
		  contentlbl.className="result";

		  contentDiv.appendChild(contentlbl);
    
          // Loop through our results, printing them to the page.
          var results = wikiSearch.results;
          for (var i = 0; i < 2; i++) 
		  {
          // For each result write it's title and image to the screen
          var result = results[i];
          var webContainer = document.createElement('div');
          var content = document.createElement('div');
		  var url = document.createElement('div');
		  url.style.color="green";
		  var url2 =document.createElement('div');
		  var a = document.createElement('a');
		  var br = document.createElement('br');
          
		  
		  content.innerHTML= result.content.substring(0,100);
		  url.innerHTML = result.visibleUrl;
          a.href = result.url;
		  a.target="_BLANK";
		  a.innerHTML=result.title;

		 
          webContainer.appendChild(a);
          webContainer.appendChild(content);    
		  webContainer.appendChild(url);
		  webContainer.appendChild(br);
		 
          contentDiv.appendChild(webContainer);
        }
    
        var more = document.createElement('a');
		more.innerHTML="See more.....";
		get_value();
		more.href="./Wiki/default.html?t="+aValue;
		contentDiv.appendChild(more);
		
      }
    }
	
	function searchComplete_ans() 
    {
      // Check that we got results
      if (answerSearch.results && answerSearch.results.length > 0) 
      {
          // Grab our content div, clear it.
          var contentDiv = document.getElementById('result_ans');
          contentDiv.innerHTML='';
		  var contentlbl = document.createElement('div');
		  contentlbl.innerHTML='Answer Results';
		  contentlbl.className="result";

		  
		  contentDiv.appendChild(contentlbl);
    
          // Loop through our results, printing them to the page.
          var results = answerSearch.results;
          for (var i = 0; i < 2; i++) 
		  {
          // For each result write it's title and image to the screen
          var result = results[i];
          var webContainer = document.createElement('div');
          var content = document.createElement('div');
		  var url = document.createElement('div');
		  url.style.color="green";
		  var url2 =document.createElement('div');
		  var a = document.createElement('a');
		  var br = document.createElement('br');
          
		  content.innerHTML= result.content.substring(0,100);
		  url.innerHTML = result.visibleUrl;
          a.href = result.url;
		  a.target="_BLANK";
		  a.innerHTML=result.title;

          // There is also a result.url property which has the escaped version
          webContainer.appendChild(a);
          webContainer.appendChild(content);    
		  webContainer.appendChild(url);
		  webContainer.appendChild(br);
		  
          // Put our title + image in the content
          contentDiv.appendChild(webContainer);
        }
         var more = document.createElement('a');
		 more.innerHTML="See more.....";
		 get_value();
		 more.href="./Yahoo/Answers/default.html?t="+aValue;
		 contentDiv.appendChild(more);
         // Now add the paging links so the user can see more results.
        // addPaginationLinks(webSearch);
      }
    }
	
	function searchComplete_image() 
    {
			  // Check that we got results
			  if (imageSearch.results && imageSearch.results.length > 0) 
			  {
				  // Grab our content div, clear it.
				  var contentDiv = document.getElementById('result_images');
				  contentDiv.innerHTML='';
				  var table = document.createElement('table');
				  var lblimage = document.createElement('div');
				  lblimage.innerHTML='Image Results';
				  lblimage.className="result";
				  contentDiv.appendChild(lblimage);
				  var more = document.createElement('a');
				  more.innerHTML="See more.....";
				  get_value();
				  more.href="Bing/Images/default.html?t="+aValue;
						  
				  // Loop through our results, printing them to the page.
				  var results = imageSearch.results;
				  var j=0;
				  for (var i = 0; i < 4; i++) 
				  {
						// For each result write it's title and image to the screen
						var result = results[i];
						var id = i+1;
						var newImg = document.createElement('img');
						var a = document.createElement('a');
						// There is also a result.url property which has the escaped version
				  
						if(i%2==0)
						{
							
							var myRow = table.insertRow(j);	
							j++;
							
						}
						
						var myCell1 = myRow.insertCell(0);
						newImg.src = result.tbUrl;
						newImg.height="80";
						newImg.width="80";
						newImg.className="Myimg";
						a.target="_BLANK";
						a.href=result.url;
						a.appendChild(newImg)
						myCell1.appendChild(a);
						//contentDiv.appendChild(table);
						//contentDiv.appendChild(more);
				  }
				   contentDiv.appendChild(table);
				   contentDiv.appendChild(more);
			  }
    }
	
	function searchComplete_video() 
	{
			 // Check that we got results
		  if (videoSearch.results && videoSearch.results.length > 0) 
			  {
				  // Grab our content div, clear it.
				  var contentDiv = document.getElementById('result_videos');
				  contentDiv.innerHTML='';
				  var table = document.createElement('table');
				  var lblvideo = document.createElement('div');
				  lblvideo.innerHTML='Video Results';
				  lblvideo.className="result";
				  
				  var title = document.createElement('div');
				  var content = document.createElement('div');
					  
				  contentDiv.appendChild(lblvideo);
				  
				  var more = document.createElement('a');
				  get_value();
				  more.innerHTML="See more.....";
				  more.href="./Bing/Videos/default.html?t="+aValue;
						  
				  // Loop through our results, printing them to the page.
				  var results = videoSearch.results;
				  for (var i = 0; i < 2; i++) 
				  {
					// For each result write it's title and image to the screen
					var result = results[i];
					var id = i+1;
					var newImg = document.createElement('img');
					var a = document.createElement('a');
					// There is also a result.url property which has the escaped version
					
					var imgContainer = document.createElement('div');
					var myRow = table.insertRow(i);
					var myCell1 = myRow.insertCell(0);
					var myCell2 = myRow.insertCell(1);
					
					myCell1.valign="top";
					myCell2.valign="top";
					
					newImg.src = result.tbUrl;
					newImg.height="80";
					newImg.width="100";
					newImg.className="Myimg";
					a.target="_BLANK";
					a.href=result.url;
					a.appendChild(newImg)
					
					title.innerHTML= result.title.substring(0,30);
					title.style.color="green";
					content.innerHTML=result.content.substring(0,20);
					myCell1.appendChild(a);
					myCell2.innerHTML=title.innerHTML;
				
						
				}
			
				contentDiv.appendChild(table);
				contentDiv.appendChild(more);
				
			  }	
		}
	
    function searchComplete_news()
	{
	// Check that we got results
      if (newsSearch.results && newsSearch.results.length > 0) 
      {
          // Grab our content div, clear it.
          var contentDiv = document.getElementById('result_news');
		  contentDiv.innerHTML = '';
		  var contentlbl = document.createElement('div');
		  contentlbl.innerHTML='News Results';
		  contentlbl.className="result";

		  // contentlbl.className="contentlbl";
		  contentDiv.appendChild(contentlbl);
    
          // Loop through our results, printing them to the page.
          var results = newsSearch.results;
          for (var i = 0; i < 3; i++) 
		  {
          	// For each result write it's title and image to the screen
          	var result = results[i];
          	var newsContainer = document.createElement('div');
          	var a = document.createElement('a');
		  	var br = document.createElement('br');
          
		  	
			publisher1 = result.publisher;
			date1 = result.publishedDate;
		  	a.href = result.unescapedUrl;
		  	a.target="_BLANK";
			a.innerHTML=result.title;
 
		    //date1.toString();
          	// There is also a result.url property which has the escaped version
          	newsContainer.appendChild(a);
          	newsContainer.appendChild(br);
		  	contentDiv.appendChild(newsContainer);
		  	   
          	// Put our title + image in the content
          	
        }
		
    	var more = document.createElement('a');
		more.innerHTML="See more.....";
		get_value();
		more.href="./News/default.html?t="+aValue;
		contentDiv.appendChild(more);
        // Now add the paging links so the user can see more results.
        //addPaginationLinks(webSearch);
      }
	
	 
    }
	
	function searchComplete_blog()
	{

      // Check that we got results
      if (blogSearch.results && blogSearch.results.length > 0) 
      {
          // Grab our content div, clear it.
          var contentDiv_blog = document.getElementById('result_blog');
          contentDiv_blog.innerHTML = '';
		  var contentlbl = document.createElement('div');
		  contentlbl.innerHTML='Blog Result';
		  contentlbl.className="result";
		  
		  var contentimg=document.createElement('img');
		  contentimg.align="right";
		  contentimg.valign="middle";
		  contentimg.src="Style/images/poweredbygoogle.png";
		  
		  contentDiv_blog.appendChild(contentlbl);
		  contentDiv_blog.appendChild(contentimg);
		  
		  
    
          // Loop through our results, printing them to the page.
          var results = blogSearch.results;
          for (var i = 0; i < 4; i++) 
		  {
          // For each result write it's title and image to the screen
          var result = results[i];
          var blogContainer = document.createElement('div');
          var content = document.createElement('div');
		  var a1 = document.createElement('a');
		  var br = document.createElement('br');
		  var blogurl = document.createElement('div');
		  blogurl.style.color="green";
          
		  content.innerHTML= result.content;
		  a1.href = result.postUrl;
		  a1.target="_BLANK";
		  a1.innerHTML=result.postUrl;
		  blogurl.innerHTML= result.blogUrl;

		   
          blogContainer.appendChild(a1);
          blogContainer.appendChild(content);    
		  blogContainer.appendChild(blogurl);
		  
		  
		  blogContainer.appendChild(br);
		 
          contentDiv_blog.appendChild(blogContainer);
		  
		  
        }
    	var more = document.createElement('a');
		more.innerHTML="<b>See more.....</b>";
		get_value();
	    more.href="./Blog/default.html?t="+aValue
		contentDiv_blog.appendChild(more);
	
      }
    
	}