
function GoToLink(e)
{
	var s = e.options[e.selectedIndex].value;
	if(s=="" || s == "0")
	{
		// do nothing
	} 
	else
	{
		document.location.href= s;
	}
}

/*

Accesible Pop Up Code

This file contains only functions necessary for the article features
The full library code and enhanced versions of the functions present
here can be found at http://v2studio.com/k/code/lib/

MISC CLEANING-AFTER-MICROSOFT STUFF

isUndefined(v)
    returns true if [v] is not defined, false otherwise

    IE 5.0 does not support the undefined keyword, so we cannot do a direct
    comparison such as v===undefined.
*/

// MISC CLEANING-AFTER-MICROSOFT STUFF

function isUndefined(v) {
    var undef;
    return v===undef;
}

function SetSearchIndicator(type)
{
	var indicator = document.getElementById("hdnSearchFlag");
	if(indicator != null)
		indicator.value = type;
}

// These defaults should be changed the way it best fits your site
//var _POPUP_FEATURES = '';
var _POPUP_FEATURES = 'height=485,width=490,location=0,statusbar=0,menubar=0,resizable=0,scrollbars=0';		
function raw_popup(url, target, features) {
    // pops up a window containing url optionally named target, optionally having features
    if (isUndefined(features)) features = _POPUP_FEATURES;
    if (isUndefined(target  )) target   = '_blank';
    var theWindow = window.open(url, target, features);
    theWindow.focus();
    return theWindow;
}

function link_popup(src, features) {
    // to be used in an html event handler as in: <a href="..." onclick="link_popup(this,...)" ...
    // pops up a window grabbing the url from the event source's href
    return raw_popup(src.getAttribute('href'), src.getAttribute('target') || '_blank', features);
}

var defaultButton=null;

function SetFocus(id){
	defaultButton = document.getElementById(id);
	if (null == defaultButton || window.event.keyCode!=13) 
		return;
	defaultButton.focus();
	defaultButton.click();
  //window.event.returnValue = false;
  return false;
}


function stopRKey(evt) {
   var evt = (evt) ? evt : ((event) ? event : null);
   var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
   if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
}



// Form Validation
//browser detection
var strUserAgent = navigator.userAgent.toLowerCase(); 
var isIE = strUserAgent.indexOf("msie") > -1; 
var isNS6 = strUserAgent.indexOf("netscape6") > -1; 
var isNS4 = !isIE && !isNS6  && parseFloat(navigator.appVersion) < 5; 

function GetMyObjectByID(itemID)
{
// In the future will need to build in the ability to handle v4 netscape browsers.
	if (document.getElementById) // Good browsers
		return document.getElementById(itemID)
	else if (document.all) // medium browsers
		return document.all[itemID];
		
	// Need to handle v4 browsers in the future.
}

function CheckField(itemID)
{
	var o = GetMyObjectByID(itemID);
	if(o.value.length<1)
		return false;
	else
		return true;
}

function CheckDD(itemID)
{
	var o = GetMyObjectByID(itemID);
	var select = o.options[o.selectedIndex].value;
	
	//if(select.length<1 || select == "0" || select == "")
	if(select.length<1 || select == "")
		return false;
	else
		return true;
}

function CheckContactDDSelected(DDitemID, tel1ItemID, tel2ItemID, tel3ItemID)
{
	var o = GetMyObjectByID(DDitemID);
	var tel1 = tel1ItemID;
	var tel2 = tel2ItemID;
	var tel3 = tel3ItemID;
	
	var dErrorMessage = GetMyObjectByID("MyErrorSpace");
	
	var select = o.options[o.selectedIndex].value;	
	    
	    if(select == "1")
            {   
                //alert(select);             
                if (CheckField(tel1) == true)
                {} 
                else
                {
                    dErrorMessage.style.display = "block";        
                    dErrorMessage.innerHTML = "*Please enter home telephone number.";
                    return false;                    
                }                       
            }
            if(select == "2")
            {       
                if (CheckField(tel2) == true)
                {} 
                else
                {
                    dErrorMessage.style.display = "block";        
                    dErrorMessage.innerHTML = "*Please enter work telephone number."; 
                    return false;                  
                }                 
            }
            if(select == "3")
            {                         
                if (CheckField(tel3) == true)
                {} 
                else
                {
                    dErrorMessage.style.display = "block";        
                    dErrorMessage.innerHTML = "*Please enter mobile telephone number.";
                    return false;                    
                }                  
            }
            return true;
}

