//Init some variables/arrays
var planner_count=0;
var plannerID=0;
var http_step=0;
var planner_max=500;


var planner_location_id = [];
var planner_location_type = [];
var planner_location_name = [];
var planner_location_state = [];
var planner_location_country = [];

//var planner_data_url="/ajax/planner_ajax.php";

var planner_beg_yyyymmdd=20070201;

var tmin=0;
var tmax=0;
var tavg=0;
var prcp=0;
var tminvsly=0;
var tmaxvsly=0;
var tavgvsly=0;
var cdd=0;
var cddvsly=0;
var hdd=0;
var hddvsly=0;
var gdd=0;
var gddvsly=0;
var week_start_day="sunday";
var saved_planner_flag=0;
var saved_planner_id=0;
var current_location_type="loc";
var selectedLocationType="station";
var location_type="station";
var select_type="single";

var one_day_seconds=86400;
var one_day_milliseconds=one_day_seconds*1000;

var period="d";

var units="e";
var need_save=0;

var planner_name="";

//Set the HTTP Object
var planner_http = getHTTPObject();

var planner_http_request_array = [];
var planner_http_index_array = [];
planner_http_index_array[0]=1;
var xhrsend = planner_http_index_array.length;

var calendar="";

var min_date=1991231;
min_date=min_date+'';
min_yyyy=min_date.substring(0,4);
min_mm=min_date.substring(4,6);
min_dd=min_date.substring(6,8);
var nice_min_date=min_date.substring(4,6) + "/" + min_date.substring(6,8) + "/" + min_date.substring(0,4);
var nice_min_date=min_mm + "/" + min_dd + "/" + min_yyyy;
var max_date=max_fcst_date;
max_yyyy=max_date.substring(6,10);
max_mm=max_date.substring(0,2);
max_dd=max_date.substring(3,5);

function change_location_type2(type_number){
	/*
	0 => Station 
	1 => Region
	2 => Custom Region	
	*/
	//alert("type_number("+type_number+")");
	
	if(type_number === 0){
		location_type="station";
		$('#region_select').hide();
		$('#custom_region_select').hide();
		$('#station_select').show();
		chgSelectSize('single');
	}
	else if(type_number === 1){
		location_type="region";
		
		$('#custom_region_select').hide();
		$('#station_select').hide();
		$('#region_select').show();
		chgSelectSize('single');
	}
	else if(type_number === 2){
		location_type="custom_region";
		$('#region_select').hide();
		$('#station_select').hide();
		$('#custom_region_select').show();
		chgSelectSize('single');
	}else{
		alert("Invalid type_number ("+type_number+") in change_location_type");
		return false;
	}
	
	//change_country();
	
}

function change_country(type_number){
	/*
	0 => Station 
	1 => Region
	2 => Custom Region	
	*/
	//alert("type_number("+type_number+")");
	
	//Find out which location we need to show and load first
	
	if(type_number == 0){
		location_type="station";
		//REMOVE$('div#debug').append('<br>change_country called for '+location_type+'<br>');
		//REMOVE$('div#debug').append('load_country for '+location_type+'<br>');
		load_country();
		
		country_value=check_country_value("station_country");
		
		location_type="region";
		if($('#region_country').containsOption(country_value)){
			$('#region_country').selectOptions(country_value,true);
			load_country();
		}
		
		location_type="custom_region";
		if($('#custom_region_country').containsOption(country_value)){
			$('#custom_region_country').selectOptions(country_value,true);
			load_country();
		}
		
		location_type="station";
	}
	else if(type_number == 1){
		location_type="region";
		//REMOVE$('div#debug').append('<br>change_country called for '+location_type+'<br>');
		//REMOVE$('div#debug').append('load_country for '+location_type+'<br>');
		load_country();
		
		country_value=check_country_value("region_country");
		
		location_type="station";
		
		if($('#station_country').containsOption(country_value)){
			$('#station_country').selectOptions(country_value,true);
			load_country();
		}
		
		location_type="custom_region";
		if($('#custom_region_country').containsOption(country_value)){
			$('#custom_region_country').selectOptions(country_value,true);
			load_country();
		}
		
		location_type="region";
	}
	else if(type_number == 2){
		location_type="custom_region";
		load_country();
		//REMOVE$('div#debug').append('<br>change_country called for '+location_type+'<br>');
		//REMOVE$('div#debug').append('load_country for '+location_type+'<br>');
		
		country_value=check_country_value("custom_region_country");
		
		location_type="station";
		if($('#station_country').containsOption(country_value)){
			$('#station_country').selectOptions(country_value,true);
			load_country();

		}
		
		location_type="region";
		if($('#region_country').containsOption(country_value)){
			$('#region_country').selectOptions(country_value,true);
			load_country();
		}
		
		location_type="custom_region";
	}
	
}

function check_country_value(id){
	
	//Make sure ID is set
	if(id.length == 0){
		alert("id is not set");
		return false;
	}
	
	//Must be set, now pull the value of the ID
	selected_id=$("select#"+id+" option:selected");
	return $(selected_id).text();
	//alert($(selected_id).text());
	
}

function check_location_type(type){
	
	//See if "type" is even set
	if(typeof(type) == "undefined"){
		//Not set
		return false;
	}
	//See if it is a valid type
	if(type == "station" || type == "region" || type == "custom_region"){
		return true;
	}
	
	//If we got here the type must be invalid
	return false;
}

function check_state_value(id){
	
	//Make sure ID is set
	if(id.length == 0){
		alert("id is not set");
		return false;
	}
	
	//Must be set, now pull the value of the ID
	selected_id=$("select#"+id+" option:selected");
	return $(selected_id).text();
	
}

function load_country(){
	
	//Make sure a location_type is set

	if(typeof(location_type) == "undefined"){
		//location_type is not set for some reason so we will set it to station
		location_type="station";
		alert("stat");
	}
	
	if(!check_location_type(location_type)){
		//Invalid Type
		alert("type not valid");
		return false;
	}
	//alert("change_country");
	
	location_url="/ajax/locations.php";
	location_data="";
	country_value_id="";
	
	if(location_type == "station"){
		country_value_id="station_country";
		country_value=check_country_value("station_country");
		location_data="type=s_country&val="+country_value;
	}
	else if(location_type == "region"){
		country_value_id="region_country";
		country_value=check_country_value("region_country");
		location_data="type=r_country&val="+country_value;
	}
	else if(location_type == "custom_region"){
		country_value_id="custom_region_country";
		country_value=check_country_value("custom_region_country");
		location_data="type=cr_country&val="+country_value;
	}
	
	if(!country_value){
		//Invalid country_value
		alert("country not valid");
		return false;
	}else{
		//location_data="type=s_country&val="+country;
	}
	//REMOVE$('div#debug').append('<br>URL=http://beta2.myskeye.com/'+location_url+'?'+location_data+'<br>');
	
	pull_location_data(location_url,location_data,"xml");

}

