function show(id){
    if (document.getElementById(id).style.display == 'none') 
        document.getElementById(id).style.display = 'block'
    else 
        if (document.getElementById(id).style.display == 'block') 
            document.getElementById(id).style.display = 'none'
    
    
}

function goTo(href){
    window.location.href = href;
}

function typesum(){
    obj = document.cos;
    var ar = obj.prods.value.split(',');
    obj2 = document.getElementById('total');
    obj2.style.display = "block";
    
    suma = 0;
    for (i = 0; i < ar.length; i++) {
        //caut pretul pt fiecare;
        pret = 0;
        nrbuc = 0;
        for (j = 0; j < obj.length; j++) {
        
            if (obj[j].name == "pret[" + ar[i] + "]") 
                pret = obj[j].value;
            if (obj[j].name == "nr-buc[" + ar[i] + "]") 
                nrbuc = obj[j].value;
        }
        suma += pret * nrbuc;
        
    }
    obj2.innerHTML = "Total &#160;" + suma + " <b>RON</b>";
}

function swap(name){

    if (document.getElementById(name).style.display == 'none') {
        document.getElementById(name).style.display = 'block';
        document.getElementById(name + "_").innerHTML = '<img src="/pics/minus.gif"/>';
        
        document.getElementById(name + "_name").style.color = '#0090FF';
        document.getElementById(name).style.border = '1px solid #0090FF';
        if (document.getElementById(name + "_cos")) 
            document.getElementById(name + "_cos").style.color = '#0090FF';
        
    }
    else 
        if (document.getElementById(name).style.display == 'block') {
            document.getElementById(name).style.display = 'none';
            document.getElementById(name + "_").innerHTML = '<img src="/pics/plus.gif"/>';
            document.getElementById(name + "_name").style.color = 'orange';
            if (document.getElementById(name + "_cos")) 
                document.getElementById(name + "_cos").style.color = 'orange';
            
        }
    
    
}

function swap2(name){

    if (document.getElementById(name).style.display == 'none') {
        document.getElementById(name).style.display = 'block';
        document.getElementById(name + "_").innerHTML = '<img src="/pics/minus.gif"/>';
        
        document.getElementById(name + "_name").style.color = '#0090FF';
        document.getElementById(name).style.border = '1px solid #0090FF';
        
    }
    else 
        if (document.getElementById(name).style.display == 'block') {
            document.getElementById(name).style.display = 'none';
            document.getElementById(name + "_").innerHTML = '<img src="/pics/plus.gif"/>';
            document.getElementById(name + "_name").style.color = 'black';
            
        }
    
    
}


function newWindow(link, width, height){
    window.open(link, "", "height=" + height + ", width=" + width + ",menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,left=50,top=150")
}

var cmd;
var _ifName;

function open_color_picker(){
    window.open("color_picker.htm", "my_window", "toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=500, height=330")
}

function setC(color){

    document.getElementById(_ifName).contentWindow.document.execCommand(cmd, false, color);
    
}


function insert(id, ifName){
    _ifName = ifName;
    if ((id == "forecolor") || (id == "hilitecolor")) {
        cmd = id;
        if (cmd == "hilitecolor") {
            try {
                document.getElementById(ifName).contentWindow.document.execCommand("hilitecolor", false, "white");
            } 
            catch (e) {
                cmd = "backcolor";
            }
        }
        open_color_picker();
    }
    else 
        if (id == "createlink") {
            var url = prompt("URL:", "http://");
            if ((url != null) && (url != "")) {
                document.getElementById(ifName).contentWindow.document.execCommand("CreateLink", false, url);
            }
        }
        else 
            document.getElementById(ifName).contentWindow.document.execCommand(id, false, null);
    //document.getElementById("myif").contentWindow.focus();

}


function _select(selectname, ifName){
    var selIndex = document.getElementById(selectname).selectedIndex;
    if (selIndex != 0) {
        var selected = document.getElementById(selectname).options[selIndex].value;
        document.getElementById(ifName).contentWindow.document.execCommand(selectname, false, selected);
        document.getElementById(selectname).selectedIndex = 0;
    }
    document.getElementById(ifName).contentWindow.focus();
}

function viewSource(source, ifName){

    if (document.body.innerText) {
    
        if (source) {
            iHTML = document.getElementById(ifName).contentWindow.document.body.innerHTML;
            document.getElementById(ifName).contentWindow.document.body.innerText = iHTML;
        }
        else {
            iText = document.getElementById(ifName).contentWindow.document.body.innerText;
            document.getElementById(ifName).contentWindow.document.body.innerHTML = iText;
        }
        
    }
    else {
    
    
        if (source) {
            html = document.createTextNode(document.getElementById(ifName).contentWindow.document.body.innerHTML);
            document.getElementById(ifName).contentWindow.document.body.innerHTML = "";
            document.getElementById(ifName).contentWindow.document.body.appendChild(html);
        }
        else {
            html = document.getElementById(ifName).contentWindow.document.body.ownerDocument.createRange();
            html.selectNodeContents(document.getElementById(ifName).contentWindow.document.body);
            document.getElementById(ifName).contentWindow.document.body.innerHTML = html.toString();
        }
        
    }
    
}


function doNothing(){
    return true;
}

//window.onerror = doNothing;

function del_goto(link){
    if (confirm('Sunteti sigur ca vreti sa stergeti?')) 
        window.location.href = link;
}


window.onload = function(){

    if (document.getElementById('fish')) {
        document.getElementById('fish').onclick = function(){
            window.open(this.href);
            return false
        }
        document.getElementById('fish').onkeypress = function(){
            window.open(this.href);
            return false
        }
    }
    document.getElementById('sigla').ondblclick = function(){
        window.location.href = '/index.php?page=login'
    }
    
    
    aTags = document.getElementsByTagName('a');
    for (i = 0; i < aTags.length; i++) 
        if (aTags[i].className == 'imageLink') {
            aTags[i].onclick = function(){
                window.open(this.href);
                return false
            }
            aTags[i].onkeypress = function(){
                window.open(this.href);
                return false
            }
        }
    
    
    
    
    if (document.getElementById("myIf")) {
        document.getElementById("myIf").contentWindow.document.designMode = "On";
        document.getElementById("html").checked = false;
    }
}

function submitForm(obj, ifName){
    obj.eText.value = document.getElementById(ifName).contentWindow.document.body.innerHTML;
    obj.submit();
}

function addTable(ifName){
    var rows = prompt("rows", "");
    var cols = prompt("cols", "");
    var border = prompt("border", "");
    var cellspacing = prompt("cell spacing", "");
    var cellpadding = prompt("cell padding", "");
    html = '<table border=' + border + ' cellspacing=' + cellspacing + ' cellpadding=' + cellpadding + '>';
    for (i = 0; i < rows; i++) {
        html += '<tr>';
        for (j = 0; j < cols; j++) {
            html += '<td></td>';
        }
        html += '</tr>';
    }
    html += '</table>';
    
    document.getElementById(ifName).contentWindow.document.execCommand('inserthtml', false, html);
}

function showPic(current, last, productId){


    for (i = 1; i <= last; i++) {
    
        if (i == current) {
        
            document.getElementById('pic_' + productId + '_' + i).style.display = 'block';
            document.getElementById('but_' + productId + '_' + i).style.backgroundColor = '#eee';
        }
        else {
        
            document.getElementById('pic_' + productId + '_' + i).style.display = 'none';
            
            
            document.getElementById('but_' + productId + '_' + i).style.backgroundColor = 'white';
        }
    }
}

