// JavaScript Document
function selItem(vInput){
	var checkboxes = frmList.rid; 	//Array que contiene los checkbox
	var cont = 0; 					//Variable que lleva la cuenta de los checkbox pulsados
	
	for (var x=0; x < checkboxes.length; x++) {
		cont = cont + 1;
	}	
	if (cont == 0){
			document.frmList.rid.checked=true;
			document.frmList.id.value=document.frmList.rid.value;
		}	else {
			document.frmList.rid[vInput].checked=true;
			document.frmList.id.value=document.frmList.rid[vInput].value;
		}		
		
}

function newItem(ItemPage, PageWidth, PageHeight){
	OpenWindow(ItemPage, PageWidth, PageHeight);
	return false;
}

function editItem(ItemPage, PageWidth, PageHeight){
  	if (document.frmList.id.value == ""){
			window.alert('debe seleccionar un registro para poder editarlo.');
			return false;
		} else	{
			OpenWindow(ItemPage+'&Id='+document.frmList.id.value, PageWidth, PageHeight);
			return false;
  		}
}

function deleteItem(ItemPage, PageWidth, PageHeight){
  	if (document.frmList.id.value == "")
		{
			window.alert('debe seleccionar un registro para poder borrarlo.');
			return false;
		}
	else
		{
			var agree=confirm("Realmente desea borrar este registro?");
			if (agree){
				OpenWindow(ItemPage+'&Id='+document.frmList.id.value, PageWidth, PageHeight);
				return true ; }
			else{
				return false ; }
		}
}


/*
////////////////////////////////////
// Funciones para efecto en tabla //
////////////////////////////////////
*/

function mOvr(src,clrOver) {
  if (!src.contains(event.fromElement)) {
	  src.style.cursor = 'hand';
	  src.bgColor = clrOver;
	}
}
function mOut(src,clrIn) {
	if (!src.contains(event.toElement)) {
	  src.style.cursor = 'default';
	  src.bgColor = clrIn;
	}
}
function mClk(src) {
    if(event.srcElement.tagName=='TD'){
	  src.children.tags('A')[0].click();
    }
}
////////////////////////////////////

/*
///////////////////////////////////
// Funciones para el Modal Popup //
///////////////////////////////////
*/
	function modalDialogShow(url,width,height){
	var vRetVal=window.showModalDialog(url,window,
		"dialogWidth:"+width+"px;dialogHeight:"+height+"px;edge:Raised;center:1;help:0;resizable:0;maximize:0");
	if(vRetVal)return vRetVal;
	else return "";
	}
	
  var winPop;
  function OpenWindow(xURL, xWidth, xHeight){
//	  modalDialogShow(xURL,xWidth,xHeight);
    if(winPop && !winPop.closed){
      winPop.focus();
	  winPop.loaction.href = xURL;
    }
    else{
	  PopUpFakeModal(xURL, xWidth, xHeight);
    }
  }
 
   function PopUpFakeModal(xPopUpUrl, xWidth, xHeight){
    var intWidth = xWidth;
	var intHeight = xHeight;
    var ScreenWidth=window.screen.width;
    var ScreenHeight=window.screen.height;
    placementx=(ScreenWidth/2)-(intWidth/2);
    placementy=(ScreenHeight/2)-((intHeight+50)/2);
    winPop=window.open(xPopUpUrl,"Win","width="+intWidth+",height="+intHeight+",resizable=0, status=1,left="+placementx+",top="+placementy+",screenX="+placementx+",screenY="+placementy+",scrollbars=1");
 
//	window.onfocus = function(){FocusCloseWindow('onfocus')};
//	window.onunload = function(){FocusCloseWindow('onunload')};
//	winPop.window.onunload = function(){window.opener.focus();}
   }
 
   function FocusCloseWindow(xAction){
     if(winPop && !winPop.closed){
	   if(xAction=="onfocus"){
	     window.blur();  
	     winPop.focus(); 
	   }
	   else{
		 winPop.close();
	   }
	 }
	 else{
	   window.onfocus = null;
	   window.onunload = null;
	 }
   }
////////////////////////////////////
