/**** [Begin : Array Prototypes ****/
if (!Array.prototype.indexOf) {
	Array.prototype.indexOf = function(elt /*, from*/) {
		var len = this.length;
		var from = Number(arguments[1]) || 0;
		from = ((from < 0) ? Math.ceil(from) : Math.floor(from));
		if (from < 0) { from += len; }
		var ret = -1;
		for (; from < len && ret == -1; from++) {
			if (this[from].search(elt, "i") == 0) { ret = from; }
		}
		return ret;
	};
}
if (!Array.prototype.contains) {
	Array.prototype.contains = function (obj) { return (this.indexOf(obj) >= 0); };
}
/**** [Finish : Array Prototypes ****/

/**** [Begin : QueryString Access ****/
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = {};

	if (qs == null) qs = location.search.substring(1, location.search.length);
	if (qs.length == 0) return;

	// Turn <plus> back to <space>
	// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &

	// split out each name=value pair
	for (var i = 0; i < args.length; i++) {
		var pair = args[i].split('=');
		var name = decodeURIComponent(pair[0]);
		var value = ((pair.length==2) ? decodeURIComponent(pair[1]) : name);
		this.params[name] = value;
	}
}
if (!Querystring.prototype.get) {
	Querystring.prototype.get = function(key, default_) {
		var value = this.params[key];
		return (value != null) ? value : default_;
	}
}
if (!Querystring.prototype.contains) {
	Querystring.prototype.contains = function(key) {
		var value = this.params[key];
		return (value != null);
	}
}
/**** [Finish: QueryString Access] ****/

/**** [Begin : Status Bar Message] ****	
function HideStatus() {
	window.status='Império Bonança Seguros';
	return true;
}
if (document.layers)document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
document.onmouseover=HideStatus;document.onmouseout=HideStatus;
*** [Finish: Status Bar Message] ****/	

