﻿
function CpoImage(clientId,url,urlBase,urlLink){this.Img=document.getElementById(clientId);if(!this.Img)
return alert("Image not found: "+clientId);this.Url=url;this.UrlBase=urlBase;this.UrlLink=urlLink;this.OriginalUrl=this.Img.src;this.Values=new Array();}
CpoImage.prototype.SetImageReplace=function(name,value){window.clearTimeout(this.SetNewThread);this.Values[name]=value;window["replace"]=this.Values;this.NewUrl=this.Url.replace(/\[[^\]]*\]/gi,this.RegExRep);this.NewUrlBase=this.UrlLink.replace(/\[[^\]]*\]/gi,this.RegExRep);this.NewUrlLink=this.UrlLink.replace(/\[[^\]]*\]/gi,this.RegExRep);var instance=this;this.SetNewThread=window.setTimeout(function(){instance.SetNew();},100);};CpoImage.prototype.RegExRep=function(str,p1,org){var nameSplit=str.substring(1,str.length-1).split("|");var found=window["replace"][nameSplit[0]];if(!found){if(nameSplit[1]!=null)
return nameSplit[1];else
nameSplit[0];}
return found};CpoImage.prototype.SetNew=function(){this.Img.src=this.NewUrl;this.Img.highRes=this.NewUrlBase;var parentNode=this.Img.parentNode;if(parentNode&&parentNode.tagName.toLowerCase()=='a')
parentNode.href=this.NewUrlLink;};