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,departure,arrival)
{	
	alert(trnNo+":::"+trnName+":::"+departure+":::"+arrival);
//-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="OSQRoute";			
		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(check)
{
    if(!isEqual("stationFrom"))
	{
		alert("The From Station You Have Selected Does Not Exist In This Route..\n Kindly Select First From The Option Shown Below");
		return false;
	}
	if(!isEqual("stationTo"))
	{
		alert("The To Station You Have Selected Does Not Exist In This Route..\n Kindly Select  Last From The Option Shown Below");
		return false;
	}

	if(check==1)
	{
		if(isChanged())
		{
			alert("Please Click On Go");
			return false;
		}
	}
	if(check==0)//MALAY
	{
		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;
		}
	}
//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.screen.value="ttrsLogin";
	document.BookTicketForm.action="../booking/ttrslogin.do?click=true";
	return true;		
}

/*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(scr)
{	
	
if(document.BookTicketForm.userName.value.length==0 && document.BookTicketForm.password.value.length==0)
	{
	
		alert("Enter All The Mandatory Fields");
		return false;
	}

	if(document.BookTicketForm.userName.value.length==0)
		{
			alert("Please Enter The UserName");
			document.BookTicketForm.userName.focus();
			return false;
		}

	if(!isEmpty(document.BookTicketForm.userName.value,"UserName"))
		{
			document.BookTicketForm.userName.focus();
			return false;
		}
		

		if(document.BookTicketForm.password.value.length==0)
		{
			alert("Please Enter The Password");
			document.BookTicketForm.password.focus();
			return false;
		}
	

	if(isProper(document.BookTicketForm.userName.value))
	{
		alert("You have entered Special Characters");
		document.BookTicketForm.userName.focus();
		return false;
	}	
	document.BookTicketForm.screen.value = scr;
	document.BookTicketForm.submitClicks.value=parseInt(document.BookTicketForm.submitClicks.value)+1;	
	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="OSQTrainsFromTo";
	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)
{

	alert("TrainNo:::"+document.BookTicketForm.radioTrnNo.value);
	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
	alert("check1111");
	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="ttrsLogin";
		document.BookTicketForm.action="../booking/ttrslogin.do?click=true";
	}//end of if
	else{
		document.BookTicketForm.screen.value="OSQRoute";
		document.BookTicketForm.Submit.click();
	}//end of else
	return true;
	
}


function submitPlannerRoute(trnNo,trnName,trnType,departure,arrival,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.departure.value=departure;
		document.BookTicketForm.arrival.value=arrival;		
		document.BookTicketForm.boardPoint.value = boardpt;
		document.BookTicketForm.destStation.value = destpt;

		return false;
	//}
}

//Struts testing ends / 28 JUN 2004
