var url = "";
var producturl = "";
var prd_attach_url = "";
var productList;
var attachmentList;
var productDetails;
var salesLocations;
var masterCatID = 0;
var archiveFilter = "";
var currentLevel = 0;
var currentName = "";
var prdNavbarHtml = "";
var cat_entry = "";
var cat_extend = "";
var cat_name = "";
var currentLang = "";
var currentPrdId = 0;
var navHtml = "";
var navigation_bar = "";
var prd_bar_object = new Array();
var previousFunction = "";

var current_cate_url = "";
var CurrentProductList;
var current_display = "no";
var load_lang = "en";

var current_level = "9";

var ready_function = new Array();
var ready_function_current = null;

function update_product_list(catid, lang, cat, catcode, name, desc, parent_name, display) {

    // add by evans 20100301 for data response start 
    var temp_function = function () { extend_product_list(cat, catcode, name, lang, curLevel); };
    if (ready_function_current != null) {
        //ready_function.push(temp_function);
    } else {
        ready_function_current = temp_function;


        // add by evans 20100225 for product session start
        var save_product_list_ajax_session_data = "update_product_list(" + catid + ",'" + lang + "','" + cat + "','" + catcode + "','" + name + "','" + desc + "','" + parent_name + "','" + display + "');";
        save_product_list_ajax("product_list_data", save_product_list_ajax_session_data, "new", 0);
        // add by evans 20100225 for product session end


        load_lang = lang;
        current_display = display;

        previousFunction = "update_product_list(" + catid + ",'" + lang + "','" + cat + "','" + catcode + "','" + name + "','" + desc + "','" + parent_name + "','" + display + "');";
        url = "/services/category.html?catid=" + catid + "&lang=" + lang;
        current_cate_url = "/services/current_category.html?catid=" + catid + "&lang=" + lang;
        producturl = "/services/productlist_bycode.html?catcode=" + catcode + "&lang=" + lang;
        prd_attach_url = "/services/product_attachment.html?cat=" + catcode + "&type=catalogue";
        //writeDebug(catid+","+cat+","+catcode);

        //parent_name=parent_name.replace('arrow',' <img src="/templates/alpha/images/arrow2.gif"/> ');


        //alert(catid+","+cat+","+catcode+","+name+","+parent_name);


        //alert(catcode.indexOf(cat));
        cat_entry = catcode;
        cat_name = name;
        prd_bar_object = new Array();
        $('prd_navbar').hide();
        $('prd_filter').update('');
        $('prd_details').hide();
        $('prd_locations').hide();
        $('prd_default').hide();


        new Ajax.Request(current_cate_url, {
            onSuccess: updateCurrentSelection,
            onFailure: function (transpot) {
            },
            method: 'get'
        });


    }
    // add by evans 20100301 for data response end
}




function updateCurrentSelection(transport, json) {
    try {
        var temptranspot = transport.responseText.gsub(/\s/, ' ');
        CurrentProductList = ('/*-secure-\n' + temptranspot + '\n*/').evalJSON();
        updateCurrentProductSelection();

    } catch (e) {
        //alert(e);
        return;
    }
}

