var featArr = new Array();
function show(nID){
	$('#feats').fadeOut("fast",function(){$('#feats').html(featArr[nID])}).fadeIn("fast");
}

function CheckRef(oRef,oVal){
	if($("#"+oRef).attr("value")==oVal)
	{
		$("#"+oRef).attr("value","");
	}
	else{
		$("#"+oRef).attr("value",""+$("#"+oRef).attr("value")+"");
	}
}	
function ClearValue(oId , oVal){
	if($("#"+oId).attr("value")==oVal)
	{
		$("#"+oId).attr("value","");
	}
}
function ResetValue(oId , oVal){
	if(!$("#"+oId).attr("value"))
	{
		$("#"+oId).attr("value",oVal);
	}
}
// JavaScript Document
function scrollUp(){
	document.getElementById('scroll').scrollTop += 57;
}
function scrollDown(){
	document.getElementById('scroll').scrollTop -= 57;
}
function showMaPic(oPic, oDesc){
	 preloadPic(oPic);
      $('#thumbB').fadeTo(150,0.1, function(){
		$('#thumbB').attr('src',oPic);
		$('#thumbB').load(function () {
			$(this).fadeTo(150,1);
		});
	  });
      $('#picname').html(' » '+oDesc);
}

var iFirst=true;
function showFirst(oPic, oDesc){
	$('.PContainer').append("<div style='visibilty:hidden; height:0; width:0;' id='preload_img'></div>");
	document.getElementById('thumbB').src=oPic;
	document.getElementById('picname').innerHTML=' » '+oDesc;
}
//carrega as imagens
function preloadPic(oImg){
	$('#preload_img').css("background","url("+oImg+")");
}
//cancela um evento, evitando que a aco final seja executada	
function cancelEvent(e)
{
	e.returnValue = false;
	e.cancelBubble = true;
	try{e.preventDefault();e.keyCode = 8}catch(e){}
}

function check2(oForm)
{	
	var sErr = "";
	if(oForm.NAM.value == ''||oForm.NAM.value == oVal1){
		sErr = sErr1;
		oForm.NAM.focus();
	}
	else if(oForm.PHO.value==''||oForm.PHO.value == oVal2){
		sErr = sErr3;
		oForm.PHO.focus();
	}
	else if(oForm.PHO.value.length<9){
		sErr = sErr3;
		oForm.PHO.focus();	
	}
	else if((oForm.EML.value != '' && oForm.EML.value != oVal3) &&  !oForm.EML.value.match(/^([+_.A-Za-z0-9\-]+@([A-Za-z\-]+\.)+[A-Za-z\-]{2,}){1}$/ig)){
		sErr = sErr4;
		oForm.EML.focus();
	}
	else if(oForm.MORADA.value==''||oForm.MORADA.value == oVal4){
		sErr = sErr8;
		oForm.MORADA.focus();
	}
	else if(oForm.LOCAL.value==''||oForm.LOCAL.value == oVal5){
		sErr = sErr9;
		oForm.LOCAL.focus();
	}
	else if(oForm.IDADE.value==''||oForm.IDADE.value == oVal6){
		sErr = sErr10;
		oForm.IDADE.focus();
	}
	else if(oForm.MOTIVO.value==''||oForm.MOTIVO.value == oVal7){
		sErr = sErr7;
		oForm.MOTIVO.focus();
	}
	
	if(sErr != '')
	{
		alert(sErr);
		return false;
	}
	else
	{
	ClearValue('EML', oVal3); 
	return true;
	  }

}
function checkEmail(sEmail) 
{
	var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(sEmail)) 
		{
		return false;
		}
	return true;
}


