<?php 
ini_set("display_errors","1");
ini_set("display_startup_errors","1");
set_magic_quotes_runtime(0);

include("include/dbcommon.php");
include("include/pf_tarja_variables.php");


//connect database
$conn = db_connect();

include('libs/Smarty.class.php');
$smarty = new Smarty();


$includes=
"<STYLE>
	.vis1	{ visibility:\"visible\" }
	.vis2	{ visibility:\"hidden\" }
</STYLE>
<script language=\"JavaScript\" src=\"include/calendar.js\"></script>
<script language=\"JavaScript\" src=\"include/jsfunctions.js\"></script>\r\n";
if ($useAJAX) {
$includes.="<script language=\"JavaScript\" src=\"include/jquery.js\"></script>
<script language=\"JavaScript\" src=\"include/ajaxsuggest.js\"></script>\r\n";
}
$includes.="<script language=\"JavaScript\" type=\"text/javascript\">\r\n".
"var locale_dateformat = ".$locale_info["LOCALE_IDATE"].";\r\n".
"var locale_datedelimiter = \"".$locale_info["LOCALE_SDATE"]."\";\r\n".
"var bLoading=false;\r\n".
"var TEXT_PLEASE_SELECT='".addslashes("Por favor seleccione")."';\r\n";
if ($useAJAX) {
$includes.="var SUGGEST_TABLE = \"pf_tarja_searchsuggest.php\";\r\n".
"var SUGGEST_LOOKUP_TABLE='pf_tarja_lookupsuggest.php';\r\n".
"var AUTOCOMPLETE_TABLE=\"pf_tarja_autocomplete.php\";\r\n";
}
$includes.="var detect = navigator.userAgent.toLowerCase();

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}


function ShowHideControls()
{
	document.getElementById('second_codigo_tarjeta').style.display =  
		document.forms.editform.elements['asearchopt_codigo_tarjeta'].value==\"Between\" ? '' : 'none'; 
	document.getElementById('second_flag').style.display =  
		document.forms.editform.elements['asearchopt_flag'].value==\"Between\" ? '' : 'none'; 
	document.getElementById('second_fecha_creacion').style.display =  
		document.forms.editform.elements['asearchopt_fecha_creacion'].value==\"Between\" ? '' : 'none'; 
	document.getElementById('second_tarja_anterior').style.display =  
		document.forms.editform.elements['asearchopt_tarja_anterior'].value==\"Between\" ? '' : 'none'; 
	document.getElementById('second_id_especie').style.display =  
		document.forms.editform.elements['asearchopt_id_especie'].value==\"Between\" ? '' : 'none'; 
	document.getElementById('second_num_cajas').style.display =  
		document.forms.editform.elements['asearchopt_num_cajas'].value==\"Between\" ? '' : 'none'; 
	document.getElementById('second_id_envase').style.display =  
		document.forms.editform.elements['asearchopt_id_envase'].value==\"Between\" ? '' : 'none'; 
	document.getElementById('second_id_tipo').style.display =  
		document.forms.editform.elements['asearchopt_id_tipo'].value==\"Between\" ? '' : 'none'; 
	document.getElementById('second_proveedor').style.display =  
		document.forms.editform.elements['asearchopt_proveedor'].value==\"Between\" ? '' : 'none'; 
	return false;
}
function ResetControls()
{
	var i;
	e = document.forms[0].elements; 
	for (i=0;i<e.length;i++) 
	{
		if (e[i].name!='type' && e[i].className!='button' && e[i].type!='hidden')
		{
			if(e[i].type=='select-one')
				e[i].selectedIndex=0;
			else if(e[i].type=='select-multiple')
			{
				var j;
				for(j=0;j<e[i].options.length;j++)
					e[i].options[j].selected=false;
			}
			else if(e[i].type=='checkbox' || e[i].type=='radio')
				e[i].checked=false;
			else 
				e[i].value = ''; 
		}
		else if(e[i].name.substr(0,6)=='value_' && e[i].type=='hidden')
			e[i].value = ''; 
	}
	ShowHideControls();	
	return false;
}";

if ($useAJAX) {
$includes.="
$(document).ready(function() {
	document.forms.editform.value_codigo_tarjeta.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value_codigo_tarjeta,'advanced')};
	document.forms.editform.value1_codigo_tarjeta.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value1_codigo_tarjeta,'advanced1')};
	document.forms.editform.value_codigo_tarjeta.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value_codigo_tarjeta,'advanced')};
	document.forms.editform.value1_codigo_tarjeta.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value1_codigo_tarjeta,'advanced1')};
	document.forms.editform.value_flag.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value_flag,'advanced')};
	document.forms.editform.value1_flag.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value1_flag,'advanced1')};
	document.forms.editform.value_flag.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value_flag,'advanced')};
	document.forms.editform.value1_flag.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value1_flag,'advanced1')};
	document.forms.editform.value_fecha_creacion.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value_fecha_creacion,'advanced')};
	document.forms.editform.value1_fecha_creacion.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value1_fecha_creacion,'advanced1')};
	document.forms.editform.value_fecha_creacion.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value_fecha_creacion,'advanced')};
	document.forms.editform.value1_fecha_creacion.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value1_fecha_creacion,'advanced1')};
	document.forms.editform.value_tarja_anterior.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value_tarja_anterior,'advanced')};
	document.forms.editform.value1_tarja_anterior.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value1_tarja_anterior,'advanced1')};
	document.forms.editform.value_tarja_anterior.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value_tarja_anterior,'advanced')};
	document.forms.editform.value1_tarja_anterior.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value1_tarja_anterior,'advanced1')};
	document.forms.editform.value_id_especie.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value_id_especie,'advanced')};
	document.forms.editform.value1_id_especie.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value1_id_especie,'advanced1')};
	document.forms.editform.value_id_especie.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value_id_especie,'advanced')};
	document.forms.editform.value1_id_especie.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value1_id_especie,'advanced1')};
	document.forms.editform.value_num_cajas.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value_num_cajas,'advanced')};
	document.forms.editform.value1_num_cajas.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value1_num_cajas,'advanced1')};
	document.forms.editform.value_num_cajas.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value_num_cajas,'advanced')};
	document.forms.editform.value1_num_cajas.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value1_num_cajas,'advanced1')};
	document.forms.editform.value_id_envase.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value_id_envase,'advanced')};
	document.forms.editform.value1_id_envase.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value1_id_envase,'advanced1')};
	document.forms.editform.value_id_envase.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value_id_envase,'advanced')};
	document.forms.editform.value1_id_envase.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value1_id_envase,'advanced1')};
	document.forms.editform.value_id_tipo.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value_id_tipo,'advanced')};
	document.forms.editform.value1_id_tipo.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value1_id_tipo,'advanced1')};
	document.forms.editform.value_id_tipo.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value_id_tipo,'advanced')};
	document.forms.editform.value1_id_tipo.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value1_id_tipo,'advanced1')};
	document.forms.editform.value_proveedor.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value_proveedor,'advanced')};
	document.forms.editform.value1_proveedor.onkeyup=function(event) {searchSuggest(event,document.forms.editform.value1_proveedor,'advanced1')};
	document.forms.editform.value_proveedor.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value_proveedor,'advanced')};
	document.forms.editform.value1_proveedor.onkeydown=function(event) {return listenEvent(event,document.forms.editform.value1_proveedor,'advanced1')};
});
</script>
<div id=\"search_suggest\"></div>
";
} else {
$includes.="
function OnKeyDown(e)
{ if(!e) e = window.event; 
if (e.keyCode == 13){ e.cancel = true; document.forms[0].submit();} }

</script>";
}

