	errBorderColor    = "#E3002A";
	normalBorderColor = "#7E9DB9";

	function validateEmptyFields(fields) {

		valid = true;
		for(n=0; n < fields.length; n++) {
				
			field = fields[n][0];
			type  = fields[n][1];
			len1  = parseInt(fields[n][2]);
			len2  = parseInt(fields[n][3]);
			
			if(isNaN(len1)) len1 = 0;
			if(isNaN(len2)) len2 = 0;

			el = $(field);
			
			if(el) {
				el.style.borderColor = normalBorderColor;
				if( el.rel != 'disabled') {
					
					val = el.value;
					val = val.replace(/^\s+/, "").replace(/\s+$/, "");
					
					//val = cleanValue(val);
				
					if(type == 'string') {
						if(val == '') {
							valid = false;
							el.style.borderColor = errBorderColor;
						} 
					} else if (type == 'float') {
						v = val.replace(',','.');
						if(!v.match(/^(\d+|\d+\.\d+)$/) || v <= '0') {
							valid = false;
							el.style.borderColor = errBorderColor;
						} 
					} else if (type == 'int_0') {
						if(parseInt(val) != 0) {
							r = new RegExp(len1 ? "^\\d{"+len1+(len2 ? ","+len2:"")+"}$" : "^\\d+$");
							if(!r.exec(val) || val < '0') {
								valid = false;
								el.style.borderColor = errBorderColor;
							} 
						}
					} else if (type == 'int') {
						r = new RegExp(len1 ? "^\\d{"+len1+(len2 ? ","+len2:"")+"}$" : "^\\d+$");
						if(!r.exec(val) || val <= '0') {
							valid = false;
							el.style.borderColor = errBorderColor;
						} 
					} else if (type == 'email') {
						var pattern = /^[+]?[_a-z0-9-]+(\.[_a-z0-9-]+)*@([0-9a-z][0-9a-z-]*\.)+[a-z]{2,4}$/i;
						if(val == '' || !val.match(pattern)) {
							valid = false;
							el.style.borderColor = errBorderColor;
						} 
					} else if (type == 'phone') {
						r = new RegExp("^\\+?[ 0-9\\(\\)\\.,\\-~;]+$");
						if(val == '' || !r.exec(val)) {
							valid = false;
							el.style.borderColor = errBorderColor;
						} 
					} else if (type == 'postcode') {
						r = new RegExp("^LV - \\d{4}$");
						if(val == '' || !r.exec(val)) {
							valid = false;
							el.style.borderColor = errBorderColor;
						} 
					} else if (type == 'always_valid') { // unselects red inputs
						;
					}
				}			
			}		
		}
		
		return valid ? 0 : error_message;	
	}
	
	
	function validateField() {
	
	}
	
	
	function cleanValue(val) {
		myregexp = new RegExp('(\\n+)');
		val = val.replace(myregexp, '');
		return val;
	}
	
	
	function sendForm(){
		error = validate();
		if(error) {
//			$('FormErrorMessage').show();
//			$('ErrorText').innerHTML = error;
			alert(error);
			return false;
		} else
			//$('main_form').submit();
			return true;
	}	
	
	
	function ifSelectedCountry(c, type) {
	
		if(type == 'baltic') {
			if(c == 'LT' || c == 'LV' || c == 'EE')
				return true;
		}
		
		if (type== 'nonES') {
			if(c == 'NO' || c == 'IS' || c == 'HR' || c == 'CH' || c == 'RS' || c == 'BA')
				return true;
		}
		
		if(type == 'baltic_ee') {
			if(c == 'LT' || c == 'LV' || c == 'EE' || c == 'PL' || c == 'FI' || c == 'CH')
				return true;
		}
		
		if(type == 'baltic_lv') {
			if(c == 'LT' || c == 'LV' || c == 'EE' || c == 'PL' || c == 'FI')
				return true;
		}
		
		if(type == 'notbaltic') {
			if(c == 'PL' || c == 'FI')
				return true;
		}	
		
		if(type == 'other') {
			if(c != 'LT' && c != 'LV' && c != 'EE' && c != 'PL' && c != 'FI')
				return true;
		}
		
		if(type == 'other_ee') {
			if(c != 'LT' && c != 'LV' && c != 'EE' && c != 'PL' && c != 'FI' && c != 'CH')
				return true;
		}
		
		return false;
	}
	
	
	function number(val) {
		return isNaN(val) || val=='' || val==0 ? 0 : parseInt(val.replace(',','.'));
	}
	
	
	function compareTime(t1, t2) {
		tt1= countTime(t1);
		tt2= countTime(t2);
		
		if(tt1 < tt2)
			return false;

		if((tt1-tt2)/60 < 2.5)
			return false;
		
		return true;		
	}
	
	
	function countTime(t) {
		m = t.match(/(\d+):(\d+)/);
		total = (parseInt(m[1] * 60) + parseInt(m[2]));
		return total;
	}
	
	
	function fixDate(d) {
		if(d < 10)
			return '0' + d;
		return d;	
	}


	function getTime() {
		var dat = new Date();
		dat.setTime(today_time);
		
		return fixDate(dat.getHours())+':'+fixDate(dat.getMinutes());
	}
	
	
	function getDate() {
		var dat = new Date();
		dat.setTime(today_time);
		
		return dat;
	}
	
	
	function UpdateTimer() {
		today_time += 1000;
		setTimeout("UpdateTimer()", 1000);
	}
	
	
	function setPassword() {
		new Ajax.Request(_ABS_PATH + 'password.php', {onComplete : showResponse2, asynchronous : true, parameters : 'get='+$F('company_id')});
	}
	
	
	function showResponse(originalRequest) {
		if(originalRequest.responseText) {
			password_ok = true;
		}
	}
	
	
	function showResponse2(originalRequest) {
		if(originalRequest.responseText) {
			$('password_id_tr').show();
			$('password').rel = ''; 
		} else {	
			$('password_id_tr').hide();
			$('password').rel = 'disabled'; 
		}	
	}
	
	
	DPD_Data = Class.create({}, { 
		initialize: function(months_el_id, days_el_id) {
			this.months_el   = $(months_el_id);
			this.days_el     = $(days_el_id);
			this.months_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
			
			this.months_el.observe('change', this.x.bind(this)),
			this.x();			
		},
		
		x: function() {
			v  = ($F(this.months_el)*1)-1;
			op = this.days_el.options;


			var s_index=this.days_el.selectedIndex;
			

			while(op.length)
				op[op.length-1] = null;	

			for(i=0, d=1; i < this.months_days[v]; i++, d++) {
				val   = d < 10 ? '0'+d : d;	
				op[i] = new Option(val);
				op[i].value = val;
			}

			if(s_index>-1)
				this.days_el.selectedIndex=s_index;
		}
	});	
	
	
	function fillForm(form_id) {
		$(form_id).getElements().each(function(s) {
			val = 'ner';
			
			el_id = s.id;
			
			if(s.name == 'action')
				return;
			
			if(el_id.match(/email/)) {
				val = 'test@test.lt';
			} else if(el_id.match(/phone|fax/)) {
				val = Math.floor(Math.random()*10000000);
			} else if(el_id.match(/phone|length|width|height|volume|dimension|weight|pallete|packs/)) {
				val = Math.floor(Math.random()*100);
			} else if(el_id.match(/id/)) {
				val = Math.floor(Math.random()*10000);
			} else {
				keywords = ["namas","stalas","sofa","durys","spinta", "lempa", "taburete"]; 
				val = keywords[Math.floor(Math.random()*keywords.length)]; 
			}
			
			s.value = val;
		});
	}
	
	
	