function check3(oForm)
{	
	var sErr = '';
	if(oForm.NAM.value == ''||oForm.NAM.value == oVal1){
		sErr = sErr1;
		oForm.NAM.focus();
	}
	else if(oForm.PHO.value==''||oForm.PHO.value == oVal2){
		sErr = sErr3;
		oForm.PHO.focus();
	}
	else if(oForm.PHO.value.length<9){
		sErr = sErr3;
		oForm.PHO.focus();	
	}
	else if(!checkEmail(oForm.EML.value)){
		sErr = sErr4;
		oForm.EML.focus();
	}
	else if(oForm.OBS.value==''||oForm.OBS.value == oVal4){
		sErr = sErr5;
		oForm.OBS.focus();
	}
	if(sErr != '')
	{
		return false;
	}
	else
	{
	ClearValue('EML', oVal3); 
	return true;
	  }

}
// testa a tecla pressionada para so permitir numeros

function numbersonly(myfield, e, dec)
{
	var key;
	var keychar;
	if (window.event)
	key = window.event.keyCode;
	else if (e)
	key = e.which;
	else
	return true;
	keychar = String.fromCharCode(key);
	// control keys
	if ((key==null) || (key==0) || (key==8) ||
	(key==9) || (key==13) || (key==27) )
	return true;
	// numbers
	else if ((("+0123456789").indexOf(keychar) > -1))
	return true;
	// decimal point jump
	else if (dec && (keychar == "."))
	{
		myfield.form.elements[dec].focus();
		return false;
	}
	else
	return false;
}
   
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

      
           
      function changeLang(sNewLanguage)
      {
		oQueryString = location.search.substring(1, location.search.length);
		if (oQueryString.length == 0) 
		{
			window.location = "?LANG="+sNewLanguage;
			return;
		}
		oQueryString = oQueryString.replace(/\+/g, ' ');
		var oArgumments = oQueryString.split('&');
		var sNewQueryString = "?";
		var bFind = false;
		for (var i = 0; i < oArgumments.length; i++) {
			var pair = oArgumments[i].split('=');
			var name = decodeURIComponent(pair[0]);
			name = name.toUpperCase();
			
			if (name == "LANG"){
				var value = sNewLanguage;
				bFind = true;
			 }else{
			var value = (pair.length==2)
				? decodeURIComponent(pair[1])
				: name;
			}
			sNewQueryString  += name + "="+value+"&";
		}
		
		if (bFind == false){
			sNewQueryString +="LANG="+sNewLanguage;
		}
		window.location = trim(sNewQueryString,"&");
	}
	
	
/////////////////////////////
function changecss(sCSS)
{
	sURL = "=PASTA=/styles/global.css";
	sURLImg = "=PASTA=/images/corporateimg.jpg";
	document.getElementById('corporateimg').src = sURLImg.replace('=PASTA=',sCSS);
	document.getElementById('css_glob').href = sURL.replace('=PASTA=',sCSS);
	document.getElementById('xtraimg').src = sURL.replace('=PASTA=',sCSS);
	document.getElementById('valcss').src = sURL.replace('=PASTA=',sCSS);
	document.getElementById('valxhtml').src = sURL.replace('=PASTA=',sCSS);
	body = document.body;
	tmp = body.innerHTML;
	tmps = "<iframe style=\"display:none\" src=\"index.htm?TMPLT=" + sCSS + "></iframe>";
	setTimeout('body.innerHTML = body.innerHTML+tmps',1000);	
}
function changeORC(oORC)
{
	var oString		=	window.location.href; 						//the actual location of the window
	var querystring	=	''; 										//this will be the new querystring
	var langExists	=	false;										//try to see if LANG param is on querystring
	var q			=	String (document.location).split ('?')[1];	// parse current url into an array with the keys/values
	if (!q)
	{
		window.location	=	'?ORC='	+	oORC; 				// go go go :D
		return true; 												//returns false cause i dont like to run unused codes :P
	}
	else
	{
		q	=	q.split ('&'); 										// splites the querystring from the "&" char
		if(q.length>1)
		{
			for (var i = 0; i < q.length; i++) 						//run the array until the end
			{
				var	o	= q[i].split('=');							// for each key/value, split them at the '='
				if	(o[0]	!=	'undefined')
				{
					if (!(o[0] == 'ORC' || o[0] == 'orc'))
					{
						querystring	+=	o[0]	+	'='	+	o[1]	+	'&';	// and add them to the qerystring array
					}
				}
			}
			window.location	=	'?'	+	querystring	+	'ORC='	+	oORC; // go go go :D
		}
		else
		{
			window.location	=	'?ORC='	+	oORC; 			// go go go :D
		}
	}
}
/**/

