var ajax = new sack();

function whenLoading(){
	var e = document.getElementById('replaceme');
	if(e){
		e.style.display="block";
		e.innerHTML = "<p>Fetching Data...</p>";
	}
}

function whenLoaded(){
	var e = document.getElementById('replaceme'); 
	if(e) e.innerHTML = "<p>Data Found...</p>";
}

function whenInteractive(){
	var e = document.getElementById('replaceme'); 
	if(e) e.innerHTML = "<p>Collecting data...</p>";
}

function whenCompleted(fieldid){
	//alert(ajax.response);
	var e = document.getElementById('replaceme'); 
	if(e){
		e.innerHTML = "";
		e.style.display="none";	///hide message box
	}

	document.getElementById(fieldid).innerHTML = ajax.response; ///display product list
	if(fieldid=="tabcontent"){
	scr  =  '$(document).ready(function() {	$("a#showpicnutri").fancybox();});';
	eval(scr);
	}
	if(fieldid=="maindiv") document.getElementById(fieldid).style.background="#fff";///if main div then change background to white
	/*if(logtrue==1){
		loc=document.getElementById("a").value;
		log_guide(logids,feat,loc);
	}*/
}

///get list of products for home page list with filter criteria - productlist
function getproductlist(form,clearses){
		fields="";
	if(form=="formfilter"){
		var matchPos1 = document.formfilter.a.value.search("actajax");
		if(matchPos1 == -1){
			document.formfilter.a.value=document.formfilter.a.value + "/actajax";
		}
	var elem = document.getElementById(form).elements; 
		for(var i = 0; i < elem.length; i++) { 
			ajax.setVar(elem[i].name,elem[i].value);			
			//fields=fields + elem[i].name + " - " + elem[i].value + "\n ";
		} 
		
	}
	//alert (fields);
	//ajax.setVar("a", "ajax/actajax");
	ajax.setVar("formname", form);
	ajax.setVar("clearses", clearses);
	ajax.setVar("ajaxtpe", "product");
	//ajax.requestFile = "library/ajax.product.php";
	ajax.requestFile = "/index.php";
	ajax.onLoading = whenLoading;
	ajax.onLoaded  = whenLoaded; 
	ajax.onInteractive = whenInteractive;
	ajax.onCompletion = function(){whenCompleted('productlist')};
	ajax.runAJAX();
}


///get product data and display in Flash banner box called maindiv
function GetProduct(url){
	url = url + "/actajaxh";
	ajax.setVar("a", url);
	//ajax.setVar("prodid", n); 
	ajax.requestFile = "/index.php";
	ajax.onLoading = whenLoading;
	ajax.onLoaded  = whenLoaded; 
	ajax.onInteractive = whenInteractive;
	//ajax.requestFile = "library/ajax.product.php?prodid="+n;
	ajax.onCompletion = function(){whenCompleted('maindiv')};
	ajax.runAJAX();
}

function getprodtab(id,tabid,divid,url){
	url = url + "/actajax";
	ajax.setVar("a", url);
	ajax.setVar("prodid", id);
	ajax.setVar("tabid", tabid);
	ajax.setVar("divid", divid);
	ajax.setVar("ajaxtpe", "producttab");
	ajax.requestFile = "/index.php";
	//ajax.requestFile = "library/ajax.product.php";
	clearclasses();
	document.getElementById(tabid).className="textbox_dkgrey_10 textBlack";
	ajax.onLoading = whenLoading;
	ajax.onLoaded  = whenLoaded; 
	ajax.onInteractive = whenInteractive;
	ajax.onCompletion = function(){whenCompleted(divid)};
	ajax.runAJAX();
}

function clearclasses(){
	document.getElementById('over').className="textbox_ltgrey_10 textBlack";
	document.getElementById('nutri').className="textbox_ltgrey_10 textBlack";
	document.getElementById('how').className="textbox_ltgrey_10 textBlack";
}