function updateCurrentProductSelection() {
    if (CurrentProductList.length > 0) {

        CurrentProductList.each(
            function (productlist) {
                $('navbar').update(productlist.name);
                var temp_full_name = "";
                var temp_full_name_arr = productlist.category_full_name.split(".");
                for (var i = 1; i < temp_full_name_arr.length; i++) {
                    temp_full_name = temp_full_name + ' <img src="/templates/alpha/images/arrow2.gif"/> ' + temp_full_name_arr[i];
                }
                $('product_breakdown_bar').update(temp_full_name);

                $('product_hierachy_bar').update('');
                $('descbar').update('');



                if (productlist.code == 'prd.ac.vrf.js' || productlist.code == 'prd.ac.vrf.viis') {

                    var el = document.createElement("iframe");
                    el.setAttribute('id', 'ifrm');
                    document.body.appendChild(el);
                    el.setAttribute('src', '/' + load_lang + '/about/feature_list.html?cat=' + cat_entry);
                    el.setAttribute('width', '700');
                    el.setAttribute('height', '580');
                    el.setAttribute('frameborder', '0');
                    el.setAttribute('marginwidth', '0');
                    el.setAttribute('marginheight', '0');
                    el.setAttribute('scrolling', 'yes');
                    el.setAttribute('style', 'overflow-x: hidden;');
                    $('prd_list').update(el);
                    $('prd_list').show();

                    for (var i = 1; i < 6; i++) {
                        $('prd_filter_' + i).update('');
                        $('prd_filter_' + i).hide();
                    }

                } else {
                    currentLang = load_lang;
                    masterCatID = productlist.id;
                    var cat_image = productlist.code.substring(4, productlist.code.length);

                    var dot_pos = cat_image.indexOf('.');
                    if (dot_pos > 0) {
                        cat_image = cat_image.substring(0, dot_pos);
                    }

                    $('prd_navbar').update('');
                    prdNavbarHtml = "";

                    new Ajax.Request(url, {
                        onSuccess: updateSelection,
                        onFailure: function (transpot) {
                        },
                        method: 'get'
                    });

                    if (current_display == 'yes') {

                        new Ajax.Request(producturl, {
                            onSuccess: displaySelection,
                            onFailure: function (transpot) {
                            },
                            method: 'get'
                        });
                    }
                    else {
                        $('prd_list').hide();
                    }
                }

            }
        )

    }

}


function updateSelection(transport, json) {
    try {
        var temptranspot = transport.responseText.gsub(/\s/, ' ');
        productList = ('/*-secure-\n' + temptranspot + '\n*/').evalJSON();
        //        //writeDebug('finish evaluate!');
        updateProductSelection();


    } catch (e) {
        //alert(e);
        return;
    }
    //writeDebug($('prd_filter').innerHTML);
}

function updateProductSelection() {
    var prdfilterHtml = "";

    productList.each(
        function (productlist) {

            //writeDebug(productlist.name);
            //alert(productlist.current_level);

            if (productlist.image == '') {
                if (productlist.parent_code == 'prd.ac.mt') {

                    prdfilterHtml += templates.prdFilterSpecialItem.evaluate(productlist);
                    //alert(prdfilterHtml);
                }
                else {
                    prdfilterHtml += templates.prdFilterItem.evaluate(productlist);
                }
            }
            else {
                prdfilterHtml += templates.prdFilterImage.evaluate(productlist);
            }

        }
    )
    $('prd_navbar').update('');
    $('prd_filter').update('');
    $('prd_details').hide();
    $('prd_locations').hide();
    //$('prd_list').update('');

    for (var i = 1; i < 6; i++) {
        $('prd_filter_' + i).update('');
        $('prd_filter_' + i).hide();
    }
    currentLevel = 0;

    $('prd_filter').update(prdfilterHtml);
    $('prd_filter').show();


    // add by evans 20100301 for data response start              
    if (current_display == "no") {
        ready_function_call_back();
    }
    // add by evans 20100301 for data response end 

}

function updateProductByBrand(catcode, brand, lang, parent, name) {

    // add by evans 20100225 for product session start
    var save_product_list_ajax_session_data = "updateProductByBrand('" + catcode + "','" + brand + "','" + lang + "','" + parent + "','" + name + "');";
    save_product_list_ajax("product_list_data", save_product_list_ajax_session_data, "new", 0);
    // add by evans 20100225 for product session end

    //alert(parent+','+name);
    var prd_breakdown_contents = "";
    currentLang = lang;
    if (parent != '') prd_breakdown_contents += '<img src="/templates/alpha/images/arrow2.gif"/> ' + parent;
    if (name != '') prd_breakdown_contents += '<img src="/templates/alpha/images/arrow2.gif"/> ' + name;
    $('product_breakdown_bar').update(prd_breakdown_contents);
    producturl = "/services/productlist_bybrand.html?brand=" + brand + "&lang=" + lang;
    prd_attach_url = "/services/product_attachment.html?cat=" + catcode + "&type=catalogue";
    $('prd_filter').update('');
    $('prd_details').hide();
    $('prd_locations').hide();
    $('prd_default').hide();
    //alert (producturl);
    new Ajax.Request(producturl, {
        onSuccess: displaySelection,
        onFailure: function (transpot) {
        },
        method: 'get'
    });

}