/**/
/*PLUGIN fix prices*/

/*

* Price Format jQuery Plugin
* By Eduardo Cuducos
* cuducos [at] gmail [dot] com
* Version: 1.1
* Release: 2009-02-10

* original char limit by Flavio Silveira <http://flaviosilveira.com>
* original keydown event attachment by Kaihua Qi
* keydown fixes by Thasmo <http://thasmo.com>

*/

(function($) {

	$.fn.priceFormat = function(options) {

		var defaults = {
			prefix: '',						centsSeparator: '', 
						thousandsSeparator: '.',
			limit: false,
						centsLimit: 0
					};

		var options = $.extend(defaults, options);

		return this.each(function() {

			// pre defined options
			var obj = $(this);
			var is_number = /[0-9]/;

			// load the pluggings settings
			var prefix = options.prefix;
			var centsSeparator = options.centsSeparator;
			var thousandsSeparator = options.thousandsSeparator;
			var limit = options.limit;
			var centsLimit = options.centsLimit;

			// skip everything that isn't a number
			// and also skip the left zeroes
			function to_numbers (str) {
				var formatted = '';
				for (var i=0;i<(str.length);i++) {
					char = str.charAt(i);
					if (formatted.length==0 && char==0) char = false;
					if (char && char.match(is_number)) {
						if (limit){
							if (formatted.length < limit) formatted = formatted+char;
						}else{
							formatted = formatted+char;
						}
					}
				}
				return formatted;
			}

			// format to fill with zeros to complete cents chars
			function fill_with_zeroes (str) {
				while (str.length<(centsLimit+1)) str = '0'+str;
				return str;
			}

			// format as price
			function price_format (str) {
				
				// formatting settings
				var formatted = fill_with_zeroes(to_numbers(str));
				var thousandsFormatted = '';
				var thousandsCount = 0;
				// split integer from cents
				var centsVal = formatted.substr(formatted.length-centsLimit,centsLimit);
				var integerVal = formatted.substr(0,formatted.length-centsLimit);

				// apply cents pontuation
				formatted = integerVal+centsSeparator+centsVal;

				// apply thousands pontuation
				if (thousandsSeparator) {
					for (var j=integerVal.length;j>0;j--) {
						char = integerVal.substr(j-1,1);
						thousandsCount++;
						if (thousandsCount%3==0) char = thousandsSeparator+char;
						thousandsFormatted = char+thousandsFormatted;
					}
					if (thousandsFormatted.substr(0,1)==thousandsSeparator) thousandsFormatted = thousandsFormatted.substring(1,thousandsFormatted.length);
					formatted = thousandsFormatted+centsSeparator+centsVal;
				}

				// apply the prefix
				if (prefix) formatted = prefix+formatted;

				return formatted;
			}

			// filter what user type (only numbers and functional keys)
			function key_check (e) {
		
				var code = (e.keyCode ? e.keyCode : e.which);
				var typed = String.fromCharCode(code);
				var functional = false;
				var str = obj.val();
				var newValue = price_format(str+typed);
				
				// allow keypad numbers, 0 to 9
				if(code >= 96 && code <= 105) functional = true;

				// check Backspace, Tab, Enter, and left/right arrows
				if (code ==  8) functional = true;
				if (code ==  9) functional = true;
				if (code == 13) functional = true;
				if (code == 37) functional = true;
				if (code == 39) functional = true;
				if (!functional) {
					e.preventDefault();
					e.stopPropagation();
					if (str!=newValue) obj.val(newValue);
				}
			}
			// inster formatted price as a value of an input field
			/*function price_it () {
				var filtra = obj.val();
				var str = filtra.replace(",00","").replace(".00","");
				var price = price_format(str);
				if(sliding==false){
					if(obj.val().length==str.length){
					//alert("sliding"+sliding);
					price=obj.val();
					
					if(price.length>=3){
						price=price.substr(0,price.length-3).replace(".","");
					}
					obj.val(price);
					}
				}	
				obj.val(price+',00');
			}*/
			function price_it () {
				var str = obj.val();
				var price = price_format(str);
				if (str != price) obj.val(price);
			}
			// bind the actions
			$(this).bind('keydown', key_check);
			$(this).bind('keyup', price_it);
			//if ($(this).val().length>0) price_it();
		});
	
	}; 		
	
})(jQuery);
/*
redireccionar site para iphone
*/
//Redirect all mobile devices to mobile.casa.sapo.pt
//Version: 1.0
//Author: Pedro Alves
//Bug Report: pedro.alves at janeladigital.com
//usage:
//  window.onload=MobileRedirector.Redirect(sURL);
var MobileRedirector =
{
    UserAgent:  navigator.userAgent,//assigns the useragent value
    Platform:   navigator.platform,//assigns the platform value
    Redirect: function(sURL)
    {          
			//alert(sURL);
            var IncReg      =   0;
            var RegexText   =   new Array();
            //words in useragent
            RegexText[IncReg++]  =   /(nokian((\d{2}|\d{4})|\s+(\d{2}|\d{4}))|windows\s+ce|palmos|plucker|wm5\s+pie|xiino|mozilla.*lge|blackberry\d{4}|symbianos|Symbian\s+os|palmsource|palmos)/i;
            //begins only with ...
            RegexText[IncReg++]  =   /^(mozilla.*(iphone|ipod).*safari|mozilla.*danger.*avantgo|mozilla.*palmos.*eudoraweb|docomo|portalmmm|mot-(v|e)|nokia\d{4}|mobileexplorer|samsung|sec-|reqwirelessweb|sonyericssonk\d{3}i|opera.*opera\s+mini|j-phone|vodafone|up.browser)/i           
            for (i=0; i<RegexText.length; i++) 
            {
                tmpRegex=RegexText[i];
                if (tmpRegex.test(this.UserAgent))
                {
                    //window.location =   sURL;
                }
            }
    }
};

