﻿// JScript source code

function updateOldCalendarFields() {
    var elemDepDate  = document.getElementById('txtDepDate');
    var elemDepDay   = document.getElementById('dateDep_date');
    var elemDepMonth = document.getElementById('dateDep_month');
    var elemDepYear  = document.getElementById('dateDep_year');

    var elemRetDate  = document.getElementById('txtRetDate');
    var elemRetDay   = document.getElementById('dateRet_date');
    var elemRetMonth = document.getElementById('dateRet_month');
    var elemRetYear  = document.getElementById('dateRet_year');

    var tmpDepDate   = elemDepDate.value.split("/");
    var depDay   = tmpDepDate[0];
    var depMonth = tmpDepDate[1];
    var depYear  = tmpDepDate[2];

    var tmpRetDate   = elemRetDate.value.split("/");
    var retDay   = tmpRetDate[0];
    var retMonth = tmpRetDate[1];
    var retYear  = tmpRetDate[2];

    elemDepDay.selectedIndex   = parseInt(depDay,10) - 1;
    elemDepMonth.selectedIndex = parseInt(depMonth,10) - 1;
    elemDepYear.selectedIndex  = parseInt(depYear,10) - 1997 -1;

    elemRetDay.selectedIndex   = parseInt(retDay,10) - 1;
    elemRetMonth.selectedIndex = parseInt(retMonth,10) - 1;
    elemRetYear.selectedIndex  = parseInt(retYear,10) - 1997 -1;

}

//OnmouseOver change the color
function OnMouseOverLink(obj)
{
    obj.style.cursor="pointer";
}

//Onmouseout reset the initial color
function OnMouseOutLink(obj)
{
	obj.style.cursor="arrow";
}


//OnmouseOver change the color
function OnMouseOverLinkImage(obj)
{
    obj.style.cursor="hand";
    obj.style.cursor="pointer";
}

//Onmouseout reset the initial color
function OnMouseOutLinkImage(obj)
{
	obj.style.cursor="arrow";
}

//Opens popup window with airport list
function OpenAirportPopoupWindow(type, lang)
{
	if (type=="from")
		window.open("AirportsList.aspx?type=from&lang="+lang,null,"width=712,height=600,status=no,toolbar=no,scrollbars=yes");
	else if (type=="to")	
		window.open("AirportsList.aspx?type=to&lang="+lang,null,"width=712,height=600,status=no,toolbar=no,scrollbars=yes");
}

//Opens popup window for multiple airorts for a City
function OpenMultipleAirportPopupWindow(type,multipleAirportArr)
{
	if (type=="from")
		window.open("MultipleAirports.aspx?multipleAirportArr="+multipleAirportArr+"",null,"width=650,height=600,status=no,toolbar=no,scrollbars=yes");
	else if (type=="to"){
		window.open("MultipleToAirports.aspx?multipleAirportArr="+multipleAirportArr+"",null,"width=650,height=600,status=no,toolbar=no,scrollbars=yes");
	}
}


//Fill in the textbox for airport
function FillTheAirportForm(obj,type){
    //parent.window.document.getElementById('from').value=obj.parentNode.id;
    //parent.window.document.getElementById(type).value="TESTTESTTEST";//obj.parentNode.textContent;
	//parent.tb_remove();
}

function FillTheAirportFormBox(airport,boxId) {
    parent.window.document.getElementById(boxId).value=airport;
	parent.tb_remove();
}

function FillTheAirportFormBoxNew(airport, boxId) {
    parent.window.document.getElementById(boxId).focus();
    parent.window.document.getElementById(boxId).value = airport;
	parent.$.fn.colorbox.close();
}

//Updates the Departure Date
function UpdateDepDate(){
	var year=window.document.getElementById("dateDep_year").value;
	var month=window.document.getElementById("dateDep_month").value;
	if ((month/1)<10)
		month="0"+month;
	var day=window.document.getElementById("dateDep_date").value;

	window.document.getElementById("completeDepDate").value=year+"-"+month+"-"+day;
}

//Updates the Return Date
function UpdateRetDate(){
	
		var year=window.document.getElementById("dateRet_year").value;
		var month=window.document.getElementById("dateRet_month").value;
		if ((month/1)<10)
		month="0"+month;
		var day=window.document.getElementById("dateRet_date").value;
	if (!(window.document.getElementById("flighttype_1").checked)){
		window.document.getElementById("completeRetDate").value=year+"-"+month+"-"+day;
		}
	else{
		window.document.getElementById("completeRetDate").value="2099-"+month+"-"+day;
		}
}

//Counts the total number of passengers
function CheckNumberOfPassengers(){
	adults=window.document.getElementById("adults").value;
	children=window.document.getElementById("children").value;
	infants=window.document.getElementById("infants").value;
	totalPassengers=adults-(-children)-(-infants);
	window.document.getElementById("totalPassengers").value=totalPassengers;
}

//Returns the Current Date
function GetDate(){
	date=new Date();
	day=date.getDate();
	//alert(day);
	month=date.getMonth()+1;
	year=date.getFullYear();
	dateStr=year+"-"+month+"-"+day;
	window.document.getElementById("currentDate").value=dateStr;
}

//Update Departure Year according to the selected month
function UpdateDepYear(){
	
	var day=window.document.getElementById("dateDep_date").value;
	var month=window.document.getElementById("dateDep_month").value;	
	var year=window.document.getElementById("dateDep_year").value;
	var cDate=window.document.getElementById("currentDate").value;
	var cMonth=cDate.split("-")[1];
	var cYear=cDate.split("-")[0];
	var cDay=cDate.split("-")[2];
	nextYear=cDate.split("-")[0]-(-1);
	if ((month/1)<(cMonth/1))
		year=nextYear;
	else if ((month/1)==(cMonth/1) && (day/1)<(cDay/1))
		year=nextYear;
	else
		year=cYear;
	window.document.getElementById("dateDep_year").value=year;
}

