// JavaScript Document
function showHideDiv(div)
{
	if (document.getElementById && document.getElementById(div)!= null)
	{
		var style2 = document.getElementById(div).style;
		if (style2.display == "none" || style2.display == "")
		{
			style2.display = "block";
		}
		else
		{
			style2.display = "none";
		}
	}
}

function hideDiv(div)
{
	if (document.getElementById && document.getElementById(div)!= null)
	{
		var style2 = document.getElementById(div).style;
		style2.display = "none";
	}
}

function showDiv(div)
{
	if (document.getElementById && document.getElementById(div)!= null)
	{
		var style2 = document.getElementById(div).style;
		style2.display = "block";
	}
}

function MM_jumpMenu(targ,selObj,restore)
{ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function showShippingMode(targ,selObj,restore)
{
	var sId = selObj.options[selObj.selectedIndex].value;
	for (i=0; i< selObj.options.length; i++)
	{
		var id = selObj.options[i].value;
		hideDiv("shippingDiv_" + id);	
		hideDiv("paymentDiv_" + id);	
	}
	if (sId != null && sId != "0")
	{
		showHideDiv("shippingDiv_" + sId);
		showHideDiv("paymentDiv_" + sId);
	}
	if (sId == "0")
	{
		showHideDiv("shippingDiv_0");
		showHideDiv("paymentDiv_0");
	}
}

function validateOrder()
{	
	if (document.getElementById)
	{
		var shipping = document.getElementById("shipping");
		if(shipping == null || shipping.value == "0")
		{
			showHideDivRedBorder("orderStep_2")
			showHideDiv("orderStep_2_error");
			return false;
		}
		else
		{
			var shipping = document.getElementById("shipping");
			var destination = document.getElementById("destination_" + shipping.value);
			if(destination == null || destination.value == "-1")
			{
				showHideDivRedBorder("orderStep_3")
				showHideDiv("orderStep_3_error");
				return false;
			}	
			
			var radioPayment = document.forms["orderForm"].elements["payment_" + shipping.value];
			var flagClear = false;
			if (radioPayment.length == null)
			{
				if (radioPayment.checked == true)
				{
					flagClear = true;
				}
			}
			else
			{
				for(var i = 0; i < radioPayment.length; i++) 
				{
					var	payment = radioPayment[i];
					if (payment.checked == true)
					{
						flagClear = true;
					}
				}
			}
			
			if (flagClear == false)
			{
				showHideDivRedBorder("orderStep_4");
				showHideDiv("orderStep_4_error");
				return false;
			}
			
			var termsAndConditions = document.forms["orderForm"].elements["termsAndConditions"];
			if (termsAndConditions.checked != true)
			{
				showHideDivRedBorder("orderStep_5");
				showHideDiv("orderStep_5_error");
				return false;
			}
		}
	}
	return true;
}

function showHideDivRedBorder(div)
{
	if (document.getElementById && document.getElementById(div)!= null)
	{
		var style2 = document.getElementById(div).style;
		if (style2.border == null || style2.border == "")
		{
			style2.border = "solid 2px #FF0000";
		}
		else
		{
			style2.border = "";
		}
	}
}

function hideDivRedBorder(div)
{
	if (document.getElementById && document.getElementById(div)!= null)
	{
		var style2 = document.getElementById(div).style;
		style2.border = "";
	}
}

function cleanStepAllStepsErrors()
{
	hideDivRedBorder("orderStep_2");
	hideDiv("orderStep_2_error");
	hideDivRedBorder("orderStep_3");
	hideDiv("orderStep_3_error");
	hideDivRedBorder("orderStep_4");
	hideDiv("orderStep_4_error");
	hideDivRedBorder("orderStep_5");
	hideDiv("orderStep_5_error");
}
