/*******************************************************************************
SI NO	DATE		NAME					DESCRIPTION
1	15-Jan-07	Harshvardhan Pathak		File modified for adding energy-related functions
2	17-Feb-07	Harshvardhan Pathak		File modified for adding energy-related 'energyRss2HTML' function
3	19-Feb-07	Harshvardhan Pathak		File modified for making callback function name unique 
											in 'energyRss2HTML' function
4	08-May-07	Savitha Adiseshappa		File modified to change CMR Market Talk date display											
5       27-NOV-07   	Manish Tomar    	        File modified for adding omniture and readCookie functions
********************************************************************************/
var MSXML2_XMLHTTP = "MSXML2.XMLHTTP";
var MICROSOFT_XMLHTTP = "Microsoft.XMLHTTP";
var BROWSERTYPE_NETSCAPE = "Netscape";
var BROWSERTYPE_IE = "Microsoft Internet Explorer";

// 0 for switching off the Analytics and 1 for switching on the Analytics
var switchOnAnalytics = 1;  

// 0 for switching off the Google Analytics and 1 for switching on the Google Analytics
var switchOnGoogleAnalytics = 1;

function openerSp(url, width, height){
var x = 0, y = 0; // default values
var browser_type=navigator.appName
var browser_version=parseInt(navigator.appVersion)

if (browser_type=="Netscape"&&browser_version>=4){
  //x = window.screenX + 733;
  //y = window.screenY +235;
  x = window.screenX + 400;
  y = window.screenY +150;
} else if (browser_type=="Microsoft Internet Explorer"){
   //x = window.screenLeft + 730;
  //y = window.screenTop + 142;
  x = window.screenLeft + 540;
  y = window.screenTop + 40;
  height+=7;
}

var popup=window.open(url,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width='+width +',height='+height+',left='+x+', top='+y+',screenX='+x+', screenY='+y)
popup.focus();

}
function opener(url){
var x = 0, y = 0; // default values
var browser_type=navigator.appName
var browser_version=parseInt(navigator.appVersion)

if (browser_type=="Netscape"&&browser_version>=4){
  x = window.screenX + 20;
  y = window.screenY +20;
}else if (browser_type=="Microsoft Internet Explorer"){
  x = window.screenLeft + 20;
  y = window.screenTop + 20;
}

var popup=window.open(url,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=620,height=515,left='+x+', top='+y+',screenX='+x+', screenY='+y)
popup.focus();

}function openerEmail(url){
var x = 0, y = 0; // default values
var browser_type=navigator.appName
var browser_version=parseInt(navigator.appVersion)

if (browser_type=="Netscape"&&browser_version>=4){
  x = window.screenX + 20;
  y = window.screenY +20;
}else if (browser_type=="Microsoft Internet Explorer"){
  x = window.screenLeft + 20;
  y = window.screenTop + 20;
}

var popup=window.open(url,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=500,height=500,left='+x+', top='+y+',screenX='+x+', screenY='+y)
popup.focus();

}
function openerScroll(url){
var x = 0, y = 0; // default values

var browser_type=navigator.appName
var browser_version=parseInt(navigator.appVersion)

if (browser_type=="Netscape"&&browser_version>=4){
  x = window.screenX + 20;
  y = window.screenY +20;
}else if (browser_type=="Microsoft Internet Explorer"){
  x = window.screenLeft + 20;
  y = window.screenTop + 20;
}

//var popupPIR=window.open(url, 'PIR Corporate Profile', 'width=600,height=515,left='+x+', top='+y+',screenX='+x+', screenY='+y,'scrollbars=yes');
popupScroll=window.open(url,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=620,height=515,left='+x+', top='+y+',screenX='+x+', screenY='+y)
popupScroll.focus();

}

function openerPIR(url){
var x = 0, y = 0; // default values

var browser_type=navigator.appName
var browser_version=parseInt(navigator.appVersion)

if (browser_type=="Netscape"&&browser_version>=4){
  x = window.screenX + 20;
  y = window.screenY +20;
}else if (browser_type=="Microsoft Internet Explorer"){
  x = window.screenLeft + 20;
  y = window.screenTop + 20;
}

//var popupPIR=window.open(url, 'PIR Corporate Profile', 'width=600,height=515,left='+x+', top='+y+',screenX='+x+', screenY='+y,'scrollbars=yes');
popupPIR=window.open(url,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=620,height=515,left='+x+', top='+y+',screenX='+x+', screenY='+y)
popupPIR.focus();

}

function openerLarge(url){
var x = 0, y = 0; // default values

var browser_type=navigator.appName
var browser_version=parseInt(navigator.appVersion)

if (browser_type=="Netscape"&&browser_version>=4){
  x = window.screenX + 20;
  y = window.screenY +20;
}else if (browser_type=="Microsoft Internet Explorer"){
  x = window.screenLeft + 20;
  y = window.screenTop + 20;
}

popupLarge=window.open(url,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=800,height=600,left='+x+', top='+y+',screenX='+x+', screenY='+y)
popupLarge.focus();

}

function rss2HTML(url1){
          var windowurl = document.URL; 
          var lead_slashes = windowurl.indexOf("//");
          var domain_start = lead_slashes + 2; 
          var without_resource = windowurl.substring(domain_start, windowurl.length); 
          var next_slash = without_resource.indexOf("/"); 
          var domain = without_resource.substring(0, next_slash);
          var url = "http://"+domain+url1;
     // var url = "http://localhost/xml/search.xml?FORMAT=rss&DOCS_PER_PAGE=6&NWCODE=n/djmt and n/cmr";
      var xml = new JKL.ParseXML( url );
      xml.async( func );
      xml.parse();
     }   
          var func = function ( data ) {      // define call back function
          
          var linkArticle = "linkArticle";
             	  var title0 = data.rss.channel.item[0].title;
            	  var link0 = data.rss.channel.item[0].link;
            	  var pubdate0 = data.rss.channel.item[0].pubDate;
            	     	     	
            	   var feedbody0 = "<p><a href = "+link0+" class = "+linkArticle+">"+pubdate0+" GMT "+title0+"</a></p>";
            	   // SI NO 4 change begin
            	   if (pubdate0 == undefined) {
		  			pubdate0 = '';
		  			feedbody0 = "<p><a href = "+link0+" class = "+linkArticle+">"+pubdate0+" "+title0+"</a></p>";
					}
					// SI NO 4 change end
            	   document.getElementById("firstTitle").innerHTML=feedbody0;
            	    var desc = data.rss.channel.item[0].description;
            	    document.getElementById("descript").innerHTML=desc;
      
                 var feedbody = "";
                	   for(var i=1;i<data.rss.channel.item.length;i++){
                	       var title = data.rss.channel.item[i].title;
                	       var link =  data.rss.channel.item[i].link;
                	       var pubdate = data.rss.channel.item[i].pubDate;
                	        feedbody= feedbody+"<div><img src=/media/trans.gif width=1 height=8></div>";
                	        feedbody = feedbody+"<div><a href = "+link+" class = "+linkArticle+">"+pubdate+" GMT "+title+"</a></div>";
                	    }
  
     	    document.getElementById("wait").innerHTML="Loading ...";
            document.getElementById("myfeeds").innerHTML=feedbody;
          }
          
          
// SI NO 2 add begin
function energyRss2HTML(url1){
	var windowurl = document.URL; 
	var lead_slashes = windowurl.indexOf("//");
	var domain_start = lead_slashes + 2; 
	var without_resource = windowurl.substring(domain_start, windowurl.length); 
	var next_slash = without_resource.indexOf("/"); 
	var domain = without_resource.substring(0, next_slash);
	var url = "http://"+domain+url1;
	// var url = "http://localhost/xml/search.xml?FORMAT=rss&DOCS_PER_PAGE=6&NWCODE=n/djmt and n/cmr";
	var xml = new JKL.ParseXML( url );
	// SI NO 3 change begin
	// SI NO 3 comment begin
	/*
	xml.async( func );
	*/
	xml.async( funcEnergy );
	// SI NO 3 comment end
	// SI NO 3 change end
	xml.parse();
}   

// SI NO 3 change begin
// SI NO 3 comment begin
/*
var func = function ( data ) {      // define call back function
*/
var funcEnergy = function ( data ) {      // define call back function
// SI NO 3 comment end
// SI NO 3 change end
	var linkArticle = "linkArticle";
	var title0 = data.rss.channel.item[0].title;
	var link0 = data.rss.channel.item[0].link;
	var pubdate0 = data.rss.channel.item[0].pubDate;
	if (pubdate0 == undefined) {
		pubdate0 = '';
	}

	var feedbody0 = "<p><a href = "+link0+" class = "+linkArticle+">"+title0+"</a></p>";
	document.getElementById("firstTitle").innerHTML=feedbody0;
	var desc = data.rss.channel.item[0].description;
	document.getElementById("descript").innerHTML=desc;

	var feedbody = "";
	for(var i=1;i<data.rss.channel.item.length;i++){
		var title = data.rss.channel.item[i].title;
		var link =  data.rss.channel.item[i].link;
		var pubdate = data.rss.channel.item[i].pubDate;
		feedbody= feedbody+"<div><img src=/media/trans.gif width=1 height=1></div>";
		feedbody = feedbody+"<div><a href = "+link+" class = "+linkArticle+">"+pubdate+" "+title+"</a></div>";
	}

	document.getElementById("wait").innerHTML="Loading ...";
	document.getElementById("myfeeds").innerHTML=feedbody;
}
// SI NO 2 add end
       
 function getHTML(url){
             var http_request = false;
             if (window.XMLHttpRequest) { // Mozilla, Safari,...
                 http_request = new XMLHttpRequest();
                 if (http_request.overrideMimeType) {
                    http_request.overrideMimeType('text/xml');
                 }
              } else if (window.ActiveXObject) { // IE
                 try {
                    http_request = new ActiveXObject("MSXML2.XMLHTTP");
                 } catch (e) {
                    try {
                       http_request = new ActiveXObject("Microsoft.XMLHTTP");
                    } catch (e) {}
                 }
              }
              if (!http_request) {
                 alert('Cannot create XMLHTTP instance');
                 return false;
              }
          
              http_request.open('GET', url , 0);
              http_request.send("");
              var htmlstring =http_request.responseText;
              document.write(htmlstring);
           
  }
function MoreEquities(){
   var more = "";
   more = "<div class=verdanaElevenBlue align=right><a class=linkArticle href=/ecs/search?NWCODE=77785&COLLECTION=djnpge/archive-djnpue/archive&SEARCH_TYPE=NWCODE&LINKTEXT=Equities/Credit>More Equities/Credit</a></div>";
   document.getElementById("morelink").innerHTML=more;

}

function MoreForex(){
    var more = "";
    more = "<div class=verdanaElevenBlue align=right><a class=linkArticle href=/ecs/search?NWCODE=77786&COLLECTION=djnpge/archive-djnpue/archive&SEARCH_TYPE=NWCODE&LINKTEXT=Debt/Forex>More Debt/Forex</a></div>";
    document.getElementById("morelink").innerHTML=more;

}         

/* SI NO 1 add begin */

// function to open help page for energy
function openEnergyHelp(url, width, height){
var x = 0, y = 0; // default values

var popup=window.open(url,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width='+width +',height='+height+',left='+x+', top='+y+',screenX='+x+', screenY='+y)
popup.focus();

}

// function to get response html for energy help page
 function getResponseHTML(url){
             var http_request = false;
             if (window.XMLHttpRequest) { // Mozilla, Safari,...
                 http_request = new XMLHttpRequest();
                 if (http_request.overrideMimeType) {
                    http_request.overrideMimeType('text/xml');
                 }
              } else if (window.ActiveXObject) { // IE
                 try {
                    http_request = new ActiveXObject(MSXML2_XMLHTTP);
                 } catch (e) {
                    try {
                       http_request = new ActiveXObject(MICROSOFT_XMLHTTP);
                    } catch (e) {}
                 }
              }
              if (!http_request) {
                 alert('Error in getting response');
                 return false;
              }
          
              http_request.open('GET', url , 0);
              http_request.send("");
              var htmlstring =http_request.responseText;
              return htmlstring;
  }

  
  
  
  // function to get the feed for energy breaking news
  function rss2HTMLEnergy(url1){
	  var windowurl = document.URL; 
	  var lead_slashes = windowurl.indexOf("//");
	  var domain_start = lead_slashes + 2; 
	  var without_resource = windowurl.substring(domain_start, windowurl.length); 
	  var next_slash = without_resource.indexOf("/"); 
	  var domain = without_resource.substring(0, next_slash);
	  var url = "http://"+domain+url1; // "http://localhost/xml/search.xml?FORMAT=rss&DOCS_PER_PAGE=6&NWCODE=n/djmt and n/cmr"
      var xml = new JKL.ParseXML( url );
      xml.async( func2 );
      xml.parse();
     }   
          var func2 = function ( data ) {      // define call back function
			var linkArticle = "linkArticle";
			var title0 = data.rss.channel.item[0].title;
			var link0 = data.rss.channel.item[0].link;
			var pubdate0 = data.rss.channel.item[0].pubDate;
			            	     	     	
			var feedbody0 = "<p><a href = "+link0+" class = "+linkArticle+">"+pubdate0+" GMT "+title0+"</a></p>";
			document.getElementById("firstTitle").innerHTML=feedbody0;
			var desc = data.rss.channel.item[0].description;
			document.getElementById("descript").innerHTML=desc;
			      
			var feedbody = "";
			for(var i=1;i<data.rss.channel.item.length;i++){
			var title = data.rss.channel.item[i].title;
			var link =  data.rss.channel.item[i].link;
			var pubdate = data.rss.channel.item[i].pubDate;
			feedbody= feedbody+"<div><img src=/media/trans.gif width=1 height=8></div>";
			feedbody = feedbody+"<div><a href = "+link+" class = "+linkArticle+">"+pubdate+" GMT "+title+"</a></div>";
			}
			  
			document.getElementById("wait").innerHTML="Loading ...";
			document.getElementById("myfeeds").innerHTML=feedbody;
          }
  
  /* SI NO 1 add end */

//function to read the cookie for getting the username
function readCookie(name) {
  	var nameEQ = name + "=";
  	var ca = document.cookie.split(';');
  	for(var i=0;i < ca.length;i++) {
  		var c = ca[i];
  		while (c.charAt(0)==' ') c = c.substring(1,c.length);
  		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  	}
  	return null;
}

//function for using the google analytics collect data
function googleAnalytics(pagename,user){
  if (typeof(pageTracker) == 'object') {
	pageTracker._trackPageview('/'+pagename);
	pageTracker._setVar('User='+user);
  }
}

//function for using the omniture site to collect data
function omniture(pagename,server,subsite,headline,type){
var user = readCookie("REMOTE_USER").substring(5);
if(switchOnGoogleAnalytics){
googleAnalytics(pagename,user);
}
if(switchOnAnalytics){
<!--
/* You may give each page an identifying name, server, and channel on
the next lines. */
s.pageName= pagename
s.server=""
s.channel=subsite
s.pageType=""
s.prop1=""
s.prop2=""
s.prop3=""
s.prop4=headline
s.prop5=type
s.prop6=user;
s.prop7=""
/* E-commerce Variables */
s.campaign=""
s.state=""
s.zip=""
s.events=""
s.products=""
s.purchaseID=""
s.eVar1=""
s.eVar2=""
s.eVar3=""
s.eVar4=""
s.eVar5=""

var s_code=s.t();
if(s_code) document.write(s_code)
}
}

//function for retreiving the subsite from url
function retrieveSubsiteFromURL(){
var channel = window.location.href.split("/")[3];
var sub = window.location.href.split("/")[4];
var channels = "cmr,energy,ge,acs,ecs,ts,npge,tsge,np,top,rtr,gm,rbs,npgm,old";
if(!(channels.indexOf(channel) >=0)){
channel = "nae";
}
if(channel=="top"){
channel = "ts";
}
if((channels.indexOf(sub) >=0) && channel=="gm"){
if(sub=="np"){
channel="npgm";
}
}
return channel;
}

//Function to open links in new window 
function OpenWindow(url)
    {
        var cWindow = window.open(url, "", "resizable=1, scrollbars=1,status=1,menubar=1,toolbar=1,location=1");
        if (cWindow) {
    		cWindow.focus();
        }
	   
    }

//Function to retreive feed for nae market promo
  function naeRss2HTML(url1){
	document.getElementById("firstTitle").innerHTML='';
	document.getElementById("myfeeds").innerHTML='';
	document.getElementById("moreLinkDiv").style.visibility="hidden";
	document.getElementById("moreLinkDiv").style.display="none";
	document.getElementById("wait").style.visibility="visible";
	document.getElementById("wait").style.display="block";

	var windowurl = document.URL; 
	var lead_slashes = windowurl.indexOf("//");
	var domain_start = lead_slashes + 2; 
	var without_resource = windowurl.substring(domain_start, windowurl.length); 
	var next_slash = without_resource.indexOf("/"); 
	var domain = without_resource.substring(0, next_slash);
	var url = "http://"+domain+url1;
	var xml = new JKL.ParseXML( url );
	xml.async( funcNAE );
	xml.parse();
}   
var funcNAE = function ( data ) {      // define call back function
	var linkArticle = "linkArticle";
	if (data.rss.channel.item.length >1) {
		var title0 = data.rss.channel.item[0].title;
		var link0 = data.rss.channel.item[0].link;
	} else {
		var title0 = data.rss.channel.item.title;
		var link0 = data.rss.channel.item.link;	
	}
	

	var feedbody0 = "<p><a href = "+link0+" class = "+linkArticle+">"+title0+"</a></p>";
	document.getElementById("firstTitle").innerHTML=feedbody0;

	var feedbody = "";
	for(var i=1;i<data.rss.channel.item.length;i++){
		var title = data.rss.channel.item[i].title;
		var link =  data.rss.channel.item[i].link;
		feedbody= feedbody+"<div><img src=/media/trans.gif width=1 height=1></div>";
		feedbody = feedbody+"<div><a href = "+link+" class = "+linkArticle+">"+title+"</a></div>";
	}

	document.getElementById("myfeeds").innerHTML=feedbody;
	document.getElementById("wait").style.visibility="hidden";
	document.getElementById("wait").style.display="none";
	document.getElementById("moreLinkDiv").style.visibility="visible";
	document.getElementById("moreLinkDiv").style.display="block";
}