function IsNumeric(input){
    var RE = /^-{0,1}\d*\.{0,1}\d+$/;
    return (RE.test(input));
}

function updateQnty(totalqnty,isdelivery)
{
var postid	= $('postid').value;
var dic	= $('discprice').value;
var qnty	= parseInt($('quantity').value);

if(IsNumeric($('quantity').value) == false)
{
	alert("Enter An Integer!");
	return true;
}

if(isdelivery == 'Y')
{
	if(qnty>totalqnty)
	{	
		alert("Quantity Greater than available product Quantity!");
		return true;
	}
}
else
{
ConfirmStatus = confirm("You selected a service. Do you want to purchase more than One?");

}

if(isdelivery == 'Y' || ConfirmStatus == true)
{
	$('subtotal').innerHTML	= (Math.round((qnty*dic)*100)/100)+' &euro;';

	new Ajax.Request('/website/cartCheckout', {
	  method: 'get',
	  parameters: {todo: 'session',quantity:qnty,postid:postid},
	  onSuccess:function(){
	  	//alert("You Have Done!!Operation Success");
	  },
	  onFailure:function(){
	  	alert("Operation Failed!");
	  }
	  });
}

}

function resetCartCheckout()
{
	$('name').value	= '';
	$('mail').value	= '';
	$('address').value	= '';
	$('fax').value	= '';
	$('comments').value	= '';
	$('payment').value	= '';
	
}

function paypalPost(iterator,postId)
{
	var totalCount	= $('totalpostcount').value; 
	if($('paypal_postid_'+iterator).value == '')
	{
		$('paypal_postid_'+iterator).value	= postId;
		$('paypal').style.display = 'block';
		return true;
	}
	else
	{
		$('paypal_postid_'+iterator).value	= '';
		var isCheck = 0;
		for(var i=0;i<totalCount; i++)
		{
			if($('paypal_postid_'+i) != null)
			{
				if($('paypal_'+i).checked == false)
				{
					isCheck =0;
					
				}
				else
				{
					isCheck =1;
				}
				
			}
		}
		
		if(isCheck == 0)
		{
			$('paypal').style.display = 'none';
		}
		
		return true;
	}
	
}

function removefromCart(postid)
{
	ConfirmStatus = confirm("Are you sure you wish to remove this item from your cart?")
	if (ConfirmStatus == true)
	{
		new Ajax.Request('/website/addtoCart', {
	  method: 'get',
	  parameters: {removeId: postid,todo:'remove',from:'ajax'},
	  onSuccess:function(){
	  	$('basket_'+postid).style.display	= 'none';
	  	alert("Item Removed!");
	  }
	   });
	}
}

function enlarge()
{
	$('smallimage').style.display = 'none';
	$('enlarge').style.display = 'block';
	$('smalimg').style.display = 'none';
	$('bigimg').style.display = 'block';
}

function actualSize()
{
	$('smallimage').style.display = 'block';
	$('enlarge').style.display = 'none';
	$('bigimg').style.display = 'none';
	$('smalimg').style.display = 'block';
}

function hideCourier(postid,couriercount)
{
	if($('div_courier_'+postid) != null)
	{
		$('div_courier_'+postid).style.display	= 'none';
		for(var i=0;i<couriercount;i++)
		{
			if($('div_courier_post'+i) != null)
			{
				$('div_courier_post'+i).style.display	= 'none';
				$('div_courier_from'+i).style.display	= 'none';
				$('div_courier_to'+i).style.display	= 'none';
				$('div_courier_price'+i).style.display	= 'none';
			}
			
		}
	}
	
}



function showCourier(postid,couriercount)
{
if($('div_courier_'+postid) != null)
{
	$('div_courier_'+postid).style.display	= 'block';
	for(var i=0;i<couriercount;i++)
	{
		if($('div_courier_post'+i) != null)
		{
			$('div_courier_post'+i).style.display	= 'block';
			$('div_courier_from'+i).style.display	= 'block';
			$('div_courier_to'+i).style.display	= 'block';
			$('div_courier_price'+i).style.display	= 'block';
		}
		
	}
}
	
}

function validateDeliveryCheck()
{
	var totalCount	= $('totalpostcount').value;
	
	
	if($('name').value=='')
	{
		alert("Name Field Can not be blank!");
		return true;
	}
	
	if($('mail').value=='')
	{
		alert("Email Field Can not be blank!");
		return true;
	}
	
	if($('address').value=='')
	{
		alert("Address Field Can not be blank!");
		return true;
	}
	
	if($('tel').value=='')
	{
		alert("Telephone Field Can not be blank!");
		return true;
	}

	
	for(var i=0;i<totalCount; i++)
	{ 
		var isPaymentCheck	= 0;
		
		if($('delivery_'+i+'_1') != null)
		{
			if($('delivery_'+i+'_1').checked == false)
			{
				isPaymentCheck	= 0;
			}
		}
		
		if($('delivery_'+i+'_2') != null)
		{
			if($('delivery_'+i+'_2').checked == false)
			{
				isPaymentCheck	= 0;
			}
		}
		
		if($('delivery_'+i+'_3') != null)
		{
			if($('delivery_'+i+'_3').checked == false)
			{
				isPaymentCheck	= 0;
			}
		}
		
		if($('delivery_'+i+'_1') != null)
		{
			if($('delivery_'+i+'_1').checked == true)
			{
				isPaymentCheck	= 1;
				
			}
		}
		
		if($('delivery_'+i+'_2') != null)
		{
			if($('delivery_'+i+'_2').checked == true)
			{
				isPaymentCheck	= 1;
				
			}
		}
		
		if($('delivery_'+i+'_3') != null)
		{
			if($('delivery_'+i+'_3').checked == true)
			{
				isPaymentCheck	= 1;
				
			}
		}
		
		if(isPaymentCheck == 0)
		{	
			alert("Check A Payment Option For All Of the Purchased Products!");
			return true;
		}
		
		var courierCount	= $('post_courier_'+i).value;
		var isCourierCheck	= 0;
	
		if(courierCount >0 )
		{
			for(var m=0;m<courierCount; m++)
			{
				if($('courier_'+m).checked == false )
				{
					isCourierCheck = 0;
				}
				
				if($('courier_'+m).checked == true)
				{
					isCourierCheck = 1;
					break;
				}
				
			}
			
			if(isCourierCheck == 0)
			{	
				alert("Check A Courier!");
				return true;
			}
		}
		
	} 

	cartCheckout.submit();
	
}

