	function ResetForm()
{
	var vForm = document.getElementById("form1");
	vForm.reset();
	var vTraka = document.getElementById("opt3");
	var vNoClients = document.getElementById("No_Clients");

	OnChangeReaderTech();
	vTraka.disabled = true;
	vNoClients.disabled = true;

	var vOKImgSrc = "/system/modules/uk.co.tssi.website/resources/images/Information.gif";
	var vNoDoorsStat = document.getElementById("helpdoor");
	var vNoReadersStat = document.getElementById("helpreader");
	var vBioReaderStat = document.getElementById("helpbio");
	var vCardHolderStat = document.getElementById("helpholder");
	var vReaderTechStat = document.getElementById("helptech");
	var vCardTypeStat = document.getElementById("helpcard");
	var vControlTypeStat = document.getElementById("helpcontrol");
	var vSoftwareStat = document.getElementById("helpsoftwaretype");
	var vClientsStat = document.getElementById("helpclient");
	var vMediaStat = document.getElementById("helpmedia");

	vNoDoorsStat.src = vNoReadersStat.src = vBioReaderStat.src = vCardHolderStat.src = 
		vReaderTechStat.src = vCardTypeStat.src = vControlTypeStat.src = vSoftwareTypeStat.src =
		vClientsStat.src = vMediaStat.src = vOKImgSrc;
}

function EnableTrakaOpt() {

       	var vSoftwareType = document.getElementById("Software_Type");
	var vTraka = document.getElementById("opt3");
	var vClients = document.getElementById("No_Clients");
	
	switch(vSoftwareType.options.item(vSoftwareType.selectedIndex).value)
	{
	case "sqlserver":
		{
		vTraka.disabled = false;
		vClients.disabled = false;
		vClients.value = 1; 
		break;
		}		
	case "lite":
		{
		vTraka.disabled = true;
		vClients.disabled = true;
		vClients.value = 0;
		break;
		}	
	case "standalone":
		{
		vTraka.disabled = true;
		vClients.disabled = true;
		vClients.value = 0;
		break;
		}
	case "blank":
		{
		vTraka.disabled = true;
		vClients.disabled = true;
		vClients.value = 0;
		break;
		}		
	}
}



function OnChangeReaderTech()
{
	var vRdrTech = document.getElementById("Reader_Tech");
	var vCardType = document.getElementById("Card_Type");
	ClearCombo(vCardType);

	switch(vRdrTech.options.item(vRdrTech.selectedIndex).value)
	{
	case "blank":
		AddCombo(vCardType, ".. select reader technology first ..", "blank", true);
		break;
	case "swipe":
	case "swipe_pin":
		AddCombo(vCardType, ".. please select one ..", "blank", true);
		AddCombo(vCardType, "ISO magnetic stripe", "iso", false);
		AddCombo(vCardType, "Watermark", "water", false);
		break;
	case "iclass":
		AddCombo(vCardType, "HiD iClass", "iclass", false);
		break;
        case "mifare":
		AddCombo(vCardType, "Mifare", "mifare", false);
		break;
        case "prox":
	case "prox_pin":
	case "hidprox":
	case "hidprox_pin":
		AddCombo(vCardType, ".. please select one ..", "blank", true);
		AddCombo(vCardType, "Plastic card (Wiegand)", "wiegand", false);
		AddCombo(vCardType, "Keyfob (Wiegand)", "wiegand_fob", false);
                AddCombo(vCardType, "Plastic card (clock / data)", "clock", false);
		AddCombo(vCardType, "HiD iClass", "iclass", false);
		AddCombo(vCardType, "MIFARE", "mifare", false);
		break;
	}
}