$smarty->assign("includes",$includes);
$smarty->assign("noAJAX",!$useAJAX);

$onload="onLoad=\"javascript: ShowHideControls();\"";
$smarty->assign("onload",$onload);

if(@$_SESSION[$strTableName."_asearchtype"]=="or")
{
	$smarty->assign("any_checked"," checked");
	$smarty->assign("all_checked","");
}
else
{
	$smarty->assign("any_checked","");
	$smarty->assign("all_checked"," checked");
}

$editformats=array();

// codigo_tarjeta 
$opt="";
$not=false;
if(@$_SESSION[$strTableName."_search"]==2)
{
	$opt=@$_SESSION[$strTableName."_asearchopt"]["codigo_tarjeta"];
	$not=@$_SESSION[$strTableName."_asearchnot"]["codigo_tarjeta"];
	$smarty->assign("value_codigo_tarjeta",@$_SESSION[$strTableName."_asearchfor"]["codigo_tarjeta"]);
	$smarty->assign("value1_codigo_tarjeta",@$_SESSION[$strTableName."_asearchfor2"]["codigo_tarjeta"]);
}	
if($not)
	$smarty->assign("not_codigo_tarjeta"," checked");
//	write search options
$options="";
$options.="<OPTION VALUE=\"Contains\" ".(($opt=="Contains")?"selected":"").">"."Contiene"."</option>";
$options.="<OPTION VALUE=\"Equals\" ".(($opt=="Equals")?"selected":"").">"."Equivale"."</option>";
$options.="<OPTION VALUE=\"Starts with ...\" ".(($opt=="Starts with ...")?"selected":"").">"."Empieza con"."</option>";
$options.="<OPTION VALUE=\"More than ...\" ".(($opt=="More than ...")?"selected":"").">"."Más que"."</option>";
$options.="<OPTION VALUE=\"Less than ...\" ".(($opt=="Less than ...")?"selected":"").">"."Menos que"."</option>";
$options.="<OPTION VALUE=\"Equal or more than ...\" ".(($opt=="Equal or more than ...")?"selected":"").">"."Igual o más"."</option>";
$options.="<OPTION VALUE=\"Equal or less than ...\" ".(($opt=="Equal or less than ...")?"selected":"").">"."Igual o menos"."</option>";
$options.="<OPTION VALUE=\"Between\" ".(($opt=="Between")?"selected":"").">"."Entre"."</option>";
$options.="<OPTION VALUE=\"Empty\" ".(($opt=="Empty")?"selected":"").">"."Vacio"."</option>";
$searchtype = "<SELECT ID=\"SearchOption\" NAME=\"asearchopt_codigo_tarjeta\" SIZE=1 onChange=\"return ShowHideControls();\">";
$searchtype .= $options;
$searchtype .= "</SELECT>";
$smarty->assign("searchtype_codigo_tarjeta",$searchtype);
//	edit format
$editformats["codigo_tarjeta"]="Text field";
// flag 
$opt="";
$not=false;
if(@$_SESSION[$strTableName."_search"]==2)
{
	$opt=@$_SESSION[$strTableName."_asearchopt"]["flag"];
	$not=@$_SESSION[$strTableName."_asearchnot"]["flag"];
	$smarty->assign("value_flag",@$_SESSION[$strTableName."_asearchfor"]["flag"]);
	$smarty->assign("value1_flag",@$_SESSION[$strTableName."_asearchfor2"]["flag"]);
}	
if($not)
	$smarty->assign("not_flag"," checked");
