///this variable says, which elemement from form is active (focused)
var activeElement;

var blockDivDestroy = false;

function useDiv(text)
////uses div to show single line ('Searching...')
{

  var div = document.getElementById('sDiv');
  div.style.visibility='visible';
  div.style.fontFamily = 'Arial';
  ////this must be overwritten, when drawing the main div 
  div.style.padding = '2px 2px 2px 2px'; 
  
  div.style.fontSize = 10;
  setPos(window.activeElement,div);
  div.innerHTML=text;
  //iframe
  adjustiFrameSDiv();
}

		
	
function setCaretPosition(ctrl, pos)
/////set the cursor(caret) position - used after selecting any airport - IE doesn't put it at the end
{

	if(ctrl.setSelectionRange)
	{
		ctrl.focus();
		ctrl.setSelectionRange(pos,pos);
	}
	else if (ctrl.createTextRange) {
		var range = ctrl.createTextRange();
		range.collapse(true);
		range.moveEnd('character', pos);
		range.moveStart('character', pos);
		range.select();
	}
}


	
function mInterval()
///the main function for calling requests after pressing any key in text box
{
  ////Length of typed text
  var tLen = activeElement.value.length;
 //alert(ev.keyCode);
 //alert(tLen);
 
  if(tLen >= 3)///min 3 chars
  {
 
    useDiv('Vyhledávám...');///show message    
    if(typeof window.interval != 'undefined') window.clearTimeout(window.interval);
    window.interval = window.setTimeout("makeSuggest();",700); ///wait 700 ms        
 }///tlen
 else
  {
   ////destroy div - eg after deleting chars
   destroyDiv();
  }
 
}//function
	
	
//Gets the browser specific XmlHttpRequest Object
function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert("Sorry, you can't use the suggester, your browser is most probably too old..");
	}
}


//Our XmlHttpRequest object to get the auto suggest
var searchReq = getXmlHttpRequestObject();


//Called from keyup on the search textbox.
//Starts the AJAX request.
function makeSuggest() {
  	//alert('Character was ' + character);
  	 //var activeElement= window.activeElement;
  	//newCursor = el.nextSibling;
	if (searchReq.readyState == 4 || searchReq.readyState == 0) {
		var str = escape(activeElement.value);
		searchReq.open("POST", 'suggest.php', true);
	  searchReq.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  searchReq.setRequestHeader("charset","utf-8");
    searchReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    searchReq.setRequestHeader("Content-Length",str.length+7);
    searchReq.send('search=' + str);
    
		searchReq.onreadystatechange = handleSearchSuggest; 
		//searchReq.send(null);
	}		
	
}

//Called when the AJAX response is returned.
function handleSearchSuggest() {
	if (searchReq.readyState == 4) {
  	var str = searchReq.responseText;
	  
   destroyDiv();
  
   /////call filling the div
   flighthandler (str);
  
 } //state
}//function





//////////////////////////////////////
///these functions are for checking submit
///////


function checkDates(element0,element1)
///connection between dates
{
//alert(document.getElementById('dout').value);
  
  var selIndex0 = element0.selectedIndex;
  var date0=element0.options[selIndex0].value;
  
  var selIndex1 = element1.selectedIndex;
  var date1=element1.options[selIndex1].value;
  
 //alert(date0);
  
 
 var arrDate0 = new Array(date0.substr(0,2),date0.substr(2,2),date0.substr(4,4));
 var arrDate1 = new Array(date1.substr(0,2),date1.substr(2,2),date1.substr(4,4));
 
 
 var myDate0=new Date();
 myDate0.setFullYear(arrDate0[2],arrDate0[1],arrDate0[0]);
 
 var myDate1=new Date();
 myDate1.setFullYear(arrDate1[2],arrDate1[1],arrDate1[0]);
 
 var ret=false;
 if(myDate0<=myDate1)
    ret = true;
 else
   alert('Návrat před odletem?');
 return ret;

} 




function checkAirport(element,text)
{
 var ret = true;
 if(element.value == '' ) 
  { 
   alert('Prosím zadejte místo '+ text +'.');
   ret=false;
 }  
 
 return ret;
}


//////////////////////////////////////////////
///div draw functions
////////////////////////////
	
