/*******************************************************************
 This function returns the browser name as a string
*******************************************************************/
function getBrowserName()
{
    var name = "Unknown";
    if(navigator.userAgent.indexOf("MSIE")!=-1)
    {
        name = "MSIE";
    }
    else if(navigator.userAgent.indexOf("Firefox")!=-1)
    {
        name = "Firefox";
    }
    else if(navigator.userAgent.indexOf("Opera")!=-1)
    {
        name = "Opera";
    }
    else if(navigator.userAgent.indexOf("Chrome") != -1)
    {
        name = "Chrome";
    }
    else if(navigator.userAgent.indexOf("Safari")!=-1)
    {
        name = "Safari";
    }
 
    return name;   
}
/*******************************************************************
 This function returns the browser version as a string
*******************************************************************/
function getBrowserVersion()
{
    var version = "0";
    //look for IE browser
   
    if (navigator.userAgent.indexOf("MSIE")!=-1)
    {
        var temp   = navigator.userAgent.split("MSIE");
            
        version = temp[1].substring(0, temp[1].indexOf(";"));
            
        //alert("You are using Microsoft Internet Explorer version " + version);
        return version;
    }
   
    //look for Firefox browser
  
    if(navigator.userAgent.indexOf("Firefox")!=-1)
    {
        var versionIndex=navigator.userAgent.indexOf("Firefox")+8;
           
        if (parseInt(navigator.userAgent.charAt(versionIndex))>=1);
        {
            version = navigator.userAgent.substring(versionIndex, versionIndex+7);
        }
  
        //alert("You are using Firefox version " + version);
        return version;
    }
    
    //look for Opera browser
    if(navigator.userAgent.indexOf("Opera")!=-1)
    {
        //check if Opera 10+
        if(navigator.userAgent.indexOf("Version/")!=-1) {
            var temp   = navigator.userAgent.split("Version/");
            version = temp[1];
        }
        else {  //we have Opera 9-
            var temp   = navigator.userAgent.split("Opera");
            
            version = temp[1].substring(1, temp[1].indexOf(" "));
  
        //alert("You are using Opera version " + version);
        }
        return version;
    }
    
    //look for Chrome Browser
    
    if(navigator.userAgent.indexOf("Chrome")!=-1)
    {
        var temp   = navigator.userAgent.split("Chrome/");
        version = temp[1].substring(0,temp[1].indexOf(" "));
        //alert("You are using Chrome version " + version);
        return version;
    }
    //look for Safari browser
    if(navigator.userAgent.indexOf("Safari")!=-1)
    {
        var temp   = navigator.userAgent.split("Version/");
        version = temp[1].substring(0,temp[1].indexOf(" "));
        //alert("You are using Safari version " + version);
        return version;
    }
}
/*****************************************************************/
var browserName   = getBrowserName();
var browserVer    = parseFloat(getBrowserVersion());
//var browserVer    = 6;
//alert("Browser = "+browserName+"\n\nVersion = "+browserVer);
var isBrowserSupported  = false;
    
function setCSSforBrowser(cssPath)
{     
    if(browserName == "MSIE" && browserVer >= 8)
    {
        //we have IE8 or higher 
        document.write('<link rel="stylesheet" type="text/css" href="'+cssPath+'style.css" />');
        isBrowserSupported = true;
    }
    else if(browserName == "MSIE" && browserVer >= 7)
    {
        //we have IE7 or higher
        /*
        alert("Your browser is Microsoft Internet Explorer version 7 !!!!"+
           "\n\nYour screen width :\t" + screen.width + " pixels." +
                "\nYour screen height:\t" + screen.height +  " pixels." +
           "\n\nThis page is optimised for Microsoft Internet Explorer V7 \nwith screen size 1280 x 1024 pixels.");
 */        
        document.write('<link rel="stylesheet" type="text/css" href="'+cssPath+'style_ie7.css" />');
        isBrowserSupported  = false;
    }
    else if(browserName == "MSIE" && browserVer <= 6)
    {
        //we have IE6 or lower
        document.write('<link rel="stylesheet" type="text/css" href="'+cssPath+'style_ie6.css" />');
        isBrowserSupported  = false;
    } 
	/*  
    else if(browserName == "Firefox")
    {
        document.write('<link rel="stylesheet" type="text/css" href="'+cssPath+'wpc_FF3.css" />');
        
        if(browserVer >= 3.6)
            isBrowserSupported  = true;
        else
            isBrowserSupported  = false;
    } 
    else if(browserName == "Safari")
    {
        document.write('<link rel="stylesheet" type="text/css" href="'+cssPath+'style.css" />');
        
        if(browserVer >= 4)
            isBrowserSupported  = true;
        else
            isBrowserSupported  = false;
    }
    else if(browserName == "Opera")
    {
        document.write('<link rel="stylesheet" type="text/css" href="'+cssPath+'wpc_OP.css" />');
        
        if(browserVer >= 10)
            isBrowserSupported  = true;
        else
            isBrowserSupported  = false;               
    }
    else if(browserName == "Chrome")
    {
        document.write('<link rel="stylesheet" type="text/css" href="'+cssPath+'wpc_GC.css" />');
        if(browserVer >= 2)
            isBrowserSupported  = true;
        else
            isBrowserSupported  = false;
    }
    else //we have an unsupported browser  - use the FF css and hope for the best !!!
    {   
        document.write('<link rel="stylesheet" type="text/css" href="'+cssPath+'wpc_FF3.css" />');
        isBrowserSupported  = false;
        browserName         = "Unsupported";
        browserVer          = "Unknown";
    }
    //reset the MSIE browser name
    if(browserName == "MSIE") browserName = "Internet Explorer"*/
}
/************************************************************************************
 This function checks if the user's browser is supported or not
************************************************************************************/
function checkForUnsupportedBrowser()
{
    if(!isBrowserSupported)
    {
        alert("** Warning **\n\nThis website is best viewed with:"+
            "\n\nInternet Explorer v7\nFirefox Portable Edition v3.0.5\nOpera v9.63\nSafari v3.1\n\n"+
            "It appears your browser is not one of the above.\n\n");
    }   
}
//----------------------------------------------------------------------------
//** This function gets a browser's viewport width and height
//----------------------------------------------------------------------------
function getViewportInfo(minWidth)
{
    var viewportwidth  = 0;
    var viewportheight = 0;
 
    // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 
    if (typeof window.innerWidth != 'undefined')
    {
        viewportwidth = window.innerWidth,
        viewportheight = window.innerHeight
    }
 
    // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
    else if (typeof document.documentElement != 'undefined'
        && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
        {
        viewportwidth = document.documentElement.clientWidth,
        viewportheight = document.documentElement.clientHeight
    }
 
    // older versions of IE
 
    else
    {
        viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
        viewportheight = document.getElementsByTagName('body')[0].clientHeight
    }
 
    //alert user if his broweer window is too small
    
    if(viewportwidth > 0 && viewportwidth < minWidth)
    {
        alert('** Warning ** \n\nYour browser width is '+viewportwidth+' pixels wide.'+
            '\n\nYour browser needs to be at least '+minWidth+' pixels wide to view this page correctly.'+
            '\n\nPlease maximise your browser window or increase your monitor\nscreen width to at least '+minWidth+' pixels\n\n');
    }
}

