var fasti_layer = null;

var fasti_current = null;

var fasti_focus = false;

var fasti_config = new Array( );

fasti_config["weekfirstday"] = 0;

fasti_config["weekdays"] = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");

fasti_config["months"] = new Array("January","February","March","April","May","June","July","August","September","October","November","December");

fasti_config["dateformat"] = "mm/dd/yyyy";



var CurrentDate = null;

var CurrentTime = null;



function fasti_changemonth(e)

{

	if(!e) e = event;

	if(e.target)

		var html_link = e.target;

	else if(e.srcElement)

		var html_link = e.srcElement;



	if(html_link && fasti_layer)

	{

		var current_month = fasti_layer.getAttribute("current").split("-");

		var fasti_date = new Date(parseInt(current_month[0], 10), parseInt(current_month[1], 10) - 1, 1);

		if(html_link.rel == "previous")

			fasti_date.setMonth(fasti_date.getMonth( ) - 1);

		else if(html_link.rel == "next")

			fasti_date.setMonth(fasti_date.getMonth( ) + 1);

		fasti_init(fasti_current, fasti_date);

		fasti_focus = false;

		fasti_current.focus( );

		fasti_current.select( );

	}

	if(e.stopPropagation)

		e.stopPropagation( );

	else if(typeof e.cancelBubble != "undefined")

		e.cancelBubble = true;

	return false;

}



function fasti_create( )

{

	var fasti_table = document.createElement("table");

	var table_head = fasti_table.appendChild(document.createElement("thead"));

	var table_foot = fasti_table.appendChild(document.createElement("tfoot"));

	var table_body = fasti_table.appendChild(document.createElement("tbody"));

	var head_row = table_head.insertRow(-1);

	var foot_row = table_foot.insertRow(-1);

	var nbsp = document.createTextNode("\xA0");

	var link_prev = document.createElement("a");

	var link_next = document.createElement("a");



	for(var f=0; f<7; f++)

	{

		var text = document.createTextNode(fasti_config['weekdays'][(f + fasti_config['weekfirstday']) % 7].charAt(0));

		var table_data = head_row.insertCell(-1);

		table_data.appendChild(text);

	}



	for(var g=0; g<6; g++)

	{

		var body_row = table_body.insertRow(-1);

		for(var f=0; f<7; f++)

		{

			table_data = body_row.insertCell(-1);

			table_data.appendChild(document.createTextNode("\xA0"));

		}

	}



	link_prev.href = "#";

	link_prev.onclick = fasti_changemonth;

	link_prev.rel = "previous";

	link_prev.appendChild(document.createTextNode("\u00AB"));

	table_data = foot_row.insertCell(-1);

	table_data.appendChild(link_prev); 

	table_data = foot_row.insertCell(-1);

	if(table_data.colSpan)

		table_data.colSpan = 5;

	else table_data.setAttribute("colspan", "5");

	table_data.appendChild(document.createTextNode("\xA0"));

	table_data = foot_row.insertCell(-1);

	link_next.href = "#";

	link_next.onclick = fasti_changemonth;

	link_next.rel = "next";

	link_next.appendChild(document.createTextNode("\u00BB"));

	table_data.appendChild(link_next); 



	fasti_table.style.position = "absolute";

	fasti_table.style.visibilty = "hidden";

	fasti_table.style.display = "none";

	fasti_table.id = "fasti_layer";

	fasti_table.className = "fasti_layer";

	fasti_table.setAttribute("status", "hidden");

  if(fasti_table.addEventListener)

    fasti_table.addEventListener("DOMMouseScroll", fasti_wheel, false);

	else if(fasti_table.attachEvent)

    fasti_table.attachEvent("onscroll", fasti_wheel);

	return document.body.appendChild(fasti_table);

}



function fasti_display(e)

