function calculateQuotation() {
	var width = document.forms.quotationform.width.value; 
	var height = document.forms.quotationform.height.value;
	
	if (isNaN(width) || isNaN(height) || (width == "") || (height == "")) {
		writeLayer("quotation","Please enter valid width and height values.");
		
	} else {
		var price = 330 * ((width * height) / (1000 * 1000));
		if (price < 330) price = 330;
		writeLayer("quotation","Quotation: &pound;" + price.toFixed(2));
		displayLayer("contact", true);
		document.forms.quotationform.cost.value = price.toFixed(2);
	}
}

function sendQuotationForm() {
	var txt = "";
	
	var name = document.forms.quotationform.name.value;
	if (name == "") {
		txt += "Name\n";
	}
	
	var address = document.forms.quotationform.address.value;
	if (address == "") {
		txt += "Address\n";
	}
	
	var city = document.forms.quotationform.city.value;
	if (city == "") {
		txt += "Town/City\n";
	}
	
	var postcode = document.forms.quotationform.postcode.value;
	if (postcode == "") {
		txt += "Post code\n";
	}
	
	var telephone = document.forms.quotationform.telephone.value;
	if (telephone == "") {
		txt += "Telephone\n";
	}
	
	var email = document.forms.quotationform.email.value;	
	if (!isValidEmail(email)) {
		txt += "Email\n";
	}		
	
	if (txt != "") {
		alert("Please check:\n\n" + txt);
	} else {	
		document.forms.quotationform.submit();
	}		
}

function isValidEmail(email) {
	var re = /^ *([a-z0-9_-]+\.)*[a-z0-9_-]+@(([a-z0-9-]+\.)+(com|net|org|mil|edu|gov|arpa|info|biz|inc|name|[a-z]{2})|[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}) *$/;
	return (re.test(email.toLowerCase()));
}

function isValidUsernamePassword(value) {
	re = /^\w+$/;
	return (re.test(value.toLowerCase()));
}

String.prototype.trim = function (){
	return this.replace(/(^\s+)/g, "").replace(/(\s+$)/g, "");
}

function isValidDate(dateStr, format) {
   if (format == null) { format = "MDY"; }
   format = format.toUpperCase();
   if (format.length != 3) { format = "MDY"; }
   if ( (format.indexOf("M") == -1) || (format.indexOf("D") == -1) || (format.indexOf("Y") == -1) ) { format = "MDY"; }
   if (format.substring(0, 1) == "Y") { // If the year is first
      var reg1 = /^\d{4}(\-)\d{1,2}\1\d{1,2}$/

   } else if (format.substring(1, 2) == "Y") { // If the year is second
      var reg1 = /^\d{1,2}(\-)\d{4}\1\d{1,2}$/

   } else { // The year must be third
      var reg1 = /^\d{1,2}(\-)\d{1,2}\1\d{4}$/

   }
   if ( reg1.test(dateStr) == false ) { return false; }
   var parts = dateStr.split(RegExp.$1); // Split into 3 parts based on what the divider was
   // Check to see if the 3 parts end up making a valid date
   if (format.substring(0, 1) == "M") { var mm = parts[0]; } else 
      if (format.substring(1, 2) == "M") { var mm = parts[1]; } else { var mm = parts[2]; }
   if (format.substring(0, 1) == "D") { var dd = parts[0]; } else
      if (format.substring(1, 2) == "D") { var dd = parts[1]; } else { var dd = parts[2]; }
   if (format.substring(0, 1) == "Y") { var yy = parts[0]; } else
      if (format.substring(1, 2) == "Y") { var yy = parts[1]; } else { var yy = parts[2]; }
   if (parseFloat(yy) <= 50) { yy = (parseFloat(yy) + 2000).toString(); }
   if (parseFloat(yy) <= 99) { yy = (parseFloat(yy) + 1900).toString(); }
   var dt = new Date(parseFloat(yy), parseFloat(mm)-1, parseFloat(dd), 0, 0, 0, 0);
   if (parseFloat(dd) != dt.getDate()) { return false; }
   if (parseFloat(mm)-1 != dt.getMonth()) { return false; }
   return true;
}

function popup(w,h,t,l,url,winName,status,toolBar,scrollBars,resizable) {
	if (scrollBars == undefined) scrollBars = "auto";
	if (resizable == undefined) resizable = "no";
  	var sWid = screen.width;
  	var sHi = screen.height;
	var wid = w;
	var hi = h;
	if ((t == 0) && (l == 0)) {
		var tp = (sHi/2)-(hi/2);
		var lft = (sWid/2)-(wid/2);
	} else {
		var tp = t;
		var lft = l;	
	}
	if (scroll && document.all && (navigator.userAgent.indexOf("Mac") > -1)) wid = wid+17;
	newwin=window.open(url,winName,"width=" + wid + ",height=" + hi + ",status=" + status + ",scrollbars=" + scrollBars + ",toolbar=" + toolBar + ",resizable=" + resizable + ", top = "+ tp +", left ="+ lft + ", screenX=" + lft +", screenY= "+tp);
	newwin.focus();
}

function changeClassName(name, className){
	var obj = document.getElementById(name);
	obj.className = className;
}


function writeLayer(name, txt){
	var layer = document.getElementById(name);
	layer.innerHTML = txt;
}

function displayLayer(name, visible){
	var foc = document.getElementById(name);
	if (foc) {
		if (visible) {
			foc.style.display='block';
		} else {
			foc.style.display='none';
		}
	}
}

function setStyle(name, property, value){
	var foc = document.getElementById(name);
	if (foc) {
		foc.style[property] = value;
	}
}
