// DJ Bio
var num = 0;
var didHeaderLoad = false;
var didFooterLoad = false;
var anchoringEnabled = false;

function BodyDidLoad()
{
	new Ajax.Request('Header.html', {
		method: "get",
		onSuccess: function(response)
		{
			$("Header").innerHTML = response.responseText;
			didHeaderLoad = true;
			if(didFooterLoad)
				LoadContentPanel();
	  	}
	});
	
	new Ajax.Request('Footer.html', {
		method: "get",
		onSuccess: function(response)
		{
			$("Footer").innerHTML = response.responseText;
			didFooterLoad = true;
			if(didHeaderLoad)
				LoadContentPanel();
			
	  	}
	});
	
	new Ajax.Request('WhereToBuy.html', {
		method: "get",
		onSuccess: function(response)
		{
			$("WhereToBuy").innerHTML = response.responseText;
	  	}
	});
	
	new Ajax.Request('Events.html', {
		method: "get",
		onSuccess: function(response)
		{
			$("Events").innerHTML = response.responseText;
	  	}
	});
	
	new Ajax.Request('BookPromo.html', {
		method: "get",
		onSuccess: function(response)
		{
			$("BookPromo").innerHTML = response.responseText;
	  	}
	});



	window.setInterval(SlideShow, 30 * 1000);
}

function ToggleNext(obj)
{
	var div = obj.nextSibling;
	if(div.tagName == null)
		div = div.nextSibling;
	if(div.tagName != null)
		div.toggle();
}


function LoadContentPanel()
{
	
	var anchor = null;
	if(anchoringEnabled && location.href.indexOf("#_") > -1)
		anchor = location.href.substring(location.href.indexOf("#_") + 2);
	
	if(anchor == null || anchor == "top")
	{
		LoadContent(document.getElementById("kezdolap"));
	}
	else
	{
		LoadContent(document.getElementById(anchor));
	}
}

function LoadContent(obj)
{
	if(anchoringEnabled)
		location.href = "#_" + obj.id;

	new Ajax.Request(obj.id + '.html', {
		method: "get",
		onSuccess: function(response)
		{
			$("Content").innerHTML = response.responseText;
			
			
			var mm = document.getElementById("mm");
			if(mm != null)
			{
				var mailAddress = String.fromCharCode(109, 97, 108, 101, 99, 122, 107, 105, 46, 109, 97, 114, 116, 111, 110, 64, 103, 109, 97, 105, 108, 46, 99, 111, 109);
				mm.innerHTML = mailAddress;
				mm.href = "mailto:" + mailAddress;
			}

			var cse = document.getElementById("cse");
			if(cse != null)
			{
				var mailAddress = String.fromCharCode(101, 115, 122, 116, 101, 114, 64, 119, 101, 98, 102, 111, 114, 99, 101, 46, 104, 117);
				cse.innerHTML = mailAddress;
				cse.href = "mailto:" + mailAddress;
			}
			
			var bb = document.getElementById("bb");
			if(bb != null)
			{
				var mailAddress = String.fromCharCode(98, 97, 116, 116, 97, 46, 98, 97, 114, 110, 97, 98, 97, 115, 64, 103, 109, 97, 105, 108, 46, 99, 111, 109);
				bb.innerHTML = mailAddress;
				bb.href = "mailto:" + mailAddress;
			}
			
			var dk = document.getElementById("dk");
			if(dk != null)
			{
				var mailAddress = String.fromCharCode(100, 105, 103, 105, 107, 111, 116, 101, 116, 64, 103, 109, 97, 105, 108, 46, 99, 111, 109);
				dk.innerHTML = mailAddress;
				dk.href = "mailto:" + mailAddress;
			}
			
			
			
	  	}
	});
	
	$$(".active").each(function(obj){obj.className = null;});
	obj.className = "active";
}

function SlideShow()
{
	$("Bio"+ (num + 1)).hide();
	num = (num + 1) % 3;
	$("Bio"+ (num + 1)).show();	
}

BodyDidLoad();





function HideValidators()
{
	$("cvQuantity").hide();
	$("cvFullName").hide();
	$("cvAddress").hide();
	$("cvCity").hide();
	$("cvZipCode").hide();
	$("cvCountry").hide();
	$("cvPhoneNumber").hide();
	$("cvEmailAddress").hide();
}

function ValidateForm()
{
	HideValidators();
	var valid = true;
	
	var quantity = parseInt($("tbQuantity").value, 10);
	if(isNaN(quantity) || quantity < 1 || quantity > 10)
	{
		$("cvQuantity").show();
		valid = false;
	}

	var fullName = $("tbFullName").value;
	if(fullName == "" || fullName.length < 5)
	{
		$("cvFullName").show();
		valid = false;
	}
	
	var address = $("tbAddress").value;
	if(address == "" || address.length < 5)
	{
		$("cvAddress").show();
		valid = false;
	}

	var city = $("tbCity").value;
	if(city == "" || city.length < 5)
	{
		$("cvCity").show();
		valid = false;
	}
	
	var zipCode = parseInt($("tbZipCode").value, 10);
	if(isNaN(zipCode) || zipCode < 1000 || zipCode > 9999)
	{
		$("cvZipCode").show();
		valid = false;
	}
	
	var country = $("tbCountry").value;
	if(country != "Magyarország")
	{
		$("cvCountry").show();
		valid = false;
	}
	
	var phoneNumber = $("tbPhoneNumber").value;
	if(phoneNumber == "" || phoneNumber.length < 5)
	{
		$("cvPhoneNumber").show();
		valid = false;
	}

	var emailAddress = $("tbEmailAddress").value;
	if(emailAddress == "" || emailAddress.length < 5)
	{
		$("cvEmailAddress").show();
		valid = false;
	}
	
	return valid;
}

function QuantityDidChange()
{
	$("litTotal").innerHTML = 2590 * parseInt($("tbQuantity").value, 10);
}

function PostOrder()
{
	new Ajax.Request('order.php', {
		method: "post",
		parameters:
		{
			Quantity: $("tbQuantity").value,
			FullName: $("tbFullName").value,
			Address: $("tbAddress").value,
			City: $("tbCity").value,
			ZipCode: $("tbZipCode").value,
			Country: $("tbCountry").value,
			PhoneNumber: $("tbPhoneNumber").value,
			PaymentType: $("tbPaymentType").value,
			EmailAddress: $("tbEmailAddress").value
			
		},
		onSuccess: function(response)
		{
			$("Content").innerHTML = response.responseText;
	  	},
		onFailure: function(response)
		{
			$("Content").innerHTML = response.responseText;
		}
	});
	
}

function SwitchToFullPage(obj)
{
	obj.className = "Box1";
	//location.href = "#top";
	scroll(0, 0);
		
	$$(".FixedHeight").each(function(obj){obj.style.display = "none";});
	$$(".Text .separator").each(function(obj){obj.style.display = "none";});
}

function SwitchBack(obj, newClass)
{
	obj.className = newClass + " FixedHeight";

	scroll(0, 0);

	$$(".FixedHeight").each(function(obj){obj.style.display = "";});
	$$(".Text .separator").each(function(obj){obj.style.display = "";});
}