var activex = ((navigator.userAgent.indexOf('Win')  != -1) && (navigator.userAgent.indexOf('MSIE') != -1) && (parseInt(navigator.appVersion) >= 4 ));
var CantDetect = ((navigator.userAgent.indexOf('Safari')  != -1) || (navigator.userAgent.indexOf('Opera')  != -1));
var CompatibleSystem = (navigator.userAgent.indexOf('Win') != -1);
var URLtoOpen = 'http://www.euro2008.polsat.com.pl/693/index.html';

function oopsPopup() {
	var popup=false;

	try { if(iplaInstallURL.length >0) URLtoOpen=iplaInstallURL;
	} catch(e){}
	
	try { if(iplaPopup) popup=true;
	}	catch(e){}
	
	if(popup) oopswindow = window.open(URLtoOpen);
	else {
	    if(!window.installIplaPage)
		window.installIplaPage = URLtoOpen;
	    document.location.href= window.installIplaPage;
	}
	return false;
}

if(typeof(detected) == "undefined" && activex) {
	document.write(['<script language="VBscript">',
		'Function isIplaInstalled()',
		'on error resume next',
		'Set oIpla = CreateObject("IPLAMK.iplamkCtrl")',
		'isIplaInstalled = IsObject(oIpla)',
		'Set oIpla = nothing',
		'End Function',
		'</script>'].join("\n")
	);
}

function iplaCheck() {
    if(CompatibleSystem){
	if(CantDetect) return true;
	else if(!activex) {
	    var iplaMime = navigator.mimeTypes["application/x-ipla"];
    	    detected = true;
    	    if(typeof(iplaMime) == "object") return true;
    	    else return oopsPopup();
    	} else {
    	    if(isIplaInstalled()) {
        	detected = true;
        	return true;
    	    }
	}
    }
    detected = true;
    return oopsPopup();
}

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++){
		var lnk = pageLinks[i];
		if(lnk.href){
			if(lnk.href.indexOf('ipla:') != -1){
				lnk.onclick = function(){
					return iplaCheck();
				}
			}
        }
    }
}

function putVODexternalNew(ids, title, img){
    var dmn = encodeURI(document.location.href);
    var html = '<a href="'+ids+'/'+dmn+'" title="'+title+'"><img src="'+img+'"></a>';
    document.write(html);
}

function WatchIplaNullMatch(url){
	if(iplaCheck())
		document.location.href=url; //;
	else
		document.location.href='http://login.ipla.redefine.pl/IplaRedirect/';
}


loadDetection();