var preferenceswindow = 'hidden';

YAHOO.example.ACFlatData = new function(){
    // Define a custom formatter function
    this.fnCustomFormatter = function(oResultItem, sQuery) {
        var sKey = oResultItem[0];
        var nQuantity = oResultItem[1];
        var sKeyQuery = sKey.substr(0, sQuery.length);
        var sKeyRemainder = sKey.substr(sQuery.length);
        var aMarkup = ["<div class='sample-result'><span class='sample-query'>",oResultItem[0],"</span>","</div>"];
        return (aMarkup.join(""));
    };
        
    // Instantiate one XHR DataSource and define schema as an array:
    //     ["Record Delimiter",
    //     "Field Delimiter"]
    this.oACDS = new YAHOO.widget.DS_XHR("autocomple.php", ["++", "||"]);
    this.oACDS.responseType = YAHOO.widget.DS_XHR.TYPE_FLAT;
    this.oACDS.maxCacheEntries = 200;
    this.oACDS.queryMatchSubset = false;



    // Instantiate third AutoComplete
    this.oAutoComp2 = new YAHOO.widget.AutoComplete('searchstring','autocompletecontainter', this.oACDS);
    this.oAutoComp2.queryDelay = 0;
    this.oAutoComp2.prehighlightClassName = "yui-ac-prehighlight";
    this.oAutoComp2.formatResult = this.fnCustomFormatter;
    this.oAutoComp2.minQueryLength = 1;
    this.oAutoComp2.maxResultsDisplayed = 10; 
    this.oAutoComp2.autoHighlight = false;
    this.oAutoComp2.animVert = true;
    this.oAutoComp2.useShadow = true;      
    this.oAutoComp2.useIFrame = true; 
    this.oAutoComp2.animSpeed = 0.2;    

};


function startajax() {

var websitelink;

var httpRequest;

if (window.XMLHttpRequest) { // Mozilla, Safari, ...

    httpRequest = new XMLHttpRequest();

} else if (window.ActiveXObject) { // IE

    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");

}

return httpRequest;

}





function OnReadyVote() {

		if(httpRequest.readyState == 4){

			document.getElementById('votes' + postid2).innerHTML = httpRequest.responseText;

		}

}





function vote(videoid, which) {

postid2 = videoid;

document.getElementById('votes' + postid2).innerHTML = "<img src=/images/voteload.gif>";

httpRequest=startajax();

httpRequest.open('GET', 'vote.php?videoid=' + videoid + '&which=' + which, true);

httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

httpRequest.send(null);

httpRequest.onreadystatechange = OnReadyVote;





    
  
   
}


function savepreferences(reload) {

	var handleSuccess = function(o) {
		var response = o.responseText;
		showpreferences();
		if(reload == 'true')
		window.location.reload();
	
	};
	var handleFailure = function(o) {
		alert("Submission failed: " + o.status);
	};
	var callback =   
 	{   
		success: handleSuccess,
  		failure: handleFailure
 	};
	
	var sUrl = "savepreferences.php?nrofresults=" + document.forms.preferencesform.nrofresults.value + "&newwindow=" + document.forms.preferencesform.newwindow.value;
	var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback); 

}

function showpreferences() {
if(preferenceswindow == 'hidden') {
document.getElementById('preferences').style.display = 'block';
preferenceswindow = 'visible';
}
else {
document.getElementById('preferences').style.display = 'none';
preferenceswindow = 'hidden';
}
}