// JavaScript Document
$(function(){
		   	$(".required").bind('change',function()
										   {
											  $(this).removeClass("ui-state-error"); 
											  //$(this).next().remove();
											  AJAXERROR = false;
											  //$(this).after('<span>' + ERROR_FIXED + '</span>');
										   });


			$('#submission_status').dialog({
								height: 200,
								width: 500,
								show: 'fold',
								modal: true,
								position: 'center',
								autoOpen: false,
								title: 'Exciting Windows - 2011 Sweepstakes'
			});
		
			$('.small_error').dialog({
								height: 150,
								width: 550,
								show: 'fold',
								modal: false,
								position: 'center',
								autoOpen: false
			});
		
		
		
			$("#PHONE").numeric();
			//$("#ZIP").alphanumeric();

			$("#COUNTRY").bind('change',function(){js__ToggleCountry()});
			
			$("#btnSubmit").click(function()
										   {
											   ajax_Submit();
										   });

			$("#PHONE").bind('blur',function()
												  {
													  ajax_PreLead();
												  });

			$("#EW_ID").bind('focus',function()
												  {
													  ajax_PreLead();
												  });
});

function js__ToggleCountry()
{
	var country = $("#COUNTRY").val();

	switch(country)
	 {
		case "CN":
			$("#ZIP").val("000000");
			$("#CITY").val("");
			$("#ZIP").attr("disabled", true);
			ajax_ListCanadaTeretories();
		break;
		
		case "US":
			$("#ZIP").val("");
			$("#CITY").val("");
			$("#ZIP").attr("disabled", '');
			$("#STATES_SPAN").html("<input id=\"STATE\" name=\"SWEEP\" type=\"text\" maxlength=\"2\" class=\"required ui-state-active\" />");
		break;
		
		default:
			$("#ZIP").val("");
			$("#CITY").val("");
			$("#ZIP").attr("disabled", '');
			$("#STATES_SPAN").html("<input id=\"STATE\" name=\"SWEEP\" type=\"text\" maxlength=\"2\" class=\"required ui-state-active\" />");
		break;
		 
	 }
}


function js__CanadianPostalCodes(_postal)
{
	switch(_postal)
	 {
		case "ON":
			$("#ZIP").val("Must provide postal code");
			$("#ZIP").focus();
			$("#ZIP").select();
			$("#CITY").val("");
			$("#ZIP").attr("disabled", false);
		break;

		default:
			$("#ZIP").val("000000");	
			$("#CITY").val("");
			$("#CITY").focus();
			$("#ZIP").attr("disabled", true);
		break;

	 }
}
