
var importerServer = location.host;

// For testing environment only //
//importerServer = 'localhost:8080';
// For testing environment only //

function showOptional(doc){
	var value=doc.options[doc.selectedIndex].value 
	
	if(value == 'NMCpressrelease'){
		document.getElementById('pressReleasesOptional').style.visibility = 'hidden';
	}else {
		document.getElementById('pressReleasesOptional').style.visibility = 'visible';
	}
} 


/////////////////////////////////////////////////////////////////////////////////////
// General Functions used in Ajax calls
/////////////////////////////////////////////////////////////////////////////////////
var objHTTP  = null;

function getXML(serverURL, functionName) {
  	objHTTP = new ActiveXObject('Microsoft.XMLHTTP');
  	objHTTP.onreadystatechange = functionName;
  	objHTTP.open('GET', serverURL, true);
  	objHTTP.send();
}	

// AJAX Function using DOJO
function getXMLwDojo(xmlUrl, functionName) {
    var bindArgs = { 
      url       : xmlUrl,
      error     : function(type, data, evt){ 
                  alert('An error occurred on function: "' + functionName + '"\nwhen trying to get XML content from: "' + xmlUrl + '"');
                },
      mimetype  : "text/plain"
    };
    
    var req = dojo.io.bind(bindArgs);
    dojo.event.connect(req, "load", functionName);
}
/////////////////////////////////////////////////////////////////////////////////////
// General Functions used in Ajax calls
/////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////////////
// Get the Amadeus in News list from Domino for the Corp Site - page x6231
/////////////////////////////////////////////////////////////////////////////////////
var amadeusInNewsStyleSheet = null;
var amadeusInNewsURLToProcess = '';

function listAmadeusInNews(){
	document.getElementById('divBack').style.height = '0px';
	document.getElementById('divBack').style.visibility = 'hidden';
	amadeusInNewsURLToProcess = 'http://'+ importerServer +'/Corpweb/CorInfV1.nsf/XML_AmainnewsPubArc?Openview&count=100';
	getXMLwDojo('http://'+ importerServer +'/amadeus/Stylesheets/importer/amadeusInNews.xsl', 'getAmadeusInNewsStyleSheet');
	// For testing environment only //
	//amadeusInNewsURLToProcess = 'http://82.150.225.80/Corpweb/CorInfV1.nsf/XML_AmainnewsPubArc?Openview&count=100';
	//getXMLwDojo('http://localhost:8080/cms-control/amadeusInNews.xsl', 'getAmadeusInNewsStyleSheet');
	// For testing environment only //
}

function getAmadeusInNewsStyleSheet(type, data, evt) {
	amadeusInNewsStyleSheet = dojo.dom.createDocumentFromText(data);
	getXMLwDojo(amadeusInNewsURLToProcess, 'updateAmadeusInNews');
}	

function updateAmadeusInNews(type, data, evt) {
	var xmlstream = data.substring(data.indexOf('<column'), data.indexOf('</column>') + 9);
	var dom       = dojo.dom.createDocumentFromText(xmlstream);

	// Transform
	if(document.implementation && document.implementation.createDocument){
		// *** Mozilla
		var xsltProcessor = new XSLTProcessor();
		xsltProcessor.importStylesheet(amadeusInNewsStyleSheet);
		// *** transform
		var resultDocument = xsltProcessor.transformToFragment(dom, document);
		document.getElementById('mainDisplayGeneralNews').innerHTML = '';
		document.getElementById('mainDisplayGeneralNews').appendChild(resultDocument);
	}
	else if(window.ActiveXObject){
		// *** IE
		// *** transform
		document.getElementById('mainDisplayGeneralNews').innerHTML = dom.transformNode(amadeusInNewsStyleSheet);
	}
}

function goBackAmadeusInNews(){
	listAmadeusInNews();
}
/////////////////////////////////////////////////////////////////////////////////////
// Get the Amadeus in News list from Domino for the Corp Site - page x6231
/////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////////////
// Get the World Markets list from Domino for the Corp Site - page x7517
/////////////////////////////////////////////////////////////////////////////////////
var marketsStyleSheet = null;
var marketsURLToProcess = '';

