var ajax_return = false;

function videoFormValidate(formDomE)
{
	var wgpsFormObjCustom = {
		wgpsPhone:{
			nullable:false,
			humanName:'Phone Number',
			msg:'Please enter a phone number where we can reach you if we have questions about your order.'
		},
		wgpsNameOnVideo:{
			nullable:false,
			humanName:'Name on Video',
			msg:'Please enter the name that you would like to appear in the video.'
		}
	};
			
	var wgpsFormObjStandard = {
		os0:{
			nullable:false,
			humanName:'Phone Number',
			msg:'Please enter a phone number where we can reach you if we have questions about your order.'
		},
		os1:{
			nullable:false,
			humanName:'Event',
			msg:'Please enter your event so we can send you the correct DVD.'
		},
		os2:{
			nullable:false,
			humanName:'Year',
			msg:'Please enter your event year so we can send you the correct DVD.'
		}
	};
	
	var wgpsFormObj = {};

	var wgpsAdditionalDataField = formDomE.os1;
	var errorMessages = '';
	var wgpsAdditionalData = '';
	var inputValueTemp = '';

	if(formDomE.name == 'orderVideoCustom')
		wgpsFormObj = wgpsFormObjCustom;
	else if(formDomE.name == 'orderVideoStandard')
		wgpsFormObj = wgpsFormObjStandard;
	else
		return false
		keyAccumulator = '';
		
		for(key in wgpsFormObj)
		{
			inputValueTemp = formDomE[key].value;
			if(! wgpsFormObj[key].nullable && (inputValueTemp==null||inputValueTemp==""))
			{
				errorMessages += wgpsFormObj[key].msg + '\n';
				formDomE[key].focus();
			}
				wgpsAdditionalData += wgpsFormObj[key].humanName + ': ' + inputValueTemp + ', ';
		}
			
		if(formDomE.name == 'orderVideoCustom'){
			wgpsAdditionalDataField.value = wgpsAdditionalData;
		}
	
	if(errorMessages != '')
	{
		alert('There was an error in your entry:\n'+errorMessages);
		return false
	}
  if(!ajax_return){
    post_track(formDomE);	
    return false;
  }
}


function post_track(o_form){
  // alert($(o_form).serialize());
   $.ajax({
     type: "POST",
     asyn: false, 
     url: '/track/track_order.php',
     data: {'data':$(o_form).serialize() },
     success: function(msg){
       ajax_return = true;
       setTimeout(function(){  ajax_return = false }, 7000);
       o_form.submit();
     }
 });
  //$.post('/track/track_order.php', {'data':$(o_form).serialize() }, function(data){alert("DONE"); ajax_return = true} );
  
}