function validateFindmore (which) {
    error=0; msg="";
    // Your Name
	if(!$("input#findmore_name").val()){error++; msg+="<strong>Full Name</strong><br />"; $("input#findmore_name").parent().addClass("error");}
	else{$("input#findmore_name").parent().removeClass("error"); findmore_name=$("input#findmore_name").val();}
	    	
	// Your Email
	if(!checkEmail($("input#findmore_email").val())){error++; msg+="<strong>Email Address</strong><br />"; $("input#findmore_email").parent().addClass("error");}
	else{$("input#findmore_email").parent().removeClass("error"); findmore_email=$("input#findmore_email").val();}
	
	// Daytime phone number
	if(!checkPhone($("input#findmore_tel").val())){error++; msg+="<strong>Daytime Phone Number</strong><br />"; $("input#findmore_tel").parent().addClass("error");}
	else{$("input#findmore_tel").parent().removeClass("error"); findmore_tel=$("input#findmore_tel").val(); }
	
	// Subject
	if($("select#findmore_subject").val() == ''){error++; msg+="<strong>Subject</strong><br />"; $("select#findmore_subject").parent().addClass("error");}
	else{$("select#findmore_subject").parent().removeClass("error"); findmore_subject=$("select#findmore_subject").val();}
	
	// Message
	findmore_message = $("textarea#findmore_message").val();
	
	if($("#msgErrorSidebar")){ $("#msgErrorSidebar").remove(); }
	if(error!=0){
		msg = "<strong>Attention</strong><br />Please verify the following fields have been properly completed and click send:<br /><br />" + msg;
		$("#"+which).before("<div id='msgErrorSidebar'>" +msg+ "</div>");
	}else{
	    $("#"+which+" .submit").hide();
		$(".b_sending").show();
		theUrl = "/en/mail/find-more.php?findmore_name="+ findmore_name +"&findmore_email="+ findmore_email +"&findmore_tel="+ findmore_tel +"&findmore_subject="+ findmore_subject +"&findmore_message="+ findmore_message;
		$.ajax({
			type: "GET",
			url: theUrl,
			success: function(resp){
                toggleFindmore('thanks');
			},
			error: function(req) { }
		});
    }
}

function toggleFindmore(state) {
    if(state == 'form') {
   	    $("#frm_findmore .submit").show();
		$(".b_sending").hide();
        $("#frm_findmore").show();
        $("div#findmore_thanks").remove();
    } else if (state == "thanks") {
	    var thanks  = '';
	    thanks += '<div id="findmore_thanks">\n';
	    thanks += '  <h3>Thanks!</h3>\n';
		thanks += '  <p>We will contact you soon.</p>\n';
//		thanks += '  <p><a href="" onclick="javascript:toggleFindmore(\'form\'); return false;" class="b b_close">Close</a></p>\n';
		thanks += '</div>\n';
	    $("#frm_findmore", "#sidebar").before(thanks);
	    $("#frm_findmore").hide();
    }
}

