function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}

function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 {
  //alert(xmlHttp.responseText);
 document.getElementById("divSubcategory").innerHTML=xmlHttp.responseText;
 }
}

function showSubcategory(str)
{
//alert('str '+str);
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 }
var url="/recipes/browse/subcategory/"+str+'/';
//alert(url);
//url=url+"?category="+str;
//url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function ListSubCategory() {
//	alert('Hi....');
	//var chklength = document.getElementById('cat').length;
	//var t = document.frmRecipeSubmit.cat.length;
// 	alert(document.frmRecipeSubmit.length);
// 	alert(document.frmRecipeSubmit.cat);
// 	alert(document.frmRecipeSubmit.cat.length);
 var obj = document.getElementById('divListSubcategory');
 obj.innerHTML = "Subcategories are loading. Please Wait...";

	var sel_category = '';
	var count = document.frmRecipeSubmit.cat.length;
	for (i=0;i<count;i++) {
		if (document.frmRecipeSubmit.cat[i].checked) {
			//alert(document.frmRecipeSubmit.cat[i].value);
			var cat_name = document.frmRecipeSubmit.cat[i].value;
			//param = param+"cat_"+i+'='+cat_name+"&";
			sel_category = sel_category+cat_name+',';
		}


	}
	//alert(sel_category);

	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="/recipes/submit/listsubcategory/";
	var params = "selected_cat="+sel_category;
	//alert(params);
	xmlHttp.open("POST",url,true);
	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.onreadystatechange=stateChanged_Category;
	xmlHttp.send(params);
	//xmlHttp.send(null);

}

function ListSubCategoryOfRecipe(recipe_id) {
//	alert('Hi....');
	//var chklength = document.getElementById('cat').length;
	//var t = document.frmRecipeSubmit.cat.length;
// 	alert(document.frmRecipeSubmit.length);
// 	alert(document.frmRecipeSubmit.cat);
// 	alert(document.frmRecipeSubmit.cat.length);
 var obj = document.getElementById('divListSubcategory');
 obj.innerHTML = "Subcategories are loading. Please Wait...";

	var sel_category = '';
	var count = document.frmRecipeSubmit.cat.length;
	for (i=0;i<count;i++) {
		if (document.frmRecipeSubmit.cat[i].checked) {
			//alert(document.frmRecipeSubmit.cat[i].value);
			var cat_name = document.frmRecipeSubmit.cat[i].value;
			//param = param+"cat_"+i+'='+cat_name+"&";
			sel_category = sel_category+cat_name+',';
		}


	}
	//alert(sel_category);

	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="/recipes/submit/listsubcategory/";
	var params = "selected_cat="+sel_category+",recipe_id"+recipe_id;
	//alert(params);
	//alert(url);
	xmlHttp.open("POST",url,true);
	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.onreadystatechange=stateChanged_Category;
	xmlHttp.send(params);
	//xmlHttp.send(null);

}

function EditListSubCategory() {
//	alert('Hi....');
	//var chklength = document.getElementById('cat').length;
	//var t = document.frmRecipeSubmit.cat.length;
// 	alert(document.frmRecipeSubmit.length);
// 	alert(document.frmRecipeSubmit.cat);
// 	alert(document.frmRecipeSubmit.cat.length);
 var obj = document.getElementById('divListSubcategory');
 obj.innerHTML = "Subcategories are loading. Please Wait...";

	var sel_category = '';
	var count = document.frmRecipeEdit.cat.length;
	for (i=0;i<count;i++) {
		if (document.frmRecipeEdit.cat[i].checked) {
			//alert(document.frmRecipeSubmit.cat[i].value);
			var cat_name = document.frmRecipeEdit.cat[i].value;
			//param = param+"cat_"+i+'='+cat_name+"&";
			sel_category = sel_category+cat_name+',';
		}


	}
	//alert(sel_category);

	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="/recipes/submit/listsubcategory/";
	var params = "selected_cat="+sel_category;
	//alert(params);
	xmlHttp.open("POST",url,true);
	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.onreadystatechange=stateChanged_Category;
	xmlHttp.send(params);
	//xmlHttp.send(null);

}


