function enableDisableElement( tagName, enable ) {
    var elems = document.getElementsByTagName( tagName );
    if (elems)
      for (i=0; i<elems.length; i++)
          elems[i].style.display = enable ? '' : 'none';
}

function submitContactFormPopup(btn) {
    var f = btn.form ;
    var email = f.email.value ;
    var text = f.text.value ;
    var nombre = f.nombre.value ;
    if ( GOLDStringTrim( nombre ) == "" ) return GOLDAlertError( "Debes ingresar tu nombre.", f.nombre ) ;
    if ( GOLDStringTrim( email ) == "" ) return GOLDAlertError( "Debes ingresar tu e-mail.", f.email ) ;
    var re = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/ ;
    if ( !email.match( re ) ) return GOLDAlertError( "Debes ingresar un e-mail válido.", f.email ) ;
    if ( GOLDStringTrim( text ) == "" ) return GOLDAlertError( "Debes ingresar tus comentarios.", f.text ) ;
    var gc = new GOLDComponent( {
        elementId: "contactFormPopup"
    } ) ;
    gc.name = "contact" ;
    gc.method = "POST" ;
    gc.componentPath = "" ;
    gc.componentFileExtension = ".php" ;
    gc.load( {
        Nombre: nombre,
        Email : email,
        TelefonoFijo: f.telefonoFijo.value,
        TelefonoMovil: f.telefonoMovil.value,
        Asunto: f.asunto.value,
        Comentarios : text } ) ;
    closeContactFormPopup() ;
}

function submitGuestBookFormPopup(btn) {
    var f = btn.form ;
    var text = f.text.value ;
    var nombre = f.nombre.value ;
    var email = f.email.value ;
    if ( GOLDStringTrim( nombre ) == "" ) return GOLDAlertError( "Debes ingresar tu nombre.", f.nombre ) ;
    if ( GOLDStringTrim( text ) == "" ) return GOLDAlertError( "Debes ingresar tus comentarios.", f.text ) ;
    if ( GOLDStringTrim( email ) != "" ) {
        var re = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/ ;
        if ( !email.match( re ) ) return GOLDAlertError( "Debes ingresar un e-mail válido.", f.email ) ;
    }
    var gc = new GOLDComponent( {
        elementId: "guestBookFormPopup"
    } ) ;
    gc.name = "guestBookSubmit" ;
    gc.method = "POST" ;
    gc.componentPath = "" ;
    gc.componentFileExtension = ".php" ;
    gc.load( {
        name: nombre,
        email: email,
        comment : text } ) ;
    closeGuestBookFormPopup() ;
    document.location.reload() ;
}

function submitContact( btn ) {
    var f = btn.form ;
    var email = f.email.value ;
    var text = f.text.value ;
    var nombre = f.nombre.value ;
    if ( GOLDStringTrim( nombre ) == "" ) return GOLDAlertError( "Debes ingresar tu nombre.", f.nombre ) ;
    if ( GOLDStringTrim( email ) == "" ) return GOLDAlertError( "Debes ingresar tu e-mail.", f.email ) ;
    var re = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/ ;
    if ( !email.match( re ) ) return GOLDAlertError( "Debes ingresar un e-mail válido.", f.email ) ;
    if ( GOLDStringTrim( text ) == "" ) return GOLDAlertError( "Debes ingresar tus comentarios.", f.text ) ;
    var gc = new GOLDComponent( {
        elementId: "contact"
    } ) ;
    gc.name = "contact" ;
    gc.method = "POST" ;
    gc.componentPath = "" ;
    gc.componentFileExtension = ".php" ;
    gc.load( {
        From: "fast-contact",
        Nombre: nombre,
        Email : email,
        Comentarios : text
    } ) ;
}

function addUser( btn ) {
    var f = btn.form ;
    var email = f.email.value ;
    if ( GOLDStringTrim( email ) == "" ) return GOLDAlertError( "Debes ingresar tu e-mail.", f.email ) ;
    var re = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/ ;
    if ( !email.match( re ) ) return GOLDAlertError( "Debes ingresar un e-mail válido.", f.email ) ;
    var gc = new GOLDComponent( {
        elementId: "subscribe"
    } ) ;
    gc.name = "adduser" ;
    gc.method = "POST" ;
    gc.componentPath = "" ;
    gc.componentFileExtension = ".php" ;
    gc.load( {
        email : email
    } ) ;
}

function showContactFormPopup( ) {
    var gc = new GOLDComponent( {
        elementId : "contactFormPopup"
    } ) ;
    gc.componentPath = "" ;
    gc.componentFileExtension = ".php" ;
    gc.name = "contactForm" ;
    gc.load( ) ;
    enableDisableElement( "select", false ) ;
    gc.element.style.visibility = "visible" ;
}

function showGuestBookFormPopup( ) {
    var gc = new GOLDComponent( {
        elementId : "guestBookFormPopup"
    } ) ;
    gc.componentPath = "" ;
    gc.componentFileExtension = ".php" ;
    gc.name = "guestBookForm" ;
    gc.load( ) ;
    enableDisableElement( "select", false ) ;
    gc.element.style.visibility = "visible" ;
}
      
