$(document).ready(function() {
   	promoheight=100;
	if($('#homecol1').height() > promoheight){
		promoheight = $('#homecol1').height();
	}
	if($('#homecol2').height() > promoheight){
		promoheight = $('#homecol2').height();
	}
	if($('#homecol3').height() > promoheight){
		promoheight = $('#homecol3').height();
	}
	$('.homebottomcol').height(promoheight);
	
	
// Trehel Logo Fader Thingy	
	justloaded=true;
//	$(".homelogo").css({opacity:0.0});
//	$(".homelogo").show();
//	$("#homelogo1").stop().animate({opacity:1.0},{queue:false, duration:900});
	
//	$(".homelogo").mouseover(function(){ 
//		if(justloaded){
//			justloaded=false;
//			theid = $(this).attr("id");
//			if(theid !="homelogo1"){
//				$("#homelogo1").stop().animate({opacity:0},{queue:false, duration:900});
//			}
//		}
//		$(this).stop().animate({opacity:1.0},{queue:false, duration:900})
//	}); 
	
//	$(".homelogo").mouseout(function(){ 
//	    $(this).stop().animate({opacity:0},{queue:false, duration:900})
//	}); 
	

// submit home contact form
	$("#successdialog").dialog({ 
    	autoOpen: false, 
        modal: true 
  	}); 

	$("#submithomecontact").click(function(){
	    var errorTxt = ''; 
		$(".error").hide(); 
        var hasError = false; 
        var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/; 
        var thenameVal = $("#thename").val();
        var emailVal = $("#email").val(); 
        var phoneVal = $("#phone").val(); 
        var companyVal = $("#company").val(); 

		var keyVal = $("#key").val();
			
      	if(thenameVal == '' | thenameVal == 'Name') { 
        	errorTxt=errorTxt+"Enter your Name.<br>"; 
            hasError = true;}

		if(companyVal == '' | companyVal == 'Company') { 
			errorTxt=errorTxt+"Enter your Company.<br>"; 
            hasError = true;} 

		if(emailVal == '' | emailVal == 'Email' | !emailReg.test(emailVal)) { 
        	errorTxt=errorTxt+"Enter your Valid email address.<br>"; 
            hasError = true;} 

		if(phoneVal == '' | phoneVal == 'Phone') { 
			errorTxt=errorTxt+"Enter your Phone Number.<br>"; 
            hasError = true;} 


      	// did not pass validation.  show error dialog         
        if(hasError == true) { 
        	$('#errormessage').html(errorTxt); 
            $('#errordialog').dialog('open');} 
                     
     	// passed validation. submit form 
        else{ 
        	$(this).hide(); 
            $("#sendEmail buttons").append('submitting form'); 
                       
            $.post("homecontactsubmit.php", 
            	{ fname: thenameVal, email: emailVal, key:keyVal, phone: phoneVal, company: companyVal }, 
            	function(data){
					if(data.trim()=="success"){
						$('#successdialog').dialog('open');
                        $("#sendEmail").slideUp("normal");
					}
					else{

					 	$('#errormessage').html('Your message appears to be spam.  Please refresh the page and try again.'); 
                    	$('#errordialog').dialog('open');}
                    } 
       		); 
       	} 
		return false; 
  	}); 

	autoFill($("#thename"), "Name");
	autoFill($("#company"), "Company");
	autoFill($("#email"), "Email");
	autoFill($("#phone"), "Phone");	
	
	
});	


//function used by homepage to auto populate input boxes
function autoFill(id, v){
	$(id).css({ color: "#b2adad" }).attr({ value: v }).focus(function(){
		if($(this).val()==v){
			$(this).val("").css({ color: "#333" });
		}
	}).blur(function(){
		if($(this).val()==""){
			$(this).css({ color: "#b2adad" }).val(v);
		}
	});

}