/**
Dynamic XMLHttp lookups based on Google Suggest XMLRPC code. See:

http://serversideguy.blogspot.com/2004/12/google-suggest-dissected.html
http://www.fastbugtrack.com/misc/google/ac.js
http://www.google.com/webhp?complete=1&hl=en

I stripped out a lot of the cool functionality (like variable timers and
highlighting parts of the search result). That was mainly to make this a little
easier to digest. Feel free to look at the JavaScript code that Chris Justus
reformatted (see the link above) and put back anything that's missing.

In version 1.2 support was added for capturing keypresses of arrow keys,
the enter key, and the tab key while the input field has focus.

You can use these scripts in any way you'd like, just don't pretend like
you wrote them yourself.

version 1.2
January 5, 2005
Julian Robichaux, http://www.nsftools.com
*/



var searchTextField;
var MAX_NUMBER_OF_ROWS = 6;
var DIV_BG_COLOR = 'white';
var DIV_HIGHLIGHT_COLOR = '#e6e6fa';
var sArr = []; 	////this is arr with suggestions

/**
The InitQueryCode function should be called by the <body onload> event, passing
at least the queryFieldName and lookupURLPrefix parameters, where:

queryFieldName = the name of the form field we're using for lookups
lookupURLPrefix = the URL we'll use to pass the query string back to the server,
                  which will be immediately proceeded by the query string

For example:
<body onload="InitQueryCode('lookupField', 'http://lookupserver/QueryHandler?q=')">

The above example will monitor the input box called "lookupField" on this page,
and when it changes the contents of the field will be passed to lookupserver like:
http://lookupserver/QueryHandler?q=fieldValue

The http://lookupserver/QueryHandler will be expected to return a text response
with a single line of text that calls the showQueryDiv function, in a format like:
showQueryDiv("smi", new Array("John Smith", "Mary Smith"), new Array("555-1212", "555-1234"));

*/


/**
This is a helper function that just adds results to our cache, to avoid
repeat lookups.
*/


/**
This is the function that monitors the searchTextField, and calls the lookup
functions when the searchTextField value changes.
*/



/**
Get the <DIV> we're using to display the lookup results, and create the
<DIV> if it doesn't already exist.
*/

function getIFrame(){
  
  var SearchBoxIFrame = document.getElementById('sDivIFrame');
  return SearchBoxIFrame;
}

function getDiv ()
{
  var SearchBoxDiv = document.getElementById('sDiv');
  return SearchBoxDiv;
}


/**
This is the function that should be returned by the XMLHTTP call. It will
format and display the lookup results.
*/
function flighthandler (result)
{
     searchTextField = window.activeElement;
     
      var token = escape(searchTextField.value);
      token = unescape(token);
      ////fill array   
      sArr = result.split("@");
    
     ////draw div
     displayDiv();    
}

/**
This is called whenever the user clicks one of the lookup results.
It puts the value of the result in the searchTextField and hides the
lookup div.
*/
function selectResult()
{
  _selectResult(this);
}


/** This actually fills the field with the selected result and hides the div */
function _selectResult(item)
{
  
     var spans = item.getElementsByTagName("td");
 
    if (spans) 
     {    
          var str = spans[0].innerHTML;
          
           
            str=str.replace(/[<][^>]*[>]/g,"");////< any char except> > globally = all tags
            ///alert(str); 
            ///set field
            searchTextField.value = str;
          
      }
     ///hide div
      showDiv(false);
       
     ////ie bug
     setCaretPosition(searchTextField,str.length);
    // alert('x');
     // searchTextField.focus();
  return false;
  
}
  
/**
This is called when a user mouses over a lookup result
*/
function highlightResult()
{
  _highlightResult(this);
  
}

/** This actually highlights the selected result */
function _highlightResult(item)
{
  item.style.backgroundColor = DIV_HIGHLIGHT_COLOR;
  var spans = item.getElementsByTagName("TD");
  
}


/**
This is called when a user mouses away from a lookup result
*/
function unhighlightResult()
{
  _unhighlightResult(this);
}

/** This actually unhighlights the selected result */
function _unhighlightResult(item)
{
  item.style.backgroundColor = DIV_BG_COLOR;
}


/**
This either shows or hides the lookup div, depending on the value of
the "show" parameter.
*/
function showDiv (show)
{
  var div = getDiv();
  if (show)
    {
     div.style.visibility = "visible";
    ///set coordinates
     setPos(window.activeElement,div);
    }
  else
    div.style.visibility = "hidden";
 
  adjustiFrameSDiv();
}