function load_states(){
	//Make sure a location_type is set

	if(!check_location_type(location_type)){
		//Invalid Type
		alert("type not valid");
		return false;
	}
	
	location_url="/ajax/locations.php";
	location_data="";
	state_value_id="";
	country_value_id="";
	
	if(location_type == "station"){
		//Pull Country Data
		country_value_id="station_country";
		country_value=check_country_value("station_country");
		location_data="type=s_state&c_val="+country_value;
		
		//Pull State Data
		state_value_id="station_state";
		state_value=check_state_value(state_value_id);		
		location_data+="&val="+state_value;
	}
	
	if(!country_value){
		//Invalid country_value
		alert("country not valid");
		return false;
	}else{
		//location_data="type=s_country&val="+country;
	}
	
	if(!state_value){
		//Invalid country_value
		alert("state not valid");
		return false;
	}else{
		//location_data="type=s_country&val="+country;
	}
	
	pull_location_data(location_url,location_data,"xml");
	
}

function pull_location_data(location_url,location_data,data_type){
	
	$.ajax({
		type: "GET",
		url: location_url,
		data: location_data,
		//dataType : 'xml',
		dataType : data_type,
		success: function(xml) {
			//First Check if an error exists
			error=$("error",xml);
			if($("error",xml).length == 0){
				//$('div#debug').append('<br>NO ERROR:<br>');				
			}else{
				alert("There was an error updating the list ("+$("number",error).text()+")");
			}	
			
			
			count=$("count",xml).text();
			locations=$("locations",xml);
			type=$("type",xml).text();
			
			//If the type is not states (only happens for the US) 
			//we should "hide" the states selection box.
			if(country_value == "United States" && type == "station_state"){
				$('#showState').show();
				$('#station_location').html("<option value=''>-Please Choose A State-</option>");
			}else if(country_value != "United States"){
				$('#showState').hide();
			}

			//REMOVE$('div#debug').append('<br>Count=<br>'+count);
			
			html="";

			$('#'+type).html("<option value='' selected>-Please Choose One-</option>");
			$("location",locations).each(function(i) {
				html+="<option value=\""+$(this).attr('id')+"\">"+$(this).text()+"</option>";
			});

			$('#'+type).append(html);
			
		}
	}); //END $.ajax
	
}

/*NEW FUNCTIONS*/
function add_location(){
	var location_id=-10;
	var location_name="";
	var location_state="";
	var location_country="";
	var use_state=0;
	var old_planner_count=planner_count;
	var oldPlannerID=plannerID;
	
	if(document.planner.use_reg){
		
		//NEW SECTION START
		var selectedArray = [];
		var selObj = document.getElementById(location_type+'_location');
		var i;
		var count = 0;
		
		for(i=0; i<selObj.options.length; i++){
			//Make sure we don't have too many locations selected
			if(planner_count > planner_max - 1){
				//We have too many
				alert("You have selected more than the maximum number of planners ("+planner_max+") and so the list has been truncated. Please contact info@myskeye.com if you need more than this");
				return;
			}
			
			if (selObj.options[i].selected) {
				//var selected_index=document.planner.loc.selectedIndex;
				
				
				var selected_index=selObj.selectedIndex;
				
				location_id=selObj.options[i].value;
				location_name=selObj.options[i].text;
				//location_country=document.planner.country.value;
				location_country=document.getElementById(location_type+'_country').value;
				
				//Make sure that it is a valid value
				if(!check_location_id(location_id)){
					alert("Please choose a valid location");
					return;
				}

				planner_location_id[planner_count]=location_id;
				planner_location_type[planner_count]=location_type;
				planner_location_name[planner_count]=location_name;

				if(location_country  =="United States"){
					planner_location_country[planner_count]="USA";
				}else if(location_country  =="United Kingdom"){
					planner_location_country[planner_count]="UK";
				}else{
					planner_location_country[planner_count]=location_country;
				}
				
				if(location_type == "station"){
					if(document.getElementById('showState') && document.getElementById('showState').style.display != "none"){
						planner_location_state[planner_count]=document.planner.state.value;
					}else{
						planner_location_state[planner_count]="";
					}
					
				}
				
				get_location_name(location_id,location_type,planner_count);
				planner_count++;
				
				plannerID++;
				//REMOVEdocument.getElementById('planner_div').innerHTML+="<br \><span id='location_"+old_planner_count+"'><a href='javascript://' onclick='remove_planner_location("+ old_planner_count +");' ><img src='/images/remove.gif'></a> Added location #" + planner_count + ": " + location_name + ", " + location_country +"</span>";
				document.getElementById('planner_div').innerHTML+="<br \><span id='location_"+oldPlannerID+"'><a href='javascript://' onclick='remove_planner_location("+ oldPlannerID +");' ><img src='/images/remove.gif'></a> Added location: " + location_name + ", " + location_country +"</span>";
				old_planner_count=planner_count;
				oldPlannerID=plannerID;
			}
			
			
			
		}
		
		
		
		
	}else{
		alert("THERE IS NO use_reg VALUE SET, PLEASE DEBUG");
		return;
	}
	
	//document.planner.loc.onchange=function (){alert("YOU CHANGED IT");}
	return;
}

function use_planner_region(val){
	saved_planner_flag=0;

		
	if(show_planner_list == 1){
		if(val == 6){
			document.getElementById('planner_select').style.display = "";
			document.getElementById('region_select').style.display = "none";
			document.getElementById('custom_region_select').style.display = "none";
			document.getElementById('station_select').style.display = "none";
			document.getElementById('multi_select_span').display="none";
		}else{
			document.getElementById('planner_select').style.display = "none";
			if(val==1){
				//      alert('USE REGION');
				document.getElementById('region_select').style.display = "";
				document.getElementById('custom_region_select').style.display = "none";
				document.getElementById('station_select').style.display = "none";
				current_location_type="reg_loc";
				selectedLocationType="region";
				chgSelectSize('single');
				document.getElementById('multi_select_span').display="";
			}else if(val==2){
				document.getElementById('region_select').style.display = "none";
				document.getElementById('custom_region_select').style.display = "";
				document.getElementById('station_select').style.display = "none";
				current_location_type="client_reg_loc";
				selectedLocationType="custom_region";
				chgSelectSize('single');
				document.getElementById('multi_select_span').display="";
			}else{
				document.getElementById('region_select').style.display = "none";
				document.getElementById('custom_region_select').style.display = "none";
				document.getElementById('station_select').style.display = "";
				current_location_type="loc";
				selectedLocationType="station";
				chgSelectSize('single');
				document.getElementById('multi_select_span').display="";
			}
		}
	}else{

		if(val==1){
			//      alert('USE REGION');
			document.getElementById('region_select').style.display = "";
			document.getElementById('custom_region_select').style.display = "none";
			document.getElementById('station_select').style.display = "none";
			current_location_type="reg_loc";
			selectedLocationType="region";
		}else if(val==2){
			document.getElementById('region_select').style.display = "none";
			document.getElementById('custom_region_select').style.display = "";
			document.getElementById('station_select').style.display = "none";
			current_location_type="client_reg_loc";
			selectedLocationType="custom_region";
		}else{
			document.getElementById('region_select').style.display = "none";
			document.getElementById('custom_region_select').style.display = "none";
			document.getElementById('station_select').style.display = "";
			current_location_type="loc";
			selectedLocationType="station";
		}
	}
}



