
function confirmNav(nav) {
	if (document.edit && document.edit.changed) {
		if (document.edit.changed.value == 1) {
			if (confirm("Leave without saving your changes?")) {
				eval(nav);
			}
		}
		else {
			eval(nav);
		}
	}
	else {
		eval(nav);
	}
}

function setConfirmNav() {
	if (document.edit && document.edit.changed) {
		document.edit.changed.value = 1;
	}
}

function uRailLoad(loadTaskId) {
	parent.document.getElementById('task_children_' + loadTaskId).innerHTML = document.body.innerHTML;
}

function annotate() {
	now = new Date;
	var month = now.getMonth() + 1;
	if (month < 10) { 
		month = "0" + month;
	}
	if (now.getDate() < 10) { 
		var day = "0" + now.getDate();
	}
	else {
		var day = now.getDate();
	}
	if (now.getMinutes() < 10) { 
		var minutes = "0" + now.getMinutes();
	}
	else {
		var minutes = now.getMinutes();
	}
	if (now.getHours() < 10) { 
		var hours = "0" + now.getHours();
	}
	else {
		var hours = now.getHours();
	}
	var add = "-----  " + month + "-" + day + "-" + now.getFullYear() + " @ " + hours + ":" + minutes + 
	          "  ---------------------\n\n\n\n----------------------------------------------------\n\n";
	document.edit.task_notes.value = add + document.edit.task_notes.value;
}


function showPicker(type, target, date) {
// date is expected in YYYY-MM-DD format
	var URL;
	var stats;
	
	URL = "picker.php?type=" + type + "&target=" + target + "&date=" + date;

	if (type.indexOf("parent") != -1) {
		stats = "height=500, width=450, scrollbars=yes, toolbar=no, location=no, status=yes";
	}
	else if (type.indexOf("date") != -1) {
		stats = "height=275, width=315, scrollbars=yes, toolbar=no, location=no, status=yes";
	}
	else {
		stats = "height=500, width=500, scrollbars=yes, toolbar=no, location=no, status=yes";
	}
	window.open(URL, "picker", stats);
}

function list_ldap_search() {

	document.forms["list_ldap"].ldap.value = 0;
	document.forms["list_ldap"].search.value = 1;
	document.forms["list_ldap"].submit();
}

function submit_deleteuser() {

	document.forms["list"].remove.value = 1;
	document.forms["list"].submit();
}

function remove_assuserproject(){
	
	document.forms["list_userproject"].remove.value = 1;
	document.forms["list_userproject"].submit();
}

function remove_assuserprospect(){
	
	document.forms["list_userprospect"].remove.value = 1;
	document.forms["list_userprospect"].submit();
}

function launch_skill_data(select_user){
	
	view_skill(select_user);
}

function view_skill(select_user){
	
	var URL;
	var stats;
		
	URL = "view_skill_data.php?select_user=" + select_user;
	
	stats = "height=150, width=300, scrollbars=yes, toolbar=no, location=no, status=yes";
	
	window.open(URL, "Skill", stats);
}

function launch_prospect_data(select_user){
	
	view_prospect_data(select_user);
}

function view_prospect_data(select_user){
	
	var URL;
	var stats;
		
	URL = "view_prospect_data.php?select_user=" + select_user;
	
	stats = "height=200, width=300, scrollbars=yes, toolbar=no, location=no, status=yes";
	
	window.open(URL, "Skill", stats);
}

function launch_project_data(select_user){
	
	view_project_data(select_user);
}

function view_project_data(select_user){
	
	var URL;
	var stats;
		
	URL = "view_project_data.php?select_user=" + select_user;
	
	stats = "height=150, width=300, scrollbars=yes, toolbar=no, location=no, status=yes";
	
	window.open(URL, "Skill", stats);
}

function evolution(){
	
	var URL;
	var stats;
		
	URL = "evolution_data.php";
	
	stats = "height=500, width=800, scrollbars=yes, toolbar=no, location=no, status=yes, resizable=yes";
	
	window.open(URL, "Evolution", stats);
}


function export_project(){
	
	document.forms["list"].export_file.value = 1;
	document.forms["list"].submit();
}

