/*-----    Google::BEGIN     -----*/
var map;
var geocoder;

function initialize() 
{
  map = new GMap2(document.getElementById("map_canvas"));
  map.setCenter(new GLatLng(42, -85), 5);
  geocoder = new GClientGeocoder();
}

function addAddressToMap(response) 
{
  map.clearOverlays();

  if (!response || response.Status.code != 200) {
    alert("Sorry, we were unable to find that address");
  } else {
    place = response.Placemark[0];
    point = new GLatLng(place.Point.coordinates[1],
                        place.Point.coordinates[0]);
    marker = new GMarker(point);
    map.addOverlay(marker);
    marker.openInfoWindowHtml(place.address + '<br>' +
      '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode);
	  
    var State = place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName;
   
  	document.cookie = "State=" + State + ";"    
  	
  	
  	if (get_cookie("OacType")=="Rate")   
  	{
  	    window.location = "EnterLocation.aspx";    
  	}
  	else    
  	{
  	    document.cookie = "OacType=";
  	    
        var Promo = getQueryVariable("Promo"); 

        if (Promo != null)
        {
            window.location = "Apply.aspx?Promo=" +  getQueryVariable("Promo");     
        }
        else
        {
            window.location = "Apply.aspx";      
        }
  	}
  }
}

function get_cookie(Name) 
{
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    // if cookie exists
    if (offset != -1) { 
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1) end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}
function ChangeZipcode()
{
    document.cookie = "Zipcode=;"
    window.location = './Products/EnterLocation.aspx';
}
function showLocation() 
{
  initialize();
        
  var address = document.forms[0].Zipcode.value;
 
  SetZipcodeCookie(address);

  geocoder.getLocations(address, addAddressToMap);
}

function findLocation(address) 
{
  showLocation();
}
/*-----    Google::END     -----*/
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
}
/*-----    Cookies::BEGIN     -----*/
function SetZipcodeCookie(Zipcode)
{
    document.cookie = "Zipcode=" + Zipcode + ";"
} 
function SetCategoryCookie(Category)
{
    document.cookie = "Category=" + Category + ";"
}         
function SetProductCookie(Product)
{
    document.cookie = "Product=" + Product + ";"
} 
function SetProductIdCookie(ProductId)
{
    document.cookie = "ProductId=" + ProductId + ";"
}         
function SetStateCookie(State)
{
    document.cookie = "State=" + State + ";"
} 
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
} 
/*-----    Cookies::END     -----*/

/*-----    MARKETING FUNCTIONS::BEGIN     -----*/
function Promotion()
{
    var domain = window.location.hostname;
    
    window.open('http://' + domain + '/Products/Apply.aspx?Category=Savings&Product=Statement Savings&Zipcode=' + get_cookie("Zipcode") + '&State=' + get_cookie("State") + '&Promo=jan09save', '', 'resizable,toolbar=yes,location=no,scrollbars=2,width=' + screen.availWidth +',height= '+ screen.availHeight + ',left=0,top=0');
}
function SellFreeAndEasyChecking()
{
    ApplyNowSellPage("Checking","Free n Easy Checking");
}
function SellAdvantageChecking()
{
    ApplyNowSellPage("Checking","Advantage Checking");
}
function SellBonusChecking()
{
    ApplyNowSellPage("Checking","Bonus Checking");
}
function SellStatementSavings()
{
    ApplyNowSellPage("Savings","Statement Savings");
}
function SellMoneyMarketSavings()
{
    ApplyNowSellPage("Savings","Money Market Savings");
}
function SellAcceleratedSavingsPlus()
{
    ApplyNowSellPage("Savings","Accelerated Savings Plus");
}
function RatesBonusChecking()
{
    RatesInquery("Checking","Bonus Checking");
}
function RatesStatementSavings()
{
    RatesInquery("Savings","Statement Savings");
}
function RatesMoneyMarketSavings()
{
    RatesInquery("Savings","Money Market Savings");
}
function RatesAcceleratedSavingsPlus()
{
    RatesInquery("Savings","Accelerated Savings Plus");
}
function RatesCd()
{
    RatesInquery("Cd","Cd");
}

/*-----    MARKETING FUNCTIONS::END     -----*/

/*-----    General::BEGIN     -----*/
function ApplyNowSellPage(Category,Product)
{
    var domain = window.location.hostname;
    window.open('http://' + domain + '/Products/Apply.aspx?Category=' + Category + '&Product=' + Product + '&Zipcode=' + get_cookie("Zipcode") + '&State=' + get_cookie("State"), '', 'resizable,toolbar=yes,location=no,scrollbars=2,width=' + screen.availWidth +',height= '+ screen.availHeight + ',left=0,top=0');
}
function RatesInquery(Category,Product)
{
    document.cookie = "OacType=Rate;"
    document.cookie = "Category=" + Category + ";"
    document.cookie = "Product=" + Product + ";"
    window.location = '/Products/EnterLocation.aspx';
} 
function ApplyRates(ProductId,BankNumber)
{
     var domain = window.location.hostname;
     window.open('http://' + domain + '/Products/ProductProcessing.aspx?ProductId=' + ProductId + '&Id=' + BankNumber, '', 'resizable,toolbar=yes,location=no,scrollbars=2,width=' + screen.availWidth + ',height=' + screen.availHeight + ',left=0,top=0');
}
function Cd()
{
    document.cookie = "OacType=Rate;"
    document.cookie = "Category=Cd;";
    window.location = '/Products/EnterLocation.aspx';
}
function queryString(ji) 
{
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i=0;i<gy.length;i++) 
    {
        ft = gy[i].split("=");
        
        if (ft[0] == ji) 
        {
            return ft[1];
        }
    }
}
/*-----    General::END     -----*/

/*------ Detect if Javascript enabled   -----*/
function SessionCookiesEnabled()
{
	var domain = window.location.hostname;
	var tmpcookie = new Date();
	chkcookie = (tmpcookie.getTime() + '');
	document.cookie = "chkcookie=" + chkcookie + "; path=/";
	if (document.cookie.indexOf(chkcookie,0) < 0) 
	{
		window.location = 'http://' + domain + '/productSection.aspx?id=2063';	
	}
}
function ClearCookies()
{
    var cookie_date = new Date();  // current date & time
    cookie_date.setTime(cookie_date.getTime()-1);

    document.cookie = "Zipcode=;expires=01/01/2000 00:00:00";
    document.cookie = "State=;expires=01/01/2000 00:00:00";
    document.cookie = "Product=;expires=01/01/2000 00:00:00";
    document.cookie = "Category=;expires=01/01/2000 00:00:00";
}

      