
str_empty = "\s*";

str_host = "[0-9a-zA-Z]+(\.[-0-9a-zA-Z]+)+";

str_path = "\/?[-/.0-9a-zA-Z&?%=_#]*";

str_email = "[-_.0-9a-zA-Z]+([+][-_.0-9a-zA-Z]+)*@"+str_host;

str_url = "((http:\/\/)|(ftp:\/\/)|(www[.])|(ftp[.]))"+str_host+"(\/"+str_path+")?";

str_tel = "(([(][+]?[0-9]{2,3}[)])|([+]?[0-9]{2,3}))?[-. 0-9]{2,30}";           
//str_tel = "0[0-9]{9}";

str_int = "[+-]?[0-9]+";

str_pc = "[0-9]{4,5}";

str_float = "[-+]?[0-9]*(\.[0-9]*)?";

str_pass = ".{4,}";

str_year = "((19)|(20))[0-9]{2}";

pcre_empty = new RegExp("^"+str_empty+"$");

pcre_host = new RegExp("^"+str_host+"$");

pcre_path = new RegExp("^"+str_path+"$");

pcre_email = new RegExp("^"+str_email+"$");

pcre_url = new RegExp("^"+str_url+"$");

pcre_tel = new RegExp("^"+str_tel+"$");

pcre_int = new RegExp("^"+str_int+"$");

pcre_pc = new RegExp("^"+str_pc+"$");

pcre_float = new RegExp("^"+str_float+"$");

pcre_pass = new RegExp("^"+str_pass+"$");

pcre_year = new RegExp("^"+str_year+"$");

function check_date(form,datename) {
	d=parseInt(form.elements[datename+'[day]'].options[form.elements[datename+'[day]'].selectedIndex].value,10);
	m=parseInt(form.elements[datename+'[mon]'].options[form.elements[datename+'[mon]'].selectedIndex].value,10)-1;
	y=parseInt(form.elements[datename+'[year]'].options[form.elements[datename+'[year]'].selectedIndex].value,10);
	datanoua = new Date(y,m,d,12,0,0);  // 12h dupa 12:00 pentru ca in IE
					    // sunt probleme cu aproximarile
	if (datanoua) ret=true;
		else ret=false;

//  pentru debugging
//	alert ("Data input: " + d + " " + m + " " + y + ".");
//	alert ("Data output: " + datanoua.getDate() + " " +
//						   datanoua.getMonth() + " " +
//						   datanoua.getFullYear() + "."); 
	if (ret) {
		if ( (d==datanoua.getDate()) &&
			(m==datanoua.getMonth()) &&
			(y==datanoua.getFullYear()) ) 
					ret=true; else ret=false;
		timestamp=datanoua.getTime()/1000;
//		alert (timestamp);
		if ( (arguments.length>2) && (timestamp<arguments[2]) ) ret=false;
		if ( (arguments.length>3) && (timestamp>arguments[3]) ) ret=false;
	}


	return(ret);
}

function parsedate(form,datename) {
	d=parseInt(form.elements[datename+'[day]'].options[form.elements[datename+'[day]'].selectedIndex].value,10);
	m=parseInt(form.elements[datename+'[mon]'].options[form.elements[datename+'[mon]'].selectedIndex].value,10)-1;
	y=parseInt(form.elements[datename+'[year]'].options[form.elements[datename+'[year]'].selectedIndex].value,10);
	data = new Date(y,m,d,0,0,1);
	return(data.getTime()/1000);
}

function array2str(arr) {
	var msg="";
	for(i=0;i<arr.length;i++)
		msg+=(i+1)+". "+arr[i]+"\n";
	return(msg);
}

function syncDates(frm,from_el,to_el,changed) {
    var from_day=frm.elements[from_el+'[day]'];
    var from_mon=frm.elements[from_el+'[mon]'];
    var from_year=frm.elements[from_el+'[year]'];
    var to_day=frm.elements[to_el+'[day]'];
    var to_mon=frm.elements[to_el+'[mon]'];
    var to_year=frm.elements[to_el+'[year]'];

    var from=new Date(from_year.options[from_year.selectedIndex].value,from_mon.options[from_mon.selectedIndex].value-1,from_day.options[from_day.selectedIndex].value);
    var to=new Date(to_year.options[to_year.selectedIndex].value,to_mon.options[to_mon.selectedIndex].value-1,to_day.options[to_day.selectedIndex].value);
    
    if (changed==from_el)
	if (to.getTime()<from.getTime()) {
	    if (from_day.selectedIndex==from_day.options.length-1) {
		to_day.selectedIndex=0;
		if (from_mon.selectedIndex==from_mon.options.length-1) {
		    to_mon.selectedIndex=0;
		    to_year.selectedIndex=from_year.selectedIndex+1;
		} else {
		    to_mon.selectedIndex=from_mon.selectedIndex+1;
		    to_year.selectedIndex=from_year.selectedIndex;
		}
	    } else {
		to_day.selectedIndex=from_day.selectedIndex+1;
		to_mon.selectedIndex=from_mon.selectedIndex;
		to_year.selectedIndex=from_year.selectedIndex;
	    }
	}
    
    if (changed==to_el)
	if (to.getTime()<from.getTime()) {
	    from_day.selectedIndex=to_day.selectedIndex;
	    from_mon.selectedIndex=to_mon.selectedIndex;
	    from_year.selectedIndex=to_year.selectedIndex;
	}
 
}
