function SubmitSearch(oForm){
  Windows(oForm);
}

function SearchWindow(STR){
  window.open(STR,"_blank","toolbar=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,location=yes,resizable=yes,copyhistory=yes,width=500,height=300,top=50,left=50");
}

var Window1,Window2,Window3,Window4,Window5,Window6,Window7,Window8,Window9,Window10,Window11,Window12,Window13,Window14;

function Windows(oForm){
  var WindowNumber=SearchEngines(oForm);
  if(WindowNumber==0){
    alert("Please choose at least one search engine.");
  }else{
    if(WindowNumber>=1)OpenWindowA(Window1);
    if(WindowNumber>=2)OpenWindowB(Window2);
    if(WindowNumber>=3)OpenWindowC(Window3);
    if(WindowNumber>=4)OpenWindowD(Window4);
    if(WindowNumber>=5)OpenWindowE(Window5);
    if(WindowNumber>=6)OpenWindowF(Window6);
    if(WindowNumber>=7)OpenWindowG(Window7);
    if(WindowNumber>=8)OpenWindowH(Window8);
    if(WindowNumber>=9)OpenWindowI(Window9);
    if(WindowNumber>=10)OpenWindowJ(Window10);
    if(WindowNumber>=11)OpenWindowK(Window11);
    if(WindowNumber>=12)OpenWindowL(Window12);
    if(WindowNumber>=13)OpenWindowM(Window13);
    if(WindowNumber>=14)OpenWindowN(Window14);
  }
}

function NextURL(PriorWindow,NextWindow){
  if(PriorWindow==0)Window1=NextWindow;
  else if(PriorWindow==1)Window2=NextWindow;
  else if(PriorWindow==2)Window3=NextWindow;
  else if(PriorWindow==3)Window4=NextWindow;
  else if(PriorWindow==4)Window5=NextWindow;
  else if(PriorWindow==5)Window6=NextWindow;
  else if(PriorWindow==6)Window7=NextWindow;
  else if(PriorWindow==7)Window8=NextWindow;
  else if(PriorWindow==8)Window9=NextWindow;
  else if(PriorWindow==9)Window10=NextWindow;
  else if(PriorWindow==10)Window11=NextWindow;
  else if(PriorWindow==11)Window12=NextWindow;
  else if(PriorWindow==12)Window13=NextWindow;
  else if(PriorWindow==13)Window14=NextWindow;
}

function CreateURL(AllSearchInput){
  var InputLength=AllSearchInput.length;
  for(InputSpaces=0;InputSpaces<=InputLength;InputSpaces++){
    if(AllSearchInput.substring(InputSpaces,InputSpaces+1)==" "){
      AllSearchInput=AllSearchInput.substring(0,InputSpaces)+"+"+AllSearchInput.substring(InputSpaces+1,InputLength);
    }
  }
  return(AllSearchInput);
}

function OpenWindowA(URL){
  window.open(URL,'_blank','toolbar=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,location=yes,resizable=yes,copyhistory=yes,width=500,height=300,top=10,left=50');
}

function OpenWindowB(URL){
  window.open(URL,'_blank','toolbar=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,location=yes,resizable=yes,copyhistory=yes,width=500,height=300,top=40,left=65');
}

function OpenWindowC(URL){
  window.open(URL,'_blank','toolbar=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,location=yes,resizable=yes,copyhistory=yes,width=500,height=300,top=70,left=80');
}

function OpenWindowD(URL){
  window.open(URL,'_blank','toolbar=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,location=yes,resizable=yes,copyhistory=yes,width=500,height=300,top=100,left=95');
}

function OpenWindowE(URL){
  window.open(URL,'_blank','toolbar=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,location=yes,resizable=yes,copyhistory=yes,width=500,height=300,top=130,left=110');
}

function OpenWindowF(URL){
  window.open(URL,'_blank','toolbar=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,location=yes,resizable=yes,copyhistory=yes,width=500,height=300,top=160,left=125');
}

function OpenWindowG(URL){
  window.open(URL,'_blank','toolbar=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,location=yes,resizable=yes,copyhistory=yes,width=500,height=300,top=190,left=140');
}

function OpenWindowH(URL){
  window.open(URL,'_blank','toolbar=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,location=yes,resizable=yes,copyhistory=yes,width=500,height=300,top=25,left=190');
}

function OpenWindowI(URL){
  window.open(URL,'_blank','toolbar=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,location=yes,resizable=yes,copyhistory=yes,width=500,height=300,top=55,left=205');
}

function OpenWindowJ(URL){
  window.open(URL,'_blank','toolbar=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,location=yes,resizable=yes,copyhistory=yes,width=500,height=300,top=85,left=220');
}

function OpenWindowK(URL){
  window.open(URL,'_blank','toolbar=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,location=yes,resizable=yes,copyhistory=yes,width=500,height=300,top=115,left=235');
}

function OpenWindowL(URL){
  window.open(URL,'_blank','toolbar=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,location=yes,resizable=yes,copyhistory=yes,width=500,height=300,top=145,left=250');
}

function OpenWindowM(URL){
  window.open(URL,'_blank','toolbar=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,location=yes,resizable=yes,copyhistory=yes,width=500,height=300,top=175,left=265');
}

function OpenWindowN(URL){
  window.open(URL,'_blank','toolbar=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,location=yes,resizable=yes,copyhistory=yes,width=500,height=300,top=205,left=280');
}

