var localResources = new Array();
localResources["Campaign Name"] = "Campaign Name is required.";
localResources["Campaign Schedule"] = "Select either Now or non-zero Frequency, not both.";
localResources["Campaign Schedule_1"] = "Please select either Now or specify a non-zero Frequency.";
localResources["Campaign Date_End"] = "Invalid Date Range!\nEnd Date has already passed!";
localResources["Campaign Date_Start"] = "Invalid Date Range!\nStart Date cannot be after End Date.";
localResources["Campaign TargetFile"] = "Please upload a Target File.";
localResources["Campaign Message"] = "Please input the message to be delivered.";

localResources["Help Start_date"] = "If your campaign has a begin and end date, fill in those dates here. If it is one time only, and you want to schedule the date your message is sent, fill in the same date for both Start and End. Then go to the time section below to set the time of day you want your messages sent.";
localResources["Help Now"] = "If Now is selected the message will be sent immediately. Either Frequency must be specified or Now must be selected.";  
localResources["Help Email"] = "If this is selected an email will be sent out. email addresses must be included in the data file that you upload.";
localResources["Help VarField"] = "To delete a variable field, just blank out its value in the corresponding Field Name box";

localResources["Help MobileNumber"] = "No spaces, dashes, etc. For example 12125556789";
localResources["Help Groups"] = "To select or deselect more than one, hold down the Control key and click.";

// Pop up help window
function show_help(help_text) {
	help_window = open("","displayWindow","width=300,height=200,left=10,top=10");
 	help_window.document.open();	
	help_window.document.write(
		"<link rel='stylesheet' type='text/css' href='styles/styles_backend.css'/>") 	
	help_window.document.write("<span class='link_text_h'>");
	help_window.document.write("<div align='left'>");
	help_window.document.write(localResources[help_text]);
	help_window.document.write("</div>");
	
	help_window.document.write("</span>");
	help_window.document.write('<p><p><a href="javascript:self.close()">Close</a> the popup.</p></p>');	
	
	help_window.document.close();
}

function checkDate(form) {
	var fromDate = form.start_dateStr.value;
	var toDate = form.end_dateStr.value;
	var dtfmt = form.date_format.value;
	
	var today = formatDate(new Date(), dtfmt);

	if (Date.parse(fromDate) > Date.parse(toDate)) {
		alert(localResources["Campaign Date_Start"]);
		return false;
	}

	if (compareDates(today, dtfmt, toDate, dtfmt) > 0) {
		alert(localResources["Campaign Date_End"]);
		return false;	
	}
	
	return true;
}

function checkDate1(form) {
	var fromDate = form.start_dateStr.value;
	var toDate = form.end_dateStr.value;
	var today = formatDate(new Date(), "M/d/y");

	if (Date.parse(fromDate) > Date.parse(toDate)) {
		alert(localResources["Campaign Date_Start"]);
		return false;
	}

	if (compareDates(today, "M/d/y", toDate, "M/d/y") > 0) {
		alert(localResources["Campaign Date_End"]);
		return false;	
	}
	
	return true;
}

//validate the campaign create/update forms
function validate(form) {
	if (form.name.value == "") {
		alert(localResources["Campaign Name"]);
		return false;
	}
	
	if (form.frequency.value > 0 && 
		form.frequency_now.checked) {
		alert(localResources["Campaign Schedule"]);
		return false;
	}
	
	if (form.frequency.value <= 0 && 
		! form.frequency_now.checked) {
		alert(localResources["Campaign Schedule_1"]);
		return false;
	}
	
	if (!checkDate(form))
		return false;
	
	return true;
}

//check if there is a target file
function checkTargetFile(mode) {
	if (document.forms[0].target_file_path.value == "" 
		&& document.forms[0].targetFile.value == "") {
		alert(localResources["Campaign TargetFile"]);
		return false;
	}

	if (mode == 0) { // do not check for message 
		return true;
	}
	
	if (document.forms[0].offer_text.value == "") {
		alert(localResources["Campaign Message"]);
		return false;
	}
	
	return true;
}


