// Email.js version 5
var tld_ 	= new Array()
tld_[0]  	= "com";
tld_[1] 	= "org";
tld_[2]  	= "net";
tld_[3]  	= "info";
tld_[4] 	= "co.uk";
tld_[5] 	= "fr";
tld_[6] 	= "org.uk";
tld_[7] 	= "gov.uk";
tld_[8] 	= "uk.com";
tld_[9] 	= "gb.com";

var topDom_ = 13;
var m_ 		= "mailto:";
var a_ 		= "@";
var d_ 		= ".";

function mail(name, dom, tl, accesskey, display) {
	var s = e(name,dom,tl-1);
	
	if (display != "") { document.write('<a href="'+m_+e(name,dom,tl)+'" accesskey="'+accesskey+'">'+display+'</a>'); }
	else { document.write('<a href="'+m_+s+'" accesskey="'+accesskey+'">'+s+'</a>'); }
		
}

function e(name, dom, tl) {
	var s = name+a_;
	if (tl!=-2) {
		s+= dom;
		if (tl>=0)
			s+= d_+tld_[tl];
	}
	else
		s+= swapper(dom);
	return s;
}

function swapper(d) {
	var s = "";
	for (var i=0; i<d.length; i+=2)
		if (i+1==d.length)
			s+= d.charAt(i)
		else
			s+= d.charAt(i+1)+d.charAt(i);
	return s.replace(/\?/g,'.');
}


var popUpWin=0;
function popUpWindow(URLStr) {
	if(popUpWin) {
    	if(!popUpWin.closed) popUpWin.close();
  	}
  	popUpWin = window.open('','popUpWin','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=400,height=500,left=250, top=100,screenX=250,screenY=100');
	var tmp = popUpWin.document;
	tmp.write('<html><head><title>Wales Craft Council PopUp</title>');
	tmp.write('<meta http-equiv=\"Pragma\" content=\"no-cache\" />');
	tmp.write('<link rel=\"stylesheet\" href=\"http://www.walescraftcouncil.co.uk/css/popup.css\">');
	tmp.write('</head><body oncontextmenu="return false";><div id=\"popup\"><dl><dt>Wales Crafts Council Image Preview</dt>');
	tmp.write('<dd><img src=\"http://www.walescraftcouncil.co.uk/' + URLStr + '\" name="myImage" onload=\"window.resizeTo(document.myImage.width+120, document.myImage.height+160); window.moveTo((screen.width-document.myImage.width)/2,5); \" /></dd>');
	tmp.write('<dd><a href=\"javascript:self.close()\">Close window</a></dd>');
	tmp.write('</div></body></html>');
	tmp.close();
}

function addBookmark(title,url) {
	if (window.sidebar) { window.sidebar.addPanel(title, url,""); } 
	else if( document.all ) { window.external.AddFavorite( url, title); } 
	else if( window.opera && window.print ) { return true; }
}

function CheckContactForm() {
	var errorMsg = "";

	// Check  name
	if (document.Form.name.value == "" || document.Form.name.value == "Full name"){
		errorMsg += "\n\tName \t- Enter your Name";	
	}
	

	//Check for an e-mail address and that it is valid
	if ((document.Form.email.value == "") || (document.Form.email.value.length > 0 && (document.Form.email.value.indexOf("@",0) == - 1 || document.Form.email.value.indexOf(".",0) == - 1))) { 
		errorMsg += "\n\tE-mail Address \t- Enter a valid e-mail address";
	}
	
	// Check phone
	if (document.Form.phone.value == "" || document.Form.phone.value == "Phone"){
		errorMsg += "\n\tPhone \t- Enter your Phone number";	
	}
	
	// Check hear about us
	if (document.Form.hearfrom.value == "" ){
		errorMsg += "\n\tWhere did you hear about us? \t- Please select...";	
	}
	
	// Check comment
	if (document.Form.comment.value == "" || document.Form.comment.value == "Message"){
		errorMsg += "\n\Comment \t- Enter your Message";	
	}
	
	//If there is aproblem with the form then display an error
	if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "Your enquiry has not been sent because there are problem(s) with the form.\n";
		msg += "Please correct the problem(s) and re-submit the form.\n";
		msg += "______________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: \n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	return true;
}

