//<![CDATA[

	var validaForm = {

		color : '#DC143C',
		errors : 0,
		extension : '|jpg|jpeg|png|gif|',

		extensionCheck : function (imgValue) {
				
			var ext = 		imgValue.split('/');
			ext = 			ext[ext.length - 1];
			ext = 			ext.split('.')[1];

			var exp = new RegExp (ext, 'i');
			
			if (exp.test(validaForm.extension)) {
				
				return true;
			}
			
			return false;
		},
		
		getElementsByClass : function(classToGet) {

			var allPageTags = document.getElementsByTagName("*");

			var el = new Array();

			for (var i = 0; i < allPageTags.length; i++) {

				if (allPageTags[i].className == classToGet) {
					el[i] = allPageTags[i];
				}
			}

			return el;
		},

		checkForm : function (idFormToCheck, tag, tagValue) {

			if (tagValue == null) {
			
				tagValue = 'required';
			}
		
			/**
			* Tag pu� assumere i seguenti valori:
			* rel - class
			*/
		
			if (!Array.indexOf) {

				Array.prototype.indexOf = function(obj){

					for (var i = 0; i < this.length; i++){

						if(this[i] == obj){
							return i;
						}
					}
					return -1;
				}
			}

			var arrayRadio = new Array();
			
			formToCheck = document.getElementById(idFormToCheck);

			var allFormTags = formToCheck.getElementsByTagName('*');

			for (var i = 0, lung = allFormTags.length; i < lung; i++) {

				if (tag == 'rel' ) {
				
					if (allFormTags[i].getAttribute('rel') && allFormTags[i].getAttribute('rel') == tagValue) {
					
						validaForm.checkElement(allFormTags[i]);
					}
				}
				else if (tag == 'class') {
				
					if (allFormTags[i].className && allFormTags[i].className == className) {

						validaForm.checkElement(allFormTags[i]);
					}
				}
			}

			return validaForm.errors;
		},
		
		checkElement : function (element) {
		
			if (element.type == 'radio') {

				var radioName = element.name;

				if (arrayRadio.indexOf(radioName) == -1) {

					arrayRadio.push(radioName);

					var allFormInputTags = formToCheck.getElementsByTagName('input');
					var numInput = allFormInputTags.length;

					var radioError = new Array();
					var stato = 0;

					for (var j = 0; j < numInput; j++) {

						if (allFormInputTags[j].type == 'radio' && allFormInputTags[j].name == radioName ) {
							
							if (!allFormInputTags[j].checked) {
								radioError.push(allFormInputTags[j]);
							}
							else {
								radioError.push(allFormInputTags[j]);
								stato = 1;
							}
						}
					}
				}

				if (stato == 0) {
					validaForm.errors++;

					for (var j = 0; j < radioError.length; j++) {
						radioError[j].parentNode.style.backgroundColor = validaForm.color;
					}
				}
				else {
					for (var j = 0; j < radioError.length; j++) {
						radioError[j].parentNode.style.backgroundColor = '';
					}
				}
			}
			else if (element.type == 'text' || element.type == 'textarea' || element.type == 'file') {

				if (element.type == 'file') {
			
					if (element.value == '') {

						var message = document.createTextNode('Foto obbligatoria');
						elSpan = document.getElementById('imgRequired');

						var child = elSpan.firstChild;
						
						if (child != null) {
							elSpan.replaceChild(message, elSpan.firstChild);
						}
						else {
							elSpan.appendChild(message);
						}

						validaForm.errors++;
					}
					else {

						var message = document.createTextNode(' ');
						elSpan = document.getElementById('imgRequired');
						elSpan.replaceChild(message, elSpan.firstChild);

						result = validaForm.extensionCheck(element.value);

						if (!result) {

							var message = document.createTextNode('Estensione immagine non valida');
							elSpan = document.getElementById('imgRequired');
							elSpan.replaceChild(message, elSpan.firstChild);
							validaForm.errors++;
						}
					}
				}
				else if (element.type != 'file') {

					if (element.value == '') {

						element.style.backgroundColor = validaForm.color;
						validaForm.errors++;
					}
					else {

						element.style.backgroundColor = '';
					}
				}
			}
			else if (element.type == 'select-one') {
			
				if (element.value == '--') {
				
					element.style.backgroundColor = validaForm.color;
					validaForm.errors++;
				}
				else {

					element.style.backgroundColor = '';
				}
			}
			else if (element.type == 'checkbox') {
						
				if (element.checked == false) {
									
					element.parentNode.style.backgroundColor = validaForm.color;
					validaForm.errors++;
				}
				else {

					element.parentNode.style.backgroundColor = '';
				}
			}
		}
	}

	// Codice per gestione indipendente dello script
	/*function checkClickAddHotel(evnt) {

		var element = evnt.target ? evnt.target : evnt.srcElement;

		if (element.id && element.id == 'submitHotel') {

			validaForm.errors = 0;

			stato = validaForm.checkForm('addHotelForm');

			if (stato == 0) {
				document.getElementById('submitHotel').disabled = 'disabled';
				document.getElementById('addHotelForm').submit();
			}
		}
	}

	if (window.addEventListener) {
		window.addEventListener("load", setupEvents, false);
	}
	else if (window.attachEvent) {
		window.attachEvent("onload", setupEvents);
	}
	else {
		window.onload = setupEvents;
	}
	
	function checkClickAddForm() {

		validaForm.errors = 0;

		stato = validaForm.checkForm('checkForm');

		if (stato == 0) {
			document.getElementById('checkFormButton').disabled = 'disabled';
			document.getElementById('checkForm').submit();
		}
	}
	
	function setupEvents() {
		
		element = document.getElementById('checkFormButton');

		if (element != null) {

			if (element.addEventListener) {
				element.addEventListener("click", checkClickAddForm, false);
			}
			else if (element.attachEvent) {
				element.attachEvent("onclick", checkClickAddForm);
			}
			else {
				element.onclick = checkClickAddForm;
			}
		}
	}*/

//]]/