//Этот файл не должен меняться под конкретные проекты
/*
 * Возвращает кол-во дней в месяце
 */
function date_count_days(year, month) {
    return  32 - new Date(year, month-1, 32).getDate();
}

/*формирует options для select*/
function date_gen_select_form(select_day_id, count_days, current_day) {
    if (document.getElementById(select_day_id)) {
        document.getElementById(select_day_id).innerHTML = null;
        for (i = 1; i<= count_days; i++) {
            var option = document.createElement("option");
            option.setAttribute("value", i);
            if (i == current_day) option.selected = true;
            option.innerHTML = i;
            document.getElementById(select_day_id).appendChild(option);
        }
    }
    else alert("id не select_day не найден " + select_day_id);
}

/**
 * Выделяет текст в текстовое поле
 */
function select_text_field(id){
    //    ie='\v'=='v'
    //    if(ie){
    var oTextBox = document.getElementById(id);
    oTextBox.focus();
    oTextBox.select();

//    } else {
//        var selection = window.getSelection();
//        var range = document.createRange();
//        var tab = document.getElementById(id);
//
//        range.selectNodeContents(tab);
//        selection.addRange(range);
//    }
}
var selected_obj = null;
function SelectLink(obj) {
    if (selected_obj != obj) { //Если сами на себя не кликаем
        obj.style.fontWeight = 'bold';
        if (selected_obj) {
            selected_obj.style.fontWeight = 'normal';
        }
        selected_obj = obj;
    }
}

function message() {
    this.hide = function () {
        $('window_message_bg').style.display = 'none';
        $('message').style.display = 'none';
    //$('window_frame_message').style.display = 'none';
    }
    this.show = function () {
        $('window_message_bg').style.display = 'block';
        $('message').style.display = 'block';
        //$('window_frame_message').style.display = 'block';
        $('message').style.top = parseInt((window.innerHeight/2)-30)+"px";
        $('message').style.left = parseInt((document.body.clientWidth/2-210))+"px";
    }
}
messages = new message;

function ShowHide(id) {
    document.getElementById(id).style.display = (document.getElementById(id).style.display == 'block') ? 'none' : 'block';
}
var selected_image_id; //Если есть выбор между картинками, то выбранная картинка помещается сюда
function basket(obj, action_id, product_id, not_detailed, image_id, add_count) {
    if (image_id) selected_image_id = image_id;
    obj.disabled = true;
    
    switch (action_id) {
        case 1:
            AjaxQuery('basket', url + 'basket/add/'+ product_id + '/'+selected_image_id + '/' + add_count + '/1/');
            
            break;
        case 2:
            AjaxQuery('basket', url + 'basket/del/'+ product_id + '/');
            
            break;
        case 3: //Изменение кол-ва
            AjaxQuery('basket', url + 'basket/add/'+ product_id + '/'+selected_image_id + '/' + add_count + '/');
            
            break;
    }
    setTimeout(function() {
        AjaxQuery('basket_detailed', url + 'basket/'+not_detailed + '/');
    }, 290);
    obj.disabled = false;
}

function detectIE6(){
    var browser = navigator.appName;
    if (browser == "Microsoft Internet Explorer"){
        var b_version = navigator.appVersion;
        var re = /\MSIE\s+(\d\.\d\b)/;
        var res = b_version.match(re);
        if (res[1] <= 6){
            return true;
        }
    }
    return false;
}
if (detectIE6()) {
    alert('Вы используете устаревший браузер. \n\nДля просмотра сайта в правильном представлении, пожалуйста обновите ваш браузер');
}
function addBookmark (a) {
    try {
        // Internet Explorer
        window.external.AddFavorite('http://girlshop.ru', 'Интернет-магазин профессиональной косметики');
    } catch (e) {
        try {
            // Mozilla
            window.sidebar.addPanel('Интернет-магазин профессиональной косметики', 'http://girlshop.ru', "");
        }
        catch (e) {
            // Opera
            if (typeof(opera)=="object") {
                a.rel="sidebar";
                a.title='Интернет-магазин профессиональной косметики';
                a.url='http://my-pack.ru/';
                return true;
            } else {
                // Unknown
                alert('Нажмите Ctrl-D чтобы добавить страницу в закладки');
            }
        }
    }
}
function open_window(link,w,h, is_center) {
    if (is_center == true) {
        var left = ( screen.width - w ) / 2-5;
        var top = ( screen.height - h ) / 2 - 50;
        var position = ", top=" +top+ ", left=" +left;
    }
    else position = null;

    var win = "width="+w+",height="+h+",menubar=no,location=no,resizable=yes,scrollbars=yes"+position;
    newWin = window.open(link,'newWin',win);
    newWin.focus();
    return false;
}


function setDefaultInputText(id, text) {
    var obj = document.getElementById(id);
    if (obj) {
        if (obj.nodeName == 'TEXTAREA') {
            obj.innerHTML = text;
            obj.onclick = function () {
                if (obj.innerHTML == text) {
                    obj.innerHTML = '';
                }
            }
            obj.onblur = function () {
                if (obj.innerHTML == '') {
                    obj.innerHTML = text;
                }
            }
        }
        else {
            if (obj.value == '') {
                obj.value = text;
            }
            obj.onclick = function () {
                if (obj.value == text) {
                    obj.value = '';
                }
            }
            obj.onblur = function () {
                if (obj.value == '') {
                    obj.value = text;
                }
            }
        }
    }
}
function showMenu(id) {
    document.getElementById(id).style.display = 'block';
}
function hideMenu(id) {
    document.getElementById(id).style.display = 'none';
}


function order_info (obj) {
    //    alert(obj.id);
    obj.id = 'order_link';
    //    alert(obj.id);
    //    $("a[id^='order_link']").prettyPopin({
    $("a#order_link").prettyPopin({
        width: 432,
        height: 158,
        followScroll:false
    });
}
