var isBackend = false;

isIE6 = /msie|MSIE 6/.test(navigator.userAgent);

function resetSTFForm(formMessage)
{
	$('ctl0_Content_STFNameReqValidator').hide();
	$('ctl0_Content_STFEmailReqValidator').hide();
	$('ctl0_Content_STFEmailValidator').hide();
	$('ctl0_Content_STFFriendEmailReqValidator').hide();
	$('ctl0_Content_STFFriendEmailValidator').hide();
	$('ctl0_Content_STFName').value = '';
	$('ctl0_Content_STFEmail').value = '';
	$('ctl0_Content_STFFriendEmail').value = '';
	$('ctl0_Content_STFMessage').value = '';
	$('ctl0_Content_STFLabel').innerHTML = formMessage;
}

function setSTFFormEnabled(value)
{
	$('ctl0_Content_STFName').disabled = !value;
	$('ctl0_Content_STFEmail').disabled = !value;
	$('ctl0_Content_STFFriendEmail').disabled = !value;
	$('ctl0_Content_STFMessage').disabled = !value;
}

function displaySendToFriend(formMessage)
{
	resetSTFForm(formMessage);
	
	var element = $('stf');
	var dim = document.viewport.getDimensions();
	
	if (!isIE6)
	{
		element.style.top = Math.round((dim.height - element.getHeight()) / 2) + 'px';
		element.style.left = Math.round((dim.width - element.getWidth()) / 2) + 'px';
	}
	
	element.show();	
}

function closeSendToFriend()
{
	var element = $('stf');
	element.hide();
}

var isNotProccessAjax=true;

function toggleElement(objectID)
{
	if ($(objectID).style.display=='none')
	{
		$(objectID).show();
	}
	else
	{
		$(objectID).hide();
	}
}

/**
 * Sets the onload event of a starting ajax execution
 */
function setLoadEvent(loadingDiv) 
{
	isNotProccessAjax=false;
	$(loadingDiv).show();	
}

function setLoadEventPayment(loadingDiv) 
{
	isNotProccessAjax=false;	
	$(loadingDiv).style.visibility = 'visible';
}

function setCompleteEventPayment(loadingDiv) 
{
	isNotProccessAjax=true;	
	$(loadingDiv).style.visibility = 'hidden';
}

/**
 * Sets the end event of an ajax request
 */
function setCompleteEvent(loadingDiv) 
{
	isNotProccessAjax=true;
	$(loadingDiv).hide();	
}

function bookmarksite()
{
	if (document.all)
	{
		// For IE
		window.external.AddFavorite(location.href, document.title);
	}
	else if (window.sidebar)
	{
		// For Firefox
		window.sidebar.addPanel(document.title, location.href, "");
	}
	else
		alert("Your browser doesn't support this function!");
}


function countChars(textField, totalChars, resultDiv) 
{
	$(resultDiv).innerHTML = totalChars - $(textField).value.length;
}

var currentPicture = -1;
function pictureTitleEdit(type, id)
{
	if (type==0)
	{
		$('static-'+id).hide();
		$('dynamic-'+id).show();
		if (currentPicture>=0&&currentPicture!=id)
		{
			$('static-'+currentPicture).show();
			$('dynamic-'+currentPicture).hide();
		}
		currentPicture=id;
	
	} else
	{
		currentPicture=-1;
		$('static-'+id).show();
		$('dynamic-'+id).hide();
	}
}

function changeText(object1, object2)
{
	$(object1).value = $(object2).innerHTML;
}

function debug(obj)
{
	console.info(obj);
}

function checkPeriodSelected(ref, sender)
{	
	if ($(ref).value == 0 )
	{
		sender.checked = false;
	}
}