function SearchEngines(oForm){
  var URLCode;
  var RegistreEngines;
  var WindowNumber=0;
  var SearchFor=oForm.searchinput.value;
  RegistreEngines="";
  // input encoding
  InputEncoding = "UTF-8";
//  InputEncoding = "win-1251";
  // Search strings come here
  if(oForm.alltheweb.checked){
    RegistreEngines=RegistreEngines+"alltheweb;"
    URLCode=CreateURL(SearchFor)
    URLCode="http://www.alltheweb.com/search?type=all&query=" + URLCode;
    NextURL(WindowNumber,URLCode)
    WindowNumber++
  }
  if(oForm.altavista.checked){
    RegistreEngines=RegistreEngines+"altavista;"
    URLCode=CreateURL(SearchFor)
    URLCode="http://www.altavista.com/web/results?pg=q&q=" + URLCode + "&ie=" + InputEncoding;
    NextURL(WindowNumber,URLCode)
    WindowNumber++
  }
  if(oForm.aport.checked){
    RegistreEngines=RegistreEngines+"aport;"
    URLCode=CreateURL(SearchFor)
    URLCode="http://www.aport.ru/search.php?fr=forms&r=" + URLCode;
    NextURL(WindowNumber,URLCode)
    WindowNumber++
  }
  if(oForm.askjeeves.checked){
    RegistreEngines=RegistreEngines+"askjeeves;"
    URLCode=CreateURL(SearchFor)
    URLCode="http://www.askjeeves.com/main/askjeeves.asp?ask=" + URLCode + "&ie=" + InputEncoding;
    NextURL(WindowNumber,URLCode)
    WindowNumber++
  }
  if(oForm.excite.checked){
    RegistreEngines=RegistreEngines+"excite;"
    URLCode=CreateURL(SearchFor)
    URLCode="http://msxml.excite.com/info.xcite/search/web/" + URLCode;
    NextURL(WindowNumber,URLCode)
    WindowNumber++
  }
  if(oForm.google.checked){
    RegistreEngines=RegistreEngines+"google;"
    URLCode=CreateURL(SearchFor)
//    URLCode="http://www.google.com/search?q=" + URLCode + "&ie=" + InputEncoding;
    URLCode="http://www.google.com/search?num=100&newwindow=1&q=" + URLCode + "&ie=" + InputEncoding;
//    URLCode="http://www.google.com/search?num=100&hl=en&lr=&ie=" + InputEncoding + "&newwindow=1&q=" + URLCode + "&btnG=Search";
    NextURL(WindowNumber,URLCode)
    WindowNumber++
  }
  if(oForm.hotbot.checked){
    RegistreEngines=RegistreEngines+"hotbot;"
    URLCode=CreateURL(SearchFor)
    URLCode="http://hotbot.lycos.com/?MT=" + URLCode + "&ie=" + InputEncoding;
    NextURL(WindowNumber,URLCode)
    WindowNumber++
  }
  if(oForm.lycos.checked){
    RegistreEngines=RegistreEngines+"lycos;"
    URLCode=CreateURL(SearchFor)
    URLCode="http://sjc-search.sjc.lycos.com/default.asp?loc=searchbox&tab=web&query=" + URLCode + "&ie=" + InputEncoding;
    NextURL(WindowNumber,URLCode)
    WindowNumber++
  }
  if(oForm.rambler.checked){
    RegistreEngines=RegistreEngines+"rambler;"
    URLCode=CreateURL(SearchFor)
    URLCode="http://www.rambler.ru/cgi-bin/rambler_search?words=" + URLCode + "&ie=" + InputEncoding;
    NextURL(WindowNumber,URLCode)
    WindowNumber++
  }
  if(oForm.searchcom.checked){
    RegistreEngines=RegistreEngines+"searchcom;"
    URLCode=CreateURL(SearchFor)
    URLCode="http://www.search.com/search?q=" + URLCode;
    NextURL(WindowNumber,URLCode)
    WindowNumber++
  }
  if(oForm.shareware.checked){
    RegistreEngines=RegistreEngines+"shareware;"
    URLCode=CreateURL(SearchFor)
    URLCode="http://shareware.search.com/search?cat=247&tag=ex.sa.fd.srch.sa_all&q=" + URLCode;
    NextURL(WindowNumber,URLCode)
    WindowNumber++
  }
  if(oForm.webcrawler.checked){
    RegistreEngines=RegistreEngines+"webcrawler;"
    URLCode=CreateURL(SearchFor)
    URLCode="http://msxml.webcrawler.com/info.wbcrwl/search/web/" + URLCode;
    NextURL(WindowNumber,URLCode)
    WindowNumber++
  }
  if(oForm.yahoo.checked){
    RegistreEngines=RegistreEngines+"yahoo;"
    URLCode=CreateURL(SearchFor)
    URLCode="http://search.yahoo.com/search?p=" + URLCode + "&ei=" + InputEncoding + "&n=100&fl=0&x=wrt";
    NextURL(WindowNumber,URLCode)
    WindowNumber++
  }
  if(oForm.yandex.checked){
    RegistreEngines=RegistreEngines+"yandex;"
    URLCode=CreateURL(SearchFor)
    URLCode="http://www.yandex.ru/yandsearch?text=" + URLCode + "&ie=" + InputEncoding;
    NextURL(WindowNumber,URLCode)
    WindowNumber++
  }
  //End search strings here
  return(WindowNumber)
}