function closeContactFormPopup() {
    var e = document.getElementById( "contactFormPopup" ) ;
    if ( e ) {
        e.style.visibility = "hidden" ;
        enableDisableElement( "select", true ) ;
    }
}

function closeGuestBookFormPopup() {
    var e = document.getElementById( "guestBookFormPopup" ) ;
    if ( e ) {
        e.style.visibility = "hidden" ;
        enableDisableElement( "select", true ) ;
    }
}


function showPrivacyPopup( ) {
    var gc = new GOLDComponent( {
        elementId : "privacyPopup"
    } ) ;
    gc.componentPath = "" ;
    gc.componentFileExtension = ".php" ;
    gc.name = "privacy" ;
    gc.load( ) ;
    enableDisableElement( "select", false ) ;
    gc.element.style.visibility = "visible" ;
}
    
function closePrivacyPopup() {
    var e = document.getElementById( "privacyPopup" ) ;
    e.style.visibility = "hidden" ;
    enableDisableElement( "select", true ) ;
}

var cleared = new Array() ;
function focusText( input ) {
    var found = false ;
    for ( var i = 0 ; i < cleared.length ; i++ ) {
        if ( cleared[ i ] == input ) {
            found = true ;
            break ;
        }
    }
    if ( !found ) {
        input.value = "" ;
        cleared[ cleared.length ] = input ;
    }
}

function bookmark( a ) {
    if( document.all && !window.opera ) { 
        window.external.AddFavorite( document.location.href, document.title ) ;
    } else {
        window.sidebar.addPanel( document.title, document.location.href, "" ) ;
    }
}
var opacity = new Array( ) ;
var randomImageLoadingTask = null ;
function setOpacity( elementId, value ) {
    initOpacity( elementId ) ;
    var element = document.getElementById( elementId ) ;
    if ( element ) {
        if ( document.all && !document.opera ) {
            element.style.filter = "alpha(opacity=" + value + ")";
        } else {
            element.style.opacity = value / 100;
            element.style.MozOpacity = value / 100;
            element.style.KhtmlOpacity = value / 100;
        }
    }
}

//function getOpacity( elementId ) {
//    var element = document.getElementById( elementId ) ;
//    var opacity = null ;
//    if ( element ) {
//        if ( document.all && !document.opera ) {
//            element.style.filter = "alpha(opacity=" + opacity + ")";
//        } else {
//            element.style.opacity = opacity / 100;
//            element.style.MozOpacity = opacity / 100;
//            element.style.KhtmlOpacity = opacity / 100;
//        }
//    }
//    return opacity ;
//}

function OpacityValue() {
    this.value = 0 ;
    this.fadeIn = true ; // block the fadeIn
    this.fadeOut = false ; // block the fadeOut
}

function loadRandomImage( elementId ) {
    var gc = new GOLDComponent( {
        elementId : elementId
    } ) ;
    gc.componentPath = "" ;
    gc.componentFileExtension = ".php" ;
    gc.name = elementId ;
    gc.load( ) ;
}


function initOpacity( elementId ) {
    if (!opacity[ elementId ]) {
        opacity[ elementId ] =  new OpacityValue() ;
    }
        
}

function getOpacity( elementId ) {
    initOpacity( elementId ) ;
    return opacity[ elementId ] ;
}

function fadeIn( elementId ) {
    if ( randomImageLoadingTask != null ) {
        clearTimeout(randomImageLoadingTask) ;
        randomImageLoadingTask = null ;
    }
    var ov = getOpacity( elementId ) ;
    if ( ov.value < 100 && ov.fadeIn ) {
        if ( ov.value < 10 ) {
            hideRandomImageLoading() ;
        }
        ov.value += 2 ;
        if ( ov.value > 100 ) ov.value = 100 ;
        setOpacity( elementId, ov.value ) ;
        setTimeout( "fadeIn( '" + elementId +"' ) ;", 2 ) ;
    } else if ( ov.value >= 100 ) {
        ov.fadeIn = false ;
        ov.fadeOut = true ;
        setTimeout( "fadeOut( '" + elementId +"' ) ;", 10000 ) ;
    }
}

function hideRandomImageLoading() {
    var ril = document.getElementById( "randomImageLoading" ) ;
    ril.style.visibility = "hidden" ;
}

function showRandomImageLoading() {
    var ril = document.getElementById( "randomImageLoading" ) ;
    ril.style.visibility = "visible" ;
}

function fadeOut( elementId ) {
    var ov = getOpacity( elementId ) ;
    if ( ov.value > 0  && ov.fadeOut ) {
        ov.value -= 2 ;
        if ( ov.value < 0 ) ov.value = 0 ;
        setOpacity( elementId, ov.value ) ;
        setTimeout( "fadeOut( '" + elementId +"' ) ;", 2 ) ;
    } else if ( ov.value == 0 ) {
        ov.fadeOut = false ;
        ov.fadeIn = true ;
        randomImageLoadingTask = setTimeout( "showRandomImageLoading() ;", 500 ) ;
        loadRandomImage( elementId ) ;
    }
}

function rotateImage() {
    fadeOut( "randomImage" ) ;
}