function ToggleCatButton(cat) {
	var count = document.images.length;
	var img0 = "/_img/button-plus.gif";
	var img1 = "/_img/button-minus.gif";
	var box;
	var cimg = document.getElementById('img-' + cat);
	box = document.getElementById('box-' + cat);
	if ( cimg.src.match(img0) ) {
		cimg.src = img1;
		box.style.display='';
	}else{
		cimg.src = img0;
		box.style.display='none';
	}

	return;
	for (i=0;i<count;i++) {
		//if (document.images[i].name.substr(0,4)=='cat-') {
		if (document.images[i].name == 'cat-'+cat) {
			box = document.getElementById('box-' + cat);
			if ( document.images[i].src.match(img0) ) {
				document.images[i].src = img1;
				box.style.display='';
			}else{
				document.images[i].src = img0;
				box.style.display='none';
			}
		}
	}
}

function LoadListSubCategory(cats) {
   var list = cats.split(',');
   var count = document.form_recipe_search.elements.length;
   var aspect;
   var cimg, box, cb;
   var img1 = "/_img/button-minus.gif";
   for (i=0; i<list.length; i++) {
	for (j=0;j<count;j++) {
		cb = document.form_recipe_search.elements[j];
		if ( cb.value == list[i] ) {
			aspect = document.form_recipe_search.elements[j].id;
			cimg = document.getElementById('img-' + aspect);
			cimg.src = img1;
			box = document.getElementById('box-' + aspect);
			box.style.display='';
			cb.checked=true;
		}
	}
   }
}



function SearchListSubCategory(cats) {
//	alert('Hi....');
	//var chklength = document.getElementById('cat').length;
	//var t = document.frmRecipeSubmit.cat.length;
// 	alert(document.frmRecipeSubmit.length);
// 	alert(document.frmRecipeSubmit.cat);
// 	alert(document.frmRecipeSubmit.cat.length);

	return; // we're not using this routine anymore, since we now use ToggleCatButton
		// to show all the subcats on the page

	var obj = document.getElementById('divListSubcategory');
	obj.innerHTML = "Subcategories are loading. Please Wait...";

	var img1 = "/_img/button-minus.gif";
	var sel_category = '';
	//var count = document.form_recipe_search.cat.length;
	var count = document.images.length;
	for (i=0;i<count;i++) {
		if ( document.images[i].src.match(img1) ) {
		//if (document.form_recipe_search.cat[i].checked) {
			//alert(document.frmRecipeSubmit.cat[i].value);
			var cat_name = document.images[i].name.substr(4);
			//var cat_name = document.form_recipe_search.cat[i].value;
			//param = param+"cat_"+i+'='+cat_name+"&";
			sel_category = sel_category+cat_name+',';
		}
	}
	//alert(sel_category);

	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="/recipes/submit/listsubcategory/";
	var params = "selected_cat="+sel_category;
	//alert(params);
	xmlHttp.open("POST",url,true);
	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.onreadystatechange=stateChanged_Category;
	xmlHttp.send(params);
	//xmlHttp.send(null);

}

function stateChanged_Category() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 	{
		//alert(xmlHttp.responseText);
		document.getElementById("divListSubcategory").innerHTML=xmlHttp.responseText;
 	}
}


function ListSubCategoryMentorSearch() {
//	alert('Hi....');
	//var chklength = document.getElementById('cat').length;
	//var t = document.frmRecipeSubmit.cat.length;
// 	alert(document.frmRecipeSubmit.length);
// 	alert(document.frmRecipeSubmit.cat);
// 	alert(document.frmRecipeSubmit.cat.length);
 var obj = document.getElementById('divListSubcategory');
 obj.innerHTML = "Subcategories are loading. Please Wait...";

	var sel_category = '';
	var count = document.frmSearchMentor.cat.length;
	for (i=0;i<count;i++) {
		if (document.frmSearchMentor.cat[i].checked) {
			//alert(document.frmRecipeSubmit.cat[i].value);
			var cat_name = document.frmSearchMentor.cat[i].value;
			//param = param+"cat_"+i+'='+cat_name+"&";
			sel_category = sel_category+cat_name+',';
		}


	}
	//alert(sel_category);

	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="/recipes/submit/listsubcategory/";
	var params = "selected_cat="+sel_category;
	//alert(params);
	xmlHttp.open("POST",url,true);
	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.onreadystatechange=stateChanged_CategorySearchMentor;
	xmlHttp.send(params);
	//xmlHttp.send(null);

}

function stateChanged_CategorySearchMentor() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 	{
		//alert(xmlHttp.responseText);
		document.getElementById("divListSubcategory").innerHTML=xmlHttp.responseText;
 	}
}
