/* --------------------------------------------------------------------------- */
/* ---------- N E L S O N S O N L I N E   F U N C T I O N A L I T Y ---------- */  
/* --------------------------------------------------------------------------- */

/* Created: 17/06/2008 SW
 ** Comments:
 ** Last updated: 18/08/2008 SW 
 */

$(document).ready(function(){

	// Services functionality, currently functionality from base does not work as subsite pages do not add subsite class to body
	/*$("#services .content").hide();
	$("#services .head .right").bind("mouseenter",function(){
		$(this).addClass("on")
		.parents("#services").children(".content").slideDown(25)
		.parents("#services").one("mouseleave",function(){
			$(this).children(".content").slideUp(25)
			.children(".right").removeClass("on");
		})
	});*/

	// Colours the product lists on the subsite pages different colours, skipping hidden items
	var ColorArray = ["#8c66d5", "#ef0039", "#04a4dc", "#53bd43", "#75b7b6", "#e49554", "#a49d8b", "#cac9c7"];
	var $ProductList = $(".e_contentMainWrapper .e_wrap .services #collection ul");
	var $Products = $ProductList.children("li:visible");
	
	for(i = 0; i < $Products.length; i++) {
		var color = ColorArray[i % ColorArray.length];
		$ProductList.children("li:visible:eq("+i+")").css("background-color", color);
	}
	
	// Renames "Purchase & Sales Agreements" to "Commercial Agreements"
	$(".e_contentMainWrapper .e_wrap .services #collection li#li-76062 > a").html("Commercial agreements");
	
	// Expands/collapses services boxes
	if (!$("body").hasClass("Home") && !$("body").hasClass("personal") && !$("body").hasClass("business")) {
		var servicesBox = $(".e_leftBar .e_services");
		servicesBox.children(".e_content").hide();
		
		servicesBox.mouseover(function(){
			$(this).children(".e_content").show().addClass("hover");
			$(this).mouseout(function(){
				$(this).children(".e_content").hide().removeClass("hover");
			})
		})
	}
	else {
		// hide the arrow
		$(".e_leftBar .e_services .e_head .e_right").hide();
	}

	$("#lawguide .level2,.e_featuresRow .e_feature,.e_rightBar .e_box").mouseover(function(){
		$(this).addClass("hover");
		$(this).one("mouseleave",function(){
			$(this).removeClass("hover");
		})
	})
	
	var documentObjSelector = $(".ele-MyServices-MyDocuments .e_list .e_documents .e_document");
	var documentObjs = []
	
	for(i=0;i<documentObjSelector.length;i++){
		documentObjs[i] = new documentObj(documentObjSelector[i]);
		documentObjs[i].init();
	}
});

var documentObj = function(obj){
	var Obj = obj
	var init = function(){
		$(Obj).mouseover(function(){
			$(this).addClass("hover").one("mouseleave",function(){
				$(this).removeClass("hover");
			})
		})
	}
	return{
		init:init
	}
};

/* ------------------------------------------- */
/* ----- NELSONS SUBSCRIPTION CALCULATOR ----- */
/* ------------------------------------------- */
(function(){
	// Nelsons RPP calculation
	var nelsonsRPP=new ele.calculator(function(n){
		var a=0,idt=.05;
		if(n==0){
			return 'Please enter a value';
		}else if(n<=2000000){
			a=.165/100;
		}else if(n>2000000&&n<=2500000){
			a=.155/100;							
		}else if(n>2500000&&n<=3000000){
			a=.150/100;
		}else if(n>3000000&&n<=3500000){
			a=.135/100;							
		}else if(n>3500000&&n<=4000000){
			a=.125/100;							
		}else{
			return 'This product is limited to a payroll of a maximum of 4M GBP.';
		}
		return(2500+(n*a*(1+idt)));	
	});
	
	$(function(){	
		$("#SubscriptionCalculator .e_result").hide();
		$('#SubscriptionCalculator').show();
		// Calculate on click
		$('#SubscriptionCalculator-Calculate').click(function(){
			nelsonsRPP.calculate($('#SubscriptionCalculator-Input').val()*1);
		});
		// Display result
		nelsonsRPP.subscribe('result',function(n){
			$('#SubscriptionCalculator .e_error').hide();
			$('#SubscriptionCalculator .e_result').show();
			$('#SubscriptionCalculator-Result').text(n.toFixed(2));
		});
		// Display error
		nelsonsRPP.subscribe('error',function(n){
			$('#SubscriptionCalculator .e_error').show().text(n);
			$('#SubscriptionCalculator .e_result').hide();
			$('#SubscriptionCalculator-Result').text('');						
		});
	});

})();
/*
function validateEeContactForm() {

	var stopForm = 0;

	$(".validate").each(function() {

		if ($(this).val() == ""){

			stopForm = 1;

		}		

	});
	
	if (stopForm == 0) {

		var emailString = $(".validateEmail").val();

		
	
		var apos=emailString.indexOf("@");
		var dotpos=emailString.lastIndexOf(".");
		
		if (apos<1||dotpos-apos<2) {
			alert('Please enter a valid email address');
			return false;
		}
	    
	
	}

	if (stopForm) {

		alert('Please complete the required fields.');

		return false;

	} 

}
*/



$(document).ready(function(){
    $("#eeContactForm").validate({
 	   rules: {
	     
    	firstname: "required",
    	
    	lastname: "required",
    	
    	ee_companyName: "required",
	    
    	email: {
	       required: true,
	       email: true
	     },
    
	    ee_contactNumber: {
		       required: true,
		       digits: true
		     },
    
		enquiry: "required"
 
	   },
	   
	   messages: {
		   
		   
		   firstname: "Please enter your name.",
	    	
		   lastname: "Please enter your surname.",
	    	
	    	ee_companyName: "Please enter the name of your company.",
		    
	    	email: {
		       required: "Please enter your email address.",
		       email: "Your email address is invalid."
		     },
	    
		    ee_contactNumber: {
			       required: "Please enter your phone number.",
			       digits: "Your phone number is invalid."
		
			     },
	    
			enquiry: "Please enter a message."
				
				
		   },
	   errorClass:'e_error',
		errorElement:'p'
    });
	   
	   
});
    
