var isIE = document.all?true:false;
if (!isIE) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMousePosition;

var InttxtX=0
var InttxtY=0

var _x;
var _y;

var _x2;
var _y2;


var ilayer = 0 ;
var posX = 0   ;
var posY = 0   ;

var gotlayers = 0;

NS = (document.layers) ? 1 : 0;
IE = (document.all) ? 1 : 0;

if (NS) {
	gotlayers = 1;
}
if (IE) {
	gotlayers = 1;
}

function getMousePosition(e) {
	
	try {
		  if (!isIE) {
		    InttxtX = window.pageXOffset;
		    InttxtY = window.pageYOffset;
		    _x = e.pageX;
		    _y = e.pageY;
		  }
		  if (isIE) {
		    _x = event.clientX + (InttxtX = document.body.scrollLeft);
		    _y = event.clientY + (InttxtX = document.body.scrollTop);
		  }
		  x=_x
		  y=_y

		  _x2=_x
		  _y2=_y
		  
		  
		  if (x>620){
		  	 x=620
		  	 _x=620
		 	}
	} 
	catch(e) {
		
	}
  
  return true;
}


//*************************************************************************
function popUp(on)
{
   var lLay ;
   
//alert("entro PopUp")
   if (IE) {
      lLay = document.all['popCal'] ;
   } else {
      lLay = document.layers['FormLayer'].document.layers['popCal'] ;
   }
   if (gotlayers) {
	if (on) {
		moveLayers();
		if (IE) {
			lLay.style.visibility = "visible";
		} else {
			lLay.visibility = "show";
		}
	} else {
		if (IE) {
			lLay.style.visibility = "hidden";
		} else {
			lLay.visibility = "hide";
		}
	}
   }
}

//*************************************************************************	
function SeeDate(i,obj1)
{
  var thedoc ;
//alert("entro SeeDate")
  if (NS) 
	thedoc = document.layers['FormLayer'].document.formulario ;
  else
  	thedoc = document.formulario;
  
 if (ilayer == 1){
  var str;
	str='thedoc.'+obj1+'.value = i;'
	eval(str);
	str='thedoc.'+obj1+'.focus();'
	eval(str);
  }
  
 if (ilayer == 2){
  var str;
	str='thedoc.'+obj1+'.value = i;'
	eval(str);
	str='thedoc.'+obj1+'.focus();'
	eval(str);
  }  
  
  //atributo cambio
  AddAttribModif(obj1);
  HideDate(thedoc);
  
  return;
}

//*************************************************************************	
function SeeDate2(i,obj1)
{
  var thedoc ;
//alert("entro SeeDate")
  if (NS) 
	thedoc = document.layers['FormLayer'].document.frmNewView ;
  else
  	thedoc = document.frmNewView;
  
 if (ilayer == 1){
  var str;
	str='thedoc.'+obj1+'.value = i;'
	eval(str);
	str='thedoc.'+obj1+'.focus();'
	eval(str);
  }
  
 if (ilayer == 2){
  var str;
	str='thedoc.'+obj1+'.value = i;'
	eval(str);
	str='thedoc.'+obj1+'.focus();'
	eval(str);
  }  
  
  //atributo cambio
  //AddAttribModif(obj1);
  HideDate(thedoc);
  
  return;
}

//*************************************************************************

//*************************************************************************
function ShowDate(i,a,b)
{
/*posX=a
posY=b*/
//alert("entro ShowDate")
  if (ilayer > 0) {
	  HideDate(document.formulario) ;
  }

  ilayer = i ;

  popUp(true);

  return;
}

//*************************************************************************
function moveLayers()
{
   var lLay, x, y  ;
   x = posX;
   y = posY;

   if (IE) {
      lLay = document.all['popCal'] ;
   } else {
      lLay = document.layers['FormLayer'].document.layers['popCal'] ;
   }

   if (gotlayers) {
	if (NS) {
		lLay.left = x;
		lLay.top = y;
	} else {
		lLay.style.pixelLeft = x;
		lLay.style.pixelTop = y;
		
	}
   }
}

//*************************************************************************
function HideDate(Obj)
{
//alert("entro HideDate")
  Obj.cont.value=0
  popUp(false) ;

  return;
}

