
function replace_content(url) {
	Element.extend('content_container');
	new Ajax.Updater('content_container', url, { method: 'get' });
}  

function replace_navigation(url) {
	Element.extend('nav_inner');
	new Ajax.Updater('nav_inner', url, { method: 'get' });
}

function show_offices() {
	replace_navigation('content/offices/offices_menu.html');
	replace_content('content/helper/offices.html');
	show_office('amsterdam', false)
}

function show_products() {
	replace_navigation('content/products/products_menu.html');
	replace_content('content/helper/products.html');
	show_product('fixed_income');
}

function show_settlement_instructions() {
	replace_navigation('content/helper/empty.html');
	replace_content('content/settlement_instructions.html')
}

function show_company() {
	replace_navigation('content/company/company_menu.html');
	replace_content('content/company/about.html')
}

function show_company_info() {
	new Ajax.Updater('company', 'content/company/about.html', 
		{ 	method: 'get',
			onComplete: function(transport) {
				// if (show_effect == true) Effect.BlindDown('office_info');
			},
			onException: function(transport) {
				Element.update($('company'), '');
			}
		 });
}

function show_company_structure() {
	new Ajax.Updater('company', 'content/company/structure.html', 
		{ 	method: 'get',
			onComplete: function(transport) {
				// if (show_effect == true) Effect.BlindDown('office_info');
			},
			onException: function(transport) {
				Element.update($('company'), '');
			}
		 });	
}

function show_company_kyc_compliance() {
	new Ajax.Updater('company', 'content/company/kyc_compliance_information.html', 
		{ 	method: 'get',
			onComplete: function(transport) {
				// if (show_effect == true) Effect.BlindDown('office_info');
			},
			onException: function(transport) {
				Element.update($('company'), '');
			}
		 });	
}


// function show_office(city) {
// 	show_office(city, true);
// }

function show_office(city, show_effect) {
	Element.extend('selected_office');
	new Ajax.Updater('selected_office', 'content/offices/' + city + '.html', 
		{ 	method: 'get',
			onComplete: function(transport) {
				// alert("city= " + city);
				Element.extend(city);
				// Element.addClassName('amsterdam', 'selected');
			},
			onException: function(transport) {
				Element.update($('office_info'), '');
			}
		 });
		
		
}

function show_product(product) {
	// if ($('office_info') && show_effect) {Effect.BlindUp('office_info');}
	new Ajax.Updater('selected_product', 'content/products/' + product + '.html', 
		{ 	method: 'get',
			onComplete: function(transport) {
				// if (show_effect == true) Effect.BlindDown('office_info');
			},
			onException: function(transport) {
				Element.update($('product_info'), '');
			}
		 });		
}

function show_daily_info_japan() {
	// if ($('office_info') && show_effect) {Effect.BlindUp('office_info');}
	new Ajax.Updater('selected_product', 'content/products/daily_info_japanese_market.html', 
		{ 	method: 'get',
			onComplete: function(transport) {
				load_daily_info_japan();
			},
			onException: function(transport) {
				Element.update($('product_info'), '');
			}
		 });		
}

var date_fields_initialized = false;

function init_date_selection_field() {
	if (!date_fields_initialized) {	

		datePickerController.create("date");
		datePickerController.addEvent(document.getElementById("date"), "change", dateChanged);
		
		date_fields_initialized = true;
	}
}

function makeTwoChars(inp) {
        return String(inp).length < 2 ? "0" + inp : inp;
}

var initAttempts = 0;

function dateChanged(e) {
  try {
          var date_field = datePickerController.getDatePicker("date");
  } catch (err) {
          if(initAttempts++ < 10) setTimeout("dateChanged()", 50);
          return;
  }

  // Check the value of the input is a date of the correct format
  var dt = datePickerController.dateFormat(this.value, date.format.charAt(0) == "m");

  // If the input's value cannot be parsed as a valid date then return
  if(dt == 0) return;

  // At this stage we have a valid YYYYMMDD date
	alert(dt);
	
}


function file_exists(file_name){
    new Ajax.Request(file_name,   
        {
        method:'get',
        onSuccess: function(transport){   
            var response = transport.status || "no response text";   
            if(parseInt(response) == 200){
				return true;	
            } 
			return false;
        },     
        onFailure: function(){ 
			return false;
        }   
    });     
}

function load_daily_info_japan() {

	var now = new Date().format('dd/mm/yyyy');
	// now = '01/01/2010';
	var url = 'script/daily.php?date='+ now;

	new Ajax.Updater('todays_comment', url, 
		{ 	method: 'get',
			onComplete: function(transport) {
				init_date_selection_field();
			},
			onException: function(transport) {
				Element.update($('todays_comment'), 'Not available');
			}
		 });
}

function load_other_daily_info(date) {

	now = date;
	var url = 'script/daily.php?date='+ now + '&default_to_latest=true';

	new Ajax.Updater('other_comment', url, 
		{ 	method: 'get',
			onComplete: function(transport) {
			},
			onException: function(transport) {
				Element.update($('other_comment'), 'Not available');
			}
		 });
}

function search_daily_info(text, options) {

	var url = 'script/result.php?SearchString='+ text;
	if (options) {
		url = url + '&' + options;
	}

	new Ajax.Updater('search_results', url, 
		{ 	method: 'get',
			onComplete: function(transport) {
			},
			onException: function(transport) {
				Element.update($('search_results'), 'Not available');
			}
		 });
}

function show_bond_prices() {
	// if ($('office_info') && show_effect) {Effect.BlindUp('office_info');}
	new Ajax.Updater('selected_product', 'content/products/daily_info_bond_prices.html', 
		{ 	method: 'get',
			onComplete: function(transport) {
				load_daily_info_bond_prices();
			},
			onException: function(transport) {
				Element.update($('product_info'), '');
			}
		 });		
}

function load_daily_info_bond_prices() {

	var url = 'script/daily_bond_prices.php';

	new Ajax.Updater('todays_comment', url, 
		{ 	method: 'get',
			onComplete: function(transport) {
				//init_date_selection_field();
			},
			onException: function(transport) {
				Element.update($('todays_comment'), 'Not available');
			}
		 });
}
    



