var pdf ;
var pdf_cat = new Array();
var total_weight = 6;

function initKW()
{
	var qs = new Querystring()
	var reqK = qs.get("KW","");
	var KWInp  = document.getElementById("keyword");
	if (KWInp) KWInp.value = reqK;
	var SForm  = document.getElementById("Sfrm");
	lib_search(SForm);
};

pdf_cat=["Electric","Power" , "Mathematic" , "Geometry" , "Paper" , "Particular" , "Project" , "Program" ] 
//   0       1          2                3                     4
// "path","Title","Many KeyWords","Descriptive Comments" , "Category"
pdf=[
["/cources/units/dg/14.pdf","Projection of position problems-1","Projectionplane,line,positions","","Geometry"],
["/cources/units/dg/15.pdf","Projection of position problems-2","Projectionparallel,intersection,plane,line","","Geometry"],
["/cources/units/dg/16.pdf","Projection of perpendiculars","Projectionperpendiculars,plane,line,true,length","","Geometry"],
["/cources/units/dg/22.pdf","Projection of cylinder","cylinder,surfaces, Projection","","Geometry"],
["/cources/units/dg/23.pdf","Projection of cone","cone,surfaces,Projection","","Geometry"],
["/cources/units/dg/25.pdf","Projection of shadow","shadow,geometry, Projection","","Geometry"],
["/cources/units/dg/31.pdf","Indexed Projection","indexed,point,line, Projection,geometry","","Geometry"],
["images/kisho.gif","programmer images","link,image,author,programmer","This is author images.","Program"],
["images/birtt.gif","Birth Certificate","Birth,certificate,author","","Particular"],
["Author/qualification/bsce.gif","B.Eng. Certificate","B.Sc.,B.Eng.,M.Sc.,Ph.D.,Engineering,certificate,degree,author,transcripts","","Particular"],
["Author/qualification/bscm.gif","B.Sc. Certificate","B.Sc.,B.Eng.,M.Sc.,Ph.D.,master,science,certificate,degree,author,transcripts","","Particular"],
["Author/qualification/msc.gif","M.Sc. Certificate","B.Sc.,B.Eng.,M.Sc.,Ph.D.,master,science,certificate,degree,author,transcripts","","Particular"],
["Author/qualification/phd.gif","Ph.D. Certificate","B.Sc.,B.Eng.,M.Sc.,Ph.D.,master,science,certificate,degree,author,transcripts","","Particular"],
["cv.htm","CV of Author","cv,author,particulars","","Particular"],
["/cources/units/pe/11.pdf","introduction to power electronics","power, electronics,review,introduction","","Power"],
["/cources/units/pe/12.pdf","electronic devices","power,electronics,devices, diodes,thyristors,mosfet,igbt","","Power"],
["/cources/units/pe/22.pdf","1-Ph rectifier","power,electronics,single, phase,rectifier,diode","","Power"],
["/cources/units/pe/23.pdf","3-Ph rectifier","power, electronics, 3-Ph, three,rectifier,diode","","Power"],
["/cources/units/pe/24.pdf","1-Ph ac/dc converter","power,electronics, single,phase,converter,thyristor","","Power"],
["/cources/units/pe/25.pdf","3-Ph ac/dc converter","power, electronics, 3-Ph,three,converter,thyristor","","Power"],
["/cources/units/pe/37.pdf","CCM dc/dc converter","power, electronics, dc-dc,converter,buck,boost,cuk","","Power"],
["/cources/units/pe/38.pdf","DCM dc/dc converter","power, electronics, dc-dc,converter,buck,boost,cuk","","Power"],
["/cources/units/pe/36.pdf","CCM dc/dc converter","power, electronics, dc-dc,converter,boost","","Power"],
["/cources/units/pe/35.pdf","CCM dc/dc converter","power, electronics, dc-dc,converter,buck","","Power"],
["/cources/units/pe/32.pdf","1-Ph dc/ac inverter","power,electronics, single,phase,inverter,switches,igbt,mosfet,unipolar,bipolar","","Power"],
["/cources/units/pe/33.pdf","3-Ph dc/ac inverter","power, electronics, 3-Ph,three,inverter,switches,igbt,mosfet,unipolar,bipolar","","Power"],
["/cources/units/drv/21.pdf","ac drive","drives,ac,vsi,csi,switches,igbt, mosfet","","Power"],
["/cources/units/drv/22.pdf","dc drive","drives,dc,vsi,csi,switches,igbt, mosfet,control,position,speed","","Power"],
["index.html","DemoSite","index,main,start,home,front","Demonstration search engine data about an imagined but probable internet site.","Electric"],
["/cources/units/emg/22.pdf","electrostatics","columb,gauss,potential,dipole,work done,charge, current,electric field","","Electric"],
["/cources/units/dsp/11.pdf","continuous time signal","fourier,dsp,asp,lti, time,continuous,signals,transform","","Electric"],
["/cources/units/dsp/22.pdf","FIR filter","fourier,dsp,fir,transform, windowing,bartlett,hamming,hanning,blackman,kaiser,filter","","Electric"],
["/cources/units/dsp/24.pdf","Frequency sampling tables","dsp,tables, fir,filters,frequency,sample,sampling,transition","","Electric"],
["/cources/units/dsp/26.pdf","IIR Filter","dsp,iir,filter,butterworth, tchebyshev,elliptic","","Electric"],
["/cources/units/dsp/27.pdf","Bilinear transform","dsp,filter,iir,transform, bilinear,implementation","","Electric"],
["/cources/units/dsp/33.pdf","Nonparametric Spectral","dsp,random,process, non-parametric,spectral,periodogram,welsh,tukey,blackman,bartlett","","Electric"],
["/cources/units/dsp/34.pdf","Parametric Spectral","dsp,random,process, parametric,spectral,moving,avarage,autoregressive,process,model","","Electric"],
["/cources/units/Rmath/malypolod.pdf","Polodes","paper,geometry,cone, polodes,conic,sections","","Paper"],
["/cources/units/Rmath/grvib.pdf","vibrating system","paper,math, mechanics,vibrating,system","","Paper"],
["/cources/units/Rdrv/chindtc.pdf","direct torque control","paper,induction, motor,im,drive,dtc,direct,torque,control,sensorless","","Paper"],
["/cources/units/Rdrv/itlyslimode.pdf","sliding mode control","paper,induction,motor,im,drive,sliding,mode,control,variable","","Paper"],
["/cources/units/Rmc/analysis/swisync.pdf","synchronous machine stability","paper,synchronous,motor,sm,stability,energy,direct","","Paper"],
["/cources/units/Rmc/dptheory/brthermc.pdf","theorms of torque","paper,induction,reluctance,motor,rm,im,stability,theorems,torque","","Paper"],
["/cources/units/Rmc/dptheory/inddp.pdf","small signal stability","paper,induction,reluctance,motor,rm,im,stability,d-partition,decomposition","","Paper"],
["/cources/units/Rmc/dptheory/trrlocus.pdf","root locus","paper,induction,reluctance,motor,rm,im,stability,roots,locus","","Paper"],
["/cources/units/Rmc/eqtqfb/egfbim.pdf","fb waves for im","paper,induction,motor,im,stability,forward,backward,waves,equivalent,circuits,torques","","Paper"],
["/cources/units/Rmc/eqtqfb/egfbrm.pdf","fb waves for rm","paper,reluctance,motor,rm,stability,forward,backward,waves,equivalent,circuits,torques","","Paper"],
["/cources/imcproj.htm","IMC Project","project,induction,motor,simulation,controller,drives","Induction motor performance project in Bahaza Malaysia","Project"],
["/cources/fyproj.htm","final year Project","project,power electronics,simulation,converter,inverter,rectifier,implimentation,plc,ac-ac, vector control","","Project"],
["/cources/units/cv/11.pdf","Polar form","complex,variables,math,numbers","This is complex mathematics","Mathematic"],
["/cources/units/cv/13.pdf","De moiver's theorem","complex,variables,math,D-,Moiver,theorem","","Mathematic"],
["/cources/units/cv/25.pdf","Analytic function","complex,variables, math,analytic,functions","","Mathematic"],
["/cources/units/cv/32.pdf","Conformal mapping","complex,variables, math,conformal,mapping","","Mathematic"],
["/cources/units/cv/43.pdf","Cauchy theorem of residues","complex,variables, math,cauchy,theorem,residues","","Mathematic"],
["/cources/units/cv/55.pdf","D-partition","complex,variables,math,D-, partition,decomposition","","Mathematic"],
["/cources/units/ode/17.pdf","Bernoulli equation","ode,differential, equations,math,bernoulli","","Mathematic"],
["/cources/units/ode/18.pdf","Riccati equation 1st order","ode,differential, equations,math,riccati","","Mathematic"],
["/cources/units/ode/24.pdf","Riccati equation 2nd order","ode,differential, equations,math,riccati","","Mathematic"],
["/cources/units/ode/23.pdf","Particular integral","ode,differential, equations,math,particular,integral","","Mathematic"],
["/cources/units/ode/25.pdf","Frobenius & Power series solution","ode, differential,equations,math,frobenius,power,series","","Mathematic"],
["/cources/units/emg/11.pdf","vector calculus","vector,coordinates,cartesian,cylindrical,spherical,product","","Electric"],
["/cources/units/emg/13.pdf","del operator","vector,coordinates,del, nabla,operator, laplacian,curl,gradian,diversion","","Electric"],
["/cources/units/vc/11.pdf","vector operation","vector,addition,division,product","","Mathematic"],
["/cources/units/vc/12.pdf","vector function","vector,function,product","","Mathematic"],
["/cources/units/vc/13.pdf","vector field","vector,field,product","","Mathematic"],
["/cources/units/vc/23.pdf","vector operator","vector,coordinates,del, operator, nabla,laplacian,curl,gradian,diversion","","Mathematic"],
["/cources/units/ode/32.pdf","3rd order solution","ode,differential, equations,math,3rd, order,third,solution","","Mathematic"],
["/cources/units/ode/53.pdf","Laplace Transform tables","ode,differential, equations,math,laplace, transform,tables","","Mathematic"],
["/cources/units/tran/13.pdf","Continuous Fourier Transform tables"," equations,math,fourier,complex,continuous, transform,tables","","Mathematic"],
["/cources/units/tran/15.pdf","Sin Cos Fourier Transform tables"," equations,math,fourier,real,sine,cosine, transform,tables","","Mathematic"],
["/cources/units/tran/22.pdf","z-Transform tables","z,equations,math,  transform,tables","","Mathematic"],
["/cources/units/la/12.pdf","Norm","linear,algebra,vectors,norm,math","","Mathematic"],
["/cources/units/la/13.pdf","Inner product","inear,algebra,vectors, inner,dot,product,math","","Mathematic"],
["/cources/units/la/14.pdf","Vector product","inear,algebra,vectors, vector,cross,product,math","","Mathematic"],
["/cources/units/la/23.pdf","Matrix Properties","inear,algebra,matrix, matrices,property,properties,math","","Mathematic"],
["/cources/units/la/25.pdf","Rank","inear,algebra,matrix,matrices,Rank, math","","Mathematic"],
["/cources/units/la/32.pdf","Cramer's rule","inear,algebra,matrix,matrices,inverse,inversion,cramer, math","","Mathematic"],
["/cources/units/la/54.pdf","Cayley-Hamilton method","inear,algebra,matrix,matrices,cayley,hamilton,method,math","","Mathematic"],
["/cources/units/ode/65.pdf","Engineering Systems","ode,differential, equations,math,circuits,vibration,rotation,beems,tables,engineering,systems","","Mathematic"],
["/cources/sf.htm","Special Functions","special,functions,error,gamma,beta, hyper,hermite,legendre,laguerre,tchebyshev,bessel,math","All functions","Mathematic"],
["/cources/units/prog/imcwin.zip","Induction Motor Characteristics","Induction,Motor,Characteristics,stability,hunting,steady,state,program","This program runs on Windows..!","Program"],
["/cources/units/prog/ems.zip","Machine Stability","synchronous,d partition, reluctance,Induction,Motor,torque, true,eigenvalue,roots,stability,hunting,program","This program runs on DOS, just type EMS..!","Program"],
["/cources/units/prog/ell.zip","Polodes Curves","cyclotron,cycloid,cardoid, sinusoidal,curves,polodes,archemeedis,ellipse,circels,drawn","This program runs on DOS, just type c1, c2 or c3 and watch, then escape..!","Program"],
];
////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
function lib_search(frm)
{
 keywords = frm.keyword.value.toLowerCase();
 keywords = trim(keywords);
 if ( keywords.length <2 ) return;
 var search_type = parseInt(frm.search_type.value);
  var search_cat =  frm.search_cat.value.toLowerCase() ;
 
 document.getElementById("output_area").innerHTML= "" ;
 page="<b>Results : </b><br>";

 txt =keywords.split(" ");
 fnd = new Array(pdf.length);
 if(search_cat == "0") { order =new Array(4, 3, 1, 2); total_weight= 10 * txt.length; }
 else { order =new Array( 3, 1, 2); total_weight= 6 * txt.length; }
 total=0;
 for (i = 0; i < pdf.length; i++)
 {
  if (pdf[i] == null) continue;
  fnd[i] = 0; 
 // alert("search_cat="+search_cat+"         this_cat="+pdf[i][4].toLowerCase());
  if ( search_cat != "0" && search_cat != pdf[i][4].toLowerCase() )  continue;      

   txt_hit = new Array(txt.length);
   intial_array(txt_hit);

   for (j = 0; j < order.length; j++)
   {
    for (k = 0; k < txt.length; k++)
    {
     if ( pdf[i][order[j]].toLowerCase().indexOf(txt[k]) > -1 && txt[k] != "" )
     {
      txt_hit[k] = txt_hit[k] + (j+1);
      //fnd[i] += (j+1);
     }
    };
   };
   fnd[i] = array_sum ( txt_hit);
   if(search_type == 1 )
   {
    if( array_times ( txt_hit) == 0 )  fnd[i] = 0;
   }

 }

 // max-first sort according to hit weight
 for (i = 0; i < fnd.length; i++)
 {
  n = 0; which = -1;
  for (j = 0;j < fnd.length; j++)  if (fnd[j] > n) { n = fnd[j]; which = j; };
  if (which > -1) total += show(which,  n);
  fnd[which] = 0;
 }
  page = page + "<br><b>Total found:</b>"+total+"<br>";
  //return page;
  document.getElementById("output_area").innerHTML= page ;
  document.getElementById("output_area").style.display = "";
}

