/*Open in a newWindow as the target=_blank */
function newWindow(url) {
	window.open(url);
}


/*deprecated */

function openWin(url) {
	window.open(url);
}


function openBlank(url) {
	window.open(url);
	return false;
}

/* Function to open a popup (no status bar, no address bar) 
 * The values width and height are optional.
 * Width is multiple of 190px. 30px is added for the scroll bar
 */
function openPopup(url, width, height) {
	var win;
	if (width == null)
		width = 3;
	if (height == null)
		height = 300;
	width = width * 190 + 30;
	win = window.open(url,'IDB','width='+width+',height='+height+',status=no,resizable=yes,scrollbars=yes');
	win.focus();
}

function openModal(divID) {
	$("#"+divID).show();
	$("body").prepend("<div id='modalContent' style='top:40%;left:40%;position:absolute;z-index:100;'><h1>test</h1></div> ");
	$("body").prepend("<div id='modalBoxBackground' style='height:"+$(document).height()+"px;width:100%; z-index:10; background-color:#999999; position:absolute; top:1px; left:1px; opacity: 0.2;filter: alpha(opacity=20)'></div>");
}

function closeModal(divID) {
	$("#"+divID).hide();
	$("#modalBoxBackground").remove();
}


function changeSelect(sourceID, targetID, arrValues) {
	var selectedItem = $('#'+sourceID).get(0).selectedIndex;
	$('#'+targetID).empty();
	for(i=0;i<arrValues[selectedItem].length;i++){
		$('#'+targetID).append("<option value="+arrValues[selectedItem][i]+">"+arrValues[selectedItem][i+1]+"</option>");
		i++;
	}
}


/* JQuery function to clear all values of a form. Usage: $("#form").clearForm()*/
$.fn.clearForm = function() {
  return this.each(function() {
	var type = this.type, tag = this.tagName.toLowerCase();
	if (tag == 'form')
	  return $(':input',this).clearForm();
	if (type == 'text' || type == 'password' || tag == 'textarea')
	  this.value = '';
	else if (type == 'checkbox' || type == 'radio')
	  this.checked = false;
	else if (tag == 'select')
	  this.selectedIndex = 0;
  });
};


/* ------------------
 * jQuery function to show/hide topics drop down on global navigation
 *	This function is called automatically
 */
 
$(document).ready(function() {
	$('#GlobalNav3, #GlobalNavTopicsList, #GlobalNavTopicsTitle').hover(
		function() {
			$('#GlobalNavTopicsList, #GlobalNavTopicsTitle').show();
			return false;
		}, 
		function() {
			$('#GlobalNavTopicsList, #GlobalNavTopicsTitle').hide();
			return false;
		});
});


/* ------------------
 * jQuery function to show/hide drop-down list of countries
 *	This function is called automatically
 */
$(document).ready(function() {
	$('#countrySelector').hover(
		function() {
			$('#countrySelector #countriesList').show();
			$('.hideOnMouseOver').css("visibility","hidden");
			return false;
		}, 
		function() {
			$('#countrySelector #countriesList').hide();
			if ($('#commentToolBox').css("display") == "none") {
				$('.hideOnMouseOver').css("visibility","");
			}
			return false;
		});
});


/* ------------------
 * jQuery function to apply alternating row colors to tables
 *	This function is called automatically
 */
$(document).ready(function() {
	$('table.striped th').addClass('theader');
	$('table.striped tr').hover(function() {$(this).addClass('theader');},function(){$(this).removeClass('theader');});
	$('table.striped tr:even').addClass('even');
});

/* ------------------
 * jQuery function to alert users that the link will redirect to an outside link
 *	This function is called automatically
 */
$(document).ready(function() {
	$(".externalLink").click(function () {
		var externalLinkText = "Note: You are leaving the IDB bank to an external site.";
		if (lang == 'es') {
			externalLinkText = "ES: Note: You are leaving the IDB bank to an external site.";
		} else if (lang == 'pt') {
			externalLinkText = "PT: Note: You are leaving the IDB bank to an external site.";
		} else if (lang == 'fr') {
			externalLinkText = "FR: Note: You are leaving the IDB bank to an external site.";	
		} 
		if (!confirm(externalLinkText)) 
			return false;
	});
});

