function trim(str) {
    while ((" \t\n\r".indexOf(str.charAt(str.length - 1)) != -1) && (str.length > 0))
        str = str.substring(0, str.length - 1);
    while ((" \t\n\r".indexOf(str.charAt(0)) != -1) && (str.length > 0))
        str = str.substring(1, str.length);
    return str;
}

function StripChars(theFilter, theString) {
    var strOut, i, curChar

    strOut = ""
    for (i = 0; i < theString.length; i++) {
        curChar = theString.charAt(i)
        if (theFilter.indexOf(curChar) >= 0)
            strOut += curChar
    }
    return strOut
}

function IsContactPhoneValidFromSubmit(submitButton) {
    if(     ( ! eval( submitButton ) )
        ||  ( ! eval( submitButton.parentNode ) )
        ||  ( ! eval( submitButton.parentNode.parentNode ) )
        ||  ( ! eval( submitButton.parentNode.parentNode.parentNode ) )
        ||  ( ! eval( submitButton.parentNode.parentNode.parentNode.parentNode ) )
        ||  ( ! eval( submitButton.parentNode.parentNode.parentNode.parentNode.childNodes[4] ) )
        ||  ( ! eval( submitButton.parentNode.parentNode.parentNode.parentNode.childNodes[4].childNodes[3] ) )
        ||  ( ! eval( submitButton.parentNode.parentNode.parentNode.parentNode.childNodes[4].childNodes[3].childNodes[0] ) )
        ||  ( ! eval( submitButton.parentNode.parentNode.parentNode.parentNode.childNodes[4].childNodes[3].childNodes[0].childNodes[0] ) )
        ||  ( ! eval( submitButton.parentNode.parentNode.parentNode.parentNode.childNodes[4].childNodes[3].childNodes[0].childNodes[0].childNodes[0] ) )
        ||  ( ! eval( submitButton.parentNode.parentNode.parentNode.parentNode.childNodes[4].childNodes[3].childNodes[0].childNodes[0].childNodes[0].childNodes[1] ) )
        ||  ( ! eval( submitButton.parentNode.parentNode.parentNode.parentNode.childNodes[4].childNodes[3].childNodes[0].childNodes[0].childNodes[0].childNodes[1].childNodes[0] ) )
        ||  ( ! eval( submitButton.parentNode.parentNode.parentNode.parentNode.childNodes[4].childNodes[3].childNodes[0].childNodes[0].childNodes[0].childNodes[5] ) ) )
        return false ;
    var inputElem = submitButton.parentNode.parentNode.parentNode.parentNode.childNodes[4].childNodes[3].childNodes[0].childNodes[0].childNodes[0].childNodes[1].childNodes[0] ;
    var messageElem = submitButton.parentNode.parentNode.parentNode.parentNode.childNodes[4].childNodes[3].childNodes[0].childNodes[0].childNodes[0].childNodes[5] ;
    return IsContactPhoneValidFromElems(inputElem, messageElem);
    return false;
}

function IsContactPhoneValidFromPhoneInput(phoneInput) {
    if(     ( ! eval( phoneInput ) )
        ||  ( ! eval( phoneInput.parentNode ) )
        ||  ( ! eval( phoneInput.parentNode.parentNode ) )
        ||  ( ! eval( phoneInput.parentNode.parentNode.childNodes[5] ) ) )
        return false ;
    var inputElem = phoneInput;
    var messageElem = phoneInput.parentNode.parentNode.childNodes[5];
    return IsContactPhoneValidFromElems( inputElem, messageElem );
}

function IsContactPhoneValidFromElems(inputElem,messageElem) {
    var passes = StripChars('1234567890', inputElem.value).length >= 7;
    messageElem.style.display = passes ? "none" : "block";
    return passes;
}

function NoEnterKey(e) {
    if ((e.keyCode ? e.keyCode : e.charCode ? e.charCode : e.which ? e.which : null) == 13) {
        if( e.preventDefault ) e.preventDefault() ;
        if( e.stopPropagation ) e.stopPropagation() ;
        if( e.returnValue ) e.returnValue = false ;
        return false ;
    }
}

$(document).ready(function() {
	// set all input.text default value according to alt attribute
    $("input.searchfield, input.accountsfield, input.Careers_InputBox, input.Calculators_InputBox").each(function () {
      if( $(this).attr("alt") != "" )
    	  $(this).val($(this).attr("alt"));
	});
	// clear input.text on focus, if still in default
	$("input.searchfield, input.accountsfield, input.Careers_InputBox, input.Calculators_InputBox").focus(function() {
	  if($(this).val()==$(this).attr("alt")) {
		$(this).val("");
	  }
	});
	// if field is empty afterward, add text again
	$("input.searchfield, input.accountsfield, input.Careers_InputBox, input.Calculators_InputBox").blur(function() {
	  if($(this).val()=="") {
		$(this).val($(this).attr("alt"));
	  }
	});

	$("ul#topnav li .sub1").css({'opacity':'0'});
	$("ul#topnav li .sub2").css({'opacity':'0'});
	$("ul#topnav li").hoverIntent( {
	        sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
	        interval: 100, // number = milliseconds for onMouseOver polling interval    
	        timeout: 500, // number = milliseconds delay before onMouseOut    
	        over: function(){
				$(this).find(".sub1").stop().fadeTo('fast', 1).show();
				$(this).find(".sub2").stop().fadeTo('fast', 1).show();
			},
	        out: function(){
				$(this).find(".sub1").stop().fadeTo('fast', 0, function(){ $(this).hide(); });
				$(this).find(".sub2").stop().fadeTo('fast', 0, function(){ $(this).hide(); });
			}
	    }
	);
   $('#accordion').accordion({autoHeight: false});
   $("#onlinebankingtabs").tabs();
   $(document).pngFix(); 
   $("a.boxes").fancybox({
	});
});
