function SetFormFocus(){
	if(document.forms[0]){
		document.forms[0].elements[0].focus();
	}
}

function FormCheck(){
	var UserForm = document.forms[0];
	if(UserForm.Password2.value != UserForm.Password.value){
		alert("The passwords you entered do not match.  Please reenter them.");
		UserForm.Password.value = '';
		UserForm.Password2.value = '';
		return false;
	}
	if(UserForm.Password2.value == "" || UserForm.Password.value == ""){
		alert("You can not leave either password field blank.");
		return false;
	}
}

function Add_Files(sMaintenance_Action, iDocument_ID, sWeb_Relative_Path){
	if(sMaintenance_Action == "Update"){
		var sConfirmUpdate = Confirm_AC_Update();	
		if(!sConfirmUpdate){
			return;
			}	
		}
	var sDocument_Location = Create_URL_QueryString("File", sMaintenance_Action, iDocument_ID, sWeb_Relative_Path);
	document.location = sDocument_Location;
}

function Add_Changes(sMaintenance_Action, iDocument_ID, sWeb_Relative_Path){
	if(sMaintenance_Action == "Update"){
		var sConfirmUpdate = Confirm_AC_Update();	
		if(!sConfirmUpdate){
			return;
			}	
	}
	var sDocument_Location = Create_URL_QueryString("Change", sMaintenance_Action, iDocument_ID, sWeb_Relative_Path);
	document.location = sDocument_Location;
}


function Create_URL_QueryString(sMaintenance_Type, sMaintenance_Action, iDocument_ID, sWeb_Relative_Path){

	var sReference_Number = document.getElementById('txtReference_Number').value;
	var sTitle = document.getElementById('txtTitle').value;
	var dPublication_Date = document.getElementById('txtPublication_Date').value;
	var sDescription = document.getElementById('txtDescription').value;
	var sOwner = document.getElementById('owner').value;
	var sPhone = document.getElementById('phone').value;
	var sConsolidated_Change = document.getElementById('chkChange');
	var sOffice = document.getElementById('cbxOffice');
	var sCategories = document.getElementById('chkCategories');
	var sCancelled = document.getElementById('sCancelled');
	
	

	var sNext_Action = "Add" + sMaintenance_Type;
	var lConsolidated_Changes = 0;
	
	if(sConsolidated_Change){
		for(i=0; i < sConsolidated_Change.length; i++){
			if(sConsolidated_Change[i].checked){
				var lConsolidated_Changes = lConsolidated_Changes + "," + sConsolidated_Change[i].value;	
				}
			}
		}
		
	for(i=0; i < sOffice.length; i++){
		if(sOffice.options[i].selected){
			var iOffice = sOffice.options[i].value;
			}
		}

	var sCategories = 1;
	for(i=0; i < sCategories.length; i++){
		if(sCategories.options[i].checked){
			var sCategories = sCategories + "," + sCategories[i].value;
			}
		}

	for(i=0; i < sCancelled.length; i++){
		if(sCancelled.options[i].selected){
			var sCancelled = sCancelled.options[i].value;
			}
		}
	
	var sDocument_Location = sWeb_Relative_Path + "/model/Fusebox.cfm?Document_ID=" + iDocument_ID + "&Reference_Number=" + sReference_Number;
	var sDocument_Location = sDocument_Location + "&Title=" + sTitle + "&Publication_Date=" + dPublication_Date;
	var sDocument_Location = sDocument_Location + "&Category_List=" + sCategories + "&Description=" + sDescription;
	var sDocument_Location = sDocument_Location + "&Office_ID=" + iOffice + "&Maintenance_Action=" + sMaintenance_Action;	
	var sDocument_Location = sDocument_Location + "&Maintenance_Type=AC&Cancelled=" + sCancelled;
	var sDocument_Location = sDocument_Location + "&Next_Action=" + sNext_Action;	
	var sDocument_Location = sDocument_Location + "&lConsolidated_Changes=" + lConsolidated_Changes;
	var sDocument_Location = sDocument_Location + "&owner=" + sOwner;
	var sDocument_Location = sDocument_Location + "&phone=" + sPhone;

	return sDocument_Location;
}

function Confirm_AC_Update(){
	var sConfirmUpdate = confirm("The information in the form presently will be submitted to the database. Continue?")
	return sConfirmUpdate;	
	}

function temp_Form_Submission(sWeb_Relative_Path)
{
	
	var iChange_ID = document.getElementById('hChange_ID').value;
	var iDocument_ID = document.getElementById('hDocument_ID').value;
	var sTitle = document.getElementById('txtTitle').value;
	var dPublication_Date = document.getElementById('txtPublication_Date').value;
	var sDescription = document.getElementById('txtDescription').value;
	var sChange_Maintenance_Action = document.getElementById('hMaintenance_Action').value;
	var sDocument_Maintenance_Action = document.getElementById('hDocument_Maintenance_Action').value;
	var sReference_Number = document.getElementById('txtReference_Number').value;

	//var iChange_ID = document.forms["AC_Change_Maintenance_Form"].hChange_ID.value;
	//var iDocument_ID = document.forms["AC_Change_Maintenance_Form"].hDocument_ID.value;
	//var sTitle = document.forms["AC_Change_Maintenance_Form"].txtTitle.value;
	//var dPublication_Date = document.forms["AC_Change_Maintenance_Form"].txtPublication_Date.value;
	//var sDescription = document.forms["AC_Change_Maintenance_Form"].txtDescription.value;
	//var sChange_Maintenance_Action = document.forms["AC_Change_Maintenance_Form"].hMaintenance_Action.value;
	//var sDocument_Maintenance_Action = document.forms["AC_Change_Maintenance_Form"].hDocument_Maintenance_Action.value;
	//var sReference_Number = document.forms["AC_Change_Maintenance_Form"].txtReference_Number.value;

	var sURL = sWeb_Relative_Path + "/model/Fusebox.cfm?Maintenance_Type=temp_AC_Change&Maintenance_Action=Add&Change_ID=" + iChange_ID + "&Document_ID=" + iDocument_ID;
	var sURL = sURL + "&Title=" + sTitle + "&Publication_Date=" + dPublication_Date + "&Description=" + sDescription + "&Change_Maintenance_Action=" + sChange_Maintenance_Action;
	var sURL = sURL + "&Reference_Number=" + sReference_Number;
	var sURL = sURL + "&Document_Maintenance_Action=" + sDocument_Maintenance_Action;
	
	document.location = sURL;
}

