
$(function() {
  $('.error').hide();
  $('input.box').css({backgroundColor:"#FFFFFF"});
  $('input.box').focus(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });
  $('input.box').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });
  
 $('input#btnsubmit').click(function() {
 
	// validate and process form first hide any error messages
    $('.error').hide();
		
	  var fullname = $("input#fullname").val();
		if (fullname == "") {
      $("span#fullname_error").show();
      $("input#fullname").focus();
      return false;
    }
    
      	var phone = $("input#phone").val();
		if (phone == "") {
      $("span#phone_error").show();
      $("input#phone").focus();
      return false;
    }
    
    var phone = $("input#phone").val();
		if (!isInteger(phone)) {
      $("span#phone_error1").show();
      $("input#phone").focus();
      return false;
    }
    
   
		var email = $("input#email").val();
		if (email == "") {
      $("span#email_error").show();
      $("input#email").focus();
      return false;
    }
    
    	var email = $("input#email").val();
		if (!isValidEmailAddress(email)) {
      $("span#email_error1").show();
      $("input#email").focus();
      return false;
    }
    
      var companyname = $("input#companyname").val();
		if (companyname == "") {
      $("span#companyname_error").show();
      $("input#companyname").focus();
      return false;
    }
    
  
	
	var dataString = 'fullname='+ fullname +'&cname='+ companyname +'&email=' + email + '&phone=' + phone;
		
		$.ajax({
      type: "POST",
     // url: "http://localhost/SiliconInteractive/sendemail.aspx?"+dataString,
       url: "http://www.silicon-interactive.com/sendemail.aspx?"+dataString,
      //data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Thanks</h2>")
        .append("<p>We will be in touch soon.</p>")
        .hide()
        .fadeIn(100, function() {
          $('#message').append("");
          $('#ibutton').hide();
        });
       
      }
     });
    return false;
	});
});
runOnLoad(function(){
  //$("input#fullname").select().focus();
});

//for trim
function trim(str)
{
s = str.replace(/^(\s)*/, '');
s = s.replace(/(\s)*$/, '');
 return s;
}

//for email
function isValidEmailAddress(emailAddress) {
var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
return pattern.test(emailAddress);
}

//check interger
function isInteger (s)
{
  var i;

  if (isEmpty(s))
  if (isInteger.arguments.length == 1) return 0;
  else return (isInteger.arguments[1] == true);

  for (i = 0; i < s.length; i++)
  {
     var c = s.charAt(i);

     if (!isDigit(c)) return false;
  }
  return true;
}

function isEmpty(s)
{
  return ((s == null) || (s.length == 0))
}

function isDigit (c)
{
  return ((c >= "0") && (c <= "9"))
}
