﻿// JScript File

//Must put <table border=0 align=center valign=middle><TR><TD><div id="bodyArea"> at top of body
//and put </DIV></td></tr></table> at bottom of body
function resizeWin() 
{ 
    if (document.all) 
    { 
        winHeight=document.all['bodyArea'].offsetHeight; 
        winWidth=document.all['bodyArea'].offsetWidth; 
    } 
    // add 30 to the width for a border 
    // add 60 to the height to account for a border + the titlebar 
    window.resizeTo(winWidth+30,winHeight+60); 
    
    //centre the window 
    if (window.moveTo) window.moveTo((screen.availWidth-winWidth)/2,(screen.availHeight-winHeight)/2); 
} 

function AFGServerURL()
{
    var SecureServerURL
    if (window.location.hostname == "www2.associatedfinancialgroup.com")
    {
        SecureServerURL = "http://secure2.associatedfinancialgroup.com";
    }
    else if(window.location.hostname == "www1.associatedfinancialgroup.com")
    {
        SecureServerURL = "http://secure1.associatedfinancialgroup.com";
    }
    else if(window.location.hostname == "localhost")
    {
        SecureServerURL = "http://secure2.associatedfinancialgroup.com";
    }
    else
    {
        SecureServerURL = "https://secure.associatedfinancialgroup.com";
    }
    return (SecureServerURL);
}

function AFGSecureServerURL()
{
    var SecureServerURL
    if (window.location.hostname == "www2.associatedfinancialgroup.com" || window.location.hostname == "secure2.associatedfinancialgroup.com")
    {
        SecureServerURL = "http://secure2.associatedfinancialgroup.com";
    }
    else if(window.location.hostname == "www1.associatedfinancialgroup.com" || window.location.hostname == "secure1.associatedfinancialgroup.com")
    {
        SecureServerURL = "http://secure1.associatedfinancialgroup.com";
    }
    else if(window.location.hostname == "localhost")
    {
        SecureServerURL = "http://secure2.associatedfinancialgroup.com";
    }
    else
    {
        SecureServerURL = "https://secure.associatedfinancialgroup.com";
    }
    return (SecureServerURL);
}

function open_url_afgSecureSite(path, openNewWindow, newWindowParam)
{
        open_url(AFGSecureServerURL()+ path, openNewWindow, newWindowParam);
}

function open_url_afgsite(path, openNewWindow, newWindowParam)
{
        open_url(AFGServerURL()+ path, openNewWindow, newWindowParam);
}

function open_url_internationalSite(openNewWindow, newWindowParam)
{
    open_url("http://www.specialtyrisk.com/insurance/quote.cfm?agent_id=%23%29I%23%2C%0A",openNewWindow, newWindowParam);
}

function open_url(url, openNewWindow, newWindowParam)
{
    var charCount = CountChar(".", url);
    var firstPeriod = url.indexOf(".", 0);
    var secondPeriod = url.indexOf(".", firstPeriod + 1);
    var redirectUrl = "";
    var domain = "";
    var promptWarning = true;
    var alertMessage = "Please be advised that this link has been provided for your convenience and that you will be leaving the Associated Financial Group Web site.  This link is not owned or controlled by Associated Financial Group or any of its affiliates or subsidiaries.  Associated Financial Group makes no representations or warranties as to this service or as to the privacy policies of other sites.";

    if (openNewWindow != null)
    {
        if (openNewWindow == "")
        {
            openNewWindow = "true";
        }
    }
    else 
    {
        openNewWindow = "true";
    }

    if (newWindowParam != null)
    {
        if (newWindowParam == "")
        {
            newWindowParam = "status=yes,toolbar=yes,menubar=yes,location=yes,resizable=yes,scrollbars=yes";
        }
    }
    else
    {
        newWindowParam = "status=yes,toolbar=yes,menubar=yes,location=yes,resizable=yes,scrollbars=yes";
    }
    
    if (firstPeriod != 0 && secondPeriod != 0 && secondPeriod > firstPeriod)
    {
        domain = url.substring(firstPeriod + 1, secondPeriod);
    }

    if (url.substring(0, 1) == "/" | url.substring(0, 1) == "." | url.substring(0, 1) == "~")
    {
        promptWarning = false;
    }
    else if (charCount < 2)
    {
        return false;
    }
    else if (domain.toLowerCase() == "associatedfinancialgroup" || domain.toLowerCase() == "associatedbank" || domain.toLowerCase() == "mybenefitsdirector" || domain.toLowerCase() == "mycompanyhr" || domain.toLowerCase() == "cfgservices" || domain == "")
    {
        promptWarning = false;
    }

    if (openNewWindow == "true")
    {
        if (promptWarning == true)
        {
            alert(alertMessage);
        }

        window.open(url,'myWindow',newWindowParam);
    }
    else
    {
        if (promptWarning == true)
        {
            alert(alertMessage);
        }
       window.location = url;     
    } 
}

function CountChar(searchCharacter, searchString)
{
    var pos = 0;
    var count = 0;
    while ((pos = searchString.indexOf(searchCharacter, pos)) != -1)
    {
        count++;
        pos++;
    }
    return count;
}

function semdesc(url){
		window.open(url,'linkwindow','height=500,width=550,status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes');
		//window.open(url,'linkwindow','height=500,width=550,status=yes,toolbar=yes,menubar=yes,location=yes,resizable=yes');
	}

var WindowObjectReference = null;
function openFFPromotionPopup(strUrl, strWindowName)
    {
        if(WindowObjectReference == null ||WindowObjectReference.closed)
        {
            WindowObjectReference = window.open(strUrl, strWindowName, "width=750,resizable=yes,scrollbars=yes,status=yes");
         }
         else
         {
            WindowObjectReference.focus();
         }
    }

