// Requiere general.js

function newDate()
{
	var date = new Date();
	var result = "";
	
	if ((date.getDate() < 10))
	{
		result = "0" + date.getDate();
	}
	else
	{
		result = date.getDate();
	}	
	
	if ((date.getMonth() + 1) < 10)
	{
		result = result + "/0" + (date.getMonth() + 1) + "/" + date.getFullYear(); 
	}
	else
	{
		result = result + "/" + (date.getMonth() + 1) + "/" + date.getFullYear();
	}
	
	return result;
}

function firstDayOfThisMonth()
{
	var date = new Date()
	var result = "";
	
	if ((date.getMonth() + 1) < 10)
	{
		result = "01/0" + (date.getMonth() + 1) + "/" + date.getFullYear(); 
	}
	else
	{
		result = "01/" + (date.getMonth() + 1) + "/" + date.getFullYear();
	}
	
	return result;
}

function newTime()
{
	var date = new Date()
	var result = "";
	
	if (date.getHours() < 10)
	{
		result = "0" + date.getHours();
	}
	else
	{
		result = date.getHours();
	}
	
	if (date.getMinutes() < 10)
	{
		result = result + ":0" + date.getMinutes();
	}
	else
	{
		result = result + ":" + date.getMinutes();
	}
	
	return result;
}

function getDaysFromTo(startDate, endDate)
{
	var dtCh = "/";	

	var pos1=startDate.indexOf(dtCh);
	var pos2=startDate.indexOf(dtCh,pos1+1);
	var strMonth=startDate.substring(pos1+1,pos2);
	var strDay=startDate.substring(0,pos1);
	var strYear=startDate.substring(pos2+1);
	var result=0;
	
	if (strDay.substring(0,1) == "0") strDay = strDay.substring(1,2);
	if (strMonth.substring(0,1) == "0") strMonth = strMonth.substring(1,2);
	
	var d_start = new Date(parseInt(strYear), parseInt(strMonth)-1, parseInt(strDay));	
		
		
	pos1=endDate.indexOf(dtCh);
	pos2=endDate.indexOf(dtCh,pos1+1);
	strMonth=endDate.substring(pos1+1,pos2);
	strDay=endDate.substring(0,pos1);
	strYear=endDate.substring(pos2+1);
	
	if (strDay.substring(0,1) == "0") strDay = strDay.substring(1,2);
	if (strMonth.substring(0,1) == "0") strMonth = strMonth.substring(1,2);
	
	var d_end = new Date(parseInt(strYear), parseInt(strMonth)-1, parseInt(strDay));	
	
	result = d_end.getTime() - d_start.getTime();
	
	result = (((result/1000) / 60 ) / 60) / 24;
	
	return parseInt(result) + 1;	
}

function expandRow(id)
{			
	if (document.getElementById(id).style.display && document.getElementById(id).style.display != "none")
	{
		document.getElementById(id).style.display = "none";		
	}
	else
	{	
		if (browser=="Microsoft Internet Explorer")
		{
			document.getElementById(id).style.display = "block";
		}
		else
		{	
			document.getElementById(id).style.display = "table-row";
		}
	}
}

function forceExpandRow(id)
{
	if (browser=="Microsoft Internet Explorer")
	{
		document.getElementById(id).style.display = "block";
	}
	else
	{	
		document.getElementById(id).style.display = "table-row";
	}
}

function hideRow(id)
{
	document.getElementById(id).style.display = "none";
}

function keyIsEnter(e)
{
	var c;
	if(!e) // Internet Explorer 
	{
		c = event.keyCode;
	} 
	else if (e.which) // Otros Navegadores
	{
		c = e.which;
	} 
	
	if(c==13 || c==9) 
	{
		return true;
	}
	else
	{
		return false;
	}
}

function getURL(href)
{
	if (!href || href == "" || href == "undefined" || href == null) href = window.location.href
		
	var url;	
	var i = href.indexOf("?");		

	if (i == -1) url = href;
	else url = href.substring(0, i);

	return url;
}

function getURLParameters(href)
{
	if (!href || href == "" || href == "undefined" || href == null) href = window.location.href 
	
	var params;
	var i = href.indexOf("?");		
	
	if (i == -1) params = "";
	else params = href.substring(i);
	
	return params;
}

function imgXY (imgID)
{   
	/* This function returns the upperleft x,y coordinates of the specified image */
	var XY = new Object();
	var imgObj = document.getElementById(imgID);
	if (document.layers) 
	{         
		XY.x = eval(imgObj).x;
		XY.y = eval(imgObj).y;
	} 
	else 
	{         
		var x,y, tempEl;         
		x = eval(imgObj).offsetLeft;
		y = eval(imgObj).offsetTop;
		tempEl = eval(imgObj).offsetParent;
		while (tempEl != null) 
		{
			x += tempEl.offsetLeft;
			y += tempEl.offsetTop;
			tempEl = tempEl.offsetParent;
        }         
        XY.x = x;         
        XY.y = y;
    }
    return XY;
}

function DisableEnableLinks(xHow)
{
	var objLinks = document.links;
	
	for(var i=0;i<objLinks.length;i++)
	{  
		//objLinks[i].disabled = xHow;
    	//link with onclick
    	if(objLinks[i].onclick && xHow)
    	{      		
        	objLinks[i].onclick = new Function("return false;" + objLinks[i].onclick.toString().getFuncBody());
    	}
    	//link without onclick
    	else if(xHow)
    	{  
      		objLinks[i].onclick = function(){return false;}
    	}
    	//remove return false with link without onclick
    	else if(!xHow && objLinks[i].onclick.toString().indexOf("function(){return false;}") != -1)
    	{            
    	  	objLinks[i].onclick = null;
    	}
    	//remove return false link with onclick
    	else if(!xHow && objLinks[i].onclick.toString().indexOf("return false;") != -1)
    	{  
	      	strClick = objLinks[i].onclick.toString().getFuncBody().replace("return false;","")
      		objLinks[i].onclick = new Function(strClick);
    	}
	}
}

String.prototype.getFuncBody = function()
{ 
	var str=this.toString(); 
	str=str.replace(/[^{]+{/,"");
	str=str.substring(0,str.length-1);   
	str = str.replace(/\n/gi,"");
	//if(!str.match(/\(.*\)/gi))str += ")";
	return str; 
} 

function ltrim(s) 
{
   return s.replace(/^\s+/, "");
}

function rtrim(s) 
{
   return s.replace(/\s+$/, "");
}

function trim(s) 
{
   return rtrim(ltrim(s));
}

function setTo2Decimals(number)
{		
	var formatedNumber = number.toString().split(".");
			
	var decimals = "";
	if(formatedNumber[1]!=null && formatedNumber[1].length > 0)
	{
		if(formatedNumber[1].length > 2)
		{
			decimals = "." + formatedNumber[1].substring(0,2);
		}
		else
		{
			decimals = "." + formatedNumber[1];
		}
	}
	
	number = formatedNumber[0] + decimals;
		
	return number;
}