//Update Return Year according to the selected month
function UpdateRetYear(){
	var day=window.document.getElementById("dateRet_date").value;
	var month=window.document.getElementById("dateRet_month").value;
	var year=window.document.getElementById("dateRet_year").value;
	var cDate=window.document.getElementById("currentDate").value;
	var	cMonth=cDate.split("-")[1];
	var	cYear=cDate.split("-")[0];
	var	cDay=cDate.split("-")[2];
	nextYear=cDate.split("-")[0]-(-1);
	if ((month/1)<(cMonth/1))
		year=nextYear;
	else if ((month/1)==(cMonth/1) && (day/1)<(cDay/1))
		year=nextYear;
	else
		year=cYear;
	window.document.getElementById("dateRet_year").value=year;
}

//Get the value of Departure City
function UpdateDepCity(){
	from=window.document.getElementById("from").value.toLowerCase();
	index=from.indexOf("[");
	if (index<0)
		city=from;
	else
		city=from.substring(0,index);
	window.document.getElementById("depCity").value=trim(city);
}

//Get the value of Return City
function UpdateRetCity(){
	to=window.document.getElementById("to").value.toLowerCase();
	index=to.indexOf("[");
	if (index<0)
		city=to;
	else
		city=to.substring(0,index);
	window.document.getElementById("retCity").value=trim(city);
}

//Get the value of Departure Airport
function UpdateDepAirport(){
	from=window.document.getElementById("from").value.toLowerCase();
	index=from.indexOf("[");
	if (index<0)
		airport=from;
	else
		airport=((from.split("["))[1]).substring(0,(from.split("[")[1]).indexOf("]"));	
	window.document.getElementById("depAirport").value=trim(airport);
}

//Get the value of Return Airport
function UpdateRetAirport(){
	to=window.document.getElementById("to").value.toLowerCase();
	index=to.indexOf("[");
	if (index<0 )
		airport=to;
	else
		airport=((to.split("["))[1]).substring(0,(to.split("[")[1]).indexOf("]"));	
	window.document.getElementById("retAirport").value=trim(airport);
}

//Trims a string
function trim(string){
	if (string!=''){
		while (string.charAt(0)==' ')
			string=string.substring(1,string.length);
		while (string.charAt(string.length-1)==' ')
			string=string.substring(0,(string.length-1));
	}
	return string;
}

//Compares from and to airports
function CompareAirports(){
	from=(window.document.getElementById("from").value).toLowerCase();
	to=(window.document.getElementById("to").value).toLowerCase();
	fromAirport=(window.document.getElementById("depAirport").value).toLowerCase();
	toAirport=(window.document.getElementById("retAirport").value).toLowerCase();
	fromCity=(window.document.getElementById("depCity").value).toLowerCase();
	toCity=(window.document.getElementById("retCity").value).toLowerCase();
	
	if ((fromCity==toCity || fromAirport==toAirport || from==to) &&  (fromCity!="" || fromAirport!=""))
		window.document.getElementById("sameAirports").value=1;
	else
		window.document.getElementById("sameAirports").value=0;
}

//Splits a Server Side String to get a client side array
function GetClientSideArray(arrayString){
	csArray= new Array();
	csArray=arrayString.split("!$");
	return csArray;
}

//Splits a Server Side String to get a client side array
function GetClientSideArraySplitBySymbol(arrayString, symbol){
	csArray= new Array();
	csArray=arrayString.split(symbol);
	return csArray;
}



//Returns an array of distinc EndDateTime items
function GetDistinctEndDateTimeItems(endTimeAr,endDateAr){
	diEndTimeArray=new Array();
	diEndDateArray=new Array();
	diEndTimeArray[0]=endTimeAr[0];
	diEndDateArray[0]=endDateAr[0];
	diEndDateTimeArray=new Array();
	diEndDateTimeArray[0]=endTimeAr[0]+"!$"+endDateAr[0];
		
	index=0;
	for (i=1;i<endTimeAr.length;i++){
		isAlreadyIn=false;
		j=0;
		while (j<(index+1) && isAlreadyIn==false){
			if (endTimeAr[i]==diEndTimeArray[j] && endDateAr[i]==diEndDateArray[j] )
				isAlreadyIn=true;
			j++;
		}
		if (isAlreadyIn==false){
			index=index+1;
			diEndTimeArray[index]=endTimeAr[i];
			diEndDateArray[index]=endDateAr[i];
			diEndDateTimeArray[index]=diEndTimeArray[index]+"!$"+diEndDateArray[index];
		}	
	}
	return diEndDateTimeArray;
}


//Sorts the array of distinct EndTime items
function SortEndDateDistinctItems(endTimeAr,endDateAr){
	diEndDateTimeArray=GetDistinctEndDateTimeItems(endTimeAr,endDateAr);
	for (j=0;j<diEndDateTimeArray.length;j++){
		diEndTimeArray[j]=diEndDateTimeArray[j].split("!$")[0];
		diEndDateArray[j]=diEndDateTimeArray[j].split("!$")[1];
	}
	siArray=new Array();
	for (i=0;i<diEndTimeArray.length;i++){
		index=0;
		for (j=0;j<diEndTimeArray.length;j++){
			if (diEndDateArray[i]>diEndDateArray[j]){
				index=index+1;
			}
			else if (diEndDateArray[i]==diEndDateArray[j]){
				if (diEndTimeArray[i]>diEndTimeArray[j]){
					index=index+1;
				}
			}
		}
	siArray[index]=diEndTimeArray[i];
	}
	return siArray;
}


