﻿function ConfirmDelete(entity) { return confirm("Weet u zeker dat u " + entity + " wilt verwijderen?"); }
function Confirmed()
{
	return confirm('Weet u zeker dat u dit item wilt verwijderen?');
}
function Navigate(index)
{
	__doPostBack('nav', index);
}

function Select(e,gvUniqueID,rowIndex)
{
	if (RowClicked(e)) __doPostBack(gvUniqueID, 'Select$' + rowIndex);
}

function RowClicked(e)
{
	var tag;
	if (e.target) tag = e.target.tagName;
	else tag = e.srcElement.tagName;

	if (tag == "SELECT" || tag == "INPUT" || tag == "OPTION") return false;
	else return true;
}

function IsClickInsideFilter(e)
{
	var target;
	if (e.target) target = e.target;
	else target = e.srcElement;

	if( target.className == "img-filter" ) return true;
	
	var scrollTop = document.documentElement.scrollTop;
	var bounds = Sys.UI.DomElement.getBounds($get('div_' + activeFilter));
	
	//debugger;
	if( e.clientX > bounds.x && e.clientX < bounds.x + bounds.width &&
		e.clientY + scrollTop > bounds.y && e.clientY + scrollTop < bounds.y + bounds.height ) return true;
	else return false;
}

function Search( filterName )
{
	var firstChildIndex = window.event ? 0 : 1
	var prefix = "m_mainContent_gv_ctl01_filter";
	var searchString = $get(prefix + filterName + "_tbSearch").value;
	var itemCount = $get(prefix + filterName + "_list").childNodes[firstChildIndex].childNodes.length;
	if (window.event == null) --itemCount;

	for (i = 0; i < itemCount; i++)
	{
		var row = $get(prefix + filterName + "_list").childNodes[firstChildIndex].childNodes[i];
		var itemText = row.cells[0].childNodes[1].innerHTML;

		var display;
		if (searchString == "" || itemText.toLowerCase().indexOf(searchString.toLowerCase()) > -1)
			display = "block";
		else
			display = "none";

		row.style.display = display;
	}
	
	return false;
}

function CheckEnter(e,buttonID)
{
	var key;
	if (window.event)
	{
		key = e.keyCode;
	}
	else if (e.which)
	{
		key = e.which;
	}
	if (key == 13)
	{
		$get(buttonID).click();
		return false;		
	}
	return true;
}
function ShowOrganisation(id)
{
	var url = "/Content/Website/Organisation.aspx?Id=" + id;
	var rand = Math.random()*1000 + "";
	window.open(url, rand.replace( /./g ,"") , 'width=1005, height=610, status=0, menubar=0, toolbar=0, location=0, resizable=1, directories=0, scrollbars=1');
	return false;
}

var databind = false;
function EditProduct(e,id,oid)
{
	var target = ( e.target ? e.target : e.srcElement );
	if( target.tagName != "INPUT" || ( target.src && target.src.indexOf("edit.gif") > 0 ) )
	{
		if(GetRadWindowManager().getActiveWindow() == null)
		{
			databind = false;
			var wnd = radopen("/Common/Product.aspx?id=" + id + "&oid=" + oid, null);
			wnd.setSize(780,380);
			wnd.set_modal(true);
			wnd.set_behaviors( Telerik.Web.UI.WindowBehaviors.Move + Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Resize + Telerik.Web.UI.WindowBehaviors.Maximize )
			wnd.add_close(windowClosed);
			wnd.set_title('Product bewerken');
		}
	}
	return false;
}

function windowClosed()
{
	if(databind)__doPostBack( "DetailsView", "DataBind" );
}

function textboxMultilineMaxNumber(e, txt, maxLen) {
	try {
		var key;
		if (window.event) {
			key = e.keyCode;
		}
		else if (e.which) {
			key = e.which;
		}
		if (key != null) {
			if (txt.value.length > (maxLen - 1)) return false;
		}
	}
	catch (e) {
	}
}
