// v1.7.3.7.a
// ***************************************************************************
// AjaxEvents.js
// Contains the functions needed to Ajax
// ***************************************************************************
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);
var btn;
var hfcontrolFocusedByDepRule = "";
// ***************************************************************************
// FUNCTION: void InitializeRequest(sender, args)
// DESCRIPTION:
// ***************************************************************************
function InitializeRequest(sender, args)
{
	document.body.style.cursor = "wait";
	var btnId=args._postBackElement.id;
	btn= $get(btnId);
	if (btn.type=="button" || btn.type=="submit")
	btn.disabled=true;
	// Disabled Ok Button
	btnOk= buttonOk();
	if (btnOk != null)
		btnOk.disabled=true;
	// Disabled Cancel Button
	btnCancel= buttonCancel();
	if (btnCancel != null)
		btnCancel.disabled=true;
	// Disabled UpdateProgress from filter Oid attributes
	if((btn.className.indexOf('filterTxtBox')>= 0 || btn.className.indexOf('txtBox')>= 0)  && (btn.id.indexOf('OidSelector') == -1))
	{
		var upIndicator = $get('ctl00_upIndicator');
		if(upIndicator != null)	{
			upIndicator.style.display = 'none';
		}
	}
	// Disabled All Buttons AutoPostBack
	for(var i=0;i<sender._asyncPostBackControlClientIDs.length;i++)
	{
		var idControl = sender._asyncPostBackControlClientIDs[i];
		control= $get(idControl);
		if(control != null)
		{
			if (control.type == "button"){
				control.disabled=true; }
		}
	}
}
// ***************************************************************************
// FUNCTION: void EndRequest(sender, args)
// DESCRIPTION:
// ***************************************************************************
function EndRequest(sender, args)
{
	document.body.style.cursor = "default";
	if(btn!=null){
		btn.disabled=false;}
	// Enabled Ok Button
	btnOk= buttonOk();
	if (btnOk != null){
		btnOk.disabled=false;}
	// Enabled Cancel Button
	btnCancel= buttonCancel();
	if (btnCancel != null){
		btnCancel.disabled=false;}
	// Apply focus in the control
	if(controlfocus != null && controlfocus.value.length > 0){
		// Control to be focused.
		var control = null;
		// Hiddenfield containing the control ID to be focused by a dependency rule.
		if (hfcontrolFocusedByDepRule.length > 0)
		{
			var hfcontrol = $get(hfcontrolFocusedByDepRule);
			if(hfcontrol != null && hfcontrol.value.length > 0){
				control = searchElementById(hfcontrol.value);
			}else{
				control = $get(controlfocus.value);
			}
		}else{
			control = $get(controlfocus.value);
		}
		if(control.type != 'button'){
			if(btn.id != control.id || btn.id.indexOf('OidSelector')>= 0 ){
				applyFocus(control);
			}
			else{
				focusNextElement(control);
			}
		}
	}
	// Enabled UpdateProgress
	if((btn.className.indexOf('filterTxtBox')>= 0 || btn.className.indexOf('txtBox')>= 0)  && (btn.id.indexOf('OidSelector') == -1))
	{
		var upIndicator = $get('ctl00_upIndicator');
		if(upIndicator != null)	{
			upIndicator.style.display = 'block';
		}
	}
	// Enabled All Buttons AutoPostBack
	for(var i=0;i<sender._asyncPostBackControlClientIDs.length;i++)
	{
		var idControl = sender._asyncPostBackControlClientIDs[i];
		control= $get(idControl);
		if(control != null)
		{
			if (control.type == "button"){
				control.disabled=false; }
		}
	}
}
// ***************************************************************************
// FUNCTION: void endToControl(control)
// DESCRIPTION:
// ***************************************************************************
function endToControl(control)
{
	if (control.createTextRange){
		var range = control.createTextRange();
		range.collapse(false); range.select();
	}
	else if (control.setSelectionRange)
	{
		control.focus();
		var length = control.value.length;
		control.setSelectionRange(length, length);
	}
}
// ***************************************************************************
// FUNCTION: void searchElementById(Id)
// DESCRIPTION: Gets an element from its ID.
// ***************************************************************************
function searchElementById(id) {
	if (document.getElementById) {
		return document.getElementById(id);
	} else if (document.all) {
		return document.all[id];
	} else return null;
}
// ***************************************************************************
// FUNCTION: void applyFocus(control)
// DESCRIPTION:
// ***************************************************************************
function applyFocus(control)
{
	var navegador = navigator.appName
	if(navegador == "Microsoft Internet Explorer" && control.disabled != false)
	{
		return;
	}
	control.focus();
	if (navegador == "Microsoft Internet Explorer") {
		// called focus twice due to a bug with ie!!!
		control.focus();
		endToControl(control);
	}
}
// ***************************************************************************
// FUNCTION: focusNextElement(field)
// DESCRIPTION:
// ***************************************************************************
function focusNextElement(field)
{
	var frm = field.form;
	var isIn = false;
	for (var e=0;e<frm.length;e++){
		if(isIn == true)
		{
			if(frm[e].className == 'button filterBtn'){
				isIn = false;
				applyFocus(field);
				break;
			}
			else if(frm[e].type == 'text'){
				isIn = false;
				applyFocus(frm.elements[e]);
			}
		}
		if(frm[e].tabIndex == field.tabIndex){
			isIn = true;
		}
	}
	if(isIn == true){
		applyFocus(field);
	}
}
// ***************************************************************************
// FUNCTION: button buttonOk()
// DESCRIPTION: Return Button Ok in page
// ***************************************************************************
function buttonOk()
{
	var btnok = $get('<%= this.btnOk.ClientID %>');
	if(btnok != null)
		return btnok;
	else
		return null;
}
// ***************************************************************************
// FUNCTION: button buttonCancel()
// DESCRIPTION: Return Button Cancel in page
// ***************************************************************************
function buttonCancel(){
try{
	var btncancel = $get('<%= this.btnCancel.ClientID %>');
	if(btncancel != null)
	return btncancel;
	else
		return null;
}catch(exception){}
}
// ***************************************************************************
// FUNCTION: Blob(blob)
// DESCRIPTION: It Puts the file name on the textbox Name of the File
// ***************************************************************************
function Blob(blob)
{
      if(typeof(blob)!="undefined")
      {
            var idPath = blob.id;
            idPath = idPath.replace("fileUpload","tbox") + "_Path";
            var pathName = $get(idPath);
            if(typeof(pathName)!="undefined")
            {
                  var posFile = blob.value.lastIndexOf('\\') + 1; 
                  pathName.value = blob.value.substring(posFile);
                  pathName.readOnly=true;
                
                  
            }
      }
      return false;
}
