// JavaScript Document
Event.observe(window,'load',function(e){
	
	
	VFIApp.getID();
	$('first_name').focus();
});
var VFIApp = {};
function vfifade(id) {
    var dom = document.getElementById(id),
        level = 1;
    function step () {
        var h = level.toString(16);
        dom.style.backgroundColor = '#FFFF' + h + h;
		/*dom.style.borderColor = '#FFFF' + h + h;*/
        if (level < 15) {
            level += 1;
            setTimeout(step, 100);
        }
    }
    setTimeout(step, 100);
}




VFIApp.getID = function(){
	VFIApp.tempID=document.getElementById('tempID').innerHTML;
	
	var url='make_id.php?id='+document.getElementById('tempID').innerHTML;

		new Ajax.Request(url,
		  {
			method:'post',
			onSuccess: function(transport){
				var response = transport.responseText || "Done";
				
				$('tempID').className='yesgo';
				$('tempID').update(response);
	   
			},
			onFailure: function(){ alert('Something went wrong...try again') }
		  });
			
	
}

VFIApp.p = function(EL){
	var data=$F(EL);
	
	var url='post_app.php?field='+EL+'&data='+data;
		new Ajax.Request(url,
		  {
			method:'post',
			onSuccess: function(transport){
				var response = transport.responseText || "Done";
	   
			},
			onFailure: function(){ alert('Something went wrong...try again') }
		  });
	
}

VFIApp.comments = function(EL){
	
	var data=$F(EL);
	
	var url='post_comments.php?field='+EL+'&data='+data;
		new Ajax.Request(url,
		  {
			method:'post',
			onSuccess: function(transport){
				var response = transport.responseText || "Done";
			},
			onFailure: function(){ alert('Something went wrong...try again'); return false; }
		  });
	
}


VFIApp.val = function(EL){
	
	var d=$(EL);
	
	if(d.value.length===0){
		var url='errors.php?field=' + EL;
		var output = 'errors';
		new Ajax.Updater(output, url, {method: 'post'});
	}
}

VFIApp.getZip = function(){
	
	var d=$('zipcode');
	
	if(d.value.length===5){
		var url='populate_city.php?ZIPCode='+d.value;

		new Ajax.Request(url,
		  {
			method:'post',
			onSuccess: function(transport){
				var response = transport.responseText || "Done";
				$('cityoutput').update(response);
	   
			},
			onFailure: function(){ alert('Something went wrong...try again') }
		  });
	}//end = 5
	
}

VFIApp.final = function(x){
	
	if($F('betty').length!=0){ parent.location='http://www.wikipedia.com'; }
	
	if($F('first_name').length===0){
		alert('Please enter your first name');
		$('first_name').focus();
		return;
	}
	
	if($F('last_name').length===0){
		alert('Please enter your last name');
		$('last_name').focus();
		return;
	}
	
	if($F('address').length===0){
		alert('Please enter your street address');
		$('address').focus();
		return;
	}
	
	if($F('zipcode').length!=5){
		alert('Please enter your full zip code!');
		$('zipcode').focus();
		return;
	}
	
	var data=document.getElementById('cityoutput').innerHTML;
	var valid= data.indexOf('Invalid');
	if(valid!=-1){
		alert('Please enter a valid zip code!');
		$('zipcode').focus();
		return;
	}
	
	if($F('phone').length===0 && $F('cell').length===0 ){
		alert('Please enter at least one phone number');
		$('phone').focus();
		return;
		
	}
	
	if($F('email').length===0){
		alert('Please enter an email address');
		$('email').focus();
		return;
	}
	
	if($F('reemail').length===0){
		alert('Please reenter your email address');
		$('reemail').focus();
		return;
	}
	
	if($F('email')===$F('reemail')){
		
	}else{
		alert('The emails do not match, please correct this.');
		$('email').focus();
		return;
	}
	
	if($F('comments').length===0){
		alert('Please tell us how you find out about us');
		$('comments').focus();
		return;
	}
	
	if($F('areas').length===0){
		alert('Please tell us the areas that you can work');
		$('areas').focus();
		return;
	}
	
	if($F('days')==="invalid"){
		alert('Please tell us the days you are available to work');
		$('areas').focus();
		return;
	}
	
	if($F('hours')==="invalid"){
		alert('Please tell us the hours you are available to work');
		$('areas').focus();
		return;
	}
	
	parent.location='finish_app.php';	
}