﻿// JScript File

// oCatProps wordt serverside gemaakt, en ziet er zo uit:
// Dim sJS = "oCatProps = {'sArticleColorClientID':'" & Me.ManagerExtension.sArticleColorClientID & "',"
// sJS += "'ClientFieldArticleID':'" & Page.CatalogManager.ClientFieldArticleID & "',"
// sJS += "'TargetButtonID':" & iTargetButtonID.ToString & ","
// sJS += "'sFromRecentClientID':'" & Me.ManagerExtension.sFromRecentClientID & "',"
// sJS += "'ID':'" & Me.ID & "'};"

// Nshop wordt serverside gevuld.
var Nshop = {
    ClientFieldArticleID: '',
    ClientFieldColorID: '',
    ID: '',
    TargetButtonID: '', 
    ClientFieldFromRecentID: '',
    ArticleID: 0,
    GroupID: 0,
    View: ''
};


// Functie voor toevoegen van een laatst bekeken artikel ( op artikel/kleur nivo )
function addLastVisit(iArticleID, iColorSpecItemID) {  
    // ColorSpecItemID opzoeken

    if (!iColorSpecItemID)
        iColorSpecItemID == 0; 
     
     // Cookie van gebruiker met laastse artikel informatie
    var sCookie = getCookie('lstVisit','');    
    aCookie = sCookie.split("+");    
    sCookie = iArticleID + '_' + iColorSpecItemID;
    
    // Controleren of artikel er al bij staat.
    for (var i = 0; i < aCookie.length; i++){
        if (aCookie[i].toLowerCase() == sCookie.toLowerCase())
            Array.removeAt(aCookie,i);
    }           
    for (var i = 0; i < 10 && i < aCookie.length; i++){
        sCookie += '+' + aCookie[i];     
    } 
    setCookie('lstVisit',sCookie,100);
}


function onProductClick(iProductID, iColorSpecItemID) {
    $get(Nshop.ClientFieldArticleID).value = iProductID + "~" + Nshop.ID;
    $get(Nshop.ClientFieldColorID).value = iColorSpecItemID;
    addLastVisit(iProductID, iColorSpecItemID);
}

// Vergroot scherm weergeven.
function showPrint(){
    var sSrc = sHostName + 'content/RelatedDetail.aspx?cmd=print&ProductID=' + Nshop.ArticleID;
    sSrc += '&View=' + Nshop.View;  
    sSrc += '&ColorID=' + Nshop.ColorSpecID;
    sSrc += '&GroupID=' + Nshop.GroupID;

    if (Nshop.sDetailImgId && Nshop.sDetailImgId.length > 0 && $get(Nshop.sDetailImgId))
        sSrc += '&FRS=' + $get(Nshop.sDetailImgId).src;
    
//    if (oCatProps.sSizeDrpId && oCatProps.sSizeDrpId.length>0 && $get(oCatProps.sSizeDrpId)){
//        sSrc += '&Size=' + GetValue($get(oCatProps.sSizeDrpId));    
//    }
    
    ModalPopupOpen("Enlarge", "80%", "80%", sSrc, null, null, true, true); 
}

function showMail(){
    var sSrc = sHostName + 'content/RelatedDetail.aspx?cmd=mail&ProductID=' + Nshop.ArticleID;
    sSrc += '&ColorSpecID=' + Nshop.ColorSpecID;
    sSrc += '&GroupID=' + Nshop.GroupID;
    sSrc += '&TargetBtnID=' + Nshop.TargetButtonID;        
    ModalPopupOpen("Mail", "35", "46", sSrc, null, null, true, true); 
}

// Recente item geklikt, naar juiste artikel gaan.
function recentClicked(iArticleID, iColorSpecItemID) {   
    // Hidden field met Kleur SpecitemID
    var oHid = getOrCreateHidden(Nshop.ClientFieldColorID, true);
    oHid.value = iColorSpecItemID;

    oHid = getOrCreateHidden(Nshop.ClientFieldArticleID, true);
    oHid.value = iArticleID;
    
    // Laatst bekeken bijwerken.
    addLastVisit(iArticleID, iColorSpecItemID);    
    
    // Serverside laten weten dat we van recentklik komen.
    oHid = getOrCreateHidden(Nshop.ClientFieldFromRecentID, true);
    oHid.value = "1"    
}

// Vergroot scherm weergeven.
function Enlarge(iArticleID){
    var sSrc = sHostName + 'content/Enlarge.aspx?ProductID=' +  iArticleID;
    sSrc += '&View=' + Nshop.View;
    sSrc += '&ColorID=' + Nshop.ColorSpecID;
    sSrc += '&GroupID=' + Nshop.GroupID;

    if (Nshop.sDetailImgId && Nshop.sDetailImgId.length > 0 && $get(Nshop.sDetailImgId))
        sSrc += '&FRS=' + $get(Nshop.sDetailImgId).src;
   
    //var sHTML = '<iframe src="' +  sSrc + '" width="775px" marginwidth=0 marginheight=0  height="570px" />'
    ModalPopupOpen("Enlarge", 780 + 30, 577 + 30, sSrc, null, null, true, true);    
}


// Vergroot scherm weergeven.
//function ShowRelated(iArticleID, iSpecColorID){
//    recentClicked(iArticleID,iSpecColorID);
//    var sSrc = sHostName + 'RelatedDetail.aspx?ProductID=' +  iArticleID;     
//    sSrc += '&ColorID=' + iSpecColorID;
//    sSrc += '&GroupID=' + oCatProps.GroupID;
//        
//    ModalPopupOpen("Related", 505 + 30, 475 + 30, sSrc, null, null, true, true);    
//}

