﻿function toggle_visibility(id) 
{
	var e = document.getElementById(id);
	if (e.style.display == 'inline')
		e.style.display = 'none';
	else
		e.style.display = 'inline';
}

function toggle_menu(divId, buttonId)
{
	toggle_visibility(divId);
	var b = $("#"+buttonId);
	if (b.attr("class") == "down")
		b.attr("class", "up");
	else
		b.attr("class", "down");
}

function HideOtherMenus(toHideMenuDivID1, toHideMenuDivID2, toHideMenuButtonID1, toHideMenuButtonID2)
{
	if($("#"+toHideMenuDivID1).css("display") != "none" )
	{
		$("#"+toHideMenuDivID1).hide();
		
		if($("#"+toHideMenuButtonID1).hasClass("up"))
		{
			$("#"+toHideMenuButtonID1).toggleClass("down");
			$("#"+toHideMenuButtonID1).toggleClass("up");
		}
	}
	
	if($("#"+toHideMenuDivID2).css("display") != "none" )
	{
		$("#"+toHideMenuDivID2).hide();
		
		if($("#"+toHideMenuButtonID2).hasClass("up"))
		{
			$("#"+toHideMenuButtonID2).toggleClass("down");
			$("#"+toHideMenuButtonID2).toggleClass("up");
		}
	}
}

/*
 * Function checks if we have to disable or enable select elements.
 * Used i.e. in News & prices archive search
 */
function ToggleDisplayTabsAndContents(idContentDivToShow) { 	
	$("#" + idContentDivToShow).parent().children().each(function()
	{
		if (this.className == "tabbed_box")
		{
			if ($(this).attr("id") == idContentDivToShow)
			{
				$(this).show();
				$(this).children().show();
			}
			else
			{
				$(this).hide();
			}
		}
	});
}
          
/*
 * Function to handle an onkeypress or related event and click an
 * element specified by the buttonId parameter
 */
function clickSearch(e, buttonId)
{
	if (window.event) { e = window.event; }
	if (e.keyCode == 13)
	{
		document.getElementById(buttonId).click();
		
		if (e.returnValue) {
			e.cancelBubble = true;
			e.returnValue = false;
		}
		else if (e.stopPropagation) {
			e.stopPropagation();
			e.preventDefault();
		}
		
		return false;
	}
}

          
/*
 * Function checks if we have to disable or enable select elements.
 * Used i.e. in News & prices archive search
 */
function EnableMonthYearSelectorCheck(radio, startMonthId, startYearId, endMonthId, endYearId, seekRadio)
{
	if(radio.checked)
	{
		// disable target select elements
		document.getElementById(startMonthId).disabled = !seekRadio;
		document.getElementById(startYearId).disabled = !seekRadio;
		document.getElementById(endMonthId).disabled = !seekRadio;
		document.getElementById(endYearId).disabled = !seekRadio;
	}
}

/*
 * Function gets html ids od select elements, and disable those elements. Used only on startup, to set deafult disable.
 * Used i.e. in News & prices archive search
 */
function DisableMonthYearSelector(startMonthId, startYearId, endMonthId, endYearId)
{	
	// disable target select elements
	document.getElementById(startMonthId).disabled = true;
	document.getElementById(startYearId).disabled = true;
	document.getElementById(endMonthId).disabled = true;
	document.getElementById(endYearId).disabled = true;
}

/*
 * Function used to validate name to save search.
 */
function ValidateSaveSearchName(sender, args) 
{
	args.IsValid = true;
	
	for (var iterator = 0; iterator < _searches.length; iterator++)
	{
		if (_searches[iterator] == args.Value)
		{
			args.IsValid = false;
			break;
		}
	}
}

/*
 * Function used to pre-populate the email address fields
 */
function freeTrialAutoSubmit(sEmail)
{
	var iCounter = 0;

	$('input').each(function(index) {
		var currentId = $(this).attr('id');

		if ( currentId.search("ShowCheckoutControl_EmailContainer_EmailAddress") >= 0 || currentId.search("ShowCheckoutControl_EmailContainer_EmailCompare") >= 0 )
		{
			$(this).val(sEmail);
			iCounter++;
		}
	});

	if ( iCounter == 2 )
	{
		//submit the form
	}
}
