﻿function trim(a){
  return a.replace(/^\s+/,'').replace(/\s+$/,'')
}

function trimAll(a){
  return a.replace(/^\s+/,'').replace(/\s+$/,'').replace(/\s+/g,' ')
}

function parsemail(indirizzo) {
	if (window.RegExp) {
    	var nonvalido = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
		var valido = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
		var regnv = new RegExp(nonvalido);
		var regv = new RegExp(valido);
		if (!regnv.test(indirizzo) && regv.test(indirizzo)) return true;
		return false;
	}
	else {
		apos=indirizzo.indexOf("@"); 
		dotpos=indirizzo.lastIndexOf(".");
		lastpos=indirizzo.length-1;
		if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) return false;
		return true;
	}
}

function verify_date(input) {
	var regex = new RegExp("[/-]");
	var date = input.split(regex);
	var nbJours = new Array('',31,28,31,30,31,30,31,31,30,31,30,31);
	var result = true;
	if (date['2']%4 == 0 && date['2']%100 > 0 || date['2']%400 == 0) nbJours['2'] = 29;
	if (isNaN(date['2']) || parseFloat(date['2']) < 1900) result=false;
	if (isNaN(date['1']) || date['1'] > 12 || date['1'] < 1) result=false;
	if (isNaN(date['0']) || date['0'] > nbJours[Math.round(date['1'])] || date['0'] < 1) result=false;
	return result;
}

function AS_popupWindow(url,target,width,height){
	var features;
	features = 'location=0,menubar=0,scrollbars,resizable,dependent,status=0,toolbar=0,width=' + width + ',innerWidth=' + width + ',height=' + height + ',innerHeight=' + height;
	if (window.screen) {
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;

		var xc = (aw - width) / 2;
		var yc = (ah - height) / 2;

		features += ",left=" + xc + ",screenX=" + xc;
		features += ",top=" + yc + ",screenY=" + yc;
	}
	var wnd = window.open(url,target,features);
	wnd.focus();
}