//	write search options
$options="";
$options.="<OPTION VALUE=\"Contains\" ".(($opt=="Contains")?"selected":"").">"."Contiene"."</option>";
$options.="<OPTION VALUE=\"Equals\" ".(($opt=="Equals")?"selected":"").">"."Equivale"."</option>";
$options.="<OPTION VALUE=\"Starts with ...\" ".(($opt=="Starts with ...")?"selected":"").">"."Empieza con"."</option>";
$options.="<OPTION VALUE=\"More than ...\" ".(($opt=="More than ...")?"selected":"").">"."Más que"."</option>";
$options.="<OPTION VALUE=\"Less than ...\" ".(($opt=="Less than ...")?"selected":"").">"."Menos que"."</option>";
$options.="<OPTION VALUE=\"Equal or more than ...\" ".(($opt=="Equal or more than ...")?"selected":"").">"."Igual o más"."</option>";
$options.="<OPTION VALUE=\"Equal or less than ...\" ".(($opt=="Equal or less than ...")?"selected":"").">"."Igual o menos"."</option>";
$options.="<OPTION VALUE=\"Between\" ".(($opt=="Between")?"selected":"").">"."Entre"."</option>";
$options.="<OPTION VALUE=\"Empty\" ".(($opt=="Empty")?"selected":"").">"."Vacio"."</option>";
$searchtype = "<SELECT ID=\"SearchOption\" NAME=\"asearchopt_flag\" SIZE=1 onChange=\"return ShowHideControls();\">";
$searchtype .= $options;
$searchtype .= "</SELECT>";
$smarty->assign("searchtype_flag",$searchtype);
//	edit format
$editformats["flag"]="Text field";
// fecha_creacion 
$opt="";
$not=false;
if(@$_SESSION[$strTableName."_search"]==2)
{
	$opt=@$_SESSION[$strTableName."_asearchopt"]["fecha_creacion"];
	$not=@$_SESSION[$strTableName."_asearchnot"]["fecha_creacion"];
	$smarty->assign("value_fecha_creacion",@$_SESSION[$strTableName."_asearchfor"]["fecha_creacion"]);
	$smarty->assign("value1_fecha_creacion",@$_SESSION[$strTableName."_asearchfor2"]["fecha_creacion"]);
}	
if($not)
	$smarty->assign("not_fecha_creacion"," checked");
