function IsJpg(cFormField)

{

	var cSuffix = cFormField.value.substr((cFormField.value.length-4),4);

	if(cSuffix.toLowerCase() != '.jpg') 

	{

		alert("You can only upload images with a 'jpg' extension"); 

		return false;

	}

	return true;

}



function IsEmpty(aTextField) {

   if ((aTextField.value.length==0) || (aTextField.value==null)) {

      return true;

   }

   else { return false; }

}





function IsNull(aTextField) {

   if ((aTextField.value.length==0) || (aTextField.value==null)) {

      return false;

   }

   else { return true; }

}





function IsNumeric(sText)

{

	var IsOK = true;

	var sValidChars = "0123456789. ";

	IsOK = searchCharacterList(sText, sValidChars);

	return IsOK;

}

function IsDecimalInteger(sText)

{

	var IsOK = true;

	var sValidChars = "0123456789.";

	IsOK = searchCharacterList(sText, sValidChars);

	return IsOK;

}



function IsCapAlphanumericOrSpace(sText)

{

	var IsOK = true;

	var sValidChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ ";

	IsOK = searchCharacterList(sText, sValidChars);

	return IsOK;

}



function IsAlphanumericOrSpace(sText)

{

	var IsOK = true;

	var sValidChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";

	IsOK = searchCharacterList(sText, sValidChars);

	return IsOK;

}



function IsUsername(sText)

{

	var IsOK = true;

	var sValidChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_";

	IsOK = searchCharacterList(sText, sValidChars);

	return IsOK;

}


function IsPassword(sText)

{

	var IsOK = true;

	var sValidChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_#";

	IsOK = searchCharacterList(sText, sValidChars);

	return IsOK;

}



function IsDateDDMMYYYY(sText)

{

	if (sText.substr(2, 1) != '/') { return false; }

	if (sText.substr(5, 1) != '/') { return false; }

	if (sText.length != 10) { return false; }

	var sValidDayChars = "0123456789";

	if (!searchCharacterList(sText.substr(0, 2), sValidDayChars)) { return false; }



	var sValidMonthChars = "0123456789";

	if (!searchCharacterList(sText.substr(3, 2), sValidMonthChars)) { return false; }



	var sValidYearChars = "0123456789";

	if (!searchCharacterList(sText.substr(6, 4), sValidYearChars)) { return false; }

	return true;

}



function IsRudeText(sText)

{

	var IsOK = false;

	var aPartialWord = new Array('fuck', 'shit', 'arse');

	// Words in aFullWord must be standalone words

	var aFullWord = new Array('cunt');

	var j;



	sText = ' '+ sText.toLowerCase() +' ';	// Need to find words at start & end of text

	for (j = 0; j < aPartialWord.length && IsOK == false; j++) 

	{

		if (sText.search(aPartialWord[j]) > 0) { IsOK = true; }

	}

	for (j = 0; j < aFullWord.length && IsOK == false; j++) 

	{

		if (sText.search(aFullWord[j] + ' ') > 0) { IsOK = true; }

	}

	return IsOK;

}



function searchCharacterList(sText, sValidChars)

{

   var IsOK = true;

   var Char, i;



   for (i = 0; i < sText.length && IsOK == true; i++) 

   {

      Char = sText.charAt(i); 

      if (sValidChars.indexOf(Char) == -1) 

      {

         IsOK = false;

      }

   }

   return IsOK;

}



