function doFIND(n, d) { 
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function Pchange(a){
    document.form1.submit();
}

function Default_position(a){
if (a.selectedIndex!=0) {a.selectedIndex=0};
}

function addBookMark(bookMarkURL,bookMarkTitle) {
  window.external.AddFavorite(bookMarkURL,bookMarkTitle)
  }

function fnSet(){
  oHomePage.setHomePage('http://www.horse21.net');
  event.returnValue = false;
}

//Added by Nick 07.10.02
var arCtV = Array();
var arCtT = Array();

function ChCn()
{  var i = 0;
  var j = 0;
  var k = 0;
  var arPr = new Array(2);
  var oStr = '';

  j = document.QuickSearch.sCt.options.length;
  for (i = j - 1; i > 0; i--)
    document.QuickSearch.sCt.options[i] = null;
  k = parseInt(document.QuickSearch.sCn.options[document.QuickSearch.sCn.selectedIndex].value);
  j = 1;
  var elOpt = new Option;
  elOpt.value = "0:0";
  elOpt.text = "Select city";
  document.QuickSearch.sCt.options[0] = elOpt;
  for (i = 0; i < arCtV.length; i++) {
    oStr = arCtV[i];
    arPr = oStr.split(':');
    if ((k == 0) || (parseInt(arPr[0]) == k)) {
      elOpt = new Option;
      elOpt.value = arCtV[i];
      elOpt.text = arCtT[i];
      document.QuickSearch.sCt.options[j] = elOpt;
      j += 1;
    }
  }
}
var DayInMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

function ChDt(name)
{
  var mYear = parseInt(doFIND('QuickSearch').item(name+'3').options[doFIND('QuickSearch').item(name+'3').selectedIndex].value, 10);
  var mMonth = parseInt(doFIND('QuickSearch').item(name+'2').options[doFIND('QuickSearch').item(name+'2').selectedIndex].value, 10);
  var mDay = parseInt(doFIND('QuickSearch').item(name+'1').options[doFIND('QuickSearch').item(name+'1').selectedIndex].value, 10);
  var k = parseInt(doFIND('QuickSearch').item(name+'1').selectedIndex, 10);
  //alert(mYear + ' ' + mMonth + ' ' + mDay + ' ' + k);
  if (mYear % 4 == 0)
    DayInMonth[1] = 29;
  else
    DayInMonth[1] = 28;

  for (i = doFIND('QuickSearch').item(name+'1').length - 1; i >= 0; i--)
    doFIND('QuickSearch').item(name+'1').options[i] = null;

  for (i = 0; i < DayInMonth[mMonth - 1]; i++) {
    var elOpt = new Option;
    elOpt.value = i+1;
    elOpt.text = String(i+1);
    doFIND('QuickSearch').item(name+'1').options[i] = elOpt;
  }
  if (k > DayInMonth[mMonth]-1)
    doFIND('QuickSearch').item(name+'1').options[DayInMonth[mMonth]-1].selected = true;
  else
    doFIND('QuickSearch').item(name+'1').options[k].selected = true;
}

function ClientSetDates()
{
var nDate = new Date();
var DayInMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31,31); //12+next january

  var aDay, aMonth, aYear, dDay, dMonth, dYear;
  aDay = nDate.getDate() + 30;
  aMonth = nDate.getMonth() + 1;
  aYear = nDate.getYear();
  if (aYear % 4 == 0) DayInMonth[1] = 29;
  if (aDay > DayInMonth[aMonth-1]) {
    aDay -= DayInMonth[aMonth-1];
    aMonth += 1;
  }
  if (aDay > DayInMonth[aMonth-1]) {
    aDay -= DayInMonth[aMonth-1];
    aMonth += 1;
  }
  if (aMonth > 12) {
    aMonth -= 12;
    aYear += 1;
    doFIND('QuickSearch').AD3.selectedIndex=1;
  }
  dDay = nDate.getDate() + 35;
  dMonth = nDate.getMonth() + 1;
  dYear = nDate.getYear();
  if (dYear % 4 == 0) DayInMonth[1] = 29;
  if (dDay > DayInMonth[dMonth-1]) {
    dDay -= DayInMonth[dMonth-1];
    dMonth += 1;
  }
  if (dDay > DayInMonth[dMonth-1]) {
    dDay -= DayInMonth[dMonth-1];
    dMonth += 1;
  }
  if (dMonth > 12) {
    dMonth -= 12;
    dYear += 1;
    doFIND('QuickSearch').DD3.selectedIndex=1;
  }
  doFIND('QuickSearch').AD2.selectedIndex=aMonth-1;
  ChDt('AD');
  doFIND('QuickSearch').AD1.selectedIndex=aDay-1;
  doFIND('QuickSearch').DD2.selectedIndex=dMonth-1;
  ChDt('DD');
  doFIND('QuickSearch').DD1.selectedIndex=dDay-1;

}

function ChRm(name)
{
  var NumberRoom;
  if (name == 'sSR')
    NumberRoom = 3 - parseInt(doFIND('QuickSearch').item('sDR').options[doFIND('QuickSearch').item('sDR').selectedIndex].value, 10);
  else
    NumberRoom = 3 - parseInt(doFIND('QuickSearch').item('sSR').options[doFIND('QuickSearch').item('sSR').selectedIndex].value, 10);
  if (parseInt(doFIND('QuickSearch').item(name).options[doFIND('QuickSearch').item(name).selectedIndex].value, 10) > NumberRoom)
    doFIND('QuickSearch').item(name).options[NumberRoom].selected = true;
}

