var image_ok = (document.images) ? true : false
var cached_images = new Array();
var a_opened_window
var b_opened_window
function runOnLoad(){
}

// Image Functions
function ev2JsImg(image_name, image_off_src, image_on_src, status_text){
	if (image_ok){
		this.name = image_name;
		this.on = new Image();
		this.on.src = image_on_src;
		this.off = new Image();
		this.off.src = image_off_src;
		if (status_text){
			this.text = status_text;
		}else{
			this.text = false;
		}
	}
}

function addImage(image_name, image_off_src, image_on_src, status_text){
	if (image_ok){
		cached_images[image_name] = new ev2JsImg(image_name, image_off_src, image_on_src, status_text);
	}
}

function showOnImage(image_object){
	var image_name = image_object.name
	if (image_ok){
		document.images[image_name].src = cached_images[image_name].on.src;
		if (cached_images[image_name].text){
			status = cached_images[image_name].text;
		}
	}
}

function showOffImage(image_object){
	var image_name = image_object.name
	if (image_ok){
		document.images[image_name].src = cached_images[image_name].off.src;
		if (cached_images[image_name].text.length){
			status = "";
		}
	}
}

function openWindow(url, width, height, title){
//	if(!a_opened_window || a_opened_window.closed){
		var window_attributes = "height=" + height + ",width=" + width + ",resizable=yes,scrollbars=yes"
		if(openWindow.arguments.length > 4){
			var i=4
			for(i; i < openWindow.arguments.length; i++){
				window_attributes += openWindow.arguments[i]
			}
		}
    if(!title || title.length == 0){title = "subwindow"}
		a_opened_window = window.open(url, title, window_attributes)
//	}else{
//		a_opened_window.location.href = url
		a_opened_window.focus()
//	}
}

function printPage(){
	var print_url = document.location.pathname
	var search_string = ""
	var new_search_string = ""
	var go_standard = true
	if(document.location.search.length > 0){
		search_string = document.location.search
		//check for a request id and remove it if it exists
		if(search_string.indexOf("_requestid") != -1){
			new_search_string = search_string.substring(0, search_string.indexOf("_requestid")-1)
			search_string = search_string.substring(search_string.indexOf("_requestid"))
			if (search_string.indexOf("&") != -1){
				new_search_string += search_string.substring(search_string.indexOf("&"))
			}
			search_string = new_search_string
		}
		//check for a DARGS and remove it if it exists
		if(search_string.indexOf("_DARGS") != -1){
			new_search_string = search_string.substring(0, search_string.indexOf("_DARGS")-1)
			search_string = search_string.substring(search_string.indexOf("_DARGS"))
			if (search_string.indexOf("&") != -1){
				new_search_string += search_string.substring(search_string.indexOf("&"))
			}
			search_string = new_search_string
		}
	}
	if(search_string.length > 0){
		print_url += search_string
		print_url += "&output=print"
	}else{
		print_url += "?output=print"
	}
  if(print_url.indexOf("historical_unit_prices") > -1){
    var the_form = document.up;
    checkDate(the_form);
		print_url += "&fundID=" + the_form.fundID[the_form.fundID.selectedIndex].value;
		print_url += "&countryId=" + the_form.countryId.value;
    print_url += "&from_day=" + the_form.from_day[the_form.from_day.selectedIndex].value;
    print_url += "&from_month=" + the_form.from_month[the_form.from_month.selectedIndex].value;
    print_url += "&from_year=" + the_form.from_year[the_form.from_year.selectedIndex].value;
    print_url += "&to_day=" + the_form.to_day[the_form.to_day.selectedIndex].value;
    print_url += "&to_month=" + the_form.to_month[the_form.to_month.selectedIndex].value;
    print_url += "&to_year=" + the_form.to_year[the_form.to_year.selectedIndex].value;
		print_url += "&version=" + the_form.version.value;
		print_url += "&show=" + the_form.show.value;
		print_url += "&fromDt=" + the_form.fromDt.value;
		print_url += "&toDt=" + the_form.toDt.value;
  }
	if((print_url.indexOf("fund_detail") != -1) && control_form){
		var the_form = document.account
		if(c_account && (the_form.client_account.selectedIndex != 0)){
			print_url += "&clientAcctID=" + the_form.client_account[the_form.client_account.selectedIndex].value
		}
		if(the_form.as_of_date.selectedIndex != 0){
			print_url += "&asofDate=" + the_form.as_of_date[the_form.as_of_date.selectedIndex].value
		}
	}
	if(print_url.indexOf("security_holdings") != -1){
		go_standard = false
	}
	if((print_url.indexOf("holdings") != -1) && (print_url.indexOf("security") == -1)){
		var the_form = document.account
		if(the_form.currency.selectedIndex != 0 && search_string.indexOf("currency") == -1){
			print_url += "&currency=" + the_form.currency[the_form.currency.selectedIndex].value
		}
		if(print_url.indexOf("detail") != -1){
			if(search_string.indexOf("accountId") == -1){
				print_url += "&accountId=" + the_form.client_account[the_form.client_account.selectedIndex].value
				print_url += "&asOfDate=" + the_form.asOfDate.value
			}
		}
	}
	if((print_url.indexOf("transaction_detail") != -1 || print_url.indexOf("income_detail") != -1)){
    var the_form = document.account
		print_url += "&accountId=" + the_form.client_account[the_form.client_account.selectedIndex].value
		print_url += "&startDate=" + the_form.startDate.value
		print_url += "&endDate=" + the_form.endDate.value
		if(print_url.indexOf("income_detail") != -1 ){
			if(the_form.currency.selectedIndex != 0 && search_string.indexOf("currency") == -1){
				print_url += "&currency=" + the_form.currency[the_form.currency.selectedIndex].value
			}
			if(the_form.version.selectedIndex == 1){
				print_url += "&version=DETAIL"
			}
		}
	}
  if(print_url.indexOf("progress_report") != -1){
    var the_form = document.progress_report
		print_url += "&accountId=" + the_form.client_account[the_form.client_account.selectedIndex].value
    print_url += "&startDate=" + the_form.startDate.value
		print_url += "&endDate=" + the_form.endDate.value
    print_url += "&version=" + the_form.version[the_form.version.selectedIndex].value
  }
  if(print_url.indexOf("client_performance") != -1){
    var the_form = document.performance
		print_url += "&asOfDate=" + the_form.asOfDate.value
  }
  if(print_url.indexOf("seclending_summary") != -1){
    var the_form = document.account;
    print_url += "&client_account=" + the_form.client_account[the_form.client_account.selectedIndex].value;
    print_url += "&asOfDate=" + the_form.asOfDate[the_form.asOfDate.selectedIndex].value;
  }
  if(print_url.indexOf("/performance.jhtml") != -1){
  	if(print_url.indexOf("asOfDate") != -1){
    	var the_form = document.account;
	  	print_url += "&asOfDate=" + the_form.asOfDate.value;	
  	}
  }
  if(print_url.indexOf("client_perf_attribution") != -1){
    var the_form = document.account
		print_url += "&accountId=" + the_form.client_account[the_form.client_account.selectedIndex].value
    print_url += "&showPeriod=" + the_form.showPeriod[the_form.showPeriod.selectedIndex].value
    print_url += "&asOfDate=" + the_form.asOfDate[the_form.asOfDate.selectedIndex].value
  }
	if(print_url.indexOf("crossing") != -1 && search_string.length <= 13){
		var the_form = document.account
		print_url += "&accountId=" + the_form.client_account[the_form.client_account.selectedIndex].value
		if(the_form.crossing_asOfDate.selectedIndex != 0){
			print_url += "&crossing_asOfDate=" + the_form.crossing_asOfDate[the_form.crossing_asOfDate.selectedIndex].value
		}
	}
	if(go_standard){
		openWindow(print_url, 700, 550 , "printable", ",menubar=yes")
	}else{
		var window_attributes = "height=700,width=600,resizable=yes,scrollbars=yes,menubar=yes"
		b_opened_window = window.open(print_url, "", window_attributes)
	}
}