function IsValidEmail(str) {

   return (str.indexOf("@") > 0);

}









	function ValidateMultiple(form)

			{

				var cErrorBackground = '#FFFFEE';	





		if(IsNull(form.expiryDate)) {



				if(!IsDateDDMMYYYY(form.expiryDate.value)) 

				{ 

					alert('Expiry date must be in format DD/MM/YYYY (e.g. 01/12/2010)');

					form.expiryDate.style.background = cErrorBackground; 

					form.expiryDate.focus(); 
					if (window.event) event.returnValue = false;
					return false; 

				}

			}


		


		    var v = new RegExp();

		    v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+");

		

		    if (!v.test(form.productLink.value)) {

		        alert("You must supply a valid URL (e.g. http://)");
				if (window.event) event.returnValue = false;
		        return false;

		    } 

	


				if(IsEmpty(form.cashDiscount) && IsEmpty(form.percDiscount) && IsEmpty(form.regBonus)) 

					{ 
					
						alert('Must have one of percentage discount, cash discount or reg bonus.');

						form.percDiscount.style.background = cErrorBackground;

						form.percDiscount.focus();
						if (window.event) event.returnValue = false;
						return false;

					}
		
		




			if(IsNull(form.cashDiscount)) 

				{ 

					if(IsNull(form.percDiscount)) {

						window.alert("Cannot have a percentage discount and cash discount together.");

						form.percDiscount.focus();
						if (window.event) event.returnValue = false;
						return false;	

					}

					

				

				}

	

	

			if(IsNull(form.percDiscount)) 

				{ 

					var number = document.getElementById("PercDisc").value;



					if ( (number >= 0) && (number <= 100) ){

					return true;

					}

					else {

					window.alert("Please enter a percentage between 1 and 100.");

					form.percDiscount.focus();
					if (window.event) event.returnValue = false;
					return false;

					}	



				}



			if(IsNull(form.cashDiscount)) 

				{ 

					var number = document.getElementById("cashDisc").value;



					if ( (number >= 0) && (number <= 1000000) ){

					return true;

					}

					else {

					window.alert("Please enter an integer for cash discount.");

					form.cashDiscount.focus();
					if (window.event) event.returnValue = false;
					return false;

					}		

				}

		

			if(IsNull(form.regBonus)) 

				{ 

					var number = document.getElementById("regBonus").value;



					if ( (number >= 1) && (number <= 1000000) ){

					return true;

					}

					else {

					window.alert("Please enter an integer for reg bonus.");

					form.regBonus.focus();
					if (window.event) event.returnValue = false;
					return false;

					}		

				}

		return true;

			}
			
			
	function ValidateUnique(form){
	
		var cErrorBackground = '#FFFFEE';	
			
				var number = document.getElementById("otrPrice").value;
	
					if ( (number >= 1) && (number <= 1000000) ){
					
			
					}

					else {

					window.alert("Please enter a valid otr price.");

					form.otrPrice.focus();
					if (window.event) event.returnValue = false;
					return false;

					}
				
					
					var v = new RegExp();

					v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+");

					if (!v.test(form.productLink.value)) {

						alert("You must supply a valid URL (e.g. http://)");
						if (window.event) event.returnValue = false;
						return false;

					} 
						
				if(IsNull(form.expiryDate)) {

					if(!IsDateDDMMYYYY(form.expiryDate.value)) 

					{ 

						alert('Expiry date must be in format DD/MM/YYYY (e.g. 01/12/2010)');

						form.expiryDate.style.background = cErrorBackground; 

						form.expiryDate.focus(); 
						if (window.event) event.returnValue = false;
						return false; 

					}

				}
				
				var userID = form.dealtype.value;
				var findList = /nearlynew/;
			
				if(findList.test(userID)){
				
					if(IsEmpty(form.otrMileage)) {
								alert('You must input a mileage up to 5000 miles. e.g. 3895');
								form.otrMileage.style.background = cErrorBackground; 
								form.otrMileage.focus(); 
								if (window.event) event.returnValue = false;
								return false; 
					}
					else if(!IsNumeric(form.otrMileage.value)){
								alert('Mileage must be an integer. e.g. 3895');
								form.otrMileage.style.background = cErrorBackground; 
								form.otrMileage.focus(); 
								if (window.event) event.returnValue = false;
								return false; 
					}
					else if(form.otrMileage.value > 5000){
								alert('Mileage can only be up to 5000. e.g. 3895');
								form.otrMileage.style.background = cErrorBackground; 
								form.otrMileage.focus(); 
								if (window.event) event.returnValue = false;
								return false; 
					}
					
					
					if(IsEmpty(form.otrRegDate)) {
								alert('You must input a vehicle registration date. e.g. 01/02/2010');
								form.otrRegDate.style.background = cErrorBackground; 
								form.otrRegDate.focus(); 
								if (window.event) event.returnValue = false;
								return false; 
					}
					else if(!IsDateDDMMYYYY(form.otrRegDate.value)) 
					{ 
						alert('Reg Date must be in format DD/MM/YYYY (e.g. 01/12/2010)');
						form.otrRegDate.style.background = cErrorBackground; 
						form.otrRegDate.focus(); 
						if (window.event) event.returnValue = false;
						return false; 
					}
					
					if(IsEmpty(form.otrRegLetter)) {
								alert('You must input a vehicle Reg Letter. e.g. 59');
								form.otrRegLetter.style.background = cErrorBackground; 
								form.otrRegLetter.focus(); 
								if (window.event) event.returnValue = false;
								return false; 
					}

				}
				
				

				
					
			return true;
	}