//Returns the Result  Sorted according to EndTime
function GetSortedItemsByEndTime(siArray,airlinesDep,price,startTimeDep,endTimeDep,stopsDep, durationDep,startDateDep,endDateDep,startAirportDep,endAirportDep,flightNumberDep,airlineCodeDep,connectionAirportDep,indexAl,ticketType,serviceCharge,airlinesRet,startTimeRet,endTimeRet,stopsRet, durationRet,startDateRet,endDateRet,startAirportRet,endAirportRet,flightNumberRet,airlineCodeRet,connectionAirportRet){   
	sortedAr=new Array();
	index=0;
	for (i=0;i<siArray.length;i++){
		for (j=0;j<endTimeDep.length;j++){
			if (endTimeDep[j]==siArray[i]){
				if (airlinesRet!="undefined" && airlinesRet!=null && airlinesRet!="")
					sortedAr[index]=airlinesDep[j]+"!$"+price[j]+"!$"+startTimeDep[j]+"!$"+endTimeDep[j]+"!$"+stopsDep[j]+"!$"+durationDep[j]+"!$"+startDateDep[j]+"!$"+endDateDep[j]+"!$"+startAirportDep[j]+"!$"+endAirportDep[j]+"!$"+flightNumberDep[j]+"!$"+airlineCodeDep[j]+"!$"+connectionAirportDep[j]+"!$"+indexAl[j]+"!$"+ticketType[j]+"!$"+serviceCharge[j]+"!$"+airlinesRet[j]+"!$"+startTimeRet[j]+"!$"+endTimeRet[j]+"!$"+stopsRet[j]+"!$"+durationRet[j]+"!$"+startDateRet[j]+"!$"+endDateRet[j]+"!$"+startAirportRet[j]+"!$"+endAirportRet[j]+"!$"+flightNumberRet[j]+"!$"+airlineCodeRet[j]+"!$"+connectionAirportRet[j];
				else
					sortedAr[index]=airlinesDep[j]+"!$"+price[j]+"!$"+startTimeDep[j]+"!$"+endTimeDep[j]+"!$"+stopsDep[j]+"!$"+durationDep[j]+"!$"+startDateDep[j]+"!$"+endDateDep[j]+"!$"+startAirportDep[j]+"!$"+endAirportDep[j]+"!$"+flightNumberDep[j]+"!$"+airlineCodeDep[j]+"!$"+connectionAirportDep[j]+"!$"+indexAl[j]+"!$"+ticketType[j]+"!$"+serviceCharge[j];
				index=index+1;
			}
		}	
	}
	return sortedAr;
}



//Returns an array of distinct items
function GetDistinctArrayItems(arrayOfItems){
	diArray=new Array();
	diArray[0]=arrayOfItems[0];
	index=0;
	for (i=1;i<arrayOfItems.length;i++){
		isAlreadyIn=false;
		j=0;
		while (j<(index+1) && isAlreadyIn==false){
			if (arrayOfItems[i]==diArray[j])
				isAlreadyIn=true;
			j++;
		}
		if (isAlreadyIn==false){
			index=index+1;
			diArray[index]=arrayOfItems[i];
		}	
	}
	return diArray;
}

//Sorts the array of distinct items
function SortArrayOfDistinctItems(arrayOfItems){
	diArray=GetDistinctArrayItems(arrayOfItems);
	siArray=new Array();
	for (i=0;i<diArray.length;i++){
		index=0;
		for (j=0;j<diArray.length;j++){
			if (diArray[i]>diArray[j]){
				index=index+1;
			}
		}
	siArray[index]=diArray[i];
	}
	return siArray;
}

//Returns the Result Array Sorted according to the first argument 
function GetSortedItems(arrayOfItems,siArray,airlinesDep,price,startTimeDep,endTimeDep,stopsDep, durationDep,startDateDep,endDateDep,startAirportDep,endAirportDep,flightNumberDep,airlineCodeDep,connectionAirportDep,indexAl,ticketType,serviceCharge,airlinesRet,startTimeRet,endTimeRet,stopsRet, durationRet,startDateRet,endDateRet,startAirportRet,endAirportRet,flightNumberRet,airlineCodeRet,connectionAirportRet){   
	sortedAr=new Array();
	index=0;
	for (i=0;i<siArray.length;i++){
		for (j=0;j<arrayOfItems.length;j++){
			if (arrayOfItems[j]==siArray[i]){
				if (airlinesRet!="undefined" && airlinesRet!=null && airlinesRet!="")
					sortedAr[index]=airlinesDep[j]+"!$"+price[j]+"!$"+startTimeDep[j]+"!$"+endTimeDep[j]+"!$"+stopsDep[j]+"!$"+durationDep[j]+"!$"+startDateDep[j]+"!$"+endDateDep[j]+"!$"+startAirportDep[j]+"!$"+endAirportDep[j]+"!$"+flightNumberDep[j]+"!$"+airlineCodeDep[j]+"!$"+connectionAirportDep[j]+"!$"+indexAl[j]+"!$"+ticketType[j]+"!$"+serviceCharge[j]+"!$"+airlinesRet[j]+"!$"+startTimeRet[j]+"!$"+endTimeRet[j]+"!$"+stopsRet[j]+"!$"+durationRet[j]+"!$"+startDateRet[j]+"!$"+endDateRet[j]+"!$"+startAirportRet[j]+"!$"+endAirportRet[j]+"!$"+flightNumberRet[j]+"!$"+airlineCodeRet[j]+"!$"+connectionAirportRet[j];
				else
					sortedAr[index]=airlinesDep[j]+"!$"+price[j]+"!$"+startTimeDep[j]+"!$"+endTimeDep[j]+"!$"+stopsDep[j]+"!$"+durationDep[j]+"!$"+startDateDep[j]+"!$"+endDateDep[j]+"!$"+startAirportDep[j]+"!$"+endAirportDep[j]+"!$"+flightNumberDep[j]+"!$"+airlineCodeDep[j]+"!$"+connectionAirportDep[j]+"!$"+indexAl[j]+"!$"+ticketType[j]+"!$"+serviceCharge[j];
				index=index+1;
			}
		}	
	}
	return sortedAr;
}


