/************************************************************************************************************************
whatsthis.js || load help information from database
------------------------------------------------------------------------------------------------------------------------
Developed By Cory Caines || Kreated Nine Web Development
************************************************************************************************************************/
browser = new browser();
function browser() {
	this.IE    = false;
	this.NS    = false
	agent = navigator.userAgent;
	if ((i = agent.indexOf("MSIE")) >= 0) {
		this.IE = true;
		return;
	}
	if ((i = agent.indexOf("Gecko")) >= 0) {
		this.NS = true;
		return;
	}
	if ((i = agent.indexOf("Netscape6/")) >= 0) {
		this.NS = true;
		return;
	}
}
//whatis over
function wi_over(event){
	//move the what is box and set to loading 
	var wiBox = $("whats_this");
	
	if(browser.IE){
		pre_obj = window.event.srcElement;	
	}
	if(browser.NS){
		pre_obj = event.target;
	}
	var src;
	src = "<div class=\"featuredCont\">";
	src += "<img src=\"../images/load.gif\" />";
	src += "  Loading ... ";
	src += "</div>";
	wiBox.innerHTML = src;
	
	wiBox.style.width = '100px';
	wiBox.style.height = '20px';
	
	if(browser.IE){
		var tbody = (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
		ypos = (tbody.scrollTop + event.clientY) - 50;
		xpos = event.clientX - 100;
	}else{
		ypos = pre_obj.y - 50;
		xpos = pre_obj.x - 100;
	}
	
	wiBox.style.left = xpos+"px";
	wiBox.style.top = ypos+"px";
	
	wiBox.onmousemove = function(){
		if(wiClose != null){
			window.clearTimeout(wiClose);	
		}
	}
	wiBox.onmouseout = function(){
		wiClose = window.setTimeout("wi_reset()",2000);
	}
	wiBox.ondblclick = function(){
		wi_reset();	
	}
	var bid = pre_obj.id;
	wi_load(bid,pre_obj.y,pre_obj.x);
}

function wi_out(){
	//reset the box
	wiClose = window.setTimeout("wi_reset()",2000);
}

function wi_reset(){
	var wiBox = $("whats_this");
	wiBox.innerHTML = "";
	wiBox.style.left = "-500px";
	wiBox.style.top = "-500px";
	wiBox.style.overflow = "hidden";
}

function wi_load(bid){
	req=makeRequest();
	if (req==null){
		msg("Browser does not support HTTP Request")
		return
	} 

	req.onreadystatechange=wi_read;
	url = "../ajax/wi_load.php?bid="+bid;
	req.open("GET",url,true)
	req.send(null)	
}
function wi_read(){
	switch (req.readyState) {
		case 1 : 
		break;
		case 4 :
			if (req.status == 200) {
				//then the information has come in
				wiBox = $("whats_this");
				data = req.responseText;
				data = data.split("*");	
				
				var info = data[0];
				info = info.split("|");
				var name = info[0];
				var title = info[1];
				var details = info[2];
				var price = info[3];
				
				wiBox.style.width = "380px";
				wiBox.style.height = "300px";
				wiBox.style.overflow = "auto";
				//change the x and y positions
				ypos = ypos - 200;
				xpos = xpos - 340;
				wiBox.style.top = ypos+"px";
				wiBox.style.left = xpos+"px";
				
				wi_src ="<div class=\"featuredContsmRed\" align=\"right\"> double click to close</div>";
				wi_src += "<div style=\"padding-top:0px;padding-left:10px;padding-right:10px\">";
					wi_src += "<div align=\"center\"><h4>"+name+" - $"+price+"</h4></div>";
					wi_src += "<div align=\"center\" class=\"featuredContsm\">"+title+"</div>";
					wi_src += "<div align=\"left\"><h2>"+details+"</h2></div>";
					wi_src += "<div>";
					wi_src += "<div align=\"center\" style=\"padding-left:20px;padding-top:10px;\">";
					wi_src +="<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"width:90%;\">";
				//build the technique list
				tech = data[1];
				tech = tech.split("~");
				for(i=0;i<=tech.length-1;i++){
					tec = tech[i].split("|");
					title = tec[0];
					num = tec[1];
					
					wi_src +="<tr class=\"featuredContsm\">";
						wi_src+="<td align=\"left\">"+title+"</td>";
						wi_src+="<td align=\"left\" style=\"padding-left:5px;\">("+num+" techniques)</td>";
					wi_src +="</tr>";
				}
					wi_src +="</table>";
					wi_src += "</div>";
				
				//build the bonus list / if exists
				if(data[2] != "none"){
					wi_src+="<div align=\"left\"><h2>* this package also includes</h2></div>";
					bonus = data[2];
					bonus = bonus.split("~");
					
					wi_src += "<div align=\"center\" style=\"padding-left:20px;padding-top:10px;\">";
					wi_src +="<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"width:90%;\">";
					
					for(i=0;i<=bonus.length-1;i++){
						bon = bonus[i].split("|");
						title = bon[0];
						num = bon[1];
						
						wi_src +="<tr class=\"featuredContsm\">";
							wi_src+="<td align=\"left\">"+title+"</td>";
							wi_src+="<td align=\"left\" style=\"padding-left:10px;\">("+num+" techniques)</td>";
						wi_src +="</tr>";
					}
					
					wi_src +="</table>";
					wi_src += "</div>";
				}
				
				wi_src += "</div>";
				wiBox.innerHTML = wi_src;
			}
		break;
	}
			
}

function makeRequest(){ 
	var objXMLHttp=null;
	
	if (window.XMLHttpRequest){
	  objXMLHttp=new XMLHttpRequest()
	}else if(window.ActiveXObject){
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}
