var v_currentOutboundSelectedID = 0;
var v_currentReturnSelectedID 	= 0;

/*Rollover states*/
/*The dontRoll fearture is to stop the row rollovers when a cell rollover has already run*/
function farePickOver(cell)	{genOver(cell,'#999999');}
function farePickOut(cell)	{genOut (cell,'');}
/*Roll-out function*/
function genOut(cell,col)
{
	cell.style.textDecoration='none';
	cell.style.backgroundColor=col;
}
/*Roll-over function*/
function genOver(cell,col)
{
	cell.style.textDecoration='underline';
	cell.style.backgroundColor=col;
}

// RailEuropWebService relate JS's
function roundTripChange() {
	if (document.getElementById('round_trip_yes').checked) {
		document.getElementById('ptp_returnLabel').style.display 			= 'inline';
		document.getElementById('ptp_returnDateDay').style.display 			= 'inline';
		document.getElementById('ptp_returnDateMonthYear').style.display 	= 'inline';
		document.getElementById('showRet').style.display 					= 'inline';
		document.getElementById('showRet').src								= '/include/yui/calendar/assets/calicon.gif';
		document.getElementById('showRet').width							= '13';
		document.getElementById('showRet').height							= '12';
		document.getElementById('ptp_returnTime').style.display 			= 'inline';
	} else {
		document.getElementById('ptp_returnLabel').style.display 			= 'none';
		document.getElementById('ptp_returnDateDay').style.display 			= 'none';
		document.getElementById('ptp_returnDateMonthYear').style.display 	= 'none';
		document.getElementById('showRet').style.display 					= 'none';
		document.getElementById('showRet').src								= '/images/px.gif';
		document.getElementById('showRet').width							= '1';
		document.getElementById('showRet').height							= '1';
		document.getElementById('ptp_returnTime').style.display 			= 'none';
	}
}
function lockReturnOptions(thisId,l_compatible_return_fares) {
	//Loop through all the radio options for the "returnPriceIdentifier" radio.
	for (i=0;i<document.getElementsByName("returnPriceIdentifier").length;i++) {
		str_l_compatible_return_fares 	= l_compatible_return_fares;
		strThisFareId 					= document.getElementsByName("returnPriceIdentifier")[i].value;
		v_name 					= document.getElementsByName("returnPriceIdentifier")[i].id;
		v_name 					= 'div_'+v_name.substring(6,v_name.length);
		if (str_l_compatible_return_fares.indexOf(strThisFareId)>=0 || l_compatible_return_fares == '') {
			document.getElementsByName("returnPriceIdentifier")[i].disabled = false;
			document.getElementById(v_name).style.color='#000000';
		} else {
			//Un-check it before you disable it.
			document.getElementsByName("returnPriceIdentifier")[i].checked = false;
			//Now disable it.
			document.getElementsByName("returnPriceIdentifier")[i].disabled = true;
			document.getElementById(v_name).style.color='#CCCCCC';
		}
	}
}
function selectedOutboundPrice(clickedItem,l_compatible_return_fares) {
	v_clickedItemId = clickedItem.id;
	v_clickedItemId = v_clickedItemId.replace('div_','');
	if (document.getElementById('radio_'+v_clickedItemId).disabled != true) {
		lockReturnOptions(v_clickedItemId,l_compatible_return_fares);
		if (v_currentOutboundSelectedID > 0) {
			//Set DIV to default colours
			document.getElementById(v_currentOutboundSelectedID).style.backgroundColor='';
			document.getElementById(v_currentOutboundSelectedID).style.color='#000000';
		}
		//Set the checkbox to checked and the highlight the DIV
		document.getElementById('radio_'+v_clickedItemId).checked = true;
		document.getElementById('div_'+v_clickedItemId).style.backgroundColor='#FF0000';
		document.getElementById('div_'+v_clickedItemId).style.color='#FFFFFF';
		v_currentOutboundSelectedID = 'div_'+v_clickedItemId;		
	}
}
function selectedReturnPrice(clickedItem) {
	v_clickedItemId = clickedItem.id;
	v_clickedItemId = v_clickedItemId.replace('div_','');
	if (document.getElementById('radio_'+v_clickedItemId).disabled != true) {		
		if (v_currentReturnSelectedID > 0) {			
			document.getElementById(v_currentReturnSelectedID).style.backgroundColor='';
			document.getElementById(v_currentReturnSelectedID).style.color='#000000';
		}
		document.getElementById('radio_'+v_clickedItemId).checked = true;
		document.getElementById('div_'+v_clickedItemId).style.backgroundColor='#FF0000';
		document.getElementById('div_'+v_clickedItemId).style.color='#FFFFFF';
		v_currentReturnSelectedID = 'div_'+v_clickedItemId;
	} else {
		alert('Sorry, that fare is unavailable:\nThe option is disabled because it is not compatible with the outbound fare you\'ve selected. Either chose a different return option or change your outbound fare to find one which is compatible with this option.');
	}
}