//Display the preffered sort type
function ChangeSortType(){
	window.document.getElementById("sortByAirline").style.display='none';
	window.document.getElementById("sortByPrice").style.display='none';
	window.document.getElementById("sortByStartTime").style.display='none';
	window.document.getElementById("sortByEndTime").style.display='none';
	window.document.getElementById("sortByStops").style.display='none';
	window.document.getElementById("sortByDuration").style.display='none';
	sType=window.document.getElementById("selectedSortTypeToDisplay").value;
	if (sType=="airline")
		window.document.getElementById("sortByAirline").style.display='block';
	else if (sType=="price")
		window.document.getElementById("sortByPrice").style.display='block';
	else if (sType=="startTime")
		window.document.getElementById("sortByStartTime").style.display='block';
	else if (sType=="endTime")
		window.document.getElementById("sortByEndTime").style.display='block';
	else if (sType=="stops")
		window.document.getElementById("sortByStops").style.display='block';
	else if (sType=="duration")
		window.document.getElementById("sortByDuration").style.display='block';			
}

//Hides the Results Tables
function HideSortedTables(){
	window.document.getElementById("sortByAirline").style.display='none';
	window.document.getElementById("sortByStartTime").style.display='none';
	window.document.getElementById("sortByEndTime").style.display='none';
	window.document.getElementById("sortByStops").style.display='none';
	window.document.getElementById("sortByDuration").style.display='none';
}

//Returns formatted date to display

function GetFormattedDateToDisplay(dateStr){
	var theDate=new Date();
	while (dateStr.indexOf("-")>0)
		dateStr=dateStr.replace("-","");
	var year=dateStr.substring(0,4);
	var month=dateStr.substring(4,6);
	var day=dateStr.substring(6,8);
	if (day.length<2)
		day="0"+day;
	theDate.setFullYear(year,(month-1),day);
	var theDay=theDate.getDay();
	var dayString="";
	if (theDay==0)
		dayString="ΚΥΡ";
	else if (theDay==1)
		dayString="ΔΕΥ";
	else if (theDay==2)
		dayString="ΤΡΙ";
	else if (theDay==3)
		dayString="ΤΕΤ";
	else if (theDay==4)
		dayString="ΠΕΜ";
	else if (theDay==5)
		dayString="ΠΑΡ";
	else if (theDay==6)
		dayString="ΣΑΒ";

	fDateString=dayString + " " + day + "-" + month + "-" + year;
	return 	fDateString;
}

function GetSelectedDay(dateStr){
	var theDate=new Date();
	while (dateStr.indexOf("-")>0)
		dateStr=dateStr.replace("-","");
	var day=dateStr.substring(6,8);
	return 	day;
}

function GetSelectedMonth(dateStr){
	var theDate=new Date();
	while (dateStr.indexOf("-")>0)
		dateStr=dateStr.replace("-","");
	var month=dateStr.substring(4,6);
	return 	month;
}

function GetSelectedYear(dateStr){
	while (dateStr.indexOf("-")>0)
		dateStr=dateStr.replace("-","");
	var year=dateStr.substring(0,4);
	return 	year;
}

//Returns formatted time to display
function GetFormattedTimeToDisplay(time){

	if (time.length==3)
		time="0"+time;
	var hour=time.substring(0,2);
	var minutes=time.substring(2,4);
	var fTime=hour+":"+minutes;
	return fTime;
}

//Converts String to Date

function ConvertStringToDate(dateStr){
	while (dateStr.indexOf("-")>0)
		dateStr=dateStr.replace("-","");
	var year=dateStr.substring(0,4);
	var month=dateStr.substring(4,6);
	month=(month/1)-1;
	var day=dateStr.substring(6,8);
	if (day.length<2)
		day="0"+day;
	var theDate=new Date();
	theDate.setFullYear(year,month,day,0,0,0);
	return theDate;
}
//Formats duration 
function FormatDuration(dur){
	var duration=dur;
	if (dur.charAt(0)=='0')
		duration=dur.substring(1,dur.length);
	return duration;
}

//Update the value of selectedAirlineToDisplay hidden form
function UpdateSelectedAirlineToDisplay(obj){
	window.document.getElementById("selectedAirlineToDisplay").value=obj.id;
}

//Update the value of selectedSortTypeToDisplay hidden form
function UpdateSelectedSortTypeToDisplay(obj){
	window.document.getElementById("selectedSortTypeToDisplay").value=obj.id;
}




