/*
 * Copyright Infoterra Ltd 2005. All Rights Reserved.
 * 
 * This file must not be stored, copied, reproduced or distributed in whole or
 * in part or used for any purposes other than for that for which it has been
 * supplied, without the prior written permission of Infoterra. Any unauthorised
 * use may result in criminal or civil action. No liability is assumed for any
 * opinions or views that may be expressed in written materials. All software is
 * provided "AS IS," and no warranty of any kind is provided. All express or
 * implied warranties or representations are excluded, including any implied
 * warranty of satisfactory quality, fitness for a particular purpose or
 * non-infringement. Infoterra/its Licensors shall not be liable for any
 * damages, howsoever caused, as a result of the use, modification or
 * distribution of the software or its derivatives. In no event shall
 * Infoterra/its Licensors be liable for any special, incidental, punitive,
 * indirect or consequential loss, including but not limited to loss of profit,
 * loss of revenue, loss of data or loss of business arising out of the use of
 * or inability to use the software, even if Infoterra has been advised of the
 * possibility of the likeliness of such damages.
 */

/* Copy Invoice Address to Delivery Address */
function copyAddress()
{
	if (document.registerFrm.dAddeqIAdd.checked == true) // .checked==true required for i.e.
	{
		document.registerFrm.deliveryAddress1.value = document.registerFrm.invoiceAddress1.value;
		document.registerFrm.deliveryAddress2.value = document.registerFrm.invoiceAddress2.value;
		document.registerFrm.deliveryAddress3.value = document.registerFrm.invoiceAddress3.value;
		document.registerFrm.deliveryCity.value = document.registerFrm.invoiceCity.value;
		document.registerFrm.deliveryCounty.value = document.registerFrm.invoiceCounty.value;
		document.registerFrm.deliveryPostCode.value = document.registerFrm.invoicePostCode.value;
		document.registerFrm.deliveryCountry.value = document.registerFrm.invoiceCountry.value;
	}
	else
	{
		document.registerFrm.deliveryAddress1.value = '';
		document.registerFrm.deliveryAddress2.value = '';
		document.registerFrm.deliveryAddress3.value = '';
		document.registerFrm.deliveryCity.value = '';
		document.registerFrm.deliveryCounty.value = '';
		document.registerFrm.deliveryPostCode.value = '';
		document.registerFrm.deliveryCountry.value = '';
	}

}