function updateNavbar() {
    //writeDebug('NAV BAR:'+$('prd_navbar').innerHTML);
    var navigation_bar_contents = $('product_hierachy_bar').innerHTML;
    if ($('prd_navbar').innerHTML != "") {
        prdNavbarHtml += ' > ';
    }

    prdNavbarHtml += currentName;
    $('product_hierachy_bar').update(navigation_bar_contents + ' <img src="/templates/alpha/images/arrow2.gif"/> ' + currentName);
    $('prd_navbar').update(prdNavbarHtml);
    $('prd_navbar').show();


    var prd_type_name = new Array();
    prd_type_name.push($('prd_navbar').innerHTML);
    highlight_prd_active_link(prd_type_name);

}

function extend_product_list(cat, catcode, name, lang, curLevel) {

    // add by evans 20100301 for data response start 
    var temp_function = function () { extend_product_list(cat, catcode, name, lang, curLevel); };
    if (ready_function_current != null) {
        //ready_function.push(temp_function);
    } else {
        ready_function_current = temp_function;


        // add by evans 20100225 for product session start
        var save_product_list_ajax_session_data = "extend_product_list(" + cat + ",'" + catcode + "','" + name + "','" + lang + "'," + curLevel + ");";
        save_product_list_ajax("product_list_data", save_product_list_ajax_session_data, "add", curLevel);
        // add by evans 20100225 for product session end




        previousFunction = "extend_product_list(" + cat + ",'" + catcode + "','" + name + "','" + lang + "'," + curLevel + ");";
        //$('prd_list').update('');
        //writeDebug('Variable:'+currentLevel);
        //writeDebug('Input:'+curLevel);
        //alert(curLevel+','+currentLevel);
        //alert($('product_hierachy_bar').innerHTML);

        prd_bar_object[curLevel] = name;
        //alert(prd_bar_object[curLevel]+','+curLevel+','+currentLevel);
        var prd_navbar_contents = "";
        var product_hierachy_bar_contents = "";

        if (curLevel <= currentLevel) {

            if (prd_bar_object[curLevel - 1]) {
                for (i = 0; i < curLevel; i++) {

                    if (prd_bar_object[i]) {
                        /*
                        prd_navbar_contents+=' <img src="/templates/alpha/images/arrow2.gif"/> '+prd_bar_object[i];   
                        if (product_hierachy_bar_contents=='')product_hierachy_bar_contents=prd_bar_object[i];   
                        else product_hierachy_bar_contents+=' > '+prd_bar_object[i];   
                        prdNavbarHtml+=prd_bar_object[i];
                        */
                        if (prd_navbar_contents != '') prd_navbar_contents += ' > ' + prd_bar_object[i];
                        else prd_navbar_contents = prd_bar_object[i];
                        product_hierachy_bar_contents += ' <img src="/templates/alpha/images/arrow2.gif"/> ' + prd_bar_object[i];
                    }
                    //$('prd_navbar').update(prd_navbar_contents);
                    $('product_hierachy_bar').update(product_hierachy_bar_contents);
                    prdNavbarHtml = prd_navbar_contents;
                }
            } else {

                //$('prd_navbar').update(prd_bar_object[curLevel]);
                $('prd_navbar').update('');
                //$('product_hierachy_bar').update('<img src="/templates/alpha/images/arrow2.gif"/> '+prd_bar_object[curLevel]);
                $('product_hierachy_bar').update('');
                prdNavbarHtml = "";

            }


        }

        if (currentLevel == 0) {

            $('prd_navbar').update('');
            $('product_hierachy_bar').update('');
            prdNavbarHtml = "";

        }

        //currentLevel=10;
        currentName = name;
        brandName = name;
        //writeDebug('check point:'+cat+','+name);
        url = "/services/category.html?catid=" + cat + "&lang=" + lang;
        //writeDebug('Category URL:'+url);
        currentLevel = curLevel;
        new Ajax.Request(url, {
            //onSuccess:extendSelection,
            onSuccess: function (transpot) {
                try {
                    var temptranspot = transpot.responseText.gsub(/\s/, ' ');
                    categoryList = ('/*-secure-\n' + temptranspot + '\n*/').evalJSON();
                    url = "/services/productlist.html?id=" + cat + "&lang=" + lang;
                    producturl = "/services/productlist_bycode.html?catcode=" + catcode + "&lang=" + lang;
                    prd_attach_url = "/services/product_attachment.html?cat=" + catcode + "&type=catalogue";
                    //writeDebug('URL:'+producturl);
                    //writeDebug('finish evaluate!'+productList);
                    //alert(prd_attach_url);
                    //alert(producturl);
                    if (categoryList.length == 0) {
                        //writeDebug('empty list!'+cat);
                        updateNavbar();

                        new Ajax.Request(url, {
                            onSuccess: displaySelection,
                            onFailure: function (transpot) {
                                //writeDebug('fail');
                            },
                            method: 'get'
                        });
                    }
                    else {
                        //writeDebug('URL:'+producturl);
                        //alert(producturl);
                        extendProductSelection();
                        new Ajax.Request(producturl, {
                            onSuccess: displaySelection,
                            onFailure: function (transpot) {
                            },
                            method: 'get'
                        });

                    }

                } catch (e) {
                    //alert(e);
                    return;
                }

            },
            onFailure: function (transpot) {
                //writeDebug('fail');
            },
            method: 'get'
        });

        /*else
        {
        //writeDebug('Reach the product level! ID='+cat);
        url="/services/productlist.html?id="+cat+"&lang="+lang;
        new Ajax.Request( url, {
        onSuccess:displaySelection,
        onFailure:function(transpot){
        //writeDebug('fail');
        },
        method: 'get'
        });
        }*/



    }
    // add by evans 20100301 for data response end
}