function displayStf (state) {
	if(state=="form"){
		if($("#stf").is("div")){
			if($("#stf").css("display")=="none"){
				$("#stf_thanks").hide(); $("#stf_form").show();
				$("#stf").show();
				$(".b_send","#li_stf_buttons").show();
        		$(".b_sending","#li_stf_buttons").hide();
			} else {
			    $("#stf").hide();
			}
		}else{
			var stf="";				
			stf += '<div id="stf">\n';
			stf += '	<div id="stf_thanks" style="display:none;">\n';
			stf += '		<h3>Thank you!</h3>\n';
			stf += '		<p>Your email has been successfully sent.</p>\n';
			stf += '		<p class="clearfix"><a href="javascript:displayStf(\'remove\');" class="b b_close">Close</a></p>\n';
			stf += '	</div>\n';
			stf += '	<div id="stf_form">\n';
			stf += '		<h3>Share this page with a friend or colleague.</h3>\n';
			stf += '		<form id="frm_stf">\n';
			stf += '			<fieldset>\n';
			stf += '				<ol>\n';
			stf += '					<li id="li_stf_name"><label for="stf_name">Your name</label><input type="text" id="stf_name" name="stf_name" class="mandatory" maxlength="200" /></li>\n';
			stf += '					<li id="li_stf_email"><label for="stf_email">Your email</label><input type="text" id="stf_email" name="stf_email" class="mandatory" maxlength="200" /></li>\n';
			stf += '					<li id="li_stf_friendsname"><label for="stf_friendsname">Recipient’s name</label><input type="text" id="stf_friendsname" name="stf_friendsname" class="mandatory" maxlength="200" /></li>\n';
			stf += '					<li id="li_stf_friendsemail"><label for="stf_friendsemail">Recipient’s email</label><input type="text" id="stf_friendsemail" name="stf_friendsemail" class="mandatory" maxlength="200" /></li>\n';
			stf += '					<li id="li_stf_comments"><label for="stf_comments">Comments<span> (optional)</span></label><textarea id="stf_comments" name="stf_comments"></textarea></li>\n';
			stf += '					<li id="li_stf_buttons">\n';
			stf += '						<a href="javascript:validateStf(\'frm_stf\');" class="b b_send">Send</a>\n';
			stf += '						<span class="b b_sending" style="display:none;">Sending...</span>\n';
			stf += '						<a href="javascript:displayStf(\'hide\');" class="b b_cancel">Cancel</a>\n';
			stf += '					</li>\n';
			stf += '				</ol>\n';
			stf += '			</fieldset>\n';
			stf += '		</form>\n';
			stf += '	</div>\n';
			stf += '</div>\n';
			
			$("#subheader").after(stf);
			$("#stf").show();
			$("#stf #stf_name").focus();
		}
	}else if (state == "thanks"){
	}else{
		$("#stf").hide();
	}
}


function validateStf(which){		
	error=0; msg="";
	
	// Your Name
	if(!$("input#stf_name").val()){ error++; msg+="<strong>Your name<strong><br />"; $("input#stf_name").parent().addClass("error"); }
	else{ $("input#stf_name").parent().removeClass("error"); stf_name=$("input#stf_name").val(); }
	
	// Your Email
	if(!checkEmail($("input#stf_email").val())){ error++; msg+="<strong>Your email</strong><br />"; $("input#stf_email").parent().addClass("error"); }
	else{ $("input#stf_email").parent().removeClass("error"); stf_email=$("input#stf_email").val(); }
	
	// Friends Name
	if(!$("input#stf_friendsname").val()){ error++; msg+="<strong>Recipient’s name</strong><br />"; $("input#stf_friendsname").parent().addClass("error"); }
	else{ $("input#stf_friendsname").parent().removeClass("error"); stf_friendsname=$("input#stf_friendsname").val(); }
	
	// Friends Email
	if(!checkEmail($("input#stf_friendsemail").val())){ error++; msg+="<strong>Recipient’s email</strong><br />"; $("input#stf_friendsemail").parent().addClass("error"); }
	else{ $("input#stf_friendsemail").parent().removeClass("error"); stf_friendsemail=$("input#stf_friendsemail").val(); }
	
	// Comments
	stf_comments=$("textarea#stf_comments").val();
	
	if(error!=0){
		msg="<strong>Attention</strong><br />Please verify the following fields have been properly completed and click send:<br /><br />" + msg;
		if($("#msgErrorTop")){ $("#msgErrorTop").remove(); }
		$("#"+which).before("<div id='msgErrorTop'>" +msg+ "</div>");
	}else{
		$(".b_send","#li_stf_buttons").hide();
		$(".b_sending","#li_stf_buttons").show();
		theUrl = "/en/mail/send-to-a-friend.php?stf_name="+ stf_name +"&stf_email="+ stf_email +"&stf_friendsname="+ stf_friendsname +"&stf_friendsemail="+ stf_friendsemail +"&stf_comments="+ escape(stf_comments) +"&stf_path="+ location.href;
		$.ajax({
			type: "GET",
			url: theUrl,
			success: function(resp){ $("#stf_thanks").show(); $("#stf_form").hide();},
			error: function(req) { }
		});
	}
}

/*  -----------------------------------------------------------------------
    Validation ------------------------------------------------------------ */

function checkEmail(to_check) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,5})+$/.test(to_check)){
	    return (true)}
	return (false);
}

function checkPhone(to_check) {
    reTel = /^\+?(\d{0,2})[ -\.()]*(\d{3})[ -\.()]*(\d{3})[ -\.]*(\d{4})$/;
	if (reTel.test(to_check)){
        return (true)}
    return (false);
}