﻿

// Utility function that helps to check/uncheck rows in a table
function ToggleAllCheckboxes() 
{	
	var inputlist = document.getElementsByTagName("input");
	for (i = 0; i < inputlist.length; i++) 
	{
		if ( inputlist[i].getAttribute("type") == "checkbox" ) 
		{			
			if (inputlist[i].checked) 
				inputlist[i].checked = false;
			else
				inputlist[i].checked = true;
		}
	}
}
// Cache the size and setup the initial size
function SetupTargetSize(behaviorID) {
    var behavior = $find(behaviorID);
    if (!behavior._height) {
        var target = behavior.get_completionList();
        behavior._height = target.offsetHeight - 2;
        target.style.height = '0px';
    }
}

// Move an element directly on top of another element (and optionally
// make it the same size)
function Cover(bottom, top, ignoreSize) 
{
    var location = Sys.UI.DomElement.getLocation(bottom);
    top.style.position = 'absolute';
    top.style.top = location.y + 'px';
    var xLocation = location.x;
    var xMin = (xLocation / 2) - 200;
    if (xLocation > xMin) xLocation -= xMin;
    top.style.left = xLocation + 'px';
    if (!ignoreSize) {
        top.style.height = bottom.offsetHeight + 'px';
        top.style.width = bottom.offsetWidth + 'px';
    }
}
// Deselect the list-box so that no items are selected.
function ClearListBox(lisBoxId) {
    var list = document.getElementById(lisBoxId);
    if (list) list.selectedIndex = -1;
   }

/* Class Act - CSS style manipulation

	Possible actions are:
	swap - replaces class class1 with class c2 in object.
	add  - adds class class1 to the object.
	remove - removes class class1 from the object.
	check - test if class class1 is already applied to object o and returns true or false.
*/
   function classAct(a, object, class1, class2) {
   	switch (a) {   		
   		case 'swap':
   			object.className = !classAct('check', object, class1) ? object.className.replace(class2, class1) : object.className.replace(class1, class2);
   			break;
   		case 'add':
   			if (!classAct('check', object, class1)) { object.className += object.className ? ' ' + class1 : class1; }
   			break;
   		case 'remove':
   			var rep = object.className.match(' ' + class1) ? ' ' + class1 : class1;
   			object.className = object.className.replace(rep, '');
   			break;
   		case 'check':
   			return new RegExp('\\b' + class1 + '\\b').test(object.className)
   			break;
   	}
   }

   function ShowModalPopupViaClient(modalPopupBehaviorID) {
   	var modalPopupBehavior = $find(modalPopupBehaviorID);
   	modalPopupBehavior.show();
   }

   function HideModalPopupViaClient(modalPopupBehaviorID) {
   	var modalPopupBehavior = $find(modalPopupBehaviorID);
   	modalPopupBehavior.hide();
   }


   /*	
	   selectId - DropDownList web server control or Select html control
	   val - Selection that you want to show your container	   
	   containerId - Container (e.g. <div></div>) that you want to hide or show.
   */
   function ShowHideContainer_DropDownList_Changed(selectId, val, containerId) {
   	var dropdownCtrl = document.getElementById(selectId);

   	if (dropdownCtrl.value == val)
   	{
   		document.getElementById(containerId).style.display = '';
   	}
   	else 
   	{
   		document.getElementById(containerId).style.display = 'none';
   	}
   }
   /*
	DynamicPopulate is a simple extender that replaces the contents of a control with 
	the result of a web service or page method call. The method call returns a string 
	of HTML that is inserted as the children of the target element. 
   */
   function ShowDynamicPopulate(behaviorId, value) {
   	var behavior = $find(behaviorId);
   	if (behavior) {
   		behavior.populate(value);
   	}
   }