/****************************************
File : utility.js
Dir  : js/
Created By : Saurabh Singh 
Created on : 20-June-2011
Description : All Java Script function
Modified on : 
Modified by :
Modified Desc : 
***********************************************************************************************/
////////////AJAX SCRIPTING///////////////////////////////////////////

// this is the default handle function of ajax, very imporatnt for ajax and is a part of it
function GetXmlHttpObject(handler)
{ 
var objXmlHttp=null

if (navigator.userAgent.indexOf("Opera")>=0)
{
objXmlHttp=new XMLHttpRequest()
objXmlHttp.onload=handler
objXmlHttp.onerror=handler 
return objXmlHttp
}
if (navigator.userAgent.indexOf("MSIE")>=0)
{ 
var strName="Msxml2.XMLHTTP"
if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
{
strName="Microsoft.XMLHTTP"
} 
try
{ 
objXmlHttp=new ActiveXObject(strName)
objXmlHttp.onreadystatechange=handler 
return objXmlHttp
} 
catch(e)
{ 
alert("Error. Scripting for ActiveX might be disabled") 
return 
} 
} 
if (navigator.userAgent.indexOf("Mozilla")>=0)
{
objXmlHttp=new XMLHttpRequest()
objXmlHttp.onload=handler
objXmlHttp.onerror=handler 
return objXmlHttp
}
} 
////////////////END OF DEFAULT AJAX FUNCTION/////////////////////////

////////AJAX JS FUNCTION FOR RIGHT BAR TRAIN SCHEDULE///////////////////////////////////////
function GetToPort(frm)
{ 
	var url="get_to_port.php?frm_port="+frm;
	//alert(url);
	xmlHttp=GetXmlHttpObject(func_GetToPort)
	xmlHttp.open("GET", url, true)
	xmlHttp.send(null)
}
function func_GetToPort() 
{ 
	if (xmlHttp.readyState==1)
	{
		document.getElementById("get_to_port").innerHTML="<img src='images/status.gif'>&nbsp;&nbsp;Loading Wait Please..........." 
	}
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById("get_to_port").innerHTML=xmlHttp.responseText 
	}
}

function GetTrainSchedule()
{ 
	//var jrny_type=document.getElementById('jrny_type').value;+"&jrny_type="+jrny_type
	var from_loc=document.getElementById('from_loc').value;
	var to_loc=document.getElementById('to_loc').value;
	
	var url="schedule_div.php?from_loc="+from_loc+"&to_loc="+to_loc;
	//alert(url);
	xmlHttp=GetXmlHttpObject(func_GetTrainSchedule)
	xmlHttp.open("GET", url, true)
	xmlHttp.send(null)
}

function func_GetTrainSchedule() 
{ 
	if (xmlHttp.readyState==1)
	{
		document.getElementById("schedule_div").innerHTML="<div style='margin:50px 0px; text-align:center;'><img src='images/status.gif'><br /><br /><strong>Loading Wait Please.....</strong></div>" 
	}
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById("schedule_div").innerHTML= xmlHttp.responseText
	}
} 

////////AJAX JS FUNCTION FOR RIGHT BAR TRAIN TARIFF///////////////////////////////////////

function GetToPortTariff(frm)
{ 
	var url="get_to_port_tariff.php?frm_port="+frm;
	//alert(url);
	xmlHttp=GetXmlHttpObject(func_GetToPortTariff)
	xmlHttp.open("GET", url, true)
	xmlHttp.send(null)
}
function func_GetToPortTariff() 
{ 
	if (xmlHttp.readyState==1)
	{
		document.getElementById("get_to_port_tariff").innerHTML="<img src='images/status.gif'>&nbsp;&nbsp;Loading Wait Please..........." 
	}
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById("get_to_port_tariff").innerHTML=xmlHttp.responseText 
	}
}
function GetTrainTariff()
{ 
	var from_loc=document.getElementById('from_loc').value;
	var to_loc=document.getElementById('to_loc').value;
	
	var url="tariff_div.php?from_loc="+from_loc+"&to_loc="+to_loc;
	//alert(url);
	xmlHttp=GetXmlHttpObject(func_GetTrainTariff)
	xmlHttp.open("GET", url, true)
	xmlHttp.send(null)
}

