﻿addLoadEvent(setContent);
addLoadEvent(setFeed);
	
function setContent() {    
	if(!document.getElementById("primary-inner") || !document.getElementById("secondary-content")) return false;	  
		var theContentId = document.getElementById("selectedValue");
		theContentId.setAttribute("focus", "0");			
		
		//theId.onchange = function(){alert('hey...you changed my value to ' + theId.value + '!');}//get_content();}				
		theContentId.onchange = function(){get_content();get_related_content();}
		//alert(theContentId.value);			
		
		if(theContentId.value == ''){       
		    //var qStringPId = getQueryVariable("parentId");
		    var qStringId;
		    //if (qStringPId==null){
		   //     qStringId = getQueryVariable("id"); 		    		        
		   // }
		    qStringId = getQueryVariable("id"); 	
		    //alert(qStringId);		    
		    if (qStringId==null) {
		        qStringId = "64";
		    }
            document.getElementById("selectedValue").value=qStringId; 
            document.getElementById("selectedValue").onchange();                
	    }      	    	    
	                            
	return true;
}

function getQueryVariable(variable) { 
    var query = window.location.search.substring(1); 
    var vars = query.split("&"); 
    for (var i=0;i<vars.length;i++) { 
        var pair = vars[i].split("="); 
        if (pair[0] == variable) { 
        return pair[1]; 
        } 
    } 
} 

function get_content() {    
//    var loader = document.getElementById("log_res");
//    loader.className = "found";	   
//    document.getElementById("primary-inner").innerHTML = ''
    var hiddenField = document.getElementById("selectedValue");	
    //alert(hiddenField.value);
	
	var xmlhttp = getHTTPObject();

	//PATH to your SEARCH FILE WOOHOOO 
	//search root is passed in from the .aspx page for fully qualifing the site root
	xmlhttp.open("POST", searchRoot + "AjaxHandlers/DynamicContent.aspx", true);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

    //alert('in here');

	xmlhttp.onreadystatechange = function() {	
		if (xmlhttp.readyState == 4) {			
			//THE HTML WAY!
			var results = xmlhttp.responseText;
			//alert(results);

			// The first line is "search_term:matches:time_it_took" and everything after that are HTML search results
			var lines = results.split("\n");
			//alert(lines);
			// Get the first line meta-data
			var data = lines.shift();
			lines.shift();
			// The HTML search data is everything left over
			var search_results = lines.join("");
			
			data = data.split(":");
			search_term = data[0];
			match_count = data[1];
			search_time = data[2];

			var header_str = "Searched for \"" + search_term + "\" and found " + match_count + " matches in " + search_time + " seconds";
			if (match_count == 0) { header_str = ""; search_results = "<ul><li>" + search_term + " was not found</li></ul>" }		
			// no! innerhtml is bad! 
			document.getElementById("primary-inner").innerHTML = search_results;			
			addReflections();
			initRollovers();
			initLytebox();
			//loader.className = "hide";	
		}
	}

	var id = hiddenField.value;	
	if (id == ''){
	    id=64;
	}	
	//alert(id);
	//id = escape(id);
	
	var params = "id=" + id
	//alert(params);
	xmlhttp.send(params);	
	return true;
}

function get_related_content() {    
    var hiddenField = document.getElementById("selectedValue");	
    //alert(hiddenField.value);
	
	var xmlhttp = getHTTPObject();

	//PATH to your SEARCH FILE WOOHOOO 
	//search root is passed in from the .aspx page for fully qualifing the site root
	xmlhttp.open("POST", searchRoot + "AjaxHandlers/DynamicRelatedContent.aspx", true);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

    //alert('in here');

	xmlhttp.onreadystatechange = function() {	
		if (xmlhttp.readyState == 4) {			
			//THE HTML WAY!
			var results = xmlhttp.responseText;
			//alert(results);

			// The first line is "search_term:matches:time_it_took" and everything after that are HTML search results
			var lines = results.split("\n");
			//alert(lines);
			// Get the first line meta-data
			var data = lines.shift();
			lines.shift();
			// The HTML search data is everything left over
			var search_results = lines.join("");
			
			data = data.split(":");
			search_term = data[0];
			match_count = data[1];
			search_time = data[2];

			var header_str = "Searched for \"" + search_term + "\" and found " + match_count + " matches in " + search_time + " seconds";
			if (match_count == 0) { header_str = ""; search_results = "<ul><li>" + search_term + " was not found</li></ul>" }		
			// no! innerhtml is bad! 
			document.getElementById("secondary-content").innerHTML = search_results;			
		}
	}

	var id = hiddenField.value;	
	if (id == ''){
	    id=64;
	}	
	//alert(id);
	//id = escape(id);
	
	var params = "id=" + id
	//alert(params);
	xmlhttp.send(params);	
	return true;
}

