/*
-Programe Developed by SIDS Solutionz Bangalore.
Created:5/nov/2009
Updated:5/nov/2009
-Disclaimer: Company does not hold any responsibility for any change in the code other than SIDSSOL Employee's.
*/

$(document).ready(function($) {
	animatedcollapse.addDiv('divPortSub', 'speed=200,fade=1');
	animatedcollapse.addDiv('diServicesSub', 'speed=200,fade=1');
	animatedcollapse.addDiv('diCorperateSub', 'speed=200,fade=1');
	animatedcollapse.addDiv('diInvestorsSub', 'speed=200,fade=1');
	animatedcollapse.addDiv('diMediaSub', 'speed=200,fade=1');
	animatedcollapse.addDiv('diCareersSub', 'speed=200,fade=1');
	animatedcollapse.addDiv('diConnectivitySub', 'speed=200,fade=1');
	animatedcollapse.init();
	hideAllMenus();
	$("body").mouseover(function(event )
	{
		targClass=event.target.className;
		if((targClass=="lbMenuLink") || (targClass=="top") ||(targClass=="bottom") || (targClass=="middle") || (targClass=="lbSubLinks") )
		{		
			
		}
		else
		{
			hideAllMenus();
		}
	});
}); 
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
function emailcheck(emailID) 
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(emailID))
	{		
		return false;					
	}
	else
	{
		return true;
	}	
}
function Left(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function Top(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
	curtop += obj.y;
	return curtop;
}
function showSubMenu(Obj,menuObj,overImg)
{
	hideAllMenus();
	lbObj=Obj.id;
	topPos=parseInt(Top(document.getElementById(lbObj)));
	leftpos=Left(document.getElementById(lbObj));
	document.getElementById(menuObj).style.top=(topPos+27)+"px";
	document.getElementById(menuObj).style.left=(leftpos)+"px";
	document.getElementById(lbObj).style.background="url('images/menu/"+overImg+"')";
	animatedcollapse.show(menuObj);
}
function hideAllMenus()
{
	activeTab=document.getElementById("HFActiveTab").value;
	if(activeTab!="lb_PortOverview")
		document.getElementById("lb_PortOverview").style.background="url('images/menu/port_inactive.jpg')";
	else
		document.getElementById("lb_PortOverview").style.background="url('images/menu/port_active.jpg')";
	animatedcollapse.hide('divPortSub');
	if(activeTab!="lb_Connectivity")
		document.getElementById("lb_Connectivity").style.background="url('images/menu/connectivity_inactive.png')";
	else
		document.getElementById("lb_Connectivity").style.background="url('images/menu/connectivity_active.png')";
	if(activeTab!="lb_Services")
		document.getElementById("lb_Services").style.background="url('images/menu/services_inactive.jpg')";
	else
		document.getElementById("lb_Services").style.background="url('images/menu/services_active.jpg')";
	animatedcollapse.hide('diServicesSub');
	if(activeTab!="lb_Corperate")
		document.getElementById("lb_Corperate").style.background="url('images/menu/corporate_inactive.jpg')";
	else
		document.getElementById("lb_Corperate").style.background="url('images/menu/corporate_active.jpg')";
	animatedcollapse.hide('diCorperateSub');
	if(activeTab!="lb_Investors")
		document.getElementById("lb_Investors").style.background="url('images/menu/investors_inactive.jpg')";
	else
		document.getElementById("lb_Investors").style.background="url('images/menu/investors_active.jpg')";
	animatedcollapse.hide('diInvestorsSub');
	if(activeTab!="lb_Media")
		document.getElementById("lb_Media").style.background="url('images/menu/media_inactive.jpg')";
	else
		document.getElementById("lb_Media").style.background="url('images/menu/media_active.jpg')";
	animatedcollapse.hide('diMediaSub');
	if(activeTab!="lb_Careers")
		document.getElementById("lb_Careers").style.background="url('images/menu/career_inactive.jpg')";
	else
		document.getElementById("lb_Careers").style.background="url('images/menu/career_active.jpg')";
	animatedcollapse.hide('diCareersSub');
}
function showMap()
{	
	document.getElementById("overlay").style.display="block";
	document.getElementById("overlay").style.height = parseInt(Top(document.getElementById("footer")))+68+"px";
	scroll(0,0);
	document.getElementById("div_Map").style.display="block";
}
function closeMap()
{
	document.getElementById("overlay").style.display="none";
	document.getElementById("div_Map").style.display="none";
	document.getElementById("div_EmailMap").style.display="none";
}
function showDirection()
{	
	document.getElementById("overlay").style.display="block";
	document.getElementById("overlay").style.height = parseInt(Top(document.getElementById("footer")))+68+"px";
	scroll(0,0);
	document.getElementById("div_Direction").style.display="block";
}

function showDirection2()
{	
	document.getElementById("overlay").style.display="block";
	document.getElementById("overlay").style.height = parseInt(Top(document.getElementById("footer")))+68+"px";
	scroll(0,0);
	document.getElementById("div_Direction2").style.display="block";
}

function closeDirection()
{
	document.getElementById("overlay").style.display="none";
	document.getElementById("div_Direction").style.display="none";
}

function closeDirection2()
{
	document.getElementById("overlay").style.display="none";
	document.getElementById("div_Direction2").style.display="none";
}
var pwin;
function printImg() {	
	pwin = window.open("images/portmap_forprint.jpg",'Map','scrollbars = no,resizable = no,location = no')
	pwin.focus();
	setTimeout("pwin.print()",1000);
}
function showEmailMap()
{	
	if(document.getElementById("div_EmailMap").style.display=="none")
	{
		document.getElementById("div_EmailMap").style.display="block";
	}
	else
	{
		document.getElementById("div_EmailMap").style.display="none";
	}
	document.getElementById("txtFrom").value="";
	document.getElementById("txtTo").value="";
	document.getElementById("txtMessage").value="";
}

function closeEmailMap()
{	
	
	document.getElementById("div_EmailMap").style.display="none";	
	document.getElementById("txtFrom").value="";
	document.getElementById("txtTo").value="";
	document.getElementById("txtMessage").value="";
}
function sendMap()
{
	var errMsg="";	
	if(document.getElementById("txtFrom").value.replace(/ /g,"")=="")
	{
		errMsg=errMsg+"- Enter your email id.\n";		
	}
	else if(emailcheck(document.getElementById("txtFrom").value)==false)
	{
			errMsg=errMsg+"- Enter a valid from email id.\n";
	}
	if(document.getElementById("txtTo").value.replace(/ /g,"")=="")
	{
		errMsg=errMsg+"- Enter your friends email id.\n";		
	}
	else if(emailcheck(document.getElementById("txtTo").value)==false)
	{
			errMsg=errMsg+"- Enter a valid email id.\n";
	}
	if(errMsg!="")
	{
		alert(errMsg);
	}
	else
	{
		document.forms[0].action="strategiclocationDB.php";
		document.forms[0].submit();
	}
}



function openMap(type)
{
	document.getElementById("overlay").style.display="block";
	document.getElementById("overlay").style.height = parseInt(Top(document.getElementById("footer")))+68+"px";
	scroll(0,0);
	if(type==1)
	{
		document.getElementById("divConnMap").style.background="url(images/maps_railconnectivity.png)";
	}
	else if(type==2)
	{
		document.getElementById("divConnMap").style.background="url(images/maps_icdconnectivity.png)";
	}
	else if(type==3)
	{
		document.getElementById("divConnMap").style.background="url(images/map_roadconnectivity.png)";
	}
	else if(type==4)
	{
		document.getElementById("divConnMap").style.background="url(images/maps_feederconnectivity.png)";
	}
	else if(type==5)
	{
		document.getElementById("divConnMap").style.background="url(images/maps_hinterland.png)";
	}
	document.getElementById("divConnMap").style.display="block";
}

function hideMap()
{
	document.getElementById("overlay").style.display="none";
	document.getElementById("divConnMap").style.display="none";
}
/* paging for news*/

function loadNews()
{
	year=document.getElementById("ddlNewsYear").value;
	document.getElementById("newsYear").innerHTML = "NEWS FOR "+document.getElementById("ddlNewsYear").value;
	loadNewsData('ajax_news.php', 'p=1',year);
}
function loadNewsData(url, qStr,year)
{
  if (url.length==0)
  {
      document.getElementById("spanNews").innerHTML="";
      return;
  }
  xmlHttp=GetXmlHttpObject()
  if (xmlHttp==null)
  {
      alert ("Browser does not support HTTP Request");
      return;
  }

  url=url+"?"+qStr;
  url=url+"&year="+year+"&sid="+Math.random();
  //alert(url);
	xmlHttp.onreadystatechange=function()
	{		
		if (xmlHttp.readyState==4)
		{						
			document.getElementById("spanNews").innerHTML=xmlHttp.responseText;			
		}					
	}		
  xmlHttp.open("GET",url,true) ;
  xmlHttp.send(null);
}
/*media page functions starts here*/
function loadNextMediaImages(type,max)
{
	var curPage=0;
	if(document.getElementById("HFMediaDownPageNo_"+type))
	{
		curPage=document.getElementById("HFMediaDownPageNo_"+type).value;
		if(document.getElementById("UlMediaImages_"+type+"_"+curPage))
		{
			document.getElementById("UlMediaImages_"+type+"_"+curPage).style.display="none";
		}
		curPage=parseInt(curPage)+1;
		if(curPage>max)
		{
		 curPage=max;
		}
		document.getElementById("HFMediaDownPageNo_"+type).value=curPage;
		loadMediaPageContent(type,max);
	}
}
function loadPrevMediaImages(type,max)
{
	var curPage=0;
	if(document.getElementById("HFMediaDownPageNo_"+type))
	{
		curPage=document.getElementById("HFMediaDownPageNo_"+type).value;
		if(document.getElementById("UlMediaImages_"+type+"_"+curPage))
		{
			document.getElementById("UlMediaImages_"+type+"_"+curPage).style.display="none";
		}
		curPage=parseInt(curPage)-1;
		if(curPage<=0)
		{
		 curPage=1;
		}
		document.getElementById("HFMediaDownPageNo_"+type).value=curPage;
		loadMediaPageContent(type,max);
	}
}
function loadMediaPageContent(type,max)
{
	var curPage=0;
	if(document.getElementById("HFMediaDownPageNo_"+type))
	{
		curPage=document.getElementById("HFMediaDownPageNo_"+type).value;
	}
	if(document.getElementById("UlMediaImages_"+type+"_"+curPage))
	{
		document.getElementById("UlMediaImages_"+type+"_"+curPage).style.display="block";
		if(document.getElementById("spanMediaImagePaging_"+type))
		{
			document.getElementById("spanMediaImagePaging_"+type).innerHTML=curPage +" of "+ max;
		}
	}
}
function showMediaDownload(type,length)
{
	max=1;
	if((length>6)&&(length<=12))
	{
	 max=2;
	}
	else if((length>12)&&(length<=18))
	{
	 max=3;
	}
	else if(length>18)
	{
	 max=4;
	}
	var curPage=document.getElementById("HFMediaDownPageNo_"+type).value;
	if(document.getElementById("UlMediaImages_"+type+"_"+curPage))
	{
		document.getElementById("UlMediaImages_"+type+"_"+curPage).style.display="none";
	}
	curPage=1;
	if(document.getElementById("HFMediaDownPageNo_"+type))
	{
		document.getElementById("HFMediaDownPageNo_"+type).value=curPage;
	}
	if(document.getElementById("UlMediaImages_"+type+"_"+curPage))
	{
		document.getElementById("UlMediaImages_"+type+"_"+curPage).style.display="block";
		if(document.getElementById("spanMediaImagePaging_"+type))
		{
			document.getElementById("spanMediaImagePaging_"+type).innerHTML=curPage +" of "+ max;
		}
	}
	for(i=1;i<=length;i++)
	{
		if(type==1)
		{
		 hfName="HFcont_img";
		 chkNumber="cont_img";
		}
		else if(type==2)
		{
		 hfName="HFconnectivity_img";
		 chkNumber="connectivity_img";
		}
		else if(type==3)
		{
		 hfName="HFpeople_img";
		 chkNumber="people_img";
		}
		else if(type==4)
		{
		 hfName="HFbulkstorage_img";
		 chkNumber="bulkstorage";
		}
		else if(type==5)
		{
		 hfName="HFlandlocation_img";
		 chkNumber="landlocation";
		}
		if(document.getElementById(hfName+i))
		{
			document.getElementById(hfName+i).value=0;
			document.getElementById(chkNumber+i).className="select_download";
		}
	}
	document.getElementById("overlay").style.display="block";
	document.getElementById("overlay").style.height = parseInt(Top(document.getElementById("footer")))+68+"px";
	document.getElementById("divMediaDownload_"+type).style.visibility="visible";
}
function closeMediaDownload(type)
{
	document.getElementById("overlay").style.display="none";
	document.getElementById("divMediaDownload_"+type).style.visibility="hidden";
}	
function selectDownload(id,type)
{
	if(type==1)
	{
	 hfName="HFcont_img";
	 chkNumber="cont_img";
	}
	else if(type==2)
	{
	 hfName="HFconnectivity_img";
	 chkNumber="connectivity_img";
	}
	else if(type==3)
	{
	 hfName="HFpeople_img";
	 chkNumber="people_img";
	}
	else if(type==4)
	{
	 hfName="HFbulkstorage_img";
	 chkNumber="bulkstorage";
	}
	else if(type==5)
	{
	 hfName="HFlandlocation_img";
	 chkNumber="landlocation";
	}
	if(document.getElementById(chkNumber+id).className=="select_download")
	{
		document.getElementById(chkNumber+id).className = "select_download_active";
		document.getElementById(hfName+id).value=1;
	}
	else
	{
		document.getElementById(chkNumber+id).className="select_download";
		document.getElementById(hfName+id).value=0;
	}
}
function download(type,count,id)
{
	var p ;
	/* var p=prompt("Please enter the password to download the files?");
	
		if(p != null)
		{	if(p!="")
			 { */
				document.FrmMedia.action="mediaDB.php?type="+type+"&count="+count+"&id="+id+"&p="+p;
				document.FrmMedia.target="download_frame";
				document.FrmMedia.submit();
			/*  }
			 else
			 {
			  alert("Password required to download the file")
			 }
		} */
}
/*media  page functions ends here*/
var slideTime = 1000, topMargin;
function winOnResize() {
  xMoveTo('leftLinks', xPageX('leftColumn')+xWidth('leftColumn')+20, topMargin);
  xGetElementById('leftLinks').style.visibility = 'visible';
  winOnScroll(); // initial slide
}
function winOnScroll() {
  xSlideTo('leftLinks', xLeft('leftLinks'), xScrollTop() + topMargin, slideTime);
}
// press page starts here 
function getPressByYears()
{
	document.getElementById("pressYear").innerHTML = "NEWS FOR "+document.getElementById("ddlPressYear").value;
	var divNews=document.getElementById("spanPress");
	var xmlHttp;	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	url="ajax_press.php?year="+document.getElementById("ddlPressYear").value;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=function()
	{
		if (xmlHttp.readyState==4)
		{			
			divNews.innerHTML=xmlHttp.responseText;
		}
		else
		{
			divNews.innerHTML="loading press news....";
		}
	}			
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}
function loadPress()
{
	year=document.getElementById("ddlPressYear").value;
	document.getElementById("pressYear").innerHTML = "PRESS RELEASES FOR "+document.getElementById("ddlPressYear").value;
	loadPressData('ajax_press.php', 'p=1',year);
}
function loadPressData(url, qStr,year)
{
  if (url.length==0)
  {
      document.getElementById("spanPress").innerHTML="";
      return;
  }
  xmlHttp=GetXmlHttpObject()
  if (xmlHttp==null)
  {
      alert ("Browser does not support HTTP Request");
      return;
  }

  url=url+"?"+qStr;
  url=url+"&year="+year+"&sid="+Math.random();
  //alert(url);
	xmlHttp.onreadystatechange=function()
	{		
		if (xmlHttp.readyState==4)
		{						
			document.getElementById("spanPress").innerHTML=xmlHttp.responseText;	 			
		}					
	}		
  xmlHttp.open("GET",url,true) ;
  xmlHttp.send(null);
}
/* page for press ends here*/

/*careers page functions starts here*/
function show_jobDetails(id){
	if(document.getElementById("link_jobDetails_"+id).innerHTML=="View Job Details")
	{
		document.getElementById("link_jobDetails_"+id).innerHTML = "Close Job Details";
	}
	else
	{
		document.getElementById("link_jobDetails_"+id).innerHTML = "View Job Details";
	}
	
	animatedcollapse.toggle('career_'+id);
}
/*careers page functions ends here*/
function showGallery(type)
{
	document.getElementById("closeGallery").style.visibility = "visible";
	document.getElementById("imageControl").style.display = "block";
	document.getElementById("imgContainer").style.display = "none";
	document.getElementById("imgContainer1").style.display = "none";
	document.getElementById("imgContainer2").style.display = "none";
	document.getElementById("galContainer").className = "galleryItems";
	document.getElementById("galBulk").className = "galleryItems";
	document.getElementById("galLiquid").className = "galleryItems";
	if(type==1)
	{				
		document.getElementById("imgContainer1").style.display = "block";
		document.getElementById("galContainer").className = "galleryItems_active";
		
		slideshow1.auto=false;
		slideshow1.speed=5;		
		slideshow1.scrollSpeed=4;
		slideshow1.spacing=5;
		slideshow1.active="#fff";
		slideshow1.init("slideshow1","image1","prevImage","nextImage","imglink1");
		
	}
	else if(type==2)
	{				
		document.getElementById("imgContainer2").style.display = "block";
		document.getElementById("galBulk").className = "galleryItems_active";
		slideshow2.auto=false;
		slideshow2.speed=5;		
		slideshow2.scrollSpeed=4;
		slideshow2.spacing=5;
		slideshow2.active="#fff";
		slideshow2.init("slideshow2","image2","prevImage","nextImage","imglink2");
	}		
	
}
function closeGallery()
{
	/* document.getElementById("closeGallery").style.visibility = "hidden";
	document.getElementById("imageControl").style.display = "none";
	document.getElementById("galContainer").className = "galleryItems";
	document.getElementById("galBulk").className = "galleryItems";
	document.getElementById("galLiquid").className = "galleryItems";
	document.getElementById("imgContainer1").style.display = "none";
	document.getElementById("imgContainer2").style.display = "none";
	document.getElementById("imgContainer").style.display = "block"; */
	window.location="cargofacilities.php";
}