function func_GetTrainTariff() 
{ 
	if (xmlHttp.readyState==1)
	{
		document.getElementById("tariff_div").innerHTML="<div style='margin:50px 0px; text-align:center;'><img src='images/status.gif'><br /><br /><strong>Loading Wait Please.....</strong></div>" 
	}
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById("tariff_div").innerHTML= xmlHttp.responseText
	}
} 


function GetNewsByYear(yearVal)
{
	//alert('Hi  '+yearVal);
	location.replace('newsall.php?ny='+yearVal);
}
function GetHighByYear(yearVal)
{
	//alert('Hi  '+yearVal);
	location.replace('latest_highsall.php?ny='+yearVal);
}
function GetAnnouncByYear(yearVal)
{
	//alert('Hi  '+yearVal);
	location.replace('announcall.php?ny='+yearVal);
}


function mainmenu(){
$(" #menu-main-menu ul ").css({display: "none"}); // Opera Fix
$(" #menu-main-menu li").hoverIntent(function(){
		$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(400);
		},function(){
		$(this).find('ul:first').hide(600);
		});
}

jQuery.fn.liScroll = function(settings) {
		settings = jQuery.extend({
		travelocity: 0.10
		}, settings);		
		return this.each(function(){
				var $strip = jQuery(this);
				$strip.addClass("newsticker")
				var stripWidth = 0;
				var $mask = $strip.wrap("<div class='mask'></div>");
				var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");								
				var containerWidth = $strip.parent().parent().width();	//a.k.a. 'mask' width 	
				$strip.find("li").each(function(i){
				stripWidth += jQuery(this, i).outerWidth(true); // thanks to Michael Haszprunar
				});
				$strip.width(stripWidth);			
				var totalTravel = stripWidth+containerWidth;
				var defTiming = totalTravel/settings.travelocity;	// thanks to Scott Waye		
				function scrollnews(spazio, tempo){
				$strip.animate({left: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);});
				}
				scrollnews(totalTravel, defTiming);				
				$strip.hover(function(){
				jQuery(this).stop();
				},
				function(){
				var offset = jQuery(this).offset();
				var residualSpace = offset.left + stripWidth;
				var residualTime = residualSpace/settings.travelocity;
				scrollnews(residualSpace, residualTime);
				});			
		});	
};

 
$(document).ready(function () {
							
	mainmenu();
	
      $(function(){
      $("ul#ticker01").liScroll();
      }); 
	  
	  var $items = $('#vtab>ul>li');
		$items.mouseover(function() {
			$items.removeClass('selected');
			$(this).addClass('selected');
		
			var index = $items.index($(this));
			$('#vtab>div').hide().eq(index).show();
		}).eq(1).mouseover();
		
		
		$("#new_track_older").click(function () {
			if(document.getElementById("new_track_div_more").style.display=="none")
			{
				$("#new_track_older").html("<img src='images/view_less.png' border='0' style='float:left;' />&nbsp;<b>Hide Older Status</b>");
				$("#new_track_div_more").show('slow');
			}
			else
			{
				$("#new_track_older").html("<img src='images/view_more.png' border='0' style='float:left;' />&nbsp;<b>Show Older Status</b>");
				$("#new_track_div_more").hide('slow');
			}
		});
});


$(function($) {
   var options = {
        timeNotation: '12h',
        am_pm: true,
        fontFamily: 'Verdana, Times New Roman',
        fontSize: '12px',
		foreground: '#005daa',
		utc: true,
        utc_offset: 5.5
      }; 
   $('.jclock_India').jclock(options);
});

function showHide_trackStatus($total)
{
	if(document.getElementById("new_track_div_more"+$total).style.display=="none")
	{
		$("#new_track_older"+$total).html("<img src='images/view_less.png' border='0' style='float:left;' />&nbsp;<b>Hide Older Status</b>");
		$("#new_track_div_more"+$total).show('slow');
	}
	else
	{
		$("#new_track_older"+$total).html("<img src='images/view_more.png' border='0' style='float:left;' />&nbsp;<b>Show Older Status</b>");
		$("#new_track_div_more"+$total).hide('slow');
	}
}


