function equal(toStation,fromStation)
{
	var sf;
	var ss;	
	
	if(fromStation.indexOf("(")==-1 || fromStation.indexOf(")")==-1)
		sf = fromStation;
	else
		sf = fromStation.substring(fromStation.indexOf("(")+1,fromStation.indexOf(")"));

	if(toStation.indexOf("(")==-1 && toStation.indexOf(")")==-1)
		ss = toStation;
	else
		ss = toStation.substring(toStation.indexOf("(")+1,toStation.indexOf(")"));
		
		if(sf.toUpperCase()==ss.toUpperCase())					
			return true;	
		else
			return false;
		
}

function submitRoute(trnNo,trnName,trainType,departure,arrival,runson)
{	
	
//-StrutsCR01/26-02-2004/Sharath/mod begins
	/*if(isChanged())
	{
		alert("Please Click On Go");
		for(i=0;i<document.BookTicketForm.radioTrnNo.length;i++)
		{	
			if(document.BookTicketForm.radioTrnNo[i].checked)
			{				
				document.BookTicketForm.radioTrnNo[i].checked=false;
				break;
			}
		
		}		
		document.BookTicketForm.Submit.focus();				
		return false;
	}
	else
	{*/
//StrutsCR01/26-02-2004/Sharath/mod ends
		if(isChanged())
		{
			alert("Please Click On Go");
			return false;
		}
		
		document.BookTicketForm.screen.value="route";			
		document.BookTicketForm.trainNo.value=trnNo;		
		document.BookTicketForm.trainName.value=trnName;	
		document.BookTicketForm.trainType.value=trainType;	
		document.BookTicketForm.departure.value=departure;
		document.BookTicketForm.arrival.value=arrival;
		document.BookTicketForm.runsOn.value=runson;
		


//StrutsTic3_ban/01-03-2004/Sharath/Mod Begins
		document.forms[0].pressedGo.value = "pressedGo";
//StrutsTic3_ban/01-03-2004/Sharath/Mod Ends
		document.BookTicketForm.Submit.click();	
		return false;
	//}
}
/*function isChanged()
{	
	//return false;
	alert('<bean:write name="BookTicketForm" property="stationFrom"/>');
	if(document.BookTicketForm.stationFrom.value!='<bean:write name="BookTicketForm" property="stationFrom"/>')return true;
//	if(document.BookTicketForm.stationTo.value!="<bean:write name="BookTicketForm" property="stationTo"/>")return true;		
//	if(document.BookTicketForm.day.options[document.BookTicketForm.day.selectedIndex].value!="<bean:write name="BookTicketForm" property="day"/>")return true;	
//	if(document.BookTicketForm.month.options[document.BookTicketForm.month.selectedIndex].value!="<bean:write name="BookTicketForm" property="month"/>")return true;	
//	if(document.BookTicketForm.year.options[document.BookTicketForm.year.selectedIndex].value!="<bean:write name="BookTicketForm" property="year"/>")return true;
//	if(document.BookTicketForm.classCode.options[document.BookTicketForm.classCode.selectedIndex].value!="<bean:write name="BookTicketForm" property="classCode"/>")return true;
	return false;
}*/
function submitBookTicket(trnName,pkgName,date,formName)
{
	
var formBox =eval("document." + formName)  ;
   if(formBox.trainName.value==0)
	{
		alert("Please Select The Train");
		formBox.trainName.focus();
	return false;

	}
var sf=pkgName.substring(pkgName.indexOf("(")+1,pkgName.indexOf("-"));
	var st=pkgName.substring(pkgName.indexOf("-")+1,pkgName.indexOf(")"));
	
		formBox.trainName.value=trnName;
		//formBox.packageName.value=pkgName;
		formBox.bkdDate.value=date;;
		formBox.boardPoint.value = sf;
		formBox.destStation.value = st;
		formBox.stationFrom.value=sf;
		formBox.stationTo.value=st;
		formBox.pressedGo.value = "pressedGo";
		formBox.screen.value="bookTicket";		
		formBox.action="../booking/ttrslogin.do?click=true&fromPlanner=true";		
		formBox.submitClicks.value=parseInt(formBox.submitClicks.value)+1;	
	return true;		
}
//jitendra END Added 30 th Nov 2006  -->
/*function isValidSelection()
{
	fromStationIndex=0;
	toStationIndex=0;
	for(i=0;i<document.BookTicketForm.fromStationRadio.length;i++)
	{
		if(document.BookTicketForm.fromStationRadio[i].checked)
		{
			fromStationIndex=i;
			break;
		}
	}
	for(i=0;i<document.BookTicketForm.toStationRadio.length;i++)
	{
		if(document.BookTicketForm.toStationRadio[i].checked)
		{
			toStationIndex=i;
			break;
		}
	}
	
	if(fromStationIndex>=toStationIndex)return false;
	else return true;
}*/
function isValidSelection()
{
	fromStationIndex=0;
	toStationIndex=0;
	for(i=0;i<document.BookTicketForm.fromStationRadio.length;i++)
	{
		if(document.BookTicketForm.fromStationRadio[i].checked)
		{
			fromStationIndex=1;			
		}
	}
	for(i=0;i<document.BookTicketForm.toStationRadio.length;i++)
	{
		if(document.BookTicketForm.toStationRadio[i].checked)
		{
			toStationIndex=1;			
		}
	}
	
	if(fromStationIndex==0)
	{
		alert("Please Select The From Station");
		return false;
	}
	if(toStationIndex==0)
	{
		alert("Please Select The To Station");
		return false;
	}	
		
	else return true;
}


