function notEmpty(elem){

	var errorName = 'error_'+elem.name;

	if(elem.value.length == 0){

		document.getElementById(errorName).style.display='block';	//Make the red asterisk show up next to the error field
		elem.focus();

		return false;
	}

	document.getElementById(errorName).style.display='none';
	return true;
}

function notEmptyTwo(elem1, elem2){
	if((elem1.value.length == 0) && (elem2.value.length == 0)){

		var errorName = 'error_'+elem2.name;

		document.getElementById(errorName).style.display='block';	//Make the red asterisk show up next to the error field
		elem2.focus();

		return false;
	}
	return true;
}

function isInteger(elem, sText)
{

   var ValidChars = "0123456789-";
   var IsNumber=true;
   var Char;


   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {

			var errorName = 'error_'+elem.name;
			document.getElementById(errorName).style.display='block';	//Make the red asterisk show up next to the error field
			elem.focus();
	        IsNumber = false;

         }
      }
   return IsNumber;
}

function moneyValidator(elem){
	var moneyExp = /^[0-9\.\-]+\.[0-9]{2,4}$/;
	if(elem.value.match(moneyExp)){
		return true;
	}else{
		var errorName = 'error_'+elem.name;

		document.getElementById(errorName).style.visibility='visible';	//Make the red asterisk show up next to the error field
		elem.focus();
	}
}

function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function validate_online_quotation_search_request(){


	// Make quick references to our fields
	var val_name = document.getElementById('Name');
	var val_email = document.getElementById('Email');
	var val_phone = document.getElementById('Phone');

	//Hide the asterisks prior to any of them showing up (otherwise they persist)
	//document.getElementById('error_name').style.display='block';

	// Check each input in the booking that it appears in the form!

	if(notEmpty(val_name)){
		if(notEmpty(val_phone)){
			if(notEmpty(val_email)){
				if (jcap()){
			   		return true;
				}
			}
		}
	}
	return false;
}

function validate_invoice_finance_cash_calculator(){

	// Make quick references to our fields

	var val_salesledgervalue = document.getElementById('SalesLedgerValue');
	var val_amountover20days = document.getElementById('AmountOver120Days');
	var val_industrysector = document.getElementById('IndustrySector');

	//Hide the asterisks prior to any of them showing up (otherwise they persist)
	//document.getElementById('error_name').style.display='block';

	// Check each input in the booking that it appears in the form!

	if(notEmpty(val_salesledgervalue)){
		if (isInteger(val_salesledgervalue, val_salesledgervalue.value)){
			if(notEmpty(val_amountover20days)){
				if (isInteger(val_amountover20days, val_amountover20days.value)){
					if(notEmpty(val_industrysector)){
				   		return true;
					}
				}
			}
		}
	}
	return false;
}


function validate_online_application(){

	// Make quick references to our fields
	var val_name = document.getElementById('Name');
	var val_email = document.getElementById('Email');
	var val_phone = document.getElementById('Phone');

	//Hide the asterisks prior to any of them showing up (otherwise they persist)
	//document.getElementById('error_name').style.display='block';

	// Check each input in the booking that it appears in the form!

	if(notEmpty(val_name)){
		if(notEmpty(val_phone)){
			if(notEmpty(val_email)){
				if (jcap()){
			   		return true;
				}
			}
		}
	}
	return false;
}

function validate_online_asset_finance_quotation_search_request(){


	// Make quick references to our fields
	var val_name = document.getElementById('Name');
	var val_email = document.getElementById('Email');
	var val_phone = document.getElementById('Phone');

	//Hide the asterisks prior to any of them showing up (otherwise they persist)
	//document.getElementById('error_name').style.display='block';

	// Check each input in the booking that it appears in the form!

	if(notEmpty(val_name)){
		if(notEmpty(val_phone)){
			if(notEmpty(val_email)){
				if (jcap()){
			   		return true;
				}
			}
		}
	}
	return false;
}

function validate_call_me_back(){

	// Make quick references to our fields
	var val_name = document.getElementById('Name');
	var val_phone = document.getElementById('Telephone');

	//Hide the asterisks prior to any of them showing up (otherwise they persist)
	//document.getElementById('error_name').style.display='block';

	// Check each input in the booking that it appears in the form!

	if(notEmpty(val_name)){
		if(notEmpty(val_phone)){
			if (jcap()){
		   		return true;
			}
		}
	}
	return false;
}

function validate_turnover(){

	// Make quick references to our fields
	var val_question7 = document.getElementById('question7');

	//Hide the asterisks prior to any of them showing up (otherwise they persist)
	//document.getElementById('error_name').style.display='block';

	// Check each input in the booking that it appears in the form!

	if(notEmpty(val_question7)){

		if(isInteger(val_question7, val_question7.value)){

		   	return true;
		}
	}
	return false;
}

function validate_percentage(){

	// Make quick references to our fields
	var val_question8 = document.getElementById('question8');

	//Hide the asterisks prior to any of them showing up (otherwise they persist)
	//document.getElementById('error_name').style.display='block';

	// Check each input in the booking that it appears in the form!

	if(notEmpty(val_question8)){

		if(isInteger(val_question8, val_question8.value)){

		   	return true;
		}
	}
	return false;
}

function validate_special_offers(){

	// Make quick references to our fields
	var val_name = document.getElementById('Name');
	var val_email = document.getElementById('Email');

	//Hide the asterisks prior to any of them showing up (otherwise they persist)
	//document.getElementById('error_name').style.display='block';

	// Check each input in the booking that it appears in the form!

	if(notEmpty(val_name)){
		if(notEmpty(val_email)){
			if (jcap()){
		   		return true;
			}
		}
	}
	return false;
}


function validate_email() {
var where = document.getElementById("news_email").value.indexOf("@");

if (document.getElementById("news_email").value.length < 1) {
  window.alert("You must include your e-mail address.");
  return false;
}
if (where < 0) {
  window.alert("You must enter a valid email address");
  return false;
}
return true;
}