function setFeed() {       
	if(!document.getElementById("feed-inner")) return false;	  
		var theContentId = document.getElementById("selectedValue");
		theContentId.setAttribute("focus", "0");					
		//theId.onchange = function(){alert('hey...you changed my value to ' + theId.value + '!');}//get_content();}				
		theContentId.onchange = function(){get_feed();}
		//alert(theContentId.value);			
		
		if(theContentId.value == ''){       
		    //var qStringPId = getQueryVariable("parentId");
		    var qStringId;		  
		    qStringId = getQueryVariable("id"); 	
		    //alert(qStringId);		    
		    if (qStringId==null) {
		        qStringId = "0";
		    }
            document.getElementById("selectedValue").value=qStringId; 
            document.getElementById("selectedValue").onchange();                
	    }      	    	    
	                            
	return true;
}

function get_feed() {    
    document.getElementById("feed-inner").style.display = 'none';    
    var hiddenField = document.getElementById("selectedValue");		
    
    document.getElementById("loading-feed").style.display = 'block';
	
	var xmlhttp = getHTTPObject();	
	//search root is passed in from the .aspx page for fully qualifing the site root
	xmlhttp.open("POST", searchRoot + "AjaxHandlers/DynamicFeed.aspx", true);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

    //alert('in here');

	xmlhttp.onreadystatechange = function() {	
		if (xmlhttp.readyState == 4) {			
			//THE HTML WAY!
			var results = xmlhttp.responseText;
			//alert(results);

			// The first line is "search_term:matches:time_it_took" and everything after that are HTML search results
			var lines = results.split("\n");
			//alert(lines);
			// Get the first line meta-data
			var data = lines.shift();
			lines.shift();
			// The HTML search data is everything left over
			var search_results = lines.join("");
			
			data = data.split(":");
			search_term = data[0];
			match_count = data[1];
			search_time = data[2];
			
			document.getElementById("feed-inner").innerHTML = search_results;	
			document.getElementById("feed-inner").style.display = 'block';	
			document.getElementById("loading-feed").style.display = 'none';				
			initRollovers();			
		}
	}

	var selectedItem = hiddenField.value;		
	var qName;
	var qValue;
	selectedItem = selectedItem.split("|");
	qName = selectedItem[0];	
	qValue = selectedItem[1];			
	var params = qName + "=" + qValue
	//alert(params);
	xmlhttp.send(params);	
	return true;
}

//function get_breadcrumb() {    
//    var hiddenField = document.getElementById("selectedValue");	
//    //alert(hiddenField.value);
//	
//	var xmlhttp = getHTTPObject();

//	//PATH to your SEARCH FILE WOOHOOO 
//	//search root is passed in from the .aspx page for fully qualifing the site root
//	xmlhttp.open("POST", searchRoot + "AjaxHandlers/DynamicBreadCrumb.aspx", true);
//	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

//    //alert('in here');

//	xmlhttp.onreadystatechange = function() {	
//		if (xmlhttp.readyState == 4) {			
//			//THE HTML WAY!
//			var results = xmlhttp.responseText;
//			//alert(results);

//			// The first line is "search_term:matches:time_it_took" and everything after that are HTML search results
//			var lines = results.split("\n");
//			//alert(lines);
//			// Get the first line meta-data
//			var data = lines.shift();
//			lines.shift();
//			// The HTML search data is everything left over
//			var search_results = lines.join("");
//			
//			data = data.split(":");
//			search_term = data[0];
//			match_count = data[1];
//			search_time = data[2];

//			var header_str = "Searched for \"" + search_term + "\" and found " + match_count + " matches in " + search_time + " seconds";
//			if (match_count == 0) { header_str = ""; search_results = "<ul><li>" + search_term + " was not found</li></ul>" }		
//			// no! innerhtml is bad! 
//			document.getElementById("secondary-content").innerHTML = search_results;			
//		}
//	}

//	var id = hiddenField.value;	
//	if (id == ''){
//	    id=64;
//	}	
//	//alert(id);
//	//id = escape(id);
//	
//	var params = "id=" + id
//	//alert(params);
//	xmlhttp.send(params);	
//	return true;
//}