img1 = new Image();
img2 = new Image();
img3 = new Image();
img4 = new Image();
img1.src = "images/nav_grey.jpg";
img2.src = "images/nav_grey-selected.jpg";
img3.src = "images/nav_red.jpg";
img4.src = "images/nav_red-selected.jpg";

function doRollover(navname, extra) {
	//changes the table cell bgcolor on rollover
	if (document.getElementById) {  //IE5+ and NS6
		document.getElementById('nav_'+navname).style.backgroundImage = "url(./images/nav_red"+extra+".gif)";
	} else if (document.layers) {  //NS4
		document.layers['nav_'+navname].bgColor = "#FF0000";
	} else if (document.all) {  //IE4
		document.layers['nav_'+navname].bgColor = "#FF0000";
	}
}
function doRollout(navname, extra) {
	//changes the table cell bgcolor on rollover
	if (document.getElementById) {  //IE5+ and NS6
		document.getElementById('nav_'+navname).style.backgroundImage = "url(./images/nav_grey"+extra+".gif)";
	} else if (document.layers) {  //NS4
		document.layers['nav_'+navname].bgColor = "#7F7F7F";
	} else if (document.all) {  //IE4
		document.layers['nav_'+navname].bgColor = "#7F7F7F";
	}
}

function converter() {
	window.open("converter.asp", "converter", "height=250,width=400,toolbars=no,scrollbars=no")
}

function delivery() {
	window.open("delivery.asp", "delivery", "height=435,width=470,toolbars=no,scrollbars=yes")
}

function doCV2() {
	window.open("cardstrip.html", "cv2", "height=68,width=70,toolbars=no,scrollbars=no")
}

function isValidEmail(email, required) {
    if (required==undefined) {   // if not specified, assume it's required
        required=true;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {  
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        return false;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
        return false;
    }
	
    return true;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}

function valCheckout() {
	if (frmCheckout.firstname.value == '' || frmCheckout.surname.value == '' || frmCheckout.address1.value == '' || frmCheckout.towncity.value == '' || frmCheckout.county.value == '' || frmCheckout.postcode.value == '' || frmCheckout.email.value == '') {
		alert("You must fill in the mandatory fields.");
		return false;
	}else{
		if (! isValidEmail(frmCheckout.email.value)) {
        	alert("Please enter a valid email address");
        	return false;
    	}else{
			return true;
		}
	}
}

function valPayment() {
	if (frmPayment.CardNumber.value == '' || frmPayment.CardHolder.value == '' || frmPayment.ExpiryDate.value == '' || frmPayment.CV2.value == '' || frmPayment.bil_address1.value == '' || frmPayment.bil_towncity.value == '' || frmPayment.bil_county.value == '' || frmPayment.bil_postcode.value == '') {
		alert("Please fill in all required fields.");
		return false;
	}else{
		return true;
	}
}

function dealerpopup(theimg) {
	window.open("viewimg.asp?theimg="+theimg, "dealerimg", "height=410,width=410,toolbars=no,scrollbars=no")
}