// expand and contract tables
function expandcontract(tableid,dis) {
//document.getElementById("superTable").style.display = '';
  document.getElementById(tableid).style.display = dis;
}

function toggleMethod(tableid, tableid2) {
  // tableid= table to show, tableid2 = table to hide
  document.getElementById(tableid).style.display = ''
  document.getElementById(tableid2).style.display = 'none';
}


// ROLL-OVER
function roll(obj, state) {
  if (state == 0) { document.images[obj].src = "/personal/images/nav/" + obj + "_0.gif" };
  if (state == 1) { document.images[obj].src = "/personal/images/nav/" + obj + "_1.gif" };
}


function rollNav (obj,state) {
	roll(obj,state);
	if (obj == 'banking' && sID != 'borrowing') {
		roll('sep0',state);
	}
	if (obj == 'borrowing') {
		if (sID != 'banking') {
			roll('sep0',state);
		}
		if (sID != 'investing') {
			roll('sep1',state);
		}
	}
	if (obj == 'investing') {
		if (sID != 'borrowing') {
			roll('sep1',state);
		}
		if (sID != 'insuring') {
			roll('sep2',state);
		}
	}
	if (obj == 'insuring') {
		if (sID != 'investing') {
			roll('sep2',state);
		}
		if (sID != 'tools_planning') {
			roll('sep3',state);
		}
	}
	if (obj == 'tools_planning' && sID != 'insuring') {
		roll('sep3',state);
	}
}


function textCounter(field,maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
	{field.value = field.value.substring(0, maxlimit);
alert("Your comments have exceeded the maximum size allowed in this textbox!");}
// otherwise, update 'characters left' counter
//else
//cntfield.value = maxlimit - field.value.length;
}




//DROP-DOWN NAVIGATION Old WEBFX
// rn function dropNav(object) {

	//added by DP 03/08/2006 Bug 494
// rn    var url = object.options[object.selectedIndex].value;
	
// rn    if (url == 'https://www.sovereignbankfx.com/')
	// rn    {
		
 // rn 		if(window.confirm("IMPORTANT MESSAGE: \n You are attempting to access Sovereign’s secure Foreign Exchange (WebFX) system. \n Select “OK” below if you are a customer of WebFX and have downloaded the required digital certificate. \n Select “Cancel” below if you are not a current customer of WebFX. \n If you would like to learn more about Sovereign’s WebFX solution, please contact Kim or Olga at 617-757-5606."))
// rn		   {window.location.href = object.options[object.selectedIndex].value;}
	        //else
		//    {alert("In order to download a certificate to access Sovereign’s Foreign Exchange System, please contact Kim or Olga at 617.757.5606.");}
    
// rn		}
// rn		else
// rn	    window.location.href = object.options[object.selectedIndex].value;

// rn 	 }



//DROP-DOWN NAVIGATION NEW WEBFX 
function dropNav(object)
{
	var url = object.options[object.selectedIndex].value;
	dropNavUrl(url, false);
}

function dropNavUrl(url, newWindow)
{
	if (newWindow)
	{
		var newWindow = window.open(url, '_blank');
		newWindow.focus();
		return false;
	}
	else
	{
		if (url == 'https://www.sovereignbank.com/fx')
		{
			if (window.confirm("Terms of Access: \n By entering your User ID and Password, and by gaining access to this on-line foreign exchange platform, you acknowledge that you have read, understand, agree to the terms and have executed the Customer Agreement for Sovereign Bank's on-line foreign exchange system, WebFX. \n \n Select “OK” below if you agree to the terms and have executed the Customer Agreement. Select “Cancel” below if you disagree with the terms or have not executed the Customer Agreement. \n \n If you would like to learn more about Sovereign’s WebFX solution, please contact Kim or Olga at 617-757-5606."))
			{
				window.location.href = url;
			}
		        //else
			//    {alert("In order to download a certificate to access Sovereign’s Foreign Exchange System, please contact Kim or Olga at 617.757.5606.");}
		}
		else window.location.href = url;
	}
}

function parseDropNav(object)
{
	var text = object.options[object.selectedIndex].value;
	var parts = text.split(",", 2);
	if (parts.length == 1)
		dropNavUrl(text, false);
	else if (parts.length == 2)
	{
		var newWindow = parts[0].toLowerCase();
		var url = parts[1];
		if (newWindow == 'true' || newWindow == 'false')
			dropNavUrl(url, newWindow == 'true');
		else
			dropNavUrl(text, false);
	}
}

