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

jbrowser.js : Website Functionality

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

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

// TWITTER UPDATE
function loadSearch1() {
	$.ajax({
	type: "GET",
	url: "./php/search.php",
	cache: false,
	beforeSend: function(html) 
	{
  	  document.getElementById("insert_search").innerHTML = ''; 
	  // $("#update1").show();
	  $('#update1').removeClass('hide');
	  $("#update1").html('Ajax/jQuery Update...');	               
      },
	success: function(html)
	{
	  // $("#insert_search").show();
	  $('#update1').addClass('show');
	  $("#insert_search").append(html);
	  // $("#update1").hide();
	  $('#update1').addClass('hide');
	  $(function() {
		$('a[href^="http://"]')  .attr("target", "_blank");
		$('a[href^="http://webredesignmiami.com"]')  .attr("target", "_self");
		$('a[href^="http://www.webredesignmiami.com"]')  .attr("target", "_self");
		$('a[href^="http://miamiwebredesign.com"]')  .attr("target", "_self");
		$('a[href^="http://www.miamiwebredesign.com"]')  .attr("target", "_self");
	  });
	}
	});
}

// MUSIC TOGGLE
$(function() {
  if ( document.getElementById('audio1') ){
    document.getElementById('audio1').onclick = function(){
      play_audio('html5_audio/Antoine_de_Saint_Exupery.mp3');
      return false;
    }
  }
});

// DOCUMENT READY
$(function() {
  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.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)+'';
        return false;
      }
    }
  } 
  // LIGHTBOXINIT
  if ( document.getElementById('contact-web-designer') )
  {
     var lightbox1 = document.getElementById('contact-web-designer');   
     lightbox1.onmouseover = function(){ document.getElementById('fade').style.display='block' }
     lightbox1.onmouseout  = function(){ document.getElementById('fade').style.display='none' }
  }
  // BEG writePhpTACookie
	date=new Date;
	date.setMonth(date.getMonth()+1);
	var name = "phpTA_resolution";
	var value = screen.width +"x"+ screen.height;
	var domain = "webredesignmiami.com";
	var path= "/";
	document.cookie=name+"="+escape(value)+"; expires="+date.toGMTString()+"; path="+path+"; domain="+domain;
  // *** MAIN DISPLAY ***
  if ( document.getElementById('web-design-miami-florida') ) 
  {
    document.getElementById('web-design-miami-overlay').className='hide';
    document.getElementById('web-design-miami-florida').className='show';
  }
  // 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 = ''; }
  }
  document.forms["Contact"].Contact_Name.focus()
  }
  // TWITTER UPDATE INIT
  if ( document.getElementById('web30-twitter-4') )
  {
  $(function() {
  $(document).ready(function() {
      loadSearch1();
      setInterval("loadSearch1()",30000);
  });
  });
  }
});

// SCREENSHOTS
function websiteredesignmiami1()
{
  document.write('<object type="application/x-shockwave-flash" data="c.swf?path=Website_Redesign_Miami.swf" width="200" height="167">\n');
  document.write('<param name="movie" value="c.swf?path=Website_Redesign_Miami.swf">\n');
  document.write('<param name="quality" value="high">\n');
  document.write('<param name="bgcolor" value="#FFFFFF">\n');
  document.write('<param name="wmode" value="transparent">\n');
  document.write('<img src="./images/Website_Redesign_Miami.jpg" width="200" height="167" alt=""/></object>\n');
}

// HOME FLASH
function miamiwebdesign1()
{
  document.write('<object type="application/x-shockwave-flash" data="c.swf?path=Web_Design_Miami_Web_Designer_8.swf" width="620" height="600">\n');
  document.write('<param name="movie" value="c.swf?path=Web_Design_Miami_Web_Designer_8.swf">\n');
  document.write('<param name="quality" value="high">\n');
  document.write('<param name="bgcolor" value="#FFFFFF">\n');
  document.write('<param name="wmode" value="transparent">\n');
  document.write('<img src="./images/Web_Design_Miami_Web_Designer_FL_2.jpg" width="620" height="600" alt="Web Design Miami"/></object>\n');
}

// 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

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