{

	if(e.target)

		var fasti_field = e.target;

	else if(e.srcElement)

		var fasti_field = e.srcElement;



	if(fasti_field.getAttribute("fasti_donothing"))

	{

		fasti_field.removeAttribute("fasti_donothing");

		return true;

	}



	var fasti_field_settings = new Array( ); 

	if(document.getElementById(fasti_field.id + "_fastisettings"))

	{

		var fasti_field_settings = document.getElementById(fasti_field.id + "_fastisettings").value.split("&");

		for(var i=0; i<fasti_field_settings.length; i++)

		{

			fasti_field_settings[i] = fasti_field_settings[i].split("=");

			fasti_field_settings[i][0] = fasti_field_settings[i][0].replace(/^\s\s*/, '').replace(/\s\s*$/, '').toLowerCase( );

			fasti_field_settings[i][1] = fasti_field_settings[i][1].replace(/^\s\s*/, '').replace(/\s\s*$/, '').toLowerCase( );

			fasti_field_settings[fasti_field_settings[i][0]] = fasti_field_settings[i][1];

		}

	}

	else var fasti_field_settings = new Array( );



	if(!fasti_layer)

	{

    if(document.getElementById)

      fasti_layer = document.getElementById("fasti_layer");

    else if(document.all)

      fasti_layer = document.all("fasti_layer");

		if(!fasti_layer)

			fasti_layer = fasti_create( );

  }



  if(fasti_field && fasti_layer)

  {

		fasti_date = fasti_formatdate(fasti_field);

		if(!fasti_date)

		{

			if(fasti_field_settings["start"])

			{

				if(document.getElementById(fasti_field_settings["start"]))

					fasti_date = fasti_formatdate(document.getElementById(fasti_field_settings["start"]));

				else

				{

					var start_date = fasti_field_settings["start"].split("-");

					if(start_date.length == 3)

					{

						fasti_date = new Date( );

						fasti_date.setFullYear(parseInt(start_date[0], 10));

						fasti_date.setMonth(parseInt(start_date[1], 10)-1);

						fasti_date.setDate(parseInt(start_date[2], 10));

					}

				}

			}

			if(!fasti_date)

				fasti_date = new Date( );

		}



		if(fasti_layer.getAttribute("status") == "hidden" || fasti_current != fasti_field)

		{

	    if(fasti_layer.getAttribute("current"))

			{

				var current = fasti_layer.getAttribute("current").split("-");

				if(parseInt(current[1], 10) != fasti_date.getMonth( ) + 1 || parseInt(current[0], 10) != fasti_date.getFullYear( ))

					fasti_init(fasti_field, fasti_date); 

			}

			else fasti_init(fasti_field, fasti_date);

	    var layer_offset = fasti_field.offsetParent;

  	  var layer_left = fasti_field.offsetLeft;

	    var layer_top = fasti_field.offsetTop + fasti_field.offsetHeight;

  	  while(layer_offset.tagName.toLowerCase( ) != "body" && layer_offset.tagName.toLowerCase( ) != "html")

	    {

  	    layer_left += layer_offset.offsetLeft;

    	  layer_top += layer_offset.offsetTop;

	      layer_offset = layer_offset.offsetParent;

  	  }

    	fasti_layer.style.left = layer_left + "px";

	    fasti_layer.style.top = layer_top + "px";

  	  if(navigator.appName == "Microsoft Internet Explorer")

	      fasti_layer.style.display = "block";

  	  else fasti_layer.style.display = "table";

			if(fasti_layer.offsetWidth < fasti_field.offsetWidth)

				fasti_layer.style.width = fasti_field.offsetWidth + "px";

	    fasti_layer.style.visibility = "visible";

			fasti_layer.setAttribute("status", "visible");

  	  fasti_current = fasti_field;

		}

    fasti_field.focus( );

    fasti_field.select( );

  }

  return fasti_layer;

}



function fasti_documentclick(e)

{

	if(e.target && !e.target.getAttribute("fasti"))

		fasti_hide(fasti_current);

	else if(e.srcElement && !e.srcElement.getAttribute("fasti"))

		fasti_hide(fasti_current);

}



function fasti_blur(e)

{

	fasti_hide(fasti_current);

}



function fasti_formatdate(fasti_field)