function CheckLinkForm() {
	var errorMsg = "";

	// Check  name
	if (document.Form.name.value == ""){
		errorMsg += "\n\tName \t- Enter your Name";	
	}
	
	// Check  url
	if (document.Form.url.value == ""){
		errorMsg += "\n\tWebsite URL \t- Enter your website address";	
	}
	
	// Check description
	if (document.Form.text.value == ""){
		errorMsg += "\n\Description \t- Enter a bref description of the site";	
	}
	
	//If there is aproblem with the form then display an error
	if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "Your enquiry has not been sent because there are problem(s) with the form.\n";
		msg += "Please correct the problem(s) and re-submit the form.\n";
		msg += "______________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: \n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	return true;
}

function CheckNewsletterForm() {
	var errorMsg = "";

	// Check  name
	if (document.Form.name.value == ""){
		errorMsg += "\n\tName \t- Enter your Name";	
	}
	

	//Check for an e-mail address and that it is valid
	if ((document.Form.email.value == "") || (document.Form.email.value.length > 0 && (document.Form.email.value.indexOf("@",0) == - 1 || document.Form.email.value.indexOf(".",0) == - 1))) { 
		errorMsg += "\n\tE-mail Address \t- Enter a valid e-mail address";
	}
	
	//If there is aproblem with the form then display an error
	if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "Your subscription has not been sent because there are problem(s) with the form.\n";
		msg += "Please correct the problem(s) and re-submit the form.\n";
		msg += "______________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: \n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	return true;
}





// PNG TRANSPARENCY

if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
	document.writeln('<style type="text/css">img { visibility:hidden; } </style>');
	window.attachEvent("onload", fnLoadPngs);
}

function fnLoadPngs() {
	var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);

	for (var i = document.images.length - 1, img = null; (img = document.images[i]); i--) {
		if (itsAllGood && img.src.match(/\.png$/i) != null) {
			var src = img.src;
			var div = document.createElement("DIV");
			div.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizing='scale')"
			div.style.width = img.width + "px";
			div.style.height = img.height + "px";
			img.replaceNode(div);
		}
		img.style.visibility = "visible";
	}
}

// Align float left or right List

function alignListElements()
{
	
	var nbElements = $("#catalogueList .product").size();

	for(i=0;i<=nbElements;i=i+2) {
		
		var j = i+1;
		var height0 = $("#catalogueList .product:eq("+i+") .mainInfo").height();
		var height1 = $("#catalogueList .product:eq("+j+") .mainInfo").height();
		
		if(height0 >= height1) {
			$("#catalogueList .product:eq("+j+") .mainInfo").height(height0+40);
			$("#catalogueList .product:eq("+i+") .mainInfo").height(height0+40);
		}
		else
		{
			$("#catalogueList .product:eq("+i+") .mainInfo").height(height1+40);
			$("#catalogueList .product:eq("+j+") .mainInfo").height(height1+40);
		}
	
	}
	
}

// JQUERY FUNCTION

		$(document).ready(function(){
			// modify global settings
			$.extend($.fn.Tooltip.defaults, {
				track: true,
				delay: 0,
				showURL: false,
				showBody: " - "
			});
			
			$('h1 > a,  h3, img, #featuredProduct1 a, .product h3').Tooltip({
				extraClass: "fancy",
				fixPNG: true
			});
			
			$("#content1 #mainContent p + ul, #content1 .newsBox p + ul").css({ position:"relative", top:"-1.3em" });
			$('#newsBlock > h3, .product h3').css({cursor:"help"});
			$("#content1 #mainContent li, #content1 .newsBox li").prepend("<span>&bull;</span>");

			//intervalID = window.setInterval("alignListElements();",2000)
		
		});

		$(window).load(function(){
			alignListElements();
		});


