﻿	$(document).ready(function(){
		$('input[type=checkbox],input[type=radio]').prettyCheckboxes();
		$('.clearinput').click(function (event) {
		    event.preventDefault();
		    $('input:text').animate({color:"#1C2F3C"},"slow",function(){$(this).val('').animate({color:"#C0DAE9"},"fast")});
		    $('textarea').animate({color:"#1C2F3C"},"slow",function(){$(this).val('').animate({color:"#C0DAE9"},"fast")});
		});
		$('.submit').click(function(event){
            var valid = true;
            hcolor = "#30536C";
		    event.preventDefault();
		    if($('#txtName').val().length < 1){
		       $('#txtName').animate({ backgroundColor: hcolor}, "fast").animate({ backgroundColor: "#1C2F3C"}, "slow");
		       valid = false;
		     }
		    if($('#txtCompany').val().length < 1){
		       $('#txtCompany').animate({ backgroundColor: hcolor}, "fast").animate({ backgroundColor: "#1C2F3C"}, "slow");
		       valid = false;
		     }
		    if($('#txtEmail').val().length < 1 || !(isValidEmail($('#txtEmail').val()))){
		       $('#txtEmail').animate({ backgroundColor: hcolor}, "fast").animate({ backgroundColor: "#1C2F3C"}, "slow");
		       valid = false;
		     }
		    if($('#txtPhone1').val().length < 1 || $('#txtPhone2').val().length < 1 || $('#txtPhone3').val().length < 1){
		       $('#txtPhone1').animate({ backgroundColor: hcolor}, "fast").animate({ backgroundColor: "#1C2F3C"}, "slow");
		       $('#txtPhone2').animate({ backgroundColor: hcolor}, "fast").animate({ backgroundColor: "#1C2F3C"}, "slow");
		       $('#txtPhone3').animate({ backgroundColor: hcolor}, "fast").animate({ backgroundColor: "#1C2F3C"}, "slow");
		       valid = false;
		     }
		    if(valid){
		    $('.submit').remove();
		    $('.clearinput').replaceWith("<img src='assets/images/pulser.gif' alt='loading' /> Sending...");
		       $('#contactForm').animate({opacity:0.5},8000);
               $('#txtName').attr("disabled","disabled");
               $('#txtCompany').attr("disabled","disabled");
               $('#txtEmail').attr("disabled","disabled");
		       $('#txtPhone1').attr("disabled","disabled");
		       $('#txtPhone2').attr("disabled","disabled");
		       $('#txtPhone3').attr("disabled","disabled");
		       $('#txtMessage').attr("disabled","disabled");
		       $.post("assets/script/script.aspx?mode=sendemail", {
		          name: $('#txtName').val()
		         ,email: $('#txtEmail').val() 
		         ,company: $('#txtCompany').val()
		         ,phone: $('#txtPhone1').val()+"-"+$('#txtPhone2').val()+"-"+$('#txtPhone3').val()
		         ,demo: $('#chkDemo').attr("checked")
		         ,call: $('#chkCall').attr("checked")
		         ,message: $('#txtMessage').val()
		     }, function(data){
                $('#contactForm').stop().slideUp('slow');
                $('#msgSent').html(data).slideDown('slow')
              });
		    }    
		});
	});
	function isValidEmail(str) {return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);}