/* $Id$ */

function SolrRequestFeatured() {
	//set the query for this request
	this.solrQuery = document.getElementById("featuredVideo").query.value;
	this.solrSort = document.getElementById("featuredVideo").sort.value;

	if(document.getElementById("featuredVideo").rows)
        {
		this.rows=document.getElementById("featuredVideo").rows.value; 

        }else{
		this.rows='10'
        }

}


SolrRequestFeatured.SERVER = "/solrsearch.htm?wt=json&q=";

SolrRequestFeatured.prototype.makeRequest = function(page) {
/*
 * Dynamically creates the script tag which then
 * sends the request to the Solr server.
 */
	this.jsonReq = new SolrScript(SolrRequestFeatured.SERVER + this.solrQuery +"&json.wrf=GetFeaturedVideo&rows="+this.rows+"&searchDomain=solr.teen&sort="+this.solrSort+ "&start=" + page);
	this.jsonReq.makeTag();
	this.jsonReq.addTag();
}

function requestHandlerFeatured(page) {
/*
 * Called on search form submit and on featured_results page request;
 * starting page argument is optional and defaults to 0.
 */
	var pageNum = page || 0;
	var solrReq = new SolrRequestFeatured();
	solrReq.makeRequest(pageNum);
	//return false; //needed to keep the form from performing action
}



function GetFeaturedVideo(obj) {

	var featured_results = "";
	var featured_pid = "";

	if(obj.response.numFound==0){
	 	featured_results ="<p class='search_norslts'>No featured_results Found</p>";
	}
    else
	{	 

		 featured_results+= "This is featured video <a class=\"feed_title\" href='/feed/getvideo.htm?contentId="+obj.response.docs[0].contentId+ "'>" + obj.response.docs[0].title + "</a>";
		 featured_results+= "This is description"+obj.response.docs[0].description;
 

	}
	document.getElementById('search_result_featured').innerHTML = featured_results;
	featured_pid = obj.response.docs[0].pid;

	
}



function SolrScript(url) {
/*
 * This class manages the dynamic script tag. Script
 * tag is added with id="solrScript".
 */
    this.url = url;
    this.headTag = document.getElementsByTagName("head").item(0);
	// clean up previous dynamic script tag
	if (document.getElementById("solrScript")) {
		this.headTag.removeChild(document.getElementById("solrScript"));
	}
}

SolrScript.prototype.makeTag = function () {
    this.scriptTag = document.createElement("script");
    this.scriptTag.setAttribute("type", "text/javascript");
    this.scriptTag.setAttribute("src", this.url + '&time=' + (new Date()).getTime());
    this.scriptTag.setAttribute("id", "solrScript");
}

SolrScript.prototype.addTag = function () {
    this.headTag.appendChild(this.scriptTag);
}



