﻿// JScript File


Sys.Application.add_init(AppInit);
function AppInit() {
	Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
	Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
}
function BeginRequestHandler(sender, args) {
	// Clear the error if it's visible from a previous request.
	//		if ($get('Error').style.visibility == "visible")
	//			CloseError();
}
function EndRequestHandler(sender, args) {
	if (args.get_error() != undefined && args.get_error().httpStatusCode == '500') {
		var errorMessage = args.get_error().message + '\nPlease try again.';
		args.set_errorHandled(true);
		//ToggleAlertDiv('visible');
		alert(errorMessage);
		//$get(messageElem).innerHTML = '"' +
		//		errorMessage + '" ' + errorMessageAdditional;
	}
}
$(document).ready(function() {
	rszpstbck();
	$(window).scroll(rszpstbck).resize(rszpstbck);
});







var lcolor, lobj = null;
function hlight(obj, color) {
	if (lobj != null) {
		lobj.style.backgroundColor = lcolor;
	}
	lcolor = obj.style.backgroundColor;
	lobj = obj;
	obj.style.backgroundColor = color;
}
function setbg(obj, bg) {
	if (obj != null) {
		if (bg == '')
			obj.style.backgroundColor = '';
		else
			obj.style.backgroundColor = bg;
	}
}

function DelThis() {
	return !confirm("Are you sure want delete item?");
}

function validateDisable(obj, group) {
	var valid = Page_ClientValidate(group);
	if (valid) {
		if (obj != null && _page_loaded) obj.disabled = true;
		return true;
	}
	return false;
}

function rszpstbck() {
	var div = $$("pstbck");
	div.style.position = "absolute";
	div.style.top = "0";
	//div.style.zIndex = "999997";
	if (oBw.konqueror) { div.style.backgroundColor = "transparent" }
	else {
		if (oBw.ie) { div.style.filter = "alpha(opacity=50)" }
		else { div.style.opacity = "0.5" }
	}
	var z = getPageSize();
	div.style.height = z[1] + "px";
	var m = document;
	if (oBw.isIE) { div.style.left = m.documentElement.scrollLeft; div.style.width = m.documentElement.clientWidth }
	else { div.style.left = "0"; div.style.width = "100%" }
}


////////////////////////////////////////////////////////////////////////////////////////////////////////

function SetUniqueRadioButton(nameregex, current) {
	re = new RegExp(nameregex);
	for (i = 0; i < document.forms[0].elements.length; i++) {
		elm = document.forms[0].elements[i]
		if (elm.type == 'radio') {
			//alert(elm.name)
			if (re.test(elm.name)) {
				elm.checked = false;
			}
		}
	}
	current.checked = true;
}


function setcntr(el, width, height) {
	$(document).ready(function() {
		$(window).scroll(function() {
			_setcntr(el, width, height);
		}).resize(function() {
			_setcntr(el, width, height);
		});
		_setcntr(el, width, height);
	});
}
function _setcntr(el, width, height) {
	$("#" + el).animate({ top: ($(window).scrollTop() + $('html').outerHeight(true) / 2 - height / 2) + "px" }, { queue: false, duration: 0 })
	.animate({ left: ($(window).scrollLeft() + $('html').outerWidth(true) / 2 - width / 2) + "px" }, { queue: false, duration: 0 })
};



//IDChecker
function IDCheckerCheckAll(checklist, ids, chk) {
	if (!checklist) return;
	for (var index = 0; index < checklist.length; index++)
		if ($$(checklist[index])) {
		$$(checklist[index]).checked = chk;
		IDCheckerAddid($$(checklist[index]), ids);
	}
}
function IDCheckerRestoreArray(checklist, ids) {
	if (!checklist) return;
	for (var index = 0; index < checklist.length; index++)
		if ($$(checklist[index])) {
		if ($$(checklist[index]).checked);
		IDCheckerAddid($$(checklist[index]), ids);
	}
}
function IDCheckerAddid(chk, ids) {
	var id = $$(chk.id + '_m').attributes['mid'].value;
	var index = searcharr(ids, id);
	if (chk.checked && index == -1) ids.splice(0, 0, id);
	else if (!chk.checked && index != -1) ids.splice(index, 1);
}
function IDCheckerCalcAll(ids, obj, msg) {
	if (ids.length == 0 || msg.length > 0 && !confirm(msg)) return false;
	obj.value = ids;
	return (ids.length > 0);
}

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();