var onImages = new Array();
var offImages = new Array();

function onImg(id)
{
    if (el = document.getElementById('nav'+id))
    {
        offImages[id] = el.src;
        el.src = onImages[id].src; 
    }
}

function offImg(id)
{
    if (el = document.getElementById('nav'+id)) el.src = offImages[id];
}

function numeralsOnly(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    
    if (charCode > 31 && (charCode < 48 || charCode > 57)
        && charCode!=37 &&  charCode!=39 && charCode!=36 && charCode!=35 && charCode!=46) //стрелки, home, end, del для ff
    {
        return false;
    }
    return true;
}

function numeralsOnlyFloat(evt) {
    
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    
    
    if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode!=45 && charCode!=44 && charCode!=46  && charCode!=43
        && charCode!=37 &&  charCode!=39 && charCode!=36 && charCode!=35 && charCode!=46) //стрелки, home, end, del для ff
    {
        return false;
    }
    return true;
}

/**
* открывает popup окно с галереей изображений
* параметры goodid и type нужны только для определения уникального имения окна
*/
function openPicture(id, width, height, goodid, type)
{
    //Определим уникальное имя окна в переменной WindowName
    var WindowName;
    if (type == 3) WindowName = 'color' + goodid;
    else WindowName = 'good' + goodid;
    
    //Перестраховка, на случай, если у картинки нет размеров в базе данных
    if (width == 0) width = 500;
    if (height == 0) height = 400;
    
    window.open('/index.php?a=goodpics&id='+id
                , WindowName
                , 'width=' + width + ',height=' + height + ', resizable=1, scrollbars=1, alwaysRaised=1, z-lock=1, left='+(screen.width-width)/2+', top='+(screen.height-height)/2
                );
}

function openCalendar(field, type)
{
    window.open("/calendar.php", "calendar", "width=400,height=240,status:yes,left="+(screen.width-400)/2+",top="+(screen.height-240)/2);
    dateField = document.getElementById(field);
    dateType = type;
}

function myRound(num)
{
    if (isNaN(num))
    {
        num = parseFloat(num);
        if (isNaN(num)) return num;
    }
    
    num = Math.round(100*num)/100;
    return num;
}

function trim(s)
{
    return s.replace(/^\s+|\s+$/g, '') ;
}

function focusElement(id)
{
    if (el = document.getElementById(id)) el.focus();
}

var activeIcoEl;
function icoInfo(picel, text)
{
    if (activeIcoEl != picel)
    {
        YAHOO.util.Dom.removeClass(activeIcoEl, 'GoodIconActive');
        YAHOO.util.Dom.addClass(picel, 'GoodIconActive');
        
        activeIcoEl = picel;
        
        if (el = document.getElementById('GoodIconInfo')) el.innerHTML = text;
    }
}

function buyGood(id,quantityImg,colorcomment,goodsimgID)
{

    var count = 1;
  
    //var quantityImg=0;
    if (el = document.getElementById('buy_count'+id)) count = el.value;
    //if (el2 = document.getElementById('ColorComment'))colorcomment=el2.innerHTML;
  
   
    if (count=='' || count==0)
    {
        alert('Не задано количество товара');
        el.focus();
    }
    else if(colorcomment==null ){
        alert('Для покупки выберите пожалуйста цвет товара');
    }
    else if(quantityImg==null || quantityImg==0 ){
        alert("Цвет :"+colorcomment+" нет в наличии, за дополнительной информацией обратитесь к нашим сотрудникам по телефону: (495) 542-40-63");
    }
    else
    {


        document.location.href="/index.php?a=order&buy_goodid="+id+"&buy_count="+count+"&comment="+goodsimgID;
    }
}

function massOrder()
{
    if (el = document.getElementById("CatalogOrderForm")) el.submit();
}
