function confirm_delete()
{
  if (confirm("Are you sure you want to delete this record?")==true)
    return true;
  else
    return false;
}

function dm(amount)
{
string = "" + amount;
dec = string.length - string.indexOf('.');
if (string.indexOf('.') == -1)
return string + '.00';
if (dec == 1)
return string + '00';
if (dec == 2)
return string + '0';
if (dec > 3)
return string.substring(0,string.length-dec+3);
return string;
}


function calculate(BasePrice, form, ShelfPrice)
{
   ShelfDepth = 0;
   TotA = 0; 
   DP=1;
   var DepthValue = form.shelf_depth.value
   var ShelfNo = form.shelf_extra.value

     if (DepthValue == "320")
     {DP = 1};    
     
     if (DepthValue == "400")
     {DP = 1.05};
      
     if (DepthValue == "500")
     {DP = 1.13};
     
     if (DepthValue == "600")
     {DP = 1.20};
     
     if (DepthValue == "700")
     {DP = 1.26};
     
     if (DepthValue == "800")
     {DP = 1.32};
  
   TotA = BasePrice * DP;

     if (ShelfNo > 0)
     {TotA = TotA + (ShelfNo * ShelfPrice)};
     
    TotA = Math.round(TotA*100)/100
    TotA = dm(eval(TotA))
    form.totalA.value = TotA;
      
   document.getElementById('thePrice').innerHTML = 'Price: £' + TotA + ' (ex VAT)';
}

//SIDE NAVIGATION FUNCTION

function display (L, category) {
	var myArray = new Array();
	var whichcategory = document.getElementById(category);
	
	myArray[0] = "who_we_are";
	myArray[1] = "where_to_buy";
	myArray[2] = "customer_service";
	myArray[3] = "FAQ";
	myArray[4] = "inno";
	myArray[5] = "save";
	myArray[6] = "tech";
	myArray[7] = "green_thinking";

	for (i=0; i < myArray.length; i++) {
		if (category != myArray[i]) {
			if (document.getElementById(myArray[i]) != null) {
				document.getElementById(myArray[i]).className="hide";
			}
		}
	}
	if (whichcategory != null) {
		if (whichcategory.className=="show") {
			whichcategory.className="hide";
		} else {
			whichcategory.className="show";
		}
	}
	
	var y = document.getElementById("leftnavcontent").getElementsByTagName("ul");
	for (i=0; i < y.length; i++) {
		if (y[i].className == "leftnav") {
			var w = y[i].getElementsByTagName("li");
			for (j=0; j < w.length; j++) {
				
				w[j].className = "navlink";
			}
		}
	}
	
	var x = document.getElementById(L);
	if (x != null) {
		x.className = x.className + " active";
	}
}

function PopWin(url, width, height) {
	var myWin = window.open(url,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=auto, resizable=yes, copyhistory=yes, width=" + width + ", height=" + height);
}

// validating forms
function formcheck(form) {
	var result = true;
	var errmsg = "";
	var focuson = -1;
	for (i = 0; i < form.length; i++) {
		// only operate when object is NOT submit type object.
		if (form.elements[i].type.toLowerCase() == "text") {
			// case 1: if this is Email...
			if ((form.elements[i].name.toLowerCase() == "email") || (form.elements[i].name.toLowerCase() == "e-mail")) {
				// check if it's empty, if so, leave it to the next case to catch this error.
				if (form.elements[i].value.length > 0) {
					at = form.elements[i].value.indexOf("@");
					dot = form.elements[i].value.lastIndexOf(".");
					if (((dot - at) <= 1) || (at < 1)) {
						if (errmsg != "") {	errmsg = errmsg + "\nInvalid Email!"; }
						else { errmsg = "Invalid Email!"; }
						if (focuson == -1) { focuson = i; }
						result = false;
					}
				}
			}
			// case 2: input cannot be empty!
			if (form.elements[i].value.length <= 0) {
				if (errmsg != "") { errmsg = errmsg + "\nPlease fill in " + form.elements[i].name; }
				else { errmsg = "Please fill in " + form.elements[i].name; }
				if (focuson == -1) { focuson = i; }
				result = false;
			}			
		}
		
		if (form.elements[i].type.toLowerCase() == "select-one") {
			if (form.elements[i].selectedIndex == 0) {
				if (errmsg != "") { errmsg = errmsg + "\nPlease fill in " + form.elements[i].name; }
				else { errmsg = "Please fill in " + form.elements[i].name; }
				if (focuson == -1) { focuson = i; }
				result = false;
			}			
		}
	}	
	if (errmsg != "") {
		alert(errmsg.replace(/_/g, " "));
		form.elements[focuson].style.background = "#FFFA78";
		form.elements[focuson].focus();
	}
	return result;
}

// Print
function printpage() {
	window.print();  
}

// get parameters value.
function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (
aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
}