/**
We originally used showDiv as the function that was called by the onBlur
event of the field, but it turns out that Firefox will pass an event as the first
parameter of the function, which would cause the div to always be visible.
So onBlur now calls hideDiv instead.
*/
function hideDiv ()
{
  
  showDiv(false);
}


/**
Use an "iFrame shim" to deal with problems where the lookup div shows up behind
selection list elements, if they're below the searchTextField. The problem and solution are
described at:

http://dotnetjunkies.com/WebLog/jking/archive/2003/07/21/488.aspx
http://dotnetjunkies.com/WebLog/jking/archive/2003/10/30/2975.aspx
*/
function adjustiFrameSDiv()
{
    var iFrameDiv = getIFrame();
    var div = getDiv();
    
    var w = div.offsetWidth + 'px';
    var h = div.offsetHeight + 'px';
    iFrameDiv.style.visibility = div.style.visibility;
    iFrameDiv.style.position = "absolute";
    iFrameDiv.style.width = w ;// div.offsetWidth;
    iFrameDiv.style.height = h ; //div.offsetHeight;
    setPos(window.activeElement,iFrameDiv);
    
}




/**
Get the number of the result that's currently selected/highlighted
(the first result is 0, the second is 1, etc.)
*/
function getSelectedSpanNum (div)
{
  var count = -1;
  var tbl = document.getElementById('tblSug'); //get table first (there are possibly more than 1)
  var spans = tbl.getElementsByTagName("tr");
  if (spans) {
    for (var i = 0; i < spans.length; i++) {
      count++;
      if (spans[i].style.backgroundColor != div.style.backgroundColor)
        return count;
    }
  }
  
  return -1;
}


/**
Select/highlight the result at the given position
*/
function setSelectedSpan (div, spanNum)
{
  var count = -1;
  var thisSpan;
  
  
  var tbl = document.getElementById('tblSug'); //get table first
  var spans = tbl.getElementsByTagName("tr");
  if (spans) {
    for (var i = 0; i < spans.length; i++) {
      if (++count == spanNum) {
        _highlightResult(spans[i]);
        thisSpan = spans[i];
      } else {
        _unhighlightResult(spans[i]);
      }
    }
  }
  
  return thisSpan;
}


/**
Select/highlight the result at the given position
*/
function getSelectedSpan (div)
{
      var count = -1;
       var tbl = document.getElementById('tblSug'); //get table first
  var spans = tbl.getElementsByTagName("tr");
      if (spans) {
        for (var i = 0; i < spans.length; i++) {
          count++;
          if (spans[i].style.backgroundColor != div.style.backgroundColor)
            return spans[i];
        }
      }
      
      return null;
}

////////////////////////////////////////////////////////

 function displayDiv()
 ///calls drawing function
 {
 
  ////show arr items from 0
  drawDiv(0);
  
 }
 
