
// ----------------------------------------------------
//
// Title      : BNA - Store Online
// Date       : 23/agosto/2007
// Description: Support functions
// Author     : Miguel Corona
//
// ----------------------------------------------------



// ----------------------------------------------------
// Begin: Simple Functions
// ----------------------------------------------------

function espacios(str)
{
	var lon = str.length;  	// Longuitud del string
	var tem = ""; 			// Variable temporal
	var con = 0;			// Contador;

	for( i = 0 ; i < lon ; i++ ){
		if( str.charAt(i) == " " ){
			con = con + 1;
		}
	}
	if( con == str.length )return(""); else	return(str);
}
function trim(s){
	sNew = "";
	if (s.length > 0){
	  for (i = 0; i < s.length; i++){
	    if (s.substring(i, i + 1) != " "){
	      for (j = s.length; j >= i; j--){
	       if (s.substring(j - 1, j) != " "){
	         sNew = s.substring(i, j);
	         break;
	       }
	      }
	      break;
	    }
	  }
	}  
	return sNew;
}
function getValueSelect(obj_select)
{
	i = obj_select.selectedIndex;

	if( i == (-1) )
		str = "-1"; //No existe índice seleccionado
	else
		str = obj_select.options[i].value;

	return(str);
}
function setObjSelect( obj_sel, x )
{
  var lon = obj_sel.length;

  if( lon > 0 ){
    if( x.length == 0){
      obj_sel.selectedIndex = 0;
      return(true);    
    }
  }

  for( var i = 0; i < lon ; i++ )
  {
    if( obj_sel.options[i].value == x )
    {
      obj_sel.selectedIndex = i;
      return(true);
    }
  }
  return(false);
}
function checkMail( p_objTxtEmail )
{ 
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

	var x = p_objTxtEmail.value;

	if ( filter.test(x) ) 
		return(true);
	else 
		return(false);
}
// ----------------------------------------------------
// End: Simple Functions
// ----------------------------------------------------



// ----------------------------------------------------
// Begin: Compound functions
// ----------------------------------------------------


// To validate text boxes

/*
 * Function: validar_txt
 *
 * Used functions:  espacios(), trim()
 *
 */
function validar_txt(obj_txt,mensaje)
{
	var valor = "";

	if( obj_txt.disabled == false )
	{
		valor = espacios(obj_txt.value);
		if(  valor == "" ){
			obj_txt.value = "";		alert(mensaje);		obj_txt.focus();		return(false);
		}else{
			obj_txt.value = trim(obj_txt.value);
			return(true);
		}
	}
	return( true );
}
/*
 * Function: seleccione
 *
 * Used functions:  getValueSelect()
 *
 */
function seleccione( ObjSelect , valueSelect , mensaje )
{	
	cod = getValueSelect( ObjSelect ) ;
	if( cod == valueSelect ){
		alert( mensaje );
		ObjSelect.focus();
		return(false);
	}
	return(true);
}


function muestra_reporte(doc,sis,log)
{
equ = 'AQSWEDRFTGYHUJDE';
if (log == '' ){
	log = 'is_free';
} 
strUrl = "http://www.bnamericas.com/cgi-bin/getreports?document="+doc+"&system="+sis+"&equiv="+equ+"&login="+log ;
window.open(strUrl ,'newWin','toolbar=no,location=no,directories=no,menubar=no,width=650,height=600,status=yes,resizable=yes,top=100,left=50,scrollbars=yes');
}


function baja_reporte(ord,sku,log)
{
strUrl = "http://www.bnamericas.com/cgi-bin/getreports_store?sku="+sku+"&orden="+ord+"&login="+log ;
window.open(strUrl ,'newWin','toolbar=no,location=no,directories=no,menubar=no,width=650,height=600,status=yes,resizable=yes,top=100,left=50,scrollbars=yes');
}

// ----------------------------------------------------
// End: Compound functions
// ----------------------------------------------------