function listWorldMarkets(letter){
	marketsURLToProcess = 'http://'+ importerServer +'/NMCDirEd.nsf/WebContactListXML2?OpenView&count=2000&RestrictToCategory=' + letter;
	getXMLwDojo('http://'+ importerServer +'/amadeus/Stylesheets/importer/offices.xsl', 'getMarketsStyleSheet');
	// For testing environment only //
	//marketsURLToProcess = 'http://82.150.225.80/NMCDirEd.nsf/WebContactListXML2?OpenView&count=2000&RestrictToCategory=' + letter;
	//getXMLwDojo('http://localhost:8080/cms-control/offices.xsl', 'getMarketsStyleSheet');
	// For testing environment only //
}

function getMarketsStyleSheet(type, data, evt) {
	marketsStyleSheet = dojo.dom.createDocumentFromText(data);
	getXMLwDojo(marketsURLToProcess, 'updateMarkets');
}	

function updateMarkets(type, data, evt) {
	var xmlstream = data.substring(data.indexOf('<column'), data.indexOf('</column>') + 9);
	var dom       = dojo.dom.createDocumentFromText(xmlstream);

	// Transform
	if(document.implementation && document.implementation.createDocument){
		// *** Mozilla
		var xsltProcessor = new XSLTProcessor();
		xsltProcessor.importStylesheet(marketsStyleSheet);
		// *** transform
		var resultDocument = xsltProcessor.transformToFragment(dom, document);
		document.getElementById('mainDisplayMarkets').innerHTML = '';
		document.getElementById('mainDisplayMarkets').appendChild(resultDocument);
	}
	else if(window.ActiveXObject){
		// *** IE
		// *** transform
		document.getElementById('mainDisplayMarkets').innerHTML = dom.transformNode(marketsStyleSheet);
	}
}
/////////////////////////////////////////////////////////////////////////////////////
// Get the World Markets list from Domino for the Corp Site - page x7517
/////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////////////
// Get the Offices list from Domino for the Corp Site - page x7516
/////////////////////////////////////////////////////////////////////////////////////
var officesStyleSheet = null;
var officesURLToProcess = '';

function listoffices(){
	officesURLToProcess = 'http://'+ importerServer +'/NMCDirEd.nsf/WebRegionListXML?OpenView&Count=1000';
	getXMLwDojo('http://'+ importerServer +'/amadeus/Stylesheets/importer/offices.xsl', 'getOfficesStyleSheet');
	// For testing environment only //
	//officesURLToProcess = 'http://82.150.225.80/NMCDirEd.nsf/WebRegionListXML?OpenView&Count=1000';
	//getXMLwDojo('http://localhost:8080/cms-control/offices.xsl', 'getOfficesStyleSheet');
	// For testing environment only //
}

function getOfficesStyleSheet(type, data, evt) {
	officesStyleSheet = dojo.dom.createDocumentFromText(data);
	getXMLwDojo(officesURLToProcess, 'updateOffices');
}	

function updateOffices(type, data, evt) {
	var xmlstream = data.substring(data.indexOf('<column'), data.indexOf('</column>') + 9);
	var dom       = dojo.dom.createDocumentFromText(xmlstream);

	// Transform
	if(document.implementation && document.implementation.createDocument){
		// *** Mozilla
		var xsltProcessor = new XSLTProcessor();
		xsltProcessor.importStylesheet(officesStyleSheet);
		// *** transform
		var resultDocument = xsltProcessor.transformToFragment(dom, document);
		document.getElementById('mainDisplayOffices').innerHTML = '';
		document.getElementById('mainDisplayOffices').appendChild(resultDocument);
	}
	else if(window.ActiveXObject){
		// *** IE
		// *** transform
		document.getElementById('mainDisplayOffices').innerHTML = dom.transformNode(officesStyleSheet);
	}
}
/////////////////////////////////////////////////////////////////////////////////////
// Get the Offices list from Domino for the Corp Site - page x7516
/////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////////////
// Get the Press Releases list from Domino for the Corp Site - page x5088
/////////////////////////////////////////////////////////////////////////////////////
var newsStyleSheet = null;
var newsURLToProcess = '';