//*************************************************************************
function PosicionCalendar(){
	var isIE = document.all?true:false;
	  //posX = document.body.scrollLeft+event.x;
	  //posY = document.body.scrollTop+event.y;
	  posX =event.x + 20; 
	  posY =event.y + 70;

	  posX = _x;
	  posY = _y;

	  /*popCal.style.top = Ypos + 20
	  popCal.style.left = Xpos + 20 */
}

function onclik_form(Obj)
{
	if (Obj){
	  if(Obj.cont){
		Obj.cont.value = parseInt(Obj.cont.value)+1
		if(Obj.cont.value==1)
			HideDate(Obj);
	  }
	}
}

function ShowCalendar_Mantencion(NameObject){
	document.getElementById("popCal").style.visibility="visible"
	document.getElementById("popCal").style.left = _x - 150
	document.getElementById("popCal").style.top  = _y - 150
	document.formulario.ObjdateActive.value = NameObject
	var StrObject = "document.formulario."+NameObject
	StrObject = eval(StrObject)
	
	if(StrObject) {
	   document.formulario.date1xx.value = StrObject.value
	 }  
	 
	window.frames['Calendar'].cal1xx.select(document.formulario.date1xx,'anchor1xx','dd/MM/yyyy');
	window.frames['Calendar'].document.getElementById("testdiv1").style.left = "0px"
	window.frames['Calendar'].document.getElementById("testdiv1").style.top = "0px"
	
	

/*
	document.getElementById("Calendar").cal1xx.select(document.formulario.date1xx,'anchor1xx','dd/MM/yyyy');
	document.getElementById("Calendar").document.getElementById("testdiv1").style.left = "0px"
	document.getElementById("Calendar").document.getElementById("testdiv1").style.top = "0px"
*/
}


function ShowCalendar(NameObject){
	document.getElementById("popCal").style.visibility="visible"
	document.getElementById("popCal").style.left = _x
	document.getElementById("popCal").style.top  = _y
	document.formulario.ObjdateActive.value = NameObject
	var StrObject = "document.formulario."+NameObject
	StrObject = eval(StrObject)
	
	if(StrObject) {
	   document.formulario.date1xx.value = StrObject.value
	 }  
	 
	window.frames['Calendar'].cal1xx.select(document.formulario.date1xx,'anchor1xx','dd/MM/yyyy');
	window.frames['Calendar'].document.getElementById("testdiv1").style.left = "0px"
	window.frames['Calendar'].document.getElementById("testdiv1").style.top = "0px"
	
	

/*
	document.getElementById("Calendar").cal1xx.select(document.formulario.date1xx,'anchor1xx','dd/MM/yyyy');
	document.getElementById("Calendar").document.getElementById("testdiv1").style.left = "0px"
	document.getElementById("Calendar").document.getElementById("testdiv1").style.top = "0px"
*/
}

function HideCalendar(){
	if(document.getElementById("popCal")){
		document.getElementById("popCal").style.visibility="hidden"
		document.getElementById("popCal").style.left = "-500px"
		document.getElementById("popCal").style.top  = "0px"
	}
}


function ShowCalendar2(NameObject){
	document.getElementById("popCal").style.visibility="visible"
	document.getElementById("popCal").style.left = _x2 -165
	document.getElementById("popCal").style.top  = _y2
	document.formulario.ObjdateActive.value = NameObject
	var StrObject = "document.formulario."+NameObject
	StrObject = eval(StrObject)
	
	if(StrObject) {
	   document.formulario.date1xx.value = StrObject.value
	 }  
	 
	window.frames['Calendar'].cal1xx.select(document.formulario.date1xx,'anchor1xx','dd/MM/yyyy');
	window.frames['Calendar'].document.getElementById("testdiv1").style.left = "0px"
	window.frames['Calendar'].document.getElementById("testdiv1").style.top = "0px"
	
	

/*
	document.getElementById("Calendar").cal1xx.select(document.formulario.date1xx,'anchor1xx','dd/MM/yyyy');
	document.getElementById("Calendar").document.getElementById("testdiv1").style.left = "0px"
	document.getElementById("Calendar").document.getElementById("testdiv1").style.top = "0px"
*/
}