



function validateEmail(fld) {
    if (fld.val() != "")
	{
		var tfld = jQuery.trim(fld.val());
		var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
		
		if (!emailFilter.test(tfld)) {      
			return false;
		} else if (fld.val().match(illegalChars)) {
			return false;
		} else {
			return true;
		}
	}
	return false;
}



function validateDDE() {
	
	// Check for Name
	if ($('#dde_Name_And_Surname').val() == '') {
		$('#validationMsg').html("Please enter your Name and Surname.");
		$('#validationMsg').fadeIn("Normal");
		return false;
	}
	if ($('#get_captcha_val').val() == '') {
		$('#validationMsg').html("What does the image show?");
		$('#validationMsg').fadeIn("Normal");
		return false;
	}
	if ($('#get_captcha_val').val() != $('#captcha_val').val()) {
		$('#validationMsg').html("What does the image show?");
		$('#validationMsg').fadeIn("Normal");
		return false;
	}
	
	
	/* Check for Telephone
	if ($('#dde_Phone_Number').val() == '') {
		$('#validationMsg').html("Please enter your Contact Number.");
		$('#validationMsg').fadeIn("Normal");
		return false;
	}
	*/
	
	
	// check if email is valid
	if (!validateEmail($('#dde_Email_Address'))) {
		$('#validationMsg').html("Please enter a valid Email Address.");
		$('#validationMsg').fadeIn("Normal");
		return false;
	}
	// check if email is valid
	if ($('#dde_Email_Address').val() != $('#dde_Email_Address2').val()) {
		$('#validationMsg').html("The Email Addresses you supplied does not match.");
		$('#validationMsg').fadeIn("Normal");
		return false;
	}
	
	
	
	
	return true;	
};







// ===== Show Query Form ======= //
function showForm() 
{
	var BH = $(document).height();	
	var BW = $(document).width();
	
	$('#overlay').css('height', BH);
	$('#overlay').css('width', BW);
	
	var st = $('html,body').scrollTop();
	if (st) 
	{
		$('#diamondEnquiryBox').css('top', $('html,body').scrollTop() + 20);
	} else
	{
		$('#diamondEnquiryBox').css('top', $('body').scrollTop() + 20);
	}
	
	$('#diamondEnquiryBox').css('left', (BW - $('#diamondEnquiryBox').width())/2); 

	$('#overlay').fadeIn("normal");
	$('#diamondEnquiryBox').fadeIn("normal");
} 

function hideForm()
{
	$('#overlay').fadeOut("normal");
	$('#diamondEnquiryBox').fadeOut("normal");
}
// ======================= //


// DOM loaded
$(document).ready(function() {				   			   	
		
	// Set alternating row formatting / backgrounds
	$(".listingTable tr:odd").addClass("listingTableBlue");
	$(".listingTable tr:even").addClass("listingTableGrey");
	$(".listingTable tr:nth-child(1)").removeClass("listingTableGrey");
	$(".listingTable tr:nth-child(1)").removeClass("listingTableBlue");
	$(".listingTable tr:nth-child(1)").addClass("listingTableHead");
	
	// Gets the values of stone clicked and populates the form
	$(".listingTable a").click(function () { 	  

		var itemShape = $("#whatCutAmI").text();
		var itemID = $(this).parent().parent().children(':nth-child(1)').text();
		var itemCarat = $(this).parent().parent().children(':nth-child(3)').text();
		//var itemCut = $(this).parent().parent().children(':nth-child(5)').text();
		var itemColour = $(this).parent().parent().children(':nth-child(5)').text();
		var itemClarity = $(this).parent().parent().children(':nth-child(7)').text();
		//var itemCert = $(this).parent().parent().children(':nth-child(11)').text();
		var itemPrice = $(this).parent().parent().children(':nth-child(9)').text();
		
		$("#shapeVal").text(itemShape);
		$("#caratVal").text(itemCarat);
		$("#colourVal").text(itemColour);
		$("#clarityVal").text(itemClarity);
		//$("#cutVal").text(itemCut);
		$("#priceVal").text(itemPrice);
		$("#idVal").text(itemID);
	
		$("#dde_diamondDetail2").html("");
		$("#dde_diamondDetail2").text(itemShape + ", " + itemCarat + " Carat, " + itemColour + " Colour, " + itemClarity + " Clarity at " + itemPrice + " with reference number " + itemID);
		$("#dde_diamondDetail").text(itemShape + ", " + itemCarat + " Carat, " + itemColour + " Colour, " + itemClarity + " Clarity at " + itemPrice + " with reference number " + itemID);

		showForm();
	  
    });
	
	// hides the form
	$("#overlay").click(hideForm);
	
	
	// Handles form field focus highlighting for usability purposes
	$("input.diamondEnqField").focus(function(){
		$(this).removeClass('diamondEnqField');
		$(this).addClass('diamondEnqFieldFocus');
	});
	$("input.diamondEnqField").blur(function(){
		$(this).removeClass('diamondEnqFieldFocus');
		$(this).addClass('diamondEnqField');
	});
	
	$("textarea.diamondEnqTA2").focus(function(){
		$(this).removeClass('diamondEnqTA2');
		$(this).addClass('diamondEnqTA2Focus');
	});
	$("textarea.diamondEnqTA2").blur(function(){
		$(this).removeClass('diamondEnqTA2Focus');
		$(this).addClass('diamondEnqTA2');
	});
	
	
	// Bind step buttons to actions
	$("#btnValidate").click(validateDDE);
	
	


});
//-->





