function loadNoImage(me)
{
	me.src = site_image_url+"noimage_T.gif";
}
function Trim(s) 
{
	return s.replace(/^\s+/g, '').replace(/\s+$/g, '');
}
function checkKeyEventFloatNumber(e)
{  
	
	if(!e) var e = window.event;
	
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	ret=true;
	if(code==13)		return true;
	if(code<48 && code!=46 && code!=43 && code!=45)
	{
		ret=false;
	}	
	if(code>57)
	{
		ret=false;
	}	
	return ret;
}
function checkKeyEventNumber(e)
{  
	
	if(!e) var e = window.event;
	
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	ret=false;
	//alert(code);
	if(code==13 || code==9 || code==39 || code==37 || code==8 )
			return true;
	if(code>=48 && code<=57)
	{
		ret=true;
	}	
	return ret;
}

function roundNumber(number, digit ) {
	var numberField = number; // Field where the number appears
	var rnum = number;
	var rlength = digit; // The number of decimal places to round to
	if (rnum > 8191 && rnum < 10485) {
		rnum = rnum-5000;
		var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
		newnumber = newnumber+5000;
	} else {
		var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
	}
	numberField.value = newnumber;
	return newnumber;
}
function validfileExtension(file, extension)
{
	var arrfile=file.split(".");
	var len=arrfile.length-1;
	var fileExt=arrfile[len];
	fileExt=fileExt.toUpperCase();
	var arrExt=extension.split(",");
	
	cnt=0;
	for(var i=0; i<arrExt.length; i++)
	{
		if(arrExt[i].toUpperCase()==fileExt)
		{
			cnt=1;break;
		}
	}
	if(cnt==0)
		return false;
	else 
		return true;	
	
}
/*	End Fucntion */	
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
function checkDelete()
{
	var y=0; var ans;
	y = getCheckCount();
	var actionvalue='Delete';
	if(y>0)
	{	ans = confirm("Confirmar borrado de los registros seleccionados ?");
		if(ans == true)
		{
			document.frmlist.mode.value=actionvalue;
		    document.frmlist.submit();
			return true;
		}
		else
		{return false;}
	}
	else
	{	alert("Por favor, selecciona registros para borrar.");	return false;	}
}
function getCheckCount()
{	var x=0;
	for(i=0;i < document.frmlist.elements.length;i++)
	{	if (document.frmlist.elements[i].id == 'iId' && document.frmlist.elements[i].checked == true)
			{x++;}
	}
	return x;
}
function checkActive()
{
	var y=0; var ans;
	y = getCheckCount();
	
	if(y>0)
	{	ans = confirm("Confirmar la activación de los registros seleccionados ?");
		if(ans == true)
		{	document.frmlist.mode.value="Active";	
		 document.frmlist.submit();
			//document.frmlist.submit();		
		}
		else
		{	return false;	}
	}
	else
	{	alert("Por favor, selecciona registros para activar.");	return false;	}
}
function checkInActive()
{
	var y=0; var ans;
	y = getCheckCount();
	
	if(y>0)
	{	ans = confirm("Confirmar la inactivacion de los registros seleccionados ?");
		if(ans == true)
		{	document.frmlist.mode.value="Inactive";	
			 document.frmlist.submit();
			return true;
		}
		else
		{	return false;	}
	}
	else
	{	alert("Por favor, selecciona registros para desactivar.");	return false;	}
}

  function getPageScroll() {
    var xScroll, yScroll;
    if (self.pageYOffset) {
      yScroll = self.pageYOffset;
      xScroll = self.pageXOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
      yScroll = document.documentElement.scrollTop;
      xScroll = document.documentElement.scrollLeft;
    } else if (document.body) {// all other Explorers
      yScroll = document.body.scrollTop;
      xScroll = document.body.scrollLeft;	
    }
    return new Array(xScroll,yScroll) 
  }
  function getPageHeight() {
    var windowHeight
    if (self.innerHeight) {	// all except Explorer
      windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
      windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
      windowHeight = document.body.clientHeight;
    }	
    return windowHeight
  }
  
  function getWindowSize()
  {
    var windowHeight,windowWidth; 
    if (self.innerHeight) {	// all except Explorer
      windowHeight = self.innerHeight;
      windowWidth = self.innerWidth;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
      windowHeight = document.documentElement.clientHeight;
      windowWidth = document.documentElement.clientWidth;
    } else if (document.body) { // other Explorers
      windowHeight = document.body.clientHeight;
      windowWidth = document.body.clientWidth;
    }	
    return [windowWidth ,windowHeight];
  
  }
  
