var bHasActiveX = ((navigator.userAgent.indexOf('Win')  != -1) && (navigator.userAgent.indexOf('MSIE') != -1) && (parseInt(navigator.appVersion) >= 4 ));
var bUnsupportedBrowser = ((navigator.userAgent.indexOf('Safari')  != -1) || (navigator.userAgent.indexOf('Opera')  != -1));
var detected;

if(typeof(detected) == "undefined" && bHasActiveX) {
    document.write(
        ['<script language="VBscript">',
        'Function isPaltalkInstalledVB()',
        'on error resume next',
        'Set paltalkObj = CreateObject("pallauncher.command")',
        'isPaltalkInstalledVB = IsObject(paltalkObj)',
        'Set paltalkObj = nothing',
        'End Function',
        '</script>'].join("\n")
    );
}

function checkPaltalk() {
    if ( !isPaltalkInstalled() ) {
        return gotoDownloadPage()
    }
    return true;
}


function isPaltalkInstalled() {
    if(bUnsupportedBrowser) {
        return true;
    } else if(!bHasActiveX) {
        var paltalkMime = navigator.mimeTypes["application/x-paltalk"];
        detected = true;
        
        
        if(typeof(paltalkMime) == "object") {
            return true;
        } else {
            return false;
        }
    } else {
        if(isPaltalkInstalledVB()) {
            detected = true;
            return true;
        }
    }
    
    detected = true;
    return false;
}



function gotoDownloadPage(target_url) {
    var download_url = "http://www.paltalk.com/en/client_download.shtml";
    
    if ( target_url!=null && target_url!='' ){
        download_url=download_url+"?target="+target_url;
    }
    
    window.location.href = download_url;
	return false;
}


    
function launchGroup(group_id){    
    
    var target_url = "paltalk://groups/"+group_id;   
    if ( isPaltalkInstalled() ) {
        window.location.href = target_url;
    } else {
       gotoDownloadPage(target_url); 
    }
}
function launchPaltalk(){    
    var target_url = "paltalk://";  
     
    if ( isPaltalkInstalled() ) {        
        window.location.href = target_url;
    } else {
       gotoDownloadPage(target_url); 
    }
}
function launchImWindow(uid){   
    var target_url = "paltalk://pm/"+uid;   
    
    if ( isPaltalkInstalled() ) {        
        window.location.href = target_url;
    } else {
       gotoDownloadPage(target_url); 
    }
}


function addBuddy(uid){   
    var target_url = "paltalk://addbuddy/"+uid;   
    
    if ( isPaltalkInstalled() ) {        
        window.location.href = target_url;
    } else {
       gotoDownloadPage(target_url); 
    }
}
function removeBuddy(uid){   
    var target_url = "paltalk://removebuddy/"+uid;   
    
    if ( isPaltalkInstalled() ) {        
        window.location.href = target_url;
    } else {
       gotoDownloadPage(target_url); 
    }
}

function launchRecorder(){   
    var target_url = "paltalk://launchrecorder/";   
    
    if ( isPaltalkInstalled() ) {        
        window.location.href = target_url;
    } else {
       gotoDownloadPage(target_url); 
    }
}

