Video.Advertising = {

	checkAdvertising: function() {

	    Video.Advertising.MediumRectangle.checkAd();

		//Video.Advertising.ArticleEnd.checkAd();
	}
};

Video.Advertising.MediumRectangle = {

    checkAd: function() {

        var cont     = document.getElementById('adMedRectContent');
        var elemsDiv = cont.getElementsByTagName('div');
        var i        = 0;

        // Check for valid element nodes within content div
        var isValid = false;
    
        if (cont.hasChildNodes()) {
        	
        	children = cont.childNodes;
        	for (var i=0, element; element=children[i]; i++) {
        		
        		if (children[i].nodeName == 'DIV') {
        			
        			if (children[i].hasChildNodes()) {
        				
        				isValid = true;
        			}
        		}
        	}
        }

        // Check if box may be shown; 'contentad' variable => comes from EMS
        if( 'undefined' == typeof(contentad) || contentad != 1 || isValid == false) {

            document.getElementById('adMedRect').style.display = 'none';
            return;
        }
        
        
        for( i=0; i<elemsDiv.length; i++ ) {

            var el = elemsDiv[i];
            if(el.innerHTML == 'Anzeige') {

                el.id = 'myAdId' + Math.random(1,100);
                el.style.fontSize = '90%';
            }
        }
    }
};

Video.Advertising.ArticleEnd = {

    checkAd: function() {

        // Check ad content and set display options.
        var cont     = document.getElementById('adArticleEndContent');
        var elemsDiv = cont.getElementsByTagName('div');
        var elemsIns = cont.getElementsByTagName('ins');

        var i=0;
        var checkDiv = true;
        var checkIns = true;

        // Check, if no ad was send from server - then hide the block
        if( elemsDiv.length <= 1 ||
    	    ('undefined' != typeof(elemsDiv[1]) && elemsDiv[1].innerHTML.length <= 10)) {

    	        checkDiv = false;
        }

        // Check, if no ad was send from server - then hide the block
        if( elemsIns.length <= 1 ||
    	    ('undefined' != typeof(elemsIns[1]) && elemsIns[1].innerHTML.length <= 10)) {

            checkIns = false;
        }

        // Check if box may be shown; 'contentad' variable => comes from EMS
        if( !checkDiv && !checkIns ) {

            document.getElementById('adArticleEnd').style.display = 'none';
            return;
        }

        if( checkDiv ) {

            for(i =0; i< elemsDiv.length; i++) {

                var el = elemsDiv[i];
                if(el.innerHTML == 'Anzeige') {

                    el.id = 'myAdId' + Math.random(1,100);
                    el.style.fontSize = '90%';
                }
            }
        }
    }
}
