//				$('#order').removeAttr ("disabled");
//				$('#order').attr("disabled", "disabled");


$(document).ready(function(){
		
		$("div#orderscript").hide();
		$("div#orderservice").hide();
			
		$("input#order").click(function() {
				//first_name validation

				var result = checkValidation ()
				return result;
								
		}
		);
		
}
);

function reseterrors ()
{
		$("span#first_name_error").html("");
		$("input").css({backgroundColor:"#ffffff"});
		
		$("span#last_name_error").html("");
		$("span#email_error").html("");
		$("span#product_error").html("");
		$("span#description_error").html("");
		$("span#amount_error").html("");
}

function checkValidation () {
		
		var firstName = $("input#first_name").val();
		var lastName = $("input#last_name").val();
		var email = $("input#email").val();
		
		reseterrors ();
		
		
		
		
		var valid = true;
		
				
		if (firstName == "") 
		{
				$("input#first_name").css({backgroundColor:"#f49696"});
				valid = false;
				$("span#first_name_error").html("*required");
		}

		if (lastName == "") 
		{
				$("input#last_name").css({backgroundColor:"#f49696"});
				valid = false;
				$("span#last_name_error").html("*required");				
		}
		
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		 if(email == "")
		 { 
		 		$("input#email").css({backgroundColor:"#f49696"});
		 		valid = false;
		 		$("span#email_error").html("*required");
		 }else
		 {
		 		if(reg.test(email) == false)
		 		{ 
		 				$("input#email").css({backgroundColor:"#f49696"});
		 				valid = false;
		 				$("span#email_error").html("wrong format");
		 		}
		 }
		 
		 
		var product = $('select[@name=product] option:selected').val();
		 if (product == "") 
		{
				valid = false;
				$("span#product_error").html("*please select");				
		}
		
		if (product == "service")
		{
				var description = $("input#description").val();
				var amount = $("input#amount").val();
				if(description == "")
		 		{ 
		 				$("input#description").css({backgroundColor:"#f49696"});
		 				valid = false;
		 				$("span#description_error").html("*required");
		 		}
		 		
		 		if(amount == "" || amount == "0" || amount == "0.00")
		 		{ 
		 				$("input#amount").css({backgroundColor:"#f49696"});
		 				valid = false;
		 				$("span#amount_error").html("*required");
		 		}
		}
		 
		 return valid;
		
		
}

function setProduct (product)
{
		$("div#orderscript").hide();
		$("div#orderservice").hide();
		reseterrors ();
		
		if (product != "")
		{
				
				var name = "order" + product;
				$("div#" + name).show();
		}
		
}