function valid_project(){
	
	document.forms["list"].valid.value = 1;
	document.forms["list"].submit();
}

function modify_project(){
	
	document.forms["list"].modify.value = 1;
	document.forms["list"].submit();
}

function history(){

	document.forms["list_prospect"].history_prospect.value = 1;
	document.forms["list_prospect"].submit();
}
function show_history_screen(select_prospect,status) {

	var URL;
	var stats;

	URL = "history_prospect.php?select_prospect=" + select_prospect+ "&status="+ status;
	stats = "height=250, width=600, scrollbars=yes, toolbar=no, location=no, status=yes, rezisable=yes";
		
	window.open(URL, "history", stats);
}
function history_data(){

	document.forms["list_prospect"].history_prospect_data.value = 1;
	document.forms["list_prospect"].submit();
}
function show_history_screen_data(select_prospect) {

	var URL;
	var stats;

	URL = "history_prospect_data.php?select_prospect=" + select_prospect;
	stats = "height=300, width=700, scrollbars=yes, toolbar=no, location=no, status=yes, rezisable=yes";
		
	window.open(URL, "history", stats);
}

function win(){

	document.forms["list_prospect"].win_prospect.value = 1;
	document.forms["list_prospect"].submit();
}

function lost(){
	
	document.forms["list_prospect"].lost_prospect.value = 1;
	document.forms["list_prospect"].submit();
}

function delete_prospect(){
	
	document.forms["list_prospect"].remove.value = 1;
	document.forms["list_prospect"].submit();
}

function show_comment_screen(title, title_comment,comment_error,data_log) {
	var URL;
	var stats;
	var com;
	URL = "comment.php?comment=" + comment_error+"&title="+ title +"&title_comment="+ title_comment
		+"&comment_log="+ data_log;

	if ( comment_error == 0 ) {
		URL = "comment.php?comment=" + comment_error+"&title="+ title +"&title_comment="+ title_comment
		+"&comment_log="+ data_log;
		stats = "height=50, width=400, scrollbars=no, toolbar=no, location=no, status=no";
	} else {
		URL = "comment.php?comment=" + comment_error+"&title="+ title +"&title_comment="+ title_comment
		+"&comment_log="+ data_log;	
		stats = "height=500, width=400, scrollbars=yes, toolbar=no, location=no, status=yes";
	}
	if ( comment_error == 999 ){
		URL = "comment.php?comment=" + comment_error+"&title="+ title +"&title_comment="+ title_comment
		+"&comment_log="+ data_log;	
		stats = "height=500, width=600, scrollbars=yes, toolbar=no, location=no, status=yes";
	}
		

	window.open(URL, "picker", stats);
}

function show_image_screen(title, title_comment,comment_error,data_log) {
	var URL;
	var stats;
	var com;
	URL = "comment.php?comment=" + comment_error+"&title="+ title +"&title_comment="+ title_comment
		+"&comment_log="+ data_log;

	if ( comment_error == 0 ) {
		URL = "comment.php?comment=" + comment_error+"&title="+ title +"&title_comment="+ title_comment
		+"&comment_log="+ data_log;
		stats = "height=50, width=400, scrollbars=no, toolbar=no, location=no, status=no";
	} else {
		URL = "comment.php?comment=" + comment_error+"&title="+ title +"&title_comment="+ title_comment
		+"&comment_log="+ data_log;	
		stats = "height=500, width=400, scrollbars=yes, toolbar=no, location=no, status=yes";
	}
	if ( comment_error == 999 ){
		URL = "comment.php?comment=" + comment_error+"&title="+ title +"&title_comment="+ title_comment
		+"&comment_log="+ data_log;	
		stats = "height=500, width=600, scrollbars=yes, toolbar=no, location=no, status=yes";
	}
		

	window.open(URL, "image", stats);
}

function show_activity_image(connected_user,name_user,date_start,date_end,detail) {

	var URL;
	var stats;

	URL = "activity_image.php?select_user=" + connected_user +"&name_user="+ name_user +"&date_start="+ date_start
		+"&date_end="+ date_end+"&detail="+ detail;	
	stats = "height=500, width=900, scrollbars=yes, toolbar=no, location=no, status=yes, rezisable=yes";
		
	window.open(URL, "image", stats);
}

