var rootdomain="http://www.sapatrainticket.com"+window.location.hostname

function ajaxinclude(url) {
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.open('GET', url, false) //get page synchronously 
page_request.send(null)
writecontent(page_request)
}

function writecontent(page_request){
if (window.location.href.indexOf("http")==-1 || page_request.status==200)
document.write(page_request.responseText)
}

function load( url, id )
{
  return function( event )
  {
    if( !event.button ) // only on left mousebutton or keyboard event
    {
      event.stopPropagation();
      event.preventDefault();
      var img = document.getElementById( id );
      if( img.className == 'loading' ) return;
      img.className = 'loading';
      img.parentNode.title = 'Loading; please wait.';
      pulsate( img );
      var what = plugins[id], method = what.method||'GET', data = '';
      var request = { url:url, method:method, onload:function( http )
		      { img.parentNode.title = 'Completed OK.';
			img.className = 'ok'; }, onerror:function( http )
		      { img.parentNode.title = 'Failed!';
			img.className = 'die'; } };
      if( method == 'POST' )
      {
	url = /^([^?]+)\??(.*)/.exec( url );
	request.url = url[1];
	request.data = url[2];
	if( what.extra_data )
	  request.data = request.data +'&'+ what.extra_data;
	request.headers = {'Content-Type':'application/x-www-form-urlencoded'};
      }
      GM_xmlhttpRequest( request );
    }
  };
}

function addonclick( link, url, id )
{
  //GM_log( 'onclick '+id+': '+link );
  link.href = url;
  if( id )
  {
    link.addEventListener( 'click', load( url, id ), false );
    link.addEventListener( 'keypress', load( url, id ), false );
  }
}
function formatTime( t )
{
  var date = [t.getFullYear(), pad( t.getMonth()+1 ), pad( t.getDate() )];
  var time = [pad( t.getHours() ), pad( t.getMinutes() )];
  return date.join( '-' ) +' '+ time.join( ':' );
}

function trap( node, event, handler )
{
/*  var original = node.getAttribute( 'on'+event );
  if( original )
  {
    original = original.replace( /;\s*$/, '' ).split( ';' );
    var last = original.pop();
    var next = 'setTimeout("'+ original.join(';') +'",100);' + last;
    node.setAttribute( 'on'+event, next );
  }
*/
  node.addEventListener( event, handler, false );
}

function accesskey( node, key, keys, color )
{
  var reserved = keys || { 'd':1, 'o':1, '.':1 };
  var accesskey = 'Alt+'; // browsers have different ideas about accesskeys
  if( navigator.userAgent.match( /opera/i ) )
    accesskey = 'Shift+Esc followed by ';
  else if( navigator.userAgent.match( /macintosh/i ) )
    accesskey = 'Control+';

  if( !key )
  {
    var letters = node.textContent.replace( /\W/g, '' ), i; // first word char
    for( i=0; i<letters.length; i++ )
    {
      key = letters.charAt( i ); // will this letter do?
      if( !reserved[key.toLowerCase()] ) break; // found the first free letter
      key = null; // try, try again!
    }
    if( !key ) return reserved; // too bad; don't do anything at all.
  }
  underline( node, key );
  reserved[key.toLowerCase()] = 1; // taken!
  node.title = 'Hotkey: '+ accesskey + key.toLowerCase(); // usability hint
  node.accessKey = key.toUpperCase();
  if( color ) node.style.color = color; // colorize the link as applicable
  return reserved;
}

function underline( node, key )
{
  if( !node ) return;
  var character = new RegExp( '^(<[^>]*>)*([^<'+ key +']*)*('+ key +')', 'i' );
  var hasOne = getStyle( node, 'textDecoration' ).match( 'underline' );
  var style = hasOne ? 'border-bottom:1px solid' : 'text-decoration:underline';
  var underlined = '$1$2<span style="'+ style +';">$3</span>';
  node.innerHTML = node.innerHTML.replace( character, underlined );
}

function getStyle( node, style )
{
  if( node.currentStyle )
    return node.currentStyle[ style ];
  if( window.getComputedStyle )
    return getComputedStyle( node, null )[ style ];
  return '';
}
// special_functions.js
// functions for master header home page include
var pollCancel = false; 

    function validateOnlinePollForm(form) {                                                                   
        if (pollCancel) 
      return true; 
        else 
       return validateRequired(form); 
   } 

    function required () { 
     this.aa = new Array("answerId", "An answer to the Online Poll is required.", new Function ("varName", " return this[varName];"));
    } 


//<!-- FLASH w/AUDIO CONTROL BEGIN v1.0-->
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_controlShockwave(objStr,x,cmdName,frameNum) { //v3.0
  var obj=MM_findObj(objStr);
  if (obj) eval('obj.'+cmdName+'('+((cmdName=='GotoFrame')?frameNum:'')+')');
}
//Cookie function on home page
function setCookie(name, value, expires, path, domain, secure) {
   var curCookie = name + "=" + escape(value) +
       ((expires) ? "; expires=" + expires : "") +
       ((path) ? "; path=" + path : "") +
       ((domain) ? "; domain=" + domain : "") +
       ((secure) ? "; secure" : "");
   document.cookie = curCookie;
}
function getCookie(name) {
   var dc = document.cookie;
   var prefix = name + "=";
   var begin = dc.indexOf("; " + prefix);
   if (begin == -1) {
     begin = dc.indexOf(prefix);
     if (begin != 0) return null;
   } else
     begin += 2;
   var end = document.cookie.indexOf(";", begin);
   if (end == -1)
     end = dc.length;
   return unescape(dc.substring(begin + prefix.length, end)); } function fixDate(date) {
   var base = new Date(0);
   var skew = base.getTime();
   if (skew > 0)
     date.setTime(date.getTime() - skew); } // --> </SCRIPT>