//Display the preffered Airline Only
function DisplaySelectedAirline(){
	selAirline=window.document.getElementById("selectedAirlineToDisplay").value;
	sType=window.document.getElementById("selectedSortTypeToDisplay").value;

	allTrPr=window.document.getElementById("sortByPrice").getElementsByTagName("TR");
	allTrAl=window.document.getElementById("sortByAirline").getElementsByTagName("TR");
	allTrSt=window.document.getElementById("sortByStartTime").getElementsByTagName("TR");
	allTrEt=window.document.getElementById("sortByEndTime").getElementsByTagName("TR");
	allTrSp=window.document.getElementById("sortByStops").getElementsByTagName("TR");
	allTrDr=window.document.getElementById("sortByDuration").getElementsByTagName("TR");
	

	// Price Sorted Table
	if (sType=='price'){
		if (selAirline!="all"){
		 	for (i=0;i<allTrPr.length;i++){
				if ( ((allTrPr[i].id).indexOf(selAirline+"_pr_")<0) && ((allTrPr[i].id).indexOf(selAirline+"_int_pr_")<0)){
					allTrPr[i].style.display='none';
				}
				else 
				{
					allTrPr[i].style.display='block';
				}
			}
		}
		else {
			for (i=0;i<allTrPr.length;i++)
				allTrPr[i].style.display='block';
		}
	}
	else{
		for (i=0;i<allTrPr.length;i++)
			allTrPr[i].style.display='none';
	}

	// Airline Sorted Table
	if (sType=='airline'){
		if (selAirline!="all"){
	 		for (i=0;i<allTrAl.length;i++){
				if ( ((allTrAl[i].id).indexOf(selAirline+"_al_")<0) && ((allTrAl[i].id).indexOf(selAirline+"_int_al_")<0)){
					allTrAl[i].style.display='none';
				}
				else {
					allTrAl[i].style.display='block';
				}
			}
		}	
		else {
			for (i=0;i<allTrAl.length;i++)
				allTrAl[i].style.display='block';
		}	
	}
	else{
		for (i=0;i<allTrAl.length;i++)
			allTrAl[i].style.display='none';
	}

	// StartTime Sorted Table
		if (sType=='startTime'){
	 if (selAirline!="all"){
	 	for (i=0;i<allTrSt.length;i++){
			if ( ((allTrSt[i].id).indexOf(selAirline+"_st_")<0)  && ((allTrSt[i].id).indexOf(selAirline+"_int_st_")<0)){
				allTrSt[i].style.display='none';
			}
			else {
				allTrSt[i].style.display='block';
			}
		}
	}
	else {
		for (i=0;i<allTrSt.length;i++)
			allTrSt[i].style.display='block';
	}
		}
	else{
		for (i=0;i<allTrSt.length;i++)
			allTrSt[i].style.display='none';
	}
	

	// EndTime Sorted Table
		if (sType=='endTime'){
	 if (selAirline!="all"){
	 	for (i=0;i<allTrEt.length;i++){
			if ( ((allTrEt[i].id).indexOf(selAirline+"_et_")<0) && ((allTrEt[i].id).indexOf(selAirline+"_int_et_")<0)){
				allTrEt[i].style.display='none';
			}
			else {
				allTrEt[i].style.display='block';
			}
		}
	}
	else {
		for (i=0;i<allTrEt.length;i++)
			allTrEt[i].style.display='block';
	}
		}
	else{
		for (i=0;i<allTrEt.length;i++)
			allTrEt[i].style.display='none';
	}
	
	// Stops Sorted Table
		if (sType=='stops'){
	 if (selAirline!="all"){
	 	for (i=0;i<allTrSp.length;i++){
			if ( ((allTrSp[i].id).indexOf(selAirline+"_sp_")<0) && ((allTrSp[i].id).indexOf(selAirline+"_int_sp_")<0)){
				allTrSp[i].style.display='none';
			}
			else {
				allTrSp[i].style.display='block';
			}
		}
	}
	else {
		for (i=0;i<allTrSp.length;i++)
			allTrSp[i].style.display='block';
	}
		}
	else{
		for (i=0;i<allTrSp.length;i++)
			allTrSp[i].style.display='none';
	}
	
	//Duration Sorted Table
if (sType=='duration'){
	 if (selAirline!="all"){
	 	for (i=0;i<allTrDr.length;i++){
			if ( ((allTrDr[i].id).indexOf(selAirline+"_dr_")<0)  && ((allTrDr[i].id).indexOf(selAirline+"_int_dr_")<0)){
				allTrDr[i].style.display='none';
			}
			else {
				allTrDr[i].style.display='block';
			}
		}
	}
	else {
		for (i=0;i<allTrDr.length;i++)
			allTrDr[i].style.display='block';
	}
}
	else{
		for (i=0;i<allTrDr.length;i++)
			allTrDr[i].style.display='none';
	}
}

//Formats price 
function FormatPrice(pr){
	var price=pr;
	while (price.charAt(0)=='0')
		price=price.substring(1,price.length);
	return price;
}

function  FillTheHiddenForms(index){ //In order to pass validation
	var addString="_"+index;
	window.document.getElementById("firstName"+addString).value="hidden";
	window.document.getElementById("surname"+addString).value="hidden";
}


function HideReturnFlight(){
		cDate=new Date();
		
		cDate.setDate(cDate.getDate()+10);
		
		cYear=cDate.getFullYear();
		cMonth=cDate.getMonth()+1;
		if (cMonth<10)
			cMonth="0"+cMonth;
		cDay=cDate.getDate();
		if (cDay<10)
			cDay="0"+cDay;
			
	if (window.document.getElementById("flighttype_1").checked){
		window.document.getElementById("dateRet_date").disabled=true;
		window.document.getElementById("dateRet_month").disabled=true;
		window.document.getElementById("timeRet").disabled=true;
		UpdateRetDate();
		}
	else{
		window.document.getElementById("dateRet_date").disabled=false;
		window.document.getElementById("dateRet_month").disabled=false;
		window.document.getElementById("timeRet").disabled=false;
		UpdateRetDate();
		}
}


function DisplaySearchScreen(){
	window.document.getElementById("searchScreen").style.display='block';
	window.document.getElementById("waitPage").style.display='none';
}


function DisplayWaitPage(){
	window.document.getElementById("searchScreen").style.display='none';
	window.document.getElementById("waitPage").style.display='block';
}

function UpdateCompleteStreetLength(){
	var street=window.document.getElementById("street_1").value;
	var streetNum=window.document.getElementById("streetNum_1").value;
	var completeStreetLength=street.length+streetNum.length;
	window.document.getElementById("CompleteStreet_Length").value=completeStreetLength;
	}
	

	function GetTotalAndCheapestFlightOfAirline(airline,airlinesArr,priceArr){
		var lowestPrice=0;
		var totalFlights=0;
		
		for (l=0;l<airlinesArr.length;l++){
			if (airlinesArr[l]==airline){
				totalFlights=(totalFlights/1)+1;
				if (((RemoveZerosAndReplaceComma(priceArr[l])/1)<(lowestPrice/1)) || ((lowestPrice/1)==0))
					lowestPrice=(RemoveZerosAndReplaceComma(priceArr[l])/1);	
			}
		}

		var bothValuesJoined=totalFlights+"!$"+lowestPrice;
		return bothValuesJoined;
	}
	
	function RemoveZerosAndReplaceComma(value){
		newValue=value;
		newValue=newValue.replace(",",".");
		return newValue;
	}

function UpdateEmailValidator(){
	var email=window.document.getElementById("email_1").value;
	returnValue=1;
	if (email.length>=5){
		email=email.substring(1,(email.length-1));
		if ((email.indexOf("@")<0) || (email.indexOf(".")<0) || ((email.indexOf("@")<0)>(email.indexOf(".")<0)))
			returnValue=0;
	}
	else if ((email.length<5) && (email.length>0))
		returnValue=0;
	window.document.getElementById("email_validator").value=returnValue;
}