function infoPage(infoarea){
	var info_url = "/help/info.jhtml?infoarea=" + infoarea
	openWindow(info_url, 400, 450 , "info")
}

function accountPage(list_object){
	var next_page = ""
if(list_object[list_object.selectedIndex].value == "Holdings Detail"){next_page = "holdings_detail.jhtml"}
if(list_object[list_object.selectedIndex].value == "Transactions"){next_page = "transaction_detail.jhtml"}
if(list_object[list_object.selectedIndex].value == "Income"){next_page = "income_detail.jhtml"}
if(list_object[list_object.selectedIndex].value == "Crossing Savings"){next_page = "crossing_savings.jhtml"}
if(list_object[list_object.selectedIndex].value == "Progress Report"){next_page = "/accounts/accounts/progress_report/progress_report.jhtml"}
	next_page += list_object.name
	document.location.href = next_page
}

// Preload Primary Navigation
addImage("ai", "/images/navigation/en/primary/account_information.gif", "/images/navigation/en/primary/account_information_on.gif")
addImage("ps", "/images/navigation/en/primary/products_and_services.gif", "/images/navigation/en/primary/products_and_services_on.gif")
addImage("ps_eu", "/images/navigation/en/primary/strategies_and_services.gif", "/images/navigation/en/primary/strategies_and_services_on.gif")
addImage("kc", "/images/navigation/en/primary/knowledge_centre.gif", "/images/navigation/en/primary/knowledge_centre_on.gif")
addImage("kc_usa", "/images/navigation/en/primary/usa_knowledge_center.gif", "/images/navigation/en/primary/usa_knowledge_center_on.gif")
addImage("pr", "/images/navigation/en/primary/press.gif", "/images/navigation/en/primary/press_on.gif")
addImage("ab", "/images/navigation/en/primary/about_bgi.gif", "/images/navigation/en/primary/about_bgi_on.gif")
// Preload Global Navigation
addImage("home", "/images/navigation/en/global/home.gif", "/images/navigation/en/global/home_on.gif")
addImage("login", "/images/navigation/en/global/login.gif", "/images/navigation/en/global/login_on.gif")
addImage("logout", "/images/navigation/en/global/logout.gif", "/images/navigation/en/global/logout_on.gif")
addImage("ctak_bgi", "/images/navigation/en/global/contact_bgi.gif", "/images/navigation/en/global/contact_bgi_on.gif")
addImage("serch", "/images/navigation/en/global/search.gif", "/images/navigation/en/global/search_on.gif")
addImage("change_region", "/images/navigation/en/global/change_region.gif", "/images/navigation/en/global/change_region_on.gif")
addImage("my_profile", "/images/navigation/en/global/my_profile.gif", "/images/navigation/en/global/my_profile_on.gif")
addImage("legal", "/images/navigation/en/global/legal.gif", "/images/navigation/en/global/legal_on.gif")
addImage("help", "/images/navigation/en/global/help.gif", "/images/navigation/en/global/help_on.gif")
