﻿/// <reference path="/Scripts/MicrosoftAjax.js" />
/// <reference path="/Scripts/Algemeen.js" />
/// <reference path="~/kkServices.asmx" />
/* 
Content : Javascript for /Ingave/zoekertje_detail.aspx  
Author : Peter Meir
Owner : N.V. CMR (Concentra Media Regie)
*/
function mijnAdvertenties(){
    this.imgIsInWebshop = null;
    this.inWebwinkel = true;
    this.userId = null;
    this.adId = null;
    this.AdsChecked = null;
    this.AdIds = null;

    mijnAdvertenties.prototype.changeWebshopStatus = function(userId, adId, inWebwinkel) {
        try{
            if(inWebwinkel=='1'){this.inWebwinkel=true;}
            if(inWebwinkel=='0'){this.inWebwinkel=false;}
            this.userId = userId;
            this.adId = adId;
            CCV.kkServices.ModifyWebshopStatus(userId, adId, this.inWebwinkel, this.changeWebWinkelStatus_OnSuccess, this.changeWebWinkelStatus_OnFailure);
        }catch(e){
            alert(e.toString());
        }
    }
    mijnAdvertenties.prototype.changeWebWinkelStatus_OnSuccess = function(result, eventargs) {
        var blnOK = result.substring(0,1);
        var resText = result.substring(1,result.length);
        if(blnOK=='0'){
            alert(resText);
        }else{
            if(mzObj.inWebwinkel==true){ //switched off now
                mzObj.imgIsInWebshop.src='/layout/in_webwinkel_0.png'
                mzObj.imgIsInWebshop.onclick = function(){var myAdId = this.id.replace('imgInWebshop','');modifyWebWinkelStatus(this, myAdId, 0);}
            }else{  //switched on now
                mzObj.imgIsInWebshop.src='/layout/in_webwinkel_1.png'
                mzObj.imgIsInWebshop.onclick = function(){var myAdId = this.id.replace('imgInWebshop','');modifyWebWinkelStatus(this, myAdId, 1);}
            }
        }
    }
    mijnAdvertenties.prototype.changeWebWinkelStatus_OnFailure = function(result, eventargs) {
        alert(result._message);
    }
    mijnAdvertenties.prototype.getSelectedAds = function() {
        this.AdsChecked = null;
        this.AdIds = null;
        for(var i=0;i<=parentObj.childNodes.length;i++){
            if(parentObj.childNodes[i]!=undefined){
                var child = parentObj.childNodes[i];
                if(child.nodeType == 1){//html element
                    if(child.type == 'checkbox'){
                        this.AdsChecked[i] = child.checked;
                        this.AdIds[i] = child.id.replace('chkZoekertje','');
                    }else{
                        if(child.hasChildNodes()){
                            checkAll(child, checked);
                        }
                    }
                }
            }
        }
        return this.AdsChecked;
    }
    mijnAdvertenties.prototype.deleteSelectedAds = function() {
        for(adKey in this.AdsChecked){
            var adId = this.AdIds[adKey];
            var adChecked = this.AdsChecked[adKey];
            if(adChecked){
                CCV.kkServices.DeleteAdFromIngeven(adId, this.DeleteAdFromIngeven_OnSuccess, this.DeleteAdFromIngeven_OnFailure);
            }
        }
    }
    mijnAdvertenties.prototype.DeleteAdFromIngeven_OnSuccess = function(result, eventargs) {
        
    }
    mijnAdvertenties.prototype.DeleteAdFromIngeven_OnFailure = function(result, eventargs) {
        alert(result._message);
    }
}

function checkAll(parentObj, checked){
    for(var i=0;i<=parentObj.childNodes.length;i++){
        if(parentObj.childNodes[i]!=undefined){
            var child = parentObj.childNodes[i];
            if(child.nodeType == 1){//html element
                if(child.type == 'checkbox'){
                    child.checked = checked;
                }else{
                    if(child.hasChildNodes()){
                        checkAll(child, checked);
                    }
                }
            }
        }
    }
}