﻿/* Lists */
function filterPoss(filterType)
{
    var value = null;
    var sel = document.getElementById(filterType);
    if(sel.selectedIndex>0)
        value = sel.options[sel.selectedIndex].value;

    if(value==null || value.length==0)
        var toUrl = 'portrait-possibilities.aspx';
    else
        var toUrl = 'portrait-possibilities.aspx?ft='+filterType+'&fv='+value;

    window.location.href = toUrl;
}
function selectPoss()
{
    var qs = new Querystring();
    var v1 = qs.get("ft");
    var v2 = qs.get("fv");
    if(v1!=null && v1=="ato")
    {
        setSelected(v1,v2);
    }
}
function setSelected(id, value)
{
    for (i=0;i<document.getElementById(id).length;i++)
    {
        if (value == document.getElementById(id).options[i].value)
            document.getElementById(id).options[i].selected = true;
    }
}
function filterProduct(ptid, catid)
{
    var ptvalue = "";
    var catvalue = "";
    var ptsel = document.getElementById(ptid);
    if(ptsel.selectedIndex>-1)
        ptvalue = ptsel.options[ptsel.selectedIndex].value;
    var catsel = document.getElementById(catid);
    if(catsel.selectedIndex>0)
        catvalue = catsel.options[catsel.selectedIndex].value;

    if(ptvalue=="" && catvalue=="")
        var toUrl = 'portrait-products-detail.aspx';
    else
        var toUrl = 'portrait-products-detail.aspx?pt='+ptvalue+'&cat='+catvalue;

    window.location.href = toUrl;
}
/* Images */
var imageInfoList = [];
function imageInfo(hrefId, thumbnail, fullsize, detail1, detail2, detail3)
{
    this.hrefId = hrefId;
    this.thumbnail = thumbnail;
    this.fullsize = fullsize;
    this.detail1 = detail1;
    this.detail2 = detail2;
    this.detail3 = detail3;
}
function addImageInfo(hrefId, thumbnail, fullsize, detail1, detail2, detail3)
{
    if(fullsize!=null && fullsize.indexOf('jpg')!=-1)
        imageInfoList[imageInfoList.length] = new imageInfo(hrefId, thumbnail, fullsize, detail1, detail2, detail3);    
}
function setImage(selectedIndex)
{
    if(imageInfoList[selectedIndex]==null)
        return;
    document.getElementById("mainimage").src = imageInfoList[selectedIndex].fullsize;
    setThumbnailSelected(selectedIndex);
}
function setThumbnailSelected(selectedIndex)
{
    for(i=0;i<imageInfoList.length;i++)
    {
       document.getElementById(imageInfoList[i].hrefId).className="";
    }
    document.getElementById(imageInfoList[selectedIndex].hrefId).className="current";
    setDetails(selectedIndex);
}
function setDetails(selectedIndex)
{
    if(imageInfoList[selectedIndex].detail1!=null && document.getElementById("detail1")!=null)
    {   
        document.getElementById("detail1").innerHTML = imageInfoList[selectedIndex].detail1;
    }
    if(imageInfoList[selectedIndex].detail2!=null && document.getElementById("detail2")!=null)
    {   
        document.getElementById("detail2").innerHTML = imageInfoList[selectedIndex].detail2;
    }
    if(imageInfoList[selectedIndex].detail3!=null && document.getElementById("detail3")!=null)
    {   
        document.getElementById("detail3").innerHTML = imageInfoList[selectedIndex].detail3;
    }
}
function setDefaultImage(defaultIfNone)
{
    if(document.getElementById("mainimage").src.indexOf('jpg')!=-1)
        return;
    if(imageInfoList.length>0)
        setImage(0);
    else
        document.getElementById("mainimage").src = defaultIfNone;
}
function getThumbnailSelectedIndex()
{
    var retval = 0;
    for(i=0;i<imageInfoList.length;i++)
    {
        if(document.getElementById(imageInfoList[i].hrefId).className=="current")
        {
            retval = i;
            break;
        }
    }
    return retval;
}
function goNextImage()
{
    var currentIndex = getThumbnailSelectedIndex();
    var nextIndex = parseInt(currentIndex)+1;
    if(nextIndex+1>imageInfoList.length)
        return;
    setThumbnailSelected(nextIndex);
    setImage(nextIndex);
}
function goPreviousImage()
{
    var currentIndex = getThumbnailSelectedIndex();
    var nextIndex = parseInt(currentIndex)-1;
    if(nextIndex<0)
        return;
    setThumbnailSelected(nextIndex);
    setImage(nextIndex);
}