//validate the form



	

	function validate() {



		var reg_email = /^\w+(\.\w+)*@\w+\.\w{2,3}$/;

		

		var checker = false;



		var email = document.getElementById( 'email' );

		

		email.onfocus = function() {

			_onfocus( "email_label" );

			checker = false;

		}

		

		if( !reg_email.test( email.value ) ) {

			_notval( "email_label" );

			checker = true;

		}



		var verifyemail = document.getElementById('verifyemail');

		

		verifyemail.onfocus = function() {

			_onfocus("verifyemail_label");

			checker = false;

		}

		if(email.value != verifyemail.value || email.value == ''){

			_notval("verifyemail_label");

			checker = true;

		}

		

		

	

		//check that important fields are not empty
		
		
		var cityname = document.getElementById('cityname');

		

		cityname.onfocus = function() {

			_onfocus( "cityname_label" );

			checker = false;

		}

		

		if(cityname.value == '-1'){

			_notval( 'cityname_label' );

			checker = true;

		}
		
		

		var fname = document.getElementById('fname');

		

		fname.onfocus = function() {

			_onfocus( "fname_label" );

			checker = false;

		}

		

		if(fname.value == ''){

			_notval( 'fname_label' );

			checker = true;

		}

		

		var lname = document.getElementById('lname');

		

		lname.onfocus = function() {

			_onfocus( "lname_label" );

			checker = false;

		}

		

		if(lname.value == ''){

			_notval( 'lname_label' );

			checker = true;

		}

		
		
		
		
		var address = document.getElementById('address');

		address.onfocus = function() {
			_onfocus( "address_label" );
			checker = false;
		}


		if(address.value == ''){
			_notval( 'address_label' );
			checker = true;
		}
		
		
		var city = document.getElementById('city');

		city.onfocus = function() {
			_onfocus( "city_label" );
			checker = false;
		}


		if(city.value == ''){
			_notval( 'city_label' );
			checker = true;
		}
		
		
		var prov = document.getElementById('prov');

		prov.onfocus = function() {
			_onfocus( "prov_label" );
			checker = false;
		}


		if(prov.value == ''){
			_notval( 'prov_label' );
			checker = true;
		}
		
		
		var pcode = document.getElementById('pcode');

		pcode.onfocus = function() {
			_onfocus( "pcode_label" );
			checker = false;
		}


		if(pcode.value == ''){
			_notval( 'pcode_label' );
			checker = true;
		}
		
		
		var country = document.getElementById('country');

		country.onfocus = function() {
			_onfocus( "country_label" );
			checker = false;
		}


		if(country.value == ''){
			_notval( 'country_label' );
			checker = true;
		}
		

	

		var area = document.getElementById('areacode');

		var pref = document.getElementById('prefix');

		var suf = document.getElementById('suffix');

		var telephone = area+pref+suf;

		

		

		area.onfocus = function(){

			_onfocus('telephone_label');

			checker = false;

		}

		

		if(area.value  == ''){

			_notval('telephone_label');

			checker = true;

		}

		

		pref.onfocus = function(){

			_onfocus('telephone_label');

			checker = false;

		}

		if(pref.value == ''){

			_notval('telephone_label');

			checker = true;

		}

		suf.onfocus = function(){

			_onfocus('telephone_label');

			checker = false;

		}

		if(suf.value == ''){

			_notval('telephone_label');

			checker = true;

		}

		



		



		if( checker ) {

			var message = 'Please correct field(s) with red labels.';

			$('error').setHTML(message);

			

			$('error').setStyles('color :#FF0000;font-size:10px;');

			

			alert('Please correct fields(s) with red labels.');

		

			

			return;

		}

		

		//finally submit the form if all data of the form are correct/valid

		goto();

		

	}

	

	function _notval( id ) {

			//document.getElementById( id ).style.backgroundColor = "red";

			document.getElementById( id ).style.color = "red";

	}

		

	function _onfocus( id ) {

			//document.getElementById( id ).style.backgroundColor = "white";

			document.getElementById( id ).style.color = "#c23c97";

	}

	 

	



	function goto() {

		



		$('CheckoutForm').setProperty('action','review_order.php');

		$('CheckoutForm').setProperty('encoding','multipart/form-data');

		

		var task = new Element('input',

							{

								'type': 'hidden', 

								'name':'task', 

								'value':'vieworder'

							}).injectInside($('CheckoutForm'));

		

		$('CheckoutForm').submit();

	

			

	}

	

