var heeloo = new heelooInterface(); var cloud = new heelooInterface(); var ua = "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)"; ua = ua.toLowerCase(); if (ua.indexOf("ipad")>-1){ cloud.isTablet = true; } if (typeof(XMLParser) == "undefined"){ xg.installScript("https://www.megatims.es/ca/xg/xg-xml.js"); } let _lastVPlay = null; xg.addEvent("win_scroll",function(){ var sv = xg.q("video[data-autoplay='true']"); const docHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; sv.forEach((v)=>{ let p = v.getBoundingClientRect(); if (v.getAttribute("data-ii")==null){ if (p.y < docHeight+500) { v.style.height = v.getBoundingClientRect().height+"px"; v.setAttribute("data-ii","true"); v.src = v.getAttribute("data-src"); } }else{ if (p.y < docHeight-500){ if (!v.paused && !v.ended && v.readyState > 2) { }else{ if (v.src.length>0) { v.loop = false; v.play(); } } } } }); }); cloud.installVideoPlayers(); cloud.installGallery(); function cloudVideoPlayer(){ this.object = null; this.playing = false; this.play = hv_playVideo; this.pause = hv_pauseVideo; this.stop = hv_stopVideo; this.fileId = null; this._monitorTimer = null; this._monitor = hv_monitor; this.duration = 0; this.pageUnload = hv_pageUnload; this.fullScreen = hv_fullscreen; this.changeButtons = hv_changebuttons; this.startFrom = 0; this._canPlay = false; this.jumpTo = hv_jumpTo; this.installControls = hv_installControls; } function cloudMusicPlayer(){ try{ this.audio = new Audio(); }catch(e){ //alert("error on browser"); this.audio = null; } this.containerClassName = "music-player-container"; this.play = himp_playMusic; this.stop = himp_stopMusic; this.duration = 0; this.jumpTo = himp_jumpTo; this.playerObj = null; this.createPlayer = himp_createPlayer; this.destroyPlayer = himp_destroyPlayer; this.fileName = null; this.fileId = null; this.lastFileId = null; this._monitorTimer = null; this._monitor = himp__monitorMP; this.changeButtons = himp_changebuttons; this.playing = false; this.status = null; this.lastPos = 0; this.artwork = null; this.setArtwork = himp_setArtwork; this.clearArtwork = himp_clearArtwork; this.musicPage = null; this.gotoPage = himp_gotoPage; this.hidePlayer = himp_hidePlayer; } function heelooInterface(){ this.addUser = hi_addHeelooUser; this.addUserRequest = hi_addCloudUserRequest; this.setUAccess = hi_setUserAccess; this.saveKey = hi_saveSetting; this.addLike = hi_addLike; this.cancelLike = hi_cancelLike; this.publishSocial = hi_publishSocial; this._calculateTime = hi_calculateTime; this.music = new cloudMusicPlayer; this.video = new cloudVideoPlayer; this.requestLogin = hi_requestLogin; this.requestFBLogin = hi_requestFBLogin; this.waveLoaded = hi_waveLoaded; this.scrollWave = hi_scrollWave; this._step =null; this._wavePos =0; this._ms =0; this._wavescroll = null; this.isTablet = false; this.isApp = false; this.appLoaded = false; this.saveForm = hi_saveForm; this.addToForm = hi_addToForm; this.clearForm = hi_clearForm; this.loginForm = hi_loginForm; this.logoutForm = hi_logoutForm; this.modForm = hi_modForm; this.installUpload = hi_installUpload; this.uploadFile = hi_uploadFile; this._facebookAppId = "254033207965456"; this.requestFriendship = himp_requestFriendship; this._socialPanePopup = null; this._socialPaneTimer = null; this.createSocialPane = hi_createSocialPane; this.showSocialPane = hi_showSocialPane; this.hideSocialPane = hi_hideSocialPane; this.addToNewsletter = hi_addToNewsLetter; this.addToContacts = hi_addToContacts; this.pushLocation = hi_pushLocation; this.addToCart = hi_addToCart; this.modifyCart = hi_modifyCart; this.emptyCart = hi_emptyCart; this.getCart = hi_getCart; this.productRemoved = hi_productRemoved; this.removeFromCart = hi_removeFromCart; this.executeCart = hi_executeCart; this.redoCartObject = hi_redoCartObject; this.cartHas = hi_cartHas; this.cartContains = hi_cartHas; this.onAddToCart = hi_onAddToCart; this.onBeforeAddToCart = hi_onBeforeAddToCart; this.onRemoveFromCart = hi_onRemoveFromCart; this.addProductToFavorites = hi_addProductToFavorites; this.removeProductsFromFavorites = hi_removeProductsFromFavorites; this.getCategoryNewFormula = hi_getCategoryNewFormula; this.changeVAT = hi_changeVAT; this.changeFromVAT = hi_changeFromVAT; this.checkForUsername = hi_checkForUsername; this.checkForPassword = hi_checkForPassword; this.showImage = hi_showImage; this.openImage = hi_showImage; this.changeImage = hi_changeImage; this.call = hi_call; this.sms = hi_sms; this.cart = new cloudCart; this.login = hc_login; this.addComment = hc_addComment; this.deleteComment = hc_deleteComment; this.commentDeleted = null; this.commentAdded = null; this.calendar = new cloudCalendarInterface; this.clients = new cloudClientsInterface; this.location = new xgLocationInterface; this.editHTML = hc_editHTML; this.selectImage = hc_selectImage; this.selectFile = hc_selectFile; this.tai = new taiInterface; this.meet = new TelssoMeetInterface; this.installVideoPlayers = hc_installVideoPlayers; this.videoOnPlay = hc_videoOnPlay; this.installGallery = hc_installGallery; this._galleryScreen = null; this._galleryObjects = new Array(); this.checkVATNumber = hc_checkVATNumber; this.installLanguages = hc_installLanguages; this.minimizeLeft = hc_minimizeLeft; } function hc_minimizeLeft(o){ let pvalue = o.getAttribute("data-minimized"); let hdr = xg.obj("hx_header"); let lp = xg.obj("hlx_leftpane"); let ams =xg.obj("app_main_surface"); let sep = xg.obj("hlx_separator_div"); let mb = xg.obj("_mainbody"); if (pvalue == null){ ams._width = ams.getBoundingClientRect().width; ams._left = ams.getBoundingClientRect().left-mb.getBoundingClientRect().left; hdr.style.left = "-100px"; mb.style.left = "0px"; mb.style.width = "100%"; xg.addClassName(lp,"xg-animated"); let rect = lp.getBoundingClientRect(); lp._width = rect.width; xg.addClassName(lp,"left-minimise"); lp.style.width = "130px"; sep.style.display = "none"; ams.style.left = (130)+"px"; ams.style.width = (xg.view().width-150)+"px"; win_onresize(); o.setAttribute("data-minimized","true"); o.setAttribute("data-pleft",rect.left); o.setAttribute("style","display:block !important"); o.setAttribute("class","icon-next-c"); window.setTimeout(function(){ xg.delClassName(lp,"xg-animated"); },300); }else{ o.setAttribute("class","icon-back-c"); lp.style.width = lp._width+"px"; xg.delClassName(lp,"left-minimise"); mb.style.left = "80px"; mb.style.width = "calc(100% - 80px)"; window.setTimeout(function(){ hdr.style.left = "5px"; let rect = lp.getBoundingClientRect(); console.debug(rect); ams.style.left = ams._left +"px"; ams.style.width = ams._width+"px"; win_onresize(); },1); o.removeAttribute("data-minimized"); } } function hc_installLanguages(objId){ xg.xhr.post("https://www.megatims.es/ca/exp/getlanguages/?content=text",function(r){ let obj = xg.obj(objId); JSON.parse(r).forEach((l)=>{ let name = l.name; let opt = xg.new(name,"OPTION"); opt.setAttribute("value",l.code); if (obj.value == l.code) opt.setAttribute("selected","true"); obj.appendChild(opt); }); let _value = obj.getAttribute("value"); if (_value!=null) obj.setValue(_value); }) } function hc_checkVATNumber(vatid){ let me = {} me.done = function(){} let url = "https://www.megatims.es/ca/exp/identify/vat/?content=text&vat="+encodeURIComponent(vatid); xg.xhr.post(url,function(r){ me.done(r); }); return me; } function hc_installGallery(){ if (document.readyState != "complete" && document.readyState == "interactive") { window.setTimeout(function(){ cloud.installGallery(); },20); return; } xg.installMedia(); var all = xg.q(".apps-gallery-object"); cloud._galleryObjects = new Array(); this.changeImage = function(index,dir){ if (cloud._galleryScreen != null) { document.body.removeChild(cloud._galleryScreen); cloud._galleryScreen = null; } let img = cloud._galleryObjects[index+dir]; if (img) img.onclick(); } var me = this; var index = 0; for (let i=0;i 0){ o.style.backgroundImage = "url('"+_thumb+"')"; }else{ o.style.backgroundImage = "url('"+dsrc+"/thumb/')"; } var mute = xg.new(); mute.innerHTML = ''; o.appendChild(mute); mute.setAttribute("class","tso-volume mute"); mute._parent = o; var play = xg.new(); play.innerHTML = " "; play.setAttribute("class","tso-btn-play"); o.appendChild(play); play._parent = o; o._play = play; o._allowClick = true; var pp = xg.new(); var progress = xg.new(); pp.setAttribute("class","tso-play-progress"); pp.setAttribute("data-visible","false"); pp.appendChild(progress); o.appendChild(pp); pp._o = o; pp._video = v; this._pptimer = null; pp.onclick = function(evt){ var dvisible = this.getAttribute("data-visible"); if (dvisible == "true") dvisible = true; else dvisible = false; if (!dvisible) return; evt.stopPropagation(); let r = this.getBoundingClientRect(); let left = evt.clientX - r.x; let proc = (left*100)/r.width; let pos = (this._video.duration*proc)/100; this._video.setAttribute("data-start",pos); this._video.currentTime = pos; this._video.muted = false; this._video.play(); this._o._allowClick = false; let me = this; if (me._pptimer != null) window.clearTimeout(me._pptimer); me._pptimer = window.setTimeout(function(){ //me.style.display = "none"; me.style.opacity = 0; me.setAttribute("data-visible","false"); },5000); } var timer = xg.new(""); timer.setAttribute("class","tso-timer"); o.appendChild(timer); v._timer = timer; v._play = play; v._progress = progress; o._progress = progress; var err = xg.new("Video can't be played."); err.setAttribute("class","tso-player-error"); o.appendChild(err); v._err = err; v._mute = mute; var me = this; if (v != null){ //v.setAttribute("src",v.getAttribute("data-src")); v.setAttribute("muted","true"); v.setAttribute("loop","false"); v.load(); var autoplay = false; if (v.getAttribute("data-autoplay") == "true") autoplay = true; if (autoplay) v.oncanplaythrough = function() { v.play(); v.style.opacity = 1; } v.onerror = function(){ this._err.style.display = "block"; } v.addEventListener('play', (event) => { progressLoop(event); }); v.addEventListener('loadeddata', function(evt) { //console.debug(evt); // this.play(); // start playing }); } var cc = document.createElement("CANVAS"); cc.setAttribute("width",100); cc.setAttribute("height",100); cc.setAttribute("style","z-index:10000000000000000"); //var p = document.getElementById("canvas-sting"); o.appendChild(cc); v._canvas = cc, v._context = v._canvas. getContext ('2d'), v._centerX = v._canvas. width / 2, v._centerY = v._canvas. height / 2, v._rad = Math. PI * 2/100, v._speed = 0.5; v._radius = 25; v._radiusStep = 0.2; drawFrame(0,v); var videoCanvas = document.createElement("CANVAS"); var r = o.getBoundingClientRect(); videoCanvas.setAttribute("width",r.width); videoCanvas.setAttribute("height",r.height); videoCanvas.setAttribute("style","position:absolute;left:0px;top:0px;opacity:0;border-radius:10px;"); o.appendChild(videoCanvas); v._videoCanvas = videoCanvas; o._movertimer = null; o.onmouseover_ = function(){ var me = this; console.debug(this._movertimer); if (this._movertimer != null) return; this._movertimer = window.setTimeout(function(){ me._progress.parentNode.style.opacity = 1; me._progress.parentNode.setAttribute("data-visible","true"); },500); } o.onmouseout = function(){ this._movertimer = null; } o.ondblclick = function(evt){ evt.stopPropagation(); this._allowClick = false; evt.preventDefault = true; this._progress.parentNode.style.opacity = 1; this._progress.parentNode.setAttribute("data-visible","true"); } o.onclick = function(){ var me = this; window.setTimeout(function(){ console.debug(" >> " + me._allowClick); if (!me._allowClick) { //me._allowClick = true; window.setTimeout(function(){ me._allowClick = true; },300); return false; } const isVideoPlaying = video => !!(me._video.currentTime > 0 && !me._video.paused && !me._video.ended && me._video.readyState > 2); if (!isVideoPlaying()){ let sa = 0; let _ds = me._video.getAttribute("data-start"); if (_ds != null) sa = parseInt(_ds,10); me._video.currentTime = sa; me._video.play(); me._video.loop = false; me._video.muted = false; me._play.setAttribute("class","tso-btn-stop"); cloud.videoOnPlay(me._video); let rect = me.getBoundingClientRect(); if (me._video.videoWidth > rect.width+400) { me._video.setAttribute("style","object-fit:contain"); } }else{ me._video.pause(); me._video.setAttribute("data-start",me._video.currentTime); me._video.loop = false; me._video.muted = false; me._play.setAttribute("class","tso-btn-play"); } },300); } mute.onclick = function(evt){ evt.preventDefault = true; evt.stopPropagation(); this._parent._allowClick = false; if (this._parent._video.muted) this._parent._video.muted = false; else this._parent._video.muted = true; } } } function progressLoop(evt) { monitorVideoPlay(evt.srcElement); } function _seconds(d){ var min = Math.floor(d/60); var sec = d-min*60; if (min < 10) min = "0"+min; if (sec < 10) sec = "0"+sec; var str = min+":"+sec; return str; } function updateStream(video){ var ctx = video._videoCanvas.getContext("2d"); var p = video._parent; p.style.backgroundImage = "none"; let r = p.getBoundingClientRect(); video._videoCanvas.style.opacity = 1; video._videoCanvas.setAttribute("width",r.width); video._videoCanvas.setAttribute("height",r.height); var vwidth = video.videoWidth; var vheight = video.videoHeight; var proc = (r.height*100)/vheight; var neww = video._videoCanvas.width; var newh = vheight*proc/100; neww = vwidth*proc/100; newh = video._videoCanvas.height; if (neww < r.width) { neww = video._videoCanvas.width; newh = vheight*proc/100; } var dify = r.height/2-newh/2; var difx = r.width/2-neww/2; ctx.drawImage(video,difx,dify,neww,newh); } function monitorVideoPlay(video) { const isVideoPlaying = __video => !!(video.currentTime >= 0 && !video.paused && !video.ended); if (!isVideoPlaying()) { video._play.setAttribute("class","tso-btn-play"); drawFrame(0,video); video._timer.innerHTML = ""; return; } updateStream(video); //Start rendering var p = ((video.currentTime / video.duration) * 100); if (!video.muted){ video._mute.setAttribute("class","tso-volume"); }else{ video._mute.setAttribute("class","tso-volume mute"); } video._progress.style.width = p+"%"; window.requestAnimationFrame(function(){ drawFrame(p,video); }); var mm = Math.round(video.currentTime) + "s → "+Math.round(video.duration)+"s"; if (video.duration > 60) mm = _seconds(Math.round(video.currentTime))+" → "+_seconds(Math.round(video.duration)); video._timer.innerHTML = mm; var dvisible = video._progress.parentNode.getAttribute("data-visible"); if (dvisible == "true") dvisible = true; else dvisible = false; if (dvisible){ window.setTimeout(function(){ video._progress.parentNode.style.opacity = 0; video._progress.parentNode.setAttribute("data-visible","false"); },5000); } requestAnimationFrame(function(){ monitorVideoPlay(video); }); } function blueCircle(video,nn) { var context = video._context; var centerX = video._centerX; var centerY = video._centerY; context.save(); context.beginPath(); context.strokeStyle = "white"; context.lineWidth = 5; context.arc(centerX, centerY, video._radius, Math.PI, Math.PI + nn * video._rad, false); context.stroke(); context.restore(); } function whiteCircle(video) { var context = video._context; var centerX = video._centerX; var centerY = video._centerY; context.save(); context.beginPath(); context.strokeStyle = "rgba(255,255,255,0.2)"; context.lineWidth = 5; var x = Math.PI * 2; context.arc(centerX, centerY, video._radius, 0, x, false); context.stroke(); context.closePath(); context.restore(); /*video._radius=video._radius+video._radiusStep; if (video._radius > 25) video._radiusStep = -0.2; if (video._radius < 20) video._radiusStep = 0.2;*/ } // Animation cycle function drawFrame(speed,video) { speed = parseInt(speed); video._context.clearRect(0, 0, video._canvas.width, video._canvas.height); whiteCircle(video); blueCircle(video,speed); } function hc_selectImage(callback){ var width = 1000; var height = 700; if (width > xg.view().width) width = xg.view().width - 100; var dlg_show_pictures = new xgDialog(myServer+"/apps/procs/dialogfiles.html?type=gallery&token="+GenerateID(),width,height); dlg_show_pictures.skin="black"; dlg_show_pictures.create(null); dlg_show_pictures.show(); dlg_show_pictures.onclose = function(res){ if (res != null) callback(res); dlg_show_pictures.destroy(); } } function hc_selectFile(callback){ var width = 1000; var height = 700; if (width > xg.view().width) width = xg.view().width - 100; var dlg_show_pictures = new xgDialog(myServer+"/apps/procs/dialogfiles.html?type=files&token="+GenerateID(),width,height); dlg_show_pictures.skin="black"; dlg_show_pictures.create(null); dlg_show_pictures.show(); dlg_show_pictures.onclose = function(res){ if (res != null) callback(res); dlg_show_pictures.destroy(); } } function hc_editHTML(text,css,callback){ var w = xg.view().width-100; var h = xg.view().height-100; if (w > 500) w = 700; if (h > 500) h = 500; var dlg = new xgDialog("https://www.megatims.es/ca/xg/procs/_html.html?h="+encodeURIComponent(text)+"&css="+encodeURIComponent(css),w,h); dlg.skin = "white"; dlg.create(); dlg.show(); dlg.onclose = function(r){ dlg.destroy(); if (typeof(callback) != undefined) callback(r); } } function xgLocationInterface(){ this.getByPC = xgli_getByPC; } function xgli_getByPC(obj){ var pc = obj.value; if (pc.length<3) return; xg.xhr.post("https://www.megatims.es/ca/exp/location/bypc/?content=json&pc="+pc,function(resObj){ var res = JSON.parse(resObj); console.debug(res); xg.setValue("txt-geo-lat",""); xg.setValue("txt-geo-lng",""); xg.setValue("txt-geo-location",""); if (res.length == 1){ xg.setValue("txt-geo-lat",res[0].latitude); xg.setValue("txt-geo-lng",res[0].longitude); xg.setValue("txt-geo-location",res[0].city); } }); } function hc_deleteComment(cid){ var conf = confirm("Are you sure you want to delete this comment?"); if (!conf) return; xg.xhr.post("https://www.megatims.es/ca/ixp/deletecomment/?cid="+cid,function(resObj){ if (cloud.commentDeleted != null) cloud.commentDeleted(cid,resObj); });} function hc_addComment(aid,bid,f){ var text = xg.getValue("txta_comment").trim(); if (text.length == 0) { alert("You need to write something."); return; } text = encodeURIComponent(text); xg.xhr.post("https://www.megatims.es/ca/ixp/addcomment/?bid="+bid+"&pid="+aid+"&user=n/a&comment="+text,function(resObj){ if (typeof(f) != "undefined") f(resObj); else if (cloud.commentAdded != null) cloud.commentAdded(resObj); }); } function hi_call(phone){ xg.loading("calling "+phone+"..."); phone = replaceStr(phone," ", ""); window.open("tel:"+phone,"hiddenframe"); } function hi_sms(phone){ alert("sms to "+phone); } function hi_showImage(url,selectedURL){ var w = xg.view().width-100; var h = xg.view().height-100; if (w > 1200) w = 1200; var arr = new Array(); if (typeof(url)=="object") { arr = url; url = url[0]; }else{ if (typeof(selectedURL) == "undefined") selectedURL = url; } var dlg = new xgDialog("https://www.megatims.es/ca/xg/procs/_image.html?url="+encodeURIComponent(url),w,h); dlg.skin = "transparent"; dlg.create(); dlg.show(); dlg.onload = function(){ if (arr.length > 1){ var d1 = xg.obj("div_img_preview_big"); var d2 = xg.obj("div_img_preview_small"); d1.style.height = "85%"; d2.style.height = "15%"; d2.style.borderTop = "solid white 1px"; d2.style.marginTop = "10px"; d2.style.overflow = "auto"; for (var i=0;i"; html += "
"+name+"
"; div.innerHTML = html; div.onclick = function(){ cloud.changeImage = hi_changeImage(this.getAttribute("data-imgsrc")); } d2.appendChild(div); } }//arr length > 1 hi_changeImage(selectedURL); }//onload dlg.onclose = function(){ this.destroy(); } } function hi_changeImage(url){ var d1 = xg.obj("div_img_preview_big"); var d2 = xg.obj("div_img_preview_small"); d1.innerHTML = ""; d1.style.backgroundImage = "url(none)"; if (xg.util.isImage(url)){ d1.style.backgroundImage = "url('"+url+"')"; }else if (xg.util.isPDF(url)){ d1.innerHTML = ""; }else if (xg.util.isTextFile(url)){ url = "https://sandbox.telsso.de/u/2/"+url.substring(url.indexOf("/dan/")+4); xg.xhr.get(url,function(txt){ txt = replaceStr(txt,"\n","
"); var html = "
"+txt+"
"; d1.innerHTML = html; }); } var divs = d2.getElementsByTagName("DIV"); for (var i=0;i 50) startPoint = endPoint/2-50; if (endPoint > 360) { endPoint = 0; startPoint = 0; } obj.setAttribute("xg-endpoint",endPoint); obj.setAttribute("xg-startpoint",startPoint); var arc = describeArc(50,50,40,startPoint,endPoint); obj.setAttribute("d",arc); console.debug(endPoint); window.setTimeout(function(){ __rotatePath(id,timer); },timer); } function hv_playVideo(fileID,fileURL){ if (this.playing){ cloud.video.object.muted = false; return; } if (this.fileId != null && this.playing == false && cloud.video.object != null){ if (!cloud.video._canPlay) console.debug("I can't play this file yet"); try{ cloud.video.object.muted = true; var playPromise = cloud.video.object.play(); if (playPromise !== undefined) { playPromise.then(function() { // Automatic playback started! }).catch(function(error) { console.debug("error playing this file"); // Automatic playback failed. // Show a UI element to let the user manually start playback. }); } }catch(e){ alert(e); } var btnPlay = xg.obj("btn-play-"+this.fileId); if (btnPlay != null) btnPlay.style.display = "none"; var btnPause = xg.obj("btn-pause-"+this.fileId); if (btnPause != null) btnPause.style.display = "block"; cloud.video.object.currentTime = cloud.video.startFrom; cloud.video.changeButtons(); cloud.video.playing = true; cloud.video._monitor(); return; } this.fileId = fileID; var btn = xg.obj("movie_playbtn_"+fileID); if (btn != null) btn.className = "pause_button"; var cont = xg.obj("movie_playcontainer_"+fileID); if (cont != null) cont.style.display = "none"; xg.addEvent("pageunload","cloud.video.pageUnload()"); xg.xhr.xss("https://media.telsso.cloud/d/info/?id="+fileID,function(resObj){ var res = xg.xhr.parse(resObj); var url = "https"+res.url; if (typeof(fileURL) != "undefined") url = fileURL; cloud.video.duration = res.duration; if (cloud.video.object != null){ try{ var parent = cloud.video.object.parentNode; parent.removeChild(cloud.video.object); }catch(e){ console.log(e); } } cloud.video.thumb = url+"thumb/"; cloud.video.object = document.createElement("video"); var parent = xg.obj("movie_container_"+fileID); if (parent == null){ console.error("Unable to find the parent for this video container"); console.error("Object with movie_container_"+fileID+" was not found"); return; } cloud.video.thumb = parent.getAttribute("data-thumb"); var autoPlay = parent.getAttribute("data-autoplay"); console.debug("player should auto play :"+autoPlay); parent.innerHTML = ""; parent.style.position ="relative"; cloud.video.object.setAttribute("style","position:absolute;left:0px;top:0px;background-color:black;"); parent.appendChild(cloud.video.object); cloud.video.object.style.width = parseInt(parent.offsetWidth,10)+"px"; cloud.video.object.style.height = parseInt(parent.offsetHeight,10)+"px"; cloud.video.object.src = url; var autoPlay = false; var playPromise = cloud.video.object.play(); if (playPromise !== undefined) { playPromise.then(function() { // Automatic playback started! }).catch(function(error) { cloud.video.object.muted = true; autoPlay = true; }); } var btnPlay = xg.obj("btn-play-"+fileID); if (btnPlay != null) btnPlay.style.display = "none"; var btnPause = xg.obj("btn-pause-"+fileID); if (btnPause != null) btnPause.style.display = "block"; cloud.video.object.addEventListener("durationchange",function(evt){ cloud.video.duration = this.duration; cloud.video.playing = true; }); var div = document.createElement("DIV"); div.setAttribute("style","position:absolute;left:10px;top:10px;z-index:50000;color:white;font-size:10px;background-color:rgba(0,0,0,0.5);padding:2px;padding-left:5px;padding-right:5px;"); parent.appendChild(div); div.innerHTML = "..."; div.id = "video_info_"+fileID; var div = document.createElement("DIV"); div.className = "cloud-video-progress-bar"; div.setAttribute("style","position:absolute;left:0px;top:0px;width:1px;height:3px;background-color:rgba(255,255,255,0.2);"); div.innerHTML = " "; div.id = "video_pbar_"+fileID; parent.appendChild(div); cloud.video.changeButtons(); cloud.video.object.addEventListener("canplaythrough", function() { cloud.video._canPlay = true; cloud.video.duration = cloud.video.object.duration; if (autoPlay) { cloud.video.object.play(); window.setTimeout(function(){ //cloud.video.object.muted = false; },500) ; } cloud.video._monitor(); },false); cloud.video.object.addEventListener('ended', function () { cloud.video.stop(); }, false); cloud.video.object.addEventListener("error", function (e) { xg.setValue("video_info_"+fileID,"Unable to play this file."); cloud.video.playing = true; cloud.video.fileId = null; cloud.video.object = null; cloud.video.changeButtons(); cloud.video.playing = false; window.clearTimeout(cloud.video._monitorTimer); },false); cloud.video.object.addEventListener('progress', function (){ try{ var endBuf = this.buffered.end(0); var soFar = parseInt(((endBuf / cloud.video.duration) * 100)); var width = parseInt(cloud.video.object.style.width,10); var swidth = (width*soFar)/100; var bar = xg.obj("video_pbar_"+cloud.video.fileId); bar.style.width = swidth+"px"; if (soFar == 100) { window.setTimeout(function(){ bar.style.display = "none"; },1000); } }catch(e){ } }, false); }); } function hv_changebuttons(){ if (cloud.video.playing == false){ var btns = xg.q(".cloud-videoplay-button"); for (var i=0;i0){ if (hours<10) hours = "0"+hours; str += hours+":"; } if (minutes<10) minutes = "0"+minutes; str += minutes+":"; if (seconds<10) seconds = "0"+seconds; str += seconds; return str; } function himp_hidePlayer(){ var obj = cloud.music.playerObj; var parent = obj.parentNode; parent.removeChild(obj); cloud.music.playerObj = null; obj = null; cloud.music.fileId = null; parent = null; } function himp_stopMusic(stop){ if (typeof(stop) == "undefined") stop= false; window.clearTimeout(this._monitorTimer); try{ var obj = xg.obj("hl_mplayer_btn_play"); obj.className = "play_button"; }catch(e){} this.audio.pause(); if (stop){ this.audio.currentTime = 0; var waveform = xg.obj("waveform_"+cloud.music.fileId); if (waveform != null) waveform.style.left = "50%"; var played = xg.obj("hplayer_played"); var sbar = xg.obj("hplayer_statusbar"); if (sbar != null) sbar.style.width = "0px"; if (played != null) played.innerHTML = cloud._calculateTime(cloud.music.audio.currentTime) + " / "+cloud._calculateTime(cloud.music.duration); var fileContainer = xg.obj("music_file_container_"+cloud.music.fileId); if (fileContainer != null && fileContainer.className.indexOf("_on")==-1) fileContainer.style.backgroundColor = ""; //window.setTimeout("cloud.music.hidePlayer()",500); } this.changeButtons(); this.playing = false; } function himp_gotoPage(){ if (this.musicPage != null){ hl_openURL(this.musicPage); } } function himp_setArtwork(){ cloud.music.artwork = cloud.music.url+"/artwork/"; var awo = xg.obj("hl_mplayer_artwork"); if (awo == null){ window.setTimeout("cloud.music.setArtwork()",200); return; } awo.style.display = "block"; awo.style.backgroundImage = "url('"+cloud.music.artwork+"')"; } function himp_clearArtwork(){ var awo = xg.obj("hl_mplayer_artwork"); if (awo != null){ awo.style.backgroundImage = "none"; awo.style.display = "none"; } } function himp_createPlayer(){ xg.xhr.get("https://www.megatims.es/ca/scripts/soundplayer-small.sc",function(resObj){ var newObj = document.createElement("DIV"); newObj.innerHTML = resObj.trim(); newObj.style.zIndex = 9000; newObj.className = cloud.music.containerClassName; if (cloud.isTablet){ newObj.style.position="fixed"; //newObj.style.left = "0px"; //newObj.style.top = "0px"; } document.body.appendChild(newObj); cloud.music.playerObj = newObj; }); } function himp_destroyPlayer(){ try{ var parent = cloud.music.playerObj.parentNode; parent.removeChild(cloud.music.playerObj); cloud.music.playerObj = null; }catch(e){ console.log(e); } } function himp_jumpTo(obj){ var x = xg.event.currentX; var left = xg.util.getLeft(obj); var dpos = x-left; var width = xg.obj("hplayer_fullbar").offsetWidth; var myTime = (cloud.music.duration*dpos)/width; cloud.music.audio.currentTime = myTime; } function himp_playMusic(fileId,startFrom){ //startFrom = 30; //this.musicPage = window.location.href; if (this.fileId == fileId){ cloud.music.changeButtons(); cloud.music.playing = true; cloud.music.audio.play(); cloud.music.audio.addEventListener("canplaythrough", function () { cloud.music.playing = true; if (typeof(startFrom) != "undefined"){ this.currentTime = startFrom; } }, false); cloud.music._monitor(); return; } cloud.music.playing = false; this.lastFileId = this.fileId; if (this.fileId != null && this.fileId != fileId){ var fileContainer = xg.obj("music_file_container_"+cloud.music.fileId); if (fileContainer != null && fileContainer.className.indexOf("_on")==-1) fileContainer.style.backgroundColor = ""; var small = xg.obj("playbtn1_"+this.fileId); if (small != null) small.className = "play_button"; } this.fileId = fileId; if (cloud.music.playerObj == null){ cloud.music.createPlayer(); } xg.xhr.xss("https://music.telsso.de/d/info/?id="+fileId,function(resObj){ var res = xg.xhr.parse(resObj); cloud.music.fileName = res.filename; cloud.music.url = "https"+res.url; if (res.artwork.length>0){ cloud.music.setArtwork(); }else{ cloud.music.clearArtwork(); } var duration = res.duration; cloud.music.duration = duration; cloud.music.audio.addEventListener("durationchange",function(evt){ //cloud.music.duration = this.duration; }); cloud.music.audio.addEventListener('loadedmetadata', getMetadata,false); cloud.music.audio.addEventListener("canplaythrough", function () { cloud.music.playing = true; if (typeof(startFrom) != "undefined"){ this.currentTime = startFrom; } }, false); cloud.music.audio.addEventListener('ended', function () { cloud.music.stop(true); cloud.music.destroyPlayer(); }, false); cloud.music.audio.addEventListener("error",function(e){ var ctime = parseInt(cloud.music.audio.currentTime,10); if (ctime>2) ctime = ctime-2; //cloud.music.stop(); cloud.music.play(cloud.music.fileId,ctime); }, false); cloud.music.audio.addEventListener('progress', function (){ try{ var endBuf = this.buffered.end(0); var soFar = parseInt(((endBuf / cloud.music.duration) * 100)); var swidth = (300*soFar)/100; var sbar = xg.obj("hplayer_loadbar"); if (sbar != null) sbar.style.width = swidth + "px"; }catch(e){ } }, false); if (cloud.music.audio.src != cloud.music.url){ cloud.music.audio.src = cloud.music.url; cloud.music.audio.load(); } cloud.music.audio.play(); cloud.music._monitorTimer = cloud.music._monitor(); cloud.music.changeButtons(); var obj = xg.obj("hl_mplayer_btn_play"); if (obj != null) obj.className = "pause_button"; }); } function getMetadata(m) { channels = cloud.music.audio.Channels; rate = cloud.music.audio.SampleRate; fbLength = cloud.music.audio.FrameBufferLength; duration = fbLength / (channels * rate); var display = xg.obj("xx_display"); cloud.music.playing = true; // TODO !!!! xg.xhr.get("https://www.megatims.es/ca/ixp/social/played/?fid="+cloud.music.fileId+"&owner=-1&visitor=n/a",function(resObj){}); } function himp__monitorMP(){ var fname = xg.obj("hplayer_filename"); var played = xg.obj("hplayer_played"); var sbar = xg.obj("hplayer_statusbar"); var fullBar = xg.obj("hplayer_fullbar"); var wstats = xg.obj("waveform_stats_"+this.fileId); var wavebar = xg.obj("waveform_div_"+cloud.music.fileId); var _width = -1; if (wavebar != null) _width = parseInt(wavebar.offsetWidth,10); var waveform = xg.obj("waveform_"+cloud.music.fileId); var fileContainer = xg.obj("music_file_container_"+cloud.music.fileId); if (fileContainer != null && fileContainer.className.indexOf("_on")==-1){ fileContainer.style.backgroundColor = "#cdf2c9"; } var barWidth = fullBar.offsetWidth; var proc = (cloud.music.audio.currentTime*100) / cloud.music.duration; var swidth = (barWidth*proc)/100; if (wavebar != null){ var wwave = _width/2-(parseInt(waveform.width,10)*proc)/100; waveform.style.left = wwave + "px"; } if (played != null) { if (cloud.music.playing){ //buttons var big = xg.obj("playbtn2_"+this.fileId); cloud.music.changeButtons(); if (fname != null) fname.innerHTML = this.fileName; var stats = cloud._calculateTime(cloud.music.audio.currentTime) + " / "+cloud._calculateTime(cloud.music.duration); if (played != null) played.innerHTML = stats; if (wstats!=null) wstats.innerHTML = stats; }else{ if (fname != null)fname.innerHTML = "..."; if (played != null) played.innerHTML = "-"; } } if (sbar != null) { sbar.style.width = swidth+"px"; } this._monitorTimer = window.setTimeout("cloud.music._monitor()",1); } checkForPluginsFeedback(); function checkForPluginsFeedback(){ var url = window.location.href.toString(); if (url.indexOf("&post_id=")>-1 || url.indexOf("?post_id=")>-1){ var myURL = "" ; if (url.indexOf("&post_id=")>-1) myURL = url.substring(0,url.indexOf("&post_id=")); if (url.indexOf("?post_id=")>-1) myURL = url.substring(0,url.indexOf("?post_id=")); window.open(myURL,"_top"); } } function hi_publishSocial(socialNetwork,id,owner,visitorId,resourceType,pattern,url){ if (typeof(url) == "undefined") url = window.location.href.toString(); /*if (socialNetwork == "fb"){ xg.loading("Contacting Facebook ..."); window.setTimeout("window.open('https://www.facebook.com/dialog/feed?app_id="+cloud._facebookAppId+"&link="+url+"&redirect_uri="+url+"','_self')","600"); }else if (socialNetwork == "twitter"){ window.open("http://twitter.com/home?status=Currentlyreading "+url,"_top"); }else if (socialNetwork == "pinterest"){ xg.loading("Contacting Pinterest ..."); //var imgURL= xg.obj("image_"+id).src; //var desc = "lala"; //var url = "http://pinterest.com/pin/create/bookmarklet/?media="+imgURL+"&url="+url+"&description="+desc+"&&is_video=false"+"&title="; // window.open(url,"_blank"); }*/ if (socialNetwork == "fb"){ xg.loading("Contacting Facebook ..."); if (visitorId == "n/a"){ cloud.requestFBLogin(); return; } if (""=="false"){ tryActivateFacebook(); }else{ xg.xhr.post("https://www.megatims.es/ca/ixp/social/share/?fid="+id+"&owner="+owner+"&visitor="+visitorId+"&resource="+resourceType+"&network=fb&url="+url+"&pattern="+pattern,function(resObj){ var res = xg.xhr.parse(resObj); var html = decodeURIComponent(res.html); if (html.indexOf("`")>-1) html = replaceStr(html,"`","'"); var box = xg.obj("sharebox_"+id); if (box != null){ box.innerHTML = html; } window.setTimeout("xg.hide()",500); }); } } } function tryActivateFacebook(){ var url = window.location.href.toString(); url = replaceStr(url,"#","!hash!"); xg.loading("Contacting Facebook ..."); window.setTimeout('window.open("https://accounts.telsso.cloud/api/facebook/login/?redirect='+url+'","_top")',500); } function hi_addHeelooUser(hid){ var dlg= new xgDialog(myServer+"/scripts/adduser.sc?user="+hid,600,270); dlg.hideClose = true; dlg.setBorder(0); dlg.skin = "white"; dlg.create(null); dlg.show(); dlg.onclose = function(){ if (this.returnValue != null){ if (this.returnValue == "refresh"){ window.location.reload(); } dlg.destroy(); } } } function hi_addCloudUserRequest(hid,obj){ let url = "https://www.megatims.es/ca/ixp/users/addrequest/?user="+hid; console.debug(url); xg.xhr.post(url, function(resObj){ console.debug(resObj); }); } function hi_setUserAccess(av,opid){ var _myrow = document.getElementById("rqst_row_"+opid); _myrow.style.display = "none"; xg.xhr.post("https://www.megatims.es/ca/ixp/resolverequest/?rid="+opid+"&val="+av, function(resObj){ }); } function hi_saveSetting(key,value){ xg.xhr.get("https://www.megatims.es/ca/ixp/settings/set/?op="+encodeURIComponent(key)+"&val="+encodeURIComponent(value),function(resObj){}); } function hi_addLike(value,fid,owner_id,visitor_id,resource,pattern){ if (visitor_id == "n/a"){ cloud.requestLogin(); return; } var url = "https://www.megatims.es/ca/ixp/social/like/?resource="+resource+"&fid="+fid+"&owner="+owner_id+"&visitor="+visitor_id+"&value="+encodeURIComponent(value); if (typeof(pattern) != "undefined") url +="&pattern="+pattern; var obj = xg.obj("socialbox_"+fid); xg.xhr.post(url,function(resObj){ var res = xg.xhr.parse(resObj); var html = decodeURIComponent(res.html); if (html.indexOf("`")>-1) html = replaceStr(html,"`","'"); var box = xg.obj("socialbox_"+fid); box.innerHTML = html; }); } function hi_cancelLike(fid,owner_id,visitor_id,resource,pattern){ if (visitor_id == "n/a"){ cloud.requestLogin(); return; } var url = "https://www.megatims.es/ca/ixp/social/cancellike/?resource="+resource+"&fid="+fid+"&owner="+owner_id+"&visitor="+visitor_id; if (typeof(pattern) != "undefined") url +="&pattern="+pattern; var obj = xg.obj("socialbox_"+fid); xg.xhr.post(url,function(resObj){ var res = xg.xhr.parse(resObj); var html = decodeURIComponent(res.html); if (html.indexOf("`")>-1) html = replaceStr(html,"`","'"); var box = xg.obj("socialbox_"+fid); box.innerHTML = html; }); } function hi_requestFBLogin(){ var wloc = window.location.toString(); wloc = replaceStr(wloc,"/!#/","/!hash!/"); var url = "https://accounts.telsso.cloud/login/US/?.done="+wloc+"&token=7F743831949B97A055746BD79138E022"; var url2 = 'https://accounts.telsso.cloud/api/facebook/login/?job=login&redirect='+encodeURIComponent(url)+'&token=0'; window.setTimeout('window.open("https://www.megatims.es/ca/_proc/redirect/?url='+encodeURIComponent(url2)+'","_top")',100); } function hi_requestLogin(){ var wloc = window.location.toString(); wloc = replaceStr(wloc,"/!#/","/!hash!/"); var url = "https://accounts.telsso.cloud/login/US/?.done="+wloc+"&token=7F743831949B97A055746BD79138E022"; window.open("https://www.megatims.es/ca/_proc/redirect/?url="+encodeURIComponent(url),"_top"); } function hi_addToForm(formId,objType,name,value){ var form = xg.obj("form_"+formId); var o = document.createElement(objType); o.name = name; o.value = value; form.appendChild(o); } function hi_saveForm(formId,opId,doneFunc,failedFunc,shopId){ var form = xg.obj("form_"+formId); var isOk = xg.verifyForm(form); if (!isOk) { xg.showFormProblems(form); return; } var params = xg.getForm(form); var url = "https://www.megatims.es/ca/exp/dag/add/"+opId+"/?"+params; var allElements = form.getElementsByTagName("*"); var definition = ""; for (var i=0;i0){ var n = elem.name; definition = definition+n+","; } } url = url + "definition="+encodeURIComponent(definition); // search for upload forms .. and upload this forms with ajax whe is possible xg.createLS(form); console.debug(url); xg.xhr.post(url,function(resObj){ console.debug(resObj); var res = xg.xhr.parse(resObj); xg.removeLS(form); if (res.code == 1){ var ignoreDone = false; var uploadInput = form.getElementsByTagName("INPUT"); for (var i=0;i0){ cloud.uploadFile(input,formId,opId,res.record,form); xg.hide(0.1); ignoreDone = true; } } } if (!ignoreDone){ if (doneFunc == "_clear_form_"){ cloud.clearForm(form,"Message was successfully posted.
Thanks."); try{ form_onclose(formId); }catch(Exception){ } }else if (doneFunc.indexOf("(")>-1){ eval(doneFunc); }else{ eval(doneFunc+"()"); } } }else{ resObj = replaceStr(resObj,"\n",""); resObj = replaceStr(resObj,"\r",""); eval(failedFunc+"("+res.code+",'"+res.message+"','"+resObj+"')"); } }); } function hi_installUpload(){ alert("installing upload"); } function hi_uploadFile(input,formId,opId,record,form){ hx_handleFiles(input.files,formId,opId,record,form); } function hx_handleFiles(files,formId,opId,recordId,form) { console.debug("here"); var url = "https://www.megatims.es/ca/exp/uploadfile/?_type=form&formId="+formId+"&recordId="+recordId+"&token=7F743831949B97A055746BD79138E022"; var count = files.length; var formData = new FormData(); for (i=0; iThanks."); }, false); xhr.send(formData); } function hi_clearForm(obj,message){ console.debug(obj); xg.createLS(obj,message); var ae = obj.getElementsByTagName("*"); for (var i=0;i-1){ eval(doneFunc); }else{ eval(doneFunc+"()"); } }else{ eval(failedFunc+"("+res.code+",'"+res.message+"')"); } }); } function hi_loginForm(formId,opId,doneFunc,failedFunc){ var form = xg.obj("form_"+formId); var isOk = xg.verifyForm(form); if (!isOk) { xg.showFormProblems(form); return; } var params = xg.getForm(form); xg.createLS(form); var url = "https://www.megatims.es/ca/exp/dag/login/"+opId+"/?"+params; xg.xhr.post(url,function(resObj){ var res = xg.xhr.parse(resObj); xg.removeLS(form); if (res.code == 1){ if (doneFunc.indexOf("(")>-1){ eval(doneFunc); }else{ eval(doneFunc+"()"); } }else{ eval(failedFunc+"("+res.code+",'"+res.message+"')"); } }); } function hi_modForm(rowId,formId,opId,doneFunc,failedFunc){ var form = xg.obj("form_"+formId); var isOk = xg.verifyForm(form); if (!isOk) { xg.showFormProblems(form); return; } var params = xg.getForm(form); xg.createLS(form); var url = "https://www.megatims.es/ca/exp/dag/modify/"+opId+"/?w$hlo_id="+rowId+"&"+params; console.debug(url); xg.xhr.post(url,function(resObj){ var res = xg.xhr.parse(resObj); xg.removeLS(form); try{ if (res.code == 1){ eval(doneFunc+"()"); }else{ eval(failedFunc+"()"); } }catch(e){ } }); } function himp_requestFriendship(id){ this.addUser(id); } function hv_fullscreen(){ if (!cloud.video.playing) return; var parent = cloud.video.object; var docElm = document.documentElement; if (docElm.requestFullscreen) { parent.requestFullscreen(); } else if (docElm.mozRequestFullScreen) { parent.mozRequestFullScreen(); } else if (docElm.webkitRequestFullScreen) { parent.webkitRequestFullScreen(); } } try{ // Events document.addEventListener("fullscreenchange", function(e) { console.log("fullscreenchange event! ", e); }); document.addEventListener("mozfullscreenchange", function(e) { console.log("mozfullscreenchange event! ", e); }); document.addEventListener("webkitfullscreenchange", function(e) { console.log("webkitfullscreenchange event! ", e); }); }catch(e){ //IE will fail here } // Add different events for fullscreen function hi_createSocialPane(){ var pop = new xgPopup("white7"); pop.setContent("
"+hx_loading+"
"); pop.draw(); this._socialPanePopup = pop; } function hi_showSocialPane(obj,id,owner_id){ if (cloud._socialPaneTimer != null) window.clearTimeout(cloud._socialPaneTimer); obj.style.cursor = "pointer"; if(this._socialPanePopup == null) this.createSocialPane(); var left = xg.util.getLeft(obj)-45; var ubox = xg.obj("div_social_usersbox"); var hh = ubox.parentNode.offsetHeight; var top = xg.util.getTop(obj)-xg.getScrollTop()-30-hh; xg.xhr.get("https://www.megatims.es/ca/exp/social/get/?type=html&id="+id+"&owner="+owner_id,function(resObj){ var html = resObj.trim(); if (html.length == 0) return; ubox.innerHTML = html; var newH = ubox.offsetHeight+20; ubox.offsetParent.style.height = newH+"px"; top = xg.util.getTop(obj)-xg.getScrollTop()-30-newH; cloud._socialPanePopup.show(left,top); cloud._socialPaneTimer = window.setTimeout("_hiHideSocialPane()",30*1000); }); } function hi_hideSocialPane(){ if (cloud._socialPaneTimer != null) window.clearTimeout(cloud._socialPaneTimer); cloud._socialPaneTimer = window.setTimeout("_hiHideSocialPane()",1000); } function _hiHideSocialPane(){ cloud._socialPanePopup.hide(); var ubox = xg.obj("div_social_usersbox"); ubox.innerHTML = hx_loading; } function hi_addToContacts(objId,tag){ var value = xg.obj(objId).value.trim(); if (value.length = 0) { alert("Please enter an e-mail address."); return; } xg.loading("You were succesfully added to this newsletter."); xg.xhr.get("https://www.megatims.es/ca/exp/contacts/add/?email="+encodeURIComponent(value)+"&tag="+encodeURIComponent(tag),function(resObj){ }); } function hi_addToNewsLetter(objId,nid){ var value = xg.obj(objId).value.trim(); if (value.length = 0) { alert("Please enter an e-mail address."); return; } xg.loading("You were succesfully added to this newsletter."); xg.xhr.get("https://www.megatims.es/ca/exp/newsletter/add/?id="+nid+"&email="+encodeURIComponent(value),function(resObj){ xg.setValue(objId,""); try{ form_newsletterAdded(nid); }catch(e){} xg.hide(0.2); }); } function hi_pushLocation(url){ try{ window.history.pushState('secondary_page', "titlex", "/"+url); }catch(e){ alert(e); } } function hi_onAddToCart(res){ console.debug("to rewrite cloud.onAddToCart"); } function hi_onBeforeAddToCart(){ return 1; } function hi_onRemoveFromCart(res){ console.debug("to rewrite cloud.onRemoveFromCart"); } function hi_getCart(shopId,visitor,callback){ var vid = xg.storage.get("cart-visitor-id"); if (vid != null && visitor == "n/a") visitor = vid; let cartId = GenerateID(); try{ cartId = xg.storage.get("cart-id").trim(); }catch(e){ } var url = "https://www.megatims.es/exp/cart/get/?content=text&shop="+encodeURIComponent(shopId)+"&visitor="+encodeURIComponent(visitor)+"&cartid="+cartId; xg.xhr.post(url,function(r){ callback(r); }); } function hi_addToCart(productId,quantity,price,props){ productId = encodeURIComponent(productId); if (typeof(quantity) == "undefined") quantity = 1; let cartId = xg.storage.get("cart-id"); if (cartId == null || cartId == "null" || cartId.length == 0) cartId = GenerateID(); else cartId = cartId.trim(); var url = "https://www.megatims.es/exp/cart/add/?content=text&pid="+productId+"&qt="+quantity+"&cartid="+cartId; // if (cartId != null && cartId.length > 0) url = url+"&cartid="+encodeURIComponent(cartId); var ronbat = cloud.onBeforeAddToCart(); if (ronbat == -1) return; var startt = new Date().getTime(); xg.xhr.post(url,function(resObj){ let json = JSON.parse(resObj); let visitorId = json["summary"]["visitor"]; xg.storage.set("cart-visitor-id",visitorId); xg.storage.set("cart-id",json["summary"]["cartid"]); xg.storage.set("cart-shop",json["summary"]["shop"]); xg.storage.set("cart-total",json["summary"]["pricevat"]); xg.storage.set("cart-currency",json["summary"]["currency"]); xg.storage.set("cart-shop-name",json["summary"]["shopname"]); try{ cloud.onAddToCart(resObj); }catch(e){ console.debug(e); } var endt = new Date().getTime(); var durationt = endt-startt; console.debug("added in "+durationt); }); } function hi_redoCartObject(){ var co = xg.obj("cart-object"); if (co != null){ var total = xg.storage.get("cart.total"); if (total == null || parseInt(total,10) == 0){ co.style.display = "none"; }else{ xg.setValue("cart-total","€" + total); var quantity = xg.storage.get("cart.items"); xg.setValue("cart-value",quantity); co.style.display = "block"; } } } function hi_cartHas(id){ var list = xg.storage.get("cart.list"); if (list == null) return false; var items = JSON.parse(list); for (var i=0;i 0){ var pv = p.split("="); json[pv[0]] = pv[1]; } } customer = json; } var conf = confirm("Are you sure you want to send this order?"); if (!conf) return; try{ if (typeof(cart_onBeforeExecute) != "undefined"){ var r = cart_onBeforeExecute(); if (r == -1) return; } }catch(E){ console.debug(E); } var url = "https://www.megatims.es/exp/cart/execute/?shopId="+shopId+"&cartId="+cartId+"&payment="+payment+"&customer="+encodeURIComponent(JSON.stringify(customer))+"&delivered="+delivered; console.debug("executing cart "+url); xg.xhr.post(url,function(resObj){ console.debug("resObj is "); console.debug(resObj); xg.storage.delete("cart-id"); var res = xg.xhr.parse(resObj); try{ cart_onExecute(cartId,res); }catch(Exception){ } }); } function hi_getCategoryNewFormula(appType,obj,appId){ var value = obj.value; var url = ""; if (appType == "shop"){ url = "https://www.megatims.es/ca/ixp/shop/getvatformula/?type=category&value="+value+"&shopId="+appId; } xg.xhr.post(url,function(resObj){ var res = xg.xhr.parse(resObj); if (res.code == 1){ var target = res.target; var formula = res.formula; target = target.substring(1,target.length-1); var objects = document.getElementsByName(target); for (var i=0;i0){ _discount = parseFloat(this.cartDiscount); _discount = _discount/100; } let cart = JSON.parse(strCart); let total = 0; for (var i=0;i0) temp.add(item); }else{ temp.add(item); } } cart.items = temp; xg.storage.set(cartKey,JSON.stringify(cart)); this.calculateTotal(cartId); this.afterRemove(xg.storage.get(cartKey),cartId,itemId); } function ccart_add(cartId,itemId,price,qt,cdate,cancelEvent){ if (typeof(cancelEvent) == "undefined") cancelEvent = false; if (typeof(qt)=="undefined") qt = 1; if (typeof(cdate)== "undefined") cdate = new Date(); var cart = {}; var cartKey = "cart-object-"+cartId; var strCart = xg.storage.get(cartKey); if (strCart != null && strCart.length > 0){ cart = JSON.parse(strCart); }else{ cart.items = new Array(); cart.total = 0; cart.discountTotal = 0; cart.discount = 0; cart.date = cdate; } let contains = false; for (let i=0;i"; if (!hideH) html += "
"+str+"
"; for (var j=1;j<=4;j++){ var minutes = j*15; minutes = xg.util.formatDouble(minutes); if (j < 4) html += "
:"+minutes+" 
"; } html += ""; } parent.innerHTML = html; } function cci_listEvents(objId,weekNo){ var hcalendar = new xgCalendar(); try{ if (typeof(weekNo) == "undefined") weekNo = hcalendar.getWeek(); }catch(e){ console.log(hcalendar); console.log(hcalendar.getWeek); return; } this.weekNo = weekNo; var cms = xg.obj(objId); this._topPos = new Array(); cms.innerHTML = ""; var hdr = document.createElement("DIV"); hdr.setAttribute("style","position:absolute;background-color:white;left:0px;top:0px;z-index:500;padding-top:0px;overflow:hidden;width:100%;"); hdr.id = "calendar_weeks_hdr"; cms.appendChild(hdr); cms.style.paddingTop = "50px"; var div = ""; var _myDate = hcalendar.getJsDate(); var curr = firstDayOfWeek (hcalendar.year, weekNo); hcalendar.setDate(curr); var first = curr.getDate() - curr.getDay()+1; // First day is the day of the month - the day of the week var firstDay = new Date(curr.setDate(first)); var left = 0; div = document.createElement("DIV"); div.className = "calendar_week_events first"; hdr.appendChild(div); div.innerHTML = " "; div.style.width = "5%"; var maxDays = 5; var maxWidth = "18%"; if (this.drawWeekend){ maxDays = 7; maxWidth = "15%"; } for (var i=0;i0) hideH = true; if (i>=5) _width = "10%"; div.style.width = _width; div.style.textAlign = "center"; var next = first + i; // last day is the first day + 6 var maxDaysInMonth = new Date(curr.getYear(), curr.getMonth() + 1, 0).getDate(); var month = curr.getMonth(); if (next > maxDaysInMonth) { month = month+1; next = next-maxDaysInMonth; } var nextDay = new Date(); nextDay.setDate(next); nextDay.setMonth(month); var nextDayStr = xg.util.formatDate(nextDay,"n/a"); div.innerHTML = hcalendar.dayName_long[i] + "
"+nextDayStr; div.id="week_day_"+next; } var curr = new Date(hcalendar.year,hcalendar.month-1,hcalendar.day,0,00,00,0); // get current date div = document.createElement("DIV"); div.className = "calendar_ruller"; cms.appendChild(div); this.drawRuller(div); div.style.width = "5%"; for (var i=0;i0) hideH = true; hideH = true; if (i>=5) _width = "10%"; div.style.width = _width; div.style.position = "relative"; var next = first + i; var maxDaysInMonth = new Date(curr.getYear(), curr.getMonth() + 1, 0).getDate(); var month = curr.getMonth(); if (next > maxDaysInMonth) { month = month+1; next = next-maxDaysInMonth; } var nextDay = new Date(); nextDay.setDate(next); nextDay.setMonth(month); var thisDay = nextDay.getDate(); var id = "calendar_week_"+thisDay; div.setAttribute("xg-day",thisDay); div.setAttribute("xg-date",nextDay); div.id = id; this.drawDayHours(thisDay,div,hideH,nextDay); this.listEventsByDay(nextDay,xg.obj("calendar_week_"+thisDay),true); var currentDate = new Date().getDate(); if (thisDay <= currentDate){ var currentTime = new Date().getHours(); var currentMinutes = new Date().getMinutes(); if (thisDay< currentDate){ currentTime = "24"; } var timeDiv = xg.obj("calendar_day_"+thisDay+"_"+currentTime); var pastSurface = document.createElement("DIV"); if (timeDiv != null){ var _top = xg.util.getTop(timeDiv)-xg.util.getTop(cms)-50; pastSurface.className ="calendar_day_pasttime"; pastSurface.style.position = "absolute"; xg.obj("calendar_week_"+thisDay).appendChild(pastSurface); var height = (currentMinutes*100)/60; pastSurface.style.top = _top+"px"; pastSurface.style.height = height+"px"; pastSurface.id = "PS"+GenerateID(); //console.log(pastSurface.id); } } } //this.updateStrings(); hcalendar.setDate(_myDate); cms.scrollTop = 0; cms.style.overflow = "auto"; //this.selectCurrentDayInWeek(); var currentTime = new Date().getHours(); var minutes = new Date().getMinutes(); try{ // win_onresize(); }catch(e) { window.setTimeout(function () { // win_onresize(); }, 20); } return this; } function hcal_drawDayHours(dayNo,cms,hideH,dayStr){ if (typeof(hideH) == "undefined") hideH = false; var html = ""; for (var i=this.startHours;i<=this.endHours;i++){ var str = ""; if (i == 12) str ="12:00"; else str = xg.util.formatDouble(i)+""; //else str = (i-12)+" PM"; html +="
"; if (!hideH) html += "
"+str+"
"; else html += "
"+str+"
"; for (var j=1;j<=4;j++){ var minutes = j*15; minutes = xg.util.formatDouble(minutes); if (!hideH) { if (j < 4) html += "
:"+minutes+" 
"; } else html += "
 
"; } html += "
"; } cms.innerHTML = html; cms.style.overflow = "auto"; } function hcal_listEventsByDay(dayDate,cms,skipDrawHours){ var hcalendar = new xgCalendar(); var dayNo = null; var month = hcalendar.monthStr; if (typeof(skipDrawHours) == "undefined") skipDrawHours = false; if (typeof(dayDate) == "undefined") { dayNo = hcalendar.dayStr; }else{ dayNo = dayDate.getDate(); month = dayDate.getMonth()+1; } if (typeof(cms) == "undefined") cms = xg.obj("cal_main_surface"); var originalCms = cms; if (cms.id == "cal_main_surface"){ cms.innerHTML = ""; cms.style.overflow = "auto"; var div = document.createElement("DIV"); div.setAttribute("style", "position:relative;width:60%;float:left;margin:20px;"); cms.appendChild(div); var second = document.createElement("DIV"); second.setAttribute("style","position:fixed;float:left;right:30px;top:150px;width:30%;overflow:hidden"); cms.appendChild(second); second.innerHTML = "…"; second.id = "div-today-second"; cms = div; } var curr = new Date(hcalendar.year,hcalendar.month-1,hcalendar.day,0,00,00,0); // get current date if (!skipDrawHours) this.drawDayHours(dayNo,cms,false,curr); var obj = {}; obj.done = function(){ } var url = "https://www.megatims.es/ca/exp/calendar/event/list/?type=day&day="+dayNo+"&month="+month+"&year="+hcalendar.yearStr+"&calendars="+this.id; xg.xhr.post(url,function(resObj){ var parser = new XMLParser(); parser.parse(resObj); var doc = parser.doc; var root = doc.getDocumentElement(); this.dayEvents = new Array(); for (var i=0;i0) event.multipleDays = true; } if (this.dayEvents == null) return; for (var i=0;i 1) { var size = events.length; var unitWidth = parseInt(width / size, 10); var left = 0; var lk = 0; for (var k = 0; k < events.length; k++) { var oevent = events[k]; var odate = xg.util.getSQLDate(oevent.startDate); var id = "div_" + oevent.id + "_" + odate.day + "_" + odate.month + "_" + odate.year + "_" + odate.hours + "_" + odate.minutes; var overlapped = xg.obj(id); left = indent + lk * (unitWidth); var top = xg.util.getTop(overlapped); overlapped.style.left = left + "px"; overlapped.setAttribute("_moved", "true"); overlapped.setAttribute("data-factor", size); if (typeof(overlapped._children) == "undefined") { overlapped._children = new Array(); } overlapped._children.add(obj); lk++; if (size > maxColumns) maxColumns = size; overlapped.style.width = (unitWidth - 5) + "px"; } } else { var dleft = 5 + indent; obj.setAttribute("data-factor", "1"); width = parentWidth - dleft; obj.style.left = dleft + "px"; obj.style.width = (width) + "px"; /*if (obj.style.position == "fixed") { dleft = dleft+xg.util.getLeft(cms)+indent; obj.style.left = dleft+"px"; }else{ obj.style.width = "95%"; }*/ } }//multiple days } maxColumns = 0; for (var i=0;i maxColumns) maxColumns = events.length; event._obj._factor = events.length; event._obj._nearEvents = events; } var columnWidth = parseInt((parentWidth-indent)/maxColumns,10); var all = xg.q("[data-factor]"); for (var i=0;i 0) { var child = obj._nearEvents[k - 1]._obj; var r = child.getBoundingClientRect(); _left = r.left + r.width - parentRect.left; obj.style.left = (_left) + "px"; } else { obj.style.left = indent + "px"; if (this.view == 2) obj.style.left = "0px"; } parent.style.overflow = "hidden"; var w = (parentRect.width - indent) / (obj._factor); w = (parentRect.width) / (obj._factor); obj.style.width = w + "px"; obj._left = _left; obj.onmouseover = function () { } obj.onmouseout = function () { } }//if not multipledays } //win_onresize(); } function hcalu_rotateText(div){ var textNode =div.getElementsByTagName("DIV")[0]; var text = textNode.innerHTML; text = ""+div.getAttribute("event_title")+", "+div.getAttribute("event_location") + " // "+div.getAttribute("event_duration"); textNode.innerHTML = text; textNode.setAttribute("style",textNode.getAttribute("style")+";overflow:visible;-moz-transform: rotate(90deg);white-space:nowrap"); } function hcal_getObjectsFromPosition(myObjects,obj){ var insides = new Array(); var left = parseInt(obj.style.left,10); var top = parseInt(obj.style.top,10); var endW = parseInt(obj.style.width,10)+left; var endH = parseInt(obj.style.height,10)+top; for (var i=0;i endH){ insides.add(div); } } } return insides; } function hcal_drawDayEvent(event,cms,dayNo){ var startDate = xg.util.getSQLDate(event.startDate).jsDate; var endDate = xg.util.getSQLDate(event.endDate).jsDate; var diffMs = (endDate - startDate); // milliseconds between now & Christmas var diffDays = Math.floor(diffMs / 86400000); // days var diffHrs = Math.floor((diffMs % 86400000) / 3600000); // hours var diffMins = Math.round(((diffMs % 86400000) % 3600000) / 60000); // minutes var startDay = xg.util.getSQLDate(event.startDate).day; var endDay = xg.util.getSQLDate(event.endDate).day; var startObj = xg.util.getSQLDate(event.startDate); var endObj = xg.util.getSQLDate(event.endDate); var startH = startObj.hours; if (startH < 10) startH = "0"+startH; var startM = startObj.minutes; if (startM < 10) startM = "0"+startM; var endH = endObj.hours; if (endH < 10) endH = "0"+endH; var endM = endObj.minutes; if (endM < 10) endM = "0"+endM; var startStr = startH+":"+startM; var durationStr = startH+":"+startM + " - "+endH+":"+endM; if (startH < cloud.calendar.startHours) startH = cloud.calendar.startHours; var parentId = "calendar_day_"+dayNo+"_"+parseInt(startH); var parent = xg.obj(parentId); var div = document.createElement("DIV"); div.setAttribute("event_title",event.title); div.setAttribute("event_location",event.location); div.setAttribute("event_duration",durationStr); div.setAttribute("event_id",event.id); var cdate = xg.util.getSQLDate(event.startDate); div.id = "div_"+event.id+"_"+cdate.day+"_"+cdate.month+"_"+cdate.year+"_"+cdate.hours+"_"+cdate.minutes; var diffStr = ""; //diffHrs+" hours and "+diffMins+" minutes"; if (diffHrs == 1) diffStr+=" 1 hour"; else if (diffHrs > 1) diffStr+= diffHrs+" hours"; if (diffMins > 0 && diffHrs > 0) diffStr+=" and "+diffMins+" minutes"; else if (diffMins>0 && diffHrs == 0) diffStr+= diffMins+" minutes"; var locationStr = ""; var _title = event.title; if (cloud.calendar.bookedText.length > 0) { _title = cloud.calendar.bookedText; } div.innerHTML = "
"+_title+ "
"+durationStr+" • "+diffStr+""+locationStr+"
"; div.className = "calendar_event calendar_acolor_"+event.color+" roundcorners"; if (startObj.jsDate < new Date()) { div.className = "calendar_event calendar_acolor_"+event.color+" roundcorners calendar_past"; } div.style.position = "absolute"; var mtop = startM/15*25; var mend = endM/15*25; var top = parseInt(startH-cloud.calendar.startHours,10)*100+mtop; div.style.top = top+"px"; var dayNo = xg.util.getSQLDate(event.startDate).jsDate.getDay(); var dleft = 0; if (dayNo == 1) { var hoursDiv = cms.childNodes[0].childNodes[0]; var dleft = parseInt(hoursDiv.offsetWidth,10)+10; } div.style.left = dleft+"px"; var endHH = parseInt(endH,10); if (endHH == 0 && startH > 0) endHH = 24; var height = endHH-parseInt(startH,10); height = diffHrs*100+diffMins/15*25; if (height < 30) height = 100; div.style.height = height+"px"; cms.appendChild(div); var currentDay = parseInt(cms.getAttribute("xg-day"),10); if (startDay != endDay){ height = 40; //cms.style.position = "relative"; div.style.position = "fixed"; var _top = 0; var contains = false; for (var h=0;h
"+locationStr+""; if (startDay == currentDay) { xg.addClassName(div,"multiple-days-start"); }else if (endDay == currentDay) { xg.addClassName(div,"multiple-days-end"); }else{ xg.addClassName(div,"multiple-days-middle"); } } div._eventId = event.id; div._eventOwner = event.owner; if (diffHrs>22 && diffHrs < 24) { div.style.position = "fixed !important"; div.style.bottom = "0px"; div.style.height = "auto !important"; } div.onclick = function(){ //cloud.calendar.showEvent(this._eventId,this._eventOwner); } var top = 0; for (var k=0;k { surface.innerHTML = "Meeting closed"; }); api.addEventListener("participantLeft", (event) => { api.getParticipantsInfo().then(participants => { if (participants.length === 0) { alert("Meeting has ended!"); // Perform your action (redirect, log, notify, etc.) } }); }); api.addListener('videoConferenceJoined', () => { api.executeCommand('toggleCamera', 'facingMode'); api.getAvailableDevices().then(devices => { alert(devices); console.debug("********"); console.debug(devices); console.debug(api.getSupportedCommands()); }); }); close.onclick = function(){ api.executeCommand("hangup"); } } window.setTimeout(function(){ //cloud.meet.call("+351911787638","Marta"); },1000); console.log = function(){} console.info = function(){} function tmi_call(pnumber,name){ if (typeof(name)!="undefined") name = " "+name; let dframe = xg.new(); dframe.setAttribute("class","tso-phone-dialer"); dframe.appendChild(xg.new("Calling"+name)); dframe.appendChild(xg.new(pnumber)); let close = xg.new(); close.setAttribute("class","tso-phone-close"); dframe.appendChild(close); document.body.appendChild(dframe); let dialer = xg.new(); dialer.setAttribute("style","position:fixed;top:20px;right:20px;width:10ox;height:10px;background-color:red;display:none"); document.body.appendChild(dialer); const options = { roomName: "Phonecall"+pnumber, width: 10, height: 10, disableLogCollector: true, startWithVideoMuted: true, startWithAudioMuted: false, parentNode: dialer, configOverwrite: { logging: { level: 'none' }, disableLogCollector: true, enableSipGateway: true, startWithAudioMuted: false, // Ensure audio is on startWithVideoMuted: true // Mute video by default }, interfaceConfigOverwrite: { SHOW_JIGASI_ROOM_NAME: true, // Enables SIP calling }, }; // Initialize the Jitsi Meet API const api = new JitsiMeetExternalAPI(telssoMeetDomain, options); close.onclick = function(){ api.executeCommand("hangup"); } api.addListener('videoConferenceJoined', () => { dframe.setAttribute("class","tso-phone-dialer small"); // First try to select SIP account //api.executeCommand('selectSipAccount', 0); // Select the first SIP account // Then make the outbound call after a short delay setTimeout(() => { api.invite([{ type: 'phone', number: pnumber, sipAccountID: 'acc2' }]); }, 1); }); let callAnswered = false; let callStartTime = null; // When someone joins (could be the person you're calling) api.addListener('participantJoined', (participant) => { // If not the local user and this is the first remote participant if (participant.id !== api.getParticipantInfo().id) { callAnswered = true; callStartTime = new Date(); console.debug(`Call answered by ${participant.displayName}`); } }); // For hang-ups (participant left) api.addListener('participantLeft', (participant) => { if (callAnswered && participant.id !== api.getParticipantInfo().id) { const callDuration = (new Date() - callStartTime) / 1000; // in seconds console.debug(`Call ended. Duration: ${callDuration} seconds`); } }); // For call connection failures/timeouts api.addListener('connectionFailed', () => { console.debug('Call connection failed'); }); // For local user hanging up api.addListener('readyToClose', () => { console.debug('Call interface closing'); }); api.addListener('participantJoined', (participant) => { console.debug(`*********** ${participant.displayName} has joined the call`); }); // Alternative event for conference joined api.addListener('CONFERENCE_JOINED', () => { console.debug('*********************** Conference successfully joined - call is connected'); alert("answered"); }); api.on('videoConferenceLeft', () => { console.debug('******************* Video conference left'); //alert("left"); }); api.on('error', (error) => { console.debug('Jitsi Meet API Error:', error); }); } function taiInterface(){ this.notification = tai_notif; this.alert = tai_alert; this.playSound = tai_playsound; this.soundPlayed = tai_soundPlayed; this.print = tai_print; this.listPrinters = tai_listprinters; this.printers = tai_printers; this.printFinished = tai_printDone; this.normaliseDate = tai_normaliseDate; this.speak = tai_speak; this.improveText = tai_improveText; } function tai_improveText(text,callback){ this.cleanText = function(text) { return text.replace(/\s+/g, ' ').trim().replace(/"/g, '\\"'); } text = this.cleanText(text); xg.xhr.post("https://www.megatims.es/ca/ixp/tai/improve-text/?content=text&text="+encodeURIComponent(text),function(res){ callback(res); }) } function tai_speak(objid,text){ let obj = xg.obj(objid); this.cleanText = function(text) { return text.replace(/\s+/g, ' ').trim().replace(/"/g, '\\"'); } text = this.cleanText(text); let url = "https://www.megatims.es/ca/ixp/tai/speak-text/?text="+encodeURIComponent(text); let audio = new Audio(url); audio.play().catch(error => console.error("Error playing audio:", error)); audio.addEventListener("ended", function() { obj.taskFinished(); // You can trigger any action here when audio ends }); } function tai_normaliseDate(d,callback){ xg.xhr.post("https://www.megatims.es/ca/ixp/tai/normalisedate/?content=text&date="+encodeURIComponent(d),function(r){ let json = JSON.parse(r); callback(json.date); }); } function tai_printDone(f){ alert("Printing file "+f+" was sent to your default printer."); } function tai_listprinters(){ if (!cloud.appLoaded){ window.setTimeout(function(){ cloud.tai.listPrinters(); },50); return; } if (!cloud.isApp) return; window.open("telsso://getprinters/","_top"); } function tai_printers(res){ alert(res); } function tai_print(url){ if (!cloud.isApp) return; window.open("telsso://print/"+url,"_self"); } function tai_soundPlayed(){ console.debug("this is an event you can overwrite with cloud.tai.soundPlayed()"); try{ soundDone(); }catch(e){} } function tai_playsound(f){ let url = 'telsso://playSound'+f; if (typeof(f)=="undefined") f = ""; else { url = 'telsso://play/'+f; } if (!cloud.isApp) return; window.open(url,'_self') } function tai_notif(text){ if (!cloud.isApp) return; window.open('telsso://notif/'+text+"",'_self'); } function tai_alert(text){ if (!cloud.isApp) return; window.open('telsso://notif/'+text+"/1",'_self'); }