function validate()
{
	var vMsg = "The following errors prevent you from submitting this form.  Please correct them and retry.\r\n\r\n";
	var vErrors = "";

	var vNoDoors = document.getElementById("No_Doors");
	var vNoReaders = document.getElementById("No_Readers");
	var vBioReader = document.getElementById("No_Bio_Readers");
	var vCardHolders = document.getElementById("No_CardHolders");
	var vReaderTech = document.getElementById("Reader_Tech");
	var vCardType = document.getElementById("Card_Type");
	var vControlType = document.getElementById("Controller_Type");
	var vSoftwareType = document.getElementById("Software_Type");
	var vClients = document.getElementById("No_Clients");
	var vMedia = document.getElementById("Soft_Media");
	var vBioOpt = document.getElementById("opt2");

	var vOKImgSrc = "/system/modules/uk.co.tssi.website/resources/images/Information.gif";
	var vNoDoorsStat = document.getElementById("helpdoor");
	var vNoReadersStat = document.getElementById("helpreader");
	var vBioReaderStat = document.getElementById("helpbio");
	var vCardHolderStat = document.getElementById("helpholder");
	var vReaderTechStat = document.getElementById("helptech");
	var vCardTypeStat = document.getElementById("helpcard");
	var vControlTypeStat = document.getElementById("helpcontrol");
	var vSoftwareTypeStat = document.getElementById("helpsoftwaretype");
	var vClientsStat = document.getElementById("helpclient");
	var vMediaStat = document.getElementById("helpmedia");

	vNoDoorsStat.src = vNoReadersStat.src = vBioReaderStat.src = vCardHolderStat.src = 
		vReaderTechStat.src = vCardTypeStat.src = vControlTypeStat.src = vSoftwareTypeStat.src = 
		vClientsStat.src = vMediaStat.src = vOKImgSrc;

	vErrors += validateMandatory(vNoDoors, "Number of doors", vNoDoorsStat);
	vErrors += validateInt(vNoDoors, "Number of doors", vNoDoorsStat);
	vErrors += validateMaxMinLimit(vNoDoors, "Number of doors", 1, 1000, vNoDoorsStat);

	vErrors += validateMandatory(vNoReaders, "Number of readers", vNoReadersStat);
	vErrors += validateInt(vNoReaders, "Number of readers", vNoReadersStat);
	vErrors += validateMaxMinLimit(vNoReaders, "Number of readers", vNoDoors.value, (vNoDoors.value * 2) + 20, vNoReadersStat);

	vErrors += validateMandatory(vBioReader, "Biometric readers", vBioReaderStat);
	vErrors += validateInt(vBioReader, "Biometric readers", vBioReaderStat);
	vErrors += validateMaxMinLimit(vBioReader, "Biometric readers", 0, vNoReaders.value, vBioReaderStat);

	vErrors += validateMandatory(vCardHolders, "Number of cardholders", vCardHolderStat);
	vErrors += validateInt(vCardHolders, "Number of cardholders", vCardHolderStat);
	vErrors += validateMaxMinLimit(vCardHolders, "Number of cardholders", 1, 100000, vCardHolderStat);

	vErrors += validateNotBlank(vReaderTech, "Reader Technology", vReaderTechStat);

	vErrors += validateNotBlank(vCardType, "Card type", vCardTypeStat);

	vErrors += validateNotBlank(vControlType, "Controller type", vControlTypeStat);

	vErrors += validateNotBlank(vSoftwareType, "Software version", vSoftwareTypeStat);

	vErrors += validateMandatory(vClients, "Number of clients", vClientsStat);
	vErrors += validateInt(vClients, "Number of clients", vClientsStat);
	vErrors += validateMaxMinLimit(vClients, "Number of clients", 0, 1000, vClientsStat);

	vErrors += validateNotBlank(vMedia, "Software media", vMediaStat);

	if(vErrors.length > 0)
	{
		alert(vMsg + vErrors);
		return false;
	}

	//check for warnings
	vMsg = "The following warning(s) have been identified.  Are you sure?\r\n\r\n";
	if(vBioOpt.checked)
	{
		if(parseInt(vBioReader.value) < 1)
		{
			vErrors += "You have selected Biometric management software but specified 0 biometric readers.";
		}
	}

	if(vErrors.length > 0)
	{
		return window.confirm(vMsg + vErrors);
	}

	return true;
}

function validateMandatory(vEdit, vName, vIcon)
{
	var vMsg = "";

	if(vEdit.value == "")
        {
                vMsg = vName + " is a mandatory field.\r\n";
		if(vIcon != null)
		{
			vIcon.src = "/system/modules/uk.co.tssi.website/resources/images/alert1.gif";
		}
	}

	return vMsg;
}

function validateInt(vEdit, vName, vIcon)
{
	var vMsg = "";

	if(isNaN(parseInt(vEdit.value)))
	{
                vMsg = "Please enter a whole number for the " + vName + ".\r\n";
		if(vIcon != null)
		{
			vIcon.src = "/system/modules/uk.co.tssi.website/resources/images/alert1.gif";
		}
	}
	else if(vEdit.value != parseInt(vEdit.value))
	{
                vMsg = "Please enter a whole number for the " + vName + ".\r\n";
		if(vIcon != null)
		{
			vIcon.src = "/system/modules/uk.co.tssi.website/resources/images/alert1.gif";
		}
	}

	return vMsg;
}

function validateMinLimit(vEdit, vName, vMin, vIcon)
{
	var vMsg = "";

	vMin = parseInt(vMin);

	if(vEdit.value < vMin)
	{
		vMsg = vName + " should be greater or equal to " + vMin + ".\r\n";
		if(vIcon != null)
		{
			vIcon.src = "/system/modules/uk.co.tssi.website/resources/images/alert1.gif";
		}
	}

	return vMsg;
}

function validateMaxMinLimit(vEdit, vName, vMin, vMax, vIcon)
{
	var vMsg = "";

	vMin = parseInt(vMin);
	vMax = parseInt(vMax);

	if(vEdit.value < vMin || vEdit.value > vMax)
	{
		vMsg = vName + " should be between " + vMin + " and " + vMax + ".\r\n";
		if(vIcon != null)
		{
			vIcon.src = "/system/modules/uk.co.tssi.website/resources/images/alert1.gif";
		}
	}

	return vMsg;
}

function validateNotBlank(vCombo, vName, vIcon)
{
	var vMsg = "";
	
	if(vCombo.value == "blank")
	{
		vMsg = "Please select a " + vName + ".\r\n";
		if(vIcon != null)
		{
			vIcon.src = "/system/modules/uk.co.tssi.website/resources/images/alert1.gif";
		}
	}

	return vMsg;
}

function ClearCombo(vCombo)
{
	if(vCombo.options.remove != null)
	{
		while(vCombo.options.length > 0)
		{
			vCombo.options.remove(0);
		}
	}
	else
	{
		vCombo.innerHTML = "";
	}
}

function AddCombo(vCombo, vText, vValue, vSelected)
{
	if(vCombo.options.remove != null)
	{
		var vOption = document.createElement("OPTION");
		vCombo.options.add(vOption);
		vOption.innerText = vText;
		vOption.value = vValue;
		vOption.selected = vSelected;
	}
	else
	{
		var vHTML = "<OPTION value='";
		vHTML += vValue;
		vHTML += "' ";
		if(vSelected)
		{
			vHTML += "selected ";
		}
		vHTML += ">";
		vHTML += vText;
		vHTML += "</OPTION>";
		vCombo.innerHTML += vHTML;
	}
}