//	write search options
$options="";
$options.="<OPTION VALUE=\"Contains\" ".(($opt=="Contains")?"selected":"").">"."Contiene"."</option>";
$options.="<OPTION VALUE=\"Equals\" ".(($opt=="Equals")?"selected":"").">"."Equivale"."</option>";
$options.="<OPTION VALUE=\"Starts with ...\" ".(($opt=="Starts with ...")?"selected":"").">"."Empieza con"."</option>";
$options.="<OPTION VALUE=\"More than ...\" ".(($opt=="More than ...")?"selected":"").">"."Más que"."</option>";
$options.="<OPTION VALUE=\"Less than ...\" ".(($opt=="Less than ...")?"selected":"").">"."Menos que"."</option>";
$options.="<OPTION VALUE=\"Equal or more than ...\" ".(($opt=="Equal or more than ...")?"selected":"").">"."Igual o más"."</option>";
$options.="<OPTION VALUE=\"Equal or less than ...\" ".(($opt=="Equal or less than ...")?"selected":"").">"."Igual o menos"."</option>";
$options.="<OPTION VALUE=\"Between\" ".(($opt=="Between")?"selected":"").">"."Entre"."</option>";
$options.="<OPTION VALUE=\"Empty\" ".(($opt=="Empty")?"selected":"").">"."Vacio"."</option>";
$searchtype = "<SELECT ID=\"SearchOption\" NAME=\"asearchopt_fecha_creacion\" SIZE=1 onChange=\"return ShowHideControls();\">";
$searchtype .= $options;
$searchtype .= "</SELECT>";
$smarty->assign("searchtype_fecha_creacion",$searchtype);
//	edit format
$editformats["fecha_creacion"]="Text field";
// tarja_anterior 
$opt="";
$not=false;
if(@$_SESSION[$strTableName."_search"]==2)
{
	$opt=@$_SESSION[$strTableName."_asearchopt"]["tarja_anterior"];
	$not=@$_SESSION[$strTableName."_asearchnot"]["tarja_anterior"];
	$smarty->assign("value_tarja_anterior",@$_SESSION[$strTableName."_asearchfor"]["tarja_anterior"]);
	$smarty->assign("value1_tarja_anterior",@$_SESSION[$strTableName."_asearchfor2"]["tarja_anterior"]);
}	
if($not)
	$smarty->assign("not_tarja_anterior"," checked");
//	write search options
$options="";
$options.="<OPTION VALUE=\"Contains\" ".(($opt=="Contains")?"selected":"").">"."Contiene"."</option>";
$options.="<OPTION VALUE=\"Equals\" ".(($opt=="Equals")?"selected":"").">"."Equivale"."</option>";
$options.="<OPTION VALUE=\"Starts with ...\" ".(($opt=="Starts with ...")?"selected":"").">"."Empieza con"."</option>";
$options.="<OPTION VALUE=\"More than ...\" ".(($opt=="More than ...")?"selected":"").">"."Más que"."</option>";
$options.="<OPTION VALUE=\"Less than ...\" ".(($opt=="Less than ...")?"selected":"").">"."Menos que"."</option>";
$options.="<OPTION VALUE=\"Equal or more than ...\" ".(($opt=="Equal or more than ...")?"selected":"").">"."Igual o más"."</option>";
$options.="<OPTION VALUE=\"Equal or less than ...\" ".(($opt=="Equal or less than ...")?"selected":"").">"."Igual o menos"."</option>";
$options.="<OPTION VALUE=\"Between\" ".(($opt=="Between")?"selected":"").">"."Entre"."</option>";
$options.="<OPTION VALUE=\"Empty\" ".(($opt=="Empty")?"selected":"").">"."Vacio"."</option>";
$searchtype = "<SELECT ID=\"SearchOption\" NAME=\"asearchopt_tarja_anterior\" SIZE=1 onChange=\"return ShowHideControls();\">";
$searchtype .= $options;
$searchtype .= "</SELECT>";
$smarty->assign("searchtype_tarja_anterior",$searchtype);
//	edit format
$editformats["tarja_anterior"]="Text field";
// id_especie 
$opt="";
$not=false;
if(@$_SESSION[$strTableName."_search"]==2)
{
	$opt=@$_SESSION[$strTableName."_asearchopt"]["id_especie"];
	$not=@$_SESSION[$strTableName."_asearchnot"]["id_especie"];
	$smarty->assign("value_id_especie",@$_SESSION[$strTableName."_asearchfor"]["id_especie"]);
	$smarty->assign("value1_id_especie",@$_SESSION[$strTableName."_asearchfor2"]["id_especie"]);
}	
if($not)
	$smarty->assign("not_id_especie"," checked");