function processCookie()
{
var now = new Date();
fixDate(now);

//now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000); 

//Set timeout to 30 minutes since the last visit
now.setMinutes(now.getMinutes() + 30);

homeVisits = getCookie("counter"); 
if (!homeVisits) {
   homeVisits = 1;
   document.write("<!-- -->");
} 
else {
   homeVisits = parseInt(homeVisits) + 1;
   document.write("<!--  -->"); 
}

setCookie("counter", homeVisits, now.toGMTString());
}
/// FUNCTION CHECK COOKIE ///
function cookie(name,value)
{ this.name = name;
this.value = value;
this.attributes = new Array();
this.expiresIn = function (days)
{ expiration = new Date();
expiration.setTime(expiration.getTime() + (days*86400000));
this.attributes["expires"] = expiration.toGMTString();
};
this.set = function ()
{ var cookiestr = this.name + "=" + escape(this.value);
for(attr in this.attributes)
{ cookiestr += "; " + attr
if(this.attributes[attr].length > 0)
cookiestr += "=" + this.attributes[attr];
}
document.cookie=cookiestr;
};
this.erase = function()
{ this.expiresIn(-1);
this.set();
delete cookies[this.name];
};
}

function cookieContainer()
{ this.add=function (name,value)
{ this[name]=new cookie(name,value);
};
this.get=function (name)
{ for(o in this)
if(o == name)
return this[o];
return null;
}
var cstr=document.cookie;
var spaces=/s/gi;
cstr=cstr.replace(spaces,'');
while(cstr.length>0)
{ cequal=cstr.indexOf("=");
if(cequal==-1) cequal=cstr.length;
var name=cstr.substring(0,cequal);
cstr=cstr.substring(cequal+1,cstr.length);
cend=cstr.indexOf(";");
if(cend==-1) cend=cstr.length;
var value=unescape(cstr.substring(0,cend));
cstr=cstr.substring(cend+1,cstr.length);
this.add(name,value);
}
}
var cookies = new cookieContainer();

// Functions that are specific to single pages (mainly include jsp files) are moved here to facilitate the Java script move to external file
function openPopupExtraParams(name, url, height, width, menubar, location, toolbar, scrollbars, status, resizable){
	var tmpPopup; var strProperties = "menubar=" + menubar + ",location=" + location + ",toolbar=" + toolbar + ",scrollbars=" + scrollbars + ",status=" + status + ",resizable=" + resizable + ",width=" + width + ",height=" + height + ",left=0, top=0";
	tmpPopup = window.open(url, name, strProperties); tmpPopup.focus();
}

function openPopup(name, url, height, width, menubar, location, toolbar, scrollbars, status, resizable){
	var tmpPopup; var strProperties = "menubar=" + menubar + ",location=" + location + ",toolbar=" + toolbar + ",scrollbars=" + scrollbars + ",status=" + status + ",resizable=" + resizable + ",width=" + width + ",height=" + height + ",left=0, top=0";
	tmpPopup = window.open(url, name, strProperties); tmpPopup.focus();
}
function openWindow(url, name, width, height) {popupWin = window.open(url, name, "resizable=no,location=no,scrollbars=yes,width="+width+",height="+height); 
}

/*
	domEl() function - painless DOM manipulation
	written by Pawel Knapik  //  pawel.saikko.com
*/
var domEl = function(e,c,a,p,x) {
if(e||c) {
	c=(typeof c=='string'||(typeof c=='object'&&!c.length))?[c]:c;	
	e=(!e&&c.length==1)?document.createTextNode(c[0]):e;	
	var n = (typeof e=='string')?document.createElement(e) : !(e&&e===c[0])?e.cloneNode(false):e.cloneNode(true);	
	if(e.nodeType!=3) {
		c[0]===e?c[0]='':'';
		for(var i=0,j=c.length;i<j;i++) {
			if(typeof c[i]=='string' && c[i].length!=0) n.appendChild(document.createTextNode(c[i]));
			else if(c[i].length!=0) n.appendChild(c[i].cloneNode(true));
		}
		if(a) {for(var i=(a.length-1);i>=0;i--) a[i][0]=='class'?n.className=a[i][1]:n.setAttribute(a[i][0],a[i][1]);}
	}
}
	if(!p)return n;
	p=(typeof p=='object'&&!p.length)?[p]:p;
	for(var i=(p.length-1);i>=0;i--) {
		if(x){while(p[i].firstChild)p[i].removeChild(p[i].firstChild);
			if(!e&&!c&&p[i].parentNode)p[i].parentNode.removeChild(p[i]);}
		if(n) p[i].appendChild(n.cloneNode(true));
	}	
}

/*
	getElementsByClass - algorithm by Dustin Diaz, shortened by Pawel Knapik
*/
function getElementsByClass(s,n,t) {
	var c=[], e=(n?n:document).getElementsByTagName(t?t:'*'),r=new RegExp("(^|\\s)"+s+"(\\s|$)");
	for (var i=0,j=e.length;i<j;i++) r.test(e[i].className)?c.push(e[i]):''; return c }
	
/*
	$() based on prototype.js dollar function idea, optimized by Pawel Knapik.
*/
function $(){var r=[],a=arguments;for(var i=0,j=a.length;i<j;i++){(typeof a[i]=='string')?(r.push(document.getElementById(a[i]))):(r.push(a[i]))}
return(r.length==1)?r[0]:r}