
function LoadData() {

//	alert("loading");

	var ele;

	if (theForm.DecoderType[1].checked) {

		ele = document.getElementById("travela");
		ele.style.display = 'block';
		ele = document.getElementById("travelb");
		ele.style.display = 'block';
		ele = document.getElementById("travelc");
		ele.style.display = 'block';
		ele = document.getElementById("travelf");
		ele.style.display = 'block';

		ele = document.getElementById("travel1");
		ele.style.display = 'block';
		ele = document.getElementById("travel2");
		ele.style.display = 'block';
		ele = document.getElementById("travel3");
		ele.style.display = 'block';

	}else{

		ele = document.getElementById("travela");
		ele.style.display = 'none';
		ele = document.getElementById("travelb");
		ele.style.display = 'none';
		ele = document.getElementById("travelc");
		ele.style.display = 'none';
		ele = document.getElementById("travelf");
		ele.style.display = 'none';

		ele = document.getElementById("travel1");
		ele.style.display = 'none';
		ele = document.getElementById("travel2");
		ele.style.display = 'none';
		ele = document.getElementById("travel3");
		ele.style.display = 'none';
	}
}

function CheckDecoderType(dectype) {

//	alert("change radio");

	strType = dectype.value;

//	alert(strType);

	var ele;

	if (strType == "Permanent"){

//		alert("is permanent");

		ele = document.getElementById("travela");
		ele.style.display = 'none';
		ele = document.getElementById("travelb");
		ele.style.display = 'none';
		ele = document.getElementById("travelc");
		ele.style.display = 'none';
		ele = document.getElementById("travelf");
		ele.style.display = 'none';

		ele = document.getElementById("travel1");
		ele.style.display = 'none';
		ele = document.getElementById("travel2");
		ele.style.display = 'none';
		ele = document.getElementById("travel3");
		ele.style.display = 'none';
		
	}else if (strType == "Traveller"){

		ele = document.getElementById("travela");
		ele.style.display = 'block';
		ele = document.getElementById("travelb");
		ele.style.display = 'block';
		ele = document.getElementById("travelc");
		ele.style.display = 'block';
		ele = document.getElementById("travelf");
		ele.style.display = 'block';

		ele = document.getElementById("travel1");
		ele.style.display = 'block';
		ele = document.getElementById("travel2");
		ele.style.display = 'block';
		ele = document.getElementById("travel3");
		ele.style.display = 'block';

	}

}

function IsNumeric(strString) {
	//  check for valid numeric strings	

	var strValidChars = "0123456789";
	var strChar;
	var blnResult = true;

	if (strString.length == 0) 
		return false;

	//  test strString consists of valid characters listed above
  	for (i = 0; i < strString.length && blnResult == true; i++){
   
  		strChar = strString.charAt(i);
	
	    if (strValidChars.indexOf(strChar) == -1){
			blnResult = false;
	    }
    }

	return blnResult;
}

function CheckEmail(strAddress)
{

//	alert(strAddress);
	
	if (strAddress.indexOf("@") == -1){

//		alert("Please input a valid email address!")

		return false
	}

	return true;
	
}


