function clearBox(box)
{
	if(box.value==box.defaultValue) {
		box.value = "";
	}
} 

function setMask(box, mask_type, country_id)
{
	$('#'+box.id).unmask();
	
	var country = 'USA';
	if(country_id != undefined)
		country = $('#'+country_id).val();

	if(mask_type == 'zip')
	{
		var m;
		if(country == 'USA')
			m = '99999';
		else
		{
			$.mask.definitions['~']='[a-zA-Z]';
			$.mask.definitions['#']='[0-9]';
			m = '~#~#~#';
		}		
		$('#'+box.id).mask(m);
	}
	else
		$('#'+box.id).mask("(999) 999-9999");
}

function clearZip(zip_id)
{
	$('#'+zip_id).unmask();
	$('#'+zip_id).val('Zip:');
}

function check_departure(dep_date_id)
{
	var dep_date = $('#'+dep_date_id).val();
	if(dep_date != '' && dep_date != 'Date of Departure:')
		return true;
	else
		return false;
}

/*
date of return >= date of departure + 3 month 
date of return <= date of departure + 9 month 
date of retrurn < december 15 of current year
*/
function check_dates(dep_id, ret_id)
{
	// departure date
	val_dep = $('#'+dep_id).val();
	if(val_dep == 'Date of Departure:')
	{
		alert('Please select Date of Departure. Thank You.');
		return false;
	}

	// return date
	val_ret = $('#'+ret_id).val();
	if(val_ret == 'Date of Return:')
	{
		alert('Please select Date of Return. Thank You.');
		return false;
	}
	
	var now = new Date();
	var year = now.getFullYear();

	var dep_m = val_dep.substring(0,2);
	var dep_d = val_dep.substring(3,5);
	var dep_y = val_dep.substring(6,10);
	
	var ret_m = val_ret.substring(0,2);
	var ret_d = val_ret.substring(3,5);
	var ret_y = val_ret.substring(6,10);

	dep_m = dep_m - 1;
	ret_m = ret_m - 1;
		
	var date_dep = new Date(dep_y,dep_m,dep_d,0,0,0);
	var date_ret = new Date(ret_y,ret_m,ret_d,0,0,0);

	// check dep date diapason from march 1 to sept 1
	var dep_from	= new Date(2010, 2,1,0,0,0);
	var dep_to		= new Date(2010, 7,31,23,59,0);

	var diff_from	= date_dep - dep_from;
	var diff_to		= date_dep - dep_to;
	if(diff_from < 0 || diff_to > 0)
	{
		alert('Date of departure should be form March 1st to August 31. Thank You.');
		return false;
	}
	
	// date of departure + 3 monthes
	var dep1_y = dep_y;
	var dep1_m = dep_m + 3;
	if(dep1_m>11)
	{
		dep1_y=dep1_y+1;
		dep1_m=dep1_m-12;
	}
	
	var new_dep1 = new Date(dep1_y, dep1_m,dep_d,0,0,0);
	
	// date of departuere + 9 monthes
	var dep2_y = dep_y;
	var dep2_m = dep_m + 9;
	if(dep2_m>11)
	{
		dep2_y=dep1_y+1;
		dep2_m=dep1_m-12;
	}
	
	var new_dep2 = new Date(dep2_y, dep2_m,dep_d,0,0,0);
	
	// date of december 15 of current year
	var now = new Date();
	var year = now.getFullYear();
	var dec_15 = new Date(year, 11, 15, 23,59,0);
		
	var diff1 = date_ret - new_dep1;
	if(diff1 < 0)
	{
		alert('The seasonal convenience plan is available for anyone who plans on being away from Florida for at least 3 months and no more than 9 months and must reconnect by December 15th '+year+'. Please check your dates and submit the form again. Thank You.');
		return false;
	}
			
	var diff2 = new_dep2 - date_ret;
	if(diff2 < 0)
	{
		alert('The seasonal convenience plan is available for anyone who plans on being away from Florida for at least 3 months and no more than 9 months and must reconnect by December 15th '+year+'. Please check your dates and submit the form again. Thank You.');
		return false;			
	}
		
	var diff3 = dec_15 - date_ret;
	if(diff3 <= 0)
	{
		alert('The seasonal convenience plan is available for anyone who plans on being away from Florida for at least 3 months and no more than 9 months and must reconnect by December 15th '+year+'. Please check your dates and submit the form again. Thank You.');
		return false;							
	}
		
	return true;
} 

/*================================
		CONTACT FORMS
================================*/