function listNews(){
	document.getElementById('divBack').style.height = '0px';
	document.getElementById('divBack').style.visibility = 'hidden';
	
	var year = document.frmNews.lstYears.options[document.frmNews.lstYears.selectedIndex].value;
	// Forced to query only Global Press Releases
	//var distribution = document.frmNews.lstDistribution.options[document.frmNews.lstDistribution.selectedIndex].value;
	var distribution = 'Pressrelease';
	// Forced to query only Global Press Releases
	var pressreleasesType = document.frmNews.lstPressreleasesType.options[document.frmNews.lstPressreleasesType.selectedIndex].value;
	var language = document.frmNews.lstLanguage.options[document.frmNews.lstLanguage.selectedIndex].value;
	
	var query='';
	if(distribution == 'NMCpressrelease'){
		query=year+distribution+language;
	}else {
		query=year+distribution+pressreleasesType+language;
	}
	newsURLToProcess = 'http://'+ importerServer +'/corpweb/newsitem2.nsf/XMLSearch_cms?openview&restricttocategory=' + query;
	getXMLwDojo('http://'+ importerServer +'/amadeus/Stylesheets/importer/newsevents.xsl', 'getNewsStyleSheet');
	// For testing environment only //
	//newsURLToProcess = 'http://82.150.225.80/corpweb/newsitem2.nsf/XMLSearch_cms?openview&restricttocategory=' + query;
	//getXMLwDojo('http://localhost:8080/cms-control/newsevents.xsl', 'getNewsStyleSheet');
	// For testing environment only //
}


function getNewsStyleSheet(type, data, evt) {
	newsStyleSheet = dojo.dom.createDocumentFromText(data);
	getXMLwDojo(newsURLToProcess, 'updateNews');
}	

function updateNews(type, data, evt) {
	var xmlstream = data.substring(data.indexOf('<docs'), data.indexOf('</docs>') + 7);
	var dom       = dojo.dom.createDocumentFromText(xmlstream);

	// Transform
	if(document.implementation && document.implementation.createDocument){
		// *** Mozilla
		var xsltProcessor = new XSLTProcessor();
		xsltProcessor.importStylesheet(newsStyleSheet);
		// *** transform
		var resultDocument = xsltProcessor.transformToFragment(dom, document);
		document.getElementById('mainDisplayGeneralNews').innerHTML = '';
		document.getElementById('mainDisplayGeneralNews').appendChild(resultDocument);
	}
	else if(window.ActiveXObject){
		// *** IE
		// *** transform
		document.getElementById('mainDisplayGeneralNews').innerHTML = dom.transformNode(newsStyleSheet);
	}
}

function displayNews(serverURL){
	document.getElementById('divBack').style.height = '50px';
	document.getElementById('divBack').style.visibility = 'visible';
	newsURLToProcess = serverURL;
	getXMLwDojo('http://'+ importerServer +'/amadeus/Stylesheets/importer/newevent.xsl', 'getNewsStyleSheet');
	// For testing environment only //
	//getXMLwDojo('http://localhost:8080/cms-control/newevent.xsl', 'getNewsStyleSheet');
	// For testing environment only //
}

function displayRSSNews(serverURL){
	newsURLToProcess = serverURL;
	getXMLwDojo('http://'+ importerServer +'/amadeus/Stylesheets/importer/newevent.xsl', 'getNewsStyleSheet');
}

function goBack(){
	listNews();
}
/////////////////////////////////////////////////////////////////////////////////////
// Get the Press Releases list from Domino for the Corp Site - page x5088
/////////////////////////////////////////////////////////////////////////////////////

	
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
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_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;
  keepSelected();
}

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];}
}

function MM_applySugSegment(position, name, segment) { //v1.0
	MM_swapImage('Image' + position,'','Images/tabs/en/tab_' +segment+ '_' + name + '_on.gif', position);

}

function popup(page,width,height){
			window.open(page, 'Amadeus', ' width='+width+', height='+height+', left=20, top=20, resizable=no, location=no, scrollbars=no, status=no, menubar=no');
}

