var msiex = ((navigator.userAgent.indexOf('Win')  != -1) && (navigator.userAgent.indexOf('MSIE') != -1) && (parseInt(navigator.appVersion) >= 4 ));
var undetectable = ((navigator.userAgent.indexOf('Safari')  != -1) || (navigator.userAgent.indexOf('Opera')  != -1));

function dldPopup(url,w,h,winopt) {
	var winName = "dld";
	var left = (screen.availWidth-w)/2;
	var top = (screen.availHeight-h)/2;
	dldWin = window.open(url, winName,'width=' + w + ',height=' + h  + ',screenx=' +left +',screeny=' +top +',top=' +top +',left=' +left + ',' + winopt);
	return false;
}

function isLivestickerInstalled(){
   try{
			var axo = new ActiveXObject("Livesticker.Infos");
			
			axo.productName = "LiveSticker";
			
			var sLivestickerVersion = axo.version; 

			axo.productName = "LiveSticker3Demo";
			
			var sLivesticker3DemoVersion = axo.version; 
			
   		return (sLivestickerVersion != "") || (sLivesticker3DemoVersion != "");
   }catch (e){
   	return false;
   }
} 

function checkLiveSticker() {
    var urlpopupdld="http://widgets.livesticker.com/buttons/popup02/download.php";  
	  //add HTA 22/01/08
    if (typeof(forcepopupdld) == 'undefined' ) {
	    if(undetectable) {
	        return true;
	    } else if(!msiex) {
	        var hasMimeLiveSticker = navigator.mimeTypes["application/x-livesticker"];
	        if(typeof(hasMimeLiveSticker) == "object") {
	            return true;
	        } 
	    } else {
	        if(isLivestickerInstalled()) {
	             return true;
	        }
	    }
	  }
	  //add HTA 22/01/08
    if (  typeof(opcode_editor) != 'undefined'){
    	urlpopupdld += '?from=' + opcode_editor;
    } 
    return dldPopup(urlpopupdld,570,510,"scrollbars='no'");
}
function loadDetection() {
    if(document.getElementById && document.getElementsByTagName) {
        if (window.addEventListener) window.addEventListener('load', addDetection, false);
        else if (window.attachEvent) window.attachEvent('onload', addDetection);
    }
}

function addDetection() {
    var pageLinks = document.getElementsByTagName("a");
    for (var i=0; i < pageLinks.length; i++) {
        if(pageLinks[i].childNodes[0] && pageLinks[i].childNodes[0].src) {
            if( (pageLinks[i].childNodes[0].src.indexOf('widgets.livesticker.com\/buttons\/stickitbtn\/') != -1 || pageLinks[i].childNodes[0].src.indexOf('clients.nosibay.com\/back-officeV2\/linkforhttps\/pluslivestickerbuttons\/stickitbtn\/') != -1) 
            && (typeof(pageLinks[i].onclick) == "undefined" || pageLinks[i].onclick == null)) {
                pageLinks[i].onclick = function sChk() { return checkLiveSticker(); }
            }
        }
    }
}

loadDetection();