{

  var fasti_return = null;

  if(fasti_field && fasti_layer)

  {

    var date_now = new Date( );

    var date_s = fasti_field.value || "";

    var date_a = new Array( );

		var class_name = "";

		var min_date = null, max_date = null;

		if(document.getElementById(fasti_field.id + "_fastisettings"))

		{

			var fasti_field_settings = document.getElementById(fasti_field.id + "_fastisettings").value.split("&");

			for(var i=0; i<fasti_field_settings.length; i++)

			{

				fasti_field_settings[i] = fasti_field_settings[i].split("=");

				fasti_field_settings[i][0] = fasti_field_settings[i][0].replace(/^\s\s*/, '').replace(/\s\s*$/, '').toLowerCase( );

				fasti_field_settings[i][1] = fasti_field_settings[i][1].replace(/^\s\s*/, '').replace(/\s\s*$/, '').toLowerCase( );

				fasti_field_settings[fasti_field_settings[i][0]] = fasti_field_settings[i][1];

			}

		}

		else var fasti_field_settings = new Array( );



		if(fasti_field_settings["min"])

		{

			if(fasti_field_settings["min"] == "now")

				min_date = new Date( );

			else if(document.getElementById(fasti_field_settings["min"]))

			{

				min_date = fasti_formatdate(document.getElementById(fasti_field_settings["min"]));

				if(!min_date && document.getElementById(fasti_field_settings["min"] + "_fastisettings"))

				{

					var fasti_field_settings2 = fasti_readsettings(document.getElementById(fasti_field_settings["min"]));

					if(fasti_field_settings2["min"])

					{

						if(fasti_field_settings2["min"] == "now")
							min_date = new Date( );
						else
						{
							fasti_field_settings2["min"] = fasti_field_settings2["min"].split("-");
							min_date = new Date(parseInt(fasti_field_settings2["min"][0], 10), parseInt(fasti_field_settings2["min"][1], 10)-1, parseInt(fasti_field_settings2["min"][2], 10), 0, 0, 0); 
						}
					}
				}
			}
			else
			{
				fasti_field_settings["min"] = fasti_field_settings["min"].split("-");
				min_date = new Date(parseInt(fasti_field_settings["min"][0]), parseInt(fasti_field_settings["min"][1])-1, parseInt(fasti_field_settings["min"][2]), 0, 0, 0); 
			}
		}

		if(fasti_field_settings["max"])

		{

			if(fasti_field_settings["max"] == "now")

				max_date = new Date( );

			else if(document.getElementById(fasti_field_settings["max"]))

			{

				max_date = fasti_formatdate(document.getElementById(fasti_field_settings["max"]));

				if(!max_date && document.getElementById(fasti_field_settings["max"] + "_fastisettings"))

				{

					var fasti_field_settings2 = fasti_readsettings(document.getElementById(fasti_field_settings["max"]));

					if(fasti_field_settings2["max"])

					{

						if(fasti_field_settings2["max"] == "now")

							min_date = new Date( );

						else

						{

							fasti_field_settings2["max"] = fasti_field_settings2["max"].split("-");

							max_date = new Date(parseInt(fasti_field_settings2["max"][0]), parseInt(fasti_field_settings2["max"][1])-1, parseInt(fasti_field_settings2["max"][2]), 0, 0, 0); 

						}

					}

				}

			}

			else

			{
				if(typeof fasti_field_settings["max"] == "string")
				{
					fasti_field_settings["max"] = fasti_field_settings["max"].split("-");
					max_date = new Date(parseInt(fasti_field_settings["max"][0]), parseInt(fasti_field_settings["max"][1])-1, parseInt(fasti_field_settings["max"][2]), 0, 0, 0);
				} 

			}

		}



    switch(date_s.toLowerCase( ))

    {

      case "oggi": case "today": case "heute": case "hoy": case "aujourd'hui": case "aujourdhui":

        fasti_field.value = fasti_zerofill(date_now.getDate( )) + "/" + fasti_zerofill(date_now.getMonth( ) + 1) + "/" + fasti_zerofill(date_now.getFullYear( ), 4);

        fasti_return = date_now;

      break;



      case "ieri": case "yesterday": case "gestern": case "ayer": case "hier":

        date_now.setDate(date_now.getDate( ) - 1);

        fasti_field.value = fasti_zerofill(date_now.getDate( )) + "/" + fasti_zerofill(date_now.getMonth( ) + 1) + "/" + fasti_zerofill(date_now.getFullYear( ), 4);

        fasti_return = date_now;

      break;



      case "domani": case "tomorrow": case "morgen": case "manana": case "maņana": case "demain":

        date_now.setDate(date_now.getDate( ) + 1);

        fasti_field.value = fasti_zerofill(date_now.getDate( )) + "/" + fasti_zerofill(date_now.getMonth( ) + 1) + "/" + fasti_zerofill(date_now.getFullYear( ), 4);

        fasti_return = date_now;

      break;



      default:

        if(date_s)

        {

					date_s = date_s.replace(/[^0-9\x20\\\/\-\.\:]/gi, "")

					date_s = date_s.replace(/[\\\/\-\.\x20\:]/gi, "/")

          

					if(date_s.indexOf("/") > -1)

					{

						date_a = date_s.split("/");

						date_a[0] = parseInt(date_a[0], 10) || 0;

						date_a[1] = parseInt(date_a[1], 10) || 0;

						date_a[2] = parseInt(date_a[2], 10) || date_now.getFullYear( );

						if(date_a[0] > 31 && date_a[2] <= 31)

						{

							if(date_a[0] < 100 && date_a[0] > 50)

								date_a[0] = 1900 + date_a[0];

							else if(date_a[0] < 100 && date_a[0] >= 0)

  							date_a[0] = 2000 + date_a[2];

							date_s = fasti_zerofill(date_a[2]) + "/" + fasti_zerofill(date_a[1]) + "/" + fasti_zerofill(date_a[0], 4);

							date_a.reverse( );

						}

            else if(date_a[2])

            {

              if(date_a[2] < 100 && date_a[2] > 50)

                date_a[2] = 1900 + date_a[2];

              else if(date_a[2] < 100 && date_a[2] >= 0)

                date_a[2] = 2000 + date_a[2];

              date_s = fasti_zerofill(date_a[0]) + "/" + fasti_zerofill(date_a[1]) + "/" + fasti_zerofill(date_a[2], 4)

            }

            else date_s = fasti_zerofill(date_a[0]) + "/" + fasti_zerofill(date_a[1]) + "/" + fasti_zerofill(date_a[2], 4);

          }

          else if(date_s.length >= 4)

          {

            date_a[0] = parseInt(date_s.substring(0, 2), 10) || 0;

            date_a[1] = parseInt(date_s.substring(2, 4), 10) || 0;

            date_a[2] = parseInt(date_s.substring(4, date_s.length), 10) || date_now.getFullYear( );

            if(date_a[2])

            {

              if(date_a[2] < 100 && date_a[2] > 50)

                date_a[2] = 1900 + date_a[2]

              else if(date_a[2] < 100 && date_a[2] >= 0)

                date_a[2] = 2000 + date_a[2]

              else date_a[2] = fasti_zerofill(date_a[2], 4)

            }

            date_s = fasti_zerofill(date_a[0], 2) + "/" + fasti_zerofill(date_a[1], 2) + "/" + date_a[2]

          }

          date_now = new Date(date_a[2], date_a[1] - 1, date_a[0]);

          if(date_now.getDate( ) == date_a[0] && date_now.getMonth( ) == (date_a[1] - 1) && date_now.getFullYear( ) == date_a[2])

          {

            fasti_field.value = date_s;

            fasti_return = date_now;

					}

					else class_name = "fasti_error";

					if((min_date && date_now < min_date) || (max_date && date_now > max_date))

						class_name = "fasti_error";  

				}

      break;

    }

		var fasti_field_class = fasti_field.className.split(" ");

		if(class_name)

		{

			var class_present = false;

			for(var i=0; i<fasti_field_class.length; i++) if(fasti_field_class[i] == class_name)

				class_present = true;

			else if(!fasti_field_class[i] || (fasti_field_class[i].indexOf("fasti_") == 0 && fasti_field_class[i] != "fasti_date"))

			{

				fasti_field_class.splice(i, 1);

				i -= 1;

			}

			if(!class_present)

				fasti_field_class.push(class_name);

		}

		else

		{

			for(var i=0; i<fasti_field_class.length; i++) if(!fasti_field_class[i] || (fasti_field_class[i].indexOf("fasti_") == 0 && fasti_field_class[i] != "fasti_date"))

			{

				fasti_field_class.splice(i, 1);

				i -= 1;

			}

		}

		fasti_field.className = fasti_field_class.join(" ");;

  }

  return fasti_return;

}