function UpdatePhoneValidator(){
	var phone=window.document.getElementById("phone_1").value;
	returnValue=1;
	allowedChars="0123456789";
	if (phone.length>0){
		for (p=0;p<phone.length;p++){
			if ((allowedChars.indexOf(phone.charAt(p))<0) || (phone.length<10))
				returnValue=0;		
			if ((p==0) && (phone.charAt(p)=="+") && (phone.length>12))
				returnValue=1;	
		}
	}
	window.document.getElementById("phone_validator").value=returnValue;
}

function UpdateNameValidator(){
	allowedChars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',. \"-";
	for (pas=1;pas<=8;pas++){
		returnValue=1;
		formName="firstName_"+pas;
		valFormName="firstName_validator_"+pas;
		var name=window.document.getElementById(formName).value;
		returnValue=1;
		if (name.length>0 && name!=" "){
			for (n=0;n<name.length;n++){
				if (allowedChars.indexOf(name.charAt(n))<0)
					returnValue=0;		
			}
		}
		window.document.getElementById(valFormName).value=returnValue;
	}
}

function UpdateSurnameValidator(){
	allowedChars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',. \"-";
	for (pas=1;pas<=8;pas++){
		returnValue=1;
		formSurName="surname_"+pas;
		valFormSurname="surname_validator_"+pas;
		var surname=window.document.getElementById(formSurName).value;
		returnValue=1;
		if (surname.length>0 && surname!=" "){
			for (s=0;s<surname.length;s++){
				if (allowedChars.indexOf(surname.charAt(s))<0)
					returnValue=0;		
			}
		}
		window.document.getElementById(valFormSurname).value=returnValue;
	}
}

function UpdateZipCodeValidator(){
	var zipCode=window.document.getElementById("zipCode_1").value;
	returnValue=1;
	allowedChars="0123456789";
	if (zipCode.length>0){
		for (p=0;p<zipCode.length;p++){
			if ((allowedChars.indexOf(zipCode.charAt(p))<0) || (zipCode.length<5))
				returnValue=0;	
		}
	}
	window.document.getElementById("zipCode_validator").value=returnValue;
}

function UpdateStreetNumberValidator(){
	var streetNum=window.document.getElementById("streetNum_1").value;
	returnValue=1;
	allowedChars="0123456789- ";
	if (streetNum.length>0){
		for (p=0;p<streetNum.length;p++){
			if (allowedChars.indexOf(streetNum.charAt(p))<0){
				returnValue=0;	
			}
		}
	}
	//alert(returnValue);
	window.document.getElementById("streetNum_validator").value=returnValue;
}

function UpdateStreetValidator(){
	var street=window.document.getElementById("street_1").value;
	allowedChars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZαβγδεζηθικλμνξοπρστυφχψωςάέήίόώύΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ -.,";
	returnValue=1;
	if (street.length>0){
		for (s=0;s<street.length;s++){
			if (allowedChars.indexOf(street.charAt(s))<0){
				returnValue=0;	
			}
		}
	}
	window.document.getElementById("street_validator").value=returnValue;
}


function UpdateCityValidator(){
	var city=window.document.getElementById("city_1").value;
	allowedChars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZαβγδεζηθικλμνξοπρστυφχψωςάέήίόώύΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ -.,";
	returnValue=1;
	if (city.length>1){
		for (p=0;p<city.length;p++){
			if (allowedChars.indexOf(city.charAt(p))<0)
				returnValue=0;	
		}
	}
	window.document.getElementById("city_validator").value=returnValue;
}

function UpdateCountryValidator(){
	var country=window.document.getElementById("country_1").value;
	allowedChars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZαβγδεζηθικλμνξοπρστυφχψωςάέήίόώύΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ -";
	returnValue=1;
	if (country.length>1){
		for (p=0;p<country.length;p++){
			if (allowedChars.indexOf(country.charAt(p))<0)
				returnValue=0;	
		}
	}
	window.document.getElementById("country_validator").value=returnValue;
}

function UpdateCCVValidator(){
	var ccv=window.document.getElementById("ccv").value;
	returnValue=1;
	allowedChars="0123456789";
	if (ccv.length>0){
		for (p=0;p<ccv.length;p++){
			if ((allowedChars.indexOf(ccv.charAt(p))<0) || (ccv.length!=3))
				returnValue=0;	
		}
	}
	window.document.getElementById("ccv_validator").value=returnValue;
}

function UpdateCardNumberValidator(){
    //alert("Starting: CC Validator");
	var cardNumber=window.document.getElementById("cardNumber").value;
	cardNumber=cardNumber.replace(" ","");
	cardNumber=cardNumber.replace(" ","");
	cardNumber=cardNumber.replace(" ","");
	cardNumber=cardNumber.replace("-","");
	cardNumber=cardNumber.replace("-","");
	cardNumber=cardNumber.replace("-","");
	window.document.getElementById("cardNumber").value = cardNumber;
	
	var cardType=window.document.getElementById("cardType").value;
	returnValue=1;
	allowedChars="0123456789";
	if (cardNumber.length>0){
		for (p=0;p<cardNumber.length;p++){
			if ((allowedChars.indexOf(cardNumber.charAt(p))<0) || (cardNumber.length!=16))
				returnValue=0;	
		}
	}
	
    if (!checkCreditCard (cardNumber, cardType))
		returnValue=0;	
		
    window.document.getElementById("cardNumber_validator").value=returnValue;
}

function UpdateCardExpDateValidator(){
	var expMonth=window.document.getElementById("expMonth").value;
	var expYear=window.document.getElementById("expYear").value;
	if(expMonth != "" && expYear != "") {
	    returnValue=1;
	}
	else {
	    returnValue=0;	
	}
	window.document.getElementById("expDate_validator").value=returnValue;
}

