function CheckEmail( field ) {
	
	//var field = document.getElementById( fieldName );
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; 
	if (!filter.test(field.value)) {
		alert( 'Please provide a valid email address' ); 
		field.focus;
	}
	
} 

function CheckPhone( field )
{
	
	
	//var field = document.getElementById( fieldName );
	var entry = field.value.replace(' ', '' );
	field.value = entry.replace('.', '-' );
	
	var filter = /^[\\(]{0,1}([0-9]){3}[\\)]{0,1}[ ]?([^0-1]){1}([0-9]){2}[ ]?[-]?[ ]?([0-9]){4}[ ]*((x){0,1}([0-9]){1,5}){0,1}$/;
	if (!filter.test(field.value)) {
		alert( 'Please provide a valid phone number in this format: (555)555-5555' ); 
		field.focus;
	}
	
}

function CheckExt( field )
{
	
	//var field = document.getElementById( fieldName );
	var filter = /^\d*$/;
	if (!filter.test(field.value)) {
		alert( 'Please provide a valid extension number' );
		field.focus;
	}
	
}

function formatPhone( field )
{
	var entry = field.value.replace(' ', '' );
	entry = entry.replace('.', '-' );
	
	if( entry.substring(0, 1) != '(' )
	{
		field.value = '(' + entry;
	}
	
	if( entry.length > 4 && entry.substring(4, 5) != ')' )
	{
		field.value = entry.substring(0, 4) + ')' + entry.substring(4);
	}
	
	
	
	if( entry.length > 8 && entry.substring(8, 9) != '-' )
	{
		field.value = entry.substring(0, 8) + '-' + entry.substring(8);
	}
	
	
	
}

function CheckForm()
{
	var error_msg;
	var error_div = document.getElementById( "error" );
	
	var requiredfields = new Array( 'company', 'nameFld', 'street', 'city', 'state', 'zip', 'email1', 'email2', 'phone_biz'  ); 
	var validfields =    new Array( 'phone_biz', 'phone_cell', 'fax','extension'  ); 
	
	var validated = true;
	for( var index = 0; index < requiredfields.length; index++ )
	{
		
		inputfield = document.getElementById( requiredfields[ index ] );
		
		if( inputfield.value == '' )
		{
			inputfield.style.backgroundColor = "#F9E5E5";
			validated = false;
		
		} else {
			
			inputfield.style.backgroundColor = "#FFFFFF";
		}
	}
	
	var filter;
	
	for( index = 0; index < validfields.length; index++ )
	{
		
		inputfield = document.getElementById( validfields[ index ] );
		
		if( inputfield.value != '' )
		{
			filter = validfields[ index ] == 'extension' ? /^\d*$/ : /^[\\(]{0,1}([0-9]){3}[\\)]{0,1}[ ]?([^0-1]){1}([0-9]){2}[ ]?[-]?[ ]?([0-9]){4}[ ]*((x){0,1}([0-9]){1,5}){0,1}$/;
			if (!filter.test(inputfield.value)) {
				inputfield.style.backgroundColor = "#F9E5E5";
				validated = false;
			}
		
		}
	}
	
	inputfield = document.getElementById( 'email1' );
	filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(inputfield.value)) {
		
		inputfield.style.backgroundColor = "#F9E5E5";
		validated = false;
	}
	
	
	if( document.getElementById( "email1" ).value != document.getElementById( "email2" ).value )
	{
		alert( "Your email addresses do not match." );
		return false;
		
	} else {
	
		if( validated )
		{
			error_msg = document.createTextNode( "Submiting your request" );
			//error_div.replaceChild( error_msg, error_div.firstChild );
			return true;
			
		} else {
			
			error_msg = document.createTextNode( "Please correct your request" );
			error_div.replaceChild( error_msg, error_div.firstChild );
			
			return false;
		}
	}
}




/************************************************************************
 * BEGIN jQuery PNG fix
 */

var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
var blank = new Image();
blank.src = 'images/_global/clear.gif';

function runPNGfix() {

	
	
	if ( badBrowser ) {
		
		// get all pngs on page
		
		$('img[src$=.png]').each(function() {
			
			if (!this.complete) {
			
				this.onload = function() { fixPng(this) };
			
			} else {
				
				fixPng(this);
			}
			
		});
		
		
		/*try {
            
            var oDivNodes = document.getElementsByTagName('div');
            for (var iIndex=0; iIndex<oDivNodes.length; iIndex++)
            {
            
                var oNode = oDivNodes.item(iIndex);
                
                if ( oNode.currentStyle && oNode.currentStyle.backgroundImage && ( oNode.currentStyle.backgroundImage.indexOf( 'url(' ) != -1 ) && ( oNode.currentStyle.backgroundImage.indexOf( '.png")' ) != -1 ) )
                {
                    fixupIEPNGBG(oNode);
                }
                
            }
        }
        
        catch (e) { }*/
	}
	
	
 
  
};

function fixPng( png ) {

	var src = png.src;
	if ( !png.style.width ) { 
  
    	png.style.width = $(png).width(); 
	}
	
	if ( !png.style.height ) { 
		
		png.style.height = $(png).height(); 
	}

	png.onload = function() { };
	png.src = blank.src;
	png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')";

}

 

$(document).ready(function() {


  	runPNGfix();
  
	$( "body" ).find( ".btn" ).each(function(i) {
	    
    
     $(this).mouseover(function() {
     	
     	var src = this.src;
     	this.src = src.replace( '_off', '_on' );
     	
     });
     
     
     $(this).mouseout(function() {
     	
     	var src = this.src;
     	this.src = src.replace( '_on', '_off' );
     	
     });
     
   });
   
   
   $( "#navigation" ).find( "img" ).each(function(i) {
   		
   		$(this).mouseout(function() {
     	
     		$( "#navigation" ).css( { 'background-image' : 'url( images/_global/nav_off.png )' }) ;
     	
   		});
   	
   });
   
   $( "#btn_flood" ).mouseover(function() {
     	
      	$( "#navigation" ).css( { 'background-image' : 'url( images/_global/nav_flood.png )' }) ;
     	
   });
     
   $( "#btn_trv" ).mouseover(function() {
     	
      	$( "#navigation" ).css( { 'background-image' : 'url( images/_global/nav_trv.png )' }) ;
     	
   });
   
   
   $( "#btn_sign_up" ).mouseover(function() {
     	
      	$( "#navigation" ).css( { 'background-image' : 'url( images/_global/nav_sign_up.png )' }) ;
     	
   });
   
   
   $( "#btn_about_us" ).mouseover(function() {
     	
      	$( "#navigation" ).css( { 'background-image' : 'url( images/_global/nav_about_us.png )' }) ;
     	
   });


});


if( document.images )
{
		
	preload_nav1 = new Image(456,30); 
	preload_nav1.src = "images/_global/nav_flood.png";
	
	preload_nav2 = new Image(456,30); 
	preload_nav2.src = "images/_global/nav_trv.png";
	
	preload_nav3 = new Image(456,30); 
	preload_nav3.src = "images/_global/nav_sign_up.png";
	
	
	preload_nav4 = new Image(456,30); 
	preload_nav4.src = "images/_global/nav_about_us.png";

}