function fasti_formattime(oTimeField)

{

  var fasti_return = null;

  if(oTimeField)

  {

    var oTime = new Date( );

    var sTime = oTimeField.value || "";

    var aTime = new Array(2);

    switch(sTime.toLowerCase( ))

    {

      case "adess": case "adesso": case "now": case "jetzt": case "ahora": case "maint": case "maintenant":

        var date_now = new Date( )

        oTimeField.value = fasti_zerofill(date_now.getHours( )) + ":" + fasti_zerofill(date_now.getMinutes( ));

        fasti_return = date_now;

        oTimeField.className = oTimeField.className.replace(/error /, "normal ");

      break;



      default:

        if(sTime)

        {

          sTime = sTime.replace(/[^0-9\:\.]/gi, "")

          sTime = sTime.replace(/[\:\.\-\,]/gi, ":")

          if(sTime.search(/^[0-9]{1,2}\:[0-9]{1,2}$/) == 0)

          {

            aTime = sTime.split(":")

            aTime[0] = parseInt(aTime[0], 10) || 0;

            aTime[1] = parseInt(aTime[1], 10) || 0;

            sTime = fasti_zerofill(aTime[0]) + ":" + fasti_zerofill(aTime[1]);

          }

          else if(sTime.length == 4)

          {

            aTime[0] = parseInt(sTime.substring(0, 2), 10) || 0;

            aTime[1] = parseInt(sTime.substring(2, 4), 10) || 0;

            sTime = fasti_zerofill(aTime[0]) + ":" + fasti_zerofill(aTime[1]);

          }

          oTime.setHours(aTime[0]);

          oTime.setMinutes(aTime[1]);

          if(oTime.getHours( ) == aTime[0] && oTime.getMinutes( ) == aTime[1])

          {

            oTimeField.value = sTime;

            fasti_return = oTime;

            oTimeField.className = oTimeField.className.replace(/error /, "normal ");

          }

          else oTimeField.className = oTimeField.className.replace(/normal /, "error ");

        }

        else

        {

          var fCampoErr = false; 

          if(document.forms["main"].elements["ElencoErrori"]) for(var f=0; f<document.forms["main"].elements["ElencoErrori"].options.length; f++)

          {

            if(document.forms["main"].elements[document.forms["main"].elements["ElencoErrori"].options[f].value] == oTimeField)

              fCampoErr = true;

          }

          if(fCampoErr)

            oTimeField.className = oTimeField.className.replace(/normal /, "error ");

          else

          {

            oTimeField.value = "";

            oTimeField.className = oTimeField.className.replace(/error /, "normal ");

          }

        }

      break;

    }

  }

  return fasti_return;

}



