////////
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = '#c7db00';
        error = "Please enter your email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#c7db00';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#c7db00';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}


function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "Please enter your phone number.\n";
        fld.style.background = '#c7db00';
    } else if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.\n";
        fld.style.background = '#c7db00';
    } 
    return error;
}

function validateName(fld) {
    var error = "";
 
    if (fld.value.length == 0 || fld.value =='Enter Full Name..' || fld.value =='Enter Notes Here...') {
        fld.style.background = '#c7db00'; 
        error = "Please enter your full name.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}

function validateNotes(fld) {
    var error = "";
 
    if (fld.value.length == 0 || fld.value =='Enter Full Name..' || fld.value =='Enter Notes Here...') {
        fld.style.background = '#c7db00'; 
        error = "Please enter your enquiry.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}
////////
function validate_qe_form(theForm) {
var reason = "";

  reason += validateName(theForm.name);
  reason += validateEmail(theForm.email);
  reason += validatePhone(theForm.tel);
  reason += validateNotes(theForm.notes);
      
  if (reason != "") {
    alert("Some fields need correction:\n\n" + reason);
    return false;
  }

  return true;
}


$(document).ready(function(){


//quickEnquiry

$("#quickEnquiry input[name='name']").click(function(){
											
	if($("#quickEnquiry input[name='name']").val() == 'Enter Full Name..'){
	$("#quickEnquiry input[name='name']").val('');	
	}
});

$("#quickEnquiry input[name='name']").blur(function(){
											
	if($("#quickEnquiry input[name='name']").val() == ''){
	$("#quickEnquiry input[name='name']").val('Enter Full Name..');	
	}
});
///// email
$("#quickEnquiry input[name='email']").click(function(){
											
	if($("#quickEnquiry input[name='email']").val() == 'Enter Email..'){
	$("#quickEnquiry input[name='email']").val('');	
	}
});

$("#quickEnquiry input[name='email']").blur(function(){
											
	if($("#quickEnquiry input[name='email']").val() == ''){
	$("#quickEnquiry input[name='email']").val('Enter Email..');	
	}
});
///// tel
$("#quickEnquiry input[name='tel']").click(function(){
											
	if($("#quickEnquiry input[name='tel']").val() == 'Enter Tel..'){
	$("#quickEnquiry input[name='tel']").val('');	
	}
});

$("#quickEnquiry input[name='tel']").blur(function(){
											
	if($("#quickEnquiry input[name='tel']").val() == ''){
	$("#quickEnquiry input[name='tel']").val('Enter Tel..');	
	}
});
///// mobile
$("#quickEnquiry input[name='mobile']").click(function(){
											
	if($("#quickEnquiry input[name='mobile']").val() == 'Enter Mobile..'){
	$("#quickEnquiry input[name='mobile']").val('');	
	}
});

$("#quickEnquiry input[name='mobile']").blur(function(){
											
	if($("#quickEnquiry input[name='mobile']").val() == ''){
	$("#quickEnquiry input[name='mobile']").val('Enter Mobile..');	
	}
});

///// notes
$("#quickEnquiry textarea[name='notes']").click(function(){
											
	if($("#quickEnquiry textarea[name='notes']").val() == 'Enter Notes Here...'){
	$("#quickEnquiry textarea[name='notes']").val('');	
	}
});

$("#quickEnquiry textarea[name='notes']").blur(function(){
											
	if($("#quickEnquiry textarea[name='notes']").val() == ''){
	$("#quickEnquiry textarea[name='notes']").val('Enter Notes Here...');	
	}
});



////// end quick enquiry
$(".cartView_drop").click(function(){
		$("#basket").slideToggle('fast');
		$(this).toggleClass("active"); return false;
			
	});


	$('.holdBox').click(function(){
		$('.holdBox').animate({
		 'marginLeft': -180
	});

});
	
	$(".sizeChartDrop").click(function(){
		$("#sizeChart").slideToggle('medium');
		$(this).toggleClass("active"); return false;
			
});
	
	
	
	
//// shippping details:
$('.showShippingAddress').click(function(){
	$('.eC_FieldsetWrapper').show();
});



/////////////////////////////////////////////////// 
/////////////////////////////////////////////////// 
/////////////////////////////////////////////////// DDACORDIAN FIX! 

$('ul.categoryitems>li>a').click(function() { 
	$.cookie("expandableMenu", 'yes' , { path: '/' });
});
$('.arrowlistmenu>ul>li>a').click(function() { 
	$.cookie("expandableMenu", 'no' , { path: '/' });
});

/////////////////////////////////////////////////// 
/////////////////////////////////////////////////// 
/////////////////////////////////////////////////// 
});





/////////
ddaccordion.init({
	headerclass: "expandable", //Shared CSS class name of headers group that are expandable
	contentclass: "categoryitems", //Shared CSS class name of contents group
	revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click" or "mouseover
	collapseprev: false, //Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [], //index of content(s) open by default [index1, index2, etc]. [] denotes no content
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: true, //persist state of opened contents within browser session?
	toggleclass: ["", "openheader"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["prefix", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "normal", //speed of animation: "fast", "normal", or "slow"
	oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
		//do nothing
		
	},
	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
		//do nothing
	}	
})



///////// NEWS MENU
ddaccordion.init({
	headerclass: "newsexpandable", //Shared CSS class name of headers group that are expandable
	contentclass: "newscategoryitems", //Shared CSS class name of contents group
	revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click" or "mouseover
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [], //index of content(s) open by default [index1, index2, etc]. [] denotes no content
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: true, //persist state of opened contents within browser session?
	toggleclass: ["", "openheader"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["prefix", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "normal", //speed of animation: "fast", "normal", or "slow"
	oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
		//do nothing
		
	},
	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
		//do nothing
	}	
})





