function clearDefault(control, defaultValue) {
  if (control.value==defaultValue) control.value = "";
}

function ShowPanel(show, id) {
    if (show) {
        YAHOO.util.Dom.addClass(id, 'ShowMe');
        YAHOO.util.Dom.removeClass(id, 'HideMe');
    }
    else {
        YAHOO.util.Dom.addClass(id, 'HideMe');
        YAHOO.util.Dom.removeClass(id, 'ShowMe');
    }
}


function LocaleStringToDate(DatePassed, DateSeparator, DayPosition, MonthPosition, YearPosition)
{	
	var ReturnedDate = new Date();
	try
	{
		var ArStDate = DatePassed.split(DateSeparator, 3);
		var iDay = 0;
		var iMonth = 0;
		var iYear = 0;
		
		for (var i = 0; i < ArStDate.length; i++)
		{
			if(i == DayPosition)
			{
				if(ArStDate[i].substring(0,1) == "0")
				{
					iDay = parseInt(ArStDate[i].substring(1,2));
				}
				else
				{
					iDay = parseInt(ArStDate[i]);
				}
			}
			if(i == MonthPosition)
			{
				if(ArStDate[i].substring(0,1) == "0")
				{
					iMonth = parseInt(ArStDate[i].substring(1,2));
				}
				else
				{
					iMonth = parseInt(ArStDate[i]);
				}

				iMonth = iMonth - 1;
			}
			if(i == YearPosition)
			{
				iYear = parseInt(ArStDate[i]);
			}
		}
		
		ReturnedDate.setFullYear(iYear,iMonth,iDay)
		if(
			(ReturnedDate.getFullYear()!=parseInt(iYear,10))
			||(ReturnedDate.getMonth()!=parseInt(iMonth,10))
			||(ReturnedDate.getDate()!=parseInt(iDay,10)))
		{
			ReturnedDate = new Date();
		}		
	}
	catch(err)
	{
		ReturnedDate = new Date();
	}
	return ReturnedDate;
}

function LocaleMonthYearToString(DatePassed, DateSeparator)
{
	var ResultLocaleMonthYearToString = "";
	ResultLocaleMonthYearToString += (DatePassed.getMonth() + 1);
	ResultLocaleMonthYearToString += DateSeparator;
	ResultLocaleMonthYearToString += DatePassed.getFullYear();
	return ResultLocaleMonthYearToString;
}

function LocaleDateToString(DatePassed, DateSeparator, DayPosition, MonthPosition, YearPosition) {
	var ResultLocaleDateToString = "";
	ResultLocaleDateToString += BuildDateString(0, DatePassed, DayPosition, MonthPosition, YearPosition);
	ResultLocaleDateToString += DateSeparator;
	ResultLocaleDateToString += BuildDateString(1, DatePassed, DayPosition, MonthPosition, YearPosition);
	ResultLocaleDateToString += DateSeparator;
	ResultLocaleDateToString += BuildDateString(2, DatePassed, DayPosition, MonthPosition, YearPosition);
	return ResultLocaleDateToString;
	
}

function BuildDateString(Position, DatePassed, DayPosition, MonthPosition, YearPosition) {
	var ResultBuildDateString = "";
	if(DayPosition == Position)
	{
		ResultBuildDateString += DatePassed.getDate();
	}
	if(MonthPosition == Position)
	{
		ResultBuildDateString += (DatePassed.getMonth() + 1);
	}
	if(YearPosition == Position)
	{
		ResultBuildDateString += DatePassed.getFullYear();
	}
	return ResultBuildDateString;
}


function OverrideDefaultKeyPress(e, ElementId, ButtonId) {

	// ElementId = the id of any element to set the focus before submitting the form
	// ButtonId = the id of the button to fire

	var Element = document.getElementById(ElementId);
	var Button = document.getElementById(ButtonId);
	var keycode;
	if (window.event) // IE
	{
		keycode = e.keyCode;
	}
	else if (e.which) // Everything else
	{
		keycode = e.which;
	}

	if (keycode == 13) {
		alert('test1');
		Element.focus();
	}
}

function ClickParentButton(buttonId) {
	var button = parent.document.getElementById(buttonId);
	if (button != null) {
		button.click();
	}
}

function ClickParentButtonReload(buttonId, url) {
	var button = parent.document.getElementById(buttonId);
	if (button != null) {
		button.click();
	}
	location.href = url;
}
