function showHideTag(id) {    
    if(document.getElementById(id) != null) {
        if(document.getElementById(id).style.display == 'block') {
            document.getElementById(id).style.display = 'none';
        } else if(document.getElementById(id).style.display == 'none') {
            document.getElementById(id).style.display = 'block';
        } else {
            document.getElementById(id).style.display = 'none';
        }
    }
}

var reportFormBox = {
    backgroundId: 'bgndId',
    backgroundHeight: 1200,
    containerId: 'reportFormId',
    containerWidth: 500,
    windowWidth: 1280,
    windowHeight: 1024,
    windowScrollX: 0,
    windowScrollY: 0,
    reportFormFile: '../comunitate/userReportForm.php',
    divsToHide: [],
    setBackgroundId: function(backgroundId) {
        this.backgroundId = backgroundId;
    },
    getBackgroundId: function() {
        return this.backgroundId;
    },
    setBackgroundHeight: function(backgroundHeight) {
        this.backgroundHeight = backgroundHeight;
    },
    getBackgroundHeight: function() {
        return this.backgroundHeight;
    },
    setContainerId: function(containerId) {
        this.containerId = containerId;
    },
    getContainerId: function() {
        return this.containerId;
    },
    setContainerWidth: function(containerWidth) {
        this.containerWidth = containerWidth;
    },
    getContainerWidth: function() {
        return this.containerWidth;
    },
    setWindowWidth: function(windowWidth) {
        this.windowWidth = windowWidth;
    },
    getWindowWidth: function() {
        return this.windowWidth;
    },
    setWindowHeight: function(windowHeight) {
        this.windowHeight = windowHeight;
    },
    getWindowHeight: function() {
        return this.windowHeight;
    },
    setWindowScrollX: function(windowScrollX) {
        this.windowScrollX = windowScrollX;
    },
    getWindowScrollX: function() {
        return this.windowScrollX;
    },
    setWindowScrollY: function(windowScrollY) {
        this.windowScrollY = windowScrollY;
    },
    getWindowScrollY: function() {
        return this.windowScrollY;
    },
    setReportFormFile: function(reportFormFile) {
        this.reportFormFile = reportFormFile;
    },
    getReportFormFile: function() {
        return this.reportFormFile;
    },
    addDivToHide: function(id) {
        this.divsToHide.push(id);
    },
    getDivsToHide: function() {
      return this.divsToHide;
    },
    initWindowParameters: function() {
        if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
            this.setWindowWidth(document.body.clientWidth);
            this.setWindowHeight(document.body.clientHeight);
        } else if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
            this.setWindowWidth(window.innerWidth);
            this.setWindowHeight(window.innerHeight);
        } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
            this.setWindowWidth(document.documentElement.clientWidth);
            this.setWindowHeight(document.documentElement.clientHeight);
        }

        if( typeof( window.pageYOffset ) == 'number' ) {
            //Netscape compliant
            this.setWindowScrollY(window.pageYOffset);
            this.setWindowScrollX(window.pageXOffset);
        } else if ( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
            //DOM compliant
            this.setWindowScrollY(document.body.scrollTop);
            this.setWindowScrollX(document.body.scrollLeft);
        } else if ( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollLeft == 0 || document.documentElement.scrollTop || document.documentElement.scrollTop == 0 ) ) {
            //IE6 standards compliant mode
            this.setWindowScrollY(document.documentElement.scrollTop);
            this.setWindowScrollX(document.documentElement.scrollLeft);
        }
    },
    showReportForm: function (fromUid, reportedUid, contentType, contentId, extraData) {
        new Ajax.Request(this.getReportFormFile(), {
            method: 'get',
            encoding: 'UTF-8',
            parameters: {fromUid: fromUid, reportedUid: reportedUid, contentType: contentType, contentId: contentId, extraData: extraData},
            onSuccess: function(transport) {
                if (200 == transport.status) {
                    if(transport.responseText.toString().length < 500) {
                        eval(transport.responseText.toString());
                        if(typeof(answer) != 'undefined') {                                                
                            if(answer.code == 7) {
                                alert(answer.msg);
                            } else {
                                alert('Incarcarea formularului in pagina a esuat! Mai incearca odata!');    
                            }
                        }        
                    } else {
                        reportFormBox.displayBox(transport.responseText);
                    }                            
                } else {
                    alert ('Incarcarea formularului in pagina a esuat! Mai incearca odata!');
                }
            }
        });
    },
    addReportMessage: function () {
        var confirm_answer = confirm("Esti sigur ca vrei sa raportezi?\nAtentie, daca raportezi gresit, Aurel va trebui sa te penalizeze, luandu-ti 10 clopotei din cont!");
        
        if (confirm_answer) {
    		var fromUid = document.reportForm.fromUid.value;
            var reportedUid = document.reportForm.reportedUid.value;
            var contentType = document.reportForm.contentType.value;
            var contentId = document.reportForm.contentId.value;
            var message = document.reportForm.reportMessage.value;
            var extraData = document.reportForm.extraData.value;
    
            new Ajax.Request(this.getReportFormFile(), {
                method: 'post',
                encoding: 'UTF-8',
                parameters: {action: 'adauga', fromUid: fromUid, reportedUid: reportedUid, contentType: contentType, contentId: contentId, reportMessage: message, extraData: extraData},
                onSuccess: function(transport) {
                    if (200 == transport.status) {
                       eval(transport.responseText.toString());
                       
                       if(typeof(answer) != 'undefined') {                   
                           if(answer.code == 5 || answer.code == 6 || answer.code == 8) {
                               alert(answer.msg);
                           } else if(answer.code == 1 || answer.code == 2 || answer.code == 3 || answer.code == 4) {
                               reportFormBox.hideBox();
                           }
                       } else {
                           reportFormBox.hideBox();
                       }                              
                    } else {
                        alert ('Datorita unor probleme tehnice raportarea ta nu s-a inregistrat! Mai incearca o data!');
                    }
                }
            });
    	} else {
    		return false;
    	}        
    },
    displayBox: function (content) {
        if(document.getElementById(this.getContainerId())) {
            this.initWindowParameters();

            if(document.getElementById(this.getBackgroundId())) {
                var fundal = document.getElementById(this.getBackgroundId());

                fundal.style.width = this.getWindowWidth() + 'px';
                fundal.style.height = this.getWindowHeight() + 'px';
                fundal.style.display = 'block';
            }

            if(this.divsToHide.length > 0)
            {
                for(q in this.divsToHide)
                {
                    if(document.getElementById(this.divsToHide[q])) {
                        document.getElementById(this.divsToHide[q]).style.display = 'none';
                    }
                }
            }

            var container = document.getElementById(this.getContainerId());

            container.innerHTML = content;
            container.style.width = this.getContainerWidth() + 'px';
            container.style.top = (this.getWindowScrollY() + 20) + 'px';
            container.style.left = (this.getWindowScrollX() + (this.getWindowWidth() - this.getContainerWidth())/2) + 'px';
            container.style.display = 'block';
        }
    },
    hideBox: function () {
        if(this.divsToHide.length > 0)
        {
            for(q in this.divsToHide)
            {
                if(document.getElementById(this.divsToHide[q])) {
                    document.getElementById(this.divsToHide[q]).style.display = 'block';
                }
            }
        }

        if(document.getElementById(this.getBackgroundId())) {
            var background = document.getElementById(this.getBackgroundId());
            background.style.display = 'none';
        }

        if(document.getElementById(this.getContainerId())) {
            var container = document.getElementById(this.getContainerId());
            container.style.display = 'none';
        }
    }
}

reportFormBox.setContainerWidth(600);
reportFormBox.setBackgroundHeight(1200);
reportFormBox.setReportFormFile(HTTP + 'comunitate/userReportForm.php');
reportFormBox.addDivToHide('selectNotaId');
reportFormBox.addDivToHide('joc');