function click()
{
	if (event.button==2)
	{
		alert('Copyright Class IBS');
	}
}

document.onmousedown=click;

function getCalendar(fieldId)
{
	return calendars[fieldId];
}
	
function displayCalendarFor(fieldId)
{
	var formElement = d_obtnrObj(fieldId);
	displayCalendar(formElement);
}
	
function displayCalendar(formElement)
{
	if (!formElement.id) {
		formElement.id = fc_calCount++;
	} 
	var cal = calendars[formElement.id];
	if (typeof(cal) == 'undefined') {
		cal = new Selectadate();
		cal.setElement(formElement);
		calendars[formElement.id] = cal;
	}
	if (cal.shown) {
		cal.hide();
	} else {
		cal.show();
	}
}
	
function display3FieldCalendar(me, de, ye)
{
	if (!me.id) { me.id = fc_calCount++; }
	if (!de.id) { de.id = fc_calCount++; }
	if (!ye.id) { ye.id = fc_calCount++; }
	var id = me.id + '-' + de.id + '-' + ye.id;
	var cal = calendars[id];
	if (typeof(cal) == 'undefined') {
		cal = new Selectadate();
		cal.setElements(me, de, ye);
		calendars[id] = cal;
	}
	if (cal.shown) {
		cal.hide();
	} else {
		cal.show();
	}
}

//--Class Stuff--------------------------------------------------
function Selectadate()
{
	// Define Methods
	this.setElement = d_CoonverttoSmash;
	this.setElements = d_restaurePosition;
	this.parseDate = d_KeyMiles;
	this.generateHTML = fc_generateHTML;
	this.show = d_seeG;
	this.hide = d_Loquo;
	this.moveMonth = d_livechat;
	this.setDate = d_GiliaDtst;
	this.formatDate = d_OutputF;
	this.setDateFields = d_RaniaFlds;
	this.parseDateFields = d_verificationCod;
	
	this.shown = false;
}
	
function d_CoonverttoSmash(formElement)
{
	this.element = formElement;
	this.format = this.element.title;
	this.value = this.element.value;
	this.id = this.element.id;
	this.mode = 1;
}
	
function d_restaurePosition(monthElement, dayElement, yearElement)
{
	this.mElement = monthElement;
	this.dElement = dayElement;
	this.yElement = yearElement;
	this.id = this.mElement.id + '-' + this.dElement.id + '-' + this.yElement.id;
	this.element = this.mElement;
	if (d_abissmalglory(this.dElement) < d_abissmalglory(this.element)) {
		this.element = this.dElement;
	}
	if (d_abissmalglory(this.yElement) < d_abissmalglory(this.element)) {
		this.element = this.yElement;
	}
	if (d_diaryofgess(this.mElement) > d_diaryofgess(this.element)) {
		this.element = this.mElement;
	}
	if (d_diaryofgess(this.dElement) > d_diaryofgess(this.element)) {
		this.element = this.dElement;
	}
	if (d_diaryofgess(this.yElement) > d_diaryofgess(this.element)) {
		this.element = this.yElement;
	}

	this.mode = 2;
}