function extendSelection(transport, json) {
    try {
        var temptranspot = transport.responseText.gsub(/\s/, ' ');
        productList = ('/*-secure-\n' + temptranspot + '\n*/').evalJSON();
        //writeDebug('finish evaluate!'+productList);
        if (productList.length == 0) //writeDebug('empty list!');

            extendProductSelection();


    } catch (e) {
        //alert(e);
        return;
    }
}

function extendProductSelection() {
    //var prdfilterHtml=archiveFilter+"<div class='clearboth'/>";
    //writeDebug('CURRENT LEVEL: '+currentLevel);
    var prdfilterHtml = "";

    categoryList.each(
        function (productlist) {
            if (productlist.is_hot == 'y') {
                productlist.is_hot = "<img src='/templates/alpha/" + currentLang + "/images/new_icon.gif'/>";
            }
            else {
                productlist.is_hot = "";
            }
            //writeDebug(productlist.image);
            if (productlist.image == '') {
                prdfilterHtml += templates.prdFilterItem.evaluate(productlist);
            }
            else {
                prdfilterHtml += templates.prdFilterImage.evaluate(productlist);
            }
        }
    );

    updateNavbar();
    //alert(currentLevel);
    for (var i = currentLevel; i < 6; i++) {

        $('prd_filter_' + i).hide();
    }

    $('prd_filter_' + currentLevel).update(prdfilterHtml);
    $('prd_filter_' + currentLevel).show();


}