function checkText(txtStr)
		{
		var TxtCount=0                       
            for(i=0;i<txtStr.length; i++)                        
            if(!((txtStr.charAt(i)>="0" && txtStr.charAt(i)<="9")))
			{
				TxtCount++
			}
			if(TxtCount>0)
                  	{
					return false
				}
			else				  
			 	{
					return true
				}
       	}

function numericonly(formname,obj1name,p)
		{
		obj1 = eval("document."+formname+"."+obj1name);		
		if(!checkText(obj1.value))
		{
						obj1_numeric = obj1.value;
						obj1_numericlen = obj1_numeric.length;
						obj1_numericlen = obj1_numericlen - 1;
						//alert(SupplierPriceLen);
						obj1_numeric = obj1_numeric.substring(0,parseInt(obj1_numericlen));
						//alert(SupplierPrice);
						obj1.value = "";
					{
						alert("Please enter a correct age for Traveller " + p);
					}
						
		}
		}
		
	function windowOpener(url,width,height,target,isfullscreen,top,left) 
      {
       browserName = navigator.appName;
       browserVer = navigator.appVersion.substring(0,1);
       if (width==null) {width=600;}
       if (height==null) {height=400;}
       if (top==null) {top=40;}
       if (left==null) {left=50;}
       if (browserName != "Netscape" || browserVer != 2)
       {
controlWindow=window.open(url,target,"toolbar=no,height="+height+",width="+width+",top="+top+",left="+left+",location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,fullscreen="+isfullscreen);
       }
      }
function ShowMenu(n) {
	var menu, arrowImg
	menu = document.getElementById("d" + n);
	
	// Determine if the menu is currently showing.
	if (menu.style.display == 'block') {
		// If it is showing, hide the menu and update the twisty image.
		menu.style.display = 'none'
	} else {
		// Hide all layers first.		
		var divs = document.getElementsByTagName("div")		
		// Show the menus and update their twisty images.
		i = 2
		while (n.length >= i) {
			menu = document.getElementById("d" + n.substring(0, i));
			menu.style.display = "block";
			i += 2;
		}
	}
}
	

function wopen(url, w, h)
{
// Fudge factors for window decoration space.
 // In my tests these work well on all platforms & browsers.
w += 32;
h += 96;
 var win = window.open(url,
  'popup', 
  'width=' + w + ', height=' + h + ', ' +
  'location=no, menubar=no, ' +
  'status=no, toolbar=no, scrollbars=yes, resizable=yes');
 win.resizeTo(w, h);
 win.focus();
}

function makeFieldAppearDisabled(fieldName) {
	document.getElementById(fieldName).disabled 				= true;
	document.getElementById(fieldName).style.color 				= '#999999';
	document.getElementById(fieldName).style.backgroundColor 	= '#eeeeee';
}
function makeFieldAppearEnabled(fieldName) {
	document.getElementById(fieldName).disabled 				= false;
	document.getElementById(fieldName).style.color 				= '#000000';
	document.getElementById(fieldName).style.backgroundColor 	= '#FFFFFF';
}

function addBookmark(title, url) {
	var title, url;
	title = 'Rail Plus - '+document.title;
	url = location.href;
	if (document.all) { 			//MSIE
		window.external.AddFavorite(url, title);
	} else if (window.sidebar) { 	// FireFox
		window.sidebar.addPanel(title, url,"");
	} else {
		alert("Sorry, your browser doesn't support this action.");
	}
}

function SelectBoxRedirect(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function OpenBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) { //v3.0
  if(window.screen)if(isCenter)if(isCenter=="true"){
    var myLeft = (screen.width-myWidth)/2;
    var myTop = (screen.height-myHeight)/2;
    features+=(features!='')?',':'';
    features+=',left='+myLeft+',top='+myTop;
  }
  window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}

function toggleLayer(objLayer, action){
	if (action == 'hide'){
		objLayer.style.display = 'none';
	}else{
		objLayer.style.display = '';
	}
}

// JavaScript Rollover Functions
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}