function checkCreditCard (cardNo, cardname) {

     
  // Array to hold the permitted card characteristics
  var cards = new Array();
  
  cards [0] = {name: "VI", 
               length: "13,16", 
               prefixes: "4",
               checkdigit: true};
  cards [1] = {name: "MA", 
               length: "16", 
               prefixes: "51,52,53,54,55",
               checkdigit: true};
  cards [2] = {name: "DinersClub", 
               length: "14,", 
               prefixes: "300,301,302,303,304,305,36,38",
               checkdigit: true};
  cards [3] = {name: "CarteBlanche", 
               length: "14", 
               prefixes: "300,301,302,303,304,305,36,38",
               checkdigit: true};
  cards [4] = {name: "AmEx", 
               length: "15", 
               prefixes: "34,37",
               checkdigit: true};
               
  // Establish card type
  var cardType = -1;
  for (i=0; i<cards.length; i++) {

    // See if it is this card (ignoring the case of the string)
    if (cardname.toLowerCase () == cards[i].name.toLowerCase()) {
      cardType = i;
      break;
    }
  }
  
 
  // Now check the modulus 10 check digit - if required
  if (cards[cardType].checkdigit) {
    var checksum = 0;                                  // running checksum total
    var mychar = "";                                   // next char to process
    var j = 1;                                         // takes value of 1 or 2
  
    // Process each digit one by one starting at the right
    for (i = cardNo.length - 1; i >= 0; i--) {
    
      // Extract the next digit and multiply by 1 or 2 on alternative digits.
      calc = Number(cardNo.charAt(i)) * j;
    
      // If the result is in two digits add 1 to the checksum total
      if (calc > 9) {
        checksum = checksum + 1;
        calc = calc - 10;
      }
    
      // Add the units element to the checksum total
      checksum = checksum + calc;
    
      // Switch the value of j
      if (j ==1) {j = 2} else {j = 1};
    } 
  
    // All done - if checksum is divisible by 10, it is a valid modulus 10.
    // If not, report an error.
    if (checksum % 10 != 0)  {
     ccErrorNo = 3;
     return false; 
    }
  }  

/* No card specific checks are made!
  // The following are the card-specific checks we undertake.
  var LengthValid = false;
  var PrefixValid = false; 
  var undefined; 

  // We use these for holding the valid lengths and prefixes of a card type
  var prefix = new Array ();
  var lengths = new Array ();
    
  // Load an array with the valid prefixes for this card
  prefix = cards[cardType].prefixes.split(",");
      
  // Now see if any of them match what we have in the card number
  for (i=0; i<prefix.length; i++) {
    var exp = new RegExp ("^" + prefix[i]);
    if (exp.test (cardNo)) PrefixValid = true;
  }
      
  // If it isn't a valid prefix there's no point at looking at the length
  if (!PrefixValid) {
     ccErrorNo = 3;
     return false; 
  }
    
  // See if the length is valid for this card
  lengths = cards[cardType].length.split(",");
  for (j=0; j<lengths.length; j++) {
    if (cardNo.length == lengths[j]) LengthValid = true;
  }
  
  // See if all is OK by seeing if the length was valid. We only check the 
  // length if all else was hunky dory.
  if (!LengthValid) {
     ccErrorNo = 4;
     return false; 
  };   
  */
  // The credit card is in the required format.
  return true;
}
//Get HTML for Priter Friendly Pages
function GetPriterFriendlyPage(obj){
	var htmlToPrint=obj.innerHTML;
	return htmlToPrint;
}

//Opens popup window for Printer Friendly Pages
function PrintResultsPopoupWindow()
{
		obj=window.document.getElementById("mainContent");
		htmlToPrint=GetPriterFriendlyPage(obj);
		printUrl=printUrl.replace('"','\"');
		var printUrl=eval("PrintResults.aspx?html="+htmlToPrint);
		window.open(printUrl,null,"width=700,height=600,status=no,toolbar=no,scrollbars=yes");
}

//Selected From Airport Value
function GetSelectedFromAirport(obj){
	var fromValue=obj.id;
	window.document.getElementById("from").value=fromValue;
}


//Selected To Airport Value
function GetSelectedToAirport(obj){
	var toValue=obj.id;
	window.document.getElementById("to").value=toValue;
}

//Initial Set of From and To Values
function SetFavoriteAirport(radioId){
	var formValue="";
	var inputs=window.document.getElementsByTagName("input");
		if (radioId=="from")
			for (i=0;i<inputs.length;i++)
				if (inputs[i].type=="radio" && inputs[i].name=="fromRadio" && inputs[i].checked)
					formValue=inputs[i].id;

		if (radioId=="to")
			for (i=0;i<inputs.length;i++)
				if (inputs[i].type=="radio" && inputs[i].name=="toRadio" && inputs[i].checked)
					formValue=inputs[i].id;

		return formValue;
	}

//Update Departure Year according to the selected month
function UpdateSelDepYear(){
	var day=window.document.getElementById("dateDep_date").value;
	var month=window.document.getElementById("dateDep_month").value;	
	var cDate=new Date();
	var	cMonth=cDate.getMonth()+1;
	var	cDay=cDate.getDate();
	var	cYear=cDate.getFullYear();
	nextYear=cYear+1;
	//alert((month/1));
	//alert((cMonth/1));
	if ((month/1)<(cMonth/1))
		year=nextYear;
	else if ((month/1)==(cMonth/1) && (day/1)<(cDay/1))
		year=nextYear;
	else
		year=cYear;
	window.document.getElementById("dateDep_year").value=year;
}
	