function displaySelection(transport, json) {
    try {
        var temptranspot = transport.responseText.gsub(/\s/, ' ');
        productList = ('/*-secure-\n' + temptranspot + '\n*/').evalJSON();
        //writeDebug('product list display!');
        //writeDebug('Product attachment URL:'+prd_attach_url);
        //alert('check point');


        new Ajax.Request(prd_attach_url, {
            //onSuccess:extendSelection,
            onSuccess: function (transpot) {
                var temptranspot = transpot.responseText.gsub(/\s/, ' ');
                attachmentList = ('/*-secure-\n' + temptranspot + '\n*/').evalJSON();

                displayProductSelection();
            },
            onFailure: function (transpot) {
                //writeDebug('fail');
                //alert('fail');
            },
            method: 'get'
        });


    } catch (e) {
        //alert(e);
        return;
    }
}

function displayProductSelection() {
    //var prdfilterHtml=archiveFilter+"<div class='clearboth'/>";
    //writeDebug('Display Products!');
    var prdListHtml = "";
    prdListHtml += templates.prdListHeader.evaluate(productList);
    //writeDebug(attachmentList.length);

    if (productList.length > 0) {

        productList.each(

            function (productlist) {

                //writeDebug(productlist.name);
                productlist.attach = "none";
                attachmentList.each(
                function (attachlist) {
                    //writeDebug("Product ID: "+productlist.id+", Attachment Product ID: "+attachlist.prd_id);
                    if (productlist.id == attachlist.prd_id) {
                        productlist.attach = attachlist.url;
                    }

                }
                );
                //writeDebug("Attachment: "+productlist.attach);
                //Add new product icon @02112009 Start
                if (productlist.is_hot == 'y') {
                    productlist.is_hot = "<img src='/templates/alpha/" + currentLang + "/images/new_icon.gif'/>";
                }
                else {
                    productlist.is_hot = "";
                }

                if (productlist.type == productlist.cat_name) productlist.cat_name = "";

                if (productlist.attach != "none") {

                    prdListHtml += templates.prdListItemAttach.evaluate(productlist);
                }
                else {
                    prdListHtml += templates.prdListItem.evaluate(productlist);
                }

            }
        );

    } else {
        var temp_obj = { "no_product": label["alpha.prd.list.no_product"] }
        prdListHtml += templates.prdListNoItem.evaluate(temp_obj); ;
    }


    $('prd_list').update(prdListHtml);
    $('prd_details').hide();
    $('prd_locations').hide();
    $('prd_list').show();


    // add by evans 20100301 for data response start              
    ready_function_call_back();
    // add by evans 20100301 for data response end    

}



function productCallBack(transpot) {
    //writeDebug("shopping cart call> success");
    //alert(transpot.responseText);
    //var result=('/*-secure-\n'+transpot.responseText+'\n*/').evalJSON();
    displayProductSelection();
}



function alpha_35() {
}


function showProductDetails(prdid, lang) {
    //alert(prdid+","+lang);
    currentLang = lang;
    currentPrdId = prdid;

    if (arguments.length == 3) {
        alert(arguments[2]);
        $('navbar').update('');
        $('navbar').update(arguments[2]);
        $('navbar').show();
    }

    var details_url = "/services/details.html?id=" + prdid + "&lang=" + lang;
    //alert(details_url);
    //writeDebug(details_url);
    new Ajax.Request(details_url, {
        onSuccess: displayProductDetails,
        onFailure: function (transpot) {
        },
        method: 'get'
    });

}

function displayProductDetails(transport, json) {
    try {
        var temptranspot = transport.responseText.gsub(/\s/, ' ');
        productDetails = ('/*-secure-\n' + temptranspot + '\n*/').evalJSON();
        //        //writeDebug('finish evaluate!');
        //alert('checkpoint');
        displayProductDetailsPage();


    } catch (e) {
        //writeDebug('Display Error:'+e);
        return;
    }
    //writeDebug($('prd_filter').innerHTML);
}

