﻿/* -------------------------------------------------------------------------------------------
DESCRIÇÃO GERAL

Nome do ficheiro: core.js
Título : Ficheiro JS principal para o site www.belasclubedecampo.pt
Autor : Sérgio Costa, scosta@ibt.pt
URL : http://www.belasclubedecampo.pt/App_Themes/Default/css/core.css

Licença: Copyright 2009, IBT. Todos os direitos reservados.
------------------------------------------------------------------------------------------- */

/*
    General
*/

var rootURL = 'http://www.belasclubedecampo.pt/golfe/';

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    }
    else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

function addUnLoadEvent(func) {
    var oldonunload = window.onunload;
    if (typeof window.onunload != 'function') {
        window.onunload = func;
    }
    else {
        window.onunload = function() {
            if (oldonunload) {
                oldonunload();
            }
            func();
        }
    }
}

function init(isContent) {
    replaceTagWithImage('h1');
    replaceTagWithImage('h2');
    replaceTagWithImage('h3');

    // flash
    var flashvars = { link: 'http://www.belasclubedecampo.pt'};
    var params = { wmode: 'transparent', scale: 'noscale' };
    var attributes = {};
    swfobject.embedSWF(rootURL + 'App_Themes/Default/swf/header.swf', 'divFlashContent', '945', '365', '9.0.0', 'expressInstall.swf', flashvars, params, attributes);
}

function ajMenu(action) {
    if (action == 1) {
        $('divGroupItems').style.display = 'block';
    }
    else {
        $('divGroupItems').style.display = 'none';
    }
}

function pbMenu(action) {
    if (action == 1) {
        $('divPlanbelasItems').style.display = 'block';
    }
    else {
        $('divPlanbelasItems').style.display = 'none';
    }
}

function cancelPropagation(e) {
    if (!e) {
        window.event.cancelBubble = true;
    }
    else if (e.stopPropagation) {
        e.stopPropagation();
    }
}

function preventDefaultAction(e) {
    if (!e) var e = window.event; // IE
    if (e.preventDefault) {
        e.preventDefault();
    } else {
        e.returnValue = false; // IE
    }
}

function fieldValue(control, newValue, oldValue, pwd) {
    if (control.value == oldValue) {
        if (pwd == 1) {
            if (newValue == '') {
                control.type = 'password';
            }
            else {
                control.type = 'text';
            }
        }
        control.value = newValue;
    }
}

function replaceTagWithImage(tag) {
    var elements = document.getElementsByTagName(tag);
    for (i = elements.length - 1; i >= 0; i--) {
        var element = elements[i];
        var attribute = element.getAttribute('imageURL');
        if (attribute != null) {
            var image = document.createElement("img");
            image.src = attribute;
            image.border = 0;
            image.alt = element.innerHTML;
            element.parentNode.replaceChild(image, element);
        }
    }

}

function checkAccess(e, control) {
    if (typeof event != 'undefined') {
        var pressedkey = window.event.keyCode;
    }
    else {
        var pressedkey = e.charCode;
        if (pressedkey == 0) {
            pressedkey = e.keyCode;
        }
    }

    if (pressedkey == 13) {
        selectLocation(control);
        return false;
    }
}

function pop(cid, tag, width, height) {
    var left = (screen.availWidth / 2) - (width / 2);
    var top = (screen.availHeight / 2) - (height / 2);

    window.open(rootURL + '/pop.aspx?cid=' + cid + '&t=' + tag + '&w=' + width + '&h=' + height, 'pop', 'width=' + width + ', height=' + height + ', top=' + top + ', left=' + left + ', scrollbars=no, resizable=no');
}

function toggle(div) {
    var elements = document.getElementsByTagName('div');
    for (i = elements.length - 1; i >= 0; i--) {
        var element = elements[i];
        if (element.id.substring(0, 3) == 'mnu') {
            if (element.id == div) {
                element.style.display = 'block';
            }
            else {
                //element.style.display = 'none';
            }
        }
    }
}
