function prepare_search_string(instr){
phrases=instr.match(/(\"(([^\"]|[a-z]| )*)\")/ig)
if( phrases!=null){
phrases=phrases.toString();
phrases=phrases.replace(/\,/g,"+and+");
}else{
phrases="";
}
//delete phrases
instr=instr.replace(/\"(([^\"]|[a-z]| )*)\"/ig,"");
//alert(RegExp.$1);
//alert (instr);
instr=instr.replace(/\s+/g,"  ");
instr=instr.replace(/^\s*([\S\s]*\S+)\s*$/,"$1");
instr=instr.replace(/^\s*|\s*$/g,"");
instr=instr.replace(/\s+/g,"+and+");
if (phrases.length>0 ){
	if (instr.length>0){
		instr=phrases+"+and+"+instr;
	} else{
		instr=phrases;
	}
}
//alert (instr)
return instr;
}
//
//
function newchecksearch()
{
//nastavitve
var zzzsisci = "/usrs/us-odl.nsf/SearchEng?SearchView&Query=";
var izbranijezik=2;
msg="Please enter search criteria.\r";
//
if (1==0){
 //just a cache for english settings
var zzzsisci = "/usrs/us-odl.nsf/SearchEng?SearchView&Query=";
var izbranijezik=2;
msg="Please enter search criteria.\r";
}
var msg;
var msgflag;
var poltekst;
var stzadeva;
var opisakt;
var opisevi;
var opisimevlag;
var opisproblem;
var vejicteskt;
var vejiczadeva;
var vejicakt;
var vejicevi;
var vejicvlag;
var pokazDODL, DODL_s_d, DODL_s_m, DODL_s_y,DODL_e_d, DODL_e_m, DODL_e_y;
var pokazDVLOG, DVLOG_s_d, DVLOG_s_m, DVLOG_s_y,DVLOG_e_d, DVLOG_e_m, DVLOG_e_y;
var pokazVRSTAD;
var pokazVRSTAV;
var pokazVODL;
var pokazVRSTAA;
var pokazVRSTARES;
var pokazJEZIK, pokazREPUB;
var f= document.forms[0];
var vredDODL_start = document.forms[0].DODL_start.value;
var vredDODL_end = document.forms[0].DODL_end.value;
var vredDVLOG_start = document.forms[0].DVLOG_start.value;
var vredDVLOG_end = document.forms[0].DVLOG_end.value;
var vredVRSTAD = document.forms[0].VRSTAD.value;
var vredVRSTAV = document.forms[0].VRSTAV.value;
var vredVODL = document.forms[0].VODL.value;
var vredVRSTAA = document.forms[0].VRSTAA.value;
var vredVRSTARES = document.forms[0].VRSTARES.value;
var db = window.location.pathname;
var firstpart = db.split(".nsf");
var dbpath = firstpart[0] + ".nsf";
var fb = db.indexOf("?"); 
var ftq = f.text.value;
var lftq = ftq.toLowerCase()
var fuzzysearching="";
if (f.fuzzyon.checked == true){ fuzzysearching="&SearchFuzzy=1";}else{fuzzysearching="&SearchFuzzy=0";}
{
ftq=prepare_search_string(ftq)
}
pokazDVLOG='';
pokazDODL='';
datediffbiggerthanyear=true;
curdate=new Date();
curdateUTC=Date.UTC(parseInt(curdate.getFullYear()),parseInt(curdate.getMonth())+1,parseInt(curdate.getDate()));
if (vredDODL_start != "" || vredDODL_end != "" ){
	if (vredDODL_start != ""){
	DODL_s_d = vredDODL_start.substr(0, 2);
	DODL_s_m = vredDODL_start.substr(3, 2);
	DODL_s_y = vredDODL_start.substr(6, 4);
	dodlqtemp1='AND+([DODLNum]>='+ DODL_s_y + DODL_s_m + DODL_s_d + ')';
	pokazDODL='+'+dodlqtemp1;
	dodldatestart=Date.UTC(parseInt(DODL_s_y), parseInt(DODL_s_m), parseInt(DODL_s_d)) ;
	
	}else{
	dodldatestart=0;
	}
	if (vredDODL_end != ""){
	DODL_e_d = vredDODL_end.substr(0, 2);
	DODL_e_m = vredDODL_end.substr(3, 2);
	DODL_e_y = vredDODL_end.substr(6, 4);
	dodlqtemp2='AND+([DODLNum]<='+ DODL_e_y + DODL_e_m + DODL_e_d + ')';
	pokazDODL=pokazDODL+'+'+dodlqtemp2;
	dodldateend=Date.UTC(parseInt(DODL_e_y), parseInt(DODL_e_m), parseInt(DODL_e_d)) ;
	}else{
	
	dodldateend=curdateUTC;
	}
	
	if ((dodldateend-dodldatestart)<31536000000){datediffbiggerthanyear=false;}
//pokazDODL = '+AND+([DODLNum]>='+ DODL_s_y + DODL_s_m + DODL_s_d + ')+AND+([DODLNum]<='+ DODL_e_y + DODL_e_m + DODL_e_d + ')'
}else{
pokazDODL = ""}
if (vredDVLOG_start != "" || vredDVLOG_end != "" ){
	if (vredDVLOG_start != ""){
		DVLOG_s_d = vredDVLOG_start.substr(0, 2);
		DVLOG_s_m = vredDVLOG_start.substr(3, 2);
		DVLOG_s_y = vredDVLOG_start.substr(6, 4);
		dvlogqtemp1='AND+([DVLOGNum]>='+ DVLOG_s_y + DVLOG_s_m + DVLOG_s_d + ')';
		pokazDVLOG='+'+dvlogqtemp1;
		dvlogdatestart=Date.UTC(parseInt(DVLOG_s_y), parseInt(DVLOG_s_m), parseInt(DVLOG_s_d)) ;
		
	}else{
		dvlogdatestart=0;
	}
	if (vredDVLOG_end != ""){
		DVLOG_e_d = vredDVLOG_end.substr(0, 2);
		DVLOG_e_m = vredDVLOG_end.substr(3, 2);
		DVLOG_e_y = vredDVLOG_end.substr(6, 4);
		dvlogqtemp2='AND+([DVLOGNum]<='+ DVLOG_e_y + DVLOG_e_m + DVLOG_e_d + ')';
		pokazDVLOG=pokazDVLOG+'+'+dvlogqtemp2;
		dvlogdateend=Date.UTC(parseInt(DVLOG_e_y), parseInt(DVLOG_e_m), parseInt(DVLOG_e_d)) ;
	}else{
	dvlogdateend=curdateUTC;
	}
if ((dvlogdateend-dvlogdatestart)<31536000000){datediffbiggerthanyear=false;}
//pokazDVLOG = '+'+dvlogqtemp1+'+'+dvlogqtemp2;
}else{
pokazDVLOG = "";
}
//**********************************************************
//	izbirni seznami
if (vredVRSTAD == "*")
	{pokazVRSTAD = ""}
	else
	{pokazVRSTAD = 
	'+AND+([VRSTAD]='+ vredVRSTAD + ')'}
if (vredVRSTAV == "*")
	{pokazVRSTAV = ""}
	else
	{pokazVRSTAV = 
	'+AND+([VRSTAV]='+ vredVRSTAV + ')'}
if (vredVODL == "*")
	{pokazVODL = ""}
	else
	{pokazVODL = 
	'+AND+([VODL]='+ vredVODL + ')'}
if (vredVRSTAA == "*")
	{pokazVRSTAA = ""}
	else
	{pokazVRSTAA = 
	'+AND+([VRSTAA]='+ vredVRSTAA + ')'}
if (vredVRSTARES == "*")
	{pokazVRSTARES = ""}
	else
	{pokazVRSTARES = 
	'+AND+([VRES]='+ vredVRSTARES + '+OR+[VRES2]='+ vredVRSTARES+ '+OR+[VRES3]='+ vredVRSTARES +' )'}
	{pokazJEZIK = 
	'+AND+([JEZIK]='+izbranijezik+')'}
	{pokazREPUB = 
	'+AND+([REPUB]=5)'}
//****************************************
msgflag = "false";
 if(f.text.value == "" && datediffbiggerthanyear)  {
 msg;
		 msgflag="true";
 }
		  if(msgflag == "true"){
		 alert(msg);
     f.text.focus()
     }
fields="";
if (f.text.value != ""){
//************************************************
boxTEKST = eval("f.TEKST"); 
if (boxTEKST.checked == false)
	{poltekst = ""}
	else
	{poltekst = 
	'([TEKST]='+ escape(ftq) + ')+OR+'} 
boxPRAPODL = eval("f.PRAPODL"); 
if (boxPRAPODL.checked == false)
	{prapodltekst = ""}
	else
	{prapodltekst = 
	'([PRAPODL]='+ escape(ftq) + ')+OR+'} 
boxZADEVA = eval("f.ZADEVA"); 
if (boxZADEVA.checked == false)
	{stzadeva = ""}
	else
	{stzadeva = 
	'([ZADEVA]='+ escape(ftq) + ')+OR+'} 
boxAKT = eval("f.AKT"); 
if (boxAKT.checked == false)
	{opisakt = ""}
	else
	{opisakt = 
	'([AKT]='+ escape(ftq) + ')+OR+'} 
boxOPOMBA = eval("f.OPOMBA"); 
if (boxOPOMBA.checked == false)
	{opisopo = ""}
	else
	{opisopo = 
	'([OPOMBA]='+ escape(ftq) + ')+OR+'}
boxPTEKST = eval("f.PTEKST"); 
if (boxPTEKST.checked == false)
	{opisptekst = ""}
	else
	{opisptekst = 
	'([PTEKST]='+ escape(ftq) + ')+OR+'}
boxIMEVLAG = eval("f.IMEVLAG"); 
if (boxIMEVLAG.checked == false)
	{opisimevlag = ""}
	else
	{opisimevlag = 
	'([IMEVLAG]='+ escape(ftq) + ')+OR+'}
boxPROBLEM = eval("f.PROBLEM"); 
if (boxPROBLEM.checked == false)
	{opisproblem = ""}
	else
	{opisproblem = 
	'([PROBLEM]='+ escape(ftq) + ')+OR+'}
boxIZREK = eval("f.IZREK"); 
if (boxIZREK.checked == false)
	{opisizrek = ""}
	else
	{opisizrek = 
	'([IZREK]='+ escape(ftq) + ')+OR+'}
fields=opisopo+ poltekst +  stzadeva  + opisakt  +opisptekst+ poltekst +prapodltekst + opisimevlag + opisproblem + opisizrek;
fields='(' +fields.replace(/\+OR\+$/,"")+  ')'
//***************************************************
}else{fields=''}
otherfields= pokazVRSTAD + pokazVRSTAV + pokazVODL + pokazVRSTAA + pokazVRSTARES + pokazJEZIK + pokazREPUB + pokazDODL + pokazDVLOG + '&iskanje=' + escape( f.text.value) +'&SearchOrder=1'+fuzzysearching+'&SearchWv=1&'
if (fields==''){otherfields=otherfields.replace(/^\+AND\+/,"");}
//zakljucek="([napredno]=1)";
if(msgflag == "false"){
window.open(zzzsisci  +fields+otherfields
+ 'start=1&count=25','_top');
}
}
