
ddaccordion.init({
	headerclass: "expandable",
	contentclass: "categoryitems",
	revealtype: "click",
	mouseoverdelay: 200,
	collapseprev: true,
	defaultexpanded: [0],
	onemustopen: false,
	animatedefault: false,
	persiststate: true,
	toggleclass: ["", "openheader"],
	togglehtml: ["prefix", "", ""],
	animatespeed: "fast", 
	oninit:function(headers, expandedindices){ 
	},
	onopenclose:function(header, index, state, isuseractivated){ 
	}
})



$(document).ready(function() {
	$('#at-a-glance li:nth-child(5n)').addClass("last");

	Cufon.replace('h1, #footer h5, #need-help h2, #at-a-glance h5, .generic h2, .generic h3');

	// Basket modal
	$modal = $("#mdlPopup");
	modalH = $modal.outerHeight();
	modalW = $modal.outerWidth();
	windowH = $(window).height();
	windowW = $(window).width();
	$modal.before("<div id=\"overlay\"><!--[if lte IE 6]><iframe></iframe><![endif]--></div>");
	$overlay = $("#overlay").css({ height: $(document).height(), opacity: "0.6" });

	// Info modal
	$infomodal = $("#infomdlPopup");
	infomodalH = $infomodal.outerHeight();
	infomodalW = $infomodal.outerWidth();
	windowH = $(window).height();
	windowW = $(window).width();
	$infomodal.before("<div id=\"overlay\"><!--[if lte IE 6]><iframe></iframe><![endif]--></div>");

});

$(window).resize(function() {
	modalH = $modal.outerHeight();
	modalW = $modal.outerWidth();
	windowH = $(window).height();
	windowW = $(window).width();
	var left = (windowW / 2) - (modalW / 2);
	//alert(left);
	var top = ((windowH / 2) + $(window).scrollTop()) - (modalH / 2) - 22;
	if ($modal.is(":visible")) {
		$modal.animate({ top: 400}, 200);
	}
});

// Info modal

$infomodal = $("#infomdlPopup");

infoModal = function(text) {
	infomodalH = $infomodal.outerHeight();
	infomodalW = $infomodal.outerWidth();
	windowH = $(window).height();
	windowW = $(window).width();
	if (text) $infomodal.find("p").html(text);
	var left = (windowW / 2) - (infomodalW / 2);
	var top = ((windowH / 2) + $(window).scrollTop()) - (infomodalH / 2) - 22;
	$overlay.fadeIn(200);
	$("#overlay iframe").css({ top: 400, width: $infomodal.outerWidth(), height: $infomodal.outerHeight() })

	$infomodal
	.css({ top: top})
	.fadeIn(200)
	.find("img[class='modal-close'], img[class='continue']")
	.click(function(e) {
		e.preventDefault();
		$infomodal.hide();
		$overlay.fadeOut(750);
	});
}
$(window).resize(function() {
	infomodalH = $infomodal.outerHeight();
	infomodalW = $infomodal.outerWidth();
	windowH = $(window).height();
	windowW = $(window).width();
	var left = (windowW / 2) - (infomodalW / 2);
	var top = ((windowH / 2) + $(window).scrollTop()) - (infomodalH / 2) - 22;
	if ($infomodal.is(":visible")) {
		$infomodal.animate({ top: 400}, 200);
	}
});



function spwordcount(field) {

	$error = false;
	$msg = "please amend the following fields on the form and re-submit.";

	var cleanedStr = trimString($("input[id$='" + field + "']").val());
	cleanedStr = cleanedStr.replace("Search by keyword", "");
	var numWords = cleanedStr.split(' ').length;
	if (cleanedStr === '') {
		numWords = 0;
	}
	//alert(numWords);
	if (numWords == 0) {
		$msg += "\n - Please enter you search keyword";
		$error = true;
	}
	if (numWords > 3) {
		$msg += "\n - Only 3 words allowed in your search";
		$error = true;
	}

	if ($error == true) {
		alert($msg);
		return false;
	}
	else return true;
}


function trimString(str) {
	str = this != window ? this : str;
	return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function newslettervalidate(name, email,compname) {

	// reset error to false

	$error = false;
	$msg = "please amend the following fields on the form and re-submit.";
	//Name...//Email Address...
	if ($("input[id$='" + name + "']").val() == "" || $("input[id$='" + name + "']").val() == "Name...") {
		$msg += "\n - Your Name";
		$error = true;
	}
	if ($("input[id$='" + compname + "']").val() == "" || $("input[id$='" + compname + "']").val() == "Company...") {
		$msg += "\n - Your Company Name";
		$error = true;
	}

	if ($("input[id$='" + email + "']").val() == "" || $("input[id$='" + email + "']").val() == "Email Address..." || echeck($("input[id$='" + email + "']").val()) == false) {
		if (echeck($("input[id$='" + email + "']").val()) == false) {
			$msg += "\n - The email address you have typed is not valid, please verify and retype.";
		}
		$error = true;
	}

	if ($error == true) {
		alert($msg);
		return false;
	}
	else return true;
}



function echeck(str) {
	var at = "@";
	var dot = ".";
	var lat = str.indexOf(at);
	var lstr = str.length;
	var ldot = str.indexOf(dot);
	var msg = "";
	if (str.indexOf(at) == -1) {
		return false
	}
	if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
		return false
	}
	if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
		return false
	}
	if (str.indexOf(at, (lat + 1)) != -1) {
		return false
	}
	if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
		return false
	}

	if (str.indexOf(dot, (lat + 2)) == -1) {
		return false
	}
	if (str.indexOf(" ") != -1) {
		return false
	}
	return true
}
// ]]>



