﻿// JScript File

function show(name){
    document.getElementById(name).style.display="block";
}

function hide(name){
    document.getElementById(name).style.display="none";
}

function tog(name)
{
    if (document.getElementById(name).style.display=="none")
    {
        show(name);
    }
    else
    {
        hide(name);
    }
}

function o(name)
{
    return document.getElementById(name);
}


function openWin(url, width, height) {
    var format = "location=0,status=0,scrollbars=1,width="+ width +",height="+heightM;
    var a = window.open(url,"wmWin",format);
    a.focus();
}


function jump(isVal)
{
    var groupby = o('ctl00_content_dGroupName').options[o('ctl00_content_dGroupName').selectedIndex].value;
    var groupval = o('ctl00_content_dGroupValue').options[o('ctl00_content_dGroupValue').selectedIndex].value;
    var fam = o('ctl00_content_hFamily').value;
    
    var runi = "en";
    if (o('r_si').checked)
        runi = "si";
    
    groupby = replaceNameVals(groupby);
    groupval = replaceNameVals(groupval);
    
    if (isVal)
        location.href="/Products/Info.aspx/" + fam + "/" + groupby + "/" + groupval + "/" + runi ;
    else    
        location.href="/Products/Info.aspx/" + fam + "/" + groupby + "/$$$/" + runi ;       
    
    /*if (isVal)
        location.href="/Products/Info.aspx/" + fam + "/" + groupby + "/" + groupval + "/" + runi ;
    else    
        location.href="/Products/Info.aspx/" + fam + "/" + groupby + "/$$$/" + runi ;    */
    
}

function jumpPagination(isVal, page)
{
    var groupby = o('ctl00_content_dGroupName').options[o('ctl00_content_dGroupName').selectedIndex].value;
    var groupval = o('ctl00_content_dGroupValue').options[o('ctl00_content_dGroupValue').selectedIndex].value;
    var fam = o('ctl00_content_hFamily').value;
    
    var runi = "en";
    if (o('r_si').checked)
        runi = "si";
    
    groupby = replaceNameVals(groupby);
    groupval = replaceNameVals(groupval);
    
    
    if (isVal)
        location.href="/Products/Info.aspx/" + fam + "/" + groupby + "/" + groupval + "/" + runi + "/" + page;
    else    
        location.href="/Products/Info.aspx/" + fam + "/" + groupby + "/$$$/" + runi + "/" + page;       
    
}

function jumpSort(page, sortName, sortType)
{
    var groupby = o('ctl00_content_dGroupName').options[o('ctl00_content_dGroupName').selectedIndex].value;
    var groupval = o('ctl00_content_dGroupValue').options[o('ctl00_content_dGroupValue').selectedIndex].value;
    var fam = o('ctl00_content_hFamily').value;
    
    var runi = "en";
    if (o('r_si').checked)
        runi = "si";
    
    groupby = replaceNameVals(groupby);
    groupval = replaceNameVals(groupval);
    sortName = replaceNameVals(sortName);
    
    if(sortName!='')
    {
        location.href="/Products/Info.aspx/" + fam + "/" + groupby + "/" + groupval + "/" + runi + "/" + page + "/" + sortName + "/" + sortType;
    }
    else
    {
        location.href="/Products/Info.aspx/" + fam + "/" + groupby + "/" + groupval + "/" + runi + "/" + page;
    }
   
    
}


function replaceNameVals(value)
{
    return value.replace(/#/g, "$").replace(/ /g, "+").replace(/\./g, "=").replace("/", "_");
}

function jumpRep(path, value)
{
    if(value!="")
    {
        value = replaceNameVals(value);
        location.href= path + "/" + value ;
    }
}


function jumpPage(obj, adv)
{
var groupval, fam, runi;
fam = o('ctl00_content_hFamily').value;
runi = "en";

if (adv=='equal')
{
    groupval = obj.options[obj.selectedIndex].value;    
}
else if(adv=='next')
{
    if (obj.selectedIndex==obj.options.length-1)
        groupval = obj.options[1].value;
    else
        groupval = obj.options[obj.selectedIndex+1].value;
}
else if(adv=='prev')
{
    if (obj.selectedIndex==0 || obj.selectedIndex==1)
        groupval = obj.options[obj.options.length-1].value;
    else
        groupval = obj.options[obj.selectedIndex-1].value;
}

    if (groupval.indexOf("M")>-1)
        runi = "si";   
    
    groupval = replaceNameVals(groupval);
    
    //location.href="/Products/Info.aspx/" + fam + "/Catalog+Page+Number/" + groupval + "/" + runi ;
    location.href="/Products/Info.aspx/" + fam + "/Catalog+Page+Number/" + groupval + "/" + runi ;
}


function selectionRow(element, out, impar)
{
    if (out)
    {                 
        oldgridSelectedColor = element.style.backgroundColor;
        if (impar==1)
        {
            element.style.backgroundColor='#E6EBED';           
        }
        else
        {
            element.style.backgroundColor='white';   
        }
        
        element.style.cursor='default';        
        element.firstChild.childNodes[0].checked = false;
    }
    else
    { 
        oldgridSelectedColor = element.style.backgroundColor;
        element.style.backgroundColor='#ffff99';
        element.style.cursor='hand';        
        element.firstChild.childNodes[0].checked = true;
    }            
}

function compareParts(tot, type)
{
    var toCompare = '';
    for(var i =0; i<tot; i++)
    {        
        if(o('chkPart_'+i).checked)
        {
            toCompare += o('chkPart_'+i).value + ',';
        }
    }
    
    if(toCompare!='')
    {
        var win = window.open("/Products/Compare.aspx?type="+ replaceNameVals(type) +"&parts=" + toCompare);
    }
    else
    {
        alert("Select the parts to compare");
    }
}