//PROMOTRACK TAG
if (document.images)
{

if(document.URL.indexOf('s') == 4 || document.URL.indexOf('S') == 4 ){
  pic1= new Image(1,1); 
  pic1.src = "https://www.sovereignbank.com/utils/track.asp?url="+ document.URL + "&fid=&cf="; 
}
else{  
  pic1= new Image(1,1); 
  pic1.src = "http://www.sovereignbank.com/utils/track.asp?url="+ document.URL + "&fid=&cf="; 
}
}


//SET THE PERSISTENT COOKIE
function setCookie(name, value, path, domain, secure) {
 var today = new Date();
 var expires = new Date();
 var daysGoodFor = 1;
 expires.setTime(today.getTime() + 3600000*24*daysGoodFor);
 path="/";
 var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
		//alert("curCookie = " + curCookie);
	document.cookie = curCookie;
}

//SET COOKIE FOR BROWSER VALIDITY
function setBrowserDetect(){
	// set browser detect cookie
	setCookie("invalidBrowser","true");
}

//INQUIRA SEARCH FUNCTIONS ***********************************************************


/**
 * Browser.js
 *
 * JavaScript object for capturing browser information.
 *
 */

/**
  * Browser Constructor
  */
function Browser()
{
    this.name = window.navigator.appName.toLowerCase();
    this.version = window.navigator.appVersion;
}


/**
  * Check to see if we are using Netscape.
  */
function _Browser_isNetscape()
{
    return (this.name == "netscape")
}


/**
  * Check to see if we are using InternetExplorer.
  */
function _Browser_isIE()
{
    return (this.name == "microsoft internet explorer")
}



/**
  * Assign Prototype Methods
  */
Browser.prototype.isNetscape    = _Browser_isNetscape;
Browser.prototype.isIE          = _Browser_isIE;

//************************************************************************************

/**
 * EventWrapper.js
 *
 * JavaScript object wrapper for browser events.
 *
 * The purpose of this object is to provide a set of browser-independent
 * APIs for accessing browser events in JavaScript.
 *
 */

/**
  * EventWrapper Constructor
  */
function EventWrapper(p_event, p_browser)
{
    // Member variables
    this.event    = p_event;
    this.browser  = p_browser;

    // Key constants
    this.key       = new Object();
    this.key.ENTER = 13;
}


/**
  * Check to see if a specific key was pressed.
  */
function _EventWrapper_isKeyPress(p_keycode)
{
    var keyCode = this.browser.isNetscape() ? this.event.which : this.event.keyCode;

    if (keyCode == p_keycode)
       return true;
    else
       return false;
}


/**
  * Return the DOM element that fired the event.
  */
function _EventWrapper_getElement()
{
    if (this.browser.isIE())
        return this.event.srcElement;
    else if (this.browser.isNetscape())
        return this.event.target;
}



/**
  * Assign Prototype Methods
  */
EventWrapper.prototype.isKeyPress    = _EventWrapper_isKeyPress;
EventWrapper.prototype.getElement    = _EventWrapper_getElement;

//************************************************************************************

/*
 * qna_common.js
 *
 * JavaScript file for common Q&A functionality.
 * 
 */


var qna_browser        = new Browser();
var qna_submitOK       = true;
var qna_instructions   = "Type a question here to search.";
var qna_max_size_alert = "";

/**
  * Handle a key press release event in the question box.
  */
function handleKeyPress_QuestionBox(p_evt)
{
    var ew = new EventWrapper(p_evt, qna_browser);

    if (ew.isKeyPress(ew.key.ENTER))
    {
        var qBox = ew.getElement();
        qBox.blur();
        qBox.value = qBox.value.replace(/\s+$/,''); // Strip whitespace from end
        submitQuestion();
        return false;
    }
    else
    {
        if (ew.getElement().value.length > 135)
        {
            ew.getElement().value = ew.getElement().value.substring(0,135);
            alert(qna_max_size_alert);
            return false;
        }
    }

    return true;
}


/**
  * Handle a focus event in the question box.
  */
function handleFocus_QuestionBox(p_evt)
{
    var ew = new EventWrapper(p_evt, qna_browser);

    var question = document.question_form.question_box.value;
    // Clear the instructions if they are in the text box
    if (qna_instructions.length > 0
        && question.indexOf(qna_instructions) > -1)
    {
        document.question_form.question_box.value = "";
        var qbox_class = document.question_form.question_box.className;
        var instruction_class_idx = qbox_class.indexOf("qna-input-instructions");
        document.question_form.question_box.className = qbox_class.substring(0, instruction_class_idx);
    }
    else
    {
        document.question_form.question_box.select();
    }

    return true;
}


/**
  * Submit the question.
  */
function submitQuestion()
{

    // Submit the question
    if (!isSubmitOK())
    {
        return false;
    }

    // Prevent another quick submit and submit this question
    disableSubmit();
    document.question_form.submit();

    // Wait 10 seconds before submit available
    setTimeout("enableSubmit();", 10000);
    startSearchingIndicator();

    return false;
}