function drawDiv(index0)
//creates the div
{
  ///segment is a chunk of items in array with suggestions
  
   //alert(index0);
 
    ///here we calculate the index1 - index of last element of segment 
    var index1;
    if((index0 + MAX_NUMBER_OF_ROWS)< sArr.length) index1 = index0 + MAX_NUMBER_OF_ROWS -1; ///not last segment
    else index1=sArr.length-1; ///last segment
   
  
   ////here we determine, in which part of array we are
   ///arr len
   var count;
   var showShifts = true; ////show shifts? (hrefs at the bottom)
  
   if(index0 == 0) /// first segment
    {
      if(index1==sArr.length-1) ///only one segment - dont show shifts
       {
        nextIndex = -1;
        showShifts =  false;
       }
      else ///more than one segment
       {
        nextIndex = index1+1;
       } 
     prevIndex = -1;//no segments before    
     count = index1 + 1;///count - how many rows to draw 
    }
   else
    {   /////not first segment
       if(index1 == sArr.length - 1) ///last segment  
       {
         count=sArr.length - index0;  
         nextIndex = -1;
       }
       else 
       {
        count = MAX_NUMBER_OF_ROWS; ////in segment
        nextIndex = index1+1;
       }
      
      prevIndex = index0 - MAX_NUMBER_OF_ROWS ;//first index of segment before    
  
    }//else       
   
   
   ///////////////////////////   
   ///now list suggestions 
    var div = getDiv();
   
    while (div.childNodes.length > 0) div.removeChild(div.childNodes[0]); //initiate
    
    ///fill div
    var tblResult = document.createElement("table"); ///create table
      tblResult.setAttribute("id","tblSug");
    tblResult.className='sDivTable';
    var tBodyResult = document.createElement("tbody");
    
   /////create rows with suggestion strings
    for(i=index0;i<=index0 + count - 1;i++)
    {
     tblResult = addTableRow(sArr[i],tBodyResult,tblResult);
    }
      div.appendChild(tblResult);   ///append
    
    if(showShifts)/////show bottom hrefs if needed
    {
     
      ///addd special row with shifts   
       tblShift = addShift(prevIndex,nextIndex);   
       div.appendChild(tblShift);    
    }
       
      div.style.padding = '0px 0px 0px 0px';  ////back to zeros again was set, when 'searching'
   
     ///display div
      showDiv(true);
} 
 
 
function addTableRow(value,tBodyResult,tblResult)
////adds row of a table
{

    var result = document.createElement( "tr");
    // result.className = "ResultRowSpan";
    result.style.cursor = "pointer";
    result.style.padding = "0px 0px 0px 0px";
    result.style.backgroundColor = "white";
    result.style.fontFamily = 'Arial';
    result.style.fontSize = 10;
    
    //_unhighlightResult(result);
    result.onmouseup = selectResult;
    result.onmouseover = highlightResult;
    result.onmouseout = unhighlightResult;
   
    //table cell
    var resAirportCity = document.createElement("td");
    resAirportCity.setAttribute("nowrap","true");
    //resAirportCity.className = "ResultSpanCity";
    resAirportCity.innerHTML = value;
    result.appendChild(resAirportCity);

    tBodyResult.appendChild(result);
    tblResult.appendChild(tBodyResult);
 
  return tblResult;

}

function addShift(prevIndex,nextIndex)
///adds table with hrefs
{
   ////prepare value
   var value0 = '';
   var value1 = '';
   
   ////text of first href  
   if(prevIndex!=-1) value0 = '<a class=shifts href=\"javascript:drawDiv(prevIndex);\"><< předchozí '+ MAX_NUMBER_OF_ROWS +'</a>&nbsp;&nbsp;';
   
   ///the last group might be smaller
   var groupSize;
   var str;
   if((sArr.length - nextIndex) < MAX_NUMBER_OF_ROWS) 
   {
    str = 'poslední'; ///we show 'last'
    groupSize = sArr.length - nextIndex; ///how many elements
   }
   else 
   {
    str = 'další'; ///normally 'next'
    groupSize = MAX_NUMBER_OF_ROWS;
   }
   ///text of second href
   if(nextIndex!=-1) value1 = '<a class=shifts href=\"javascript:drawDiv(nextIndex);\">'+ str + ' ' + groupSize +' >></a>';
   
   
     ////create table
       var tblResult = document.createElement("table"); ///create table
       tblResult.className='sDivTable';///class
       var tBodyResult = document.createElement("tbody");
   ///create row
    var result = document.createElement( "tr");
   // result.className = "ResultRowSpan";
    result.style.padding = "0px 0px 0px 0px";
    result.style.backgroundColor = "white";
    result.style.fontFamily = 'Arial';
    result.style.fontSize = 10;
    
    //table two cells
    var shiftCell = document.createElement("td");
    shiftCell.setAttribute("nowrap","true");
    shiftCell.innerHTML = value0;
    result.appendChild(shiftCell);
    
    var shiftCell = document.createElement("td");

    shiftCell.setAttribute("nowrap","true");
    shiftCell.innerHTML = value1;
    result.appendChild(shiftCell);
    
    tBodyResult.appendChild(result);
    tblResult.appendChild(tBodyResult);
 
  return tblResult;

}