function fasti_hide(fasti_field)

{

  if(fasti_layer && fasti_field == fasti_current)

  {

		fasti_formatdate(fasti_current);

    fasti_current = null;

    fasti_layer.style.display = "none";

    fasti_layer.style.visibility = "hidden";

		fasti_layer.setAttribute("status", "hidden");

  }

}



function fasti_readsettings(fasti_field)

{

	var fasti_field_settings = new Array( ); 

	if(document.getElementById(fasti_field.id + "_fastisettings"))

	{

		var fasti_field_settings = document.getElementById(fasti_field.id + "_fastisettings").value.split("&");

		for(var i=0; i<fasti_field_settings.length; i++)

		{

			fasti_field_settings[i] = fasti_field_settings[i].split("=");

			fasti_field_settings[i][0] = fasti_field_settings[i][0].replace(/^\s\s*/, '').replace(/\s\s*$/, '').toLowerCase( );

			fasti_field_settings[i][1] = fasti_field_settings[i][1].replace(/^\s\s*/, '').replace(/\s\s*$/, '').toLowerCase( );

			fasti_field_settings[fasti_field_settings[i][0]] = fasti_field_settings[i][1];

		}

	}

	else var fasti_field_settings = new Array( );

	return fasti_field_settings;

}



function fasti_init(fasti_field, fasti_date)