function displayProductDetailsPage() {
    var prdDetailsHtml = "";
    var prdLocationHtml = "";
    var rowCount = 0;

    productDetails.each(
        function (productdetails) {

            /*
            var temp_full_name = "";              
            var temp_full_name_arr = productdetails.cat_full_name.split(".");                
            for(var i=1; i < temp_full_name_arr.length; i++) {
            temp_full_name = temp_full_name + ' <img src="/templates/alpha/images/arrow2.gif"/> ' + temp_full_name_arr[i];
            }                        
            $('product_breakdown_bar').update(temp_full_name);                    
            $('product_hierachy_bar').update('');
            $('descbar').update('');        
            $('navbar').update('');
            //$('navbar').update(productdetails.prd_name + " " + label["alpha.prd.detail.top_information"]);
            //$('navbar').update(productdetails.prd_name);
            $('navbar').show();    
            */

            productdetails.facebook_link = "http://" + info.domain + "/" + productdetails.lang + "/product/list.html?prd_id=" + productdetails.id + "&lang=" + productdetails.lang + "&code=" + productdetails.cat_code + "&level=" + current_level;
            productdetails.facebook_link = encodeURIComponent(productdetails.facebook_link);


            //writeDebug(productdetails.desc1);
            //                productdetails.catId = masterCatID;
            //                productdetails.brand = brandName;

            //                alert(masterCatID);
            productdetails.attachmentlist = "<a href=\"javascript: alpha_35();\" onclick=\"window.open('/" + productdetails.lang + "/product/shopList/location_popup.html?id=" + currentPrdId + "&cat_id=" + productdetails.cat_id + "&lang=" + productdetails.lang + "', 'windowname1', 'width=550,status=no,location=no,toolbar=no,scrollbars=yes,resizable=yes');return false;\"><img src='/templates/alpha/" + productdetails.lang + "/images/btn_store.gif'/></a>";
            productdetails.cat_name = cat_name;

            if (previousFunction == "") {
                productdetails.previous_function = "window.history.back(-1);";
            } else {
                productdetails.previous_function = previousFunction;
            }


            if (productdetails.is_hot == 'y') {
                productdetails.is_hot = "<img style='vertical-align:middle;' src='/templates/alpha/" + currentLang + "/images/new_icon.gif'/>";
            }
            else {
                productdetails.is_hot = "";
            }
            if (productdetails.catalogue) {
                productdetails.attachmentlist += "<br/>";
                productdetails.attachmentlist += "<a href='" + productdetails.catalogue + "' target='_blank'><img src='/templates/alpha/" + currentLang + "/images/btn_down_catalogue.gif' /></a>";

                //alert(productdetails.catalogue);
            }
            if (productdetails.av_icon) {
                productdetails.attachmentlist += "<br/>";
                rowCount = 0;
                productdetails.av_icon.each(
                    function (productavicons) {
                        productdetails.attachmentlist += "<img src='" + productavicons.icon + "'/>";
                        rowCount++;
                        if (rowCount == 4) {
                            productdetails.attachmentlist += "<br/>";
                            rowCount = 0;
                        }
                    }
                    )

                //alert(productdetails.catalogue);
            }

            if (productdetails.firmware) {
                productdetails.attachmentlist += "<br/>";
                productdetails.attachmentlist += "<a href='" + productdetails.firmware + "' target='_blank'><img src='/templates/alpha/" + currentLang + "/images/btn_firmware.gif' /></a>";
                //alert(productdetails.catalogue);
            }
            if (productdetails.manual) {
                productdetails.attachmentlist += "<br/>";
                productdetails.attachmentlist += "<a href='" + productdetails.manual + "' target='_blank'><img src='/templates/alpha/" + currentLang + "/images/btn_manual.gif' /></a>";
                //alert(productdetails.catalogue);
            }
            if (productdetails.desc3 != '') {
                var desc3Tmp = productdetails.desc3;
                productdetails.desc3 = '<p class="prd_detail_spec_title">'
                                            + '<span style="padding-left: 10px; padding-right: 10px; font-size: 12pt;">'
                                            + label["alpha.prd.detail.accessories.title"]
                                            + '</span>'
                                            + '</p>'
                                            + '<div style="padding-left:15px;*padding-left:0px;line-spacing:14px;">'
                                            + desc3Tmp
                                            + '</div>';
            }
            prdDetailsHtml += templates.prdDetails.evaluate(productdetails);
            //                $('prd_navbar').update('');
            //                 prdLocationHtml+=templates.prdDetails_nav.evaluate(productdetails);
            //                $('prd_navbar').update(prdLocationHtml);
            //                $('prd_navbar').show();

        }
    )

    $('prd_details').update(prdDetailsHtml);

    //    $('prd_navbar').update(
    /*for (var i=1;i<6;i++)
    {
    $('prd_filter_'+i).hide();
    }*/


    $('prd_list').hide();
    $('prd_details').show();

}