function CheckForm() {

	strerrors = "";
	bError = 0;

	if ((theForm.FirstName.value.length==0) || (theForm.LastName.value.length==0)){
		bError = 1;
		strerrors = strerrors + "- Your First & Last names\n";
	}

	if (theForm.FirstName.value.length > 40){
		bError = 1;
		strerrors = strerrors + "- Your First Name must be less than 40 characters\n";
	}

	if (theForm.LastName.value.length > 60){
		bError = 1;
		strerrors = strerrors + "- Your Last Name must be less than 60 characters\n";
	}

	if (theForm.CompanyName.value.length > 50){
		bError = 1;
		strerrors = strerrors + "- Company Name must be less than 50 characters\n";
	}

	if ((theForm.PostalAddress.value.length==0) || (theForm.PostalTown.value.length==0) || (theForm.PostalPostCode.value.length==0)){
		bError = 1;
		strerrors = strerrors + "- Full Postal Address - Address, Town & Post Code\n";
	}

	if (theForm.PostalAddress.value.length > 100){
		bError = 1;
		strerrors = strerrors + "- Postal Address must be less than 100 characters\n";
	}

	if (theForm.PostalAddress2.value.length > 100){
		bError = 1;
		strerrors = strerrors + "- Postal Address 2 must be less than 100 characters\n";
	}

	if (theForm.PostalTown.value.length > 40){
		bError = 1;
		strerrors = strerrors + "- Town must be less than 40 characters\n";
	}

	if (theForm.PostalPostCode.value.length != 4){
		bError = 1;
		strerrors = strerrors + "- Post Code must be 4 characters\n";
	}

	if (IsNumeric(theForm.PostalPostCode.value) != true){
		bError = 1;
		strerrors = strerrors + "- Post Code must be numeric\n";
	}	
	
	if ((theForm.PhoneNumber.value.length==0) && (theForm.MobileNumber.value.length==0)){
		bError = 1;
		strerrors = strerrors + "- Phone and/or Mobile Number\n";
	}

	strPhoneNo = theForm.PhoneNumber.value;

	strPhoneNo = strPhoneNo.replace(/ /g, "");

	if (strPhoneNo != "" && strPhoneNo.length != 10){
		bError = 1;
		strerrors = strerrors + "- Phone Number must be 10 characters and include Area Code & Number\n";
	}

	strFaxNo = theForm.FaxNumber.value;

	strFaxNo = strFaxNo.replace(/ /g, "");

	if (strFaxNo != "" && strFaxNo.length != 10){
		bError = 1;
		strerrors = strerrors + "- Fax Number must be 10 characters and include Area Code & Number\n";
	}

	strMobileNo = theForm.MobileNumber.value;

	strMobileNo = strMobileNo.replace(/ /g, "");

	if (strMobileNo != "" && strMobileNo.length != 10){
		bError = 1;
		strerrors = strerrors + "- Mobile Number must be 10 charaters\n";
	}
	
	if (theForm.EmailAddress.value.length==0){
		bError = 1;
		strerrors = strerrors + "- Email Address is required for verification\n";
	}

	if (theForm.EmailAddress.value.length > 100){
		bError = 1;
		strerrors = strerrors + "- Email Address must be less than 100 characters\n";
	}

	if (CheckEmail(theForm.EmailAddress.value) != true){
		bError = 1;
		strerrors = strerrors + "- Email Address is invalid\n";
	}

	if (theForm.Model.value.length > 40){
		bError = 1;
		strerrors = strerrors + "- The Decoder Model must be less than 40 characters\n";
	}

	if (theForm.SmartCardNo.value.length==0){
		bError = 1;
		strerrors = strerrors + "- Smart Card Number\n";
	}

	strSmartCardNo = theForm.SmartCardNo.value;

	strSmartCardNo = strSmartCardNo.replace(/ /g, "");

	if (strSmartCardNo.length != 11){
		bError = 1;
		strerrors = strerrors + "- Smart Card No must be 11 characters\n";
	}

	// site address for permanent installation

	if (theForm.DecoderType[0].checked){

		if ((theForm.SiteAddress.value.length==0) || (theForm.SiteTown.value.length==0) || (theForm.SitePostCode.value.length==0)){
			bError = 1;
			strerrors = strerrors + "- Full Site Address - Address, Town & Post Code\n";
		}

		if (theForm.SiteAddress.value.length > 100){
			bError = 1;
			strerrors = strerrors + "- Site Address must be less than 100 characters\n";
		}

		if (theForm.SiteAddress2.value.length > 100){
			bError = 1;
			strerrors = strerrors + "- Site Address 2 must be less than 100 characters\n";
		}

		if (theForm.SiteTown.value.length > 40){
			bError = 1;
			strerrors = strerrors + "- Site Town must be less than 40 characters\n";
		}

		if (theForm.SitePostCode.value.length != 4){
			bError = 1;
			strerrors = strerrors + "- Site Post Code must be 4 characters\n";
		}

		if (IsNumeric(theForm.SitePostCode.value) != true){
			bError = 1;
			strerrors = strerrors + "- Site Post Code must be numeric\n";
		}	
	
	}

	// travel intinerary for traveler

	if (theForm.DecoderType[1].checked){

		if ((theForm.TravelDates.value.length==0) && (theForm.TravelItinerary.value.length==0)) {

			bError = 1;
			strerrors = strerrors + "- Provide Travel Dates & Itinerary\n";

		}else{
		
			if (theForm.TravelDates.value.length==0) {

				bError = 1;
				strerrors = strerrors + "- Provide Travel Dates\n";
			}

			if (theForm.TravelItinerary.value.length==0) {

				bError = 1;
				strerrors = strerrors + "- Provide Travel Itinerary\n";
			}
		}
				
		if (theForm.TravelDates.value.length > 100){
			bError = 1;
			strerrors = strerrors + "- Keep Travel Dates less than 100 characters\n";
		}

		if (theForm.TravelItinerary.value.length > 400){
			bError = 1;
			strerrors = strerrors + "- Keep Travel Itinerary less than 400 characters\n";
		}

		if ((theForm.TravelDates.value.length + theForm.TravelItinerary.value.length) > 500){
			bError = 1;
			strerrors = strerrors + "- Keep Travel Information less than 500 characters total\n";
		}

	}

	if (theForm.Notes.value.length > 200){
		bError = 1;
		strerrors = strerrors + "- Keep Extra Information less than 200 characters\n";
	}


/*
	if(document.getElementsByName('firstname')[0].value == "" && document.getElementsByName('surname')[0].value == ""){

		bError = 1;
		strerrors = strerrors + "- Your First name & Surname\n";
	}

*/

	if (bError == 1) {
		window.alert("Please correct these details\n" + strerrors + "\nThanks");
		return false;
	}


//	document.getElementById('registerform').submit();

//	clearForm();

}

function CheckfffForm(theForm) {
//	if ((theForm.Name.value.length==0) || (theForm.Name.value.length><%=NameLength%>)) { alert("'Shareholder's Name' field is required and must be less than <%=OrganisationLength%> characters."); return false; }
//	if ((theForm.Address.value.length==0) || (theForm.Address.value.length><%=AddressLength%>)) { alert("'Address' field is required and must be less than <%=AddressLength%> characters."); return false; }
//	if (theForm.Identification.value.length=0) { alert("'SRN or HIN' field is required."); return false; }
//	if (theForm.Question.value.length=0) { alert("'Question' field is required and must be less than <%=DateTimeLength%> characters."); return false; }
	return true;
}