/* ------------------
 * jQuery function to open/close the share tool
 *	This function is called when clicking on "share on this page" button
 */
function openShareList() {
	$('#commentToolBox').slideUp('fast');
	$('#shareToolBox').slideDown('fast');
	$('.hideOnMouseOver').css("visibility","hidden");
	$('.hideOnShareOpen').css("visibility","hidden");
	
}

function closeShareList() {
	$('#shareToolBox').slideUp('fast');
	setTimeout("$('.hideOnMouseOver').css('visibility','');",200);
	setTimeout("$('.hideOnCommentOpen').css('visibility','');",200);
}


/* ------------------
 * jQuery function to open/close the comment tool
 *	This function is called when clicking on "Comment on this page" button
 */
function openCommentForm() {
	$('#shareToolBox').slideUp('fast');
	$('#commentToolBox').slideDown('fast');
	$('.hideOnMouseOver').css("visibility","hidden");
	$('.hideOnCommentOpen').css("visibility","hidden");
	
}

function closeCommentForm() {
	$('#commentToolBox').slideUp('fast');
	setTimeout("$('.hideOnMouseOver').css('visibility','');",200);
	setTimeout("$('.hideOnCommentOpen').css('visibility','');",200);
}

function submitCommentForm() {
	var url = "/global/templates/core/feedbacktool/commentController.cfc?method=addCommentAjax&pageName="+commentPageName+"&section="+commentSection+"&lang="+commentLang;
	var comment = $('#commentToolText').val();
	var commentType = $("input[@name=commentType]:checked").val();
	var name = $('#CommentName').val();
	var emailaddress = $('#CommentEmailaddress').val();
	
	$('#commentToolForm').load("/global/templates/core/feedbackTool/sending.cfm?lang="+commentLang);
	$.ajax({
		type: "POST",
		url: url,
		data:{ comment:comment, 
			   commentType:commentType,
			   ContactName:name,
			   ContactEmail:emailaddress
			 },
		success: function() { $('#commentToolForm').load("/global/templates/core/feedbackTool/success.cfm?lang="+commentLang); },
		error: function() { $('#commentToolForm').load("/global/templates/core/feedbackTool/failed.cfm?lang="+commentLang); }
	});
	return false;
}



function submitContactForm_do_not_change() {
	var url = "/common/contactus/contactController.cfc?method=addCommentAjax&pageName="+commentPageName+"&section="+commentSection+"&lang="+commentLang;
	var comment = $('#commentToolText').val();
	var commentType = $("input[@name=commentType]:checked").val();
	var contactEmail = $("input[@name=contactEmail]").val();
	var contactName = $("input[@name=contactName]").val();
	var contactSubject = $("select[@name=subject]").val();
	var contactMessage = $("textarea[@id=contactText]").val();
	
	$('#contactForm').load("/common/contactus/sending.cfm?lang="+commentLang);
	$.ajax({
		type: "POST",
		url: url,
		data:{ comment:comment, 
			   commentType:commentType,
			   contactEmail:contactEmail,
			   contactName:contactName,
			   contactSubject:contactSubject,
			   contactMessage:contactMessage			   
			 },
		success: function() { $('#contactForm').load("/common/contactus/success.cfm?lang="+commentLang); },
		error: function() { $('#contactForm').load("/common/contactus/failed.cfm?lang="+commentLang); }
	});
	return false;
}

/* done by EmanuelC on 03/09/09. Se example on /global/templates/sites/IDBV2/resources/footer.cfm */
$(document).ready(function() {
	$('#facebookFooter,#youtubeFooter,#twitterFooter').hover(
	function() {
		var currentImg = $(this).attr('src');
		$(this).attr('src', $(this).attr('name'));
		$(this).attr('name', currentImg);
	}, 
	function() {
		var currentImg = $(this).attr('src');
		$(this).attr('src', $(this).attr('name'));
		$(this).attr('name', currentImg);
	});
});