//	write search options
$options="";
$options.="<OPTION VALUE=\"Contains\" ".(($opt=="Contains")?"selected":"").">"."Contiene"."</option>";
$options.="<OPTION VALUE=\"Equals\" ".(($opt=="Equals")?"selected":"").">"."Equivale"."</option>";
$options.="<OPTION VALUE=\"Starts with ...\" ".(($opt=="Starts with ...")?"selected":"").">"."Empieza con"."</option>";
$options.="<OPTION VALUE=\"More than ...\" ".(($opt=="More than ...")?"selected":"").">"."Más que"."</option>";
$options.="<OPTION VALUE=\"Less than ...\" ".(($opt=="Less than ...")?"selected":"").">"."Menos que"."</option>";
$options.="<OPTION VALUE=\"Equal or more than ...\" ".(($opt=="Equal or more than ...")?"selected":"").">"."Igual o más"."</option>";
$options.="<OPTION VALUE=\"Equal or less than ...\" ".(($opt=="Equal or less than ...")?"selected":"").">"."Igual o menos"."</option>";
$options.="<OPTION VALUE=\"Between\" ".(($opt=="Between")?"selected":"").">"."Entre"."</option>";
$options.="<OPTION VALUE=\"Empty\" ".(($opt=="Empty")?"selected":"").">"."Vacio"."</option>";
$searchtype = "<SELECT ID=\"SearchOption\" NAME=\"asearchopt_id_especie\" SIZE=1 onChange=\"return ShowHideControls();\">";
$searchtype .= $options;
$searchtype .= "</SELECT>";
$smarty->assign("searchtype_id_especie",$searchtype);
//	edit format
$editformats["id_especie"]="Text field";
// num_cajas 
$opt="";
$not=false;
if(@$_SESSION[$strTableName."_search"]==2)
{
	$opt=@$_SESSION[$strTableName."_asearchopt"]["num_cajas"];
	$not=@$_SESSION[$strTableName."_asearchnot"]["num_cajas"];
	$smarty->assign("value_num_cajas",@$_SESSION[$strTableName."_asearchfor"]["num_cajas"]);
	$smarty->assign("value1_num_cajas",@$_SESSION[$strTableName."_asearchfor2"]["num_cajas"]);
}	
if($not)
	$smarty->assign("not_num_cajas"," checked");
