﻿var KeyCode_PageUp = 33;
var KeyCode_PageDown = 34;
var KeyCode_End = 35;
var KeyCode_Home = 36;
var KeyCode_ArrowLeft = 37;
var KeyCode_ArrowUp = 38;
var KeyCode_ArrowRight = 39;
var KeyCode_ArrowDown = 40;
var KeyCode_Enter = 13;

function OnAjaxResponseEndCommon()
{
	InitColorBox();
}

/// ********************************
/// COLORBOX INIT
/// ********************************
$(document).ready(InitColorBox);

function InitColorBox()
{
	InitColorBoxGroup(".thickbox");
	InitColorBoxGroup(".colorbox");
}

function InitColorBoxGroup(groupSelector, title, rel)
{
	$(groupSelector).colorbox
	({
		transition: "elastic",
		speed: 700,
		opacity: 0.85,
		current: "Obrázek {current} z {total}",
		next: "Předchozí",
		previous: "Další",
		close: "Zavřít",
		title: title != null ? !title : null,
		rel: rel
	});
}

/// ********************************
/// VALIDATION HELPER
/// ********************************
function ValidateTextLength(elemID, minLength, maxLength, initValue)
{
	var value = jQuery.trim($("#" + elemID).val());
	
	return value.length >= minLength
		&& (maxLength == null || value.length <= maxLength)
		&& (initValue == null || value.toLowerCase() != initValue.toLowerCase());
}

function OnTextValueClientValidate(validator, args, minLength, maxLength)
{
	args.IsValid = ValidateTextLength(validator.controltovalidate, minLength, maxLength);
}

function OnComboBoxClientValidate(validator, args)
{
	var cmb = $find(validator.controltovalidate);
	var fitem = cmb.get_items().getItem(0);
	
	if (fitem != null && fitem.get_value() == "0") args.IsValid = fitem.get_selected() == false;
	else args.IsValid = true;
}

function OnDropDownListClientValidate(validator, args)
{
	var cmb = $("#" + validator.controltovalidate);
	args.IsValid = cmb.attr("selectedIndex") > 0;
}
