// show a help window
function showHelp( url) {
	var peacockHelp= window.open( url, 
		'peacockHelp',
		'resizable=yes,location=no,menubar=no,scrollbars=yes,status=yes,toolbar=no,' + 
		'fullscreen=no,dependent=no,width=500,height=800,left=20,top=20'); 
	peacockHelp.focus(); 
	return false;
}

// show a template window
function showTemplates( offset) {
	var peacockTemplate= window.open( '../admin/templates.php?nomenu=1&offset=' + offset, 
			'peacockTemplate',
			'resizable=yes,location=no,menubar=no,scrollbars=yes,status=yes,toolbar=no,' + 
	'fullscreen=no,dependent=no,width=600,height=700,left=60,top=60'); 
	peacockTemplate.focus(); 
	return false;
}

function noOp() {}

function getDate() {
	var d= new Date();
	return d.getMonth()+ 1 + "/" + d.getDate() + "/" + d.getFullYear() ;	
}

function fieldStamp( i, s) {
	var d= new Date();
	var stamp= getDate() + " - " + (s ? s : '');
	$(i).value= stamp + "\n\n" + $(i).value;
	setCaretPosition($(i), stamp.length);
}

function setCaretPosition(ctrl , pos)
{
	if(ctrl.setSelectionRange)
	{
		ctrl.focus();
		ctrl.setSelectionRange(pos,pos);
	}
	else if (ctrl.createTextRange) {
		var range = ctrl.createTextRange();
		range.collapse(true);
		range.moveEnd('character', pos);
		range.moveStart('character', pos);
		range.select();
	}
}

var gaViolations= [
   	"violationTypeAge",
	"violationTypeAnimal",
	"violationTypeConstruction",
	"violationTypeDriveway",
	"violationTypeDues",
	"violationTypeGarage",
	"violationTypeLandscaping",
	"violationTypeNuisance",
	"violationTypeOther",
	"violationTypePaint",
	"violationTypeParking",
	"violationTypeRoof",
	"violationTypeSurvey",
	"violationTypeTrash"
	];

var gaViolationsteps= [
	"violationStepFriendlyNotice",
	"violationStepNotice",
	"violationStepHearing",
   	"violationStepFineLetter",
	"violationStepV2",
	"violationStepV3"
	];

function violationClose() {
	var current= $('violationMemoCurrent').value;
	if( current.length > 0) {
		$('violationMemoPast').value= current + "\n\n" + $('violationMemoPast').value;
		$('violationMemoCurrent').value= "";
	}
	
	var stamp="CLOSED";
	
	// violation Checkboxes
	var violations= "";
	for( var i= 0; i < gaViolations.length; i++) {
		e= $(gaViolations[i]);
		if( e.checked) {
			violations += " " + gaViolations[i].substr(13);
			e.checked= false;
		}
	}
	if( violations.length > 0) { 
		violations= "Violations:" + violations;
		stamp+= ", " + violations;
	} else {
		alert( "There are no Violations checked off");
		return;
	}
	
	// Description
	e= $('violationDescription');
	if( e.value.length > 0) { stamp += " (" + e.value + ")"; }
	e.value="";
	
	// Received
	e= $('violationConfirmDate');
	if( e.value.length > 0) { stamp += ", Confirmed: " + e.value; }
	e.value="";
	
	// violation Steps
	var steps= "";
	for( var i= 0; i < gaViolationsteps.length; i++) {
		e= $(gaViolationsteps[i]+"Yes");
		if( e.checked) {
			steps += " " + gaViolationsteps[i].substr(13);
			e.checked= false;
			$(gaViolationsteps[i]+"No").checked= true;
		}
	}
	if( steps.length > 0) { 
		steps= "Steps:" + steps;
		stamp+= ", " + steps;
	}
	$('violationFollowUpDate').value= "";
	$('violationFollowUpYes').checked= false;
	$('violationFollowUpNo').checked= true;
	
	fieldStamp( 'violationMemoPast', stamp);
}

var gaRFAs= [
 	"rfaTypeConstruction",
	"rfaTypeFence",
	"rfaTypeFrontDoor",
	"rfaTypeGarageDoor",
	"rfaTypeOther",
	"rfaTypePaint",
	"rfaTypeRoof",
	"rfaTypeWall",
	"rfaTypeWindows"
     ];

function rfaClose() {
	var current= $('rfaMemoCurrent').value;
	if( current.length > 0) {
		$('rfaMemoPast').value= current + "\n\n" + $('rfaMemoPast').value;
		$('rfaMemoCurrent').value= "";
	}
	
	var stamp="CLOSED";
	
	// rfa Checkboxes
	var rfas= "";
	for( var i= 0; i < gaRFAs.length; i++) {
		e= $(gaRFAs[i]);
		if( e.checked) {
			rfas += " " + gaRFAs[i].substr(7);
			e.checked= false;
		}
	}
	if( rfas.length > 0) { 
		rfas= "RFAs:" + rfas;
		stamp+= ", " + rfas;
	} else {
		alert( "There are no RFAs checked off");
		return;
	}
	
	// Description
	e= $('rfaDescription');
	if( e.value.length > 0) { 
		stamp += " (" + e.value + ")"; 
		e.value="";
	}
	
	// Received
	e= $('rfaReceivedDate');
	if( e.value.length > 0) { stamp += ", Received: " + e.value; }
	e.value="";
	
	// Inspected
	e= $('rfaInspectedDate');
	if( e.value.length > 0) { stamp += ", Inspected: " + e.value; }
	e.value="";
	
	// Roof Mate
	e= $('rfaRoofMateDate');
	if( e.value.length > 0) { stamp += ", RoofMate: " + e.value; }
	e.value="";
	
	// Approval
	e= $('rfaApprovedDate');
	if( e.value.length > 0) { 
		stamp += ", Approved: " + e.value; 
		e.value="";
		e= $('rfaApprovedBy');
		if( e.value.length > 0) { 
			stamp += " by " + e.value; 
			e.value="";
		}
	}
	
	$('rfaNewYes').checked= false;
	$('rfaNewNo').checked= true;

	fieldStamp( 'rfaMemoPast', stamp);
}


