// JavaScript Document
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
		 //alert(imgName);
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}

function checkABC(my_input) {
	if (my_input.value.charAt(my_input.value.length-1)) {
		var c2eval = my_input.value.charAt(my_input.value.length-1);
		if (!isNaN(c2eval) || c2eval=="." || c2eval==" " || c2eval=="-" || c2eval=="_" || c2eval=="-") {
			my_input.value = my_input.value.substring(0,((my_input.value.length-1)));
		}
	}
}

function checkNumbers(my_input) {
	if (my_input.value.charAt(my_input.value.length-1)) {
		var c2eval = my_input.value.charAt(my_input.value.length-1);
		if (isNaN(c2eval) && c2eval!=".") {
			my_input.value = my_input.value.substring(0,((my_input.value.length-1)));
		}
	}
}

function checkDateNumbers(my_input) {
	if (my_input.value.charAt(my_input.value.length-1)) {
		var c2eval = my_input.value.charAt(my_input.value.length-1);
		if (isNaN(c2eval) && c2eval!="/") {
			my_input.value = my_input.value.substring(0,((my_input.value.length-1)));
		}
	}
}

function showehide(id)
{
	obj = document.getElementById(id).style;
	obj.visibility = obj.visibility == 'visible'|| obj.visibility == ''? 'hidden':'visible';	
}

function showcolapse(id)
{
	obj = document.getElementById(id).style;
	obj.display = obj.display== 'inline'|| obj.display == ''? 'none':'inline';
}

function isdate(e)
{
	e= (window.event)? event : e;
	dxm = Array(31,28,31,30,31,30,31,31,30,31,30,31);
	obj = e.srcElement? e.srcElement: e.target;
	keycode = e.keyCode ? e.keyCode : e.which
	keycode = keycode <= 95 ? keycode: (keycode- 48);
	char = parseInt(String.fromCharCode(keycode));
	arr = obj.value.split("/");
	slength = obj.value.length;
	if((keycode < 58 && keycode > 47) || keycode == 8 || keycode == 9 || e.altKey || e.ctrlKey || e.shiftKey)
	{
		if(keycode != 8 && keycode != 9)
		{
			if(slength == 0 && keycode != 48 && keycode != 49)
					killEvent(e);
			if(slength == 1 && (parseInt(obj.value + char) > 12 || parseInt(obj.value + char) == 0))
					killEvent(e);
			if(slength == 2 || slength == 5)
			{
					obj.value += "/";
					if(slength == 2 && (char > 3 || char < 0))
					killEvent(e);
			}
			if(slength == 3)
				if(parseInt(arr[0]) == 2 && char > 2)
					killEvent(e);
				else if(parseInt(arr[0]) != 2 && char > 3)
					killEvent(e);
			if(slength == 4)
				if(parseInt(arr[0]) == 2 && char > 28)
					killEvent(e);
				else if(parseInt(arr[0]) != 2 && parseInt(arr[1] + char) > dxm[arr[0] - 1])
					killEvent(e);
				else if(parseInt(arr[1] + char) == 0)
					killEvent(e);
			if(slength == 9 && parseInt(arr[0]) == 2 && parseInt(arr[1]) == 29 && parseInt(arr[1] + char) % 4 != 0)
					killEvent(e);
			if(slength == 10)
					killEvent(e);
		}
	}
	else
		killEvent(e);
}

function killEvent(e){
	try{
		e.preventDefault();
	}
	catch(ex){
		e.returnValue = false; 
	}
}

function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
function showehide(id)
{
	obj = document.getElementById(id).style;
	obj.visibility = obj.visibility == 'visible'|| obj.visibility == ''? 'hidden':'visible';	
}
function tooltip(evt, msg)
{
	var e = (window.event) ? window.event : evt;
	origen = e.srcElement? e.srcElement: e.target;
	idtool = "tooltip_" + origen.id;
	
	if(document.getElementById(idtool))
	{
		obj = document.getElementById(idtool)
	}
	else
	{
		obj = document.createElement("div");
		obj.id = idtool;
		obj.style.visibility = "hidden";
		obj.style.position = "absolute";
		obj.style.left = 0;
		obj.style.top = 0;
		obj.style.z_index = 10000;
		obj.style.background = "#dee7f7";
		obj.style.border = "1px solid #336";  
		obj.style.padding = "4px";
		obj.style.color = "#000";
		obj.style.font_size = "11px";
		obj.style.line_height = "1.2";
		obj.style.filter = "alpha(opacity=60)";
		obj.style.opacity = "0.60";
		document.body.appendChild(obj);
		
	}
	origen.onmouseout=function(){showehide(idtool);};
	obj.style.left = (findPosX(origen) + 2) + "px";
	obj.style.top = (findPosY(origen) + origen.offsetHeight + 2) + "px";
	obj.innerHTML = msg;
	showehide(idtool);
}
function getValue(id)
{
		obj = document.getElementById(id);
		return obj.value? obj.value: obj.innerHTML;
}
function setValue(id, val)
{
		obj = document.getElementById(id);
		if(obj.type)
				obj.value = val;
		else
				obj.innerHTML = val;
}
function obj2button() {
	var id = arguments[0];
	var toDo = arguments[1];
	if (document.getElementById(id)) {
		obj = document.getElementById(id);
	} else {
		eval('obj = document.all.' + id );
	}
	//LE PONEMOS CURSOR
	if (obj.style)
		obj.style.cursor = 'pointer';
	
	//LE AGREGAMOS EL EVENTO
	if (!toDo || toDo==null) {
		event2obj(obj,'click',eval(id));
	} else {
		//alert('con toDo');
		event2obj(obj,'click',toDo);
	}
	//alert('Fin de obj2button: ' + id);
}
function event2obj(obj,ev,toDo) {
	//alert('Lo primero')
	//alert(obj.innerHTML?obj.innerHTML:obj.value);
	if (obj.addEventListener) {
		obj.addEventListener (ev,toDo,false);
	} else if (obj.attachEvent) {
		obj.attachEvent ( ("on" + ev) ,toDo);
	} else {
		eval('obj.on' + ev ) = toDo;
	}
}


event2obj(window,'load',correctPNG);