//	write search options
$options="";
$options.="<OPTION VALUE=\"Contains\" ".(($opt=="Contains")?"selected":"").">"."Contiene"."</option>";
$options.="<OPTION VALUE=\"Equals\" ".(($opt=="Equals")?"selected":"").">"."Equivale"."</option>";
$options.="<OPTION VALUE=\"Starts with ...\" ".(($opt=="Starts with ...")?"selected":"").">"."Empieza con"."</option>";
$options.="<OPTION VALUE=\"More than ...\" ".(($opt=="More than ...")?"selected":"").">"."Más que"."</option>";
$options.="<OPTION VALUE=\"Less than ...\" ".(($opt=="Less than ...")?"selected":"").">"."Menos que"."</option>";
$options.="<OPTION VALUE=\"Equal or more than ...\" ".(($opt=="Equal or more than ...")?"selected":"").">"."Igual o más"."</option>";
$options.="<OPTION VALUE=\"Equal or less than ...\" ".(($opt=="Equal or less than ...")?"selected":"").">"."Igual o menos"."</option>";
$options.="<OPTION VALUE=\"Between\" ".(($opt=="Between")?"selected":"").">"."Entre"."</option>";
$options.="<OPTION VALUE=\"Empty\" ".(($opt=="Empty")?"selected":"").">"."Vacio"."</option>";
$searchtype = "<SELECT ID=\"SearchOption\" NAME=\"asearchopt_num_cajas\" SIZE=1 onChange=\"return ShowHideControls();\">";
$searchtype .= $options;
$searchtype .= "</SELECT>";
$smarty->assign("searchtype_num_cajas",$searchtype);
//	edit format
$editformats["num_cajas"]="Text field";
// id_envase 
$opt="";
$not=false;
if(@$_SESSION[$strTableName."_search"]==2)
{
	$opt=@$_SESSION[$strTableName."_asearchopt"]["id_envase"];
	$not=@$_SESSION[$strTableName."_asearchnot"]["id_envase"];
	$smarty->assign("value_id_envase",@$_SESSION[$strTableName."_asearchfor"]["id_envase"]);
	$smarty->assign("value1_id_envase",@$_SESSION[$strTableName."_asearchfor2"]["id_envase"]);
}	
if($not)
	$smarty->assign("not_id_envase"," checked");
//	write search options
$options="";
$options.="<OPTION VALUE=\"Contains\" ".(($opt=="Contains")?"selected":"").">"."Contiene"."</option>";
$options.="<OPTION VALUE=\"Equals\" ".(($opt=="Equals")?"selected":"").">"."Equivale"."</option>";
$options.="<OPTION VALUE=\"Starts with ...\" ".(($opt=="Starts with ...")?"selected":"").">"."Empieza con"."</option>";
$options.="<OPTION VALUE=\"More than ...\" ".(($opt=="More than ...")?"selected":"").">"."Más que"."</option>";
$options.="<OPTION VALUE=\"Less than ...\" ".(($opt=="Less than ...")?"selected":"").">"."Menos que"."</option>";
$options.="<OPTION VALUE=\"Equal or more than ...\" ".(($opt=="Equal or more than ...")?"selected":"").">"."Igual o más"."</option>";
$options.="<OPTION VALUE=\"Equal or less than ...\" ".(($opt=="Equal or less than ...")?"selected":"").">"."Igual o menos"."</option>";
$options.="<OPTION VALUE=\"Between\" ".(($opt=="Between")?"selected":"").">"."Entre"."</option>";
$options.="<OPTION VALUE=\"Empty\" ".(($opt=="Empty")?"selected":"").">"."Vacio"."</option>";
$searchtype = "<SELECT ID=\"SearchOption\" NAME=\"asearchopt_id_envase\" SIZE=1 onChange=\"return ShowHideControls();\">";
$searchtype .= $options;
$searchtype .= "</SELECT>";
$smarty->assign("searchtype_id_envase",$searchtype);
//	edit format
$editformats["id_envase"]="Text field";
// id_tipo 
$opt="";
$not=false;
if(@$_SESSION[$strTableName."_search"]==2)
{
	$opt=@$_SESSION[$strTableName."_asearchopt"]["id_tipo"];
	$not=@$_SESSION[$strTableName."_asearchnot"]["id_tipo"];
	$smarty->assign("value_id_tipo",@$_SESSION[$strTableName."_asearchfor"]["id_tipo"]);
	$smarty->assign("value1_id_tipo",@$_SESSION[$strTableName."_asearchfor2"]["id_tipo"]);
}	
if($not)
	$smarty->assign("not_id_tipo"," checked");