/**** [Begin : Show Formated Date] ****/
var m_names 	= new Array("Janeiro", "Fevereiro", "Mar&ccedil;o", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro");
var d 			= new Date();
var curr_date 	= d.getDate();
var curr_month 	= d.getMonth();
var curr_year 	= d.getFullYear();
var formateddate= curr_date + " de " + m_names[curr_month] + " de " + curr_year;
/**** [Finish: Show Formated Date] ****/

/**** [Begin : Shows One Specific DIV & Hide All Others] ****/
function hideAllExcept(elm) {
	for (var i = 0; i < FAQItems .length; i++) {
		var layer = document.getElementById("div_" + FAQItems [i]);
		layer.style.display = ((elm != "div_"+FAQItems[i]) ? "none" : "block");
	}
}
/**** [Finish: Shows One Specific DIV & Hides All Other DIV's] ****/	

/**** [Begin : Shows All DIV's & Hides One Specific DIV] ****/	
function ShowAllExcept(elm) {
	for (var i = 0; i < FAQItems .length; i++) {
		var layer = document.getElementById("div_" + FAQItems [i]);
		layer.style.display = ((elm != "div_"+FAQItems [i]) ? "block" : "none");
	}
}
/**** [Finish: Shows All DIV's & Hides One Specific DIV] ****/	

/**** [Begin : Show All / Hide All Button Behavior] ****/	
function ShowAll() {
	document.getElementById("ShowALL").style.display = "none";
	document.getElementById("HideALL").style.display = "block";
}
function HideAll() {
	document.getElementById("HideALL").style.display = "none";
	document.getElementById("ShowALL").style.display = "block";
}

/// <summary>
/// Hides all divs with a given prefix
/// </summary>
/// <param name="prefix">Spans ID prefix to hide</param>
function HideAllDivs(prefix) {
	try {
		var aDivs = document.getElementsByTagName("TABLE");
		for (var i = 0; i < aDivs.length; i++) {
			var div = aDivs[i];
			var id = div.id;
			if (id.indexOf(prefix) != -1) { HideDiv(id); }
		}
	}
	catch(e) { }
}
/// <summary>
/// Hides a div
/// </summary>
/// <param name="id">Div ID to hide</param>
function HideDiv(id) {
	try {
		elem = document.getElementById(id);
		elem.style.display = "none";
	}
	catch(e) { }
}
/// <summary>
/// Shows a span
/// </summary>
/// <param name="id">Div ID to show</param>
function ShowDiv(id) {	
	try {
		elem = document.getElementById(id);
		elem.style.display = "inline";
	}
	catch(e) { }
}	
/// <summary>
/// Toggles Span visibility
/// </summary>
/// <param name="id">Span ID to toggle visibility</param>
/// <param name="prefix">Spans ID prefix to hide</param>
function HideShowSpan (id,prefix) {
	try {
		var elem = document.getElementById(id);
		var display = elem.style.display;
		HideAllSpans(prefix);
		if (display == 'none') { ShowSpan(id); }
	}
	catch (e) { }
}
/// <summary>
/// Hides a span
/// </summary>
/// <param name="id">Span ID to hide</param>
function HideSpan(id) {
	try {
		var elem = document.getElementById(id);
		elem.style.display = "none";
	}
	catch(e) { }
}	
/// <summary>
/// Shows a span
/// </summary>
/// <param name="id">Span ID to show</param>
function ShowSpan(id) {
	try {
		elem = document.getElementById(id);
		elem.style.display = "inline";
	}
	catch(e) { }
}
/// <summary>
/// Hides all spans with a given prefix
/// </summary>
/// <param name="prefix">Spans ID prefix to hide</param>
function HideAllSpans(prefix) {
	try {
		var aSpans = document.getElementsByTagName("SPAN");
		for (var i = 0; i < aSpans.length; i++) {
			var span = aSpans[i];
			var id = span.id;
			if (id.indexOf(prefix) != -1) { HideSpan(id); }
		}
	}
	catch(e) { }	
}
/// <summary>
/// Shows all spans with a given prefix
/// </summary>
/// <param name="prefix">Spans ID prefix to show</param>
function ShowAllSpans(prefix) {
	try {
		var aSpans = document.getElementsByTagName("SPAN");
		for (var i = 0; i < aSpans.length; i++) {
			var span = aSpans[i];
			var id = span.id;
			if (id.indexOf(prefix) != -1) { ShowSpan(id); }
		}
	}
	catch(e) { }
}
/// <summary>
/// Toggles Visibility of FAQ Categories
/// </summary>
/// <param name="id">Category Span ID show</param>
/// <param name="CategotyPrefix">Category Spans ID prefix to hide</param>
/// <param name="FAQPrefix">FAQ Spans ID prefix to hide</param>
function ToggleFAQCategories(id, CategoryPrefix, FAQPrefix) {
	try {
		HideAllSpans(CategoryPrefix);
		ShowSpan(id);
		HideAllSpans(FAQPrefix);
	}
	catch(e) { }
}
/**** [Finish: Show All / Hide All Button Behavior] ****/

/**** [Begin : Scroll To Page Top] ****/
function GoToTop() {
	location.href = "#PageTop";
}
/**** [Finish: Scroll To Page Top] ****/

/**** [Begin : Show / Hide DIV's For Site Map] ****/
function HideDiv(divId) {
	divToHide 	= document.getElementById(divId);
	imgToChange = document.getElementById("IMG"+divId);
	if(divToHide.style.display == "none") {
		divToHide.style.display = "block";
		imgToChange.src = "/Style Library/Images/IBImages/img_esconder.gif";
	}
	else {
		divToHide.style.display = "none";
		imgToChange.src = "/Style Library/Images/IBImages/img_expandir.gif";
	}
}
/**** [Finish: Show / Hide DIV's For Site Map] ****/

/**** [Begin : Redirect] ****/
function RedireccionarUrl(url, redirectUrl, descricao, target) {
	if(redirectUrl == "") { return; }
	if(target == 'Sml')	{
		NewWindow(url + "?Url=" + redirectUrl + "&Dc=" + descricao , 'Redireccionar', 790, 490, 'yes', 0, 0, 'no', 'no', 'yes', 'no', 'no');
	}
	else {
		document.frmPost.action = url + "?Url=" + redirectUrl + "&Dc=" + descricao;
		document.frmPost.target = "_blank";
		document.frmPost.submit();
	}
}
function NewWindow(mypage, myname, w, h, scroll, posX, posY, toolbar, menubar, resizable, location, status) {
	var win = null;

	LeftPosition = posX;
	TopPosition = posY;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',toolbar='+toolbar+',menubar='+menubar+',resizable='+resizable+',location='+location+',status='+status;

	win = window.open(mypage,myname,settings);
	return win;
}
/**** [Finish: Redirect] ****/

/**** [Begin : Product Details] ****/
var itemsHidden = true;
function ShowAllDivs(n) {
	for(var j = 0; j < n; j ++) {
		if(itemsHidden) { ShowItem(j); }
		else { HideItem(j); }
	}
 	if(itemsHidden) {
		document.getElementById("btShowAll").style.display = "none";
		document.getElementById("btHideAll").style.display = "inline";
		document.getElementById("txShowAll").innerHTML = "Ocultar Todos";
 	}
	else {
		document.getElementById("btShowAll").style.display = "inline";
		document.getElementById("btHideAll").style.display = "none";
		document.getElementById("txShowAll").innerHTML = "Ver Todos";
	}
	itemsHidden = !itemsHidden;
}
function ShowDiv(i, n) {
	for(j = 0; j < n; j ++) {
		HideItem(j);
	}

	ShowItem(i);
}
function HideItem(i) {
	document.getElementById("div_" + i).style.display = "none";
}
function ShowItem(i) {
	document.getElementById("div_" + i).style.display = "block";
}
/**** [Finish: Product Details] ****/

/**** [Begin: Link Functions] ****/
var internalHostnames = [];
//var internalHostnames = ['sdc6001spt05', 'sdc6001spt06', 'www.fidelidademundial.pt', 'www.imperiobonanca.pt', 'corporate.fidelidademundial.pt', 'www.medinet-seguros.pt', 'www.adn.imperiobonanca.pt'];
// 
function isLinkValid(url) {
	var pattern = new RegExp(
		'^(http[s]?:\/\/)?'+ // protocol
		'((([a-z\d]([a-z\d-]*[a-z\d])*)\.)+[a-z]{2,}|'+ // domain name
		'((\d{1,3}\.){3}\d{1,3}))'+ // OR ip (v4) address
		'(\:\d+)?(\/[-a-z\d%_.~+]*)*'+ // port and path
		'(\?[;&a-z\d%_.~+=-]*)?'+ // query string
		'(\#[-a-z\d_]*)?$' // fragment locater
		, "i"
	);
	// 
	var ret = (pattern.test(url) == true);
	//if(ret == false) { alert("Please enter a valid URL."); }
	return ret;
}
function isHostInternal(host) {
	host = host.replace(/:[0-9]+$/, ''); // remove port
	return (host && (host == document.location.hostname || internalHostnames.contains(host) == true));
}
function isLinkExternal(url) {
	var ret = false;
	// 
	var arr = url.split('/');
	if (arr && arr.length > 0) {
		if (arr[0]) { // doesn't start with '/xpto'
			var firstWord = arr[0];
			firstWord = firstWord.replace(/:[0-9]+$/, ''); // remove port
			if (firstWord.indexOf(':') >= 0) {
				var protocol = firstWord.split(':')[0];
				if (protocol.search(/^http[s]?$/i) == 0) {
					var hostname = '';
					for(var i = 2; i < arr.length; i++) { // find the word after the protocol 'http://xpto'
						hostname = arr[i];
						if (arr[i]) { break; }
					}
					ret = (hostname && isHostInternal(hostname) == false);
				}
				else if (protocol.search(/^javascript$/i) == 0) { ret = false; } // javascript: links are considered local
				else { ret = true; } // other protocols than http and javascript
			}
			else { // doesn't have a protocol (can be a hostname, or a page) (ex.: www.google.com, page.aspx)
				ret = (isHostInternal(firstWord) == false && firstWord.search(/.(com|org|net)+/i) > 1); // (consider that any non internal link that is dotcom is external)
			}
		}
		// else starts with '/'
	}
	// 
	return ret;
}
//function testLink(url){
//	if (isLinkExternal(url) == true) { window.alert(url +' is external'); } else { window.alert(url +' is LOCAL'); }
//}
//testLink('http://sdc6001spt05:9002/Pages/Home.aspx');
//testLink('http://www.teste.com');
//testLink('sdc6001spt05');
//testLink('sdc6001spt05:9002');
//testLink('www.google.com');
//testLink('/pagina.aspx');
//testLink('pagina.aspx');
//testLink('javascript:teste();');
//testLink('http://www.medinet-seguros.pt/');
//testLink('http://corporate.fidelidademundial.pt/');
/**** [Finish: Link Functions] ****/

function titleDDLChange(ddl) {
	for(var i = 0; i < ddl.length; i++) {
		if (ddl[i].selected) {
			var urlSite = ddl[i].value;
			if (urlSite != '') {
				// window.location = urlSite;
				window.open(urlSite, "_blank", "toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes");
			}
		}
	}
}

/// <summary>
/// Obtains the mask from the Best for me area
/// </summary>
function GetMask() {
	var strTempMask;
	var strMask = "";
	var aSpans = document.getElementsByTagName("SPAN");
	//Iterates spans - categories
	for (var cat_index = 0; cat_index < aSpans.length; cat_index++) { // for spans
		var strInputType = "";
		bFoundSelected = false;

		//Mask value before the inputs
		strTempMask = strMask;

		var aElems = document.getElementsByName(aSpans[cat_index].id + "_profile");
		if (aElems.length > 0) {
			strInputType = aElems[0].type;
		}

		//Iterates inputs - questions
		for (var index = 0; index < aElems.length; index++) { //for inputs
			strMask += ((aElems[index].checked) ? "1" : "0");
		}
	}

	return strMask;
}

/// <summary>
/// Returns a string padded with length characters
/// </summary>
function PadString(strExp, length) {
	var result = strExp;
	try {
		result = "";
		if (strExp.length < length) {
			for (index = strExp.length; index < length; index++) {
				result = "0" + result;
			}
		}
		result += strExp;
	}
	catch(e) { }

	return result;
}

/// <summary>
/// Performs a bitwise AND without carriage return
/// </summary>
function BinaryAnd(strPartA, strPartB) {
	var strLeftSideOperator, strRightSideOperator;
	var iOperatorLength;
	var index;
	var iSumPart;
	var result;

	result = strPartA;
	try {
		strLeftSideOperator = "";
		strRightSideOperator = "";
		result = "";
		if (strPartA.length > strPartB.length) {
			strLeftSideOperator = strPartA;
			strRightSideOperator = PadString(strPartB,strPartA.length);
		}
		else {
			strLeftSideOperator = PadString(strPartA,strPartB.length);
			strRightSideOperator = strPartB;
		}

		iOperatorLength = strPartA.length;
		for (index = iOperatorLength - 1; index >= 0; index--) {
			iSumPart = parseInt(strLeftSideOperator.substring(index,index+1)) * parseInt(strRightSideOperator.substring(index,index+1))
			result = iSumPart + result;
		}
	}
	catch(e) { }

	return result;	
}

/// <summary>
/// Applies the mask to the BestForMe User Control
/// </summary>
function ApplyMask() {
	var strMask;	
	var aSpans;
	var span;
	var i;
	var id;
	var product_profile_sep;
	var product_profile;
	var profileKeywork;

	profileKeywork = "PROFILE_"

	try {
		strMask = GetMask();
		// resets the product visibility
		HideAllSpans (profileKeywork);
		aSpans = document.getElementsByTagName("SPAN");

		for (i=0; i < aSpans.length; i++) {
			span = aSpans[i];
			id = span.id;
			product_profile_sep = id.indexOf(profileKeywork);
			if (product_profile_sep > 0) {
				product_profile = id.substring(product_profile_sep + profileKeywork.length,id.length);
				if (BinaryAnd(strMask,product_profile) == strMask) {
					ShowSpan(id);
				}
			}
		}
	}
	catch(e) { }
}

/// <summary>
/// Resets the inputs with a given prefix
/// </summary>
function ResetOptions(prefix) {
	var aElems;
	var elem;
	var id;
	try {
		aElems = document.getElementsByTagName("INPUT");
		for (i=0; i < aElems.length; i++) {
			elem = aElems[i];
			id = elem.id;

			if (id.indexOf(prefix) != -1) {
				elem.checked = false;
			}
		}
		ApplyMask();
	}
	catch(e) { }
}

/// <summary>
/// Changes a style class for an element
/// </summary>
function ChangeClass(id,ClassName) {
	var elem;
	try {
		elem = document.getElementById(id);
		elem.className = ClassName;
	}
	catch(e) { }
}

/// <summary>
/// Changes the visibilities of FAQs and Glossaries
/// </summary>
function ToggleFAQGlossary(SpanIDToShow,SpanPrefixToHide) {
	try {
		//Hide all spans
		HideAllSpans (SpanPrefixToHide);
		ShowSpan(SpanIDToShow);
	}
	catch(e) { }
}

/// Switches the DropDown Menus
/// Input: spanName: Parent Menu name being switch
function SwitchMenu(spanName) {
	var elems;
	var elem;
	var nameParts;
	var MainSplit;
	var MainSplitCount;
	var arDivs;
	var mainDiv;
	var arActiveElem;
	var activeElem;

	try {
		//Determines the start menu level
		MainSplit = spanName.split("_");
		MainSplitCount = MainSplit.length;

		//obtains all Divs from screen
		arDivs = document.getElementsByTagName("div");
		for (var i=0; i< arDivs.length; i++) {
			if (arDivs[i].id.indexOf("masterdiv") != -1) {
				mainDiv = arDivs[i];
				break;
			}
		}

		//obtains all inputs into an array
		arActiveElem = mainDiv.getElementsByTagName("input");
		for (var i=0; i< arActiveElem.length; i++) {
			activeElem = arActiveElem[i];

			//verifies if it's the Active menu Hidden input
			if (activeElem.id.indexOf("ActiveMenu") != -1) {
				activeElem.value = spanName;
				break;
			}
		}

		//Build the menu full path 
		//to build the breadcrumb
		BuildMenuPath();

		//obtains all spans into an array
		elems =	mainDiv.getElementsByTagName("span");
		for (var i=0; i< elems.length; i++) {
			elem = elems[i];
			//determines the level of menu item
			nameParts = elem.id.split("_");

			//Verifies if it's a sub-menu 
			//The "_" is inserted to prevent other menus with
			//similar names to be shown
			if (elem.id.indexOf(spanName + "_") != -1) {
				//verifies if it's a direct sub-menu
				if ((nameParts.length - 1 ) == MainSplitCount) {
					//switch menu visibility
					if (elem.style.display == "block") {
						elem.style.display = "none";
					}
					else {
						elem.style.display = "block";
					}
				}

				//if it's not a direct sub-menu hides it
				if ((nameParts.length - 1 ) > MainSplitCount) {
					elem.style.display = "none";
				}
			}
			else {
				//make sure the menu is not an ancester
				if (spanName.indexOf(elem.id) == -1) {
					if (nameParts.length > MainSplitCount) {
						elem.style.display = "none";
					}
				}
			}
		}
	}
	catch(e) {
		//alert(e.message);
	}
}

/// Function that reads from a hidden field and shows
/// the active field there indicated
function SetActiveMenuItem() {
	var elemActive;
	var arInputs;

	try {
		arInputs = document.getElementsByTagName("input");
		for (var i=0; i< arInputs.length; i++) {
			if (arInputs[i].id.indexOf("m_inActiveMenu") != -1) {
				elemActive = arInputs[i];
				break;
			}
		}
		if (elemActive.value != "") { ShowMenu(elemActive.value); }
	}
	catch(e) {
		//alert(e.message);
	}
}

/// Shows the indicated menu and all at the same level, sons of same menu or upper
function ShowMenu(menuName) {
	var elems;
	var arDivs;
	var mainDiv;
	var MainSplit;
	var MainSplitCount;
	var nameParts;
	var i;
	var bParentShown;
	var parentName;

	try {
		//Determines the start menu level
		MainSplit = menuName.split("_");
		MainSplitCount = MainSplit.length;

		//build the parent name
		parentName = '';
		for (var i=0; i < MainSplitCount - 1; i++) {
			parentName += MainSplit[i];
			if (i < MainSplitCount - 2)
				parentName += "_";
		}

		if (parentName != '' && parentName != 'menu') {
			//obtains all Divs from screen-Discover masterdiv
			arDivs = document.getElementsByTagName("div");
			for (i=0; i< arDivs.length; i++) {
				if (arDivs[i].id.indexOf("masterdiv") != -1) {
					mainDiv = arDivs[i];
					break;
				}
			}

			//obtains all spans in an array
			elems =	mainDiv.getElementsByTagName("span");
			for (var i=0; i< elems.length; i++) {
				elem = elems[i];

				//determines the level of menu item
				nameParts = elem.id.split("_");

				//It's an element of the same level...show
				//The "_" is inserted to prevent other menus with
				//similar names to be shown
				if (elem.id.indexOf(parentName + "_") != -1 && nameParts.length == MainSplitCount) {
					elem.style.display = "block";
				}
			}

			// show parents - recursive
			if (MainSplitCount > 3)	
				ShowMenu(parentName);
		}
	}
	catch(e) { }
}


/// Builds the menu path for the breadcrumb
function BuildMenuPath() {
	var activeElem;
	var ActiveName;
	var ActiveSplit;
	var ActiveSplitCount;
	var parentName;
	var parentElem;
	var FullMenuPath;

	try {
		FullMenuPath = LoadElementByPartialName("div","masterdiv","input","FullMenuPath");
		FullMenuPath.value = "";

		activeElem = LoadElementByPartialName("div","masterdiv","input","ActiveMenu");

		ActiveName = activeElem.value;

		//obtains the level of the active menu
		ActiveSplit = ActiveName.split("_");
		ActiveSplitCount = ActiveSplit.length;

		parentName = "menu";
		for (var i=1; i < ActiveSplitCount; i++) {
			parentName += "_" + ActiveSplit[i];
			//Load the menu Label element
			parentElem = LoadElementByPartialName("span",parentName,"a","_MenuLabel");

			//if it's the first time don't place the seperator
			if (FullMenuPath.value != "")
				FullMenuPath.value += "&nbsp;>&nbsp;";

			// childNodes instead of innerText for mozilla compatibility
			//FullMenuPath.value += parentElem.innerText;
			FullMenuPath.value += parentElem.childNodes[0].nodeValue;
		}
	}
	catch(e) {
		//alert(e.message);
	}
}


/// Builds the BreadCrumb based on the hidden values 
function BuildBreadCrumb(BreadCrumbPath) {
	var BeginCrumb;
	var AreaCrumb;
	var AreaCrumbLink;
	var MenuCrumb;
	var PageCrumb;
	var BreadCrumb;
	var Seperator;
	var BreadCrumbElement;

	BreadCrumb = "";
	Seperator = "&nbsp;>&nbsp;";

	try {
		//fixed crumb
		BeginCrumb = "<a href='../site/homepage.aspx'>In&iacute;cio</a>";

		//Load Area Description crumb
		AreaCrumb = LoadElementByPartialName("","","input","hdnAreaDescription");

		//Load Area Description crumb Link
		AreaCrumbLink = LoadElementByPartialName("","","input","hdnAreaDescriptionLink");

		//Load Menu crumb
		MenuCrumb = LoadElementByPartialName("div","masterdiv","input","FullMenuPath");

		//Load Page crumb
		PageCrumb = LoadElementByPartialName("","","input","hdnPageCrumb");

		//*** Begin building the output ***
		BreadCrumb = BeginCrumb;

		if (AreaCrumb != null && AreaCrumb.value != "") {
			if (AreaCrumbLink != null && AreaCrumbLink.value != "")
				BreadCrumb += Seperator + "<a href='" + AreaCrumbLink.value + "'>" + AreaCrumb.value + "</a>";
			else
				BreadCrumb += Seperator + AreaCrumb.value;
		}

		if (MenuCrumb != null && MenuCrumb.value != "")
			BreadCrumb += Seperator + MenuCrumb.value;

		if (PageCrumb != null && PageCrumb.value != "")
			BreadCrumb += Seperator + PageCrumb.value;

		BreadCrumbElement = LoadElementByPartialName("","","div",BreadCrumbPath);
		if (BreadCrumbElement != null & BreadCrumb != "")
			BreadCrumbElement.innerHTML = BreadCrumb;
	}
	catch(e) {
		//alert("ERRO:" + e.message);
	}
}

/// Loads an element from screen based on its partial name and TagName
/// It can narrow the search by provding a masterTag section
function LoadElementByPartialName(masterTag, masterName, tagName, elementName) {
	var arDivs;
	var mainDiv;
	var arElems;
	var elem;	
	var bFound;

	mainDiv = null;
	elem = null;	
	bFound = false;

	try {
		if (masterName != "" && masterTag != "") {	
			//obtains all Divs from screen
			arDivs = document.getElementsByTagName(masterTag);

			for (var i=0; i< arDivs.length; i++) {
				if (arDivs[i].id.indexOf(masterName) != -1) {
					mainDiv = arDivs[i];
					break;
				}
			}
		}

		if (mainDiv != null)
			//obtains all inputs into an array
			arElems = mainDiv.getElementsByTagName(tagName);
		else
			arElems = document.getElementsByTagName(tagName);

		for (var i=0; i< arElems.length; i++) {
			elem = arElems[i];

			//verifies if it's the Active menu Hidden input
			if (elem.id.indexOf(elementName) != -1) {
				//found
				bFound = true;
				break;
			}
		}

		if (!bFound)
			elem = null;
		return elem;
	}
	catch (e) {
		return null;
	}
}

/// Jumps to the url of the selected option in a dropdown box
function MM_jumpMenu(targ,selObj,restore){ //v3.0
	var jaRedireccionou = false;
	try {
		var optionValue = selObj.options[selObj.selectedIndex].value;	

		if (optionValue.length > 0) {
			// se a opcao for do tipo "abcdef;1", a opcao depois de ';' indica se e' 
			// para abrir numa nova janela ou nao

			var args = optionValue.split(";");
			if(args.length>1) {
				if(args[1] == "1") {
					targ = window.open();
					targ.location = args[0];
					jaRedireccionou = true;
				}
			}

			if(!jaRedireccionou) {
				eval(targ+".location='"+args[0]+"'");
			}
			if (restore) selObj.selectedIndex=0;
		}
	}
	catch(e) { }
}

/// Performs the contact search with full text
function SearchContact() {
	try {
		var searchInput = "SearchString";		
		var searchStringElem = document.getElementById(searchInput);
		location.href = '../Site/WhereWeAre.aspx?TotalText=' + searchStringElem.value;
	}
	catch(e) {
		//alert(e.message);
	}
}
function SearchSite() {
	try {
		var searchInput = "SiteSearch";
		var searchStringElem = document.getElementById(searchInput);
		location.href = '../Site/Search.aspx?all=True&query=' + searchStringElem.value;
	}
	catch(e) {
		//alert(e.message);
	}
}

// Sets default buttons.
// Compatibilidade: -Mozilla, IE...
function fnTrapKD(btn, event) {
	try {
		if (document.all) {
			if (event.keyCode == 13) {
				event.returnValue=false;
				event.cancel = true;
				btn.click();
			}
		}
		else if (document.getElementById || document.layers) {
			if (event.which == 13) {
				event.returnValue=false;
				event.cancel = true;
				btn.onclick();
			}
		}
	}
	catch(e) {
		//alert(e.message);
	}
}

// Validate BirthDay field - current age must be between 18 and 45
// The age is calculated only using the years, as in the BSG service
function ValidateBirthdate( object, args ) {
	var birthDateString;
	var birthYearString = new String();
	var birthYearInt;
	var yearNow = new Date();
	var age;
	
	try {
		args.IsValid = true;

		birthDateString = String(args.Value);
		
		// gets the year from date. The format validator does not allow a date in another format
		birthYearString = birthDateString.substring(6, 10);
		
		// year not well formed - The format validator will give the error message,
		// this validator doesn't need to show its own
		if (birthYearString.length != 4) {
			args.IsValid = false;
			return;
		}
		
		// trick to convert a string to int	
		birthYearInt = birthYearString * 1;
		age = yearNow.getYear() - birthYearInt;

		if (age < 18 || age > 45) {
			args.IsValid = false;
		}
		else {
			args.IsValid = true;
		}
	}
	catch(e) {
		// there was an error getting the year. The format validator will give the error message,
		// this validator doesn't need to show its own
		args.IsValid = true;
	}
}


var dtCh= "-";
var minYear=1800;
var maxYear=2100;

function isInteger(s){
	var i;
	for (i = 0; i < s.length; i++){	 
		// Check that current character is number.
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
	}
	// All characters are numbers.
	return true;
}

function stripCharsInBag(s, bag){
	var i;
	var returnString = "";
	// Search through string's characters one by one.
	// If character is not in bag, append to returnString.
	for (i = 0; i < s.length; i++){	 
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) returnString += c;
	}
	return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
	// EXCEPT for centurial years which are not also divisible by 400.
	return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
	 } 
	 return this
}

function isDate(dtStr) {
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		//alert("O formato da data deverá ser: dd-mm-aaaa")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		//alert("Por favor, indique um mês válido.")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		//alert("Por favor, indique um dia válido.")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//alert("Por favor, indique um ano válido (entre"+minYear+" e "+ maxYear + ")")
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Por favor, indique uma data válida.")
		return false
	}
	return true
}

function ValidaData(source) {
	var dt= document.getElementById(source.id);
	if (isDate(dt.value) == false) {
		dt.focus();
		return false;
	}
	return true;
}

function SetValueToTextInputs(prefix, value) {
	try {
		var aTextInputs = document.getElementsByTagName("INPUT");
		for (var i = 0; i < aTextInputs.length; i++) {
			var textInput = aTextInputs[i];
			if (textInput.id.indexOf(prefix) != -1) {
				textInput.value = value;
			}
		}
	}
	catch(e) { }
}