function displayfaceboxpopup(message, obj, p_errormsg)
{
    if(typeof(obj)=="object")
    {
      var pos_x=findPosX(obj);
      var pos_y=findPosY(obj);
    }
    else
    {
      var pos_y = getPageScroll()[1]+150;      
      var pos_x='300';
    }
    var class1='';
    if( typeof(p_errormsg) =='undefined' )
      class1='var_msg';

    
    var html='<div id="div-facebox" >';
          html+='<div>';
            html+='<span class="'+class1+'" >'+message+'</span>';
          html+='</div>';
        html+='</div>';
  
  jQuery.facebox(html);
  $("#facebox").css({'top':pos_y, 'left':pos_x, 'width':'400', 'display':'block'});
}

function close_box()
{
  jQuery(document).trigger('close.facebox');
}

function openPopupImageWindow(ImageName,vImageURL)
{
	s=window.open(site_url+'popup.php?page=enlarge&pid=1&h=300&w=300&popup=1&vImage='+ImageName+'&vImageURL='+vImageURL,'enlarged_view','toolbar=no,resizable=yes,scrollbars=yes,width=700, height=700');
	s.focus();
	return false;
}

function getWeekAndMonthName()
{
    var dayNamesMin=['Dom' ,'Lun', 'Mar', 'Mie', 'Jue' ,'Vie' ,'Sab'];
    var dayNames =['Domingo' ,'Lunes', 'Martes', 'Miircoles', 'Jueves', 'Viernes', 'Sabado' ];
    var monthNamesShort=['Ene', 'Feb'  ,'Mar', 'Abr' ,'May' ,'Jun', 'Jul' ,'Ago', 'Sep', 'Oct', 'Nov' ,'Dic' ];
    var monthNames=['Enero',  'Febrero', 'Marzo', 'Abril', 'Mayo','Junio', 'Julio',  'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre' ];  
    
    var array={'dayNamesMin':dayNamesMin,'dayNames':dayNames, 'monthNamesShort':monthNamesShort, 'monthNames':monthNames   };
    return array; 
}

function display_calendar(id, params)
{
  var buttonText='';
  if(typeof(params)=="undefined")
    params={}; 

  if(typeof(params["buttonText"])!="undefined")
    buttonText=params["buttonText"]; 
  
  if(params["dateType"]=="expire")
    var mindate=' 0d ';
  else
    var mindate=null;
    
  var obj;
  
  if( typeof(id)=="string" )
    obj=$("#"+id);
  else
    obj=id;
   var weekmonths=getWeekAndMonthName();
	obj.datepicker({
      buttonText:buttonText, 
      showOn: "both",
      buttonImage: "images/cal.gif",
      buttonImageOnly: false,
      firstDay : 1,
      changeMonth: true ,
      changeYear: true ,
      dateFormat :'dd-mm-yy',
      buttonImageOnly : true,
      minDate:mindate,
      dayNamesMin:weekmonths.dayNamesMin,
      dayNames : weekmonths.dayNames,
      monthNamesShort:weekmonths.monthNamesShort,
      monthNames:weekmonths.monthNames  

		});

}

function openPopupImageWindowDB(type,id)
{
	s=window.open(site_url+"popup_db_image.php?type="+type+"&id="+id, 'enlarged_view','toolbar=no,resizable=yes,scrollbars=yes,width=700, height=700');
	s.focus();
	return false;
}


/*
function getWindowSize()
{
 var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [myWidth, myHeight ];
}
*/