//	write search options
$options="";
$options.="<OPTION VALUE=\"Contains\" ".(($opt=="Contains")?"selected":"").">"."Contiene"."</option>";
$options.="<OPTION VALUE=\"Equals\" ".(($opt=="Equals")?"selected":"").">"."Equivale"."</option>";
$options.="<OPTION VALUE=\"Starts with ...\" ".(($opt=="Starts with ...")?"selected":"").">"."Empieza con"."</option>";
$options.="<OPTION VALUE=\"More than ...\" ".(($opt=="More than ...")?"selected":"").">"."Más que"."</option>";
$options.="<OPTION VALUE=\"Less than ...\" ".(($opt=="Less than ...")?"selected":"").">"."Menos que"."</option>";
$options.="<OPTION VALUE=\"Equal or more than ...\" ".(($opt=="Equal or more than ...")?"selected":"").">"."Igual o más"."</option>";
$options.="<OPTION VALUE=\"Equal or less than ...\" ".(($opt=="Equal or less than ...")?"selected":"").">"."Igual o menos"."</option>";
$options.="<OPTION VALUE=\"Between\" ".(($opt=="Between")?"selected":"").">"."Entre"."</option>";
$options.="<OPTION VALUE=\"Empty\" ".(($opt=="Empty")?"selected":"").">"."Vacio"."</option>";
$searchtype = "<SELECT ID=\"SearchOption\" NAME=\"asearchopt_id_tipo\" SIZE=1 onChange=\"return ShowHideControls();\">";
$searchtype .= $options;
$searchtype .= "</SELECT>";
$smarty->assign("searchtype_id_tipo",$searchtype);
//	edit format
$editformats["id_tipo"]="Text field";
// proveedor 
$opt="";
$not=false;
if(@$_SESSION[$strTableName."_search"]==2)
{
	$opt=@$_SESSION[$strTableName."_asearchopt"]["proveedor"];
	$not=@$_SESSION[$strTableName."_asearchnot"]["proveedor"];
	$smarty->assign("value_proveedor",@$_SESSION[$strTableName."_asearchfor"]["proveedor"]);
	$smarty->assign("value1_proveedor",@$_SESSION[$strTableName."_asearchfor2"]["proveedor"]);
}	
if($not)
	$smarty->assign("not_proveedor"," checked");
//	write search options
$options="";
$options.="<OPTION VALUE=\"Contains\" ".(($opt=="Contains")?"selected":"").">"."Contiene"."</option>";
$options.="<OPTION VALUE=\"Equals\" ".(($opt=="Equals")?"selected":"").">"."Equivale"."</option>";
$options.="<OPTION VALUE=\"Starts with ...\" ".(($opt=="Starts with ...")?"selected":"").">"."Empieza con"."</option>";
$options.="<OPTION VALUE=\"More than ...\" ".(($opt=="More than ...")?"selected":"").">"."Más que"."</option>";
$options.="<OPTION VALUE=\"Less than ...\" ".(($opt=="Less than ...")?"selected":"").">"."Menos que"."</option>";
$options.="<OPTION VALUE=\"Equal or more than ...\" ".(($opt=="Equal or more than ...")?"selected":"").">"."Igual o más"."</option>";
$options.="<OPTION VALUE=\"Equal or less than ...\" ".(($opt=="Equal or less than ...")?"selected":"").">"."Igual o menos"."</option>";
$options.="<OPTION VALUE=\"Between\" ".(($opt=="Between")?"selected":"").">"."Entre"."</option>";
$options.="<OPTION VALUE=\"Empty\" ".(($opt=="Empty")?"selected":"").">"."Vacio"."</option>";
$searchtype = "<SELECT ID=\"SearchOption\" NAME=\"asearchopt_proveedor\" SIZE=1 onChange=\"return ShowHideControls();\">";
$searchtype .= $options;
$searchtype .= "</SELECT>";
$smarty->assign("searchtype_proveedor",$searchtype);
//	edit format
$editformats["proveedor"]="Text field";

$linkdata="";

if ($useAJAX) {
	$linkdata .= "<script type=\"text/javascript\">\r\n";
	$linkdata .= "$(document).ready(function(){ \r\n";
	$linkdata .= "
function loadSelectContent(txt, selectControl, selectValue) 
{
	$('#'+selectControl).get(0).options[0]=new Option(TEXT_PLEASE_SELECT,'');
	var str = txt.split('\\n');
	var index = 0;
	for(i=0,j=0; i < str.length - 1; i=i+2, j++) {
		$('#'+selectControl).get(0).options[j+1]=new Option(unescape(str[i+1]),unescape(str[i]));
		if ( unescape(str[i]) == selectValue ) {index = j+1;}
	}
	$('#'+selectControl).get(0).selectedIndex = index;
}"."\r\n";
	$linkdata .= "});\r\n";
	$linkdata .= "</script>\r\n";
} else {
}

$smarty->assign("linkdata",$linkdata);

$templatefile = "pf_tarja_search.htm";
if(function_exists("BeforeShowSearch"))
	BeforeShowSearch($smarty,$templatefile);

$smarty->display($templatefile);

?>