/**
  * Check to see if submitting is OK.
  */
function isSubmitOK()
{

    if (!qna_submitOK)
        return false;

    var question = document.question_form.question_box.value;
    // Trim any whitespace from question
    question = question.replace(/^\s+/,'');
    question = question.replace(/\s+$/,'');

    // Don't submit a blank query
    if (question == "")
    {	//Please type in your question, e.g., what type of loans do you offer?"
		alert("Please type in your question, e.g., what type of loans do you offer?");
        document.question_form.question_box.value = "";
        document.question_form.question_box.focus();
        return false;
    }
	
	 // Don't submit a 'Search' query
    if (question == "search")
    {	alert("Please type in a search topic, e.g., search car loans");
        document.question_form.question_box.value = "";
        document.question_form.question_box.focus();
        return false;
    }

    // Don't submit if the instructions are still in the text box
    if (qna_instructions.length > 0
        && question.indexOf(qna_instructions) > -1)
    {
		alert("Please type in your question, e.g., what type of loans do you offer?");
        document.question_form.question_box.value = "";
        document.question_form.question_box.focus();
        return false;
    }

    return true;
}


/**
  * Disable the submit feature.
  */
function disableSubmit()
{
    qna_submitOK = false;
    //document.question_form.Ask.disabled = true;
}


/**
  * Enable the submit feature.
  */
function enableSubmit()
{
    qna_submitOK = true;
    //document.question_form.Ask.disabled = false;
}


/**
  * Start progress bar
  *
  * This isn't a real progress indicator since we don't really know how
  * long it will take for the search to finish, but it will give
  * the user some feedback that the system is processing their search.
  */
var progressIndex = 0;
var maxIndex      = 0;
function startSearchingIndicator()
{
    // Start up the search indicator if it is defined
    var progBox = document.getElementById("prog_box");

    if (progBox)
    {
        // Show progress area
        progBox.style.visibility = "inherit";

        // Initialize progress area
        var progIdx = 1;
        var progElement = document.getElementById("prog" + progIdx);
        while (progElement != null)
        {
            progElement.className = "qna-progress-empty";
            progIdx++;
            progElement = document.getElementById("prog" + progIdx);
        }
        maxIndex = progIdx - 1; // Keep track of the size of the progress bar

        // Start the animation
        progressIndex = 0;
        showProgress();
    }
}

function clearSearchingIndicator()
{
    // Initialize progress area
    var progIdx = 1;
    var progElement = document.getElementById("prog" + progIdx);
    while (progElement != null)
    {
        progElement.className = "qna-progress-empty";
        progIdx++;
        progElement = document.getElementById("prog" + progIdx);
    }
}

function showProgress()
{
    // Increment to our next progress field
    if (progressIndex < maxIndex)
        progressIndex++;
    else
    {
        clearSearchingIndicator();
        progressIndex = 1;
    }

    // Display progress
    progElement = document.getElementById("prog" + progressIndex);
    progElement.className = "qna-progress-full"

    setTimeout("showProgress();", 1000);
}


/**
  * Return to the previous page
  */
function goBack()
{
    history.back();
    return true;
}


/**
  * Validate Data
  */

function isValidEmail(email)
{

	if (email == null) return false;
	if (email == "") return false;

	return (email.match(/^.+@[^\.].*\.[a-z]{2,}$/) != null);

}

function isValidZip(zip)
{

	if (zip == null) return false;
	if (zip == "") return false;

	return (zip.match(/^\d{5}(-\d{4})?$/) != null);

}



/**
  * Handle onload event.
  */
function handleOnLoad()
{
    // Fill in any message variables
    if (document.qna_messages != null)
    {
        if (document.qna_messages.question_box_instructions != null
            && document.qna_messages.question_box_instructions.value.length > 0)
            qna_instructions = document.qna_messages.question_box_instructions.value;
        if (document.qna_messages.question_length_warning != null)
            qna_max_size_alert = document.qna_messages.question_length_warning.value;
    }


    // Put focus on the question box
    if (document.question_form != null
        && document.question_form.question_box != null)
    {
        if (qna_instructions.length > 0 && document.question_form.question_box.value == "")
        {
            document.question_form.question_box.value = qna_instructions;
            document.question_form.question_box.className += " qna-input-instructions";
        }
        /*
        else if (document.user_feedback_form != null)
            document.question_form.question_box.focus();
        */
    }

    return true;
}


/*
 * Set up a window load handler if none exists.
 */
if (window.onload == null)
    window.onload = handleOnLoad;

/* Please type in your question, e.g., what type of loans do you offer?"*/
