/*
    Javascript Validations
*/

function submitForm(formObj,actVal)
{
    if(actVal=='none')
    {
	formObj.hidNoOfRowsDisplayed.value="0";
	formObj.hidNextOrBack.value='next';
    
	if(formObj.radiobutton1[0].checked)
	{
	    if(formObj.selOrigin.selectedIndex == 0)
	    {
		alert("Please select city of origin");
		formObj.selOrigin.focus();
		return ;
	    }

	    if(formObj.selDestination.selectedIndex == 0)
	    {
		alert("Please select city of destination");
		formObj.selDestination.focus();
		return ;
	    }

	    if(formObj.selOrigin.selectedIndex == formObj.selDestination.selectedIndex)
	    {
		alert("City of origin and destination cannot be the same");
		formObj.selDestination.focus();
		return ;
	    }
	}

	if(formObj.radiobutton1[1].checked)
	{
		if(formObj.txtFlightNo.value=="")
		{    	
			alert("Please enter flight number");
			formObj.txtFlightNo.focus();
			return ;
		}
	}

	if(formObj.optType[1].checked)
	{
		if(formObj.txtDate.value=="")
		{    	
			alert("Please enter date");
			formObj.txtDate.focus();
			return ;
		}
		
		var numDays = dateDiff(formObj.hidTodayDate.value,formObj.txtDate.value);
		
		if(numDays<0)
		{
			alert("Please enter future date");
			formObj.txtDate.focus();
			return ;
		}
	}	
    }
    else
    {
	formObj.hidNextOrBack.value=actVal;
	
	formObj.selOrigin.options[formObj.selOrigin.selectedIndex].value = formObj.hidSelectedOrigin.value;
	
	formObj.selDestination.options[formObj.selDestination.selectedIndex].value = formObj.hidSelectedDestination.value;
	
	formObj.selAirline.options[formObj.selAirline.selectedIndex].value = formObj.hidSelectedAirline.value;
	
	formObj.selDayOfOperation.options[formObj.selDayOfOperation.selectedIndex].value = formObj.hidSelectedDOP.value;
	
	formObj.txtFlightNo.value = formObj.hidSelectedFlightNo.value;
	
	formObj.txtDate.value = formObj.hidSelectedDate.value;
    }

    formObj.submit();            
    
	//sName = "hWnd";
	//if(!navigator.mWins) navigator.mWins = new Array();
	//navigator.mWins[navigator.mWins.length] = window.open("/timetable/jsp/publicuser/processing.jsp","messagewindow","scrollbars=no,toolbar=no,location=no,resizable=no,width=330,height=150,top=250,left=300");
    
}

function winClose()
{
	for(i=0;i<navigator.mWins.length;i++) navigator.mWins[i].close();
		navigator.mWins = new Array();
}


function checkValues(obj)
{
    if(obj.value=="days")
    {
	document.frm.txtDate.value="";
    }
    else
    if(obj.value=="date")
    {
	document.frm.selDayOfOperation.options[0].selected=true;
    }
    else
    if(obj.value=="flightno")
    {
	document.frm.selOrigin.options[0].selected=true;
	document.frm.selDestination.options[0].selected=true;
	document.frm.selAirline.options[0].selected=true;
    }
    else
    {
	document.frm.txtFlightNo.value="";
    }
}

function resetValues(val)
{
    if(val == "date")
    {
	document.frm.txtDate.value="";
	document.frm.optType[0].checked=true;
    }
    else
    if(val == "days")
    {
	document.frm.selDayOfOperation.options[0].selected=true;
	document.frm.optType[1].checked=true;	
    }
    else
    if(val=="flightno")
    {
    	document.frm.txtFlightNo.value="";
    	document.frm.radiobutton1[0].checked=true;
    }
    else    
    {
	document.frm.selOrigin.options[0].selected=true;
	document.frm.selDestination.options[0].selected=true;
	document.frm.selAirline.options[0].selected=true;
	
	document.frm.radiobutton1[1].checked=true;
    }    
}


function clearForm(objForm)
{
	objForm.selOrigin.options[0].selected=true;
	objForm.selDestination.options[0].selected=true;
	objForm.selDayOfOperation.options[0].selected=true;
	objForm.selAirline.options[0].selected=true;
	objForm.txtDate.value = "";
	objForm.txtWeekDay.value = "";
	objForm.optType[0].checked=true;
	objForm.radiobutton1[0].checked=true;
	objForm.hidNoOfRowsDisplayed.value="0";
}


function resetValuesNdisplayCalendar(evt,dateObj,val)
{	
	resetValues(val);
	displaySearch(evt,dateObj);
}

//date validation is here....

function dateDiff(fromDate,toDate)
{
	var strTemp;
	if((fromDate != null) ||(fromDate != ""))
	{
		strTemp = fromDate.substring(0,2);
		if(strTemp.charAt(0)=='0')
			strTemp=strTemp.substr(1);
		var fromDay=parseInt(strTemp);
		strTemp = fromDate.substring(3,5);
		if(strTemp.charAt(0)=='0')
			strTemp=strTemp.substr(1);
		var fromMonth=parseInt(strTemp);
		var fromYear=parseInt(fromDate.substring(6,10));		
	}
	
	if((toDate != null) ||(toDate != ""))
	{
		strTemp = toDate.substring(0,2);
		if(strTemp.charAt(0)=='0')
			strTemp=strTemp.substr(1);
		var toDay=parseInt(strTemp);
		strTemp = toDate.substring(3,5);
		if(strTemp.charAt(0)=='0')
			strTemp=strTemp.substr(1);
		var toMonth=parseInt(strTemp);
		var toYear=parseInt(toDate.substring(6,10));		
	}
        
    if(toYear < fromYear)
    	return -1;
    else
    if((toYear == fromYear) && (toMonth < fromMonth))
  		return -1;
  	else
  	if((toYear == fromYear) && (toMonth == fromMonth) && (toDay < fromDay))
  		return -1;
  	else
  	if((toYear == fromYear) && (toMonth == fromMonth) && (toDay == fromDay))
  		return 0;
  	else
  	{
		date1 = new Date();
		date2 = new Date();
		diff  = new Date();

		date1temp = new Date(fromYear,fromMonth-1,fromDay);
		date1.setTime(date1temp.getTime());
	
		date2temp = new Date(toYear,toMonth-1,toDay);
		date2.setTime(date2temp.getTime());

		diff.setTime(Math.abs(date2.getTime() - date1.getTime()));

		timediff = diff.getTime();		
		return Math.floor(timediff / (1000 * 60 * 60 * 24))+1;		
  	}
}

function OpenAirContactPrintForm()
{	
	myWin5=window.open('','AddprintPage1','toolbar=yes,scrollbars=yes,status=yes,WIDTH=650,HEIGHT=450,resizable=yes');	
	document.frm2.method="post";
	document.frm2.action = "PUAirlineContact.servlet";
	document.frm2.target='AddprintPage1';	
	document.frm2.submit();
}
