var Bnt=new SBnt();
//************************************************************************
// SBnt
//************************************************************************
function SBnt()
{
}
SBnt.prototype.Version = function()
{
	alert('Version 3');
}
//************************************************************************
// SBnt
//************************************************************************
// Separator to represents arrays into strings separated by ?
var BNT_SEPARATOR='|';
var BNT_PREFIX_TAB='tab';
var BNT_PREFIX_PAN='pan';
var BNT_SUFFIX_SELECTED='Selected';

// Get an element by its id
function BntGet(id)
{
var oRet=document.getElementById(id);
if (oRet==null) oRet=id;
return oRet;
}

// Set a property of a control
function BntSet(control,value,property)
{
	var oControl=BntGet(control);
	if (typeof(oControl)=='object')
	{
		if (property)
		{oControl[property]=value;}
		else
		{oControl.value=value;}
	}
}

// Apply the function BntSet(control,value,property) to a multiple controls (numControls)
// The names of the controls are: controlName0,controlName1,...,controlName(numControls-1)
function BntSetMultiple(controlName, numControls, value, property)
{
var i=0;
var sName="";
for (i=0;i<numControls;i++)
	{
	sName=controlName + i;
	BntSet(sName,value,property);
	}
}  

// Show hide a control. 
// Second parameter[optionally]: show(true) hide(false)
function BntShowHide(control, show, controller)
{
	var oControl=BntGet(control);
	var oController=BntGet(controller);
	
	if (typeof(oControl)=='object')
	{
		if (typeof(show)=='undefined' || show==null)
		{
		var sDisplay=oControl.style.display;
		if (sDisplay=='none')
			{
			oControl.style.display='';
			if (oController)
				oController.innerText='-';
			}
		else
			{
			oControl.style.display='none';
			if (oController)
				oController.innerText='+';
			}
		}
		else if (show==true)
		{
		oControl.style.display='';
		if (oController)
			oController.innerText='-';
		}
		else if (show==false)
		{
		oControl.style.display='none';
		if (oController)
			oController.innerText='+';
		}
	}
}

// Apply the function BntShowHide(control,show) to a multiple controls (numControls)
// The names of the controls are: controlName0,controlName1,...,controlName(numControls-1)
function BntShowHideMultiple(control, numControls, show)
{
var i=0;
var sName="";
for (i=0;i<numControls;i++)
	{
	sName=control + i;
	BntShowHide(sName,show);
	}
}  

// Manage tabs on client
// Suppose that if the control name is XXX and numControls=3
// exists:  XXXtab0, XXXtab1, XXXtab2 (for user selection)
// exists:  XXXpan0, XXXpan1, XXXpan2 (for content presentation)
function BntShowTab(control, numControls, selectedControl, cssClass)
{
// close all pan and open the selected pan
var sPan=control+BNT_PREFIX_PAN;
BntShowHideMultiple(sPan,numControls, false);
BntShowHide(sPan+selectedControl,true);
// change the name of the cssClasses
var sTab=control+BNT_PREFIX_TAB;
BntSetMultiple(sTab,numControls,cssClass,'className');
BntSet(sTab+selectedControl,cssClass+BNT_SUFFIX_SELECTED,'className');
// select the current tab
document.forms[0][control + 'miSelectedIndex'].value=selectedControl;
}  

function SetCursor(cursor)
{
document.body.style.cursor=cursor;
}
// OpenModaldialog
// url: the url to load into the new window
// windowOptions: window options
// eventTarget: name (postback without validation) 
function OpenModalDialog(url,windowOptions, eventTarget)
{
// Show modal dialog
if (!windowOptions) 
	{windowOptions="edge: Raised; help: No; resizable: Yes; status: No;";}

SetCursor('wait');
var oRetValue=window.showModalDialog(url, window, windowOptions);

// For each control update: we process only optional parameters
if (oRetValue!=null)
	{
	var iInit=3;
	var iRet=0;
	var sRetValues='';
	var sId=null;
	var oControl=null;
	var sType=null;
	for (i=iInit;i<arguments.length;i++)
		{
		sId=arguments[i];
		oControl=BntGet(sId);
		if (typeof(oControl)=='object')
		{
		sType=oControl.tagName;
		
		sRetValues+=oRetValue[iRet] + BNT_SEPARATOR;

		if (sType=='INPUT') // textbox
			{oControl.value=oRetValue[iRet];}
		else if (sType=='SPAN') // labels
			{oControl.innerText=oRetValue[iRet];}
		else	// el resto de controles
			{i++; oControl[arguments[i]]=oRetValue[iRet];}
		}
		iRet++;
		}
	}

// we make a postback if needed
if (eventTarget)
	{
	__doPostBack(eventTarget,sRetValues);
	}
	
//Page_ValidationActive=True;
SetCursor('');
return oRetValue;
}

// SubmitValidated : Validate and if there are no errors make a submit 
// eventTarget: name of the control wich receive the postback
// eventArgument: arguments for the postBack
// validationDisabled: if false validate before postback
function SubmitValidated (eventTarget, eventArgument, validationDisabled)
{
// parameters
if (!eventTarget)
	{eventTarget='';}
if (!eventArgument)
	{eventArgument='';}
//alert('eventTarget=' + eventTarget + '; eventArgument=' + eventArgument + '; validationDisabled=' + validationDisabled);

// code
if (!validationDisabled && typeof(Page_Validators)!='undefined' && typeof(Page_ClientValidate) == 'function') 
	{
	if (Page_ClientValidate())
		{__doPostBack(eventTarget,eventArgument);}
	}
else
	{__doPostBack(eventTarget,eventArgument);}

}

// array to string 
function BntToString(val)
{
var sRet='';
var i=0;
if (val)
	{
	for (i=0;i<val.length;i++)
		{
		sRet=sRet+val[i] + BNT_SEPARATOR;
		}
	}
return sRet;
}

// High and low 
// (not support more than one control at the same page with diferent styles)
var msBntSelectedClassName;
var msBntHighClassName=" BntRollOver";
function BntHigh(obj) {
	msBntSelectedClassName=obj.className;
	obj.className=obj.className + msBntHighClassName;
}
function BntLow(obj) {
	obj.className=msBntSelectedClassName;
}
// Show hide a control
function BntProcessKey(control)
{
	//alert(window.event.keyCode);
	if (window.event.keyCode==46) // DELETE KEY >> keyPress doesn't detect
		{BntSet(control,"");}
}

// Set Focus to Control parameter if maxLength=CurrentLength
function BntNext(ControlID)
{
var skeyCode=event.keyCode;
if (document.activeElement.value.length  == document.activeElement.maxLength 
	&& skeyCode>=48 && skeyCode<=122)
	{
	var oControl=BntGet(ControlID);
	oControl.focus();
	}
}		

/*****************************************************************************/
function pnlDesplegar(control)
{
	var oControl=BntGet(control);
  if (oControl.style.display == 'none')
     {oControl.style.display = '';}
  else   
     {oControl.style.display = 'none';}
}