/**
This is the key handler function, for when a user presses the up arrow,
down arrow, tab key, or enter key from the input field.
*/
function keypressHandler (evt)
{

  // don't do anything if the div is hidden
  var div = getDiv();
  
  var NoOfRows=0;
  var spans = div.getElementsByTagName("tr");
   if (spans) {
      
       //alert(spans);
       if(spans.length > 1 ) //the tables were generated
        {
         var tbl = document.getElementById('tblSug'); //get table first
         var spans = tbl.getElementsByTagName("tr");
        }
      
        NoOfRows = spans.length;
   }
  

  // make sure we have a valid event variable
  if(!evt && window.event) {
    evt = window.event;
  }
  var key = evt.keyCode;
  
  ///alert(evt.keyCode);
  // if this key isn't one of the ones we care about, just return
  var KEYUP = 38;
  var KEYDOWN = 40;
  var KEYENTER = 13;
 // var KEYTAB = 9;
  
  var KEYESC = 27;
  var KEYLEFT = 37;
  var KEYRIGHT = 39;
  
  
  if ((key != KEYUP) && (key != KEYDOWN) && (key != KEYENTER))  
   {
    if((key != KEYLEFT) && (key != KEYRIGHT) && (key != KEYESC)) mInterval();///anything
    else destroyDiv(); ///destroy div
  }
   else
  {
  // get the span that's currently selected, and perform an appropriate action
  var selNum = getSelectedSpanNum(div);
  var selSpan = null;
  selSpan = getSelectedSpan(div);
  
    if (key == KEYENTER) {
   
        if (selSpan)
        _selectResult(selSpan);
         evt.cancelBubble=true;
        return false;
    } 
    else 
    {
        if (key == KEYUP){
            if(selNum == -1 && NoOfRows > 0 )
            {
            selNum = NoOfRows;
            }
            selSpan = setSelectedSpan(div, selNum - 1);
        }
        if (key == KEYDOWN)
            selSpan = setSelectedSpan(div, selNum + 1);
        
    }//else
  }///else
  
  //showDiv(true);
  return true;
}

function setActiveElement(element)
/////set which textbox is active
{
 
 window.activeElement = element;

}	



function destroyDiv()
////destroy suggest div and iFrame
{
 var div = document.getElementById('sDiv');
 var iFrame = document.getElementById('sDivIFrame');
 
   div.style.visibility='hidden';
   iFrame.style.visibility='hidden';
  
}

function refreshRet()
////check, if selected return / ow flight
{

//alert(element.id);
  var element = document.getElementById('retQow');
  if(element.checked)
  {
    document.getElementById('dd_ret').disabled = true;
    document.getElementById('mmyyyy_ret').disabled = true;
    //document.getElementById('flex1').disabled = true;
   }
   else
   {
    document.getElementById('dd_ret').disabled = false;
     document.getElementById('mmyyyy_ret').disabled = false;
    //document.getElementById('flex1').disabled = false;
  }
}

function checkSubmit()
///check all elements before submiting
{
 
 

     el0 = document.getElementById('orig0');
     el1 = document.getElementById('orig1');
     el2 = document.getElementById('dest0');
     el3 = document.getElementById('dest1');
     
    
  
  if((el0.selectedIndex!=0)&&(el1.selectedIndex!=0))
   document.frm1.origF.value =  el1.options[el1.selectedIndex].text + ', ' + el0.options[el0.selectedIndex].text;
  else 
   document.frm1.origF.value ='';

  
  if((el2.selectedIndex!=0)&&(el3.selectedIndex!=0)) 
   document.frm1.destF.value =  el3.options[el3.selectedIndex].text + ', ' + el2.options[el2.selectedIndex].text;
  else 
   document.frm1.destF.value = '';

   
  if (checkAirport(document.getElementById('origF'),'odletu'))
  {
    if (checkAirport(document.getElementById('destF'),'příletu'))    
          document.frm1.submit();   
  }
  
}///func


function load()
///load all stuff
{

 fillComboMmYyyy(document.getElementById('mmyyyy_out'));
 fillComboDd(document.getElementById('dd_out'),document.getElementById('mmyyyy_out'));
 
 fillComboMmYyyy(document.getElementById('mmyyyy_ret'));
 fillComboDd(document.getElementById('dd_ret'),document.getElementById('mmyyyy_ret'));
 ///say if disabled
 refreshRet(document.getElementById('retQ'));
 

 //document.getElementById('orig').focus();
}


