<!--
var win=null;
function NewWindow(mypage,myname,w,h,pos,infocus){
if(pos=="random"){myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h)/2:100;}
else if((pos!='center' && pos!="random") || pos==null){myleft=0;mytop=20}
settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes";win=window.open(mypage,myname,settings);
win.focus();}
//-->

$(document).ready(function(){
	$.ajaxSetup ({
		// Disable caching of AJAX responses
		cache: false
	});
	
	jQuery.ajaxSetup({
		xhr: function() {
			//return new window.XMLHttpRequest();
			try{
				if(window.ActiveXObject)
					return new window.ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) { }

			return new window.XMLHttpRequest();
		}
	});


	$("#submit").click(function () {
	
		if ( $( "#name" ).val().length < 1 || $( "#name" ).val() == 'Full Name' ) {
			$( "#name" ).css( "borderColor", "#FF0000" );
			$( "#name_ad" ).css("display","block");
			$( "#name" ).focus();
		    return false;
		}else{
			$( "#name" ).css( "borderColor", "#EEE" );
			$( "#name_ad" ).css("display","none");
		}
		
		var email_valid_patron = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		if ( $( "#email2" ).val().length < 1 || $( "#email2" ).val() == 'Email' || !email_valid_patron.test( $( "#email2" ).val() ) ) {
			$( "#email2" ).css("borderColor","#FF0000");
			$( "#email_ad" ).css("display","block");
			$( "#email2" ).focus();
		    return false;
		}else{
			$( "#email2" ).css("borderColor","#EEE");
			$( "#email_ad" ).css("display","none");
		}
		
		if ( $( "#password2" ).val().length < 1 || $( "#password2" ).val() == 'Password' ) {
			$( "#password2" ).css("borderColor","#FF0000");
			$( "#password_ad" ).css("display","block");
			$( "#password2" ).focus();
		    return false;
		}else{
			$( "#password2" ).css("borderColor","#EEE");
			$( "#password_ad" ).css("display","none");
		}
		
		$( "#full_name" ).val( $( "#name" ).val() );
		$( "#email" ).val( $( "#email2" ).val() );
		$( "#password" ).val( $( "#password2" ).val() );
		//document.getElementById('full_name2').value = document.getElementById('full_name').value;
		
		//alert( "full_name=" + $( "#full_name" ).val() + "&email=" + $( "#email" ).val() + "&password=" + $( "#password" ).val() + "" );
		
		$.ajax({
			type	: "POST",
			cache	: false,
			url		: "user_save.php",
			data	: $( "form#user_save" ).serialize(),
			success : function(data) {
				//alert(data);
				if( data != 'good' ){
					alert( data );
				}else{
					$("form#aweber_save").trigger("submit");
				}
			},
			error   : function(){
				alert('There was an error. Please try again.');
			}
		});
				
	});

});
