﻿/*(function(){
    return new TellAFriend();
})();
*/

function TellAFriend() {
   
    this.isVisible = true;
    this.box = document.getElementById("ptWTBBucket");
    this.tellAFriendLink = document.getElementById("tellAFriendLink");
    this.tellAFriendName = document.getElementById("tellAFriendName");
    this.tellAFriendFrom = document.getElementById("tellAFriendFrom");
    this.tellAFriendTo = document.getElementById("tellAFriendTo");
    
    if (this.tellAFriendName)
        this.init(); 
}


TellAFriend.prototype = {

    init: function() {
        var self = this;
       
        if (this.tellAFriendName.value == this.tellAFriendName.getAttribute("rel") && 
            this.tellAFriendFrom.value == this.tellAFriendFrom.getAttribute("rel") && 
            this.tellAFriendTo.value == this.tellAFriendTo.getAttribute("rel"))
            this.toggleVisibility();
        
        this.tellAFriendLink.onclick = function() {self.toggleVisibility()};
        this.tellAFriendName.onfocus = function() {self.clearInput(this)};
        this.tellAFriendFrom.onfocus = function() {self.clearInput(this)};
        this.tellAFriendTo.onfocus = function() {self.clearInput(this)};
        this.tellAFriendName.onblur = function() {self.resetInput(this)};
        this.tellAFriendFrom.onblur = function() {self.resetInput(this)};
        this.tellAFriendTo.onblur = function() {self.resetInput(this)};    
    },
    
    toggleVisibility: function() {
        if (this.isVisible) {
            this.box.style.display = "none";
            this.isVisible = false;
        } else {
            this.box.style.display = "block";
            this.isVisible = true;
        }
    },
    
   clearInput: function(id) {
        if (id.getAttribute("rel") == id.value) id.value = "";
   },
   
   resetInput: function(id) {
        if(id.value == '') {
		    id.value = id.getAttribute("rel")
	    }
   }
}

var tell = new TellAFriend();

