function submitCommentForm() {
	// Change the form action to the real submission page
	document.getElementById('form2').action = "https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8";

	// Submit the form
	if (validateNew())
	{
		return true;
	}
	else
	{
		return false;
	}
}


function validateNew()
	{
	if((document.form2.first_name.value=="First Name... (required)") || (document.form2.first_name.value=="")){
		alert('Please enter your first name.');
		document.form2.first_name.focus()
		return false;
	}
	
	if((document.form2.last_name.value=="Last Name... (required)") || (document.form2.last_name.value=="")){
		alert('Please enter your last name.');
		document.form2.last_name.focus()
		return false;
	}
	
	if((document.form2.email.value=="Email... (required)") || (document.form2.email.value=="")){
		alert('Please enter your email address.');
		document.form2.email.focus()
		return false;
	}
	
	if((document.form2.description.value=="Enquiry... (required)") || (document.form2.description.value=="")){
		alert('Please enter your enquiry details.');
		document.form2.description.focus();
		return false;
	}
	
	return true;
}
 
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function prepareInputsForHints() {
	var inputs = document.getElementsByTagName("input");
	for (var i=0; i<inputs.length; i++){
			inputs[i].onfocus = function () {
				//if (this.value == this.title) {
					//this.value = '';
					this.select();
				//}
			}
			inputs[i].onblur = function () {
				if (this.value == '') {
					this.value = this.title;
				}
			}
	}
	var textareas = document.getElementsByTagName("textarea");
	for (var i=0; i<textareas.length; i++){
			textareas[i].onfocus = function () {
				//if (this.value == this.title) {
					//this.value = '';
					this.select();
				//}
			}
			textareas[i].onblur = function () {
				if (this.value == '') {
					this.value = this.title;
				}
			}
	}
}
addLoadEvent(prepareInputsForHints);

function submitMailshotForm() {
	// Change the form action to the real submission page
	document.getElementById('form2').action = "https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8";
	document.form2.description.value="Starter Email Marketing Service interest response: "+document.getElementById("Signup").value;
	

	// Submit the form
	if (validateMailshotForm())
	{
		return true;
	}
	else
	{
		return false;
	}
}


function validateMailshotForm()
	{
	if(document.form2.first_name.value==""){
		alert('Please enter your first name.');
		document.form2.first_name.focus()
		return false;
	}
	
	if(document.form2.last_name.value==""){
		alert('Please enter your last name.');
		document.form2.last_name.focus()
		return false;
	}
		
	if(document.form2.email.value==""){
		alert('Please enter your email address.');
		document.form2.email.focus()
		return false;
	}
		
	return true;
}

function PageQuery(q) {
if(q.length > 1) this.q = q.substring(1, q.length);
else this.q = null;
this.keyValuePairs = new Array();
if(q) {
for(var i=0; i < this.q.split("&").length; i++) {
this.keyValuePairs[i] = this.q.split("&")[i];
}
}
this.getKeyValuePairs = function() { return this.keyValuePairs; }
this.getValue = function(s) {
for(var j=0; j < this.keyValuePairs.length; j++) {
if(this.keyValuePairs[j].split("=")[0] == s)
return this.keyValuePairs[j].split("=")[1];
}
return false;
}
this.getParameters = function() {
var a = new Array(this.getLength());
for(var j=0; j < this.keyValuePairs.length; j++) {
a[j] = this.keyValuePairs[j].split("=")[0];
}
return a;
}
this.getLength = function() { return this.keyValuePairs.length; } 
}

//function to retrieve a given value from the querystring
function queryString(key){
var page = new PageQuery(window.location.search); 
var val = page.getValue(key); 
return val==''?'':unescape(page.getValue(key));
}

//function that retrieves a given value from the standard querystring if availble, or the cookie-based querystring as a fallback
function cachedqueryString(key){
	var qstr = location.search.substring(1);
	if (qstr.length > 0){
		return queryString(key); //return the value from the current querystring
	}else{
		qstr=getCookie("referurl"); 
		//try and get the value from the cached cookie querystring
		var page = new PageQuery(qstr); 
		var val = page.getValue(key); 
		return val==''?'':unescape(val);
	}
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
	{
	c_start=c_start + c_name.length+1;
	c_end=document.cookie.indexOf(";",c_start);
	if (c_end==-1) c_end=document.cookie.length;
	return unescape(document.cookie.substring(c_start,c_end));
	}
  }
return "";
}
