
/********************
Various functions used in freibrothers.com UI
/********************/


//close wine popup onclick
	document.onclick=function(e){
		var targ;
		if (!e) var e = window.event;
		if (e.target) targ = e.target;
		else if (e.srcElement) targ = e.srcElement;
		if (targ.nodeType == 3) // defeat Safari bug
			targ = targ.parentNode;
		closeWine(targ)
	};
	
$(document).ready(function(){
 	//init wine popup
	//getDiv("wineSelection").onclick=showWine;
});
//function to toggle wines box (ftr select)
function showWine(){
	if(getDiv("wines").style.display=="block")
		closeWine()
	else 
		getDiv("wines").style.display="block";

	return false;
}

//function to update selected wine (ftr select)
function updateWine(wine){
	getDiv("wineInput").value=wine;
	closeWine();
	getDiv("wineSelection").innerHTML=wine;
	return false;
}

//function to close box when document is clicked
function closeWine(e){
	if(String(e).indexOf("#showWine")==-1)
		getDiv("wines").style.display="none";	
}

//document.getelementbyid shortcut function
function getDiv(div){
	return document.getElementById(div);
}

function showShare(){
	getDiv("friendFormContainer").style.display="block";
	$(".formContainer").show();
	$(".friendFormContent").hide();
}
function hideShare(){
	getDiv("friendFormContainer").style.display="none";
}


function sendPage(){
	yourName=$(".input[name=yourName]").val();
	yourEmail=$(".input[name=yourEmail]").val();
	friendName=$(".input[name=friendName]").val();
	friendEmail=$(".input[name=friendEmail]").val();
	if(!yourName){
		alert("Please tell us your name");
		return false;
	}
	else if(!yourEmail){
		alert("Please tell us your email");
		return false;
	}
	else if(!friendName){
		alert("Please tell us your friend's name	");
		return false;
	}
	else if(!friendEmail){
		alert("Please tell us your friend's email");
		return false;
	}
	else{
		query="yourName="+yourName
		query+="&yourEmail="+yourEmail
		query+="&friendName="+friendName
		query+="&friendEmail="+friendEmail
		$.ajax({
		  type: "GET",
		  url: "../inc/sendPage.asp?"+query,
		 success: function(response){
		  	$(".formContainer").hide();
			$(".friendFormContent").show();
			$(".friendFormContent").html(response);
		  }
		});

	}
	return false;
	
}
