﻿// Textos em caixas de formularios (controlos newsletter, pesquisa, ...)

function TextFieldOnFocus(InputTag, TextToShow)
{
	if (InputTag.value == TextToShow)
	{
		InputTag.value = "";
	}
}
function TextFieldOnBlur(InputTag, TextToShow)
{
	if (InputTag.value == "")
	{
		InputTag.value = TextToShow;
	}
}

function TextBoxMaxText(objTxt,maxLen){if(objTxt.value.length > (maxLen-1))return false;}

// para abertura da janela flutuante, recomende, ..

var newFloatWindow = null;
function openRecomende(URLtoOpen){
	FloatWindowFeatures ="menubar=no,scrollbars=no,location=no,favorites=no,resizable=no,status=no,toolbar=no,directories=no";
	var Swidth = 690;
	var Sheight = 415;
	var SwinLeft = (screen.width-Swidth)/2; 
	var SwinTop = (screen.height-(Sheight+10))/2; 
    newFloatWindow = window.open("","Recomende","width=" + Swidth +",height=" + Sheight + ",left=" + SwinLeft + ",top=" + SwinTop + ",'" + FloatWindowFeatures + "'");
   	if (newFloatWindow != null) {
		if (newFloatWindow.opener == null) {
        	newFloatWindow.opener = self;
        }
    newFloatWindow.location.href = URLtoOpen;
   	newFloatWindow.opener.name = "xtendsite";
    newFloatWindow.focus();
	}
}


//Esta funcao serve para associar à tecla enter numa caixa de texto o evento click de um botão
function doButtonClick(buttonName,e)
{
    var key;
        if(window.event)
            key = window.event.keyCode;     //IE
        else
            key = e.which;     //firefox
    if (key == 13)
    {
        var btn = document.getElementById(buttonName);
        if (btn != null)
        {   btn.click();
            event.keyCode = 0
        }
    }
}


// Popup window (print, ...)
// parametersToOpenWindow: URLtoOpen, OpenerSufix, NewWindowName, height, width, params
var newWindow = null;
function openWindow(parametersToOpenWindow){
    var test = "'";
    var winLeft = 0;
    var winTop = 0;
    var windowFeatures ="menubar=no,scrollbars=yes,location=no,favorites=no,resizable=no,status=no,toolbar=no,directories=no";
	var URLtoOpen = "";
	var SelectArray = new Array();
	SelectArray = parametersToOpenWindow.split(",")
	if (newWindow && newWindow.open && SelectArray[0]=="close.htm") {
		if (!newWindow.closed) {
			newWindow.close();
		}
	} else {
        winLeft = (screen.width-SelectArray[4])/2; 
        winTop = (screen.height-(SelectArray[3]+10))/2; 
        URLtoOpen = SelectArray[0] + "?" +SelectArray[5].split(":").join("&");
        newWindow = window.open("",SelectArray[2],"width=" + SelectArray[4] +",height=" + SelectArray[3] + ",left=" + winLeft + ",top=" + winTop + "," + test + windowFeatures + test);
        if (newWindow != null) {
        if (newWindow.opener == null) {
            newWindow.opener = self;
            }
        newWindow.location.href = URLtoOpen;
        newWindow.opener.name = "xtd" + SelectArray[1];
        newWindow.focus();
		}
    }
}

