﻿// Tab
//var nTab = 5;
function TabLoad(nTab) {
    var ActivePanel = $get("ctl00_cph_ucProductDetail1_hfActiveTab").value;
    if (ActivePanel == "") { ActivePanel = 'tab1'; }

    for (i = 1; i < nTab; i++) {
        if ('tab' + i == ActivePanel) {
            $get('div_' + ActivePanel).style.display = '';
            $get(ActivePanel).className = 'TabActive';
        }
        else {
            $get('div_' + 'tab' + i).style.display = 'none';
        }
    }
}

function TabChanged(obj, nTab) {
    obj.className = 'TabActive';
    $get('ctl00_cph_ucProductDetail1_hfActiveTab').value = obj.id;

    for (i = 1; i < nTab; i++) {
        if ('tab' + i == obj.id) {
            $get('div_' + obj.id).style.display = '';
        }
        else {
            $get('div_tab' + i).style.display = 'none';
            $get('tab' + i).className = 'Tab';
        }
    }
}


var menuids = ["VerticalMenu"] //Enter id(s) of SuckerTree UL menus, separated by commas

function buildsubmenus_vertical() {
    for (var i = 0; i < menuids.length; i++) {
        var ultags = document.getElementById(menuids[i]).getElementsByTagName("ul")
        for (var t = 0; t < ultags.length; t++) {
            ultags[t].parentNode.getElementsByTagName("a")[0].className = "subfolderstyle"
            if (ultags[t].parentNode.parentNode.id == menuids[i]) //if this is a first level submenu
                ultags[t].style.left = ultags[t].parentNode.offsetWidth + "px" //dynamically position first level submenus to be width of main menu item
            else //else if this is a sub level submenu (ul)
                ultags[t].style.left = ultags[t - 1].getElementsByTagName("a")[0].offsetWidth + "px" //position menu to the right of menu item that activated it
            ultags[t].parentNode.onmouseover = function() {
                this.getElementsByTagName("ul")[0].style.display = "block"
            }
            ultags[t].parentNode.onmouseout = function() {
                this.getElementsByTagName("ul")[0].style.display = "none"
            }
        }
        for (var t = ultags.length - 1; t > -1; t--) { //loop through all sub menus again, and use "display:none" to hide menus (to prevent possible page scrollbars
            ultags[t].style.visibility = "visible"
            ultags[t].style.display = "none"
        }
    }

}

function doClear(theText) {
    if (theText.value == theText.defaultValue) {
        theText.value = ""
    }
}

function isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode

    if (charCode == 44)
        return true;

    if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46)
        return false;

    return true;
}
function ChangePicture(PicPath) {
    Progress(); //Update progressi gösteriyor
    document.getElementById('ctl00_cph_ucProductDetail1_imgPicture').src = PicPath;
    setTimeout("document.getElementById('ctl00_cph_ucProductDetail1_imgPicture').style.display='';Progress();", 1500);
    //Update progressi kapatıyor
}



function Progress() {
    if (document.getElementById("Progress").style.display == 'none') {
        document.getElementById("Progress").style.display = '';
    }
    else {
        document.getElementById("Progress").style.display = 'none';
    }
}

function ShowHide(Obj) {
    try {
        if ($get(Obj).style.display == '') {
            $get(Obj).style.display = 'none';
        }
        else {
            $get(Obj).style.display = '';
        }
    }
    catch (e) {
        alert(e.message);
    }
}

function OpenChildWindow(URL, Width, Height) {
    var sFeatures = "dialogHeight: " + Height + "px;";
    sFeatures += "dialogWidth: " + Width + "px;";
    sFeatures += "center: yes;";
    sFeatures += "scroll: no;";
    sFeatures += "status: yes;";
    sFeatures += "resizable: yes;";

    entryWindow = window.showModalDialog(URL, 'ChildForm', sFeatures);
    if (entryWindow == true) {
        window.document.getElementById('ctl00_cph_btnHiddenForUpdate').click();
    }

}

function WindowClose() {
    window.returnValue = true;
    window.close();
}
function WindowCancel() {
    window.returnValue = false;
    window.close();
}


var w = 800, h = 600;

if (document.all || document.layers) {
    w = screen.availWidth;
    h = screen.availHeight;
}

