/*
Elxis CMS - plugin Youtube Video
Created by Stavros Stratakis / Ioannis Sannos
Copyright (c) 2006-2025 elxis.org
https://www.elxis.org
*/

/* ADD VIDEO ID */
function addYTVideoID() {
	var videoid = document.getElementById('youtube_videoid').value;
    if (videoid == '') { return false; }
	var pcode = '{youtube}'+videoid+'{/youtube}';
	addPluginCode(pcode);
}

function plugYTOnLoad() {
	if (!document.getElementById('plugytaddlink')) { return; }
	document.getElementById('plugytaddlink').addEventListener('click', function(e){ e.preventDefault(); addYTVideoID(); }, false);
}

if (document.getElementById('plugytaddlink')) {
	plugYTOnLoad();
} else {
	if (document.readyState != 'loading') {
		plugYTOnLoad();
	} else if (document.addEventListener) {
		document.addEventListener('DOMContentLoaded', function(){ plugYTOnLoad(); });
	} else {
		document.attachEvent('onreadystatechange', function() { if (document.readyState == 'complete') { plugYTOnLoad(); } });
	}
}
