// 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="../../wwwroot/js/%27+m_+e(name,dom,tl)+%27" accesskey="'+accesskey+'">'+display+'</a>'); }
	else { document.write('<a href="../../wwwroot/js/%27+m_+s+%27" 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>Image Preview</dt>');
	tmp.write('<dd><img src=\"http://www.walescraftcouncil.co.uk/' + URLStr + '\" name="myImage" onload=\"window.resizeTo(document.myImage.width+180, 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 CheckRegistrationForm() {
	var errorMsg = "";

	// Check  business name
	if (document.Form.businessName.value == ""){
		errorMsg += "\n\tBusiness Name \t- Enter your business name";	
	}

	if (document.Form.mainBusinessName.value == ""){
			errorMsg += "\n\tName of main contact in business \t- Enter the name of main contact in business";	
	}
	
	if (document.Form.workshopAddress.value == ""){
		errorMsg += "\n\tWorkshop Address \t- Enter your address";	
	}
	
	if (document.Form.town.value == ""){
		errorMsg += "\n\tTown \t- Enter the town";	
	}
	
	if (document.Form.postcode.value == ""){
		errorMsg += "\n\tPost Code \t- Enter your postcode";	
	}
	
	if (document.Form.county.value == ""){
		errorMsg += "\n\tCounty \t- Enter your county";	
	}
	
	if (document.Form.dayTimeTel.value == ""){
		errorMsg += "\n\tDay time telephone \t- Enter your day time telephone";	
	}
	
	if (document.Form.mainTrade.value == ""){
		errorMsg += "\n\tMain Trade \t- Enter your main trade";	
	}
	
	if (document.Form.dateBusiness.value == ""){
		errorMsg += "\n\tDate business established  \t- Enter the date";	
	}
	
	if (document.Form.tradingAs.value == ""){
		errorMsg += "\n\tTrading as  \t- Select an answer";	
	}
	
	if (document.Form.verificationContact.value == ""){
		errorMsg += "\n\tVerification of the main contact  \t- Select yes or no";	
	}
	
	
	//If there is aproblem with the form then display an error
	if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "Your registration 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;
}

