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

jbrowser.js : Website Functionality

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

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

// DISABLE-ENTER
function checkCR(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;}
}
document.onkeypress = checkCR; // attach the function to the onkeypress event

// TWITTER UPDATE
function loadSearch1() {
	$.ajax({
	type: "GET",
	url: "./php/search.php",
	cache: false,
	beforeSend: function(html) 
	{
  	  document.getElementById("insert_search").innerHTML = ''; 
	  $('#update1').removeClass('hide');
	  $("#update1").html('...Experience Posada...');	               
      },
	success: function(html)
	{
	  $('#update1').addClass('show');
	  $("#insert_search").append(html);
	  $('#update1').addClass('hide');
	  $(function() {
		$("#insert_search a").attr("target", "_blank");
	  });
	}
	});
}

// LOAD KUDOS
function loadKudos1() {
	$.ajax({
	type: "GET",
	url: "./php/kudos1.php",
	cache: false,
	beforeSend: function(html) 
	{
        if($.browser.msie){
          document.getElementById('kudos-overlay1').className='hide';
        }else{
          $('#kudos-overlay1').fadeTo('slow',0);
        }
 	  $('#kudos-update1').removeClass('hide');
        $('#kudos-update1').fadeTo('slow',1);
	  document.getElementById("kudos-insert1").innerHTML = ''; 
	},
	success: function(html)
	{
	  $('#kudos-update1').addClass('show');
        $('#kudos-update1').fadeTo('slow',0);
	  document.getElementById("kudos-insert1").innerHTML = html; 
	  $('#kudos-update1').addClass('hide');
        if($.browser.msie){
          document.getElementById('kudos-overlay1').className='show';
        }else{
          $('#kudos-overlay1').fadeTo('slow',1);
        }
	}
	});
}

// DOCUMENT READY FUNCTIONS
$(function() {
  // LOAD VIDEOS
  $(".loadvideo1").click(function(){ 
    var url = $(this).attr('href');
    var vid = url.split("=")[1]; 
    var videoString = html5video("motivational-speaker-" + vid,"motivational_speaker_video/" + vid,
    "jpg","ogg","mp4","mp4","js","false","false","false","true","480","320","return");
    document.getElementById("speaker-video").innerHTML = videoString;
    return false;
  });
  // 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 UPDATE1
  if ( document.getElementById('kudos-ajax-1') )
  {
  $(function() {
  $(document).ready(function() {
      loadKudos1();
      setInterval("loadKudos1()",30000);
  });
  });
  }
  // END UPDATE1
  // BEG UPDATE2
  if ( document.getElementById('web30-twitter-4') )
  {
  $(function() {
  $(document).ready(function() {
      loadSearch1();
      setInterval("loadSearch1()",60000);
  });
  });
  }
  // END UPDATE2
});

// FORM FOCUS
sfFocus = function() { 
  if ( document.getElementById('Contact') )
  {

  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); 

// FORM CHECK
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;
}

// FOR BIG FIVE TEST
function mastervalidateLogin(frm)
{
	if(frm.name.value=="")
	{
alert("Please Enter Your Name");
frm.name.focus();
return false;
	}
	if(frm.email.value=="")
	{
alert("Please Enter Your Email Address");
frm.email.focus();
return false;
	}
 var Email=frm.email.value;
	
	if (Email.indexOf('@', 0) == -1 || Email.indexOf('.', 0) == -1)
	{ 
	alert("Please Enter A Valid Email Address");
	frm.email.focus();
	return false;
	}
}