function ExcSbm()
{  var bPer = true;
  var ADate = new Date(doFIND('QuickSearch').AD3.options[doFIND('QuickSearch').AD3.selectedIndex].value,
    doFIND('QuickSearch').AD2.selectedIndex,
    doFIND('QuickSearch').AD1.options[doFIND('QuickSearch').AD1.selectedIndex].value);
  var DDate = new Date();
  var iSR = (doFIND('QuickSearch').NumberOfPersons.value==1?doFIND('QuickSearch').NumberOfRooms.value:0);
  var iDR = (doFIND('QuickSearch').NumberOfPersons.value>1?doFIND('QuickSearch').NumberOfRooms.value:0);
  var oStr = doFIND('QuickSearch').sCt.options[doFIND('QuickSearch').sCt.selectedIndex].value;
  var arPr = new Array();
  var iPer = 0;

  arPr = oStr.split(':');

  if ((doFIND('QuickSearch').sCn.selectedIndex == 0) && (arPr[0] == '0')) {
    alert('Country should be selected.');
    bPer = false;
  }
    if (bPer) {
      if (doFIND('QuickSearch').MoreCities.value.search(/[^a-zA-Z .''-]/)!=-1) {
        alert('Please fill the "destination city" field with English spelling of the city name only.');
        bPer = false;
      }
    }

  if (bPer) {
    iPer = Math.round((ADate.getTime() - DDate.getTime()) / 86400000);
    if (iPer < -1) {
      alert('Arrival date should be later than today.');
      bPer = false;
    }
  }
  if (bPer) {
    DDate = new Date(doFIND('QuickSearch').DD3.options[doFIND('QuickSearch').DD3.selectedIndex].value,
      doFIND('QuickSearch').DD2.selectedIndex,
      doFIND('QuickSearch').DD1.options[doFIND('QuickSearch').DD1.selectedIndex].value);
    iPer = Math.round((DDate.getTime() - ADate.getTime()) / 86400000);
    if (iPer < 1) {
      alert('Arrival date should be sooner than departure date.');
      bPer = false;
    }
    else if (iPer > 31) {
      alert('There are more than 30 days between arrival and departure.');
      bPer = false;
    }
  }

  if (bPer) {
    iPer = doFIND('QuickSearch').sCn.selectedIndex;
    if (iPer == 0) {
      for (iPer = 1; iPer < doFIND('QuickSearch').sCn.options.length; iPer++)
        if (arPr[0] == doFIND('QuickSearch').sCn.options[iPer].value)
          break;
    }
    oStr = doFIND('QuickSearch').sCn.options[iPer].value + ':' +
      doFIND('QuickSearch').sCn.options[iPer].text + ':';
    oStr += arPr[1] + ':';
    if (arPr[1] != '0')
      oStr += doFIND('QuickSearch').sCt.options[doFIND('QuickSearch').sCt.selectedIndex].text;
    oStr += ';' + ADate.getFullYear() + '-';
    iPer = ADate.getMonth() + 1;
    if (iPer < 10)
      oStr += '0';
    oStr += iPer + '-';
    iPer = ADate.getDate();
    if (iPer < 10)
      oStr += '0';
    oStr += iPer + ';' + DDate.getFullYear() + '-';
    iPer = DDate.getMonth() + 1;
    if (iPer < 10)
      oStr += '0';
    oStr += iPer + '-';
    iPer = DDate.getDate();
    if (iPer < 10)
      oStr += '0';
    oStr += iPer + ';' + iSR + ';' + iSR + ';' + iDR + ';' + String(2*parseInt(iDR,10)) + ';1;';

  }
  var frm1 = document.forms["QuickSearch"];
	//frm1["ControlForm:_CountryName"].value = doFIND('QuickSearch').sCn.options[doFIND('QuickSearch').sCn.selectedIndex].text;
	frm1["ControlForm:_ArrivalDate"].value = ADate.getFullYear()+'-'+(ADate.getMonth()+1)+'-'+ADate.getDate();
	frm1["ControlForm:_DepartureDate"].value = DDate.getFullYear()+'-'+(DDate.getMonth()+1)+'-'+DDate.getDate();
	frm1["ControlForm:_AmountOfRooms"].value = doFIND('QuickSearch').NumberOfRooms.value;
	frm1["ControlForm:_RoomType"].value = doFIND('QuickSearch').NumberOfPersons.value;
  if (bPer)
  {
    doFIND('QuickSearch').BP1.value = oStr + ";;5,4,3,2,1,0;;;";
    doFIND('QuickSearch').BP.value  = oStr + ";;5,4,3,2,1,0;;;";
//document.write(doFIND('QuickSearch').BP1.value);
    doFIND('QuickSearch').submit();
  }

}

//End Nick

function CityHelp()
{
var retval=showModalDialog('list_cities.asp?CountryID='+doFIND('QuickSearch').sCn.value, 'displayWindow', 'dialogWidth:320px;dialogHeight:500px;status:no;center:yes;help=no;minimize=no;maximize=no;');
if (String(retval)!="undefined") doFIND('QuickSearch').MoreCities.value = retval;
return false;
}

function SetDate(target,year,month,day)
{
if (target=="AD")
  {
                        eval (doFIND('QuickSearch').AD2.options[month].selected=true);
                        eval (doFIND('QuickSearch').AD3.options[year-2005].selected=true);
            ChDt('AD');
                        eval (doFIND('QuickSearch').AD1.options[day-1].selected=true);
  }
else
  {
                        eval (doFIND('QuickSearch').DD2.options[month].selected=true);
                        eval (doFIND('QuickSearch').DD3.options[year-2005].selected=true);
            ChDt('DD');
                        eval (doFIND('QuickSearch').DD1.options[day-1].selected=true);
  }
}

