


//locations
function  init_locations()
{
 var combo0 = document.getElementById('location_country'); 
 var combo1 = document.getElementById('location_city'); 

 //init countries
 combo0.options.length = countries.length + 1;
   
 //initial settings  
   combo0.options[0].value = '-1';
   combo0.options[0].text = comboInitString0; 
 var i;
 for(i=1;i<=countries.length;i++)
  {
   combo0.options[i].value = countries[i-1];
   combo0.options[i].text = countries[i-1]; 
  }
 
 
 //init city select
   combo1.options.length=1;
   combo1.options[0].value = '-1';
   combo1.options[0].text = comboInitString1; 
  

}

function update_select_city(countryVal)
//update city combo
{
    //please select selected
    if(countryVal!=-1)
    { 
    
     var combo1 = document.getElementById('location_city'); 
     //alert(countryVal);
     
     //use cities
     var str = cities[countryVal];
     
     //split
     var arr = new Array();
     arr = str.split(',');
     arr.sort();
     //set length
      combo1.options.length = arr.length; //city,code
      
     var i;
     var arrT = new Array();
     for(i=0;i<=arr.length-1;i++)
      {
       arrT = arr[i].split('@');
       if(arrT.length>1) combo1.options[i].value = arrT[1]; //city not clear use code 
       else combo1.options[i].value = arrT[0];
       combo1.options[i].text = arrT[0]; 
      }
     
    }
 
}


//load date picker
function init_date_pickers(dayshift0,dayshift1,monthshift1)
{
  document.getElementById('beg_d').selectedIndex=dayshift0-1;
  document.getElementById('beg_my').selectedIndex=0;
 
  document.getElementById('end_my').selectedIndex=monthshift1;
  if(monthshift1 >= 1) updateDays('end_d','end_my');
  document.getElementById('end_d').selectedIndex=dayshift1-1;
  
}

function updateDays(combo_days,combo_month)
{
  //selected month
  var month =  document.getElementById(combo_month);
  //selected month value
  var monthValueArr = new Array();
  var monthValueArr = month.value.split("-"); 
  
  var days = monthValueArr[0];
   
  var strMonth = monthValueArr[1];
  var strYear = monthValueArr[2];
  
  
  //update days  
  var element = document.getElementById(combo_days);
  element.options.length=days;
  var i;
  for(i=0;i<=days-1;i++) 
  {
   element.options[i].value=strMonth+' '+(i+1)+','+strYear;
   element.options[i].text=(i+1);
  }
}


function presetSecondCombo(element)
{
 if(element.name=='beg_my') 
 {
  document.getElementById('end_my').selectedIndex=element.selectedIndex;
  updateDays('end_d','end_my');
 } 
}

function setDMY(day)
//create date day contains month and year
{
 
 dateObject = new Date(day + ' 23:59:59');
 
 return dateObject;
}

function checkD(comboD0,comboD1)
//check dates
{
 var d = new Date();
  
 var ret = true;
 
 
 //alert(document.getElementById(comboD1)[document.getElementById(comboD1).selectedIndex].value);
 //return false;
 
 //set date object 
 d0 = setDMY(document.getElementById(comboD0)[document.getElementById(comboD0).selectedIndex].value);
 //set date object 
 d1 = setDMY(document.getElementById(comboD1)[document.getElementById(comboD1).selectedIndex].value);

 
 if(d0<d)
  {
   alert(errorAlertStartPast);
   ret = false;
  }
 
 if(ret)
  {
   if(d1<d)
    {
     alert(errorAlertEndPast);
     ret = false;
    }
  }
  
  if(ret)
   {
    if(d0>d1)
     {
      alert(errorAlertEndBeforeStart);
      ret = false;
     }
   } 
   
 return ret;
 
}


function checkForm()
//check before submit
{

 
 var ret = true; //return

 //check destinations
 cityElement = document.getElementById('location_city');
 
 if(cityElement.options[0].value == '-1')
  {
   alert(errorSelectCountry)
   ret = false;
  }
  
  
 document.entryForm.location.value = cityElement.options[cityElement.selectedIndex].value;  


//check dates
if(ret) ret = checkD('beg_d','end_d');
 

//set dates
if(ret) 
{
 document.entryForm.startDate.value=document.entryForm.beg_d.options[document.entryForm.beg_d.selectedIndex].value; 
 document.entryForm.endDate.value=document.entryForm.end_d.options[document.entryForm.end_d.selectedIndex].value;  
}  
  
return ret;
}



function goToCityPage(code,startD,endD)
{

 //alert(endD);
  
 document.entryForm.location.value=code;
 
 document.entryForm.startDate.value=startD;
 document.entryForm.endDate.value=endD;
 
 //alert(document.entryForm.endDate.value);
 
 document.entryForm.submit();
 
}