{

  if(fasti_field)

  {

    var today = new Date( );

		var html_link = document.createElement("a"); 

    var nbsp = document.createTextNode("\xA0");

		var fasti_field_settings = fasti_readsettings(fasti_field);

		var min_date = null, max_date = null;

		if(fasti_field_settings["min"])

		{

			if(fasti_field_settings["min"] == "now")

				min_date = new Date( );

			else if(document.getElementById(fasti_field_settings["min"]))

			{

				min_date = fasti_formatdate(document.getElementById(fasti_field_settings["min"]));

				if(!min_date && document.getElementById(fasti_field_settings["min"] + "_fastisettings"))

				{

					var fasti_field_settings2 = fasti_readsettings(document.getElementById(fasti_field_settings["min"]));

					if(fasti_field_settings2["min"])

					{

						if(fasti_field_settings2["min"] == "now")

							min_date = new Date( );

						else

						{

							fasti_field_settings2["min"] = fasti_field_settings2["min"].split("-");

							min_date = new Date(parseInt(fasti_field_settings2["min"][0]), parseInt(fasti_field_settings2["min"][1])-1, parseInt(fasti_field_settings2["min"][2]), 0, 0, 0); 

						}

					}

				}

			}

			else

			{

				fasti_field_settings["min"] = fasti_field_settings["min"].split("-");

				min_date = new Date(parseInt(fasti_field_settings["min"][0], 10), parseInt(fasti_field_settings["min"][1], 10)-1, parseInt(fasti_field_settings["min"][2], 10), 0, 0, 0); 

			}

		}

		if(fasti_field_settings["max"])

		{

			if(fasti_field_settings["max"] == "now")

				max_date = new Date( );

			else if(document.getElementById(fasti_field_settings["max"]))

			{

				max_date = fasti_formatdate(document.getElementById(fasti_field_settings["max"]));

				if(!max_date && document.getElementById(fasti_field_settings["max"] + "_fastisettings"))

				{

					var fasti_field_settings2 = fasti_readsettings(document.getElementById(fasti_field_settings["max"]));

					if(fasti_field_settings2["max"])

					{

						if(fasti_field_settings2["max"] == "now")

							min_date = new Date( );

						else

						{

							fasti_field_settings2["max"] = fasti_field_settings2["max"].split("-");

							max_date = new Date(parseInt(fasti_field_settings2["max"][0]), parseInt(fasti_field_settings2["max"][1])-1, parseInt(fasti_field_settings2["max"][2]), 0, 0, 0); 

						}

					}

				}

			}

			else

			{

				if(typeof fasti_field_settings["max"] == "string")
				{
					fasti_field_settings["max"] = fasti_field_settings["max"].split("-");
					max_date = new Date(parseInt(fasti_field_settings["max"][0]), parseInt(fasti_field_settings["max"][1])-1, parseInt(fasti_field_settings["max"][2]), 0, 0, 0);
				} 
			}
		}



		if(!fasti_date)

			fasti_date = new Date( );

    fasti_date.setDate(1);

		fasti_layer.tFoot.rows[0].cells[1].replaceChild(document.createTextNode(fasti_config['months'][fasti_date.getMonth( )] + " " + fasti_date.getFullYear( )), fasti_layer.tFoot.rows[0].cells[1].firstChild);

		fasti_layer.setAttribute("current", fasti_date.getFullYear( ) + "-" + fasti_zerofill(fasti_date.getMonth( ) + 1));

		var fasti_unlock = false;  



    for(var f=0; f<fasti_layer.tBodies[0].rows[0].cells.length; f++)

    {

			if(!fasti_unlock && (f + fasti_config['weekfirstday']) % 7 == fasti_date.getDay( ))

				fasti_unlock = true;

			if(fasti_unlock)

      {

        if((min_date && fasti_date < min_date) || (max_date && fasti_date > max_date))

				{

	        fasti_layer.tBodies[0].rows[0].cells[f].className = "";

					if(fasti_layer.tBodies[0].rows[0].cells[f].firstChild)

						fasti_layer.tBodies[0].rows[0].cells[f].replaceChild(document.createTextNode(fasti_date.getDate( )), fasti_layer.tBodies[0].rows[0].cells[f].firstChild);

					else fasti_layer.tBodies[0].rows[0].cells[f].appendChild(document.createTextNode(fasti_date.getDate( )));

				}

				else

				{  

					var class_name = new Array( );

					var html_link = document.createElement("a"); 

					html_link.href = "#";

					html_link.onclick = fasti_writedate;

					html_link.setAttribute("time", fasti_date.getTime( ));

					if(html_link.firstChild)

						html_link.replaceChild(document.createTextNode(fasti_date.getDate( )), html_link.firstChild);

					else html_link.appendChild(document.createTextNode(fasti_date.getDate( )));

					if(fasti_layer.tBodies[0].rows[0].cells[f].firstChild)

						fasti_layer.tBodies[0].rows[0].cells[f].replaceChild(html_link, fasti_layer.tBodies[0].rows[0].cells[f].firstChild);

					else fasti_layer.tBodies[0].rows[0].cells[f].appendChild(html_link);



	        if(fasti_date.getFullYear( ) == today.getFullYear( ) && fasti_date.getMonth( ) == today.getMonth( ) && fasti_date.getDate( ) == today.getDate( )) 

  	        class_name.push("today");

    	    if(CurrentDate && fasti_date.getFullYear( ) == CurrentDate.getFullYear( ) && fasti_date.getMonth( ) == CurrentDate.getMonth( ) && fasti_date.getDate( ) == CurrentDate.getDate( ))

      	    class_name.push("current"); 

        	fasti_layer.tBodies[0].rows[0].cells[f].className = class_name.join(" ");

				}

        fasti_date.setDate(fasti_date.getDate( ) + 1);

      }

      else

      {

				if(fasti_layer.tBodies[0].rows[0].cells[f].firstChild)

					fasti_layer.tBodies[0].rows[0].cells[f].replaceChild(nbsp, fasti_layer.tBodies[0].rows[0].cells[f].firstChild);

				else fasti_layer.tBodies[0].rows[0].cells[f].appendChild(nbsp);

        fasti_layer.tBodies[0].rows[0].cells[f].className = "";

      }

    }

    for(var d=1; d<fasti_layer.tBodies[0].rows.length; d++)

    {

      for(var f=0; f<fasti_layer.tBodies[0].rows[d].cells.length; f++)

      {

        if(fasti_date.getDate( ) > 1)

        {

	        if((min_date && fasti_date < min_date) || (max_date && fasti_date > max_date))

					{

	  	      fasti_layer.tBodies[0].rows[d].cells[f].className = "";

						if(fasti_layer.tBodies[0].rows[d].cells[f].firstChild)

							fasti_layer.tBodies[0].rows[d].cells[f].replaceChild(document.createTextNode(fasti_date.getDate( )), fasti_layer.tBodies[0].rows[d].cells[f].firstChild);

						else fasti_layer.tBodies[0].rows[d].cells[f].appendChild(document.createTextNode(fasti_date.getDate( )));

					}

					else

					{

	          var class_name = new Array( );

						var html_link = document.createElement("a"); 

						html_link.href = "#";

						html_link.onclick = fasti_writedate;

						html_link.setAttribute("time", fasti_date.getTime( ));

						if(html_link.firstChild)

							html_link.replaceChild(document.createTextNode(fasti_date.getDate( )), html_link.firstChild);

						else html_link.appendChild(document.createTextNode(fasti_date.getDate( )));

						if(fasti_layer.tBodies[0].rows[d].cells[f].firstChild)

							fasti_layer.tBodies[0].rows[d].cells[f].replaceChild(html_link, fasti_layer.tBodies[0].rows[d].cells[f].firstChild);

						else fasti_layer.tBodies[0].rows[d].cells[f].appendChild(html_link);

  	        if(fasti_date.getFullYear( ) == today.getFullYear( ) && fasti_date.getMonth( ) == today.getMonth( ) && fasti_date.getDate( ) == today.getDate( )) 

    	        class_name.push("today");

      	    if(CurrentDate && fasti_date.getFullYear( ) == CurrentDate.getFullYear( ) && fasti_date.getMonth( ) == CurrentDate.getMonth( ) && fasti_date.getDate( ) == CurrentDate.getDate( ))

        	    class_name.push("current"); 

          	fasti_layer.tBodies[0].rows[d].cells[f].className = class_name.join(" ");

					}

          fasti_date.setDate(fasti_date.getDate( ) + 1);

        }

        else

        {

	        if(fasti_layer.tBodies[0].rows[d].cells[f].firstChild)

						fasti_layer.tBodies[0].rows[d].cells[f].replaceChild(nbsp, fasti_layer.tBodies[0].rows[d].cells[f].firstChild);

					else fasti_layer.tBodies[0].rows[d].cells[f].appendChild(nbsp);

          fasti_layer.tBodies[0].rows[d].cells[f].className = "";

        }

      }

    }

  }

}