function chgSelectSize(type){
	if(!type){
		//No type specified
	}
	else if(type == "single"){
		document.getElementById(location_type+'_location').size=1;
		document.getElementById(location_type+'_location').multiple="";
		document.getElementById('multi_select_span').innerHTML="<a href='javascript:void(0);' onclick=\"chgSelectSize('multiple');\">Select Multiple</a>";
	}
	else if(type == "multiple"){
		document.getElementById(location_type+'_location').size=6;
		document.getElementById(location_type+'_location').multiple="multiple";
		document.getElementById('multi_select_span').innerHTML="<a href='javascript:void(0);' onclick=\"chgSelectSize('single');\">Select Single</a>";
	}
	else{
	}
	return 1;
}

function update_data_table_legend(){
  if(document.planner.units[0].checked){
  	if(planner_type && planner_type == 'Energy'){
  		//Energy planner
  		document.getElementById('table_settings').innerHTML="<br>\
  		<table align=center border=0 style=\"font-size:10px;\">\
        <tr>\
          <th colspan=10 align=left>\
            Data Table Legend (Versus Last Year):\
          </th>\
        </tr>\
        <tr>\
          <th colspan=10 align=left>\
            Temperature Change:\
          </th>\
        </tr>\
        <tr>\
          <td class='temp_much_colder' width='22px'>&nbsp;</td>\
          <td>Much Colder <=-5&deg;</td>\
          <td class='temp_colder' width='22px'>&nbsp;</td>\
          <td>Colder -1&deg; to -5&deg;</td>\
          <td class='temp_similar' width='22px'>&nbsp;</td>\
          <td>Similar -1&deg; to +1&deg;</td>\
          <td class='temp_warmer' width='22px'>&nbsp;</td>\
          <td>Warmer +1&deg; to +5&deg;</td>\
          <td class='temp_much_warmer' width='22px'>&nbsp;</td>\
          <td>Much Warmer >=5&deg;</td>\
        </tr>\
        <tr>\
          <th colspan=10 align=left>\
            CDD:\
          </th>\
        </tr>\
        <tr>\
          <td class='temp_much_colder' width='22px'>&nbsp;</td>\
          <td>Much Colder <85%</td>\
          <td class='temp_colder' width='22px'>&nbsp;</td>\
          <td>Colder 85% - 95%</td>\
          <td class='temp_similar' width='22px'>&nbsp;</td>\
          <td>Similar 95% - 105%</td>\
          <td class='temp_warmer' width='22px'>&nbsp;</td>\
          <td>Warmer 105% - 115%</td>\
          <td class='temp_much_warmer' width='22px'>&nbsp;</td>\
          <td>Much Warmer >115%</td>\
        </tr>\
        <tr>\
          <th colspan=10 align=left>\
            HDD:\
          </th>\
        </tr>\
        <tr>\
          <td class='temp_much_warmer' width='22px'>&nbsp;</td>\
          <td>Much Warmer <85%</td>\
          <td class='temp_warmer' width='22px'>&nbsp;</td>\
          <td>Warmer 85% - 95%</td>\
          <td class='temp_similar' width='22px'>&nbsp;</td>\
          <td>Similar 95% - 105%</td>\
          <td class='temp_colder' width='22px'>&nbsp;</td>\
          <td>Colder 105% - 115%</td>\
          <td class='temp_much_colder' width='22px'>&nbsp;</td>\
          <td>Much Colder >115%</td>\
        </tr>\
      </table>\
        ";
  	}else{
  		//Favorability planner
  		document.getElementById('table_settings').innerHTML="<br>\
  		<table align=center border=0 style=\"font-size:10px;\">\
        <tr>\
          <th colspan=10 align=left>\
            Data Table Legend (Versus Last Year):\
          </th>\
        </tr>\
        <tr>\
          <td class='temp_much_colder' width='22px'>&nbsp;</td>\
          <td>Much Colder <=-5&deg;</td>\
          <td class='temp_colder' width='22px'>&nbsp;</td>\
          <td>Colder -1&deg; to -5&deg;</td>\
          <td class='temp_similar' width='22px'>&nbsp;</td>\
          <td>Similar -1&deg; to +1&deg;</td>\
          <td class='temp_warmer' width='22px'>&nbsp;</td>\
          <td>Warmer +1&deg; to +5&deg;</td>\
          <td class='temp_much_warmer' width='22px'>&nbsp;</td>\
          <td>Much Warmer >=5&deg;</td>\
        </tr>\
        <tr>\
          <td class='prcp_much_wetter' width='22px'>&nbsp;</td>\
          <td>Much Wetter >200%</td>\
          <td class='prcp_wetter' width='22px'>&nbsp;</td>\
          <td>Wetter 125% - 200%</td>\
          <td class='prcp_similar' width='22px'>&nbsp;</td>\
          <td>Similar 75% - 125%</td>\
          <td class='prcp_drier' width='22px'>&nbsp;</td>\
          <td>Drier 50% - 75%</td>\
          <td class='prcp_much_drier' width='22px'>&nbsp;</td>\
          <td>Much Drier <50%</td>\
        </tr>\
      </table>\
      ";
  	}

  }else if(document.planner.units[1].checked){
  	if(planner_type && planner_type == 'Energy'){
  		//Energy planner
  		document.getElementById('table_settings').innerHTML="<br>\
  		<table align=center border=0 style=\"font-size:10px;\">\
        <tr>\
          <th colspan=10 align=left>\
            Data Table Legend (Versus Last Year):\
          </th>\
        </tr>\
        <tr>\
          <th colspan=10 align=left>\
            Temperature Change:\
          </th>\
        </tr>\
        <tr>\
          <td class='temp_much_colder' width='22px'>&nbsp;</td>\
          <td>Much Colder <=-2.8&deg;</td>\
          <td class='temp_colder' width='22px'>&nbsp;</td>\
          <td>Colder -0.6&deg; to -2.8&deg;</td>\
          <td class='temp_similar' width='22px'>&nbsp;</td>\
          <td>Similar -0.6&deg; to +0.6&deg;</td>\
          <td class='temp_warmer' width='22px'>&nbsp;</td>\
          <td>Warmer +0.6&deg; to +2.8&deg;</td>\
          <td class='temp_much_warmer' width='22px'>&nbsp;</td>\
          <td>Much Warmer >=2.8&deg;</td>\
        </tr>\
        <tr>\
          <th colspan=10 align=left>\
            CDD:\
          </th>\
        </tr>\
        <tr>\
          <td class='temp_much_colder' width='22px'>&nbsp;</td>\
          <td>Much Colder <85%</td>\
          <td class='temp_colder' width='22px'>&nbsp;</td>\
          <td>Colder 85% - 95%</td>\
          <td class='temp_similar' width='22px'>&nbsp;</td>\
          <td>Similar 95% - 105%</td>\
          <td class='temp_warmer' width='22px'>&nbsp;</td>\
          <td>Warmer 105% - 115%</td>\
          <td class='temp_much_warmer' width='22px'>&nbsp;</td>\
          <td>Much Warmer >115%</td>\
        </tr>\
        <tr>\
          <th colspan=10 align=left>\
            HDD:\
          </th>\
        </tr>\
        <tr>\
          <td class='temp_much_warmer' width='22px'>&nbsp;</td>\
          <td>Much Warmer <85%</td>\
          <td class='temp_warmer' width='22px'>&nbsp;</td>\
          <td>Warmer 85% - 95%</td>\
          <td class='temp_similar' width='22px'>&nbsp;</td>\
          <td>Similar 95% - 105%</td>\
          <td class='temp_colder' width='22px'>&nbsp;</td>\
          <td>Colder 105% - 115%</td>\
          <td class='temp_much_colder' width='22px'>&nbsp;</td>\
          <td>Much Colder >115%</td>\
        </tr>\
      </table>\
        ";
  	}else{
  		//Favorability planner
  		document.getElementById('table_settings').innerHTML="<br>\
  		<table align=center border=0 style=\"font-size:10px;\">\
        <tr>\
          <th colspan=10 align=left>\
            Data Table Legend (Versus Last Year):\
          </th>\
        </tr>\
        <tr>\
          <td class='temp_much_colder' width='22px'>&nbsp;</td>\
          <td>Much Colder <=-2.8&deg;</td>\
          <td class='temp_colder' width='22px'>&nbsp;</td>\
          <td>Colder -0.6&deg; to -2.8&deg;</td>\
          <td class='temp_similar' width='22px'>&nbsp;</td>\
          <td>Similar -0.6&deg; to +0.6&deg;</td>\
          <td class='temp_warmer' width='22px'>&nbsp;</td>\
          <td>Warmer +0.6&deg; to +2.8&deg;</td>\
          <td class='temp_much_warmer' width='22px'>&nbsp;</td>\
          <td>Much Warmer >=2.8&deg;</td>\
        </tr>\
        <tr>\
          <td class='prcp_much_wetter' width='22px'>&nbsp;</td>\
          <td>Much Wetter >200%</td>\
          <td class='prcp_wetter' width='22px'>&nbsp;</td>\
          <td>Wetter 125% - 200%</td>\
          <td class='prcp_similar' width='22px'>&nbsp;</td>\
          <td>Similar 75% - 125%</td>\
          <td class='prcp_drier' width='22px'>&nbsp;</td>\
          <td>Drier 50% - 75%</td>\
          <td class='prcp_much_drier' width='22px'>&nbsp;</td>\
          <td>Much Drier <50%</td>\
        </tr>\
      </table>\
      ";
  	}
  }
}

	
function handleSelect(type,args,obj) {
	var dates = args[0];
	var date = dates[0];
	var year = date[0], month = date[1], day = date[2];

	var txtDate1 = document.getElementById("start_date");
	var mm=month;
	var dd=day;
	if(month<10){
		mm="0"+month;
	}
	if(day<10){
		dd="0"+day;
	}
	//txtDate1.value = month + "/" + day + "/" + year;
	txtDate1.value = mm + "/" + dd + "/" + year;
	
	//Hide the pop-up calendar since we have selected a date already
	YAHOO.example.calendar.planner_cal.hide()
}

