
var vayamaCurrent;
var vayamaDiv;
var vayamaTxt;
var http_request = false;
function submitVayamaForm(){
	if (document.getElementById("OR") !=null) {
		if (document.getElementById("OR").value.length < 3) {
			document.getElementById("OR").focus();
			alert('Please enter a valid origin.');
			return false;
		}
	}
	if (document.getElementById("AR") !=null) {
		if (document.getElementById("AR").value.length < 3) {
			document.getElementById("AR").focus();
			alert('Please enter a valid destination.');
			return false;
		}
	}
	document.tripdetails.ITT.value='RT';
	document.tripdetails.cl.value='Y';
	document.tripdetails.ref.value='vayama';
	document.tripdetails.pdt.value='standard';
	var curdate = new Date();
	var year = curdate.getYear();
	if (year < 1900) { year+=1900; }
	var monthLeaving = document.tripdetails.dateLeavingMonth.options[document.tripdetails.dateLeavingMonth.selectedIndex].value;
	var dayLeaving = document.tripdetails.dateLeavingDay.options[document.tripdetails.dateLeavingDay.selectedIndex].value;
	var monthReturning = document.tripdetails.dateReturningMonth.options[document.tripdetails.dateReturningMonth.selectedIndex].value;
	var dayReturning = document.tripdetails.dateReturningDay.options[document.tripdetails.dateReturningDay.selectedIndex].value;
	var mydate1 = new Date();
	var yearLeaving = year;
	mydate1.setFullYear(yearLeaving,monthLeaving-1,dayLeaving);
	if(curdate>mydate1){
		yearLeaving=year+1;
		mydate1.setFullYear(yearLeaving,monthLeaving-1,dayLeaving);
	}
	var mydate2 = new Date();
	mydate2.setFullYear(year,monthReturning-1,dayReturning);
	var yearReturning=year;
	if(mydate2<mydate1){
		yearReturning=year+1;
	}
	document.tripdetails.DT1.value = dayLeaving+monthLeaving+yearLeaving;
	document.tripdetails.DT2.value = dayReturning+monthReturning+yearReturning;
}

function completer(inputControl, evt) {
  evt = evt ? evt : (event ? event : null);
  if (evt) {
    // Ignore keys that don't factor in to the text entry
    var key = evt.charCode ? evt.charCode : evt.keyCode;
    if (key < 32 || (key >= 33 && key <= 46) ||
     (key >= 112 && key <= 123))
      return;
    // Store away the current input
    vayamaCurrent = (inputControl.id).substring(0,2);
	if(inputControl.value.length>2) 
    	startup(inputControl.value);
  }
}

 

function vayamaCityChosen(div){
	document.getElementById(vayamaCurrent+"vis").value=document.getElementById(div).innerHTML;
	document.getElementById(vayamaCurrent).value=div; 
	document.getElementById("vayama"+vayamaCurrent).style.display="none";
	document.getElementById("vayama"+vayamaCurrent+"cover").style.display="none";
	if(onPage=="air") getSitematchPartnersAir(false);  //update the airline partners displayed list
	else if(onPage=="hotel") getSitematchPartnersHotel(false);  //update the hotel partners displayed list
	else if(onPage=="car") getSitematchPartnersCar(false);  //update the car partners displayed list
}
 

/* json */
function vayamaAirportListJSON(feed){
  txt='';
  if(feed.items.length==0) {txt='<em>No Matching City Found</em>'}
  else{
	  for (x=0; x<feed.items.length; x++) {
		 txt+="<div class='vayCity'><a href='javascript:void(0)' id='"+ feed.items[x].code +"' onclick=vayamaCityChosen('"+ feed.items[x].code +"');>"+ feed.items[x].name +"</a></div>";
	  }
  }
  var popupDiv = document.getElementById("vayama"+vayamaCurrent);
  popupDiv.style.display="";
  popupDiv.innerHTML=txt;
  var cov = document.getElementById("vayama"+vayamaCurrent+"cover");
  cov.style.display = "";
  cov.style.left = popupDiv.style.left;
  cov.style.top = popupDiv.style.top;
  cov.style.width = popupDiv.offsetWidth;
  cov.style.height = popupDiv.offsetHeight;  
  cov.style.visibility = "visible";	
}

function startup(query) {       
   var jsonDiv=document.getElementById("vayamaJSON");
   jsonDiv.innerHTML="";
   var newScript = document.createElement('script');
   newScript.type = 'text/javascript';
   newScript.src = 'http://www.vayama.com/jsp/bookingwidget/vayamaAirportListJSON.jsp?search='+query;
   jsonDiv.appendChild(newScript);  
}