function show_calendar_image(connected_user,name_user,date_start,date_end,detail) {

	var URL;
	var stats;

	URL = "calendar_image.php?select_user=" + connected_user +"&name_user="+ name_user +"&date_start="+ date_start
		+"&date_end="+ date_end+"&detail="+ detail;	
	stats = "height=500, width=900, scrollbars=yes, toolbar=no, location=no, status=yes, rezisable=yes";
		
	window.open(URL, "image", stats);
}

function submit_assignement(select_user) {

	var URL;
	var stats;

	URL = "assignement.php?select_user="+select_user;
	stats = "height=500, width=900, scrollbars=yes, toolbar=no, location=no, status=yes, resizable=yes";
		
	window.open(URL, "assignement", stats);
}
function submit_calendar(list_page){

	document.forms["list"].export_calendar.value = 1;
	document.forms["list"].action = list_page;
	document.forms["list"].submit();
}

function pickDate(thisYear, thisMonth, thisDay, target) {
	if (target == "edit") {
		setSelectToValue(window.opener.document.edit.task_month, thisMonth);
		setSelectToValue(window.opener.document.edit.task_day, thisDay);
		setSelectToValue(window.opener.document.edit.task_year, thisYear);
		window.opener.setConfirmNav();
		window.close();
	}
	else 	if (target == "edit2") {
		setSelectToValue(window.opener.document.edit.task_month2, thisMonth);
		setSelectToValue(window.opener.document.edit.task_day2, thisDay);
		setSelectToValue(window.opener.document.edit.task_year2, thisYear);
		window.opener.setConfirmNav();
		window.close();
	}
	else 	if (target == "edit3") {
		setSelectToValue(window.opener.document.edit.task_month3, thisMonth);
		setSelectToValue(window.opener.document.edit.task_day3, thisDay);
		setSelectToValue(window.opener.document.edit.task_year3, thisYear);
		window.opener.setConfirmNav();
		window.close();
	}
	else 	if (target == "edit4") {
		setSelectToValue(window.opener.document.edit.task_month4, thisMonth);
		setSelectToValue(window.opener.document.edit.task_day4, thisDay);
		setSelectToValue(window.opener.document.edit.task_year4, thisYear);
		window.opener.setConfirmNav();
		window.close();
	}
}

function selectedDate(formName, prefix) {
	var selectedYear;
	var selectedMonth;
	var selectedDay;
	eval("selectedYear = document." + formName + "." + prefix + "_year.options[document." + formName + "." + prefix + "_year.selectedIndex].value;");
	eval("selectedMonth = document." + formName + "." + prefix + "_month.options[document." + formName + "." + prefix + "_month.selectedIndex].value;");
	eval("selectedDay = document." + formName + "." + prefix + "_day.options[document." + formName + "." + prefix + "_day.selectedIndex].value;");
	return selectedYear + "-" + selectedMonth + "-" + selectedDay;
}

function toggleGroupBackground(thisDiv, prefix) {
	var i;
	for (i = 0; document.getElementById(prefix + i); i++) {
		document.getElementById(prefix + i).className = "group";
	}
	thisDiv.className = "groupActive";
}

function validateEditData() {
	var day = document.edit.task_day[document.edit.task_day.selectedIndex].value;
	var month = document.edit.task_month[document.edit.task_month.selectedIndex].value;
	var year = document.edit.task_year[document.edit.task_year.selectedIndex].value;
	if (day != "" || month != "" || year != "") {
		var editDate = new Date(parseFloat(year), parseFloat(month)-1, parseFloat(day));
// editDate = new Date(parseFloat(document.edit.task_year[document.edit.task_year.selectedIndex].value), parseFloat(document.edit.task_month[document.edit.task_month.selectedIndex].value)-1, parseFloat(document.edit.task_day[document.edit.task_day.selectedIndex].value));alert(editDate.getDate());
		if (editDate.getDate() != day || editDate.getMonth() != (month - 1) || editDate.getFullYear() != year) {
			return "The current value in the Date Due field is not a valid date. Change or clear this value before Saving.";
		}
		else {
			return true;
		}
	}
	else {
		return true;
	}
}