function setFromStation(fromStationCode)
{
	for(i=0;i<document.BookTicketForm.fromStationRadio.length;i++)
	{
		if(document.BookTicketForm.fromStationRadio[i].value.toUpperCase()==fromStationCode.toUpperCase())
		{
			document.BookTicketForm.fromStationRadio[i].checked=true;
			break;
		}
	}	
}
function setToStation(toStationCode)
{	
	for(i=0;i<document.BookTicketForm.toStationRadio.length;i++)
	{
		if(document.BookTicketForm.toStationRadio[i].value.toUpperCase()==toStationCode.toUpperCase())
		{
			document.BookTicketForm.toStationRadio[i].checked=true;
			break;
		}
	}
}

function incrementClicks(strDate)
{	
//MALAY ADDED FOR TATKAL 26 DEC 05 STARTS
var curdate=strDate;

//MALAY ADDED FOR TATKAL 26 DEC 05 ENDS
//From Stations
//alert("Submit Click before increment: "+document.BookTicketForm.submitClicks.value);

//if(document.BookTicketForm.trainType[0].checked==false && document.BookTicketForm.trainType[1].checked==false &&document.BookTicketForm.trainType[2].checked==false &&document.BookTicketForm.trainType[3].checked==false &&document.BookTicketForm.trainType[4].checked==false &&document.BookTicketForm.trainType[5].checked==false)
//	{
//		alert("Please Select The Train Type");
//		document.BookTicketForm.trainType[0].focus();
//		return false;
//	}

document.BookTicketForm.submitClicks.value=parseInt(document.BookTicketForm.submitClicks.value)+1;

if(document.BookTicketForm.trainTypeList.value==0)
	{
		alert("Please Select The Train");
		document.BookTicketForm.trainTypeList.focus();
		return false;
	}
	if(document.BookTicketForm.classCode.value==0)
	{
		alert("Please Select a Class");
		document.BookTicketForm.classCode.focus();
		return false;
	}

/*	if(!isValidJourneyDate("BookTicketForm",new  Date(document.BookTicketForm.CurrentYear.value,document.BookTicketForm.CurrentMonth.value,document.BookTicketForm.CurrentDate.value))) 
	{		
		document.BookTicketForm.day.focus();
		return false;
	}
	*/
//StrutsTic33/ 13-04-2004/ Sharath/ Mod Begins
	if(!isValidDate("BookTicketForm"))
	{
		return false;
	}	
//StrutsTic33/ 13-04-2004/ Sharath/ Mod Ends

// select a class
	
	
//StrutsTic3_ban/01-03-2004/Sharath/Mod Begins
	if(document.forms[0].pressedGo.value != "pressedGo")
	{
		document.forms[0].pressedGo.value="";
		if(!isValidJourneyDate("BookTicketForm",new  Date(document.BookTicketForm.CurrentYear.value,document.BookTicketForm.CurrentMonth.value,document.BookTicketForm.CurrentDate.value),curdate)) return false;
	}
	//MALAY 9 JAN 2006 STARTS
	if(document.forms[0].pressedGo.value == "pressedGo")
	{	document.forms[0].pressedGo.value="";
		if(!isValidJourneyDate("BookTicketForm",new  Date(document.BookTicketForm.CurrentYear.value,document.BookTicketForm.CurrentMonth.value,document.BookTicketForm.CurrentDate.value),curdate)) return false;
	}
	//MALAY 9 JAN 2006 ENDS
	if(document.forms[0].screen.value=="bookTicket")
	{
		document.forms[0].screen.value="trainsFromTo";
	}


	return true;
}

