
//**********************************************************
// History modification
// 12/10/02: Read value type, before setting a parameter value  
// 21/07/03: Remove connect in start_proe(), to speed up the process
//**********************************************************

var g_log_all = true;


//**********************************************************
// return true if input car is in input string
//**********************************************************
function car_is_in_str ( in_car, in_str )
{
	
	var idx = in_str.indexOf(in_car);
	
	if ( idx != -1 )
		return (true);
	else
		return (false);
}

//**********************************************************
// return parity of value
//**********************************************************
function is_pair( in_value )
{
	if ( in_value % 2 == 0 )
		return (true);
	else
		return (false);
}

//**********************************************************
// return true if value is an integer 
//**********************************************************
function is_integer(value)
{
  if ( convFloat(value) - convInt(value) == 0 )
  		return (true);
  else
  		return (false);
}

//**********************************************************
// append message into a text file
//**********************************************************
function printf(filename,datatosave)
{
// add a newline
datatosave += "\r\n";
netscape.security.PrivilegeManager.enablePrivilege('UniversalFileAccess');
var append = true;
var fileWriter = new java.io.FileWriter(filename, append);
fileWriter.write (datatosave, 0, datatosave.length);

fileWriter.close();

}

function doError()
{
document.bev_form.error_code.value = "JAVASCRIPT ERROR";
window.status="Javascript error detected ....";
// Reload document
//window.location.href = window.location.href;
return (true);
}

//**********************************************************
// call a cgi-script
//**********************************************************
function run_cgi( script_name , param )
{
if (param)
{
 window.location.href=GBL_SERVER_ADD+"/"+script_name+"?"+param;
}
else
{
 window.location.href=GBL_SERVER_ADD+"/"+script_name;
}

}

//**********************************************************
// log message in a textarea or window
//**********************************************************
function log_msg( message )
{
// display message with set_parameter ERROR
   if (  g_log_all )
	{
		win_id=window.open('',"logWindow","outerWidth=1000,outerHeight=600,screenX=200,screenY=0,scrollbars=yes,resizable=yes,location=yes,status=yes");
		win_id.document.writeln( message +"<br>" );
		win_id.focus();
	}
// printf("c:\\temp\\bev_activity.log",message);

}

//**********************************************************
// Show chromeless window with message
//**********************************************************
function show_popup( message )
{
		close_popup();
		var win_id=window.open('',"popup","outerWidth=300,outerHeight=300,screenX=100,screenY=0");
		win_id.document.writeln( message +"<br>" );
		win_id.focus();
}

//**********************************************************
// close chromeless window with message
//**********************************************************
function close_popup( )
{
		var win_id=window.open('',"popup");
		win_id.close();

}

//**********************************************************
// Convert to float
// ParseInt and ParseFloat return "NaN" (Not a number)
// if input param is empty string
//**********************************************************
function convFloat( value )
{
	return ( value.toString() == "" ? 0.0 : parseFloat(value) ) ;
}

//**********************************************************
// Convert to an Integer
// ParseInt and ParseFloat return "NaN" (Not a number)
// if input param is empty string
//**********************************************************
function convInt( value )
{
	return ( value.toString() == "" ? 0 : parseInt(parseFloat(value)) ) ;
}


//**********************************************************
// return true if input string is positive integer
//**********************************************************
function is_num( in_str )
{
	var to_return=true;
	var car="";
	
	if ( in_str == NaN ) return (false);
	
	return ( in_str.match(/^\d+$/) );
}


//**********************************************************
// dump properties of an JS object
//**********************************************************
function dump( obj)
{
var result="", ii="";
for ( ii in obj )
{
   result += ii+"="+obj[ii]+";";
}
log_msg (result);
}


//**********************************************************
// Callled to convert to a boolean type
//**********************************************************
function parse_boolean( valeur )
{ 
	
	var to_return = true;

	var test_val=valeur.toString();

	switch (test_val.toUpperCase())
	{
	case "":
	case "0":
	case "FALSE":
	case "FAUX":
	case "NO":
	case "NON":
	case "N":
	case "OFF":
	case "NIL":
	case "NUL":
		to_return=false;
		break;
	}
	
	return (to_return);	
}

//**********************************************************
// Callled to check if value is boolean type
//**********************************************************
function is_boolean( valeur )
{ 
	
	var to_return = false;
	
	switch (valeur.toUpperCase() )
	{  
//	case "0":
//	case "1":   Removed on 16/09/02
	case "YES":
	case "NO":
	case "TRUE":
	case "ON":
	case "OFF":
	case "FALSE":
	case "VRAI":
	case "FAUX":
	case "OUI":
	case "NON":
	case "NIL":
	case "NUL":
		to_return=true;
		break;
	}
	
	return (to_return);	
}


