/***********************************************************************************************************************

jbrowser.js : Website Functionality

Author:          Bruce Arnold (bruce@webredesignmiami.com)
Copyright:       2010 (c) Bruce Arnold & WebReDesignMiami.com  
License:         All Rights Reserved

************************************************************************************************************************/

function slide(navigation_id, pad_out, pad_in, time, multiplier)
{
	// creates the target paths
	var list_elements = navigation_id + " li.accident-liability";
	var link_elements = list_elements + " a";
	
	// initiates the timer used for the sliding animation
	var timer = 0;
	
	// creates the slide animation for all list elements 
	$(list_elements).each(function(i)
	{
		$(this).css("margin-left","-400px");
		// updates timer
		timer = (timer*multiplier + time);
		$(this).animate({ marginLeft: "0" }, timer);
		$(this).animate({ marginLeft: "15px" }, timer);
		$(this).animate({ marginLeft: "0" }, timer);
	});

	// creates the hover-slide effect for all link elements 	
      document.getElementById('insurance-coverage').className='show';
	$(link_elements).each(function(i)
	{
		$(this).hover(
		function()
		{
			$(this).animate({ paddingLeft: pad_out }, time);
		},		
		function()
		{
			$(this).animate({ paddingLeft: pad_in }, time);
		});
	});
}

function check_it(the_form){
    var illegalChars1= /[\(\)\<\>\,\;\:\\\/\"\@\[\]]/
    if (the_form.Contact_Name.value.match(illegalChars1)) {
        alert('Contact name contains illegal characters');
        the_form.Contact_Name.focus();
        return false;    
    }
    var illegalChars2= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
    if (the_form.email.value.match(illegalChars2)) {
        alert('The email address contains illegal characters');
        the_form.email.focus();
        return false;    
    }
    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(the_form.email.value))) { 
        alert('Please enter a valid email address');
        the_form.email.focus();
        return false;    
    }
    if(the_form.email.value != the_form.email_confirm.value){
        alert('Email address does not match Email Confirm.');
        the_form.email.focus();
        return false;
    }
    var illegalChars3= /[\<\>\\\/\[\]]/
    if (the_form.Message_Text.value.match(illegalChars3)) {
        alert('Message text contains illegal characters');
        the_form.Message_Text.focus();
        return false;    
    }
    var checkdigit4 = parseInt(the_form.checkdigit1.value)+ parseInt(the_form.checkdigit2.value);
    if(parseInt(the_form.checkdigit3.value) != checkdigit4 ){
        alert('Invalid Spam Check Digit.');
        the_form.checkdigit3.focus();
        return false;
   }
   return true;
}

sfFocus = function() { 
  var sfEls1 = document.getElementsByTagName("input"); 
  for (var i=0; i<sfEls1.length; i++) { 
    if(sfEls1[i].getAttribute("type") != "checkbox") {
      sfEls1[i].onfocus=function() { this.className="sfFocus"; } 
      sfEls1[i].onblur=function() { this.className="formbox"; } 
    } 
  } 
  var sfEls2 = document.getElementsByTagName("select"); 
  for (var i=0; i<sfEls2.length; i++) { 
    sfEls2[i].onfocus=function() { this.className="sfFocus"; } 
    sfEls2[i].onblur=function() { this.className="formbox"; } 
  } 
  var sfEls3 = document.getElementsByTagName("textarea"); 
  for (var i=0; i<sfEls3.length; i++) { 
    sfEls3[i].onfocus=function() { this.className="sfFocus"; } 
    sfEls3[i].onblur=function() { this.className="formbox"; } 
  } 
} 
if (window.attachEvent) window.attachEvent("onload", sfFocus); 

// DOCUMENT READY FUNCTIONS
$(function() {
  // LINKS
  if (!document.getElementsByTagName) return; 
  var anchors = document.getElementsByTagName("a"); 
  for (var i=0; i<anchors.length; i++) { 
    var anchor = anchors[i]; 
    // EXTERNAL
      if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "external" || anchor.getAttribute("rel") == "external nofollow" )){ 
      anchor.target = "_blank"; 
    }
    // ADD2FAVS
    if ( anchor.className == "add2Favs" ){
      anchor.onclick = function(){
        var titlef = document.title;
        var urlf = location.href;
        if (window.sidebar) { 
          window.sidebar.addPanel(titlef, urlf,""); 
        } 
        else if( document.all ) {
          window.external.AddFavorite( urlf, titlef);
        } 
        else if( window.opera && window.print ) {
          return true;
        }
        return false;
      }
    }
    // ADD2SOCIAL
    if ( anchor.className == "add2Social" ){
      anchor.onclick = function(){
        var titlef = document.title;
        var urlf = location.href;
	  // window.location = 'http://www.tagenie.com/submit.php?url='+encodeURIComponent(urlf)+'&amp;title='+encodeURIComponent(titlef)+'';
	  window.open('http://www.addthis.com/bookmark.php?v=250&username=&url='+encodeURIComponent(urlf)+'&title='+encodeURIComponent(titlef)+'','_blank');        
	  return false;
      }
    }
  } 
  // BEG formInit 
  if ( document.getElementById('Contact') )
  {
    document.getElementById('Contact').onsubmit = function () {
      return check_it(this)
    }
    document.getElementById('Message_Text').onclick = function () {
      var defaultText = 'Your questions or comments can be entered here...';
      if ( this.value == defaultText ){ this.value = ''; }
    }
  }
  // END formInit
  $("#managing-general-agency-2").animate({
	bottom: "0px"
  }, 1500, 'swing', function() {
      slide("#insurance-coverage", 25, 15, 150, .8);
  });
  $('#personal-lines').animate({
	top: "0px"
  }, 1500, 'swing', function() {
      $('#Contact_Name').focus();
  });
  $('#commercial-lines').animate({
	bottom: "20px"
  }, 1500, 'swing', function() {
  });
});

$(window).bind('beforeunload', function() { 
 $("#managing-general-agency-2").animate({
	bottom: "-1500px"
  }, 500, "swing");
 $("#personal-lines").animate({
	top: "-1500px"
  }, 500, "swing");
 $("#commercial-lines").animate({
	bottom: "-1500px"
  }, 500, "swing");
});