//sharath

//********************************************************//
// Function name: isEmpty(s,txt_fld)                      //
// Parameters:s											  //
//Return : Void											  //
//Description :This function is used to validate          //
//whether the field is empty or not				          //
//********************************************************//
function isEmpty(s,txt_fld)
{  
        if ((s == null) || (s.length == 0)){	
			alert("Enter Value for  "+txt_fld);
           	 return false;
		}//end of if

       for (var i=0; i<s.length; i++){
           if(s.charAt(i) != " ")
		      return true;
           else{
		      alert("Enter Value for "+txt_fld);
		  	  return false
		   }//end of else
		 }//end of for
		 return true;
}//end of function

//********************************************************//
// Function name: verify(a)			                      //
// Parameters:string									  //
//Return : 0 (false),1 (true) &3 (length>3)				  //
//Description :This function is used to validate          //
//whether the field has brackets and length < 3	          //
//********************************************************//
function verify(a)
{
	if(a.indexOf('(')<0 && a.indexOf(')')<0 )
	{
		if(a.length>4)		
		return 3;	
	return 1;
	}
	
	else if(a.indexOf('(')<0 || a.indexOf(')')<0 )
		return 0;
	else
	{
		var q = a.indexOf('(');
		var w = a.indexOf(')');
		var z = w-q-1;
		if(z>0 && z<5)
		   return 1;
		else 
			return 0;
	}
}

function isLetters(c)
{     return (((c >= "a") && (c <= "z"))||((c >= "A") && (c <= "Z")) ||(c=="(" || c==")" ) || (c==" "));
}//end of function

//******************************************************//
// Function name: isProper(string)	    				//
// Parameters:string						            //
// Return : boolean										//
// Description :This function is used to validate       //
// whether the field Value has some special characters  //
//******************************************************//
function isProper(string)
{
   if (!string) return false;
   var iChars = "\\*|,\":<>[]{}`\';@&$#%~!^*-+=?_/.";
   for (var i = 0; i < string.length; i++) 
   {
        if (iChars.indexOf(string.charAt(i)) != -1)
     	 return true;
   }
   return false;
} 
/********************************************************/
// Function name: isAlphabet (s,msg)                     //
// Parameters:string,string								 //
//Return : boolean										 //
//Description :This function is used to validate         //
//whether the given string  contains only Alphabets 	 //
//********************************************************//
function isAlphabet (str,msg)
{
	for(var i=0; i<str.length; i++)
	{
		var c = str.charAt(i);
		if(!isLetters(c))
		{
			alert("Enter Only Alphabets for " + msg);
			return false;
		}
	}
	return true;
}
//sharath

//StrutsTic11/20-02-2004/Sharath/mod begins
function fareAvailability()
{
	if(!isEqual("stationFrom"))
	{
		alert("The From Station You Have Selected Does Not Exist In This Route..\n Kindly Select From The Option Shown Below OR Press GO");
		return false;
	}
	if(!isEqual("stationTo"))
	{
		alert("The To Station You Have Selected Does Not Exist In This Route..\n Kindly Select From The Option Shown Below OR Press GO");
		return false;
	}
	if(document.forms[0].changetext.value==1)
	{
		if(isChanged())
		{
			alert("Please Click On Go");
			return false;
		}
	}
	if(!isValidSelection())
	{
		//alert("Please Select The Stations Properly.... \n Destination Station Should Be After Source Station");
		return false;
	}
	return true;
}
function back()
{
	document.BookTicketForm.method="post";
	document.BookTicketForm.Submit.value="TRUE";	
	document.BookTicketForm.screen.value="trainsFromTo";
	document.BookTicketForm.select.value="TRUE";
//STR_PROD_TC_11/ 15-Apr-2004/ Sharath/ Mod Begins
	if(!incrementClicks())
		return false;
//STR_PROD_TC_11/ 15-Apr-2004/ Sharath/ Mod Ends
	document.BookTicketForm.action = "../booking/planner.do?Submit=TRUE";
	
	return true;

		//document.forms[0].a.value = "sharath";		
//		history.back();
	//	document.BookTicketForm.screen.value="trainsFromTo";
		
}
//StrutsTic11/20-02-2004/Sharath/mod ends


