/*
$(document).ready(function(){
		create_datepicker();
});


function create_datepicker()
	{


		$('.ship_picker').each(function(){

		var selectedDate= $(this).val();
		$(this).mask("9999-99-99").val(selectedDate);

		var dpInput = this;



		var daterange = new Date();
		var day = daterange.getDate()+2;
		var month = daterange.getMonth()+1;
		var year = daterange.getFullYear();


		//if(selectedDate!='')
		//{
		//	var dDate = new Date.parseIso8601(selectedDate);
		//}
		//else
		//
		var dDate = new Date();


		var minDate = dDate;
		var minRange = minDate;
		var maxRange = dDate.add(8,'weeks');

		var usedPicker = false;

		var jDateA = new Array();
		for(bo=0;bo< javaDates.length;bo++)
		{
			var jDate = Date.parseIso8601(javaDates[bo]) + '';
			jDateA.push(jDate);
		}


		$(this).datepicker({
			blackoutDates: jDateA,
			showOn:'click',
			dateFormat: 'yy-mm-dd',
			minDate: minRange,
			maxDate:  maxRange,
			mandatory: true,
			defaultDate:dDate,
			beforeShow: function(){
				usedPicker = true;
			},
			onSelect: function(dateText) {
	    		if(dateText!='')
	    		{
	    			var myDate = Date.parseIso8601(dateText);
	    			isFillDate(myDate, this,$(this).parent().parent().parent().parent().next(),myDate);
	    			usedPicker = true;
	    		}
	  		},
	  		onClose: function(){

	  		}
		});

		$(this).keydown(function(e){
			if(e.which!=9) usedPicker = false;
		});

		$(this).blur(function(){
			var dateText = $(this).val();
				if(dateText!='')
			{
				// createDateText(dateText,this,$(this).parent().parent().parent().parent().next());
				if(!usedPicker)
				{
					var myDate = Date.parseIso8601(dateText);
					isFillDate(myDate,this,$(this).parent().parent().parent().parent().next(),myDate);
				}
			}
		})

		});

	}


	function isFillDate(myDate, picker, textDiv,originalDate)
	{
		var todayDate = new Date();
		todayDate = todayDate.add(2,'days');
		if(myDate < todayDate) myDate = todayDate;

		var dDate = new Date();
		var maxRange = dDate.add(8,'weeks');

		if(maxRange.getDay()==0) maxRange.add(1,'days');
		if(maxRange.getDay()==6) maxRange.add(2,'days');

		if(myDate > maxRange)
		{
			myDate = maxRange;
		}

		var newDate = myDate;

		validDate = false;
		//console.log('first new date:'+newDate)
		validDate = checkFillDate(newDate);
		if(validDate==false)
		{
			newDate = newDate.add(1,'days');
			isFillDate(newDate, picker, textDiv,originalDate);
		}
		else
		{
			var originalDateString = originalDate+'';
			var newDateString = newDate+'';
			if(newDateString!=originalDateString) var moved = true;
			else var moved = false;
			createDateText(newDate,picker,textDiv,moved);
		}
	}

	function checkFillDate(myDate)
	{



		for(i=0;i< javaDates.length;i++)
		{
			var jDate = Date.parseIso8601(javaDates[i]) + '';
			var myDateString = ''+myDate;
			if(myDateString == jDate)
			{
				return false;
			}
		}

		if(myDate.getDay()==0 || myDate.getDay()==6) return false;

		return true;
	}
*/

	function createDateText(newDate,picker,textDiv,moved)
	{

	    		var aMonths= ["January","February","March","April","May","June","July","August","September","October","November","December"];
	    		var weekDays= ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"];

	    		var textSub = '';

	    		/* if ship date is a sunday, move forward to monday */
	    		//if(myDate.getDay()==0)
	    		//{
	    		//	var newDate = myDate.add(1,'days');
	    		//	textSub = '<div class="sub_msg">Note: Boca Java does not ship on weekends, so your shipping date has been moved to the next weekday</div>';
	    		//}
	    		//else if(myDate.getDay()==6)
	    		//{
	    		//	var newDate = myDate.add(2,'days');
	    		//	textSub = '<div class="sub_msg">Note: Boca Java does not ship on weekends, so your shipping date has been moved to the next weekday</div>';
	    		//}
	    		//else var newDate = myDate;


	    			if(moved)
	    			{
	    				textSub = '<div class="sub_msg">Your shipment has been moved to the next available shipment date.</div>';
	    			}

	    			var curDate = newDate.iso8601Format("YMD");

	    			var d = curDate.split('-');

	    			day= d[2];
	    			textDay = weekDays[newDate.getDay()];
	    			textMonth = aMonths[newDate.getMonth()];
	    			year = newDate.iso8601Format("Y");
	    			month = newDate.iso8601Format("M");
	    			$(picker).setDatepickerDate(newDate);
	    			$(picker).val(curDate);
	    			if($("#f_dateDelivery").val()!=null) $("#f_dateDelivery").val(curDate);

	    	//	console.log(day)
	    		if(textDiv.is(':visible')) textDiv.hide();
	    		textDiv.html('You have selected <b>'+textDay+', '+textMonth+' '+day+', '+year+'</b> as your next shipment date.'+textSub);
	    		if(textDiv.is(':hidden'))textDiv.fadeIn();
	    		return curDate;
	}



	/** EASY FORMS **/

	 /* QUICK BUILD CLIENT SIDE VALIDATION */
	 function validationBuilder(options)
	 {
	 	this.validationType = options.validationType;
	 	this.partner = options.partner;
	 	this.required = options.required; //null assumes y, otherwise n
	 	this.field= options.field;
	 	this.iMsg = options.iMsg;
	 	this.min = options.min;
	 	this.minMsg = options.minMsg;
	 	this.maxMsg= options.maxMsg;
	 	this.pattern = options.pattern;
	 	this.patternMsg = options.patternMsg;
	 	this.max = options.max;
	 	this.numeric = options.numeric;
	 	this.numericMsg = options.numericMsg;
	 	this.type = options.type;
	 	this.wait = options.wait;
	 	this.choose = options.choose;
                this.allowed = options.allowed;
                this.inclusion= options.inclusion;
                this.inclusionMsg = options.inclusionMsg;
	 	if(this.wait==null) this.wait = 1000;
	 }

	function easyForm(options)
	{
		this.ajax = true;
		if(options.ajax!=null) this.ajax = options.ajax;
        if(options.force!=null) this.force = options.force;
		this.response = null;
		this.remotePath = options.remotePath;
		this.submitAction = options.submitAction;
		this.href = options.url;
		this.vA = {};
		this.rd = {}; //to reverse the data flow and reinject values back into the page
		this.submitData = {};
		this.key = options.key;
		this.array = options.array;
		this.anchor = options.anchor;
        this.toggleArray = {};
        this.totalhack = {};
		if(this.array!=null && this.array.length > 0)
		{
			if(this.href!=null) this.breakUrl();
			this.specialFunctions();
			this.arrayToObject();
			if(this.key!=null) this.activateSubmit();
		}
		else
		{
			this.activateDelete();
		}

	}

	easyForm.prototype.breakUrl = function()
	{
		var ef = this;
		var query = this.href.split('#');
		var params = query[1].split('&');
		for(i=0;i<params.length;i++)
		{

			var keyVal = params[i].split('=');
			ef.submitData[keyVal[0]] = keyVal[1];
		}
	}

	easyForm.prototype.breakAnchor = function()
	{
		var href = $(this.anchor).attr('href');
		var query = href.split('?');
		var params = query[1].split('&');

		for(i=0;i<params.length;i++)
		{
			var keyVal = params[i].split('=');
			this.pair[keyVal[0]] = keyVal[1];
			if(keyVal[0] == this.pairKey) this.key = keyVal[1];
		}
	}

	easyForm.prototype.specialFunctions = function() //adds special functionality based on obj entries
	{
		for(i=0;i<this.array.length;i++)
		{
		//datepicker functionality
			var current = this.array[i];
			if(current.field.match(/date/gi))
			{
				var dateField = current.field;
				var cField = dateField.replace(/f_/,'c_');
				var hasText = false;


				if($("#passData_"+this.key+" ."+cField).html()!=null)
				{
					if($("input[name='lastDateDelivery']").val()!=null) selectedDate = $("input[name='lastDateDelivery']").val();
					else selectedDate = $("#passData_"+this.key+" ."+cField).html();
					if(selectedDate!='')
					{
						var aDate = selectedDate.split('-');
						var dDate = new Date.parseIso8601(selectedDate);
					}
					else dDate = new Date();
					$('#'+dateField+"_pick").datepicker({
						defaultDate:dDate,
						dateFormat: 'yy-mm-dd',
		    			onSelect: function(date) {
		        			$('#'+dateField).val(date);
		    			}
					});
				}
				else if($('.inlinePicker').html()!=null)
				{
					if($("input[name='lastDateDelivery']").val()!=null) selectedDate = $("input[name='lastDateDelivery']").val();
					else selectedDate = $('.inlinePicker').next().children('input').val();
					if(selectedDate!='')
					{
						var aDate = selectedDate.split('-');
						var dDate = new Date.parseIso8601(selectedDate);
					}
					else dDate = new Date();

					/* this is such a hack */
					var minDate = dDate;
					var minRange = minDate.add(3,'days');
					var maxRange = dDate.add(8,'weeks');

					var jDateA = new Array();
					for(bo=0;bo< javaDates.length;bo++)
					{
						var jDate = Date.parseIso8601(javaDates[bo]) + '';
						jDateA.push(jDate);
					}

					$('#'+dateField+"_pick").datepicker({
						blackoutDates: jDateA,
						minDate: minRange,
						maxDate:  maxRange,
						mandatory: true,
						defaultDate:dDate,
						dateFormat: 'yy-mm-dd',
	    				onSelect: function(date) {
	    					var myDate = Date.parseIso8601(date);
	        				isFillDate(myDate,$('#'+dateField+"_pick"),$('#'+dateField+"_pick").next().next().next(), myDate);
	        				//$('#'+dateField).val(date);
	    				}
					});

					hasText = true;


				}
				else
				{
					dDate = new Date();
					$('#'+dateField+"_pick").datepicker({
						dateFormat: 'yy-mm-dd',
		    			onSelect: function(date) {
		        			$('#'+dateField).val(date);
		    			}
					});
				}

			}

			if(current.valid == 'Other')
			{
				//console.log(current.field)

				var field = current.field;
				var cField = field.replace(/f_/,'c_');
				if($('#passData_'+this.key+' .'+cField).html()=='Other') $('#'+field+"_other:hidden").fadeIn(); //fade in if passed data is other


				$('#'+field).change(function(){
					var fId = $(this).attr('id');
					if($(this).val()=='Other')
					{
						$('#'+fId+"_other:hidden").fadeIn();
					}
					else
					{
						$('#'+fId+"_other:visible").fadeOut();
					}
				});
			}

		}
	}

	easyForm.prototype.arrayToObject = function(){
		for(i=0;i<this.array.length;i++)
		{
			var current = this.array[i];
            var ta = this.toggleArray;
			if(current.required!='n')
			{

                if(current.field.match(/state/gi))
                {
                   $("#"+current.field).keyup(function(){
                      $(this).val($(this).val().toUpperCase());
                   });
                }

				if(current.field.match(/date/gi)) this.vA[current.field] = new validationBuilder({field:current.field,iMsg:'Please select a date'});
				else if(current.field.match(/email/gi)) this.vA[current.field] = new validationBuilder({field:current.field,iMsg:'Please enter your e-mail address'});
				else if(current.field.match(/name/gi)) this.vA[current.field] = new validationBuilder({field:current.field,iMsg:'Please enter a name'});
				else if(current.field.match(/address/gi)) this.vA[current.field] = new validationBuilder({field:current.field,iMsg:'Please enter an address'});
				else if(current.field.match(/city/gi)) this.vA[current.field] = new validationBuilder({field:current.field,iMsg:'Please enter a city'});
				else if(current.field.match(/state/gi) && statesAllowed.length > 2) this.vA[current.field] = new validationBuilder({field:current.field,iMsg:'Please enter a state',max:2,maxMsg:'please enter your 2 letter state code',min:2,minMsg:'please enter your 2 letter state code',inclusion:true,allowed:statesAllowed,inclusionMsg:'Must be a valid state or US territory'});
                else if(current.field.match(/state/gi)) this.vA[current.field] = new validationBuilder({field:current.field,iMsg:'Please enter a state',max:2,maxMsg:'please enter your 2 letter state code',min:2,minMsg:'please enter your 2 letter state code'});
				else if(current.field.match(/postal/gi) || current.field.match(/zip/gi)) this.vA[current.field] = new validationBuilder({field:current.field,iMsg:'Please enter a zip code',pattern:/^([0-9]{5})([\-]{1}[0-9]{4})?$/,patternMsg:'Please enter in 5 or 5-4 format'});
				else if(current.field.match(/match/i)) this.vA[current.field] = new validationBuilder({field:current.field,iMsg:'Fields do not match'});
				else if(current.field.match(/password/gi)) this.vA[current.field] = new validationBuilder({field:current.field,iMsg:'Your password must be between 6 and 12 characters in length',min:6,minMsg:'Your password must be between 6 and 12 characters in length',max:12,maxMsg:'Your password must be between 6 and 12 characters in length'});
				else if(current.field.match(/cvv/gi)) this.vA[current.field] = new validationBuilder({field:current.field,iMsg:'Please enter the CVV number on your credit card',min:3,minMsg:'The cvv number is either 3 or 4 digits long',numeric:true,numericMsg:'The cvv number only contains digits'});
				else if(current.field.match(/month/gi) || current.field.match(/year/gi)) this.vA[current.field] = new validationBuilder({field:current.field,iMsg:'This field is required',numeric:true,numericMsg:'Please enter as a digit'});
				else if(current.field.match(/routing/gi)) this.vA[current.field] = new validationBuilder({field:current.field,iMsg:'Routing number is 9 digits',numeric:true,numericMsg:'Routing number is 9 digits in length',min:9,minMsg:'Routing number is 9 digits in length',max:9,maxMsg:'Routing number is 9 digits in length'});
                else if(current.field.match(/accountnumber/gi)) this.vA[current.field] = new validationBuilder({field:current.field,iMsg:'Account number is all digits',numeric:true,numericMsg:'Account number is all digits'});

				else
				{
					this.vA[current.field] = new validationBuilder({field:current.field,iMsg:'This field is required'});
				}


                if(current.toggle)
                {
                    ta[i] = current.field;

                }

			}
			else
			{

			}


			 //use this to format or act on fields that don't need validation
			if(current.field.match(/phone/gi)) $("#"+current.field).mask("999-999-9999");
			if(current.field.match(/fax/gi)) $("#"+current.field).mask("999-999-9999");
			if(current.field.match(/date/gi)) $("#"+current.field).mask("9999-99-99");

		}
		this.setValidation();
	}

    easyForm.prototype.disableValidation = function()
    {

       for (var i in this.toggleArray)
		{
            this.totalhack[this.toggleArray[i]].disable();
        }
    }

    easyForm.prototype.enableValidation = function()
    {
        for (var i in this.toggleArray)
		{
            this.totalhack[this.toggleArray[i]].enable();
        }
    }


	easyForm.prototype.setValidation = function()
	{
		for (var i in this.vA)
		{

		//	//console.log("var valid_"+this.vA[i].field+"= new LiveValidation('"+this.vA[i].field+"',{validMessage:' ',wait:"+this.vA[i].wait+"});");
	 		eval("var valid_"+this.vA[i].field+"= new LiveValidation('"+this.vA[i].field+"',{validMessage:' ',wait:"+this.vA[i].wait+"});");

            eval("this.totalhack[i] = valid_"+this.vA[i].field);

	 		if(this.vA[i].required!='n') eval("valid_"+this.vA[i].field+".add(Validate.Presence,{failureMessage:'"+this.vA[i].iMsg+"'});");
	 		if(this.vA[i].max!=null)
	 		{
	 			eval("valid_"+this.vA[i].field+".add(Validate.Length,{maximum:"+this.vA[i].max+",failureMessage:'"+this.vA[i].maxMsg+"'});");
	 		}
	 		if(this.vA[i].min!=null)
	 		{
	 			eval("valid_"+this.vA[i].field+".add(Validate.Length,{minimum:"+this.vA[i].min+",failureMessage:'"+this.vA[i].minMsg+"'});");
	 		}

	 		if(this.vA[i].numeric!=null)
	 		{
	 			eval("valid_"+this.vA[i].field+".add(Validate.Numericality,{notAnIntegerMessage:'"+this.vA[i].numericMsg+"'});");
	 		}

	 	/*	if(this.vA[i].field.match(/phone/gi))
	 		{
	 			eval("valid_"+this.vA[i].field+".add(Validate.Format,{pattern: /[0-9]{3}\-[0-9]{3}\-[0=9]{4}/,failureMessage:'Please enter a valid phone #'});");
	 		}
	 		*/
	 		if(this.vA[i].field.match(/email/gi))
	 		{
	 			eval("valid_"+this.vA[i].field+".add(Validate.Email);");
	 		}

	 		if(this.vA[i].field.match(/match/i))
	 		{
	 			var matchField = $("#"+this.vA[i].field).attr('matches');
	 			eval("valid_"+this.vA[i].field+".add(Validate.Confirmation,{match:'"+matchField+"',failureMessage:'Passwords do not match'});");
	 		}

	 		if(this.vA[i].pattern!=null)
	 		{
	 			eval("valid_"+this.vA[i].field+".add(Validate.Format,{pattern:"+this.vA[i].pattern+",failureMessage:'"+this.vA[i].patternMsg+"'});");
	 		}

            if(this.vA[i].inclusion==true)
	 		{
                
	 			eval("valid_"+this.vA[i].field+".add(Validate.Inclusion,{within:this.vA[i].allowed,failureMessage:'"+this.vA[i].inclusionMsg+"'});");
	 		}


		}
	}


	easyForm.prototype.passData = function() //passes the div data into the form for ajax updates
	{

		$("#passData_"+this.key+" span").each(function(){
			var poppy=this;
			if($(this).attr('class') && $(this).attr('class').match(/c_/))
			{
				var fname = $(this).attr('class').replace(/c_/,'f_');

				if($("#"+fname))
				{
					$("#"+fname).val($(this).text());

					$("select#"+fname).each(function(){
						$(this).children().each(function(){
							if(parseFloat($(this).attr('value')) == parseFloat($(poppy).text())) $(this).attr('selected','selected');
							else if($(this).text().toUpperCase() == $(poppy).text().toUpperCase()) $(this).attr('selected','selected');
						});
					});

					$("#"+fname+"[class='noedit']").html($(this).text());
					if(document.getElementById(fname).nodeName.toUpperCase()=="UL")
					{

						$("#"+fname+" input").each(function(){
							//console.log($(this).val()+":"+$(poppy).text())
							if($(this).val()==$(poppy).text()) $(this).attr('checked','checked')
							else $(this).attr('checked','');
						});
					}
				}
				var pname = $(this).attr('class').replace(/c_/,'p_');

				if($("#"+pname)) $("#"+pname).text($(this).text());


			}
		});
	}

	easyForm.prototype.reverseData = function() //passes the div data into the form for ajax updates
	{
		//future - add a highlight fade to this action
		/*
		for(i in this.rd)
		{
			var cname = i.replace(/f_/,'c_');


			//hacked in gift reminder code (not elegant, but it works)
			if(cname=='c_addressbookId')
			{
				console.log(this.rd[i]);
				if(this.rd[i]!='Other')
				{
					this.rd['f_firstname'] = this.rd[i];
					this.rd['f_lastname'] = '';
				}
			}
		}
		*/

		for(i in this.rd)
		{
			var cname = i.replace(/f_/,'c_');
			if(cname!=undefined && cname!=null) $("#passData_"+this.key+" span."+cname).html(this.rd[i]).effect('highlight','',3000);
		}



	}


	easyForm.prototype.reloadData = function()
	{
		window.location.href = window.location.href;
	}


	easyForm.prototype.removeData = function()
	{
		//future - add a highlight fade to this action

		if($("#upcomingData_"+this.key).html()!=null)
		{
			var pt = $("#upcomingData_"+this.key).parent();
			$("#upcomingData_"+this.key).remove();
			if(!pt.is(':has("tr")'))
			{
				$("#upcomingTable").remove();
			}
		}

		$("#passData_"+this.key).fadeOut('slow',function(){
			$(this).remove();
			$.modal.close();
		})
	}


	easyForm.prototype.labelWriter = function()
	{
		var ef = this;



		$("input:text").each(function(){
			if($(this).attr('class')!='ff_email') ef.labelWrite(this);
		});

		$(':text').keyup(function(){
			if($(this).attr('class')!='ff_email') ef.labelWrite(this);
		});


		$(':text').blur(function(){
			if($(this).attr('class')!='ff_email') ef.labelWrite(this);
		});


		/*$(':textarea').keyup(function(){
			ef.labelWrite(this);
		});

		$(':select').change(function(){
			ef.labelWrite(this);
		});
			*/
	}

	easyForm.prototype.labelWrite = function(w)
	{
			var id = $(w).attr('id');
			if(id!=undefined)
			{
				var pname = id.replace(/f_/,'p_');
				$("#"+pname).html($(w).val());
			}
	}

	easyForm.prototype.activateDelete = function(){
		var ef = this;
		$("#modalContainer button").click(function(){
			var key = $("#modalContainer form").attr('id') + 'Id';
			ef.submitData[key] = ef.key;


			var state = ef.completeSubmit('delete');

			return false;
		});
	}



	easyForm.prototype.activateSubmit = function()
	{
		var errors = 0;
		var ef = this;
		var valueArray = {};
		$("#modal_ae form").submit(function(){


			//get rid of any failure messages
			$("#modalContainer .failure").remove();

			//gets values of text/select/textarea/button
			$('#modal_ae form input').each(function(){

				var type=$(this).attr('type');
				if(type == 'hidden' || type == 'text')
				{
					var key = $(this).attr('name');
					var rdID = $(this).attr('id');
                    if(rdID=='') rdID = 'whaevah';
					var value = $(this).val();
					ef.submitData[key] = value;
				//	console.log(key+':'+ef.submitData[key])
					ef.rd[rdID] = value;
                 //  console.log(rdID+'='+ef.rd[rdID])
				}
				else if(type == 'radio' || type=='checkbox')
				{
					//console.log($(this).is(':checked'));
					if($(this).is(':checked'))
					{
						var key = $(this).attr('name');
						var rdID = $(this).attr('id');
						var value = $(this).val();
                        if(rdID=='') rdID = 'whaevah';
						ef.submitData[key] = value;
						ef.rd[rdID] = value;
                    //    console.log(rdID+'='+ef.rd[rdID])
					}
				}
			});

			$('#modal_ae form select').each(function(){
					var key = $(this).attr('name');
					var rdID = $(this).attr('id');
                    if(rdID=='') rdID = 'whaevah';
					var value = $(this).val();
					ef.submitData[key] = value;
				//	console.log(key+':'+ef.submitData[key])
					ef.rd[rdID] = value;

					$(this).children('option').each(function(){
						if($(this).attr('value') == value) ef.rd[rdID] = $(this).html();
					});
				//	console.log(rdID+'='+ef.rd[rdID])


			});

			$('#modal_ae form textarea').each(function(){
					var key = $(this).attr('name');
					var rdID = $(this).attr('id');
                    if(rdID=='') rdID = 'whaevah';
					var value = $(this).html();
					ef.submitData[key] = value;
				//	console.log(key+':'+ef.submitData[key])
					ef.rd[rdID] = value;
                //    console.log(rdID+'='+ef.rd[rdID])
			});

			$('#modal_ae .noedit').each(function(){
					var key = $(this).attr('name');
					var rdID = $(this).attr('id');
                    if(rdID=='') rdID = 'whaevah';
					var value = $(this).html();
					ef.submitData[key] = value;
					ef.rd[rdID] = value;
               //     console.log(rdID+'='+ef.rd[rdID])
			});



			//check for errors without relying on error class
			for(i=0;i<ef.array.length;i++)
			{

				if($('#'+ef.array[i].field).val()=='')
				{
					errors=1;
				}
			}

			if(($("span[class*='LV_invalid']").html()==null && errors==0) || ef.force==true)
			{

				var state = ef.completeSubmit('ae');
			}

			return false;
		});
	}




	easyForm.prototype.completeSubmit = function(s_type){
		var ef = this;


		if(ef.ajax == true)
				{
					ef.submitData['responseType'] = 'json';
					ef.remotePath = $('#modalContainer form').attr('action');

					//do the actual ajax request
					$.ajax({
					   type: "POST",
					   cache:false,
					   url: ef.remotePath,
					   data: ef.submitData,
					   dataType: 'text',
					   error: function (XMLHttpRequest, textStatus, errorThrown) {
		  // typically only one of textStatus or errorThrown
		  // will have info
		  alert(errorThrown+":"+textStatus); // the options for this ajax request
	},
					   success: function(data){


					   	var nData = data.replace(/\n/gi,'');
					   	eval('var eData= '+nData);

					   	//output new message
					   		$("#modalContainer .success").remove();
					   		$("#modalContainer .failure").remove();
					  //	alert(data.error);
					   	//check data for validation errors

					   	if(nData.length<20)
					   	{
					   		$("#modalContainer h2").after('<div class="success"><b>Update successful.</b><div class="sub_msg">This window will close in 3 seconds</div></div>');

					   		// this part is just for adding a new address (ship to multiple)
							$("#shipto_"+this.key).append('<option value="'+eData.id+'" selected >'+ef.submitData['nickName'] +'</option>');

					   		 setTimeout("closeModal()",3000);

					   		 if(ef.submitAction==null)
					   		 {

								if(s_type!='delete') ef.reverseData();
								 else ef.removeData();
					   		 }
					   		 else eval('ef.'+ef.submitAction+'()');
							return true;

					   	}
					   	else if(eData.error == true)
					   	{
					   		var dE = 0;
					   		var errors = eData.errorData;
							for (var i in errors)
							{
								if(i == 'serverSideMessage')
								{
									dE++;
									$("#modalContainer h2").after('<div class="failure">Sorry. We\'ve encountered an error. '+errors.serverSideMessage+'</div>');

									if(errors.serverSideMessage.match(/Address Not Found/gi)!=null)
									{
										$("#usps_notfound").show();
									}

								}
								else
								{
									$("#f_"+i).next().remove();
									$("#f_"+i).addClass('LV_invalid_field').after('<span class="LV_validation_message LV_invalid">'+errors[i]+'</span>');
								}
							}


							if(dE==0) $("#modalContainer h2").after('<div class="failure">Sorry. We\'ve encountered an error. Please check your information.</div>');
					   		return false;
					   	}
					   	else
					   	{
					    	return true;
					   	}


					   }
					 });



				}
				else
				{
					//we aren't using ajax - submit the form
					$("#modalContainer form").submit();
					return true;
				}
				return false;
	};
	