function updateCal() {
  var txtDate1 = document.getElementById("start_date");

	if (txtDate1.value != "") {
		YAHOO.example.calendar.planner_cal.select(txtDate1.value);
		var selectedDates = YAHOO.example.calendar.planner_cal.getSelectedDates();
		if (selectedDates.length > 0) {
			var firstDate = selectedDates[0];
			YAHOO.example.calendar.planner_cal.cfg.setProperty("pagedate", (firstDate.getMonth()+1) + "/" + firstDate.getFullYear());
			YAHOO.example.calendar.planner_cal.render();
		} else {

		}
		//document.getElementById("show_planner_cal_container").style.display="none";
			
	}
}

function matt_chg_daily(){
	
	YAHOO.example.calendar.planner_cal.removeRenderers();
	YAHOO.example.calendar.planner_cal.render();

}

function matt_chg_weekly(){

  //var m_date_regexp=/^\d\d/\d\d\/\d\d\d\d/;
  var m_date_regexp=/^\d+\/\d+\/\d\d\d\d/;


  if(week_start_day=="sunday"){
  	//alert(document.getElementById("start_date").value);
  	//return;

  	if(m_date_regexp.test(document.getElementById("start_date").value)){
      chk_day_of_week("start_date");
    }
 

    YAHOO.example.calendar.planner_cal.addWeekdayRenderer(2, YAHOO.example.calendar.planner_cal.renderOutOfBoundsDate);
    YAHOO.example.calendar.planner_cal.addWeekdayRenderer(3, YAHOO.example.calendar.planner_cal.renderOutOfBoundsDate);
    YAHOO.example.calendar.planner_cal.addWeekdayRenderer(4, YAHOO.example.calendar.planner_cal.renderOutOfBoundsDate);
    YAHOO.example.calendar.planner_cal.addWeekdayRenderer(5, YAHOO.example.calendar.planner_cal.renderOutOfBoundsDate);
    YAHOO.example.calendar.planner_cal.addWeekdayRenderer(6, YAHOO.example.calendar.planner_cal.renderOutOfBoundsDate);
    YAHOO.example.calendar.planner_cal.addWeekdayRenderer(7, YAHOO.example.calendar.planner_cal.renderOutOfBoundsDate);



    YAHOO.example.calendar.planner_cal.selectEvent.subscribe(handleSelect, YAHOO.example.calendar.planner_cal, true);

    YAHOO.example.calendar.planner_cal.render();

    YAHOO.util.Event.addListener("update", "click", updateCal);

  }else{


    if(m_date_regexp.test(document.getElementById("start_date").value)){
      chk_day_of_week("start_date");
    } 

    YAHOO.example.calendar.planner_cal.addWeekdayRenderer(1, YAHOO.example.calendar.planner_cal.renderOutOfBoundsDate);
    YAHOO.example.calendar.planner_cal.addWeekdayRenderer(2, YAHOO.example.calendar.planner_cal.renderOutOfBoundsDate);
    YAHOO.example.calendar.planner_cal.addWeekdayRenderer(3, YAHOO.example.calendar.planner_cal.renderOutOfBoundsDate);
    YAHOO.example.calendar.planner_cal.addWeekdayRenderer(4, YAHOO.example.calendar.planner_cal.renderOutOfBoundsDate);
    YAHOO.example.calendar.planner_cal.addWeekdayRenderer(5, YAHOO.example.calendar.planner_cal.renderOutOfBoundsDate);
    YAHOO.example.calendar.planner_cal.addWeekdayRenderer(6, YAHOO.example.calendar.planner_cal.renderOutOfBoundsDate);
 
    YAHOO.example.calendar.planner_cal.selectEvent.subscribe(handleSelect, YAHOO.example.calendar.planner_cal, true);

    YAHOO.example.calendar.planner_cal.render();

    YAHOO.util.Event.addListener("update", "click", updateCal);

  }

}

/*END YUI SECTION*/

function run_planner(){
	//alert('running planner');
	
	if(get_settings()==1){
		return false;
	}
	saved_planner_flag=0;
	if(document.planner.use_reg){
		if(document.planner.use_reg[3] && document.planner.use_reg[3].checked){
			saved_planner_flag=1;
		}
	}
	

	
	load_planner();
	return;
	
	
}


