function sure()
{
    return confirm('Are you sure ?');
}

function openWin(url, name, width, height)
{
  width  = width  || screen.width*0.9;
  height = height || screen.height*0.75;

  var win = window.open(url, name, 'left=' + Math.ceil((screen.width - width)/2) + ',top=' + Math.ceil((0+screen.height - height)/2) + ',width=' + width + ',height=' + height + ',location=0,toolbar=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,channelmode=0,fullscreen=0');
  win.focus();

  return false;
}


function getSelectedId(name)
{
    var cb = document.getElementsByName(name);
    for (var i=0; i < cb.length; i++)
        if(cb[i].checked)
            return cb[i].value;
            
    return false;
}

function insertToTextArea(textArea, txt)
{
    //for IE
    if (document.selection) {
            textArea.focus();
            sel = document.selection.createRange();
            sel.text = txt;
    }
    //for MOZILLA/NETSCAPE
    else if (textArea.selectionStart || textArea.selectionStart == "0") {
            var startPos  = textArea.selectionStart;
            var endPos    = textArea.selectionEnd;
            var str       = textArea.value;

            textArea.value = str.substring(0, startPos) + txt + str.substring(endPos, str.length);
    } else {
            textArea.value += txt;
    }

    return true;
}

function selectCategory(prefix, show_all)
{
    return openWin("/index.php?mod=catalog&act=show_cat&show_all="+show_all+"&prefix="+prefix, "selectCat", 500);
}

function htmlFormOther(selMain, inpOther)
{
    if (!document.getElementById(inpOther))
        return;
    var s = (selMain.value == -1 ? 'block': 'none');
    document.getElementById(inpOther).style.display = s;
    if ('none' == s)
        document.getElementById(inpOther).value = "";
}

function htmlCopyValues(_contactCountrySelect, _contactCityInput, _contactAddrInput, _contactZipInput)
{
    var countrySelect = document.getElementById ? document.getElementById("countrySelect") : document.all.countrySelect;
    var contactCountrySelect = document.getElementById ? document.getElementById("contactCountrySelect") : document.all.contactCountrySelect;

    var cityInput = document.getElementById ? document.getElementById("cityInput") : document.all.cityInput;
    var contactCityInput = document.getElementById ? document.getElementById("contactCityInput") : document.all.contactCityInput;

    var addrInput = document.getElementById ? document.getElementById("addrInput") : document.all.addrInput;
    var contactAddrInput = document.getElementById ? document.getElementById("contactAddrInput") : document.all.contactAddrInput;

    var zipInput = document.getElementById ? document.getElementById("zipInput") : document.all.zipInput;
    var contactZipInput = document.getElementById ? document.getElementById("contactZipInput") : document.all.contactZipInput;

    var contactCopyCheckbox = document.getElementById ? document.getElementById("contactCopyCheckbox") : document.all.contactCopyCheckbox;

    if (!contactCopyCheckbox.checked) {
        contactCountrySelect.value = _contactCountrySelect;
        contactCityInput.value = _contactCityInput;
        contactAddrInput.value = _contactAddrInput;
        contactZipInput.value = _contactZipInput;
    } else {
        contactCountrySelect.value = countrySelect.value;
        contactCityInput.value = cityInput.value;
        contactAddrInput.value = addrInput.value;
        contactZipInput.value = zipInput.value;
    }
}

function submitForm(frmName, type, requiredChecked)
{
    if (requiredChecked == null)
        requiredChecked = false;
    
    if (requiredChecked && 
        getSelectedId("p_id[]") == false &&
        getSelectedId("l_id[]") == false &&
        getSelectedId("c_id[]") == false )
    {
         
        alert("Check items first");
        return;
    }
    var url = '';
    switch (type)
    {
        case 1 : // compare
            url="/compare.html";
            break;
        case 2 ://send bulk sms
            url="/index.php?alias=sendsms&t=sms";
            break;
        case 3 ://send messages
            url="/index.php?alias=sendsms&t=message";
            break;
        case 4 ://add to basket
            url="/index.php?mod=account&act=add_to_basket";
            break;
        case 5 ://delete from basket
            url="/index.php?mod=account&act=delete_from_basket";
            break;
    }
    document.getElementById(frmName).action = ('http://' + document.location.href.match(/([a-z]+\.[a-z]+)\/[a-z]/i)[1] + url);  
    document.getElementById(frmName).submit();
}

/*
* using in /mod/object/tpl/visitor_list_header.php
*/
function listHeaderMenuMOver(obj)
{
    obj.className = "listheader-active";
}

/*
* using in /mod/object/tpl/visitor_list_header.php
*/
function listHeaderMenuMOut(obj)
{
    obj.className = "listheader-inactive";
}

function selectAll(name, checked, formName)
{
    var cb = document.getElementsByName(name);
    for (var i=0; i < cb.length; i++)
    {
        if (formName == null || cb[i].form.name == formName)
            cb[i].checked = checked;
    }
}

function listSelectClick(value)
{
    selectAll('c_id[]',value);
    selectAll('l_id[]',value);
    selectAll('p_id[]',value);
    selectAll('lh_select[]',value);    
}

function _phone(baseName)
{
    var v1 = document.getElementsByName(baseName + '_1')[0].value;
    var v2 = document.getElementsByName(baseName + '_2')[0].value;
    var v3 = document.getElementsByName(baseName + '_3')[0].value;
    if (v1 && v2 && v3)
        document.getElementsByName(baseName)[0].value = v1 + '-' + v2 + '-' + v3;
}

function setImg(url, w, h)
{
    var i = document.getElementById('big_img');
    if (i){
        i.src = url;
        //i.width = w;
        //i.height = h;
    }
    return false;
}