function showProductLocations(prdid, lang) {
    //alert(prdid+","+lang);
    var locations_url = "/services/product_locations.html?id=" + prdid + "&cat_id=" + masterCatID + "&lang=" + lang;
    //alert(details_url);
    //writeDebug(details_url);
    new Ajax.Request(locations_url, {
        onSuccess: displayLocationsDetails,
        onFailure: function (transpot) {
        },
        method: 'get'
    });

}

function displayLocationsDetails(transport, json) {
    try {
        var temptranspot = transport.responseText.gsub(/\s/, ' ');
        salesLocations = ('/*-secure-\n' + temptranspot + '\n*/').evalJSON();
        //        //writeDebug('finish evaluate!');
        displayLocationsDetailsPage();


    } catch (e) {
        //writeDebug('Display Error:'+e);
        return;
    }
    //writeDebug($('prd_filter').innerHTML);
}

function displayLocationsDetailsPage() {
    var locDetailsHtml = "";
    var prdLocationHtml = "";
    var navAdded = false;
    if (salesLocations.length > 0) {

        salesLocations.each(
        function (locations) {
            // Used to add store button for prd deatil in navigation bar, but useless now
            if (!navAdded) {
                //$('prd_navbar').update('');
                salesLocations.catId = masterCatID;
                salesLocations.brand = brandName;
                salesLocations.lang = currentLang;
                prdLocationHtml += templates.prdDetails_nav.evaluate(salesLocations);
                //$('prd_navbar').update(prdLocationHtml);
                $('prd_navbar').show();
                navAdded = true;
            }
            //writeDebug(productdetails.desc1);

            //                locDetailsHtml+=templates.prdSalesLocations.evaluate(locations);

        }
    )
        return prdLocationHtml;
        //    $('prd_locations').update(locDetailsHtml);
        //    /*for (var i=1;i<6;i++)
        //    {
        //        $('prd_filter_'+i).hide();
        //    }*/
        //    
        //    
        //    //$('prd_list').hide();
        //    $('prd_locations').show();

    }

}


function writeDebug(msg) {
    //alert(msg);
    if ($('debugDiv')) {
        $('debugDiv').value = msg + '\r\n' + $('debugDiv').value;
    }
}

//Event.observe(window, 'load', loadAccordions, false);

//
//	Set up all accordions
//
function loadAccordions() {

    var Accordion = new accordion('vertical_container');

    /*, {
    classNames : {
    toggle : 'vertical_accordion_toggle',
    toggleActive : 'vertical_accordion_toggle_active',
    content : 'vertical_accordion_content'
    }
    });
    */
    // Open first one
    //Accordion.activate($$('#vertical_container .accordion_toggle')[0]);

}

function show_div(name) {
    document.getElementById(name).style.display = "block";
}

var good;
function checkEmailAddress(field) {
    // the following expression must be all on one line...
    var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
    if (goodEmail) {
        good = true;
    } else {
        alert('Please enter a valid e-mail address.');
        field.focus();
        field.select();
        good = false;
    }
}


m = "I thought this might interest you...";

function mailThisUrl() {
    good = false
    checkEmailAddress(document.emailer.address);
    if (good) {
        var u = 'http://' + info.domain + '/' + currentLang + '/product/list.html?prd_id=' + currentPrdId + '%26clang=' + currentLang + '%26cat_name=' + masterCatID;
        // the following expression must be all on one line...
        window.open("mailto:" + document.emailer.address.value + "?subject=" + m + "&body=" + u, '_blank');
        //    window.location = ;
    }
}