function get_settings(){
	
		//Check to see if the units are set
	if(document.planner.units[0].checked){
    units=document.planner.units[0].value;
  }else if(document.planner.units[1].checked){
    units=document.planner.units[1].value;
  }else{
    alert("THERE IS A PROBLEM WITH THE UNITS");
    return;
  }
  
  //Check to see which calendar is being used
	if(document.planner.calendar[0].checked){
    calendar=document.planner.calendar[0].value;
  }else if(document.planner.calendar[1].checked){
    calendar=document.planner.calendar[1].value;
  }else{
    alert("THERE IS A PROBLEM WITH THE Calendar");
    return;
  }
	
	//Check to see which variables are selected
	
	var error=check_start_date();
	if(error==1){
		//alert("There was an error");
		return 1;
	}else{
		//alert("NO error");
	}
	//return;
	
	var variableCount=0;
	
	

	if(document.planner.minTemp && document.planner.minTemp.checked){
		tmin=1;
		variableCount++;
	}else{
		tmin=0;
	}
  if(document.planner.maxTemp && document.planner.maxTemp.checked){
		tmax=1;
		variableCount++;
	}else{
		tmax=0;
	}
	if(document.planner.avgTemp && document.planner.avgTemp.checked){
		tavg=1;
		variableCount++;
	}else{
		tavg=0;
	}
	if(document.planner.prcp && document.planner.prcp.checked){
		prcp=1;
		variableCount++;
	}else{
		prcp=0;
	}
	
	if(document.planner.minTempvsly && document.planner.minTempvsly.checked){
		tminvsly=1;
		variableCount++;
	}else{
		tminvsly=0;
	}
  if(document.planner.maxTempvsly && document.planner.maxTempvsly.checked){
		tmaxvsly=1;
		variableCount++;
	}else{
		tmaxvsly=0;
	}
	if(document.planner.avgTempvsly && document.planner.avgTempvsly.checked){
		tavgvsly=1;
		variableCount++;
	}else{
		tavgvsly=0;
	}
	if(document.planner.cdd && document.planner.cdd.checked){
		cdd=1;
		variableCount++;
	}else{
		cdd=0;
	}
	if(document.planner.hdd && document.planner.hdd.checked){
		hdd=1;
		variableCount++;
	}else{
		hdd=0;
	}
	if(document.planner.gdd && document.planner.gdd.checked){
		gdd=1;
		variableCount++;
	}else{
		gdd=0;
	}
	if(document.planner.cddvsly && document.planner.cddvsly.checked){
		cddvsly=1;
		variableCount++;
	}else{
		cddvsly=0;
	}
	if(document.planner.hddvsly && document.planner.hddvsly.checked){
		hddvsly=1;
		variableCount++;
	}else{
		hddvsly=0;
	}
	if(document.planner.gddvsly && document.planner.gddvsly.checked){
		gddvsly=1;
		variableCount++;
	}else{
		gddvsly=0;
	}
	
	//Make sure we found at least one variable
	if(variableCount >= 1){
		//Found a variable, please continue
	}
	else{
		//Did not find at least one variable
		alert("Please specify at least one variable before attempting to generate a planner");
		return 1;
	}
	
	if(document.planner.increment[0].checked){
    period="d";
  }else if(document.planner.increment[1].checked){
    period="w";
  }else if(document.planner.increment[2].checked){
    period="m";
  }else{
    alert("THERE IS A PROBLEM WITH INCREMENT");
  }
	
	
}

//JQUERY SECTION START

function save_planner(){
	//alert("SAVING");
	
	
	var txt = '<p align=center>Please enter a name for this planner:<br />\
      <input type="text" id="plannerName"\
      name="planner_name_input" value="" /></p>';
	
  function mysubmitfunc(v,m){
    an = m.children('#plannerName');
    if(an.val() == ""){
      an.css("border","solid #ff0000 1px");
      //return false;
    }
    if(v){
    	//alert("Not false");
    	need_save=1;
    	
    }else{
    	//alert("is false");
    	need_save=0;
    	return true;
    }
    planner_name=document.getElementById('plannerName').value;
    //alert("planner_name_end="+planner_name);
     
    get_settings();
	
    if(planner_count<1){
	    alert("Don't you want to include some locations?");
	  }else{
	    //alert("You have selected "+planner_count+" locations");
	  }
	  //return;

    if(planner_count>=1){
				
      //Append info to URL
	    planner_data_url="/ajax/planner_ajax.php?count=" + planner_count + "&beg=" + planner_beg_yyyymmdd + "&per=" + period + "&units=" + units + "&tmin=" + tmin + "&tmax=" + tmax + "&tavg=" + tavg + "&prcp=" + prcp;
	    planner_data_url+="&tminvsly=" + tminvsly + "&tmaxvsly=" + tmaxvsly + "&tavgvsly=" + tavgvsly;
	    planner_data_url+="&cdd=" + cdd + "&hdd=" + hdd + "&gdd=" + gdd;
	    planner_data_url+="&cddvsly=" + cddvsly + "&hddvsly=" + hddvsly + "&gddvsly=" + gddvsly + "&calendar=" + calendar;
	    planner_data_url+="&save_planner=1&planner_name="+planner_name;

	    /*
	    for(i=0;i<planner_count;i++){
		    location_number=i+1;
	     	planner_data_url+="&loc_" + location_number + "=" + planner_location_id[i] + "&type_" + location_number + "=" + planner_location_type[i];
	    }
	    */
	    //alert(planner_data_url);
	    //return;
	    //document.getElementById('planner_div').innerHTML =planner_data_url;
	    //document.getElementById('debug_div').innerHTML ="sAVING "+planner_data_url;
	    //document.getElementById('debug_div').innerHTML+="<a href='"+planner_data_url+"'><span style=\"color:red;\">test "+planner_data_url+"</span></a>";
	    
	  
	    planner_http.open("GET", planner_data_url, true);
	    planner_http.onreadystatechange = handleHttpPlannerSave;
	    planner_http.send(null);

	  }else{
		  //There are no planners specified
		  return true;
	  }
      
    return true;
  }

  $.prompt(txt,{
      submit: mysubmitfunc,
      //buttons: { Ok:true }
      buttons: { Ok:true, Cancel:false }
  }).corner();
  
}

//JQUERY SECTION END


function load_planner(){
	

	
	if(planner_count>=1){
		if(planner_count==1){
		  document.getElementById('planner_div').innerHTML="<p align='center'><img src='/images/loading.gif'><br >Please wait while your planner is loading</p>";
		}else{
			document.getElementById('planner_div').innerHTML="<p align='center'><img src='/images/loading.gif'><br >Please wait while your planners are loading</p>";
		}
		
		//Append info to URL
		planner_data_url="/ajax/planner_ajax.php?count=" + planner_count + "&beg=" + planner_beg_yyyymmdd + "&per=" + period + "&units=" + units + "&tmin=" + tmin + "&tmax=" + tmax + "&tavg=" + tavg + "&prcp=" + prcp;
		planner_data_url+="&tminvsly=" + tminvsly + "&tmaxvsly=" + tmaxvsly + "&tavgvsly=" + tavgvsly;
		planner_data_url+="&cdd=" + cdd + "&hdd=" + hdd + "&gdd=" + gdd;
		planner_data_url+="&cddvsly=" + cddvsly + "&hddvsly=" + hddvsly + "&gddvsly=" + gddvsly + "&calendar=" + calendar;
		planner_data_url+="&saved_planner_flag=" + saved_planner_flag + "&saved_planner_id=" + saved_planner_id;

  
	  planner_http.open("GET", planner_data_url, true);
	  planner_http.onreadystatechange = handleHttpPlanner;
		planner_http.send(null);

	}else{
		//There are no planners specified
		//REMOVEalert("NO PLANNERS TO LOAD");
		alert("Please specify at least one location");
		return;
	}

}

