function editItem(nItemId){
        var oEditWindow = window.open('/modules/catalog/admin/index.php?fct=items&op=editItem&Id='+nItemId, 'CatalogItemEdit', "resizable=yes, scrollbars=yes, width=800px, height=600px");
                oEditWindow.focus();
}


function appendItemToOrder(nItemId){
        window.open("/modules/catalog/shopingcart.php?Action=AppendItemToOrder&ItemId="+nItemId, null,'width=400,height=200,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 testTel(str, allowNull) {
        var MaskReg = /^[0-9\-\s\+]+$/i
        var r = MaskReg.exec(str);
        if (allowNull && str.length==0)
                return true;
    if( r == null || !str.length == r[0].length ) {
        return false;
    }
        return true;
}

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; }
        if ( !testTel(document.getElementById('customerOrderInfo[Phone]').value,false) ) { window.alert("Телефон должен содержать только цифры"); document.getElementById('customerOrderInfo[Phone]').focus(); return false; }
        document.getElementById("oOrderAction").value = "submitOrder";
        document.getElementById('oOrderForm').submit();
}
function calculateAmount(nItemId, oObj) {
        var oTarget = document.getElementById("oTDAmount["+nItemId+"]");
        var nRetail = document.getElementById("oTDRetail["+nItemId+"]").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("num");
        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-3].innerHTML*1;
                }
        else {
                aCells = aRows.cells;
                nTotal+= aCells[aCells.length-3].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 imgprev(imgPath, title, alt) {
    width = 50;
    height = 50;
    var win = window.open('','preview','width='+width+',height='+height+',left=0,top=0,screenX=0,screenY=0,resizable=1,scrollbar=0,status=0');
 
    var winDoc = win.document;
    if (title == undefined) title = 'Image, Click to Close';
    if (alt   == undefined) alt   = 'Image, Click to Close';
    var content = '<html><head><title>' + title + '</title>' +
    			  '<style>body{overflow: hidden;margin:0;}img{border:0;}</style>' +
    			  '</head><body><a href="javascript:self.close()">' +
    			  '<img alt="' + alt + '" id="image" src="' + imgPath + '" /></a></body></html>'
    win.document.write(content);
 
    winDoc.body.onload = function() {
    	var obj = winDoc.getElementById('image');
    	var w = obj.width, h = obj.height;
    	var iHeight= document.body.clientHeight, iWidth = self.innerWidth;
 
    	var left = (self.opera ? iWidth : screen.availWidth)/2 - w/2;
    	var top =  (self.opera ? iHeight : screen.availHeight)/2 - h/2;
    	win.resizeTo(w+10, h+40);
    	win.moveTo(left, top);
    }
 
    win.onload = winDoc.body.onload; // special for Mozilla
 
    // !!! Important statement: popup onload won't execute without it!
    win.document.close();
    win.focus();
}
