//////////////////////////////////////////////////////
// ORDER NOW FORM
//////////////////////////////////////////////////////
function orderNowEnableT1(value)
{
	var v = value;
	
	if(v == "personalised")
	{
		document.orderNow.bookmakerCustomVerse.disabled = false;
		$("#BookmarkerVersePers").slideDown("fast");
	}
	else
	{
		document.orderNow.bookmakerCustomVerse.disabled = true;
		$("#BookmarkerVersePers").slideUp("fast");
	}
}

function orderNowEnableT2(value)
{
	var v = value;
	
	if(v == "personalised")
	{
		document.orderNow.walletCardCustomVerse.disabled = false;
		$("#WalletcardVersePers").slideDown("fast");
	}
	else
	{
		document.orderNow.walletCardCustomVerse.disabled = true;
		$("#WalletcardVersePers").slideUp("fast");
	}
}

function onLoadProdsCount()
{
	var prodsCond = document.getElementById('prodsCond').value;
	
	if(prodsCond != 0)
	{
		document.getElementById('discount').innerHTML = 0;
		document.getElementById('postDiscount').value = 0;
	}
}

function countOrderTotal()
{
	var orderTotal = 0;
	
	var discount = 0;
	
	var prodsCond 		= parseInt(document.getElementById('prodsCond').value);
	var activeDiscount 	= document.getElementById('activeDiscount').value;
	var curProds 		= document.getElementById('curProds').value;
	var curProdsInt 	= parseInt(curProds);
	
	if(document.getElementById('postDiscount') != null)
	{
		discount = parseInt(activeDiscount);
	}

	var bookmakerAmount 		= parseInt(document.orderNow.bookmakerAmount.value);
	var memoriamAmount 			= parseInt(document.orderNow.memoriamAmount.value);
	var walletCardAmount 		= parseInt(document.orderNow.walletCardAmount.value);
	var keyRingAmount 			= parseInt(document.orderNow.keyRingAmount.value);
	var acAmount 				= parseInt(document.orderNow.acAmount.value);
	var notePaperAmount 		= parseInt(document.orderNow.notePaperAmount.value);
	
	//COUNT
	if(bookmakerAmount != 0){orderTotal = (orderTotal + bookmakerAmount); document.getElementById('curProds').value = curProdsInt + 1;}
	if(memoriamAmount != 0){orderTotal = (orderTotal + memoriamAmount); document.getElementById('curProds').value = curProdsInt + 1;}
	if(walletCardAmount != 0){orderTotal = (orderTotal + walletCardAmount); document.getElementById('curProds').value = curProdsInt + 1;}
	if(keyRingAmount != 0){orderTotal = (orderTotal + keyRingAmount); document.getElementById('curProds').value = curProdsInt + 1;}
	if(acAmount != 0){orderTotal = (orderTotal + acAmount); document.getElementById('curProds').value = curProdsInt + 1;}
	if(notePaperAmount != 0){orderTotal = (orderTotal + notePaperAmount); document.getElementById('curProds').value = curProdsInt + 1;}
	
	var curProdsAdded = parseInt(document.getElementById('curProds').value);
	
	if(curProdsAdded >= prodsCond)
	{
		document.getElementById('discount').innerHTML = activeDiscount;
		document.getElementById('postDiscount').value = activeDiscount;
	}
	
	if(discount != 0 && curProdsAdded >= prodsCond)
	{
		var totalDiscount 		= (orderTotal / 100) * discount;
		var totalWithDiscount 	= orderTotal - totalDiscount;	
		//var totalDiscount 		= (orderTotal)-(orderTotal / (1 + (discount / 100)));
		//var totalWithDiscount 	= orderTotal - totalDiscount;		
	}	
	
	document.getElementById("postOrderTotal").value = orderTotal;
	
	if(discount != 0 && curProdsAdded >= prodsCond)
	{
		document.getElementById("postDiscountOrderTotal").value 		= totalWithDiscount;
		document.getElementById("discountOrderTotalPrice").innerHTML 	= totalWithDiscount.toFixed(2);		
	}
	else
	{
		document.getElementById("postDiscountOrderTotal").value 		= orderTotal;
		document.getElementById("discountOrderTotalPrice").innerHTML 	= orderTotal.toFixed(2);
	}
	
	document.getElementById("orderTotalPrice").innerHTML = orderTotal.toFixed(2);
}

//FILL SELECT - AJAX (JQUERY)
//if elementId is class enter .elementClassName
//if elementId is htmlId enter #elementIdName
function fillSelect(elementId, recordId)
{
	$.get('elements/fillSelectElement.php?id=' + recordId, function(data) {

		$(elementId).html(data);	
		
		//call - count total price
		countOrderTotal();
		
	});
}

function orderFillAll(id)
{
	if(id > 0)
	{
		fillSelect('#bookmakerAmount', id);
		fillSelect('#memoriamAmount', id);
		fillSelect('#walletCardAmount', id);
		fillSelect('#keyRingAmount', id);
		fillSelect('#acAmount', id);
		fillSelect('#notePaperAmount', id);
	}
}


function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
	thisfield.value = "";
	}
	}
	function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
	thisfield.value = defaulttext;
	}
	}
