﻿	var navVersion=null;
	navVersion=navigator.appVersion.toLowerCase();
	this.ie5=(navVersion.indexOf("msie 5.0")!=-1)?true:false;
	this.ie55=(navVersion.indexOf("msie 5.5")!=-1)?true:false;
	this.ie6=(navVersion.indexOf("msie 6.0")!=-1)?true:false;
	this.ie7=(navVersion.indexOf("msie 7.0")!=-1)?true:false;
	this.isIE=(this.ie5||this.ie55||this.ie6||this.ie7)?true:false;
	this.isGecko=!this.isIE;
	
	
		function CreateValidator(parentElement,message,validator_field,align)
			{		
			
				
				if (typeof(align)=="undefined")
				align="left;"
				var validator_control = null
				if (document.getElementById("validator_" + validator_field)==null){
					validator_control = document.createElement("DIV");
					 
					if (this.isGecko)
						parentElement.parentNode.appendChild(validator_control)
					else
						parentElement.parentElement.appendChild(validator_control)
				}	
				else
					validator_control=document.getElementById("validator_" + validator_field)
					validator_control.style.display="";
					
					if (this.isGecko)
						validator_control.innerHTML = message;
					else
  					validator_control.innerText = message;
				
					validator_control.id="validator_" + validator_field;
					validator_control.name="validator_" + validator_field;
					validator_control.className="texterror";
					validator_control.style.color="red";
					//validator_control.setAttribute("style","float:" + align);
					return true;
					
					
			}

			function Validator_clear(validator_field)
			{
				// Validator dinamico compatibile sia in mozilla che ie.
				var validator_control = null
				if (document.getElementById("validator_" + validator_field)!=null)
				{
					if (Trim(document.getElementById(validator_field).value)!=""){
						bok=true;
						if (bok){
						document.getElementById("validator_" + validator_field).innerHTML="";
						document.getElementById("validator_" + validator_field).style.display="none";
					}
				}
			}
				return true;
			}
		
			function Trim(strText) { 
					// this will get rid of leading spaces 
					while (strText.substring(0,1) == ' ') 
							strText = strText.substring(1, strText.length);

					// this will get rid of trailing spaces 
					while (strText.substring(strText.length-1,strText.length) == ' ')
							strText = strText.substring(0, strText.length-1);

				return strText;
			} 
			
			function isEmail (s) {
			var i = 1;
			var sLength = s.length;
			if (noWhitespace(s)) {
				while ((i<sLength) && (s.charAt(i) != "@")) { i++ }
				if ((i>=sLength) || (s.charAt(i) != "@"))
					return false;
				while ((i<sLength) && (s.charAt(i) != ".")) { i++ }
				if ((i>=sLength-2) || (s.charAt(i) != "."))
					return false;
				return true;
			}
			return false;
		}
							
				
		
						  
		function isEmpty (s) { return ((s==null) || (s.length==0)) }

		function isDigit (c) { return ((c>="0") && (c<="9")) }

		function isWhitespace (s) {
			var whitespace="\t\r\n";
			var i;
			if(isEmpty(s))
				return true;
			for (i=0;i<s.length;i++) {
				var c = s.charAt(i);
				if (whitespace.indexOf(c)==-1)
					return false;
			}

			return true;
		}

		function noWhitespace (s) {
			var whitespace="\t\r\n ";
			var i;
			if(isEmpty(s))
				return true;
			for (i=0;i<s.length;i++) {
				var c = s.charAt(i);
				if (whitespace.indexOf(c)!=-1)
					return false;
			}
			return true;
		}

		function isEmail (s) {
			var i = 1;
			var sLength = s.length;
			if (noWhitespace(s)) {
				while ((i<sLength) && (s.charAt(i) != "@")) { i++ }
				if ((i>=sLength) || (s.charAt(i) != "@"))
					return false;
				while ((i<sLength) && (s.charAt(i) != ".")) { i++ }
				if ((i>=sLength-2) || (s.charAt(i) != "."))
					return false;
				return true;
			}
			return false;
		}

		function isAllDigit (s) {
			var i;
			if(isEmpty(s) || isWhitespace(s))
				return false;
			for (i=0;i<s.length;i++) {
				var c = s.charAt(i);
				if (!isDigit(c))
					return false;
			}
			return true;
		}

		function validate_inputfield(object_tovalidate,validatorname,errormessage)
		{
				
			var returnvalue =true;
			//"Il campo indirizzo \351 obbligatorio";
		
			if (document.getElementById(object_tovalidate).value==""){
						CreateValidator(document.getElementById(object_tovalidate),errormessage,validatorname)
						returnvalue =false;
					}
				else{
						Validator_clear(validatorname)
						returnvalue =true;
				}					
				
			return 	returnvalue ;
		}
		function validate_dropdownlist(object_tovalidate,validatorname,errormessage,value)
		{
			var returnvalue =true;
			if ($('#'+object_tovalidate)[0].value==value){
			    CreateValidator($('#'+object_tovalidate)[0],errormessage,validatorname)
			    returnvalue =false;
			}
			else{
				Validator_clear(validatorname)
				returnvalue =true;
			}					
			return 	returnvalue ;
		}