function fasti_load( )

{

	var meta_info = document.getElementsByTagName("meta");

	for(f=0; f<meta_info.length; f++) if(meta_info[f].name.toLowerCase( ).indexOf("fasti_") == 0 && !meta_info[f].getAttribute("fasti_load"))

	{

		switch(meta_info[f].name.toLowerCase( ))

		{

			case "fasti_dateformat":

				var date_format = meta_info[f].content.toLowerCase( ); 

				if(date_format && date_format.indexOf("mm") > -1 && date_format.indexOf("dd") > -1 && date_format.indexOf("yy") > -1)

				{

					fasti_config["dateformat"] = date_format;

					meta_info[f].setAttribute("fasti_load", "true");

				}

				else meta_info[f].setAttribute("fasti_load", "false");

			break;

			case "fasti_months":

				var months = meta_info[f].content.split(",");

				for(g=0; g<months.length; g++)

				{

					months[g] = months[g].replace(/^\s+|\s+$/g, "");

					if(months[g])

						fasti_config["months"][g] = months[g]; 

				}

				meta_info[f].setAttribute("fasti_load", months.length ? "true" : "false");

			break;

			case "fasti_weekfirstday":

				fasti_config["weekfirstday"] = parseInt(meta_info[f].content) || 0;

				meta_info[f].setAttribute("fasti_load", "true");

			break;

			case "fasti_weekdays":

				var week_days = meta_info[f].content.split(",");

				for(g=0; g<week_days.length; g++)

				{

					week_days[g] = week_days[g].replace(/^\s+|\s+$/g, "");

					if(week_days[g])

						fasti_config["weekdays"][g] = week_days[g]; 

				}

				meta_info[f].setAttribute("fasti_load", week_days.length ? "true" : "false");

			break;

		}

	}

	

	if(document.forms && document.forms.length) for(var f=0; f<document.forms.length; f++)

	{

		if(document.forms[f].elements && document.forms[f].elements.length) for(var g=0; g<document.forms[f].elements.length; g++)

		{

			if(!document.forms[f].elements[g].getAttribute("fasti"))

			{

				if(document.forms[f].elements[g].type == "text" && !document.forms[f].elements[g].getAttribute("fasti") && document.forms[f].elements[g].className.search(/(^|\s)fasti_date(\s|$)/i) > -1)

				{

					if(document.forms[f].elements[g].addEventListener)

					{

						document.forms[f].elements[g].addEventListener("focus", fasti_display, false);

						document.forms[f].elements[g].addEventListener("dblclick", fasti_display, false);

					}

					else if(document.forms[f].elements[g].attachEvent)

					{

						document.forms[f].elements[g].attachEvent("onfocus", fasti_display);

						document.forms[f].elements[g].attachEvent("ondblclick", fasti_display);

					}

					document.forms[f].elements[g].setAttribute("autocomplete", "off");

					document.forms[f].elements[g].setAttribute("fasti", "date");

				}

				else

				{

					if(document.forms[f].elements[g].addEventListener)

						document.forms[f].elements[g].addEventListener("focus", fasti_blur, false);

					else if(document.forms[f].elements[g].attachEvent)

						document.forms[f].elements[g].attachEvent("onfocus", fasti_blur);

				}

			} 

		}

	}

	if(document.body && !fasti_layer)

		fasti_layer = fasti_create( );

}