function showLCI()
//show low cost interface
{
 var tbl = document.getElementById('dsel_tab');
    
    var body = tbl.getElementsByTagName("tbody");///because iE!
    
    var rows = tbl.getElementsByTagName("tr");
    
     var cells = rows[1].getElementsByTagName("td");
     cells[0].innerHTML = '<select class="genSel" style="width:175px;" name=\"orig0\" id=\"orig0\" onChange="updateForm(this);"><option value=\'\'>-- Vyberte --</select>&nbsp;<select class="genSel" style="width:175px;" name=\"orig1\" id=\"orig1\" onChange="updateForm(this);"><option value=\'\'>-- Vyberte zemi odletu --</select>';
     
     var cells = rows[3].getElementsByTagName("td");
     cells[0].innerHTML = '<select class="genSel" style="width:175px;" name=\"dest0\" id=\"dest0\" onChange="updateForm(this);"><option value=\'\'>-- Vyberte místo odletu --</select>&nbsp;<select class="genSel" style="width:175px;" name=\"dest1\" id=\"dest1\"><option value=\'\'>-- Vyberte zemi příletu --</select>';

callComboFill('','','');//init


 //updateForm(document.getElementById('orig0'));

//alert($("#orig0").options);//.selected=true;
}

function showUNI(receivedOrig,receivedDest)
//show universal interface
{

 var tbl = document.getElementById('dsel_tab');
    
    var body = tbl.getElementsByTagName("tbody");///because iE!
    
    var rows = tbl.getElementsByTagName("tr");
    
     var cells = rows[1].getElementsByTagName("td");
     cells[0].innerHTML = '<input class="text_form" type="text" maxlength=200 id="orig" name="orig" alt="origin" onkeyup="keypressHandler(event);" onfocus="setActiveElement(this);" onBlur="if(!window.blockDivDestroy) destroyDiv();" autocomplete="off" value="'+ receivedOrig +'">';
     
     var cells = rows[3].getElementsByTagName("td");
     
     cells[0].innerHTML = '<input class="text_form"  type="text" maxlength=200 id="dest" name="dest" alt="destination" onkeyup="keypressHandler(event);" onfocus="setActiveElement(this);" onBlur="if(!window.blockDivDestroy) destroyDiv();" autocomplete="off" value="'+ receivedDest +'">';


}

//Our XmlHttpRequest object to get the auto suggest
var comboReq = getXmlHttpRequestObject();

function callComboFill(c0,c1,c2) {
//alert('');
 	if (comboReq.readyState == 4 || comboReq.readyState == 0) {
		
    comboReq.open("GET", 'combo_fill.php?c0='+ c0 +'&c1='+ c1 +'&c2='+ c2 +'', true);
		comboReq.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );//ie cache
		comboReq.onreadystatechange = handleComboFill; 
		comboReq.send(null);
    
		//searchReq.send(null);
	}		
	
}

function handleComboFill()
{
 if (comboReq.readyState == 4) {
  	var str = comboReq.responseText;
  	var i;
  	var arr = new Array();
  	
  	str = str.replace('\r\n','');
  	
  	arr = str.split('@');
  	//alert(arr[0]);
  	el = document.getElementById(arr[0]);
  	el.options.length=arr.length;
  	el.options[0].value='';
  	el.options[0].text='-- Vyberte --';
    
  	for(i=1;i<=arr.length-1;i++)
  	 {
  	  var values = arr[i].split('#'); 
      el.options[i].value=values[0];
      el.options[i].text=values[1];
      if((arr[0]=='orig0')&&(values[0]=='Czech Republic')) el.options[i].selected=true;
      if((arr[0]=='orig1')&&(values[0]=='Prague (PRG)')) el.options[i].selected=true;
      
     }
    
    //initial setup
    if(arr[0]=='orig0') updateForm(document.getElementById('orig0'));
    if(arr[0]=='orig1') updateForm(document.getElementById('orig1'));
  } //state
  
 
}


function updateForm(element)
//update combo
{
 el0 = document.getElementById('orig0');
 el1 = document.getElementById('orig1');
 el2 = document.getElementById('dest0');
 
 //alert(element.id);
 if(element.id=='orig0')
  {
   //alert('');
    callComboFill(el0.options[el0.selectedIndex].value,'','');
  }
 else
  {
   if(element.id=='orig1')
     callComboFill(el0.options[el0.selectedIndex].value,el1.options[el1.selectedIndex].value,'');
   else
    callComboFill(el0.options[el0.selectedIndex].value,el1.options[el1.selectedIndex].value,el2.options[el2.selectedIndex].value);
  }
  
   callComboFill(el0.options[el0.selectedIndex].value,el1.options[el1.selectedIndex].value,el2.options[el2.selectedIndex].value);
   
}



