function menu_swap(obj,stat) {
    if(stat == "on") {
        obj.src = obj.src.replace("_off","_on");
    } else {
        obj.src = obj.src.replace("_on","_off");
    }
}

function show_hide(id){
    obj = document.getElementById(id);
    obj.style.display = obj.style.display == "none" ? "block":"none";
}

function popit(id,caption){
    window.open("http://www.webin.ro/lastimob/popup.php?id=" + id,null,"width=400, height=320, scrollbars=yes, status=no, menu=no, buttons=no, resizable=yes");
}

/*
        ajax class properties
        ajaxObj - Holds the XMLHttpRequest object
        actionString - the data that is going to be sent to the server
        section - the section to wich the data is sent to
        target_id - the id of the target into wich the ajax response will be inserted
*/

        
//ajaxTpl class
function ajaxTpl() {
                if(this.ajaxObj = init_ajax()) {
                        this.actionString = "?"
                        this.section = "";
                        this.target_id ="";
                } else {
                        return false;
                }
                ajaxTpl.prototype.insertTpl = function(feedbackData) {
                if (document.getElementById(this.targetId)) {
                        document.getElementById(this.targetId).innerHTML = feedbackData;
                } else {
                        alert("Warning: " + this.targetId + " does not exist!");
                }
        }
        function init_ajax(){
            var xmlHttp
                    try {
                    // Firefox, Opera 8.0+, Safari
                    xmlHttp=new XMLHttpRequest();
                    }
                    catch (e) {
                            // Internet Explorer
                            try {
                                    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
                            }
                            catch (e) {
                                    try {
                                            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                                    }
                                    catch (e) {
                                            alert("Browserul dumneavoastra nu suporta AJAX!");
                                            return false;
                                    }
                            }
                    }
                    return xmlHttp;
            }
        
            ajaxTpl.prototype.getajax = function(indexFile , method) {
                    if (document.getElementById(this.targetId)) {
                            document.getElementById(this.targetId).innerHTML = " Se incarca...";
                    } else {
                            alert("Warning: " + this.targetId + " does not exist!");
                    }
                    var	ajaxTmp = this.ajaxObj;
                    var me = this;
                    ajaxTmp.onreadystatechange = function() {
                    if(ajaxTmp.readyState == 4) {
                                if(ajaxTmp.responseText != "") {
                            me.insertTpl(ajaxTmp.responseText) 
                                } else {
                                        me.insertTpl("O eorare a intervenit, ne cerem scuze.") 
                                }
                    }
                }
                    if (method == "GET") {
                            this.ajaxObj.open(method,indexFile + "?" + this.section + "&" + this.actionString ,true);
                            this.ajaxObj.send(null);
                    } else if (method == "POST") {
                            this.ajaxObj.open(method,indexFile,true);
                            this.ajaxObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
                            this.ajaxObj.send(this.actionString);
                    }
            }
        }
function form_to_action(formId,output_target) {
        var sender = new ajaxTpl();
        var form = document.getElementById(formId);
        var toSend = new Array();
        for(i = 0; i<form.elements.length; i++) {
                obj = form.elements[i];
                switch (obj.type) {
        case "radio":
        case "checkbox":
            if(obj.checked) {
                                toSend.push(obj.name + "=" + obj.value);
                        }
            break;
                case "select-multiple":
                        for(j = 0; j<obj.options.length; j++) {
                                if(obj.options[j].selected) {
                                        toSend.push(obj.name + "[]=" + obj.options[j].value); 
                                }
                        }
                        break;
                case "select-one":
        case "text":
        case "textarea":
        case "password":
        case "hidden":
            toSend.push(obj.name + "=" + escape(obj.value));
            break;
                }
        }
        sender.actionString = toSend.join("&");
        sender.targetId = output_target;
        sender.getajax(form.action,form.method.toUpperCase());
}