function CheckCheckbox(itemID)
{
	var o = GetMyObjectByID(itemID);
	
	return (o.checked);
}
/* rex custom */
function CheckRadioButton(itemID)
{	

    var o = GetMyObjectByID(itemID);
    
    if (o.checked == true) 
		return true;
	else 
		return false;

}
/* end rex custom */

function CheckRadio(FormName,itemID)
{	
	//var o = GetMyObjectByID(itemID);
	var o = document.forms[FormName][itemID];
	
	var cnt = -1;
	for (var i=0; i < o.length; i++) {
		if (o[i].checked) {
	   	cnt = i; 
		i = o.length;
	   }
	}
	if (cnt > -1) 
		return true;
	else 
		return false;
}

function CheckEmail(itemID) 
{
	var o = GetMyObjectByID(itemID);	
	if (o != null)
	{	
		// Make sure we let an email go through that is empty... The required field catcher will get that
		if (o.value.length < 1)
		{
			return false;
		}
		//var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;

//		var regex = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
//		
//		if (!regex.test(o.value))
//		{
//			return false;
//		}
//		else
//		{
//			return true;
		//		}

		return isRFC822ValidEmail(o.value);
	}
}
function isRFC822ValidEmail(sEmail) {

    var sQtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
    var sDtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
    var sAtom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
    var sQuotedPair = '\\x5c[\\x00-\\x7f]';
    var sDomainLiteral = '\\x5b(' + sDtext + '|' + sQuotedPair + ')*\\x5d';
    var sQuotedString = '\\x22(' + sQtext + '|' + sQuotedPair + ')*\\x22';
    var sDomain_ref = sAtom;
    var sSubDomain = '(' + sDomain_ref + '|' + sDomainLiteral + ')';
    var sWord = '(' + sAtom + '|' + sQuotedString + ')';
    var sDomain = sSubDomain + '(\\x2e' + sSubDomain + ')*';
    var sLocalPart = sWord + '(\\x2e' + sWord + ')*';
    var sAddrSpec = sLocalPart + '\\x40' + sDomain; // complete RFC822 email address spec
    var sValidEmail = '^' + sAddrSpec + '$'; // as whole string

    var sFinal = /^(([^<>;()[\]\\.,;:@"]+(\.[^<>()[\]\\.,;:@"]+)*)|(".+"))@((([a-z]([-a-z0-9]*[a-z0-9])?)|(#[0-9]+)|(\[((([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-5]))))\.){3}(([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-5]))))\]))\.)*(([a-z]([-a-z0-9]*[a-z0-9])?)|(#[0-9]+)|(\[((([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-5]))))\.){3}(([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-5]))))\]))$/;
    //alert(sFinal);
    var reValidEmail = new RegExp(sFinal);

    if (reValidEmail.test(sEmail)) {
        return true;
    }

    return false;
}


function CheckText(itemID) 
{
	var o = GetMyObjectByID(itemID);	
	if (o != null)
	{	
		// Make sure we let an email go through that is empty... The required field catcher will get that
		if (o.value.length < 1)
		{
			return false;
		}
		var regex = /[a-zA-Z]/;		
		if (!regex.test(o.value))
		{
			return false;
		}
		else
		{
			return true;
		}
	}
}


function CheckIsValidEmail(itemID) 
{
	var o = GetMyObjectByID(itemID);	
	if (o != null)
	{	
		// Make sure we let an email go through that is empty... The required field catcher will get that
		if (o.value.length < 1)
		{
			return true;
		}
		var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;		
		if (!regex.test(o.value))
		{
			return false;
		}
		else
		{
			return true;
		}
	}
}

function isSpecialKey(strValue){
// Returns true if one of these special key codes is pressed
//backspace Ctrl + C,enter, Ctrl + X, Ctrl + V, Ctrl + Z
var reKeyboardChars = /[\x00\x03\x08\x0D\x16\x18\x1A]/;
	return reKeyboardChars.test(strValue);
}

/*
To filter the max length here is some example code 
to catch both key down and to catch paste events
onkeypress="return FilterMaxLength(event,this,250)" onpaste="return CheckPaste(this,250)"
*/
function FilterMaxLength(e,o,max){
// we must allow spaces , backspace etc to go through 
	var iKeyCode, strKey;  
	
	if (isIE) {
		iKeyCode = e.keyCode;
	} else {
		iKeyCode = e.which;
	}	
	strKey = String.fromCharCode(iKeyCode);	
	// Make sure we let special keys go through.
		if (isSpecialKey(strKey))
			return true;	
		var maxLength = max;
     	if(o.value.length > maxLength-1){
	 		alert('You are only able to make a maximum payment of $99,999. Please reduce the amount and try again');
        	return false;
     	}
    	return true
	}
function CheckPaste(o,max){
	var maxLength = max;
	// Get from clipboard
	var data = window.clipboardData.getData("Text");

	var CurrentLength = o.value.length + data.length;
    if (CurrentLength > maxLength)
    {
		alert('You are only able to make a maximum payment of $99,999. Please reduce the amount and try again');
		return false;
	}
	else
		return true;
}
//mask input to allow integer only
function CheckNumeric(objEvent) {
	var iKeyCode, strKey;  
	var reValidChars = /\d/;	
	var reKeyboardChars =       /[\x00\x03\x08\x0D\x16\x18\x1A]/;
	if (isIE) {
		iKeyCode = objEvent.keyCode;
	} else {
		iKeyCode = objEvent.which;
	}
	
	strKey = String.fromCharCode(iKeyCode);
	
	if (!reValidChars.test(strKey) && !reKeyboardChars.test(strKey)) {
		return false;
	}
}

 function gup( name )
{
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    if( results == null )
      return "";
    else
      return results[1];
}                              

function setupSlider() {
	$('#friendtoggle').toggle(function(){
		$(this).removeClass("e2afCLOSED");
		$(this).next().show();
		$('#fff').hide();
	},function(){
		$(this).addClass("e2afCLOSED");
		$(this).next().hide();
		$('#fff').show();
	});	
}



function checkBackButton(counter) {
	if (counter) {
		$(".btn-left").show();
	}

	else {
		$("#page-buttons .btn-left").hide();
	}
}

function checkContinueButton(counter,max) {
	if (counter == (max - 1)) {
		$("#page-buttons .btn-continue").hide();
		$("#page-buttons .btn-submit").show();
	}

	else {
		$("#page-buttons .btn-continue").show();
		$("#page-buttons .btn-submit").hide();
	}
}


// BROKER TESTIOMONIAL FUNCTIONS

function ShowBrokerTestimonialHome()
{
        $("#crumbs li:contains('Home')").remove();
		$('#crumbs li.jsCrumb').remove();
		$('#crumbs').append("<li class='jsCrumb'><a href='#brokerhome'>Home</a></li>");
		/*
		$('.bbdpanel:visible').hide();
		$('#brokernews').show();
		$('#bbdhome').show();
		$('#broker-photos').show();	
		$('#broker-dodge').show();	*/
		if ($('#testimonial_0').length > 0)
		{
		    $('#testimonial_0').show();
		    $('#testimonial_1').hide();
		    $('#testimonial_2').hide();
		    $('#testimonial_3').hide();
		}
}

function ShowBrokerTestimonialNewsletter()
{
        $("#crumbs li:contains('Home')").remove();
		$('#crumbs li.jsCrumb').remove();
		$('#crumbs').append("<li class='jsCrumb'><a href='#newsletter'>Newsletter</a></li>");
	    
		/*							
		$('.bbdpanel:visible').hide();
		$('#brokernews').hide();
		$('#broker-dodge').hide();	
		$('#broker-photos').hide();	
		$('#bbdnews').show();*/
		
		if ($('#testimonial_2').length > 0)
		{
		    $('#testimonial_0').hide();
		    $('#testimonial_1').hide();
		    $('#testimonial_2').show();
		    $('#testimonial_3').hide();
		}
}

function ShowBrokerTestimonialBusiness()
{
        $("#crumbs li:contains('Home')").remove();
		$('#crumbs li.jsCrumb').remove();
		$('#crumbs').append("<li class='jsCrumb'><a href='#business'>Business &amp; Community</a></li>");
		
		/*
		$('.bbdpanel:visible').hide();
		$('#brokernews').hide();
		$('#broker-photos').hide();
		$('#broker-dodge').hide();	
		$('#bbdbusiness').show();*/
		
		if ($('#testimonial_3').length > 0)
		{
		    $('#testimonial_0').hide();
		    $('#testimonial_1').hide();
		    $('#testimonial_2').hide();
		    $('#testimonial_3').show();
		}
}

function ShowBrokerTestimonialTeam()
{
        $("#crumbs li:contains('Home')").remove();
		$('#crumbs li.jsCrumb').remove();
		$('#crumbs').append("<li class='jsCrumb'><a href='#team'>Our Team</a></li>");
		
		/*
		$('.bbdpanel:visible').hide();
		$('#brokernews').hide();
		$('#bbdteam').show();
		$('#broker-photos').hide();
		$('#broker-dodge').hide();	*/
		
		if ($('#testimonial_1').length > 0)
		{
		    $('#testimonial_0').hide();
		    $('#testimonial_1').show();
		    $('#testimonial_2').hide();
		    $('#testimonial_3').hide();
		}
}



function DisplayBrokerTesimonials() {

    $(document).ready(function() {

        $('#testimonial_0').show();

        if (gup('nav') == 'newsletter') {
            ShowBrokerTestimonialNewsletter();
        }
        else if (gup('nav') == 'business') {
            ShowBrokerTestimonialBusiness();
        }
        else if (gup('nav') == 'team') {
            ShowBrokerTestimonialTeam();
        }

    });
}


$(document).ready(function() {
	var counter = 0;
	var max = $(".pagePanel").length;


	$("#page-buttons .btn-continue").bind("click", function(e){
	    
	    if (counter == 0 || Validate(counter))
	    {
			
		    $(".pagePanel:eq("+counter+")").hide();
		    $(".pagePanel:eq("+(counter+1)+")").show();	

		    $("#paging ul li").removeClass("current");
		    $("#paging ul li:eq("+(counter+2)+")").addClass("current");
    		
		    counter += 1;

		    checkBackButton(counter);
		    checkContinueButton(counter,max);
		}
    });


	$("#page-buttons .btn-goback").bind("click", function(e){
		$(".pagePanel:eq("+counter+")").hide();
		$(".pagePanel:eq("+(counter-1)+")").show();	

		$("#paging ul li").removeClass("current");
		$("#paging ul li:eq("+(counter)+")").addClass("current");
		
		counter -= 1;

		checkBackButton(counter);
		checkContinueButton(counter,max);
    });
});


$(document).ready( function() {
	$(".bbdpanel a").attr('target','_blank');
});

$(document).ready(function() {
	$('#search_box').keydown(function(e){
		if (e.keyCode == 13) {
			DOSearch();
			return false;
		}
	});
});
function Print(elementName) {
    var headID = document.getElementsByTagName("head")[0];
    var cssNode = document.createElement('link');
    cssNode.type = 'text/css';
    cssNode.rel = 'stylesheet';
    if (isIE) {
        cssNode.href = 'includes/googleprintie.css';
    } else {
        cssNode.href = 'includes/googleprint.css';
    }
    cssNode.media = 'print';
    $(".ui-dialog-overlay").hide();
    marker.closeInfoWindow();
    headID.appendChild(cssNode);
    window.print();
    
}