function swapPanel(panelon) {
	//turn all off
	document.getElementById('homeImageBlank').style.display = 'none';
	document.getElementById('homeImageEncore').style.display = 'none';
	document.getElementById('homeEncore').className = '';
	document.getElementById('homeImageOmega').style.display = 'none';
	document.getElementById('homeOmega').className = '';
	document.getElementById('homeImagePrima').style.display = 'none';
	document.getElementById('homePrima').className = '';
	document.getElementById('homeImageOdyssey').style.display = 'none';
	document.getElementById('homeOdyssey').className = '';
	document.getElementById('homeImageNuance').style.display = 'none';
	document.getElementById('homeNuance').className = '';
	
	//show selected one
	document.getElementById('homeImage'+panelon).style.display = 'block';
	document.getElementById('home'+panelon).className = 'home'+panelon+'over';
}

function swapSelectorPanel(panelon) {
	//turn all off
	document.getElementById('productSelectorBlank').style.display = 'none';
	document.getElementById('productSelectorEncore').style.display = 'none';
	document.getElementById('selectorEncore').className = '';
	document.getElementById('productSelectorOmega').style.display = 'none';
	document.getElementById('selectorOmega').className = '';
	document.getElementById('productSelectorPrima').style.display = 'none';
	document.getElementById('selectorPrima').className = '';
	document.getElementById('productSelectorOdyssey').style.display = 'none';
	document.getElementById('selectorOdyssey').className = '';
	document.getElementById('productSelectorNuance').style.display = 'none';
	document.getElementById('selectorNuance').className = '';
	
	//show selected one
	document.getElementById('productSelector'+panelon).style.display = 'block';
	document.getElementById('selector'+panelon).className = 'home'+panelon+'over';
}

function galSwap(panelon) {
	//turn all off
	for (i=1;i<=16;i++)
	{
		if(document.getElementById("galPic"+i)) {
			document.getElementById("galPic"+i).style.display = 'none';
		}
	}
	
	//show selected one
	document.getElementById("galPic"+panelon).style.display = 'block';
}

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 checkFields() {
	if (document.sampleform.CustomerFirstName.value == '' || document.sampleform.CustomerLastName.value == '' || document.sampleform.AddressLine1.value == '' || document.sampleform.Town.value == '' || document.sampleform.County.value == '' || document.sampleform.Postcode.value == '' || document.sampleform.CustomerEmailAddress.value == '') {
		alert("You must fill in the mandatory fields.");
		return false;
	}else{
		if (! isValidEmail(document.sampleform.CustomerEmailAddress.value)) {
        	alert("Please enter a valid email address");
        	return false;
    	}else{
			return true;
		}
	}
}

function samplePopup(sample_id, v, range) {
	window.open("samplepopup.asp?sample_id="+sample_id+"&v="+v+"&range="+range, "samplepopup", "width=420,height=560,toolbar=no,scrollbars=no")
}

function viewBasket(sample_id) {
	window.open("basketpop.asp", "basketpopup", "width=420,height=450,toolbar=no,scrollbars=no")
}

function gotoComplete(v) {
	window.opener.location.href = "complete.asp?v="+v;	
	window.close()
}

function standPopup() {
	window.open("standpopup.asp", "standpopup", "width=500,height=611,toolbar=no,scrollbars=no")
}