function openPopup(theURL, Width, Height) { //v2.0

    var popW = Width, popH = Height;

    if (typeof (parent.blnMultilanguage) != "undefined" && popupLocation.indexOf("multilanguage") == -1)
        popH += 180;

    var leftPos = (w - popW) / 2, topPos = (h - popH) / 2;
    if (popH > 500)
        topPos = 0;

    entryWindow = window.open(theURL, 'Keops', 'width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos + ',status=0,resizable=1,scrollbars=yes,location=yes');
}


function getPrint(print_area) {
    var pp = window.open();
    pp.document.writeln('<HTML><HEAD><title>Baskı Önizleme</title></HEAD>')
    pp.document.writeln('<form  method="post">');
    pp.document.writeln('<TABLE width=100%><TR><TD></TD></TR><TR><TD align=right><INPUT ID="PRINT" type="button" value="Yazdır" onclick="javascript:location.reload(true);window.print();"><INPUT ID="CLOSE" type="button" value="Kapat" onclick="window.close();"></TD></TR><TR><TD></TD></TR></TABLE>');
    pp.document.writeln(document.getElementById(print_area).innerHTML);
    pp.document.writeln('</form></body></HTML>');

}

function CheckOtherIsCheckedByGVID(spanChk, gv) {
    var IsChecked = spanChk.checked;
    //    if (IsChecked) {
    //        spanChk.parentElement.parentElement.style.backgroundColor = '#228b22';
    //        spanChk.parentElement.parentElement.style.color = 'white';
    //    }

    var CurrentRdbID = spanChk.id;
    var CurrentRdbValue = spanChk.value;
    var Chk = spanChk;

    Parent = document.getElementById(gv);

    var items = Parent.getElementsByTagName('input');


    for (i = 0; i < items.length; i++) {

        if (items[i].id != CurrentRdbID && items[i].type == "radio" && items[i].value == CurrentRdbValue) {
            if (items[i].checked) {
                items[i].checked = false;
                //items[i].parentElement.parentElement.style.backgroundColor = 'white';
                //items[i].parentElement.parentElement.style.color = 'black';
            }

        }

    }

}


function CheckOtherIsCheckedByGVIDMore(spanChk) {
    var IsChecked = spanChk.checked;
    //    if (IsChecked) {
    //        spanChk.parentElement.parentElement.style.backgroundColor = '#228b22';
    //        spanChk.parentElement.parentElement.style.color = 'white';
    //    }

    var CurrentRdbID = spanChk.id;

    var Chk = spanChk;

    Parent = document.getElementById('ctl00_cph_ucShipping1_gvAddress');

    for (i = 0; i < Parent.rows.length; i++) {

        var tr = Parent.rows[i];
        var td = tr.childNodes[0];
        var item = td.firstChild;

        if (item.id != CurrentRdbID && item.type == "radio") {
            if (item.checked) {
                item.checked = false;
                //item.parentElement.parentElement.style.backgroundColor = 'white';
                //item.parentElement.parentElement.style.color = 'black';
            }
        }

    }

}

function Calculate(ComboNo) {
    try {
        var ddlP = document.getElementById("ctl00_cph_ddlP" + ComboNo);

        var Price = ddlP.options[ddlP.selectedIndex].getAttribute("Price");
        var CurrencyType = ddlP.options[ddlP.selectedIndex].getAttribute("CurrencyType");
        var TotalPrice = ddlP.options[ddlP.selectedIndex].getAttribute("TotalPrice");
        var Item = document.getElementById("ddlI" + ComboNo).value;
        var kar = document.getElementById("kar").value;

        //    if (isNaN(kar) == false & kar != "0") {
        //        Price = parseFloat(Price + ((Price / 100) * kar));
        //    }
        //    else {
        //        document.getElementById("kar").value = "0";
        //    }

        document.getElementById("p" + ComboNo).value = Price;
        document.getElementById("k" + ComboNo).innerText = CurrencyType;
        if (isNaN(kar) == false & kar != "0") {
            document.getElementById("t" + ComboNo).value = formatPrice((Price * Item) + (((Price * Item) / 100) * kar));
            document.getElementById("ht" + ComboNo).value = formatPrice((TotalPrice * Item) + (((TotalPrice * Item) / 100) * kar));
        } else {
        document.getElementById("t" + ComboNo).value = formatPrice(Price * Item);
        document.getElementById("ht" + ComboNo).value = formatPrice(TotalPrice * Item);
        }


        var t = document.getElementsByName('t');
        var ht = document.getElementsByName('ht');
        var ListTotalTL = 0;
        var ListTotalUSD = 0;

        for (i = 0; i < t.length; i++) {
            if (isNaN(t[i].value) == false && t[i].type == "text" && t[i].value != "") {
                ListTotalUSD = ListTotalUSD + parseFloat(t[i].value);
            }
        }

        for (i = 0; i < ht.length; i++) {
            if (isNaN(ht[i].value) == false && ht[i].type == "hidden" && ht[i].value != "") {
                ListTotalTL = ListTotalTL + parseFloat(ht[i].value);
            }
        }


        //        if (isNaN(kar) == false & kar != "0") {
        //            ListTotalUSD = parseFloat(ListTotalUSD + ((ListTotalUSD / 100) * kar));
        //            ListTotalTL = parseFloat(ListTotalTL + ((ListTotalTL / 100) * kar));
        //        }

        document.getElementById("TotalUSD").innerText = formatPrice(ListTotalUSD);
        document.getElementById("TotalTL").innerText = formatPrice(ListTotalTL);
    }
    catch (e) {

    }
}

//function ReturnPrice(obj) {
//    return parseInt(obj) + "." + String(obj).substring(String(obj).indexOf(".") + 1, String(obj).indexOf(".") + 3);
//}

function formatPrice(price) {
    var price = price;
    var price = new Number(price);
    var price = (price.toFixed(2));
    return price;
}     
 
function ShowProduct(id) {
    var DrpObj = document.getElementById("ctl00_cph_ddlP" + id)
    if (DrpObj.value != 0) {
        openPopup("ProductInfo.aspx?ProductID=" + DrpObj.value, 750, 500);
    } else {
        alert('Lütfen bir ürün seçiniz.');
    }
}

function PrintList(print_area) {
    var table = document.getElementById(print_area);
    var rows = table.getElementsByTagName('tr');
    var html = '';

    html = html + '<table border="1">';

    for (r = 0; r < rows.length; r++) {
        var columns = rows[r].getElementsByTagName('td');
        var row = '';
        var current = true;

        for (c = 0; c < columns.length; c++) {
            var column = '';

            var selects = columns[c].getElementsByTagName('select');
            if (selects.length > 0) {
                var index = document.getElementById(selects[0].id).selectedIndex;
                var selected_text = selects[0].options[index].text;

                if (selected_text == "") {
                    column = '&nbsp;';
                    if (selects[0].id.indexOf('ddlI')) {
                        current = false;
                    }
                }
                else {
                    column = selected_text;
                    if (selects[0].id.indexOf('ddlI')) {
                        current = true;
                    }
                }
            }

            var inputs = columns[c].getElementsByTagName('input');
            if (inputs.length > 0) {
                if (inputs[0].name != 'p') {
                    column = inputs[0].value;
                }
            }

            if (column == "") {
                if (columns[c].innerText != 'B.Fiyat') {
                    column = columns[c].innerText;
                }
            }

            row += '<td>' + column + '</td>';
        }
        if (current == true) {
            html += '<tr>' + row + '</tr>';
        }
    }
    html = html + '<tr><td colspan="7"><div style="float: right; font-size: 14px; padding-top: 5px; padding-right: 10px;"><table><tr><td>Toplam</td><td align="right">' + document.getElementById("TotalUSD").value + '</td><td>USD</td></tr><tr><td>Toplam (KDV Dahil)</td><td align="right">' + document.getElementById("TotalTL").value + '</td><td>TL</td></tr></table></div></td></tr>';
            
    html = html + '</table>';

    var pp = window.open();
    pp.document.writeln('<HTML><HEAD><title>Baskı Önizleme</title></HEAD>')
    pp.document.writeln('<form  method="post">');
    pp.document.writeln('<TABLE width=100%><TR><TD></TD></TR><TR><TD align=right><INPUT ID="PRINT" type="button" value="Yazdır" onclick="javascript:location.reload(true);window.print();"><INPUT ID="CLOSE" type="button" value="Kapat" onclick="window.close();"></TD></TR><TR><TD></TD></TR></TABLE>');
    pp.document.writeln(html);
    pp.document.writeln('</form></body></HTML>');

}

function topluguncelle() {
    for (r = 0; r < 19; r++) {
        Calculate(r);

    }

}