function show(which,num)
{
 line = "<table align=center border=0 cellspacing=2 width=100%>" +
 		"<tr><td valign=top>"+
 		"<a href='"+pdf[which][0]+"'>"+pdf[which][1]+"</a></td>" +
 		"<td valign=top nowrap width=20%><b>Score:</b>"+Math.round(100*(num/total_weight*100))/100+"%</td></tr>" +
 		"<tr><td valign=top colspan='2'>"+ pdf[which][3] + "</td></tr></table><br>";
 page = page + line; 
 return 1;
}
//////////////////////////////////////////////////////////
/////////////////////////////// index ///////////////////////////////
function lib_cat_list(sel)
{
 if ( sel == "0") sel = " ";
 else sel =" selected ";
 for (i = 0; i < pdf_cat.length; i++)
 {
  if ( pdf_cat[i] == null) continue;
  if(i==0) document.write("<option value='"+pdf_cat[i].toLowerCase()+"' "+ sel +">"+pdf_cat[i]+"</option>");
  else document.write("<option value='"+pdf_cat[i].toLowerCase()+"'  >"+pdf_cat[i]+"</option>");
 }
}

function lib_cat_select(cat)
{
 if(cat.length < 1) return;	
 cat = cat.toLowerCase();
 var list="<select name=\"file\" size=\"8\" onChange=\"lib_file_select(this.value);\">";
 for (i = 0; i < pdf.length; i++)	
 {
  if( pdf[i] ==null ) continue;
  if( cat == pdf[i][4].toLowerCase() )  list = list + "<option value='"+i+"' selected>"+pdf[i][1]+"</option>" ;
 };
 list = list + "</select>";
 document.getElementById("file_list").innerHTML= list ;
}

function lib_file_select(index)
{
 if(index.length < 1) return;	
  var info=""; 
  info = info +"<p><b>Description :</b><br> "+pdf[index][3]+"</p> <a href='"+pdf[index][0]+"' >Download..!</a>";
  document.getElementById("info_area").innerHTML= info ;
  //document.getElementById("output_area").style.display = "";
}
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
	
 function trim(inputString)
{
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ")
   {
      // spaces at the beginning 
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ")
   {
      // spaces at the end 
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1)
    { 
    // multiple spaces within
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; 
} 


function array_sum(arr)
{
 sum = 0;
 for(is=0; is<arr.length; is++) sum = sum + arr[is];
 
 return sum;
}


function array_times(arr)
{
 sum = 1;
 for(it=0; it<arr.length; it++) sum = sum * arr[it];
 return sum;
}


function  intial_array(arr)
{
 for(ii=0; ii<arr.length; ii++) arr[ii]=0;
}	