///testing for struts on 28 JUN 2004


function submitPlannerTicket(check)
{
	var flag = 0;
	if(document.BookTicketForm.radioTrnNo.length!=null)
	{
		for(i=0;i<document.BookTicketForm.radioTrnNo.length;i++)
		{	
			if(document.BookTicketForm.radioTrnNo[i].checked)
			{				
				flag=1;
				break;
			}
		}
	}
	if(document.BookTicketForm.radioTrnNo.length==null)
	{
		if(document.BookTicketForm.radioTrnNo.checked)
			{
				flag=1;
			}
	}
	if(flag == 0){
		alert("Please select the train from train list");
		return false;
	}//end of if	
	if(check==0)
	{
		//if(document.forms[0].changetext.value==1)
		//{
			
			if(isChanged())
			{
				alert("Please Click On Go");
				return false;
			}
		//}

	}

//StrutsTic3_ban/01-03-2004/Sharath/Mod Begins
	document.forms[0].pressedGo.value = "pressedGo";
//StrutsTic3_ban/01-03-2004/Sharath/Mod ends
	incrementClicks();
	//document.BookTicketForm.stationFrom.value = document.BookTicketForm.boardPoint.value;
	//document.BookTicketForm.stationTo.value = document.BookTicketForm.destStation.value;
	//document.BookTicketForm.screen.value="bookTicket";
	//document.BookTicketForm.action="../booking/bookticket.do?click=true";
//	alert(document.BookTicketForm.stationFrom.value);
	//alert(document.BookTicketForm.stationTo.value);
//	alert(document.BookTicketForm.boardPoint.value);
	//alert(document.BookTicketForm.destStation.value);
	if(equal(document.BookTicketForm.stationFrom.value,document.BookTicketForm.boardPoint.value) && equal(document.BookTicketForm.stationTo.value,document.BookTicketForm.destStation.value)){		
		document.BookTicketForm.screen.value="bookTicket";
		document.BookTicketForm.action="../booking/ttrslogin.do?click=true";
	}//end of if
	else{
		document.BookTicketForm.screen.value="route";
		document.BookTicketForm.Submit.click();
	}//end of else
	return true;
	
}


function submitPlannerRoute(trnNo,trnName,trainType,departure,arrival,runson,boardpt,destpt)
{		
	
//-StrutsCR01/26-02-2004/Sharath/mod begins
	/*if(isChanged())
	{
		alert("Please Click On Go");
		for(i=0;i<document.BookTicketForm.radioTrnNo.length;i++)
		{	
			if(document.BookTicketForm.radioTrnNo[i].checked)
			{				
				document.BookTicketForm.radioTrnNo[i].checked=false;
				break;
			}
		
		}		
		document.BookTicketForm.Submit.focus();				
		return false;
	}
	else
	{*/
//StrutsCR01/26-02-2004/Sharath/mod ends

		if(isChanged())
		{
			alert("Please Click On Go");
			return false;
		}

		document.BookTicketForm.trainNo.value=trnNo;		
		document.BookTicketForm.trainName.value=trnName;	
		document.BookTicketForm.trainType.value=trainType;	
		document.BookTicketForm.departure.value=departure;
		document.BookTicketForm.arrival.value=arrival;
		document.BookTicketForm.runsOn.value=runson;
		document.BookTicketForm.boardPoint.value = boardpt;
		document.BookTicketForm.destStation.value = destpt;
		return false;
	//}
}

//Struts testing ends / 28 JUN 2004
