$(document).ready(function() { 
        $('#topnav a').click(function(){
		var _Href = $(this).attr('href');
			$.ajax({
				type:	'POST',
				url:	_Href,
				data:	"ajax=1",
				dataType:	'html',
				cache: true,
				timeout:	5000,
				success: function(d,s){
									$('#wrapper').fadeOut('slow',function(){
										$(this).html(d).fadeIn('slow');
							
							});
						},
				error: function(o,s,e){
							window.location = _Href;
						}
		});
		return false;
	});

	$('#matching').click(function() {
		disablePopup();

		var ing = $('input[name=ingredients[]]');
		var match = $('#match');
		var arrayCheckBox = new Array;
		$("input:checked").each(function(id) {
			var myVar = $("input:checked").get(id);
			arrayCheckBox.push(myVar.value);
		});
		var data = "ingredients="+arrayCheckBox+"&match="+match.val();
		$.ajax({
		   url: "/infocenter/cookbook2/newrecipe.php",
		   type: "POST",
	           data: data,
		   cache: false,
                   success: function(results){
                               $('#wrapper').fadeOut('slow',function(){
                                     $(this).html(results).fadeIn('slow');
                               });
			}
		   });
	        return false;
	});

        $('#single_recipe').click(function() {
                var recipe = $('#recipe');
                var data = "recipe="+recipe.val();
                $.ajax({
                   url: "/infocenter/cookbook2/findrecipe.php",
                   type: "POST",
                   data: data,
                   cache: false,
                   success: function(results){
                               $('#wrapper').fadeOut('slow',function(){
                                     $(this).html(results).fadeIn('slow');
                               });
                        }
                   }); 
                return false;
        });


	//LOADING POPUP
	//Click the button event!
	$("button").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
		return false;
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupIngredientsClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
$("#myInputField").focus(function(){
    // Select input field contents
    this.select();
});
});


/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupIngredients").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupIngredients").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupIngredients").height();
	var popupWidth = $("#popupIngredients").width();
	//centering
	$("#popupIngredients").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2,
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

var xmlHttp

function showDas(str)
{ 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
var url="/infocenter/das/getdas.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function showApp(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
var url="/infocenter/das/getapp.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("txtHint").innerHTML=xmlHttp.responseText 
 } 
}
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;
}