function update_nav(name) {
    //    var defaultNavHtml = "<a href='/" + info.lang + "/home.html'>" + label["alpha.prd.nav.main"] + "</a> "
    //                        +"&nbsp; > &nbsp;<a href='/" + info.lang + "/product/list.html'>" + label["alpha.prd.nav.prd.cate"] + "</a> ";
    //    if(arguments.length > 1){
    //        navHtml = defaultNavHtml + "&nbsp; > &nbsp;<a href='#" + name + "</a> ";
    //    }
    //    else{
    //        navHtml += "&nbsp; > &nbsp;<a href='#" + name + "</a> ";
    //    }
}



function highlight_prd_active_link(prd_type_name) {
    var anchors = document.getElementsByTagName('a');
    for (var i = 0; i < anchors.length; i++) {
        var anchor = anchors[i];

        var a_class = anchor.className;
        if (a_class.indexOf("prdListOptions") >= 0) {
            if (check_array_data(prd_type_name, anchor.innerHTML)) {
                $(anchor).addClassName("prd_active_type");
            } else {
                $(anchor).removeClassName("prd_active_type");
            }
        }
    }
}

function check_array_data(array_data, check_data) {
    var re = false;
    for (var i = 0; i < array_data.length; i++) {
        var temp_arr = array_data[i].split(" &gt; ");
        for (var j = 0; j < temp_arr.length; j++) {
            //if (temp_arr[j].indexOf(check_data) >= 0) {
            if (temp_arr[j] == check_data) {
                re = true;
                break;
            }
        }
    }
    return re;
}



// for product left menu start
var PrdTagStatus = true;
var PrdTagCurrent = "";
var ChangeTagSpeed = parseFloat(0.8);


function PrdChangeTag(tag_id) {
    var action = false;
    var current_status = PrdTagStatus;
    var current_tag = PrdTagCurrent;

    if (current_tag == tag_id) {
        if ($(tag_id).visible() == true && current_status) {
            
            $('picClose_' + tag_id).style.display = "block";
            $('picOpen_' + tag_id).style.display = "none";
            new Effect.SlideUp($(tag_id), { duration: ChangeTagSpeed });
            current_status = false;
            current_tag = "";
            action = true;
        }
    } else {
        if ($(tag_id).visible() == false && current_status) {
            if (current_tag != "") {
                
                $('picClose_' + current_tag).style.display = "block";
                $('picOpen_' + current_tag).style.display = "none";
                new Effect.SlideUp($(current_tag), { duration: ChangeTagSpeed });
            }
            else {
                
            }
            
            $('picClose_' + tag_id).style.display = "none";
            $('picOpen_' + tag_id).style.display = "block";
            new Effect.SlideDown($(tag_id), { duration: ChangeTagSpeed });
            current_status = false;
            current_tag = tag_id;
            action = true;
        }
    }

    if (action) {

        PrdTagStatus = current_status;
        PrdTagCurrent = current_tag;
        window.setTimeout(function () { checkStatus(); }, ChangeTagSpeed * 1000);
    }
}

function checkStatus() {
    PrdTagStatus = true;
}
// for product left menu end



// add by evans 20100301 for data response start         
function ready_function_call_back() {
    if (ready_function.length > 0) {
        var temp_function = ready_function[0];
        for (var i = 1; i < ready_function.length; i++) {
            ready_function[i - 1] = ready_function[i];
        }
        ready_function.length = ready_function.length - 1;
        window.setTimeout(function () { ready_function_current = null; temp_function(); }, 500);
    } else {
        $('product_breakdown_bar').style.display = "block";
        $('product_hierachy_bar').style.display = "block";
        $('hidden_loding_body_div').style.display = "none";
        $('hidden_body_div').style.display = "block";
        ready_function_current = null;
    }
}
// add by evans 20100301 for data response end   