function check_form()
{
	var name	= 'name';
	var em		= 'email';
	var conf_em	= 'confirm_email';
	var acc_n_1	= 'acc_number_1';
	var acc_n_2	= 'acc_number_2';
	var acc_n_3	= 'acc_number_3';
	var acc_n_4	= 'acc_number_4';
	var s_addr	= 'service_address';
	var s_city	= 'service_city';
	var s_state	= 'service_state';
	var s_zip	= 'service_zip';
	var s_l_p	= 'local_phone';
	var dep_d	= 'dep_date';
	var ret_d	= 'ret_date';
	var b_c		= 'bill_country';
	var b_addr	= 'bill_address';
	var b_city	= 'bill_city';
	var b_state	= 'bill_state';
	var b_zip	= 'bill_zip';
	var off_p	= 'off_phone';
	var isp		= 'isp_name';

	var com_id	= 'comcast_id';
	
	var agree	= 'agree';
	
	var val = '';
	
	// check dates diapason
	if(!check_dates(dep_d, ret_d))
	{
		return false;
	}
	
	val	= $('#'+agree).attr('checked'); 
	if(!val)
	{
		alert('You must agree to the terms of service. Thank You.');
		return false;
	}
		
	val = $('#'+com_id).val();
	if(val == undefined)
	{
		// check email for regular form
		val = $('#'+em).val();	
		if(val == '' || val == 'E-mail:')
		{
			alert('Please check the Email field. Thank You.');
			return false;
		}
		else
		{
			if(!check_email(''+em+''))
				return false;
			
			if(val != $('#'+conf_em).val())
			{
				alert('Confirmation email and email do not match. Please review them and submit again. Thank You.');
				return false;
			}
		}
	}
	else
	{
		// check email for admin form
		val = $('#'+em).val();	
		if(val == '' || val == 'E-mail:')
		{
			$('#'+em).val('');
			$('#'+conf_em).val('');
		}
		else
		{
			if(!check_email(''+em+''))
				return false;
			
			var conf_val = $('#'+conf_em).val(); 
			if(val != conf_val)
			{
				if(conf_val != '' && conf_val != 'Confirm E-mail:')
				{
					alert('Confirmation email and email do not match. Please review them and submit again. Thank You.');
					return false;
				}
			}
		}
	}
	
	// check name
	val = $('#'+name).val();
	if(val == 'Name:')
	{
		alert('Please check the Name field. Thank You.');
		return false;
	}
	else
	{
		if(!check_name(''+val+''))
			return false;
	}
	
	// check account numbers
	val = $('#'+acc_n_1).val();
	if(!check_acc_number(val))
		return false;

	val = $('#'+acc_n_2).val();
	if(!check_acc_number(val))
		return false;

	val = $('#'+acc_n_3).val();
	if(!check_acc_number(val))
		return false;

	val = $('#'+acc_n_4).val();
	if(!check_acc_number(val))
		return false;
		
	
	// check service address
	val = $('#'+s_addr).val();
	if(val == 'Service Address:')
	{
		alert('Please check the Service Address field. Thank You.');
		return false;
	}
	else
	{
		if(!check_address(''+val+'', 'service'))
			return false;
	}

	// check service city
	val = $('#'+s_city).val();
	if(val == 'City:')
	{
		alert('Please check the Service City field. Thank You.');
		return false;
	}
	else
	{
		if(!check_city(''+val+'', 'service'))
			return false;
	}
	
	// check service zip
	val = $('#'+s_zip).val();
	if(val == 'Zip:')
	{
		alert('Please check the Service Zip field. Thank You.');
		return false;
	}
	else
	{
		if(!check_zip(''+val+'', 'service'))
			return false;
	}
	
	// check off season phone
	val = $('#'+s_l_p).val();
	if(val == 'Local Phone Number:')
	{
		alert('Please check the Local Phone number field. Thank You.');
		return false;
	}
	else
	{
		if(!check_valid_phone(''+val+'', 'service'))
			return false;
	}

	// check billing address
	val = $('#'+b_addr).val();
	if(val == 'Address:')
	{
		alert('Please check the Billing Address field. Thank You.');
		return false;
	}
	else
	{
		if(!check_address(''+val+'', 'billing'))
			return false;
	}

	// check billing city
	val = $('#'+b_city).val();
	if(val == 'City:')
	{
		alert('Please check the Billing City field. Thank You.');
		return false;
	}
	else
	{
		if(!check_city(''+val+'', 'billing'))
			return false;
	}
	
	var country = $('#'+b_c).val();
	// check billing zip
	val = $('#'+b_zip).val();
	if(val == 'Zip:')
	{
		alert('Please check the Billing Zip field. Thank You.');
		return false;
	}
	else
	{
		if(!check_zip(''+val+'', 'billing', country))
			return false;
	}

	// check local phone
	val = $('#'+off_p).val();
	if(val == 'Off- Season phone:')
	{
		alert('Please check the Off-Season Phone Number field. Thank You.');
		return false;
	}
	else
	{
		if(!check_valid_phone(''+val+'', 'billing'))
			return false;
	}

	// check internet provider
	val = $('#'+isp).val();
	if(val == 'Name of internet provider:')
	{
		$('#'+isp).val('');
	}
	else
	{
		if(val != '')
		{
			if(!check_isp(''+val+''))
				return false;	
		}
	}
	
	// check if comcast id exist
	val = $('#'+com_id).val();
	if(val != undefined)
	{
		if(val == 'Comcast Id:' || val == '')
		{
			alert('Please enter Comcast Id. Thank You.');
			return false;
		}
	}
	// now check departure date
	xajax_check_departure_date($('#'+em).val(), $('#'+dep_d).val(), $('#'+ret_d).val());
	return false;
	
//	alert('Your request has been succesfully processsed. A confirmation email has been sent to the email address you provided. Thank You.');
//	return true;
}