function convert_date_to_yyyymmdd(date){
  yyyymmdd=date.substring(6,10)+date.substring(0,2)+date.substring(3,5);
  alert("what");
}

function check_start_date(){
  var no_date_regexp=/^Pick\sDate/;
  var valid_date_regexp=/^(\d+)\/(\d+)\/(\d{4})/;
  var invalid_loc_regexp=/Select/;
  var beg_date_reset=0;
  
  if(document.planner.start_date){
  	if(checkValidDate(document.planner.start_date.value) != 1){
  		alert("Please specify a valid start date in MM/DD/YYYY format (ex. 01/20/2009)3");
  		return 1;
  	}

  }
  else{
  	return 1;
  }
	
	
	if(document.planner.start_date){
	  var beg_date=document.planner.start_date.value;
	  
    if(no_date_regexp.test(beg_date)){
    	alert("Please specify a start date ");
    	return 1;
    }


    //Check to see if the format of the date is valid
    if(valid_date_regexp.test(beg_date)){

      match_beg=valid_date_regexp.exec(beg_date);

      var beg_date_mm=match_beg[1];
      var beg_date_dd=match_beg[2];
      var beg_date_yyyy=match_beg[3];

      if(beg_date_mm<1 || beg_date_mm>12){
        alert("\""+beg_date_mm+"\" is not a valid month.  Please specify a valid start date in MM/DD/YYYY format");
        return 1;
      }
      if(beg_date_dd<1 || beg_date_dd>31){
        alert("\""+beg_date_dd+"\" is not a valid day of the month.  Please specify a valid start date in MM/DD/YYYY format");
        return 1;
      }
      if(beg_date_yyyy<min_yyyy || beg_date_yyyy>max_yyyy){
        alert("\""+beg_date_yyyy+"\" is not a valid year.  Please specify a valid start date in MM/DD/YYYY format");
        return 1;
      }

      if(beg_date_mm.length<2){
        if(beg_date_mm*1.0<10){
          beg_date_mm="0"+beg_date_mm;
          beg_date_reset=1;
        }else{
         alert("There is a problem with the MONTH ("+beg_date_mm+") in date ("+beg_date+")");
          return 1;
        }
      }

      if(beg_date_dd.length<2){
        if(beg_date_dd*1.0<10){
          beg_date_dd="0"+beg_date_dd;
          beg_date_reset=1;
        }else{
          alert("There is a problem with the DAY ("+beg_date_dd+") in date ("+beg_date+")");
          return 1;
        }
      }

      if(beg_date_yyyy.length<4){
        alert("Please specify a valid date in MM/DD/YYYY format");
        return 1;
      }
    
      if(beg_date_reset==1){
        document.getElementById('start_date').value=beg_date_mm+"/"+beg_date_dd+"/"+beg_date_yyyy;
      }
    

      var beg_date_yyyymmdd=beg_date_yyyy+beg_date_mm+beg_date_dd;
      if(beg_date_yyyymmdd<min_date*1.0){
        alert("Please specify a start date after "+nice_min_date);
        return 1;
      }
      if(beg_date_yyyymmdd>max_date*1.0){
        alert("Please specify a start date ("+beg_date_yyyymmdd+") before "+nice_max_date);
        return 1;
      }
    }else{
      //alert("Please specify a valid start date in MM/DD/YYYY format");
      return 1;
    }
  
	  
	  
  }else{
	  alert("NO DATE");
  }
  planner_beg_yyyymmdd=beg_date_yyyy+beg_date_mm+beg_date_dd;
  return;
}

function pull_planner_settings(planner_rowid){
	
	if(document.planner.saved_planner_id){
		planner_rowid=document.planner.saved_planner_id.value;
		saved_planner_id=planner_rowid;
		//alert("LOADING PLANNER_ROWID="+planner_rowid);
		//return;
	}else{
		alert("nothing loaded");
		return;
	}
	//document.getElementById('debug_div').innerHTML="/ajax/planner_settings.php?planner_rowid="+planner_rowid;
	
	$.ajax({
	  type: "GET",
	  url: "/ajax/planner_settings.php",
	  data: "planner_rowid="+planner_rowid,
	  datatype: "xml",
	  success: function(xml) {
	  	var settings=$(xml).find('settings');
	  	tmin=settings.attr('min_temp_actual');
	  	tmax=settings.attr('max_temp_actual');
	  	tavg=settings.attr('avg_temp_actual');
	  	prcp=settings.attr('prcp_actual');
	  	tminvsly=settings.attr('min_temp_diff');
	  	tmaxvsly=settings.attr('max_temp_diff');
	  	tavgvsly=settings.attr('avg_temp_diff');
	  	cdd=settings.attr('cdd');
	  	hdd=settings.attr('hdd');
	  	gdd=settings.attr('gdd');
	  	cddvsly=settings.attr('cddvsly');
	  	hddvsly=settings.attr('hddvsly');
	  	gddvsly=settings.attr('gddvsly');
	  	calendar=settings.attr('calendar');
	  	planner_beg_yyyymmdd=settings.attr('start_yyyymmdd');
	  	units=settings.attr('units');
	  	period=settings.attr('increment');

	  	//planner_count=0;

	  	var locations=$(xml).find('location').each(function(){
	  		planner_location_id[planner_count]=$(this).attr('id');
	  		planner_location_type[planner_count]=$(this).attr('type');
	  		planner_count++;
	  		plannerID++;
	  	});//close each
	  	load_settings();
	  	document.getElementById('planner_div').innerHTML+="<br \>Planner Loaded.  Click \"Generate Planner\" to display the planner.";
	  	return;
	  }
	});
}