function fasti_wheel(e)

{

	if(!e) e = event;

  if(e)

  {

		var current_month = fasti_layer.getAttribute("current").split("-");

		var fasti_date = new Date(parseInt(current_month[0], 10), parseInt(current_month[1], 10) - 1, 1);

    var months = 0;

    if(e.wheelDelta)

      months = parseInt(e.wheelDelta / 120, 10) || 0;

    else if(e.detail)

			months = e.detail > 0 ? -1 : 1;

    if(months)

		{

			fasti_date.setMonth(fasti_date.getMonth( ) - months);

  	  fasti_init(fasti_current, fasti_date);

		}

		if(e.stopPropagation)

			e.stopPropagation( );

		else if(typeof e.cancelBubble != "undefined")

			e.cancelBubble = true;

  }

  return false;

}



function fasti_writedate(e)

{

	if(!e) e = event;

	if(e.target)

		var fasti_link = e.target;

	else if(e.srcElement)

		var fasti_link = e.srcElement;



	fasti_time = parseInt(fasti_link.getAttribute("time")) || 0;



	if(fasti_time && fasti_current)

  {

		var fasti_field_class = fasti_current.className.split(" ");

    current_date = new Date(fasti_time);

    fasti_focus = false;

   	var fasti_current_value = fasti_zerofill(current_date.getDate( )) + "/" + fasti_zerofill(current_date.getMonth( ) + 1) + "/" + fasti_zerofill(current_date.getFullYear( ), 4);

	  if(fasti_current.value != fasti_current_value)

		{ 

			fasti_current.value = fasti_current_value;

			if(typeof fasti_current.dispatchEvent != "undefined")

			{

				var change_event = document.createEvent("HTMLEvents");

				change_event.initEvent("change", true, false);

				fasti_current.dispatchEvent(change_event);

			}

			else if(typeof fasti_current.fireEvent != "undefined")

				fasti_current.fireEvent("onchange");

		}

		for(var i=0; i<fasti_field_class.length; i++) if(!fasti_field_class[i] || (fasti_field_class[i].indexOf("fasti_") == 0 && fasti_field_class[i] != "fasti_date"))

		{

			fasti_field_class.splice(i, 1);

			i -= 1;

		}

		fasti_current.className = fasti_field_class.join(" ");;

		fasti_current.setAttribute("fasti_donothing", "true");

    fasti_current.focus( );

    fasti_current.select( );

  }

	fasti_hide(fasti_current);

	if(e.preventDefault)

		e.preventDefault( );

	else if(typeof e.cancelBubble != "undefined")

		e.cancelBubble = true;



/*	if(e.stopPropagation)

		e.stopPropagation( );

	else if(typeof e.cancelBubble != "undefined")

		e.cancelBubble = true;*/

  return false;

}



function fasti_zerofill(fasti_qty)

{

  var qty_s = "";

  var qty_z = 2;

  if(arguments.length > 1)

    qty_z = parseInt(arguments[1], 10) || 2;

  switch(typeof fasti_qty)

  {

    case "number": qty_s = Math.floor(Math.abs(fasti_qty)).toString( ); break;

    case "string" : qty_s = fasti_qty.replace(/\D/g, ""); break;

  }

  for(var f=qty_s.length; f<qty_z; f++)

    qty_s = "0" + qty_s;

  return qty_s;

}



if(document.attachEvent)

{

	document.attachEvent("onload", fasti_load);

	document.attachEvent("onclick", fasti_documentclick);

	document.attachEvent("onreadystatechange", fasti_load);

}

else if(self.addEventListener)

{

	self.addEventListener("load", fasti_load, false);

	self.addEventListener("readystatechange", fasti_load, false);

	document.addEventListener("click", fasti_documentclick, false);

}