//function MM_openBrWindow(theURL,winName,features) { //v2.0
//  window.open(theURL,winName,features);
//}

var blnWinOpen = false;
var winToOpen;
function MM_openBrWindow(theURL,winName,features) { //v3.0
	if(blnWinOpen && !winToOpen.closed) {
		winToOpen.focus();
	}
	else {
		winToOpen = null;
		winToOpen = window.open(theURL,winName,features);
		blnWinOpen = true;
		winToOpen.opener = this;
	}
}

/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////


// Function for Check URLs for combo boxes
// Author: jnavarro
// Date: 10/03/2009
//OLD Function without OMNITURE actions
// Date: 24/01/2006
function check_url(url) {
	var prefix = 'http://www.amadeus.com/';
	if (url.match('http://') != null)
		prefix = '';
	else if (url.match('https://') != null)
		prefix = '';
	else if (url.match('#') != null)
		prefix = '';
	document.location.href = prefix + url;
}
//NEW Function with OMNITURE actions
function check_url_o(url,obj,rs) {
	// Omniture - START
	var ss;
	ss=s_gi(rs);
	ss.linkTrackVars='prop21';
	ss.prop21=url;
	ss.tl(obj,'e','Link to Segment Site');
	// Omniture - END
	
	var prefix = 'http://www.amadeus.com/';
	if (url.match('http://') != null)
		prefix = '';
	else if (url.match('https://') != null)
		prefix = '';
	else if (url.match('#') != null)
		prefix = '';
	document.location.href = prefix + url;
}


// Functions for Random images
// Author: jnavarro
// Date: 12/01/2006

// Set up the image files to be used.
var theImages = new Array();
var whichImage = 0;

// Pre-load the image array
function loadImages(imgsPrefix, imgsExt, imgNum){
	var indexStr = 01;
	var j = 0;
	var p = imgNum;
	for (i = 0; i < p; i++){
	   var j = i + 1;
	   if (j<10) indexStr = '0' + j;
	   theImages[i] = new Image();
	   theImages[i].src = imgsPrefix + indexStr + imgsExt;
	}
	whichImage = Math.round(Math.random()*(p-1));
}

function showImage(objName, imgNum){
	var obj = new Image();
	obj = document.getElementById(objName);
	var path = obj.src.substring(0, (obj.src.lastIndexOf('/') + 1));
	var objName = obj.src.substring((obj.src.lastIndexOf('/') + 1), obj.src.lenght);
	var prefix = path + objName.substring(0, (objName.lastIndexOf('.') - 2));
	var suffix = objName.substring(objName.lastIndexOf('.'), objName.lenght);
	loadImages(prefix, suffix, imgNum);
	obj.src = theImages[whichImage].src;
}
// END Functions for Random images


// Code to customize the Hitbox campaign
function hitboxCampaign(){
	var query = window.location.search.substring(1);
	var parms = query.split('&');
	for (var i=0; i<parms.length; i++) {
		var pos = parms[i].indexOf('=');
		if (pos > 0) {
			var key = parms[i].substring(0,pos);
			if (key == 'param') {
				_cp = parms[i].substring(pos+1);
				for (var j =0; j < document.links.length; j++) {
					if (document.links[j].href.indexOf('param') == -1) {
						if (document.links[j].href.indexOf('?')  == -1) {
							document.links[j].href = document.links[j].href + '?param=' + _cp;
						} else {
							document.links[j].href = document.links[j].href + '&param=' + _cp;
						}	  
					}
				}
				break;
			}
		}
	}
}	
// END Code to customize the Hitbox campaign

// Send to a Friend
function sendToAFriend( stafpage ){
	var stafurl = stafpage + '?referrer=' + document.location;
	document.location = stafurl;
}
// END Send to a Friend

// Bookmark Page
function addToFavorites() {
	if (document.all) {
             // For IE
             window.external.AddFavorite(location.href, document.title);
         }
        else if (window.sidebar) {
             // For Firefox
             window.sidebar.addPanel(document.title, location.href, '');
        }
}
// END Bookmark Page

/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////