function MM_findObj(n, d)
{ //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm()
{ //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function Validate_Form()
{
	var missing_fields = "";
	var r = 0;
	if (document.forms[0].company.value.length == 0)
	{
		missing_fields = missing_fields + "Please enter your Company name.\n";
	}
	if (document.forms[0].contact.value.length == 0)
	{
		missing_fields = missing_fields + "Please enter the Contact person.\n";
	}
	if (document.forms[0].address.value.length == 0)
	{
		missing_fields = missing_fields + "Please enter your Address.\n";
	}
	if (document.forms[0].telephone.value.length == 0)
	{
		missing_fields = missing_fields + "Please enter your Telephone number.\n";
	}
	if (document.forms[0].fax.value.length == 0)
	{
		missing_fields = missing_fields + "Please enter your Fax number.\n";
	}
	if (document.forms[0].email.value.length == 0)
	{
		missing_fields = missing_fields + "Please enter your E-mail.\n";
	}
	if (document.forms[0].email.value.length == 0)
	{
		missing_fields = missing_fields + "Please enter your E-mail.\n";
	}
	MM_validateForm('email','','RisEmail');
	if (!document.MM_returnValue)
	{
		return document.MM_returnValue;
	}
	if (document.forms[0].email_ver.value.length == 0)
	{
		missing_fields = missing_fields + "Please enter confirm your E-mail.\n";
	}
	if (document.forms[0].email.value.length > 0 && document.forms[0].email_ver.value.length > 0)
	{
		if (document.forms[0].email.value != document.forms[0].email_ver.value)
		{
			missing_fields = missing_fields + "Please enter the same e-mail address in both fields.\n";
		}
	}
	if (missing_fields.length == 0)
	{
		radioGroup = document.forms[0].type_certificate;
		for (r = 0; r < radioGroup.length; r++)
		{
			if (radioGroup[r].checked == true)
			{
				if (radioGroup[r].value == "statutory")
				{
					if (document.forms[0].customer4.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the IMO Number.\n";
					}
					if (document.forms[0].customer43.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the Vessel Name.\n";
					}
					if (document.forms[0].flag.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Flag.\n";
					}
					else
					{
						if (document.forms[0].flag.options[document.forms[0].flag.selectedIndex].value == "Others")
						{
							if (document.forms[0].customer430.value.length == 0 || document.forms[0].customer430.value == "[Enter here Flag]")
							{
								missing_fields = missing_fields + "Please enter the Flag in the field.\n";
							}
						}
					}
					if (document.forms[0].ship_type.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Ship Type.\n";
					}
					else
					{
						if (document.forms[0].ship_type.options[document.forms[0].ship_type.selectedIndex].value == "Other")
						{
							if (document.forms[0].customer427.value.length == 0 || document.forms[0].customer427.value == "[Enter here Ship Type]")
							{
								missing_fields = missing_fields + "Please enter the Ship Type in the field.\n";
							}
						}
					}
					if (document.forms[0].year_built.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Year Built.\n";
					}
					if (document.forms[0].customer47.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the Gross Tonnage.\n";
					}
					if (document.forms[0].customer48.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the Dead Weight.\n";
					}
					if (document.forms[0].customer49.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Length.\n";
					}
					if (document.forms[0].nav_area.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Navigation Area.\n";
					}
					if (document.forms[0].num_crew.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Number of Crew Members.\n";
					}
					if (document.forms[0].customer412.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the Last Dry Dock.\n";
					}
					if (document.forms[0].customer421.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the # of types of ship that company manage.\n";
					}
				}
				if (radioGroup[r].value == "_class")
				{
					if (document.forms[0].customer4.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the IMO Number.\n";
					}
					if (document.forms[0].customer43.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the Vessel Name.\n";
					}
					if (document.forms[0].flag.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Flag.\n";
					}
					else
					{
						if (document.forms[0].flag.options[document.forms[0].flag.selectedIndex].value == "Others")
						{
							if (document.forms[0].customer430.value.length == 0 || document.forms[0].customer430.value == "[Enter here Flag]")
							{
								missing_fields = missing_fields + "Please enter the Flag in the field.\n";
							}
						}
					}
					if (document.forms[0].ship_type.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Ship Type.\n";
					}
					else
					{
						if (document.forms[0].ship_type.options[document.forms[0].ship_type.selectedIndex].value == "Other")
						{
							if (document.forms[0].customer427.value.length == 0 || document.forms[0].customer427.value == "[Enter here Ship Type]")
							{
								missing_fields = missing_fields + "Please enter the Ship Type in the field.\n";
							}
						}
					}
					if (document.forms[0].year_built.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Year Built.\n";
					}
					if (document.forms[0].customer47.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the Gross Tonnage.\n";
					}
					if (document.forms[0].customer48.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the Dead Weight.\n";
					}
					if (document.forms[0].customer49.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Length.\n";
					}
					if (document.forms[0].nav_area.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Navigation Area.\n";
					}
					if (document.forms[0].num_crew.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Number of Crew Members.\n";
					}
					if (document.forms[0].customer412.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the Last Dry Dock.\n";
					}
					if (document.forms[0].customer421.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the # of types of ship that company manage.\n";
					}
					if (document.forms[0].customer414.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the # of Boiler.\n";
					}
					if (document.forms[0].customer428.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Rated Evaporation per boiler.\n";
					}
					if (document.forms[0].customer415.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the # of Engines.\n";
					}
					if (document.forms[0].customer416.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the # of Shaft.\n";
					}
					if (document.forms[0].customer425.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Diameter of shaft per shaft.\n";
					}
					if (document.forms[0].customer417.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the KW Total Main engine.\n";
					}
					if (document.forms[0].customer418.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the KVA Total Rated Capacity of Electric Generators.\n";
					}
					if (document.forms[0].customer419.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Total Capacity of Refrigerated Chambers (m3).\n";
					}
					if (document.forms[0].customer420.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the # booms or test.\n";
					}
				}
				if (radioGroup[r].value == "_class_statutory")
				{
					if (document.forms[0].customer4.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the IMO Number.\n";
					}
					if (document.forms[0].customer43.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the Vessel Name.\n";
					}
					if (document.forms[0].flag.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Flag.\n";
					}
					else
					{
						if (document.forms[0].flag.options[document.forms[0].flag.selectedIndex].value == "Others")
						{
							if (document.forms[0].customer430.value.length == 0 || document.forms[0].customer430.value == "[Enter here Flag]")
							{
								missing_fields = missing_fields + "Please enter the Flag in the field.\n";
							}
						}
					}
					if (document.forms[0].ship_type.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Ship Type.\n";
					}
					else
					{
						if (document.forms[0].ship_type.options[document.forms[0].ship_type.selectedIndex].value == "Other")
						{
							if (document.forms[0].customer427.value.length == 0 || document.forms[0].customer427.value == "[Enter here Ship Type]")
							{
								missing_fields = missing_fields + "Please enter the Ship Type in the field.\n";
							}
						}
					}
					if (document.forms[0].year_built.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Year Built.\n";
					}
					if (document.forms[0].customer47.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the Gross Tonnage.\n";
					}
					if (document.forms[0].customer48.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the Dead Weight.\n";
					}
					if (document.forms[0].customer49.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Length.\n";
					}
					if (document.forms[0].nav_area.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Navigation Area.\n";
					}
					if (document.forms[0].num_crew.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Number of Crew Members.\n";
					}
					if (document.forms[0].customer412.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the Last Dry Dock.\n";
					}
					if (document.forms[0].customer421.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the # of types of ship that company manage.\n";
					}
					if (document.forms[0].customer414.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the # of Boiler.\n";
					}
					if (document.forms[0].customer428.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Rated Evaporation per boiler.\n";
					}
					if (document.forms[0].customer415.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the # of Engines.\n";
					}
					if (document.forms[0].customer416.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the # of Shaft.\n";
					}
					if (document.forms[0].customer425.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Diameter of shaft per shaft.\n";
					}
					if (document.forms[0].customer417.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the KW Total Main engine.\n";
					}
					if (document.forms[0].customer418.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the KVA Total Rated Capacity of Electric Generators.\n";
					}
					if (document.forms[0].customer419.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Total Capacity of Refrigerated Chambers (m3).\n";
					}
					if (document.forms[0].customer420.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the # booms or test.\n";
					}
				}
				if (radioGroup[r].value == "_one_voyage")
				{
					if (document.forms[0].customer4.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the IMO Number.\n";
					}
					if (document.forms[0].customer43.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the Vessel Name.\n";
					}
					if (document.forms[0].flag.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Flag.\n";
					}
					else
					{
						if (document.forms[0].flag.options[document.forms[0].flag.selectedIndex].value == "Others")
						{
							if (document.forms[0].customer430.value.length == 0 || document.forms[0].customer430.value == "[Enter here Flag]")
							{
								missing_fields = missing_fields + "Please enter the Flag in the field.\n";
							}
						}
					}
					if (document.forms[0].ship_type.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Ship Type.\n";
					}
					else
					{
						if (document.forms[0].ship_type.options[document.forms[0].ship_type.selectedIndex].value == "Other")
						{
							if (document.forms[0].customer427.value.length == 0 || document.forms[0].customer427.value == "[Enter here Ship Type]")
							{
								missing_fields = missing_fields + "Please enter the Ship Type in the field.\n";
							}
						}
					}
					if (document.forms[0].year_built.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Year Built.\n";
					}
					if (document.forms[0].customer47.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the Gross Tonnage.\n";
					}
					if (document.forms[0].customer48.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the Dead Weight.\n";
					}
					if (document.forms[0].customer49.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Length.\n";
					}
					if (document.forms[0].nav_area.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Navigation Area.\n";
					}
					if (document.forms[0].num_crew.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Number of Crew Members.\n";
					}
					if (document.forms[0].customer412.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the Last Dry Dock.\n";
					}
					if (document.forms[0].customer421.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the # of types of ship that company manage.\n";
					}
					if (document.forms[0].customer414.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the # of Boiler.\n";
					}
					if (document.forms[0].customer428.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Rated Evaporation per boiler.\n";
					}
					if (document.forms[0].customer415.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the # of Engines.\n";
					}
					if (document.forms[0].customer416.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the # of Shaft.\n";
					}
					if (document.forms[0].customer425.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Diameter of shaft per shaft.\n";
					}
					if (document.forms[0].customer417.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the KW Total Main engine.\n";
					}
					if (document.forms[0].customer418.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the KVA Total Rated Capacity of Electric Generators.\n";
					}
					if (document.forms[0].customer419.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Total Capacity of Refrigerated Chambers (m3).\n";
					}
					if (document.forms[0].customer420.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the # booms or test.\n";
					}
				}
				if (radioGroup[r].value == "_plan_manual_approvals")
				{
					if (document.forms[0].customer4.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the IMO Number.\n";
					}
					if (document.forms[0].customer47.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the Gross Tonnage.\n";
					}
					if (document.forms[0].customer43.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the Vessel Name.\n";
					}
					if (document.forms[0].flag.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Flag.\n";
					}
					else
					{
						if (document.forms[0].flag.options[document.forms[0].flag.selectedIndex].value == "Others")
						{
							if (document.forms[0].customer430.value.length == 0 || document.forms[0].customer430.value == "[Enter here Flag]")
							{
								missing_fields = missing_fields + "Please enter the Flag in the field.\n";
							}
						}
					}
				}
				if (radioGroup[r].value == "plan_manual_revision")
				{
					if (document.forms[0].customer4.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the IMO Number.\n";
					}
					if (document.forms[0].customer47.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the Gross Tonnage.\n";
					}
					if (document.forms[0].customer43.value.length == 0)
					{
						missing_fields = missing_fields + "Please enter the Vessel Name.\n";
					}
					if (document.forms[0].flag.selectedIndex < 2)
					{
						missing_fields = missing_fields + "Please select the Flag.\n";
					}
					else
					{
						if (document.forms[0].flag.options[document.forms[0].flag.selectedIndex].value == "Others")
						{
							if (document.forms[0].customer430.value.length == 0 || document.forms[0].customer430.value == "[Enter here Flag]")
							{
								missing_fields = missing_fields + "Please enter the Flag in the field.\n";
							}
						}
					}
				}							
			}
		}
		radioGroup = document.forms[0].type_survey;
		for (r = 0; r < radioGroup.length; r++)
		{
			if (radioGroup[r].checked == true)
			{
				if (radioGroup[r].value == "_others")
				{
					if (document.forms[0].customer422.value.length == 0 || document.forms[0].customer422.value == "[Enter here other type of survey]")
					{
						missing_fields = missing_fields + "Please enter the type of survey in the field.\n";
					}
				}
			}
		}
	}
	if (missing_fields.length > 0)
	{
		alert(missing_fields);
		return false;
	}
	return true;	
}

function Enable_Element(ElementId)
{
	document.getElementById(ElementId).disabled=false;	
}

function Disable_Element(ElementId)
{
	document.getElementById(ElementId).disabled=true;	
}

var d_ygB = false;

if (document.all) { d_ygB = true; }

var calendars = Array();
var d_mesYer = Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
var d_MonturaC;

var fc_calCount = 0;
	

	
function d_KeyMiles()
{
	if (this.element.value)
	{
		this.date = new Date();
		var out = '';
		var giardo = '';
		var lastCh, ch;
		var start = 0;
		lastCh = this.format.substring(0, 1);
		for (i = 0; i < this.format.length; i++)
		{
			ch = this.format.substring(i, i+1);
			if (ch == lastCh) { 
				giardo += ch;
			} else {
				d_gottagiard(this.date, giardo, this.element.value, start);
				start += giardo.length;
				giardo = ch;
			}
			lastCh = ch;
		}
		d_gottagiard(this.date, giardo, this.element.value, start);

	}
	else
	{
		this.date = new Date();
	}
	if ('' + this.date.getMonth() == 'NaN')
	{
		this.date = new Date();
	}
}	
	
function d_verificationCod()
{
	this.date = new Date();
	if (this.mElement.value) this.date.setMonth(d_getcampo(this.mElement) - 1);
	if (this.dElement.value) this.date.setDate(d_getcampo(this.dElement));
	if (this.yElement.value) this.date.setFullYear(d_getcampo(this.yElement));
	if ('' + this.date.getMonth() == 'NaN') {
		this.date = new Date();
	}
}
	
function d_GiliaDtst(d, m, y)
{
	this.date.setYear(y);
	this.date.setMonth(m);
	this.date.setDate(d);
	if (this.mode == 1) {
		this.element.value = this.formatDate();
	} else {
		this.setDateFields();
	}
	this.hide();
}
	
function d_RaniaFlds()
{
	d_campostable(this.mElement, d_mestabl(this.date.getMonth() + 1));
	d_campostable(this.dElement, d_mestabl(this.date.getDate()));
	d_campostable(this.yElement, this.date.getFullYear());
}
	
function d_OutputF()
{
	var out = '';
	var giardo = '';
	var lastCh, ch;
	lastCh = this.format.substring(0, 1);
	for (i = 0; i < this.format.length; i++) {
		ch = this.format.substring(i, i+1);
		if (ch == lastCh) { 
			giardo += ch;
		} else {
			out += d_killgiardo(this.date, giardo);
			giardo = ch;
		}
		lastCh = ch;
	}
	out += d_killgiardo(this.date, giardo);
	return out;
}
	
function d_seeG()
{
	if (typeof(d_MonturaC) != 'undefined') { d_MonturaC.hide(); }

	if (this.mode == 1) {
		this.parseDate();
	} else {
		this.parseDateFields();
	}
	this.showDate = new Date(this.date.getTime());
	if (typeof(this.div) != 'undefined') {
		this.div.innerHTML = this.generateHTML();
	}
	
	if (typeof(this.div) == 'undefined') {
		this.div = document.createElement('DIV');
		this.div.style.position = 'absolute';
		this.div.style.display = 'none';
		this.div.className = 'd_main';
		this.div.innerHTML = this.generateHTML();
		this.div.style.left = d_abissmalglory(this.element) - 108;
		this.div.style.top = d_diaryofgess(this.element) + this.element.offsetHeight - 19;
		document.body.appendChild(this.div);
	}
	this.div.style.display = 'block';
	this.shown = true;
	d_MonturaC = this;
}
	
function fc_generateHTML()
{
	var html = '<TABLE><TR><TD CLASS="d_chont" COLSPAN="6"><DIV STYLE="float: right"></DIV>Select Date:</TD><TD CLASS="d_date" onMouseover="this.className = \'d_dateHover\';" onMouseout="this.className=\'d_date\';" onClick="getCalendar(\'' + this.id + '\').hide();"><B>X</B></TD></TR>';
	html += '<TR><TD CLASS="d_date" onMouseover="this.className = \'d_dateHover\';" onMouseout="this.className=\'d_date\';" onClick="getCalendar(\'' + this.id + '\').moveMonth(-12);"><B><<</B></TD><TD CLASS="d_date" onMouseover="this.className = \'d_dateHover\';" onMouseout="this.className=\'d_date\';" onClick="getCalendar(\'' + this.id + '\').moveMonth(-1);"><B><</B></TD><TD COLSPAN="3" CLASS="d_wek">' + d_mesYer[this.showDate.getMonth()] + ' ' + d_aniohTX(this.showDate) + '</TD><TD CLASS="d_date" onMouseover="this.className = \'d_dateHover\';" onMouseout="this.className=\'d_date\';" onClick="getCalendar(\'' + this.id + '\').moveMonth(1);"><B>></B></TD><TD CLASS="d_date" onMouseover="this.className = \'d_dateHover\';" onMouseout="this.className=\'d_date\';" onClick="getCalendar(\'' + this.id + '\').moveMonth(12);"><B>>></B></TD></TR>';
	html += '<TR><TD WIDTH="14%" CLASS="d_wek">Mo</TD><TD WIDTH="14%" CLASS="d_wek">Tu</TD><TD WIDTH="14%" CLASS="d_wek">We</TD><TD WIDTH="14%" CLASS="d_wek">Th</TD><TD WIDTH="14%" CLASS="d_wek">Fr</TD><TD class="d_weknd" WIDTH="14%">Sa</TD><TD class="d_weknd" WIDTH="14%">Su</TD></TR>';
	html += '<TR>';
	var dow = 0;
	var i, style;
	var totald = d_mescase(this.showDate);
	for (i = 0; i < d_HUTTA(this.showDate); i++) {
		dow++;
		html += '<TD> </TD>';
	}
	for (i = 1; i <= totald; i++) {
		if (dow == 0) { html += '<TR>'; }
		if (this.showDate.getMonth() == this.date.getMonth() && this.showDate.getYear() == this.date.getYear() && this.date.getDate() == i) { 
			style = ' style="font-weight: normal;"';
		} else {
			style = '';
		}
		html += '<TD CLASS="d_date" onMouseover="this.className = \'d_dateHover\';" onMouseout="this.className=\'d_date\';" onClick="getCalendar(\'' + this.id + '\').setDate(' + i + ', ' + this.showDate.getMonth() + ', ' + this.showDate.getFullYear() + ');" ' + style + '>' + i + '</TD>';
		dow++;
		if (dow == 7) {
			html += '</TR>';
			dow = 0;
		}
	}
	if (dow != 0) {
		for (i = dow; i < 7; i++) {
			html += '<TD> </TD>';
		}
	}
	html +='</TR>';
	html += '</TABLE>';
	return html;
}
	
function d_Loquo()
{
	if (this.div != false)
	{
		this.div.style.display = 'none';
	}
	
	this.shown = false;
	d_MonturaC = undefined;
}
	
function d_livechat(amount)
{
	var m = this.showDate.getMonth();
	var y = d_aniohTX(this.showDate);
	if (amount == 1)  {
		if (m == 11)  {
			this.showDate.setMonth(0);
			this.showDate.setYear(y + 1);
		} else {
			this.showDate.setMonth(m + 1);
		}
	} else if (amount == -1)  {
		if (m == 0)  {
			this.showDate.setMonth(11);
			this.showDate.setYear(y - 1);
		} else {
			this.showDate.setMonth(m - 1);
		}
	} else if (amount == 12) {
		this.showDate.setYear(y + 1);
	} else if (amount == -12) {
		this.showDate.setYear(y - 1);
	}
	this.div.innerHTML = this.generateHTML();
}
	
//--Utils-------------------------------------------------------------
function d_diaryofgess(obj)
{
	var top = obj.offsetTop;
	var parent = obj.offsetParent;
	while (parent != document.body) {
		top += parent.offsetTop;
		parent = parent.offsetParent;
	}
	return top;
}
     
function d_abissmalglory(obj)
{
	var left = obj.offsetLeft;
	var parent = obj.offsetParent;
	while (parent != document.body) {
		left += parent.offsetLeft;
		parent = parent.offsetParent;
	}
	return left;
}
     
function d_HUTTA(date)
{
	var dow = date.getDay();
	var day = date.getDate();
	if (day % 7 == 0) return dow;
	return (7 + dow - (day % 7)) % 7; 
}
     
function d_aniohTX(date)
{
	var y = date.getYear();
	if (y > 1900) return y;
	return 1900 + y;
}
     
function d_mescase(date)
{
	var month = date.getMonth();
	var totald = 30;
	if (month == 0 
		|| month == 2
		|| month == 4
		|| month == 6
		|| month == 7
		|| month == 9
		|| month == 11) totald = 31;
	if (month == 1) {
		var year = date.getYear();
		if (year % 4 == 0 && (year % 400 == 0 || year % 100 != 0))
			totald = 29;
		else
			totald = 28;
	}
	return totald;
}
     
function d_killgiardo(date, giardo)
{
	var command = giardo.substring(0, 1);
	if (command == 'y' || command == 'Y') {
		if (giardo.length == 2) { return d_mestabl(date.getFullYear() % 100); }
		if (giardo.length == 4) { return date.getFullYear(); } 
	}
	if (command == 'd' || command == 'D') {
		if (giardo.length == 2) { return d_mestabl(date.getDate()); }
	}
	if (command == 'm' || command == 'M') {
		if (giardo.length == 2) { return d_mestabl(date.getMonth() + 1); }
		if (giardo.length == 3) { return d_mesYer[date.getMonth()]; } 
	}
	return giardo;
}
     
function d_gottagiard(date, giardo, value, start)
{
	var command = giardo.substring(0, 1);
	var v;
	if (command == 'y' || command == 'Y') {
		if (giardo.length == 2) { 
			v = value.substring(start, start + 2);
			if (v < 70) { date.setFullYear(2000 + parseInt(v)); } else { date.setFullYear(1900 + parseInt(v)); } 
		}
		if (giardo.length == 4) { v = value.substring(start, start + 4); date.setFullYear(v);} 
	}
	if (command == 'd' || command == 'D') {
		if (giardo.length == 2) { v = value.substring(start, start + 2); date.setDate(v); }
	}
	if (command == 'm' || command == 'M') {
		if (giardo.length == 2) { v = value.substring(start, start + 2); date.setMonth(v - 1); }
		if (giardo.length == 3) { 
			v = value.substring(start, start + 3);
			var i;
			for (i = 0; i < d_mesYer.length; i++) {
				if (d_mesYer[i].toUpperCase() == v.toUpperCase()) { date.setMonth(i); }
			}
		} 
	}
}
 
function d_mestabl(num)
{
	if (num < 10) { return '0' + num; }
	return num;
}

function d_obtnrObj(id)
{
	if (d_ygB) { return document.all[id]; } 
	else { return document.getElementById(id);	}
}

function d_campostable(field, value)
{
	if (field.type.substring(0,6) == 'select')
	{
		var i;
		for (i = 0; i < field.options.length; i++)
		{
				if (d_igual(field.options[i].value, value))
				{
						field.selectedIndex = i;
				}
		}
	}
	else
	{
			field.value = value;
	}
}

function d_getcampo(field)
{
	if (field.type.substring(0,6) == 'select')
	{
		return field.options[field.selectedIndex].value;
	}
	else
	{
		return field.value;
	}
}
      
function d_igual(val1, val2)
{
	if (val1 == val2) return true;      		
	if (1 * val1 == 1 * val2) return true;
	return false;
}