﻿function CkKeyPress(e){
    var evt = (e) ? e : window.event;
    var key = (evt.keyCode) ? evt.keyCode : evt.which;
        if (key == 13){
            CancelDefault(evt);
            }
    }
    function CancelDefault(e){
    if( e.preventDefault ) { e.preventDefault(); }
           e.returnValue = false;
   }

// commonly used to check/uncheck all checkbox

// checkout_shipping_multi.aspx

// advancedsearch/component/checkboxselection.ascx
function ClearAllCheckBox(tblid, filtertype) {
    parentObj = document.getElementById(tblid);
    chks = getElementsByType('checkbox', 'input', parentObj);
    for (var i = 0; i < chks.length; i++) {
        chks[i].checked = false;
    }

    var alink = document.getElementById('aClearAll' + filtertype);
    alink.style.visibility = 'hidden';
}

function go2site(id) {
    var li = document.getElementById('value' + id);
    window.document.location = li.innerText;
}

function OpenMapHelper(url, arg) {
    //OpenWin(400, 500, "Map Helper", url);
    window.open(url + arg, 'test', 'width=800, height=800, toolbar=no,location=no,status=no,statusbar=0,menubar=0,locationbar=0,scrollbars=yes,resizable=yes');
}

/*------------------------------------------
Seller Rating
----------------------------------------------*/
var bind_mouseover_negative = function() {

}

function initializeSellerScore() {
    //var negativebg1 = '#
    //alert('initilalize seller score....');

    //alert($('#spanSellerScoreReadonly').text());
    if ($('#spanSellerScoreReadonly').text().toLowerCase() == 'false') {

        $('#tableSellerScore .negative').bind('mouseover', function() {
            
            $('#tableSellerScore .positive').css('background-color', '#ffffff');
            $('#tableSellerScore .positive').css('opacity', 1.0);
            var ids = $(this).attr('id').split('_');
            var idx = -1 * parseInt(ids[1]);
            SetSellerScore(idx);

        });

        $('#tableSellerScore .positive').bind('mouseover', function() {
            //alert('hi');
            $('#tableSellerScore .negative').css('background-color', '#ffffff');
            $('#tableSellerScore .negative').css('opacity', 1.0);
            var ids = $(this).attr('id').split('_');
            var idx = parseInt(ids[1]);
            SetSellerScore(idx);

        });

        $('#tableSellerScore .negative').bind('click', function() {
            var ids = $(this).attr('id').split('_');
            var v = -1 * parseInt(ids[1]);

            $('.selectSellerScore:first').val(v + '');

        });

        $('#tableSellerScore .positive').bind('click', function() {
            var ids = $(this).attr('id').split('_');
            var v = parseInt(ids[1]);

            $('.selectSellerScore:first').val(v + '');

        });

        $('.selectSellerScore').bind('click', function() {
            //alert('hi');
            SetSellerScore($('.selectSellerScore:first').val());
        });
    }
    // set score

    //SetSellerScore($('.selectSellerScore:first').val());
}


function SetSellerScore(v) {
    //alert(v);
    var score = parseInt(v);
    var idx = score;
    var bgcolor = '#009900';
    if (score == 0) {
        // zero
        $('#tableSellerScore #p_' + i).css('background-color', '#ffffff');
        $('#tableSellerScore #n_' + i).css('background-color', '#ffffff');
    }
    else {
        // positive
        var np = 'p_';
        if (score > 0) {


            $('#tableSellerScore .negative').css('background-color', '#ffffff');

        }
        else if (score < 0) {
            // negative
            idx = -1 * idx;
            bgcolor = '#ff0000';

            $('#tableSellerScore .positive').css('background-color', '#ffffff');
            np = 'n_';
        }


        for (var i = 1; i <= idx; i++) {
            $('#tableSellerScore #' + np + i).css('background-color', bgcolor);
            $('#tableSellerScore #' + np + i).css('opacity', i * 0.1);
        }
        for (var i = idx + 1; i <= 10; i++) {
            $('#tableSellerScore #' + np + i).css('background-color', '#ffffff');
            //$('#tableSellerScore #' + np + i).css('opacity', 1.0);
        }
    }

    $('.selectSellerScore:first').val(score);
}

function OnGetCartItemSuccess(result) {//alert(result);
    jsonResult = eval(result);

    generateCartItem(jsonResult[0].items);

    showCartItem();
}

function generateCartItem(items) {
    //alert(items.length);
}

/* user control customized drop down list -like  select control */
function showDDL(divid) {
    //alert('hi');
    $('.divDDLValues').hide();
    var divDDL = document.getElementById(divid);
    $('#' + divid).show();
    var tbl = $('#' + divid).closest('.tableDDL');

    var pos = $(tbl).find('.tableSelected').position();

    $('#' + divid).css('top', pos.top + $(tbl).height());
    $('#' + divid).css('left', pos.left);
    $('#' + divid).css('width', $(tbl).width());
}

var dividg;
function hideDDL(divid) {//alert('you out');
    dividg = divid;
    setTimeout(_hideDDL, 100);
}

function _hideDDL() {

    if (!checkMouseIn(dividg)) $('#' + dividg).hide();

}

function updateIndex(id, i, v) {
    var tblddl = $('#' + id).closest('.tableDDL');
    var obj = $(tblddl).find('.hfIndex:first'); //document.getElementById('<%=hfIndex.ClientID %>');
    $(obj).text(i);
    $('#' + id).hide();
    var span = $(tblddl).find('.selValue:first');  //document.getElementById('<%=selValue.ClientID %>');
    span.text(v);
    //changeView(i);
}


function setFlag() {
    flag = '1';
}

function ShowSaveSearch() {//alert('show save search...');


    $('#divSaveSearch').show();
    Move2CenterMiddle('divSaveSearch');
    if ($('.searchAlertCheckbox input').is(':checked')) {
        ShowEmailAlert();
    }
    else {
        HideEmailAlert();
    }

    //$('#spanShowSaveSearch').val('1');
    /*
    var hf = $get('<%=hfShowSaveSearch.ClientID %>');
    hf.value = '1';
    */
}

function HideSaveSearch() {
    //alert($('#divSaveSearch').length);
    $('#divSaveSearch').hide();
    /*
    //EnableSiteFrame();
    HideEmailAlert();
    $('#divSaveSearch').hide();
    $('#spanShowSaveSearch').val('0');
    */
    /*
    var hf = $get('<%=hfShowSaveSearch.ClientID %>');
    hf.value = '0';
    */
}

function AdjustSaveSearch() {
    //var div = document.getElementById('divSaveSearch');
    Move2CenterMiddle('divSaveSearch');
}
function chkEmailAlert_checked(id) {
    var chk = document.getElementById(id);
    var hf = $get('<%=hfShowEmailAlert.ClientID %>');

    if (chk.checked) {
        ShowEmailAlert();
        hf.value = '1';
    }
    else {
        HideEmailAlert();
        hf.value = '0';
    }
}

function ShowEmailAlert() {
    $('#divEmailAlert').show();

}
function HideEmailAlert() {
    $('#divEmailAlert').hide();

}

