    
    var strHostName = location.hostname.toLowerCase();
    var strURL = location.hostname + location.pathname + location.search;
    var strProtocol = location.protocol;
    
    var blnNeedsWWW = false;
    var blnNeedsProtocol = false;
    var blnLocalhost = false;
    var blnIsIPAddress = false;

    // is the URL an IP address?    
    var IPRegEx = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/; 
    var arrMatches = IPRegEx.exec(strHostName);
    blnIsIPAddress = (arrMatches != null);
    
    blnLocalhost = (strHostName.indexOf("localhost") != -1);
    
    // check for "www".  if it doesn't exist, add it and redirect
    if ((!blnLocalhost) && (strHostName.indexOf("www") == -1) && (!blnIsIPAddress)) {
        blnNeedsWWW = true;
        strURL = "www." + strURL;
    }
    
    // check protocol, switch if needed
    if ((!blnLocalhost) && (strProtocol == "http:")) {
        blnNeedsProtocol = true;
        strProtocol = "https:";
    }   
	
	// if either protocol or "www" need to change, redirect
	if (blnNeedsProtocol || blnNeedsWWW) { 
		var strNewURL = strProtocol + "//" + strURL;
		location.href = strNewURL;
    }

