var BrowserDetect = {
						init: function () {
							this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
							this.version = this.searchVersion(navigator.userAgent)
								|| this.searchVersion(navigator.appVersion)
								|| "an unknown version";
							this.OS = this.searchString(this.dataOS) || "an unknown OS";
						},
						searchString: function (data) {
							for (var i=0;i<data.length;i++)	{
								var dataString = data[i].string;
								var dataProp = data[i].prop;
								this.versionSearchString = data[i].versionSearch || data[i].identity;
								if (dataString) {
									if (dataString.indexOf(data[i].subString) != -1)
										return data[i].identity;
								}
								else if (dataProp)
									return data[i].identity;
							}
						},
						searchVersion: function (dataString) {
							var index = dataString.indexOf(this.versionSearchString);
							if (index == -1) return;
							return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
						},
						dataBrowser: [
							{
								string: navigator.userAgent,
								subString: "Chrome",
								identity: "Chrome"
							},
							{ 	string: navigator.userAgent,
								subString: "OmniWeb",
								versionSearch: "OmniWeb/",
								identity: "OmniWeb"
							},
							{
								string: navigator.vendor,
								subString: "Apple",
								identity: "Safari",
								versionSearch: "Version"
							},
							{
								prop: window.opera,
								identity: "Opera"
							},
							{
								string: navigator.vendor,
								subString: "iCab",
								identity: "iCab"
							},
							{
								string: navigator.vendor,
								subString: "KDE",
								identity: "Konqueror"
							},
							{
								string: navigator.userAgent,
								subString: "Firefox",
								identity: "Firefox"
							},
							{
								string: navigator.vendor,
								subString: "Camino",
								identity: "Camino"
							},
							{		// for newer Netscapes (6+)
								string: navigator.userAgent,
								subString: "Netscape",
								identity: "Netscape"
							},
							{
								string: navigator.userAgent,
								subString: "MSIE",
								identity: "Explorer",
								versionSearch: "MSIE"
							},
							{
								string: navigator.userAgent,
								subString: "Gecko",
								identity: "Mozilla",
								versionSearch: "rv"
							},
							{ 		// for older Netscapes (4-)
								string: navigator.userAgent,
								subString: "Mozilla",
								identity: "Netscape",
								versionSearch: "Mozilla"
							}
						],
						dataOS : [
							{
								string: navigator.platform,
								subString: "Win",
								identity: "Windows"
							},
							{
								string: navigator.platform,
								subString: "Mac",
								identity: "Mac"
							},
							{
								   string: navigator.userAgent,
								   subString: "iPhone",
								   identity: "iPhone/iPod"
						    },
							{
								string: navigator.platform,
								subString: "Linux",
								identity: "Linux"
							}
						]
					
					};
					BrowserDetect.init();
					
					if (BrowserDetect.browser == "Chrome"){
		        		document.write('<link rel="stylesheet" type="text/css" href="/lib/layout-yui-chrome.css">');
		        	}
		        	else if (BrowserDetect.browser == "Safari"){
		        		document.write('<link rel="stylesheet" type="text/css" href="/lib/layout-yui-safari.css">');
		        	}
		        	else if (BrowserDetect.browser == "Opera"){
						document.write('<link rel="stylesheet" type="text/css" href="/lib/layout-yui-opera.css">');
		           	}
		        	else if ((BrowserDetect.browser == "Explorer") && (BrowserDetect.version > "8")) {
		        		document.write('<link rel="stylesheet" type="text/css" href="/lib/layout-yui.css">');
		        		document.write('<link rel="stylesheet" type="text/css" href="/lib/layout-yui-IE9.css">');
		        	}
		        	else if ((BrowserDetect.browser == "Explorer") && (BrowserDetect.version >= "7")) {
		        		document.write('<link rel="stylesheet" type="text/css" href="/lib/layout-yui.css">');
		        		document.write('<link rel="stylesheet" type="text/css" href="/lib/layout-yui-IE.css">');
		        	}
		        	else if ((BrowserDetect.browser == "Explorer") && (BrowserDetect.version <= "6")) {
		        		document.write('<link rel="stylesheet" type="text/css" href="/lib/layout-yui-IE6-min.css">');
		        		document.write('<div id="ie6-box">');
        				document.write('<p class="browser-links">');
        				document.write('<a href="http://www.google.com/chrome?hl=pt-PT" class="browser-link" ><img src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" class="chrome-link"></a>');
        				document.write('<a href="http://www.mozilla.com/pt-PT/" class="browser-link" ><img src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" class="firefox-link"></a>');
        				document.write('<a href="http://www.microsoft.com/windows/internet-explorer/default.aspx" class="browser-link" ><img src="http://s.ytimg.com/yt/img/pixel-vfl73.gif" class="ie8-link"></a>');
        				document.write('</p>');
        				document.write('<p class="upgrade-message"><strong class="nobr">O seu Browser n&atilde;o &eacute; suportado nesta nova vers&atilde;o do miau.pt.</strong><br><span class="nobr">Por favor actualize para um destes Browsers mais modernos.</span></p>'); 
        				document.write('</div>');
		        	}
		        	else
		            	document.write('<link rel="stylesheet" type="text/css" href="/lib/layout-yui.css">'); 

					function order(orderBy){
						document.frmOrderBy.order_by.value = orderBy;
						document.frmOrderBy.submit();
					}
					function ordenar(orderby,sortorder){
						document.frmOrderBy.orderby.value= orderby;
						document.frmOrderBy.ascdesc.value= sortorder;
						document.frmOrderBy.submit();
					}
					function show_photo(current_val){
						document.frmOrderBy.showpics.value = current_val;
						document.frmOrderBy.submit();
					}
					function auction(offer_id){
						document.frmAuction.offer_id.value = offer_id;
						document.frmAuction.submit();
					}

					function goToCategory(level,cat_id){
						document.frmDestPage.cat_id.value = cat_id;
						document.frmDestPage.level.value = level;
						document.frmDestPage.submit();
					}

					function gtc(level,cat_id, parent_cat_id){
						document.frmDestPage.cat_id.value = cat_id;
						document.frmDestPage.parent_cat_id.value = parent_cat_id;	
						document.frmDestPage.level.value = level;
						document.frmDestPage.submit();
					}

					function show_closing(current_val){
						document.frmOrderBy.show_closing.value = current_val;
						document.frmOrderBy.passagem.value = "";
						document.frmOrderBy.n_items_ini.value = "";
						document.frmOrderBy.lngNpageNavStart.value = "";
						document.frmOrderBy.lngNpageNavEnd.value = "";
						document.frmOrderBy.orderby.value = "";
						document.frmOrderBy.ascdesc.value = "";
						document.frmOrderBy.topic.value = "";
						document.frmOrderBy.submit();
					}
					function sorter(str) {
						if (str != -1) {
							var array = str.split(',', 2);
							ordenar(array[0], array[1]);
						}
					}
					function check_pesquisar(frm){
						  
						  for (i=0;i < document.frmSearch.pesquisar_varios_type.length;i++){
						    if (document.frmSearch.pesquisar_varios_type[i].checked){
						      var var_check = document.frmSearch.pesquisar_varios_type[i].value;		
						      break;
						    }
						  }
						  
						  if (var_check != "offer_id"){
						    document.frmSearch.origem.value = 0;
						    if (document.frmSearch.topic.value.length < 2){
						      alert("Insira palavras com mais do que uma letra");
						      return false;
						    }
						    if (document.frmSearch.topic.value.length > 20 ){
						      alert("T�pico muito extenso");
						      return false;
						    }	
						  }
						  
						  if (var_check == "offer_id"){
						    var var_check_value = document.frmSearch.topic.value;
						    if (isNaN(var_check_value)){		 
						      alert ("Insira um valor para o ID")
							return false;
						    }
						    if (var_check_value == ""){		 
						      alert ("Insira um valor para o ID")
							return false;
						    }
						    document.frmSearch.origem.value = 1;
						    document.frmSearch.offer_id.value = document.frmSearch.topic.value;
						    return true;
						  }
						  
						  return true;
						}

						function pesquisarNoRet(){
						  if (document.frmSearch.brand_search != null) {
						    if (document.frmSearch.brand_search.value == "1") {
						      document.frmSearch.submit();
						      return;
						    }
						  }
						  if (check_pesquisar() == true)
						    document.frmSearch.submit();
						}
						if (!document.layers&&!document.all&&!document.getElementById)
							event="test";
							function showtip(current,e,text){
							    if (document.all||document.getElementById){
								thetitle=text.split('<br>');
								  if (thetitle.length>1){
								      thetitles='';
								      for (i=0;i<thetitle.length;i++)
									thetitles+=thetitle[i];
								      current.title=thetitles;
								  }else
								    current.title=text;
							    } else if (document.layers){
								document.tooltip.document.write('<layer bgColor="white" style="border:1px solid black;font-size:12px;">'+text+'</layer>');
								document.tooltip.document.close();
								document.tooltip.left=e.pageX+5;
								document.tooltip.top=e.pageY+5;
								document.tooltip.visibility="show";
							    }
							}

							function hidetip(){
							    if (document.layers)
							      document.tooltip.visibility="hidden";
							}
							function parseCurrency(aVal) {
							    if(isNaN(Math.round(aVal)))
							      return parseFloat(aVal.split(',').join('.'));
							    else
							      return aVal;
							}

							function convertEURtoPTE(eurVal) {
							    
							    var EURVal = parseCurrency(eurVal);

							    pteVal = Math.round(EURVal*200.482);
							    
							    return pteVal+'$';
							}

							function updatePTE(eurVal,pteVal) {
							    pteVal.value = convertEURtoPTE(eurVal.value);
							}
							// Adicionar e remover negocios ah lista debaixo de olho.
							// requer mootools com suporte AJAX

							function success_debaixo_olho(responseText) {
								alert("Xarann: "+(responseText.trim()));
							}

							function adicionar_debaixo_olho(data) {
								var options = {
										url:'/conta_pessoal/debaixo_olho/adicionar.jsp',
										method:'post',
										data:data,
										noCache:true,
										onSuccess:success_debaixo_olho
								};
								var myRequest = new Request(options);
								myRequest.send();
							}

							function remover_debaixo_olho(data) {
								var options = {
										url:'/conta_pessoal/debaixo_olho/ajax.jsp',
										method:'post',
										data:data,
										noCache:true,
										onSuccess:success_debaixo_olho
								};
								var myRequest = new Request(options);
								myRequest.send();
							}


							function esconder_olho(offer_id) {
								var elem = document.getElementById('eye_'+offer_id);
								if(elem) {
									elem = elem.parentNode;
									elem.innerHTML='&nbsp;';
								}
							}

							function personal_navigator() {

							  window.open('/home_popup2.jsp','Popup','left=530,top=230,width=240,height=305,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no');

							}
					
