// JavaScript Document
var server = top.location.host;

$(document).ready(function() {
	// sets up the Contact form
	$(function() { 
		$('#submit').click(function() { 
			form = $(this).parents('form');
			doEmail(form);
			return false; 
		});
	});	
	$('.eml').defuscate();
	
});

function doEmail(form) {
	from_name	= $(form).find('#NAME').val();
	from_eml 	= $(form).find('#EML').val();
	phone 		= $(form).find('#PHONE').val();
	msg 		= $(form).find('#MSG').val();
	
	$.ajax({
		type: 'POST',
		url: 'http://'+server+'/assets.php',
		data: {func:'mailer',NAME:from_name,EML:from_eml,PHONE:phone,MSG:msg},
		success: function(msg){
					$('#contact_form').css({'opacity': 0});
					$('#contact_form').html(msg);
					$('#contact_form').animate({'opacity': 1}, 800);
					
					$('#reset_form').bind('click',function() {
						resetEmail();
					 });					
				}
	});	
}
// HELPER FUNCTIONS
function gup(name,href)  // gets a url parameter
{
  if(!href) {
	  href = window.location.href;
  }
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( href );
  if( results == null )
    return "";
  else
    return results[1];
}
/*
 * Email Defuscator - jQuery plugin 1.0-beta2
 *
 * Copyright (c) 2007 Joakim Stai
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 * Revision: $Id$
 *
 */

/**
 * Converts obfuscated email addresses into normal, working email addresses.
 *
 * @name defuscate
 * @param Boolean link If true, all defuscated email addresses will be turned into links, defaults to true (optional)
 * @param String find The regular expression used to search for obfuscated email addresses (optional)
 * @param String replace Replacement text for defuscating email addresses (optional)
 * @descr Converts obfuscated email addresses into normal, working email addresses
 */

jQuery.fn.defuscate = function( settings ) {
    settings = jQuery.extend({
        link: true,
        find: /\b([A-Z0-9._%-]+)\([^)]+\)((?:[A-Z0-9-]+\.)+[A-Z]{2,6})\b/gi,
        replace: '$1@$2'
    }, settings);
    return this.each(function() {
        if ( $(this).is('a[@href]') ) {
            $(this).attr('href', $(this).attr('href').replace(settings.find, settings.replace));
            var is_link = true;
        }
        $(this).html($(this).html().replace(settings.find, (settings.link && !is_link ? '<a href="mailto:' + settings.replace + '">' + settings.replace + '</a>' : settings.replace)));
    });
};