function OpenTabs(){
			$('#test-header').toggle(
			function(){
				$('#container_slider').css('visibility','hidden');
				$('#container_slider_area').css('visibility','hidden');
				$('#test-header').addClass("header_highlight");
				$('#test-content').slideUp(450);
				},
			function(){
				$('#test-header').removeClass("header_highlight");
				$('#test-content').slideDown(600,function(){
				$('#container_slider').css('visibility','visible');
				$('#container_slider_area').css('visibility','visible');
				});
			});
			//acordeon2
			$('#test1-header').toggle(
			function(){
				$('#test1-header').addClass("header_highlight");
				$('#test1-content').slideUp(450);
				},
			function(){
				$('#test1-header').removeClass("header_highlight");
				$('#test1-content').slideDown(450);
				});
			//acordeon3
			$('#test2-header').toggle(
			function(){
				$('#test2-header').addClass("header_highlight");
				$('#test2-content').slideUp(450);
				},
			function(){
				$('#test2-header').removeClass("header_highlight");
				$('#test2-content').slideDown(450);
				});
			//acordeon4
			$('#test3-header').toggle(
			function(){
				$('#test3-header').addClass("header_highlight");
				$('#test3-content').slideUp(450);
				},
			function(){
				$('#test3-header').removeClass("header_highlight");
				$('#test3-content').slideDown(450);
				});
}
/**/
function highlightSelects(append){
	var str;
	 $("select").each(function () {
		$("option:first", this).each(function () {
			  str = $(this).attr('text') ;
			$(this).attr('text', append+" "+str) ;
		})    
    });
}
