var bookmarkurl="http://www.trasportichiapparini.it"
var bookmarktitle="Trasportichiapparini.it"

function addbookmark()
{
	if (document.all)
	window.external.AddFavorite(bookmarkurl,bookmarktitle)
}

function PrintMe()
{
	window.print();  
}

function isComboSelected(cmbCombo)
{
	vValue=cmbCombo.options[cmbCombo.selectedIndex].value
	return vValue!=-1
}

		
function isEmpty(txtText)
{
	re=/^\s*$/
	return re.test(txtText)
}

			
function isNumeric_old(txtText)
{
	re=/^\d+$/
	return re.test(txtText)
}


function isFloat(txtText)
{
	re=/(^\d+$)|(^\d+\.\d+$)|(^\d+\,\d+$)/
	return re.test(txtText)
}			


function isDate(txtText)
{
	//Verifica la corretta formattazione della stringa #0/#0/0000
	re=/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/

	if (!re.test(txtText)) return 0
				
	//Suddivide la data in giorno, mese e anno
	vDatePart=re.exec(txtText)
	vDay=parseInt(vDatePart[1],10)
	vMonth=parseInt(vDatePart[2],10)
	vYear=parseInt(vDatePart[3],10)

	//Verifica il mese
	if (vMonth<1||vMonth>12) return 0
				
	//Determina il numero di giorni presenti nel mese
	switch(vMonth)
	{
		case 2:
			vDaysPerMonth=((vYear % 4 == 0) && ( (!(vYear % 100 == 0)) || (vYear % 400 == 0) ) ) ? 29 : 28
			break
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			vDaysPerMonth=31
			break
		case 4:
		case 6:
		case 9:
		case 11:
			vDaysPerMonth=30
			break
	}
				
	//Verifica se il giorno è corretto
	if (vDay<1||vDay>vDaysPerMonth) return 0
				
	//La data è valida
	return -1
}


function isTime(timeStr) 
{
var timePat = /^(\d{1,2}):(\d{2})/;
var matchArray = timeStr.match(timePat);

if (matchArray == null) { return false; }
var hour = matchArray[1];
var minute = matchArray[2];
if (hour < 0  || hour > 23) { return 0; }
if (minute < 0 || minute > 59) { return 0; }

return 1;
}


function Replace(strString,CharOut,CharIn)
{
	strToSplit = new String (strString)

	pattern = CharOut

	ArrayString = strToSplit.split (pattern)

	FinalString=""
	for ( i = 0; i < ArrayString.length; i++) {
	   if (i==ArrayString.length-1)
			{	   
			FinalString=FinalString+(ArrayString[i])
			}
	   else
			{	   
			FinalString=FinalString+(ArrayString[i] + CharIn)
			}		
	}
	return FinalString;
}


function CheckEmail(TextBoxValue)
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(TextBoxValue))
	{
	return (true)
	}
	return (false)
}


function isOk(txtText)
{
	re=/^[a-z0-9\ \_\-\/.\|\\]+$/i
	return re.test(txtText)

}


function OpenWindow(MyURL, MyWidth, MyHeight)
	{
	var NewWindow;
	var BrowserName = navigator.appName;
	var myurl = MyURL;
	var MyLeft=(window.screen.width - MyWidth) / 2;
	var MyTop=(window.screen.height - MyHeight) / 2;
	
	if (BrowserName == "Microsoft Internet Explorer") 
		{
		var props = 'scrollBars=yes,resizable=yes,toolbar=no,menubar=no,location=no,directories=no,width=' + MyWidth + ',height=' + MyHeight + ',left=' + MyLeft + ',top=' + MyTop;
		}
	else 
		{
		var props = 'scrollBars=yes,resizable=yes,toolbar=no,menubar=no,location=no,directories=no,width=' + MyWidth + ',height=' + MyHeight + ',screenX=' + MyLeft + ',screenY=' + MyTop;
		}		
	NewWindow = window.open(myurl, "NewWindow", props);
	NewWindow.focus();
	}

function isNumeric(fldval)  { 
    for (inf = 0; inf < fldval.length; inf++) 
	{ 
      ch = fldval.substring(inf, inf+1); 
      //if ((ch >= "0" && ch <= "9") || (ch == ".") || (ch == ",") || (ch == "-") || (ch == "+") || (ch == " ")) { 
	if ((ch >= "0" && ch <= "9") || (ch == ".") || (ch == "-")) 
		{
		VarisNumeric=true; 
        	}
	else 
		{
	    	VarisNumeric=false;
	    	break;	
		} 
    	} 
	return VarisNumeric;
}

function isIntero(fldval)  { 
    for (inf = 0; inf < fldval.length; inf++) 
	{ 
      ch = fldval.substring(inf, inf+1); 
	if ((ch >= "0" && ch <= "9") || (ch == "-")) 
		{
		VarisNumeric=true; 
        	}
	else 
		{
	    	VarisNumeric=false;
	    	break;	
		} 
    	} 
	return VarisNumeric;
} 

function isTelefono(fldval)  { 
    for (inf = 0; inf < fldval.length; inf++) 
	{ 
      ch = fldval.substring(inf, inf+1); 
	if ((ch >= "0" && ch <= "9") || (ch == "/") || (ch == "-")) 
		{
		VarisNumeric=true; 
        	}
	else 
		{
	    	VarisNumeric=false;
	    	break;	
		} 
    	} 
	return VarisNumeric;
} 

/*
function ReplaceChars(entry, out, add) 
	{
	temp = "" + entry;

	while (temp.indexOf(out)>-1) 
		{
		pos = temp.indexOf(out);
		temp = "" + (temp.substring(0, pos) + add + temp.substring((pos + out.length), temp.length));
		}
	
	return temp;
	}
*/

function DateDayDiff(DateMaxIn, DateMinIn) 
	{

DateMaxInSplit = DateMaxIn.split("-")
DateMaxIn = DateMaxInSplit[2] + "/" + DateMaxInSplit[1] + "/" + DateMaxInSplit[0]
DateMinInSplit = DateMinIn.split("-")
DateMinIn = DateMinInSplit[2] + "/" + DateMinInSplit[1] + "/" + DateMinInSplit[0]

//alert("FF " + DateMaxIn)

	re=/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/

	//re=/^(\d{4})(\/|-)(\d{1,2})(\/|-)(\d{1,2})$/

	//Suddivide la data in giorno, mese e anno
	vDatePart = re.exec(DateMaxIn)
	vDay = parseInt(vDatePart[1],10)
	vMonth = parseInt(vDatePart[2],10)
	vYear = parseInt(vDatePart[3],10)
	var DateMax = new Date(vMonth + "/" + vDay + "/" + vYear);

//alert("dd " + vYear + vMonth + vDay)

	vDatePart = re.exec(DateMinIn)
	vDay = parseInt(vDatePart[1],10)
	vMonth = parseInt(vDatePart[2],10)
	vYear = parseInt(vDatePart[3],10)
	var DateMin = new Date(vMonth + "/" + vDay + "/" + vYear);

	Diff = (DateMax.getTime() - DateMin.getTime());

	var Days = Math.floor(Diff / (24 * 60 * 60 * 1000));
	
	return Days;
	}
