function mailMe(name) { //v2.0
var string1 = name;
var string2 = "@";
var string3 = "crss";
var string4 = ".org.uk";
var string5 = string1 + string2 + string3 + string4;
mailMeWindow=window.open('','name','height=200,width=200');
var tmp = mailMeWindow.document;
tmp.write("<p>");
tmp.write("To send an email to "+ string1 +" using your own mail client click on the link below:");
tmp.write("</p><p>");
tmp.write("<a href=" + "mail" + "to:" + string5 +">" + string5 + "</a>");
tmp.write("</p>");
tmp.close();
}
function colourSwatch(colour) { //v2.0
var string1 = colour;
colourWindow=window.open('','name','height=200,width=200');
var temp = colourWindow.document;
temp.write("<p>");
temp.write("Colour: "+ string1 +"");
temp.write("</p><p>");
temp.write("<img src=\"http://www.terramar.co.uk/katrine/productIMG/colourswatches/150/"+string1+".jpg\" alt=\"colour: "+ string1 +"\" />");
temp.write("</p>");
temp.close();
}
function openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function validateNews() {
	if (document.news_subscribe.full_name.value.length < 1) {
		alert("Please complete the name field");
		document.news_subscribe.full_name.focus();
		return false;
	}
	if (document.news_subscribe.email.value.length < 3) {
		alert("Please complete the email field");
		document.news_subscribe.email.focus();
		return false;
	}
	return true;
}
function validateForm() {
	if (document.form_mail_results.full_name.value.length < 1) {
		alert("Please complete the name field");
		document.form_mail_results.full_name.focus();
		return false;
	}
	if (document.form_mail_results.email.value.length < 3) {
		alert("Please complete the email field");
		document.form_mail_results.email.focus();
		return false;
	}
	if (document.form_mail_results.message.value.length < 5) {
		alert("Please add a message");
		document.form_mail_results.message.focus();
		return false;
	}
	return true;
}
function validateRequest() {
	if (document.consumer_catalogue.full_name.value.length < 1) {
		alert("Please complete the name field");
		document.consumer_catalogue.full_name.focus();
		return false;
	}
	if (document.consumer_catalogue.email.value.length < 5) {
		alert("Please complete the email field");
		document.consumer_catalogue.email.focus();
		return false;
	}
	if (document.consumer_catalogue.address_1.value.length < 10) {
		alert("Please add your address");
		document.consumer_catalogue.address_1.focus();
		return false;
	}
	if (document.consumer_catalogue.postcode.value.length < 4) {
		alert("Please add your postcode");
		document.consumer_catalogue.postcode.focus();
		return false;
	}
	return true;
}
//test coffee
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);