function load_settings(){
	
	if(units == 'm'){
		document.planner.units[0].checked=false;
		document.planner.units[1].checked=true;
	}else{
		document.planner.units[0].checked=true;
		document.planner.units[1].checked=false;
	}
	
	if(document.planner.minTemp){
		if(tmin == 1){
			document.planner.minTemp.checked=true;
		}else{
			document.planner.minTemp.checked=false;
		}
	}
	if(document.planner.minTempvsly){
		if(tminvsly == 1){
			document.planner.minTempvsly.checked=true;
		}else{
			document.planner.minTempvsly.checked=false;
		}
	}

	if(document.planner.maxTemp){
		if(tmax == 1){
			document.planner.maxTemp.checked=true;
		}else{
			document.planner.maxTemp.checked=false;
		}
	}
	if(document.planner.maxTempvsly){
		if(tmaxvsly == 1){
			document.planner.maxTempvsly.checked=true;
		}else{
			document.planner.maxTempvsly.checked=false;
		}
	}

	if(document.planner.avgTemp){
		if(tavg == 1){
			document.planner.avgTemp.checked=true;
		}else{
			document.planner.avgTemp.checked=false;
		}
	}
	if(document.planner.avgTempvsly){
		if(tavgvsly == 1){
			document.planner.avgTempvsly.checked=true;
		}else{
			document.planner.avgTempvsly.checked=false;
		}
	}

	if(document.planner.prcp){
		if(prcp == 1){
			document.planner.prcp.checked=true;
		}else{
			document.planner.prcp.checked=false;
		}
	}

	if(document.planner.cdd){
		if(cdd == 1){
			document.planner.cdd.checked=true;
		}else{
			document.planner.cdd.checked=false;
		}
	}
	if(document.planner.hdd){
		if(hdd == 1){
			document.planner.hdd.checked=true;
		}else{
			document.planner.hdd.checked=false;
		}
	}
	if(document.planner.gdd){
		if(gdd == 1){
			document.planner.gdd.checked=true;
		}else{
			document.planner.gdd.checked=false;
		}
	}
	if(document.planner.cddvsly){
		if(cddvsly == 1){
			document.planner.cddvsly.checked=true;
		}else{
			document.planner.cddvsly.checked=false;
		}
	}
	if(document.planner.hddvsly){
		if(hddvsly == 1){
			document.planner.hddvsly.checked=true;
		}else{
			document.planner.hddvsly.checked=false;
		}
	}
	if(document.planner.gddvsly){
		if(gddvsly == 1){
			document.planner.gddvsly.checked=true;
		}else{
			document.planner.gddvsly.checked=false;
		}
	}
	
	if(period == 'w'){
		document.planner.increment[0].checked=false;
		document.planner.increment[1].checked=true;
		//REMOVEmatt_chg_weekly();
		changeGraphIncrement('weekly');
	}else{
		document.planner.increment[0].checked=true;
		document.planner.increment[1].checked=false;
		//REMOVEmatt_chg_daily();
		changeGraphIncrement('daily');
	}
	
	if(document.planner.calendar){
		//Check to see which calendar is being used
		if(calendar == 'retail'){
			document.planner.calendar[0].checked=false;
			document.planner.calendar[1].checked=true;
		}else{
			document.planner.calendar[0].checked=true;
			document.planner.calendar[1].checked=false;
		}
	}
	

	
}

function check_location_id(id){
	var valid_location_regex=/^(\d+)$/;
	if(valid_location_regex.test(id)){
		return true;
	}
	//alert ("not valid");
	return false;
}

function handleHttpPlanner() {
	if (planner_http.readyState == 4) {
		
		if (planner_http.responseText.indexOf('invalid') == -1) {
			results = planner_http.responseText;
			if (results != "") {
				
        //This works in non-sucky browsers but since IE SUCKS I needed to swap it out 
        //document.getElementById('planner_div').innerHTML = results;
				
				var oldDiv = document.getElementById('planner_div');
        var newDiv = document.createElement(oldDiv.tagName);
        newDiv.id = oldDiv.id;
        newDiv.className = oldDiv.className;
        //newDiv.innerHTML = "<div></div><br><hr><br><p align='center'><b>Weather Planner</b></p><br \>" + results;
        //newDiv.innerHTML = "<div></div><p align='center'><b>Favorability Planner</b></p><hr><br>" + results;
        //newDiv.innerHTML = "<div></div><p align='center'><b>"+planner_type+" Planner</b></p><hr><br>" + results;
        //newDiv.innerHTML = "<p align='center'><b>"+planner_type+" Planner</b></p><hr>" + results;
        newDiv.innerHTML = "<br><center><b>"+planner_type+" Planner</b></center><hr>" + results;
        oldDiv.parentNode.replaceChild(newDiv, oldDiv);
        show_export_button(1);

			}
		}
	}
	http_step++;
}


function handleHttpPlannerSave() {
	if (planner_http.readyState == 4) {
		if (planner_http.responseText.indexOf('invalid') == -1) {
			results = planner_http.responseText;
			if (results != "") {
				
        //This works in non-sucky browsers but since IE SUCKS I needed to swap it out 
        //document.getElementById('planner_div').innerHTML = results;
        //alert(results);
				/*
				var oldDiv = document.getElementById('planner_div');
        var newDiv = document.createElement(oldDiv.tagName);
        newDiv.id = oldDiv.id;
        newDiv.className = oldDiv.className;
        newDiv.innerHTML = "<div></div><br><hr><br><p align='center'><b>Weather Planner</b></p><br \>" + results;
        oldDiv.parentNode.replaceChild(newDiv, oldDiv);
        */

			}
		}
	}
}