//Update Return Year according to the selected month
function UpdateSelRetYear(){
	var day=window.document.getElementById("dateRet_date").value;
	var month=window.document.getElementById("dateRet_month").value;	
	var cDate=new Date();
	var	cMonth=cDate.getMonth()+1;
	var	cDay=cDate.getDate();
	var	cYear=cDate.getFullYear();
	nextYear=cYear+1;
	if ((month/1)<(cMonth/1))
		year=nextYear;
	else if ((month/1)==(cMonth/1) && (day/1)<(cDay/1))
		year=nextYear;
	else
		year=cYear;
	window.document.getElementById("dateRet_year").value=year;
}
/*
//Update Departure Year according to the selected month
function UpdateSelDepYear(cDay,cMonth,cYear){
	var day=window.document.getElementById("dateDep_date").value;
	var month=window.document.getElementById("dateDep_month").value;	
	nextYear=cYear+1;
	if ((month/1)<(cMonth/1))
		year=nextYear;
	else if ((month/1)==(cMonth/1) && (day/1)<(cDay/1))
		year=nextYear;
	else
		year=cYear;
	window.document.getElementById("dateDep_year").value=year;
}

//Update Return Year according to the selected month
function UpdateSelRetYear(cDay,cMonth,cYear){
	var day=window.document.getElementById("dateRet_date").value;
	var month=window.document.getElementById("dateRet_month").value;	
	nextYear=cYear+1;
	if ((month/1)<(cMonth/1))
		year=nextYear;
	else if ((month/1)==(cMonth/1) && (day/1)<(cDay/1))
		year=nextYear;
	else
		year=cYear;
	window.document.getElementById("dateRet_year").value=year;
}
*/

//Updates the Selected Departure Date
function UpdateSelDepDate(){
	//var year=window.document.getElementById("dateDep_year").value;
	var month=window.document.getElementById("dateDep_month").value;	
	var year = 2006
	var cDate=new Date();
	var	cMonth=cDate.getMonth()+1;
	var	cDay=cDate.getDate();
	var	cYear=cDate.getFullYear();
	nextYear=cYear+1;
	//alert((month/1));
	//alert((cMonth/1));
	if ((month/1)<(cMonth/1))
		year=nextYear;
	else if ((month/1)==(cMonth/1) && (day/1)<(cDay/1))
		year=nextYear;
	else
		year=cYear;
	var month=window.document.getElementById("dateDep_month").value;
	var day=window.document.getElementById("dateDep_date").value;
//alert(year);
//alert('DepDate:'+year+"-"+month+"-"+day);
	window.document.getElementById("completeDepDate").value=year+"-"+month+"-"+day;
}

//Updates the Selected Return Date
function UpdateSelRetDate(){
	//var year=window.document.getElementById("dateRet_year").value;
	var month=window.document.getElementById("dateRet_month").value;	
	var year = 2006
	var cDate=new Date();
	var	cMonth=cDate.getMonth()+1;
	var	cDay=cDate.getDate();
	var	cYear=cDate.getFullYear();
	nextYear=cYear+1;
	if ((month/1)<(cMonth/1))
		year=nextYear;
	else if ((month/1)==(cMonth/1) && (day/1)<(cDay/1))
		year=nextYear;
	else
		year=cYear;
	var month=window.document.getElementById("dateRet_month").value;
	var day=window.document.getElementById("dateRet_date").value;

	//alert('RetDate:'+year+"-"+month+"-"+day);

	if (window.document.getElementById("completeRetDate")){
		window.document.getElementById("completeRetDate").value=year+"-"+month+"-"+day;
		}
}

//Validates Client Side the TotalPasseners of Mini Search
function CheckTotalPassengers(adults,children,infants){
	window.document.getElementById("totalPassengers").value=(adults/1)+(children/1)+(infants/1);
	totalPassengers=window.document.getElementById("totalPassengers").value;
	if (totalPassengers>8){
			return false;
		}
	else
		return true;	
}

//Validates Client Side the Dates of Mini Search
function CheckDates(depDate,retDate, flightType){
	var depArray=depDate.split("-");
	var depYear=depArray[0];
	var depMonth=depArray[1];
	var depDay=depArray[2];
	var retArray=retDate.split("-");
	var retYear=retArray[0];
	var retMonth=retArray[1];
	var retDay=retArray[2];
	var returnValue=true;
	if (flightType=="Return"){
		if ((retYear/1)<(depYear/1)){
			returnValue=false;
			}
		else if ((retYear/1)==(depYear/1) && (retMonth/1)<(depMonth/1)){
			returnValue=false;
		}
		else if ((retYear/1)==(depYear/1) && (retMonth/1)==(depMonth/1) && (retDay/1)<(depDay/1)){
			returnValue=false;
		}
	}
	return returnValue;
}

//Validates Client Side the Airports of Mini Search
function CheckAirports(from,to){
	var returnValue=true;
	if (from=="" || to==""){
		returnValue=false;
	}
	else if (from==to)
	{
		returnValue=false;
	}
	return returnValue;
}

function ValidateMiniSearch(){
	var returnValue=true;
	var adults=window.document.getElementById("adults").value;
	var children=window.document.getElementById("children").value;
	var infants=window.document.getElementById("infants").value;
	var depDate=window.document.getElementById("completeDepDate").value;
	var retDate=window.document.getElementById("completeRetDate").value;
	var from=window.document.getElementById("from").value;
	var to=window.document.getElementById("to").value;
	var flightType=window.document.getElementById("flightType").value;
	var errorMessage="";
	if (!CheckAirports(from,to)){
		returnValue=false;
		errorMessage="Τα αεροδρόμια Αναχώρησης και Προορισμού δεν πρέπει να είναι ίδια ή κενά";
		alert(errorMessage);
	}
	else if (!CheckDates(depDate,retDate,flightType)){
		returnValue=false;
		errorMessage="Η ημερομηνία επιστροφής πρέπει να είναι μετά την ημερομηνία αναχώρησης";
		alert(errorMessage);
	}
	else if (!CheckTotalPassengers(adults,children,infants)){
		returnValue=false;
		errorMessage="Ο μέγιστος αριθμός επιβατών είναι 8";
		alert(errorMessage);
	}
	return returnValue;

}
function SubmitNewSearch(){
	var obj=window.document.getElementById("searchForm");
	obj.submit();
}
