$(document).ready(function() {

	//$('input[type=button]').attr('disabled', 'disabled');
	
	
//EMAIL --------------------------------------------------------------------------------------------------------
	var checkEmail = function (email) {
		$("#field3_box").removeClass().addClass('messagebox').text('Checking your Email...').fadeIn("slow"); 
		var email = $("#field3").val();	

		if (email=='') {	 //a1a
  			$("#field3_box").removeClass().addClass('messageboxerror').text('Enter valid email').fadeIn("slow");
			$('input[type=button]').attr('disabled', true); 
 		}
 		else {		//a1a
		
		
		$.post(
			"php_bin/validateForm.php",
			{check: 'field3', emailAddress: email},
			function(data) {
				if(data=='no') { //if username not avaiable	
				  	$("#field3_box").fadeTo(200,0.1,function() { //start fading the messagebox
						//add message and change the class of the box and start fading
			  			$(this).html('Email address unavailable for Quote Request!').addClass('messageboxerror').fadeTo(900,1);
						$('input[type=button]').attr('disabled', true);
					});		
          			}
		  		else if(data=='invalid') { //if username not avaiable
				  	$("#field3_box").fadeTo(200,0.1,function() { //start fading the messagebox
						//add message and change the class of the box and start fading
			  			$(this).html('Email address provided is invalid!').addClass('messageboxerror').fadeTo(900,1);
						$('input[type=button]').attr('disabled', true);
					});		
          			}
		  		else if(data=='yes'){
		  			$("#field3_box").fadeTo(200,0.1,function() {  //start fading the messagebox
			  			//add message and change the class of the box and start fading
			 		 	$(this).html('Email address is ok for Quote Request!').addClass('messageboxok').fadeTo(900,1);
						$('input[type=button]').attr('disabled', false);	
					});
		  		}
				else if(data=='no_db_server_connection') {
					$("#field3_box").fadeTo(200,0.1,function() {  //start fading the messagebox
			  			//add message and change the class of the box and start fading
			 		 	$(this).html('The mySQL server is down!').addClass('messageboxerror').fadeTo(900,1);
						$('input[type=button]').attr('disabled', true);
					});
				}
				else if(data=='no_db_connection') {
					$("#field3_box").fadeTo(200,0.1,function() {  //start fading the messagebox
			  			//add message and change the class of the box and start fading
			 		 	$(this).html('The specified database does not exist!').addClass('messageboxerror').fadeTo(900,1);
						$('input[type=button]').attr('disabled', true);
					});
				}	
			}			
		)	 
		
 			
 		}	 //a1a
		
		
	}		 
	$("#field3").blur(checkEmail); 
// ******************  EMAIL --------------------------------------------------------------------------------------------------------
  
	
// TELEPHONE --------------------------------------------------------------------------------------------------------
	var checkPhone = function (phone) {
		$("#field4_box").removeClass().addClass('messagebox').text('Checking your Phone...').fadeIn("slow"); 
		var phone = $("#field4").val();	

		if (phone=='') {	 //a2a
  			$("#field4_box").removeClass().addClass('messageboxerror').text('Please enter your Phone!').fadeIn("slow");
			$('input[type=button]').attr('disabled', true); 
 		}
 		else {		//a2a
		
		
		$.post(
			"php_bin/validateForm.php",
			{check: 'field4', phoneAddress: phone},
			function(data) {
				if(data=='invalid') { //if username not avaiable
				  	$("#field4_box").fadeTo(200,0.1,function() { //start fading the messagebox
						//add message and change the class of the box and start fading
			  			$(this).html('Phone is invalid! Your phone need to be: 123.123.1234').addClass('messageboxerror').fadeTo(900,1);
						$('input[type=button]').attr('disabled', true);
					});		
          			}
		  		else if(data=='yes'){
		  			$("#field4_box").fadeTo(200,0.1,function() {  //start fading the messagebox
			  			//add message and change the class of the box and start fading
			 		 	$(this).html('The Phone is ok for Quote Request!').addClass('messageboxok').fadeTo(900,1);
						$('input[type=button]').attr('disabled', false);	
					});
				}	
			}			
		)	 
		
 			
 		}	 //a2a
		
		
	}		 	
	//$("#field4").blur(checkPhone); 
// ******************  TELEPHONE --------------------------------------------------------------------------------------------------------


// AREACODE --------------------------------------------------------------------------------------------------------
	var checkAreaCode = function (areacode) {
		$("#field18_box").removeClass().addClass('messagebox').text('Checking your Area Code...').fadeIn("slow"); 
		var areacode = $("#field18").val();	

		if (areacode=='') {	 //a2a
			$("#field18_box").fadeTo(200,0.1,function() {  //start fading the messagebox
			  			//add message and change the class of the box and start fading
			 		 	$(this).html('Area Code not requiered!').addClass('messageboxok').fadeTo(900,1);
						//$('input[type=button]').attr('disabled', false);	
					});
 		}
 		else {		//a2a
		
		
		$.post(
			"php_bin/validateForm.php",
			{check: 'field18', areacodeAddress: areacode},
			function(data) {
				if(data=='invalid') { //if username not avaiable
				  	$("#field18_box").fadeTo(200,0.1,function() { //start fading the messagebox
						//add message and change the class of the box and start fading
			  			$(this).html('Your Area Code need to be: 123 or 123 134 ').addClass('messageboxerror').fadeTo(900,1);
						$('input[type=button]').attr('disabled', true);
					});		
          			}
		  		else if(data=='yes'){
		  			$("#field18_box").fadeTo(200,0.1,function() {  //start fading the messagebox
			  			//add message and change the class of the box and start fading
			 		 	$(this).html('The Area Code is ok for Quote Request!').addClass('messageboxok').fadeTo(900,1);
						$('input[type=button]').attr('disabled', false);	
					});
				}	
			}			
		)	 
		
 			
 		}	 //a2a
		
		
	}		 	
	//$("#field18").blur(checkAreaCode); 
// ******************  AREACODE --------------------------------------------------------------------------------------------------------

});
	
	 /*
	var state = 'none'; 
	
	function showhide(layer_ref) { 
	
		if (state == 'block') { 
			state = 'none'; 
		} 
		else 
		{ 
			state = 'block'; 
		}  
		
		if (document.all) { //IS IE 4 or 5 (or 6 beta) 
			eval( "document.all." + layer_ref + ".style.display = state"); 
		} 
		
		if (document.layers) { //IS NETSCAPE 4 or below 
			document.layers[layer_ref].display = state; 
		}  
		
		if (document.getElementById &&!document.all) { 
			hza = document.getElementById(layer_ref); 
			hza.style.display = state; 
		} 
	} 
				 
	
	   	*/
		
	function show_info() { 
	
		var state = 'block'; 
		var layer_ref1 = 'tr_field15'; 
		var layer_ref2 = 'tr_field16'; 
		var layer_ref3 = 'tr_field17'; 
		   
		if (document.all) { //IS IE 4 or 5 (or 6 beta) 
			eval( "document.all." + layer_ref1 + ".style.display = state"); 
			eval( "document.all." + layer_ref2 + ".style.display = state"); 
			eval( "document.all." + layer_ref3 + ".style.display = state"); 
		} 
		
		if (document.layers) { //IS NETSCAPE 4 or below 
			document.layers[layer_ref1].display = state; 
			document.layers[layer_ref2].display = state; 
			document.layers[layer_ref3].display = state; 
		}  
		
		if (document.getElementById &&!document.all) { 
			hza1 = document.getElementById(layer_ref1); 
			hza2 = document.getElementById(layer_ref2); 
			hza3 = document.getElementById(layer_ref3);
			hza1.style.display = state; 
			hza2.style.display = state; 
			hza3.style.display = state; 
		} 
		
	} 
			 
	
	function hide_info() { 
		var state = 'none'; 
		var layer_ref1 = 'tr_field15'; 
		var layer_ref2 = 'tr_field16'; 
		var layer_ref3 = 'tr_field17'; 
		   
		if (document.all) { //IS IE 4 or 5 (or 6 beta) 
			eval( "document.all." + layer_ref1 + ".style.display = state"); 
			eval( "document.all." + layer_ref2 + ".style.display = state"); 
			eval( "document.all." + layer_ref3 + ".style.display = state"); 
		} 
		
		if (document.layers) { //IS NETSCAPE 4 or below 
			document.layers[layer_ref1].display = state; 
			document.layers[layer_ref2].display = state; 
			document.layers[layer_ref3].display = state; 
		}  
		
		if (document.getElementById &&!document.all) { 
			hza1 = document.getElementById(layer_ref1); 
			hza2 = document.getElementById(layer_ref2); 
			hza3 = document.getElementById(layer_ref3); 
			hza1.style.display = state; 
			hza2.style.display = state; 
			hza3.style.display = state; 
		} 
	} 
							 
		
	function show_info_email() { 
	
		var state = 'block'; 
		var layer_ref1 = 'tr_field20'; 
		var layer_ref2 = 'tr_field21'; 
		var layer_ref3 = 'tr_field22'; 
		   
		if (document.all) { //IS IE 4 or 5 (or 6 beta) 
			eval( "document.all." + layer_ref1 + ".style.display = state"); 
			eval( "document.all." + layer_ref2 + ".style.display = state"); 
			eval( "document.all." + layer_ref3 + ".style.display = state"); 
		} 
		
		if (document.layers) { //IS NETSCAPE 4 or below 
			document.layers[layer_ref1].display = state; 
			document.layers[layer_ref2].display = state; 
			document.layers[layer_ref3].display = state; 
		}  
		
		if (document.getElementById &&!document.all) { 
			hza1 = document.getElementById(layer_ref1); 
			hza2 = document.getElementById(layer_ref2); 
			hza3 = document.getElementById(layer_ref3);
			hza1.style.display = state; 
			hza2.style.display = state; 
			hza3.style.display = state; 
		} 
		
	} 
			 
	
	function hide_info_email() { 
		var state = 'none'; 
		var layer_ref1 = 'tr_field20'; 
		var layer_ref2 = 'tr_field21'; 
		var layer_ref3 = 'tr_field22'; 
		   
		if (document.all) { //IS IE 4 or 5 (or 6 beta) 
			eval( "document.all." + layer_ref1 + ".style.display = state"); 
			eval( "document.all." + layer_ref2 + ".style.display = state"); 
			eval( "document.all." + layer_ref3 + ".style.display = state"); 
		} 
		
		if (document.layers) { //IS NETSCAPE 4 or below 
			document.layers[layer_ref1].display = state; 
			document.layers[layer_ref2].display = state; 
			document.layers[layer_ref3].display = state; 
		}  
		
		if (document.getElementById &&!document.all) { 
			hza1 = document.getElementById(layer_ref1); 
			hza2 = document.getElementById(layer_ref2); 
			hza3 = document.getElementById(layer_ref3); 
			hza1.style.display = state; 
			hza2.style.display = state; 
			hza3.style.display = state; 
		} 
	} 
	
	/* ***********************************************************/
	/* ***********************************************************/	 
	function show_State_Province_choice() { 
	
		var state = 'block'; 
		var layer_ref1 = 'tr_field12_choice'; 
		   
		if (document.all) { //IS IE 4 or 5 (or 6 beta) 
			eval( "document.all." + layer_ref1 + ".style.display = state"); 
		} 
		
		if (document.layers) { //IS NETSCAPE 4 or below 
			document.layers[layer_ref1].display = state; 
		}  
		
		if (document.getElementById &&!document.all) { 
			hza1 = document.getElementById(layer_ref1); 
			hza1.style.display = state; 
		} 
		
	} 
			 
	
	function hide_State_Province_choice() { 
		var state = 'none'; 
		var layer_ref1 = 'tr_field12_choice'; 
		   
		if (document.all) { //IS IE 4 or 5 (or 6 beta) 
			eval( "document.all." + layer_ref1 + ".style.display = state"); 
		} 
		
		if (document.layers) { //IS NETSCAPE 4 or below 
			document.layers[layer_ref1].display = state; 
		}  
		
		if (document.getElementById &&!document.all) { 
			hza1 = document.getElementById(layer_ref1); 
			hza1.style.display = state; 
		} 
	} 
	/* ***********************************************************/
	/* ***********************************************************/		
	
	
	/* ***********************************************************/
	/* ***********************************************************/	 
	function show_State_Province_enter() { 
	
		var state = 'block'; 
		var layer_ref1 = 'tr_field12_enter'; 
		   
		if (document.all) { //IS IE 4 or 5 (or 6 beta) 
			eval( "document.all." + layer_ref1 + ".style.display = state"); 
		} 
		
		if (document.layers) { //IS NETSCAPE 4 or below 
			document.layers[layer_ref1].display = state; 
		}  
		
		if (document.getElementById &&!document.all) { 
			hza1 = document.getElementById(layer_ref1); 
			hza1.style.display = state; 
		} 
		
	} 
			 
	
	function hide_State_Province_enter() { 
		var state = 'none'; 
		var layer_ref1 = 'tr_field12_enter'; 
		   
		if (document.all) { //IS IE 4 or 5 (or 6 beta) 
			eval( "document.all." + layer_ref1 + ".style.display = state"); 
		} 
		
		if (document.layers) { //IS NETSCAPE 4 or below 
			document.layers[layer_ref1].display = state; 
		}  
		
		if (document.getElementById &&!document.all) { 
			hza1 = document.getElementById(layer_ref1); 
			hza1.style.display = state; 
		} 
	} 
	/* ***********************************************************/
	/* ***********************************************************/
