function appendItemToOrder(nItemId,nPeriod){
        document.location="/modules/catalog/shopingcart.php?Action=AppendItemToOrderConfirm&Period="+nPeriod+"&ItemId="+nItemId;
}
function showCalendar(nItemId){
        window.open("/modules/catalog/calendar.php?Id="+nItemId, 'Calendar','width=300,height=300,alwaysRaised="yes",z-lock="no"');
}
function onAppendingDone(s, oCaller){
        var nWidth = 300;
        var nHeight = 150;
        var sContent = s+"<BR><BR>Успешно Добавлено в Корзину!";
        var sTitle = "Ваш Заказ";
                appendServerDialogContent(nWidth, nHeight, sTitle, sContent);
}

function submitOrderForm() {
        var myform = document.getElementById('oOrderForm');
        if ( document.getElementById('customerOrderInfo[Name]').value == "" ) { window.alert("Пожалуйста, введите ФИО"); document.getElementById('customerOrderInfo[Name]').focus(); return false; }
        if ( document.getElementById('customerOrderInfo[Phone]').value == "" ) { window.alert("Пожалуйста, введите телефон"); document.getElementById('customerOrderInfo[Phone]').focus(); return false; }
        document.getElementById("oOrderAction").value = "submitOrder";
        document.getElementById('oOrderForm').submit();
}
function calculateAmount( oObj) {
        var oTarget = document.getElementById("oTDAmount");
        var nRetail = document.getElementById("oTDRetail").innerHTML;
                oTarget.innerHTML = nRetail*oObj.value;

               // calculateTotalAmount();
}

function deleteItemFromOrder(nItemId){
        document.getElementById("oOrderAction").value = "deleteItem";
        document.getElementById("oOrderItemId").value = nItemId;
        document.getElementById("oOrderForm").submit();
}

function calculateTotalAmount() {
        var oTarget = document.getElementById("oOrderTotal");
        var nTotal = 0;
        var aCells;
        var aRows = document.getElementById("oOrderContent").rows("oDataRow");
        if(aRows.length)
                for(var i=0; i<aRows.length; i++) {
                        aCells = aRows.item(i).cells;
                        nTotal+= aCells[aCells.length-2].innerHTML*1;
                }
        else {
                aCells = aRows.cells;
                nTotal+= aCells[aCells.length-2].innerHTML*1
        }
        oTarget.innerHTML = Math.round(nTotal * 100)/100;
}

function submitOrder(sMsg){
        var aRows = xoopsGetElementById('oOrderInfo').rows;
        var oElement = null;
        for(var i=1; i < aRows.length-1; i++){
                oElement = aRows.item(i).cells.item(0).firstChild.rows.item(0).cells.item(1).firstChild;
                if(oElement.getAttribute("NonEmpty") && oElement.value == ""){
                        alert(sMsg);
                        return;
                }
        }
        xoopsGetElementById("oOrderAction").value = "submitOrder";
        xoopsGetElementById("oOrderForm").submit();
}

function onShopWindowTableMouseOver(oObj, sText) {
        oObj.title = (event.srcElement.tagName != 'DIV' ? sText : '');
}

function onShopWindowTableClick(sUrl) {
        if(event.srcElement.tagName != 'DIV')
                document.location.href = sUrl;
}
function onShopWindowDIVMouseEvent(oObj, sClassName) {
        var oDescription, oRetail;
        switch(oObj.id) {
                case "Description":
                        oObj.className = sClassName;
                        oObj.parentNode.parentNode.parentNode.lastChild.firstChild.firstChild.rows.item(0).cells.item(1).firstChild.className = sClassName;
                break;
                case "Retail":
                        oObj.className = sClassName;
                        oObj.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes(1).firstChild.firstChild.className = sClassName;
                break;
                case "Detailes":
                        oObj.parentNode.parentNode.childNodes(1).firstChild.className = sClassName;
                        oObj.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes(1).firstChild.firstChild.className = sClassName;
                break;
        }
}
function onShopWindowDIVMouseClick(sUrl) {
        document.location.href = sUrl;
}
function showImage(sUrl, width, height, sName) {


        leftpos=(screen.width-width)/2;
        toppos=(screen.height-height)/2;
        var oWin = window.open("Images" , "Images" ,'width=' + width + ', height=' + height+', scrollbars=no, left='+leftpos+', top='+toppos);
        var doc = oWin.document;
                doc.write("<HTML><HEAD><TITLE>"+sName+"</TITLE></HEAD><IMG SRC='" + sUrl + "' ALT='" + sName + "'></HTML>");
                oWin.focus();
}
function submitBeznalForm() {
        if ( document.getElementById('subscriberInfo[CompanyName]').value == "" ) { window.alert("Пожалуйста, введите Полное название компании"); document.getElementById('subscriberInfoInfo[CompanyName]').focus(); return false; }
        if ( document.getElementById('subscriberInfo[INN]').value == "" ) { window.alert("Пожалуйста, введите ИНН"); document.getElementById('subscriberInfoInfo[INN]').focus(); return false; }
        if ( document.getElementById('subscriberInfo[Bank]').value == "" ) { window.alert("Пожалуйста, введите название банка"); document.getElementById('subscriberInfoInfo[Bank]').focus(); return false; }
        if ( document.getElementById('subscriberInfo[RSch]').value == "" ) { window.alert("Пожалуйста, введите Расчетный счет"); document.getElementById('subscriberInfoInfo[RSch]').focus(); return false; }
        if ( document.getElementById('subscriberInfo[KSch]').value == "" ) { window.alert("Пожалуйста, введите Кор/счет"); document.getElementById('subscriberInfoInfo[KSch]').focus(); return false; }
        if ( document.getElementById('subscriberInfo[BIK]').value == "" ) { window.alert("Пожалуйста, введите БИК"); document.getElementById('subscriberInfoInfo[BIK]').focus(); return false; }
        document.getElementById('oBeznalForm').submit();
}