// args = {'ProductID' : iProductID, 'ColorSpecID' : iColorSpecID};
function popupClosed(Args){
    var oHid = theForm[Nshop.ClientFieldColorID + Args.ProductID];
    if (!oHid) {
        oHid = document.createElement("INPUT")
        oHid.type = "hidden";
        oHid.name = Nshop.ClientFieldColorID + Args.ProductID;
        theForm.appendChild(oHid);   
    }

    oHid.value = Args.ColorSpecID;
    onProductClick(Args.ProductID, Args.ColorSpecID);

    //MenuClick(null, Nshop.TargetButtonID, '', null);
    __doVwaPB('', '', 2);
}

//function ArticleSwichtImage(oImg) {
//        var oImgDet = $get(oCatProps.sDetailImgId);      
//        var sCurImg = oImgDet.src.substr(sHostName.length);
//        var sCurTitle = oImgDet.title;
//        
//        // Detail afbeelding instellen
//        oImgDet.src = sHostName + replaceString(oImg.src.substr(sHostName.length), '_sm.', '_det.');
//        oImgDet.title = oImg.title;
//        
//        // Kleine afbeelding instellen
//        oImg.src = sHostName + replaceString(sCurImg, '_det.', '_sm.');
//        oImg.title = sCurTitle;
//}

function showAlertIFrame(sHtml){
   var iframe = document.getElementById(oPopup.sPopupID + 'Ifrm').contentWindow;    
   if (iframe && iframe.ModalPopupOpen){
        iframe.ModalPopupOpen('Alert', 305, 195, sHtml ,null,null,false,true);   
   }
}

/*
 
/// Slide functies   
function vwaSlideOnclick(sCMD, sID){
    // Slide tabel zoeken.
    var oTable = $get(sID);
    var oIndex = $get(sID + '_Index');
    var iItemCount = toNumber(oTable.ItemCount);    
    var iContentWidth = toNumber(oTable.ContentWidth);
    var iItemOnPage =toNumber(oTable.ItemOnPage);
    var iStepWidth = toNumber(oTable.StepWidth);
    var iIndex = toNumber(oIndex.value);
    var oAnimation = null;
    var sOrientation = oTable.Orientation;
    
    if (!iContentWidth || !iStepWidth)
        return false;
          
    oAnimation = oTable.animation; 
    if (!oAnimation){
        oAnimation = new $AA.MoveAnimation($get(sID + '_items'), 0.2, 100, "scrollTop");   
        oTable.animation = oAnimation;
    }        
    if (oAnimation.get_isPlaying())
        return false;
    
    switch(sCMD) {
        case 'back':
            iIndex +=1;
            if (sOrientation == 'Horizontal')
                oAnimation.set_horizontal(iStepWidth);
            else
                oAnimation.set_vertical(iStepWidth);
            
            break;            
        case 'forward':
            iIndex -=1;
             if (sOrientation == 'Horizontal')
                oAnimation.set_horizontal(iStepWidth * -1);
            else
                oAnimation.set_vertical(iStepWidth * -1);
            break;
    }
    
    if (iIndex <= (iItemCount * -1) + iItemOnPage)        
        return false;       
    
    if (iIndex >0)
        return false;
           
   vwaSetButton(sID, iIndex, (iItemCount * -1) + iItemOnPage);
   
    oAnimation.play();    
    
   // $get(sID + '_items').style.left = iIndex * iStepWidth;    
    oIndex.value = iIndex;
}

function vwaSlideInit(sID, iItemCount, iContentWidth, iStepWidth, sOrientation){
     // Slide tabel zoeken.
    var oTable = $get(sID);
    var oIndex = $get(sID + '_Index');  
    oTable.ItemCount = iItemCount;    
    oTable.ContentWidth = iContentWidth;    
    oTable.StepWidth = iStepWidth;    
    oTable.Orientation = sOrientation;
    
    var iIndex = toNumber(oIndex.value);    
    if (!iContentWidth || !iStepWidth)
        return false;        
    var iItemOnPage = iContentWidth / iStepWidth;
    oTable.ItemOnPage = iItemOnPage;
    var oFWBtn = $get(sID + '_forwardbutton');
    oFWBtn._className = oFWBtn.className;
    var oBKBtn =  $get(sID + '_backbutton');
    oBKBtn._className = oBKBtn.className;   
    vwaSetButton(sID, iIndex, (iItemCount * -1) + iItemOnPage);
    oFWBtn.onmouseover = function() {
        this.className += 'hover';
    }
    oFWBtn.onmouseout = function() {
        this.className = this.className.replace('hover','');
    }    
    oBKBtn.onmouseover = function() {
        this.className += 'hover';
    }
    oBKBtn.onmouseout = function() {
       this.className =  this.className.replace('hover','');
    }
}


function vwaSetButton(sID, iIndex, iMaxIndex){

    if (iIndex < iMaxIndex+1)     
        $get(sID + '_backbutton').className += 'dis';
    else if ($get(sID + '_backbutton').className.Contains('dis'))
        $get(sID + '_backbutton').className = $get(sID + '_backbutton')._className; 
           
    if (iIndex == 0)
        $get(sID + '_forwardbutton').className += 'dis';
    else if ($get(sID + '_forwardbutton').className.Contains('dis'))
        $get(sID + '_forwardbutton').className = $get(sID + '_forwardbutton')._className;
}
*/
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded()