var searchCat='';
var searchSubCat='';
function mainmenu(){
$(" #nav ul ").css({display: "none"}); // Opera Fix
$(" #nav li").hover(function(){
		$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(400);
		},function(){
		$(this).find('ul:first').css({visibility: "hidden"});
		});
}

 function setCat(category){
 	searchCat = category;
	searchSubCat = '';
 }
 function setSubCat(subcategory){
	searchSubCat = subcategory;
 }
 function loadSearchFromKey(){
	
}
function loadSearch(){
	var searchVal = document.getElementById("sfield").value;
	searchVal = document.getElementById("sfield").value.replace(" ","__");
	while(searchVal.indexOf(" ") != -1){
		searchVal = searchVal.replace(" ","__");
	}
	var newlocation = "";		
	var adaptedCat = searchCat.replace(" ","_");
	while(adaptedCat.indexOf(" ") != -1){
		adaptedCat = adaptedCat.replace(" ","_");
	}
	var adaptedSubCat = searchSubCat.replace(" ","_");
	while(adaptedSubCat.indexOf(" ") != -1){
		adaptedSubCat = adaptedSubCat.replace(" ","_");
	}
	if(searchCat=="" || searchCat=="All Categories"){
		newlocation = "/AllCategories/AllSubcategories/"+searchVal+"/";
	} else {
		if(searchSubCat!=''){
			newlocation = "/"+adaptedCat +"/"+adaptedSubCat+"/"+searchVal+"/";
		} else {
			newlocation = "/"+adaptedCat + "/AllSubcategories/"+searchVal+"/";
		}
	}	

	window.location = newlocation;
}
function loadSubCat(id){  				
		var catID = id.substring(0,id.indexOf('+'));		
		var catName = id.substring(id.indexOf('+')+1);		
		$.get('externals/home/SubCatQuery.php', {cid:catID}, 
			function(data) {
				$('#SubCategory').html(data);
		});
		setCat(catName);
}

function countPage(form,edit){
    		$.get('externals/home/count.php', {formula:form,editor:edit}, 
			function(data) {

		});

}

function goTo(address) {
	window.location=address;
}

function openPage(address){
	document.getElementById("testframe").src=address;
}

function createframe(){
	$('#column3').html("<link rel='stylesheet' href='externals/fp.css' type='text/css'><table width='98%'><tr><td class='purpose'  align='center' style='height:20px;'><font size='2px'> If you want to define and calculate your OWN formulas<a href='index.php?option=com_comprofiler&task=registersFree' border='0' target='_self' style='color:white;'> <u>REGISTER HERE</u></a></font></td></tr><tr><td><input style='background-color:#6669A0;color:#FFFFFF;font-weight:bold;margin-top:5px;height:25px;' type='button' value='Back' onClick='history.go(-1);'><br /><br /><iframe id='testframe' width='100%' height='600px'></iframe></td></tr></table>");
}
