var now = new Date();
var year = now.getYear();
year = (year < 1000) ? year + 1900 : year;

var myimages = new Array();
rnd.today=new Date();
rnd.seed=rnd.today.getTime();

var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false;

function load(tab) {
    headerImage();
    if (tab) {
        tabLoad(tab);
    }
    scrollLoad(); // requires scroller/main.js include
}

function clearField(id) {
    document.getElementById(id).value = "";
}

function tabLoad(tab) {
    document.getElementById('tab' + tab).className = "active";
}

function getEURValue(eurorate, price) {
    price = eurorate*price;    
    price = price * Math.pow(10, 0)
    price = Math.round(price)
    price = price/Math.pow(10, 0)
    price = price.toString();

    if (price.length > 3) {
        price = price.substring(0,price.length-3) + "," + price.substring(price.length-3,price.length);
    }
    document.write("&nbsp;(€" + price + ")");
}

function populateNameValue(id) {
    document.getElementById(id.substring(0,id.length-2)).value = document.getElementById(id).options[document.getElementById(id).selectedIndex].innerHTML;
}

function closeHelp() {
    document.getElementById('help').innerHTML = "";
    document.getElementById('help').style.display = "none";
}

function showSeason() {
	var season = "";
        var now = new Date();
	var month = now.getMonth()+1;
	var yy = now.getYear();
	var year = (yy < 1000) ? yy + 1900 : yy;
	var year2 = year.toString();
	var year2Int = 0;
	year2Int = parseInt(year2.substring(2,4));
	year2Int++;

	if (month < 6) {
		season = year;
	} else {
		season = year + "/" + padout(year2Int);
	}
	document.write(season);
}

function headerImage() {
    document.getElementById('header').style.backgroundImage = 'url(images/background/image' + rand(3) + '.gif)';
}

function rnd() {
    rnd.seed = (rnd.seed*9301+49297) % 233280;
    return rnd.seed/(233280.0);
}

function rand(number) {
    return Math.ceil(rnd()*number);
}

function padout(number) {
	return (number < 10) ? '0' + number : number;
}

function navigateTo(page) {
    if (page != null && page.length > 0) {
        if (page.indexOf("http://") == -1) {
            document.location.href = url + page;
        } else {
            window.open(page);
        }
    }
}

function scrollerEmail() {
    var email = window.open('mailto:?subject=' + escape('Destination Portugal - ' + title) + '&body=' + escape('Take a look at this site! Destination Portugal are a travel company offering exclusive villas, apartments and hotels across Europe at great prices!\n\n' + lnk + '\n\nIf you are interested in Destination Portugal, why not subscribe to our newsletter? Click the link below and follow the on-screen instructions to subscribe!\n\n' + url + 'news/subscribe.jsp\n\nRegards,'));
    if (navigator.appVersion.indexOf("MSIE") == -1) {
        email.close();
    }
}

function scrollerBookmark() {
    if ((navigator.appVersion.indexOf("MSIE") > 0) && (parseInt(navigator.appVersion) >= 4)) {
        window.external.AddFavorite(location.href,"Destination Portugal - " + title); 
    } else {
        alert("Please press <CTRL>+<D> to bookmark this page");
    }
}

function copyText(field) {
    var text = document.getElementById(field).value;

    if (window.clipboardData) {
    	// the IE-manier
    	window.clipboardData.setData("Text", text);
    } else {
        document.getElementById(field).focus()
        alert("Please manually select all text in the " + field + " field (CTRL+A) then copy (CTRL+C)");
    }
}