var already_sent = 0;
function validateForm()
{
	var myForm = document.registerFrm;
	var isWrong = false;
	if (already_sent == 0)
	{
		if (myForm.authorisationCode != null)
		{
			if (myForm.authorisationCode.value == "")
			{
				document.getElementById("authorisationCodeStatus").innerHTML = "* [value must be supplied]";
				isWrong = true;
			}
			else if (myForm.authorisationCode.value.length < 8)
			{
				document.getElementById("authorisationCodeStatus").innerHTML = "* [minimum 8 characters]";
				isWrong = true;
			}
			else
			{
				document.getElementById("authorisationCodeStatus").innerHTML = "*";	
			}
		}
		
		if (myForm.contactName.value == "")
		{
			document.getElementById("contactNameStatus").innerHTML = "* [value must be supplied]";
			isWrong = true;
		}
		else
		{
			document.getElementById("contactNameStatus").innerHTML = "*";
		
			
		}
		
		if (myForm.telephone.value == "")
		{
			document.getElementById("telephoneStatus").innerHTML = "* [value must be supplied]";
			isWrong = true;
		}
		else
		{
			document.getElementById("telephoneStatus").innerHTML = "*";
		}
		
		if (myForm.email.readOnly == false)
		{
			if (myForm.email.value == "")
			{
				document.getElementById("emailStatus").innerHTML = "* [value must be supplied]";
				isWrong = true;
			}
			else
			{
				document.getElementById("emailStatus").innerHTML = "*";
			}
			
			if (myForm.email.value != myForm.email2.value)
			{
				document.getElementById("email2Status").innerHTML = "* [email does not match]";
				isWrong = true;
			}
			else
			{
				document.getElementById("email2Status").innerHTML = "*";
			}
			
		}
		else
		{
			if (myForm.email.value != myForm.email2.value)
			{
				document.getElementById("email2Status").innerHTML = "* [email does not match]";
				isWrong = true;
			}
			else
			{
				document.getElementById("email2Status").innerHTML = "*";
			}
		}
		
		if (myForm.passwordOld == null )
		{
			if (myForm.password.value == myForm.password2.value)
			{
				if (myForm.password.value == "")
				{
					document.getElementById("passwordStatus").innerHTML = "* [value must be supplied]";
					isWrong = true;
				}
				else if (myForm.password.value.length < 8) 
				{
					document.getElementById("passwordStatus").innerHTML = "* [minimum 8 characters]";
					document.getElementById("password2Status").innerHTML = "*";
					isWrong = true;
				}
				else 
				{
					document.getElementById("passwordStatus").innerHTML = "*";
					document.getElementById("password2Status").innerHTML = "*";
				}
			}
			else if (myForm.password.value != myForm.password2.value)
			{		
				if (myForm.password.value == "")
				{
					document.getElementById("passwordStatus").innerHTML = "* [value must be supplied]";
					isWrong = true;
				}
				else if (myForm.password.value.length < 8)
				{
					document.getElementById("passwordStatus").innerHTML = "* [minimum 8 characters]";
					isWrong = true;
				}
				else 
				{
					document.getElementById("passwordStatus").innerHTML = "*";
				}
				
				document.getElementById("password2Status").innerHTML = "* [password does not match]";
				isWrong = true;	
			}
			
		}
		else
		{
			if (myForm.passwordOld.value == "")
			{
				document.getElementById("passwordOldStatus").innerHTML = "* [value must be supplied]";
				isWrong = true;
			}
			else if (myForm.passwordOld.value.length < 8)
			{
				document.getElementById("passwordOldStatus").innerHTML = "* [minimum 8 characters]";
				isWrong = true;
			}
			else
			{
				document.getElementById("passwordOldStatus").innerHTML = "*";
			}
								
			if (myForm.password.value == myForm.password2.value)
			{
				if ((myForm.password.value.length < 8) && (myForm.password.value != "")) 
				{
					document.getElementById("passwordStatus").innerHTML = "* [minimum 8 characters]";
					document.getElementById("password2Status").innerHTML = "*";
					isWrong = true;
				}
				else 
				{
					document.getElementById("passwordStatus").innerHTML = "*";
					document.getElementById("password2Status").innerHTML = "*";
				}
			}
			else
			{	
				document.getElementById("password2Status").innerHTML = "* [value must match new password]";
				isWrong = true;
				
				if (myForm.password.value == "")
				{
					document.getElementById("passwordStatus").innerHTML = "* [value must be supplied]";
					isWrong = true;
				}
				else if (myForm.password.value.length < 8) 
				{
					document.getElementById("passwordStatus").innerHTML = "* [minimum 8 characters]";
					isWrong = true;
				}
				else 
				{
					document.getElementById("passwordStatus").innerHTML = "*";
				}
			}
		}
		
		if (myForm.invoiceAddress1 != null)
		{
			if (myForm.invoiceAddress1.value == "")
			{
				document.getElementById("invoiceAddress1Status").innerHTML = "* [value must be supplied]";
				isWrong = true;
			}
			else
			{
				document.getElementById("invoiceAddress1Status").innerHTML = "*";
			}
		
			if (myForm.invoiceCity.value == "")
			{
				document.getElementById("invoiceCityStatus").innerHTML = "* [value must be supplied]";
				isWrong = true;
			}
			else
			{
				document.getElementById("invoiceCityStatus").innerHTML = "*";
			}
		
			if (myForm.invoicePostCode.value == "")
			{
				document.getElementById("invoicePostCodeStatus").innerHTML = "* [value must be supplied]";
				isWrong = true;
			}
			else
			{
				document.getElementById("invoicePostCodeStatus").innerHTML = "*";
			}
		
			if (myForm.invoiceCountry.value == "")
			{
				document.getElementById("invoiceCountryStatus").innerHTML = "* [value must be supplied]";
				isWrong = true;
			}
			else 
			{
				document.getElementById("invoiceCountryStatus").innerHTML = "*";
			}
		}
		
		if (myForm.deliveryAddress1.value == "")
		{
			document.getElementById("deliveryAddress1Status").innerHTML = "* [value must be supplied]";
			isWrong = true;
		}
		else
		{
			document.getElementById("deliveryAddress1Status").innerHTML = "*";
		}
		
		if (myForm.deliveryCity.value == "")
		{
			document.getElementById("deliveryCityStatus").innerHTML = "* [value must be supplied]";
			isWrong = true;
		}
		else
		{
			document.getElementById("deliveryCityStatus").innerHTML = "*";
		}
		
		if (myForm.deliveryPostCode.value == "")
		{
			document.getElementById("deliveryPostCodeStatus").innerHTML = "* [value must be supplied]";
			isWrong = true;
		}
		else
		{
			document.getElementById("deliveryPostCodeStatus").innerHTML = "*";
		}
		
		if (myForm.deliveryCountry.value == "")
		{
			document.getElementById("deliveryCountryStatus").innerHTML = "* [value must be supplied]";
			isWrong = true;
		}
		else 
		{
			document.getElementById("deliveryCountryStatus").innerHTML = "*";
		}
	
		if (isWrong == false)
		{	
			if(confirm("Are you sure?"))
			{
				already_sent = 1;
				return true;
			}			
			else
			{
				return false;
			}
		}
	}
	else
	{
		alert("Data already sent.");
	}

	return false;
}