(function($) {
  $.fn.customFadeIn = function(speed, callback) {
  	$(this).fadeIn(speed, function() {
  		if(jQuery.browser.msie)
  			$(this).get(0).style.removeAttribute('filter');
  		if(callback != undefined)
  			callback();
  	});
  };
  $.fn.customFadeOut = function(speed, callback) {
  	$(this).fadeOut(speed, function() {
  		if(jQuery.browser.msie)
  			$(this).get(0).style.removeAttribute('filter');
  		if(callback != undefined)
  			callback();
  	});
  };
})(jQuery);
    
$(document).ready(function() {

	$('textarea.resizable:not(.processed)').TextAreaResizer();


  $('tbody th.fsection:first-child').parents('tr').siblings().hide();
  var toggleMinus = '../resources/Image/icons/delete.png';
  var togglePlus = '../resources/Image/icons/add.png';
  var $subHead = $('tbody th.fsection:first-child');
  $subHead.prepend('<img src="' + togglePlus + '"class="toggle" alt="Expand or collapse this section" style="cursor: pointer" align="absmiddle" hspace="5"/>');
  $('img.toggle', $subHead).addClass('clickable')
  .click(function() {
	var toggleSrc = $(this).attr('src');
	if ( toggleSrc == toggleMinus ) {
	  $(this).attr('src', togglePlus)
	  .parents('tr').siblings().customFadeOut('slow');
	} else{
	  $(this).attr('src', toggleMinus)
	  .parents('tr').siblings().customFadeIn('slow');
	};
  });
})

$(document).ready(function() {

$('a.qTip').each(function()
{
	$(this).qtip(
	{
		content: {
			url: '../tooltip.php',
			data: {
				id: $(this).attr('name')
			},
			method: 'post'
		},
		
		show: 'mouseover',
		
		hide: 'mouseout',
		
		position: {
			corner: {
				target: 'rightTop',
				tooltip: 'leftBottom'
			}
		},
		
		style: {
			name: 'blue',
			tip: 'leftBottom',
			width: { 
				min: 225,
				max: 300
			},
			border: {
         		width: 1,
         		radius: 3,
        		color: '#069'
        	}
		}
	});
});

	$('.alpha').alpha();
	$('.alphanumeric').alphanumeric();
	$('.numeric').numeric();
	$('.numeric-with-spaces').numeric({allow:" "});
	$('.numeric-date').numeric({allow:"/"});
	$('.regular').alphanumeric({allow:".,'()-& "});
	$('.alpha-with-spaces').alpha({allow:".,()-' "});
	$('.alphanumeric-with-spaces').alphanumeric({allow:" "});
	$('.email').alphanumeric({allow: "@.'!#$%&*+-/= ?^_`{|}~"});
	
    var options = { 
        //target: '#result',   // target element(s) to be updated with server response 
        resetForm: true     // reset the form after successful submit 
	    };
    
 	jQuery.validator.addMethod("matches", function(value, element, param) 
	{
		if($('#' + param).val() != $(element).val())
		return false;
		return true;
	}, "Spam field is incorrect");
	 	
    // validate signup form on keyup and submit
	$("#myForm").validate({
		
		groups: {
    		username: "first_name last_name"//,
    		//mpan: "sup1 sup2 sup3 sup4 sup5 sup6 sup7"
		},
		rules: {
			first_name: {
				required: true,
				minlength: 2
			},
			last_name: {
				required: true,
				minlength: 2
			},
			company: {
				required: true,
				minlength: 3
			},
			title: {
				required: true,
				minlength: 3				
			},
			phone: {
				required: true,
				minlength: 10
			},
			email: {
				required: true,
				email: true
			},
			zip: {
				minlength: 5
			},
			fax: {
				minlength: 10
			},
			mobile: {
				minlength: 10
			}
		},
		messages: {
			first_name: {
				required: "Please enter your first name",
				minlength: "First name is too short"
			},
			last_name: {
				required: "Please enter your second name",
				minlength: "Last name is too short"
			},
			company: {
				required: "Please enter your company name",
				minlength: "Company name is too short"
			},
			title: {
				required: "Please enter your job title",
				minlength: "Job title is too short"
			},
			phone: {
				required: "Please enter your phone number",
				minlength: "Phone number is too short"
			},
			email: "Please enter a valid email",
			zip: { 
				minlength: "Postcode is too short"
			},
			fax: {
				minlength: "Fax number is too short"
			},
			mobile: { 
				minlength: "Mobile number is too short"
			}
		},
		errorPlacement: function(error, element) {
       			error.appendTo(element.parent("td").next("td"));
   		}

	}); // end validate
    
}); // end document ready
        
        jQuery(function()
		{
    		$('#form').corners('10px');
    		$('#products').corners('10px');
    		$('#maininfo').corners('10px');
    		$('#freeservice').corners('10px');
			$(".datepicker").datepicker({ dateFormat: 'dd/mm/yy', minDate: +1, maxDate: '+4Y'});
			$("#00N200000011zDq").attr("disabled", "disabled");
			$("#00N20000000xJjf").attr("disabled", "disabled");
			$("#00N200000011zDp").attr("disabled", "disabled");
			$("#00N20000000xJjk").attr("disabled", "disabled");
			$("#00N20000000xJjf").css("background-color", "#ECE9D8");
			$("#00N20000000xJjk").css("background-color", "#ECE9D8");
    	});
		
		jQuery(function()
		{
			$("input:radio[name='00N200000011zEc']").click(function()
			{
				if($(this).val() == 'Yes')
				{
					// enable fields and set bcolor as white [for IE]
					$("#00N200000011zDq").attr("disabled", "");
					$("#00N20000000xJjf").attr("disabled", "");
					$("#00N20000000xJjf").css("background-color", "#fff");
					
				}
				else if($(this).val() == 'No' || $(this).val() == "Not Sure")
				{
					// uncheck box and disable
					$("input[name='00N200000011zDq']").attr("checked", false);
					$("#00N200000011zDq").attr("disabled", "disabled");
					// clear date and disable fields, ghost date field [for IE]
					$("#00N20000000xJjf").attr("value", "");
					$("#00N20000000xJjf").attr("disabled", "disabled");
					$("#00N20000000xJjf").css("background-color", "#ECE9D8");
					
				}
			});
			
			$("input:radio[name='00N200000011zES']").click(function()
			{
				if($(this).val() == 'Yes')
				{
					// enable fields
					$("#00N200000011zDp").attr("disabled", "");
					$("#00N20000000xJjk").attr("disabled", "");
					$("#00N20000000xJjk").css("background-color", "#fff");
					
				}
				else if($(this).val() == 'No' || $(this).val() == 'Not Sure')
				{
					// uncheck box and disable
					$("input[name='00N200000011zDp']").attr("checked", false);
					$("#00N200000011zDp").attr("disabled", "disabled");
					$("#00N20000000xJjk").css("background-color", "#fff");
					// clear date field and disable
					$("#00N20000000xJjk").attr("value", "");
					$("#00N20000000xJjk").attr("disabled", "disabled");
					$("#00N20000000xJjk").css("background-color", "#ECE9D8");
				}
			});
		});