function get_location_name(id,type,number){
	var planner_loc_url="/ajax/planner_loc_name.php?id=" + id + "&type=" + type + "&num=" + number;
	//alert("running: " + planner_loc_url)
	//planner_http.open("GET", planner_loc_url, true);
	//planner_http.onreadystatechange = handleHttpPlannerLoc;
	//planner_http.send(null);
	
	//Need to find an available index, init to the last one and loop over
	//var xhrsend = planner_http_index_array.length;
	xhrsend = planner_http_index_array.length;
	
	for (var i=0; i<planner_http_index_array.length; i++) {
		// IF IT'S 1 (AVAILABLE), ALLOCATE IT FOR USE AND BREAK
		if (planner_http_index_array[i] == 1) {
			planner_http_index_array[i] = 0;
			xhrsend = i;
			break;
		}
	}
	
	// SET TO 0 SINCE IT'S NOW ALLOCATED FOR USE
	planner_http_index_array[xhrsend] = 0;
	
	
	// SET UP THE REQUEST
	if (window.ActiveXObject) {
		try {
			planner_http_request_array[xhrsend] = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				planner_http_request_array[xhrsend] = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	} else if (window.XMLHttpRequest) {
		planner_http_request_array[xhrsend] = new XMLHttpRequest();
		if (planner_http_request_array[xhrsend].overrideMimeType) {
			planner_http_request_array[xhrsend].overrideMimeType('text/html');
		}
	}
	
  planner_http_request_array[xhrsend].open("GET", planner_loc_url, true);
	planner_http_request_array[xhrsend].onreadystatechange = handleHttpPlannerLoc;
	planner_http_request_array[xhrsend].send(null);
	return;
}

function handleHttpPlannerLoc() {
	//ORIG
	/*
	if (planner_http.readyState == 4) {
		if (planner_http.responseText.indexOf('invalid') == -1) {
			results = planner_http.responseText;
			if (results != "") {

        

			}
		}
	}
	*/
	//NEW
	if (planner_http_request_array[xhrsend].readyState == 4) {
		if (planner_http_request_array[xhrsend].responseText.indexOf('invalid') == -1) {
			results = planner_http_request_array[xhrsend].responseText;
			if (results != "") {

        

			}
		}
	}
}

function remove_planner_location(number){
	if(number=="all"){
		//alert("ALL");
		planner_count=0;
		plannerID=0;

    planner_location_id = [];
    planner_location_type = [];
    planner_location_name = [];
    planner_location_state = [];
    planner_location_country = [];
    document.getElementById('planner_div').innerHTML="";
		
	}else{
	
	  //alert("REMOVING #"+number);
	  var div_id="location_"+number;

	  if(document.getElementById(div_id+"_spacer")){
	    document.getElementById(div_id+"_spacer").style.display="none";
	  }
	  
	  if(document.getElementById(div_id)){
	  	document.getElementById(div_id).style.display="none";
	  }
	  
	  if(tmin == 1 && document.getElementById(div_id+"_min_temp")){
		  document.getElementById(div_id+"_min_temp").style.display="none";
	  }
	  if(tminvsly == 1 && document.getElementById(div_id+"_min_tempvsly")){
		  document.getElementById(div_id+"_min_tempvsly").style.display="none";
	  }
	
	  if(tmax == 1 && document.getElementById(div_id+"_max_temp")){
		  document.getElementById(div_id+"_max_temp").style.display="none";
	  }
	  if(tmaxvsly == 1 && document.getElementById(div_id+"_max_tempvsly")){
		  document.getElementById(div_id+"_max_tempvsly").style.display="none";
	  }
	  
	  if(tavg == 1 && document.getElementById(div_id+"_avg_temp")){
		  document.getElementById(div_id+"_avg_temp").style.display="none";
	  }
	
	  if(tavgvsly == 1 && document.getElementById(div_id+"_avg_tempvsly")){
	  	document.getElementById(div_id+"_avg_tempvsly").style.display="none";
	  }
	 
	  if(prcp == 1 && document.getElementById(div_id+"_prcp")){
		  document.getElementById(div_id+"_prcp").style.display="none";
	  }
	  
	  if(prcp == 1 && document.getElementById(div_id+"_deg_days")){
		  document.getElementById(div_id+"_deg_days").style.display="none";
	  }
	  
	  var removeURL="/ajax/planner_loc_name.php?id=" + planner_location_id[number] + "&type=" + planner_location_type[number] + "&num=" + number;
	  var removeURL="/ajax/planner_loc_name.php";
	  //REMOVEvar removeData="id=" + planner_location_id[number] + "&type=" + planner_location_type[number] + "&num=" + number + "&remove=1";
	  var removeData="id=" + planner_location_id[number] + "&type=" + planner_location_type[number] + "&num=" + number + "&remove=1";
	  
	  
	  $.ajax({
		  type: "GET",
		  url: removeURL,
		  data: removeData,
		  //dataType : 'xml',
		  dataType : 'text',
		  success: function(xml) {
		  	//First Check if an error exists
		  	error=$("error",xml);
		  	if($("error",xml).length == 0){
		  		//$('div#debug').append('<br>NO ERROR:<br>');				
		  	}else{
		  		alert("There was an error updating the list ("+$("number",error).text()+")");
		  		//REMOVE$('div#debug').append('<br>ERROR:<br>');
		  	}
		  }
		}); //END $.ajax
	  
	  /*REMOVE	
		planner_location_id.splice(number,1);
    planner_location_type.splice(number,1);
    planner_location_name.splice(number,1);
    planner_location_state.splice(number,1);
    planner_location_country.splice(number,1);
	  planner_count--;
	  */
	  //Loop over all the current locations so that we can consolidate the arrays
	  var tmp_planner_location_id = [];
	  var tmp_planner_location_type = [];
	  var tmp_planner_location_name = [];
	  var tmp_planner_location_state = [];
	  var tmp_planner_location_country = [];
	  var plannerIndex=0;
	  for(var i = 0;i < planner_count; i++){
	  	if(i != number){
	  		tmp_planner_location_id[plannerIndex]=planner_location_id[i];
	  		tmp_planner_location_type[plannerIndex]=planner_location_type[i];
	  		tmp_planner_location_name[plannerIndex]=planner_location_name[i];
	  		tmp_planner_location_state[plannerIndex]=planner_location_state[i];
	  		tmp_planner_location_country[plannerIndex]=planner_location_country[i];
	  		plannerIndex++;
	  	}
	  }
	  
	  planner_count--;
	  //Reset all the arrays
	  planner_location_id = [];
	  planner_location_type = [];
	  planner_location_name = [];
	  planner_location_state = [];
	  planner_location_country = [];
	  
	  planner_location_id = tmp_planner_location_id;
	  planner_location_type = tmp_planner_location_type;
	  planner_location_name = tmp_planner_location_name;
	  planner_location_state = tmp_planner_location_state;
	  planner_location_country = tmp_planner_location_country;
	  
	}

}

function show_export_button(show){
	if(use_export === 1){
		if(show === 0){
			document.getElementById('export_button_span').style.display="none";
		}else{
			document.getElementById('export_button_span').style.display="";
		}
	}
}


function chk_day_of_weekPlan(id){
	
	if(document.planner.increment[0].checked){
    period="d";
  }else if(document.planner.increment[1].checked){
    period="w";
    
    id_date=document.getElementById(id).value;
    cur_date=new Date();
    cur_date.setFullYear(id_date.substring(6,10),id_date.substring(0,2)-1,id_date.substring(3,5));
    cur_day=cur_date.getDay();
    var new_date=new Date();
    if(week_start_day=="sunday"){
      var add_seconds=(cur_day)*one_day_milliseconds*-1;
    }else{
      var add_seconds=(6-cur_day)*one_day_milliseconds;
    }

    new_date.setTime(cur_date.getTime()+add_seconds);
    var new_cur_mm=new_date.getMonth()+1;
    var new_cur_dd=new_date.getDate();
    var new_cur_yyyy=new_date.getFullYear();
    if(new_cur_mm<10){
      new_cur_mm="0"+new_cur_mm;
    }
    if(new_cur_dd<10){
      new_cur_dd="0"+new_cur_dd;
    }
  
    var new_cur_date=new_cur_mm+"/"+new_cur_dd+"/"+new_cur_yyyy;


    document.getElementById(id).value=new_cur_date;

    var p=check_start_date();
    if(p==1){
      p=0;
      return;
    }else{
    }

    document.getElementById(id).value=new_cur_date;
    
  }else if(document.planner.increment[2].checked){ //Monthly increment
    period="w";
    
    id_date=document.getElementById(id).value;
    cur_date=new Date();
    cur_date.setFullYear(id_date.substring(6,10),id_date.substring(0,2)-1,id_date.substring(3,5));
    cur_day=cur_date.getDay();
    var new_date=new Date();
    if(week_start_day=="sunday"){
      var add_seconds=(cur_day)*one_day_milliseconds*-1;
    }else{
      var add_seconds=(6-cur_day)*one_day_milliseconds;
    }

    new_date.setTime(cur_date.getTime()+add_seconds);
    var new_cur_mm=new_date.getMonth()+1;
    var new_cur_dd=new_date.getDate();
    var new_cur_yyyy=new_date.getFullYear();
    if(new_cur_mm<10){
      new_cur_mm="0"+new_cur_mm;
    }
    if(new_cur_dd<10){
      new_cur_dd="0"+new_cur_dd;
    }
  
    var new_cur_date=new_cur_mm+"/"+new_cur_dd+"/"+new_cur_yyyy;


    document.getElementById(id).value=new_cur_date;

    var p=check_start_date();
    if(p==1){
      p=0;
      return;
    }else{
    }

    document.getElementById(id).value=new_cur_date;
    
  }else{
    alert("THERE IS A PROBLEM WITH INCREMENT");
  }

}