// JavaScript Document

function ID(id){
	if(x = document.getElementById(id)) return x;
	return false;
}

function expandShipping() {
	document.getElementById('smallShipping').style.display = 'none';
	document.getElementById('bigShipping').style.display = 'block';
	return false;
}


function Visibility(id, visible){
	
	if(visible == 0) 	ID(id).style.display = "none";
	if(visible == 1) 	ID(id).style.display = "block";
	
	if(visible == 3){
		if(ID(id).style.display == "none")	ID(id).style.display = "block";
		else ID(id).style.display = "none";
	}
}

function CheckFlavour(){
	if (ID('Option1') != false && ID('Option1').value == ''){
		Visibility('flavourError', 1)
		return false;
	}
	return true;
}

function SubmitForm(FormID){
	if(CheckFlavour()) document.getElementById(FormID).submit();
	else return false;
}



function ShowBasket(){
	document.getElementById('APBasketSmall').style.display = "none";	
	document.getElementById('APBasketLarge').style.display = "block";	
}

function HideBasket(){
	document.getElementById('APBasketSmall').style.display = "block";	
	document.getElementById('APBasketLarge').style.display = "none";	
}

var CheckoutStep = 1;
function SetCheckout(Direction)
{	
	Show = CheckoutStep;
	switch(Direction){
		case "Previous":
			Show = (CheckoutStep > 1) ? CheckoutStep-1 : 1;
		break;
		case "Next":
		default:
			if(CheckoutStep == 3)	{
					SubmitForm('CheckoutForm');
					return;
			} else Show = CheckoutStep+1;
		break;
	}
	
	for(K=1; K<5; K++){
		ID('APStep' + K).style.display = "none";
	}
	
	ID('order').style.display = 'none';
	ID('goBack').style.display = 'block';		
	ID('goForeward').style.display = 'block';
	
	//alert(Show);
	
	if(Show == 4){
		ID('order').style.display = 'block';
		ID('goForeward').style.display = 'none';		
	}
	
	if(Show == 1){
		ID('goBack').style.display = 'none';		
	}
	
	ID('APStep' + Show).style.display = "block";
	CheckoutStep = Show;
	
	return;
}


function isVisible(){
	
	if(document.getElementById("useKreditKarte").checked == true)  Visibility("payWithCreditCard", 1);   
	if(document.getElementById("useKreditKarte").checked == false) Visibility("payWithCreditCard", 0);
}

pic = null;
document.onmousemove = MouseOverPic;

function MouseOverPic(p){ 
	x = (document.all) ? window.event.x : p.pageX;
	y = (document.all) ? window.event.y : p.pageY;
	if (pic != null) {
		pic.style.left = (x + 10 ) + "px";
		pic.style.top 	= (y + 10) + "px";
	}
}

function copyForm(form){
    var string;
	if (ID("userCompany").value.length == 0) {
		string = [ID("userNameTitle").value, ' ', ID("userName").value, ' ', ID("userSurname").value, "\n", ID("userStreet").value, "\n", ID("userZip").value, ' ', ID("userCity").value, "\n"].join(''); 
	} else {
		string = [ID("userCompany").value, "\n", 'z.H. ', ID("userNameTitle").value, ' ', ID("userName").value, ' ', ID("userSurname").value, "\n", ID("userStreet").value, "\n", ID("userZip").value, ' ', ID("userCity").value, "\n"].join('');
	}
    if (ID("userCountry").nodeName.toLowerCase() === 'select') {
        string += ID("userCountry").options[ID("userCountry").selectedIndex].innerHTML;
    } else {
        string += ID("userCountry").value;
    }
	ID(form).value = string;
}

function hideAll(){
	document.getElementById('pay1').style.display = 'none';	
	document.getElementById('pay2').style.display = 'none';	
	document.getElementById('pay3').style.display = 'none';	
	document.getElementById('pay4').style.display = 'none';	
}
	
