/***************************/
//@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");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
		fixPNG(this);
	}
}

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

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


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$(".button").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
});

/*********** Contact Form ****************/

var state = 'none'; 
function showhide(layer_ref, state){
	/*if(state == 'block'){ 
	 state = 'none';
	 }else{
	 state = 'block';
	 } */
	/*if(document.all){ //IS IE 4 or 5 (or 6 beta) 
	 eval("document.all." +layer_ref+ ".style.display = state");
	 }
	 if (document.layers) { //IS NETSCAPE 4 or below
	 document.layers[layer_ref].display = state;
	 }
	 if (document.getElementById &&!document.all) {
	 hza = document.getElementById(layer_ref);
	 hza.style.display = state;
	 } */
	if (state == 'block') {
		if (document.getElementById) { // DOM3 = IE5, NS6
			document.getElementById(layer_ref).style.display = "block";
		}
		else {
			if (document.layers) { // Netscape 4
				document.layer_ref.display = "block";
			}
			else { // IE 4
				document.all.layer_ref.style.display = "block";
			}
		}
	} else {
		document.getElementById(layer_ref).style.display = "none";
		if (document.getElementById) { // DOM3 = IE5, NS6
			document.getElementById(layer_ref).style.display = "none";
		} else {
			if (document.layers) { // Netscape 4
				document.layer_ref.display= "none";
			} else { // IE 4
				document.all.layer_ref.style.display = "none";
			}
		}
	}
} 

function changeDisplay(formOption){
	if (formOption == ''){
		loadform();
	}
	if (formOption == 'Im happy'){
		showhide('type1st','none');
		showhide('type2','none');
		showhide('type3','none');
		showhide('store','block');
		showhide('datevisited','block');
		showhide('timevisited','block');
		showhide('enquiry', 'none');
		showhide('product','none');
		showhide('served','block');
		showhide('message','block');
		showhide('title','block');
		showhide('name','block');
		showhide('lastname','block');
		showhide('address','block');
		showhide('postcode','block');
		showhide('contactnumber','block');
		showhide('emailaddress','block');
		showhide('submit_link','block');
	}
	if (formOption == 'Im not happy'){
		showhide('type1st','none');
		showhide('type2','block');
		showhide('type3','none');
		showhide('store','block');
		showhide('datevisited','block');
		showhide('timevisited','block');
		showhide('enquiry', 'none');
		showhide('product','block');
		showhide('served','block');
		showhide('message','block');
		showhide('title','block');
		showhide('name','block');
		showhide('lastname','block');
		showhide('address','block');
		showhide('postcode','block');
		showhide('contactnumber','block');
		showhide('emailaddress','block');
		showhide('submit_link','block');
	}
	if (formOption == 'Id like to know'){
		showhide('type1st','block');
		showhide('type2','none');
		showhide('type3','none');
		showhide('store','none');
		showhide('datevisited','none');
		showhide('timevisited','none');
		showhide('enquiry', 'none');
		showhide('product','none');
		showhide('served','none');
		showhide('message','block');
		showhide('title','block');
		showhide('name','block');
		showhide('lastname','block');
		showhide('address','block');
		showhide('postcode','block');
		showhide('contactnumber','block');
		showhide('emailaddress','block');
		showhide('submit_link','block');
	}
	if (formOption == 'Ive got an idea'){
		showhide('type1st','none');
		showhide('type2','none');
		showhide('type3','block');
		showhide('store','none');
		showhide('datevisited','none');
		showhide('timevisited','none');
		showhide('enquiry', 'none');
		showhide('product','none');
		showhide('title','block');
		showhide('served','none');
		showhide('message','block');
		showhide('name','block');
		showhide('lastname','block');
		showhide('address','block');
		showhide('postcode','block');
		showhide('contactnumber','block');
		showhide('emailaddress','block');
		showhide('submit_link','block');
	}
	if (formOption == 'Open a store near me'){
		showhide('type1st','none');
		showhide('type2','none');
		showhide('type3','none');
		showhide('store','none');
		showhide('datevisited','none');
		showhide('timevisited','none');
		showhide('enquiry', 'none');
		showhide('product','none');
		showhide('served','none');
		showhide('message','block');
		showhide('title','block');
		showhide('name','block');
		showhide('lastname','block');
		showhide('address','block');
		showhide('postcode','block');
		showhide('contactnumber','block');
		showhide('emailaddress','block');
		showhide('submit_link','block');
	}
}
function changesmallDisplay(formOption){
	if (formOption == 'General Inquiry') {
		showhide('enquiry', 'none');
		showhide('nutritional', 'none');
		showhide('storelocatoroption', 'none');
	}
	if (formOption == 'Nutritional Info') {
		showhide('enquiry', 'block');
		showhide('nutritional', 'block');
		showhide('storelocatoroption', 'none');
	}
	if (formOption == 'Franchise Info') {
		showhide('enquiry', 'none');
		showhide('nutritional', 'none');
		showhide('storelocatoroption', 'none');
	}
	if (formOption == 'Store Locator') {
		showhide('enquiry', 'block');
		showhide('nutritional', 'none');
		showhide('storelocatoroption', 'block');
	}
	if (formOption == 'Other') {
		showhide('enquiry', 'none');
		showhide('nutritional', 'none');
		showhide('storelocatoroption', 'none');
	}
}
function loadform(){
		showhide('type1st','none');
		showhide('type2','none');
		showhide('type3','none');
		showhide('store','none');
		showhide('datevisited','none');
		showhide('timevisited','none');
		showhide('product','none');
		showhide('enquiry','none');
		showhide('nutritional','none');
		showhide('storelocatoroption','none');
		showhide('served','none');
		showhide('message','none');
		showhide('title','none');
		showhide('name','none');
		showhide('lastname','none');
		showhide('address','none');
		showhide('postcode','none');
		showhide('contactnumber','none');
		showhide('emailaddress','none');
		showhide('submit_link','none');
}


