function confirm_delete() {
	if (confirm("Are you sure you want to PERMANENTLY DELETE this item?") == true) {
		if (confirm("This deletion is final and may break associations with other data elements. Do you wish to proceed?") == true) {
			return (true);
		} else {
			return (false);
		}
	} else {
		return (false);
	}
}

function checkLength(areaObject,maxLength) {
	if (areaObject.value.length > maxLength) {
		areaObject.value=areaObject.value.substr(0,maxLength);
		alert('Please do not enter more than ' + maxLength.toString() + ' characters!');
	}
}


var maxLength = 4000;
//var counter = document.getElementById("counter");
//var toAlert = true;

function isAlphaNumericKey(keyCode)
{
	if ((keyCode > 47 && keyCode < 58) || (keyCode > 64 && keyCode < 91))
	{
		return true;
	}
		return false;
}

function RADLimitCharacters(editor)
{
	editor.AttachEventHandler ("RADEVENT_KEYDOWN", function (e)
	{					
		e = (e == null )? window.event : e;
		if (isAlphaNumericKey(e.keyCode))
		{													
			textLength = editor.GetText().length;
			//counter.innerHTML = textLength;						
			if (textLength >= maxLength)
			{
				alert('Please do not enter more than ' + maxLength.toString() + ' characters! You must delete some text before you continue.');
				e.returnValue = false;						
			}
			
			// make the menu link bold and red if there is a value entered
			
			RADboldtext();
			
		}
	});
}


function RADLimitCharactersPS(editor)
{
	editor.AttachEventHandler ("RADEVENT_KEYDOWN", function (e)
	{					
		e = (e == null )? window.event : e;						
		if (isAlphaNumericKey(e.keyCode))
		{													
			textLength = editor.GetText().length;					
			if (textLength >= maxLength) {
				alert('Please do not enter more than ' + maxLength.toString() + ' characters! You must delete some text before you continue.');
				e.returnValue = false;						
			}
		}
	});
}


function RADboldtext() {

	// this function bolds all appropriate menu links associated with rad editors

	if (mission_t.GetText().length > 2 || document.forms[1].upl_project_mission.value != "") {
		document.getElementById("sp_project_mission").style.fontWeight = "bold";
		document.getElementById("sp_project_mission").style.color = "#ae3334";
	} else {
		document.getElementById("sp_project_mission").style.fontWeight = "normal";
		document.getElementById("sp_project_mission").style.color = "#000000";
	}
	
	if (scope_t.GetText().length > 2 || document.forms[1].upl_project_scope.value != "") {
		document.getElementById("sp_project_scope").style.fontWeight = "bold";
		document.getElementById("sp_project_scope").style.color = "#ae3334";
	} else {
		document.getElementById("sp_project_scope").style.fontWeight = "normal";
		document.getElementById("sp_project_scope").style.color = "#000000";
	}
	
	if (scope_outside_t.GetText().length > 2 || document.forms[1].upl_project_scope_outside.value != "") {
		document.getElementById("sp_project_scope_outside").style.fontWeight = "bold";
		document.getElementById("sp_project_scope_outside").style.color = "#ae3334";
	} else {
		document.getElementById("sp_project_scope_outside").style.fontWeight = "normal";
		document.getElementById("sp_project_scope_outside").style.color = "#000000";
	}

	if (goals_t.GetText().length > 2 || document.forms[1].upl_project_goals.value != "") {
		document.getElementById("sp_project_goals").style.fontWeight = "bold";
		document.getElementById("sp_project_goals").style.color = "#ae3334";
	} else {
		document.getElementById("sp_project_goals").style.fontWeight = "normal";
		document.getElementById("sp_project_goals").style.color = "#000000";
	}
	
	if (assumptions_t.GetText().length > 2 || document.forms[1].upl_project_assumptions.value != "") {
		document.getElementById("sp_project_assumptions").style.fontWeight = "bold";
		document.getElementById("sp_project_assumptions").style.color = "#ae3334";
	} else {
		document.getElementById("sp_project_assumptions").style.fontWeight = "normal";
		document.getElementById("sp_project_assumptions").style.color = "#000000";
	}

}


function TEXTboldtext() {

	// this function bolds all appropriate menu links associated with textboxes
	
	if (document.forms[1].txt_project_charter_link.value != "" || document.forms[1].txt_project_post_review_link.value != "" || document.forms[1].txt_project_uri_1.value != "" || document.forms[1].txt_project_uri_2.value != "" || document.forms[1].txt_project_uri_3.value != "" || document.forms[1].txt_project_uri_4.value != "" || document.forms[1].txt_project_uri_5.value != "" || document.forms[1].txt_project_uri_6.value != "" || document.forms[1].txt_project_uri_7.value != "" || document.forms[1].txt_project_uri_8.value != "" || document.forms[1].txt_project_uri_9.value != "" || document.forms[1].txt_project_uri_10.value != "") {
		document.getElementById("sp_project_links").style.fontWeight = "bold";
		document.getElementById("sp_project_links").style.color = "#ae3334";
	} else {
		document.getElementById("sp_project_links").style.fontWeight = "normal";
		document.getElementById("sp_project_links").style.color = "#000000";
	}
	
	
	/*
	if (document.forms[1].txt_project_start_date.value != "" || document.forms[1].txt_project_completion_date.value != "" || document.forms[1].txt_project_end_date.value != "") {
		document.getElementById("sp_project_dates").style.fontWeight = "bold";
		document.getElementById("sp_project_dates").style.color = "#ae3334";
	} else {
		document.getElementById("sp_project_dates").style.fontWeight = "normal";
		document.getElementById("sp_project_dates").style.color = "#000000";
	}
	*/
	
	
	if (document.forms[1].budget_t.value != "" || document.forms[1].background_t.value != "" || document.forms[1].issues_t.value != "" || document.forms[1].comm_plan_t.value != "" || document.forms[1].cm_plan_t.value != "" || document.forms[1].other_plan_t.value != "" || document.forms[1].comments_t.value != "" || document.forms[1].timeline_t.value != "" || document.forms[1].txt_project_start_date.value != "" || document.forms[1].txt_project_completion_date.value != "" || document.forms[1].txt_project_end_date.value != "" || document.forms[1].upl_project_budget.value != "" || document.forms[1].upl_project_background.value != "" || document.forms[1].upl_project_issues.value != "" || document.forms[1].upl_project_comm_plan.value != "" || document.forms[1].upl_project_cm_plan.value != "" || document.forms[1].upl_project_other_plan.value != "" || document.forms[1].upl_project_comments.value != "" || document.forms[1].upl_project_timeline.value != "") {
		document.getElementById("sp_project_additional").style.fontWeight = "bold";
		document.getElementById("sp_project_additional").style.color = "#ae3334";
	} else {
		document.getElementById("sp_project_additional").style.fontWeight = "normal";
		document.getElementById("sp_project_additional").style.color = "#000000";
	}
	
	
	
}



function window_new_person(tblname,from) {
	window.open("AdminPersonAdd.aspx?tblname=" + tblname + "&from=" + from,"PSST","location=no,toolbar=no,status=yes,titlebar=no,menubar=no,width=700,height=250,scrollbars=yes");
}


function window_udds(fieldname) {
	window.open("../Report/AdminUDDSLookUp.aspx?fieldname=" + fieldname,"PSST","location=no,toolbar=no,status=yes,titlebar=no,menubar=no,width=750,height=250,scrollbars=yes");
}


function window_linked_projects(tblname) {
	window.open("AdminProjectLookUp.aspx?tblname=" + tblname,"PSST","location=no,toolbar=no,status=yes,titlebar=no,menubar=no,width=600,height=250,scrollbars=yes");
}


function ViewDashboard(psid) {
	window.open("../Report/ViewProjectStatusDash.aspx?ps_id=" + psid,"PSST","location=no,toolbar=no,status=yes,titlebar=no,menubar=no,width=420,height=180,scrollbars=no");
}


function ShowHideTop(div_name) {

	var div_top = document.getElementById(div_name);
	var image = document.images[div_name + "_img"];
	var image2 = document.images[div_name + "_hidden"];
	
	if (div_top.style.display=="none") {
		div_top.style.display="block";
		image.src="../Images/hide_trans.gif";
		image2.src="../Images/trans_spacer.gif";
	} else if (div_top.style.display=="block" || div_top.style.display=="") {
		div_top.style.display="none";
		image.src="../Images/show_trans.gif";
		image2.src="../Images/show_trans.gif";
	}

}



function ShowHidePS(div_name,theimage) {

	var div_top = document.getElementById(div_name + "_top");
	var div_sub = document.getElementById(div_name + "_sub");
	var image = document.images[div_name + "_img"];
	
	if (div_sub.style.display=="none") {
		div_sub.style.display="block";
		image.src="../Images/hide_trans.gif";
		var editor = eval("rad_" + div_name.replace("project_ps_",""));
		editor.SetVisible(true);
		var iframe = document.getElementById("RadEContentIframe" + "rad_" + div_name.replace("project_ps_",""));			
		iframe.style.height = "400px";
	} else if (div_sub.style.display=="block") {
		div_sub.style.display="none";
		image.src="../Images/show_trans.gif";
	}

}



function ShowHide(div_name,theimage) {

	var div_top = document.getElementById(div_name + "_top");
	var div_sub = document.getElementById(div_name + "_sub");
	var image = document.images[div_name + "_img"];
	
	if (div_sub.style.display=="none") {

		div_sub.style.display="block";
		if (theimage == "1" || theimage == "3") {
			image.src="../Images/hide.gif";
		} else if (theimage == "2") {
			image.src="../Images/hide_sub.gif";
		}

		if (div_name != "project_additional" && div_name != "project_links" && div_name != "project_team" && div_name != "project_dates" && div_name != "project_customer" && div_name != "project_cbs" && div_name != "project_budget" && div_name != "project_background" && div_name != "project_issues" && div_name != "project_comm_plan" && div_name != "project_cm_plan" && div_name != "project_other_plan" && div_name != "project_comments" && div_name != "project_timeline" && div_name != "project_person" && theimage != "3") {
			var editor = eval(div_name.replace("project_","") + "_t");
			editor.SetVisible(true);
			var iframe = document.getElementById("RadEContentIframe" + div_name.replace("project_","") + "_t");			
			iframe.style.height = "400px";
		}
	
	} else if (div_sub.style.display=="block") {

		div_sub.style.display="none";
		if (theimage == "1" || theimage == "3") {
			image.src="../Images/show.gif";
		} else if (theimage == "2") {
			image.src="../Images/show_sub.gif";
		}
	
	}

}



function ShowHideAll(div_name,rb) {

	//var div_top = document.getElementById(div_name + "_top");
	//var div_sub = document.getElementById(div_name + "_sub");
	//var image = document.images[div_name + "_img"];
	var div_top;
	var div_sub;
	var image;
	var div_top2;
	var div_sub2;
	var image2;
	//var ck = cb.checked;
	
	//var alldivs = document.getElementsByTagName("div");
	
	//for (i=0; i<alldivs.length; i++) {
	//	alldivs[i].style.display = "none";
	//}
	

	theRadioSet = eval('document.forms[1].rb_project_menu');
	i = 0;
	while(theRadioSet[i]) {
		
		if (theRadioSet[i].checked) {
			
			div_top = document.getElementById(theRadioSet[i].value + "_top");
			div_sub = document.getElementById(theRadioSet[i].value + "_sub");
			image = document.images[theRadioSet[i].value + "_img"];
			
			if (div_top) {
				div_top.style.display = "block";
				div_sub.style.display = "block";
				if (div_name != "project_additional") {
					image.src="../Images/hide.gif";
				}
				if (div_name != "project_additional" && div_name != "project_links" && div_name != "project_team" && div_name != "project_dates" && div_name != "project_customer" && div_name != "project_cbs" && div_name != "project_budget" && div_name != "project_background" && div_name != "project_issues" && div_name != "project_comm_plan" && div_name != "project_cm_plan" && div_name != "project_other_plan" && div_name != "project_comments" && div_name != "project_timeline" && div_name != "project_person") {
					var editor = eval(theRadioSet[i].value.replace("project_","") + "_t");
					editor.SetVisible(true);
					var iframe = document.getElementById("RadEContentIframe" + theRadioSet[i].value.replace("project_","") + "_t");		
					iframe.style.height = "400px";
				}
			}
		
		} else {
			
			// set all other divs to be hidden
			
			div_top2 = document.getElementById(theRadioSet[i].value + "_top");
			div_sub2 = document.getElementById(theRadioSet[i].value + "_sub");
			image2 = document.images[theRadioSet[i].value + "_img"];
			
			if (div_top2) {
				div_top2.style.display = "none";
				div_sub2.style.display = "none";
				if (theRadioSet[i].value != "project_additional") {
					image2.src="../Images/show.gif";
				}
			}
			
		}
		i++;
	}
}


function team_edit_change(thing) {

	// alert("name: " + thing.name + " value: " + thing.value + " checked: " + thing.checked);
	
	// this function sets the team changed hidden field to equal one if a new tool is added to an old team
	
	var x = parseInt(eval(thing.name.replace("_tool_id","")));
	
	if (thing.checked == true) {
		eval("document.forms[1].team_change_" + x).value = "1";
	}
	
}




function project_uri_addrow() {

	for (i = 1; i <= 10; i++) {
	
		var row = document.getElementById("tr_project_uri_" + i);
		
		if (row.style.display == "none") {
			row.style.display = "";
			if (i == 10) {
				document.getElementById("span_project_uri_addrow").style.display = "none";
			}
			break;
		}	
	}
}




function search_addrow() {

	for (i = 1; i <= 10; i++) {
	
		var row = document.getElementById("tr_search" + i);
		
		if (row.style.display == "none") {
			row.style.display = "";
			search_btn_display(i,'add');
			break;
		}	
	}
}



function search_delrow() {

	for (i = 1; i <= 10; i++) {
	
		var row = document.getElementById("tr_search" + i);
		
		if (row.style.display == "none") {
			document.getElementById("tr_search" + parseInt(i-1)).style.display = "none";
			search_btn_display(i,'del');
			eval("document.forms[1].search_field" + parseInt(i-1)).selectedIndex = 0;
			eval("document.forms[1].search_type" + parseInt(i-1)).selectedIndex = 0;
			eval("document.forms[1].search_text" + parseInt(i-1)).value = "";
			break;
		} else if (i == 10) {
			row.style.display = "none";
			//search_btn_display(i,'del');
			document.getElementById("span_search_addrow").style.display = "";
			eval("document.forms[1].search_field" + i).selectedIndex = 0;
			eval("document.forms[1].search_type" + i).selectedIndex = 0;
			eval("document.forms[1].search_text" + i).value = "";
			break;
		}
		
	}
}


function search_btn_display(item,action) {

	//alert(item);
		
	if (item == 10 && action == "add") {
		document.getElementById("span_search_addrow").style.display = "none";
	} else {
		document.getElementById("span_search_addrow").style.display = "";
	}
		
	if ((item <= 1 && action == "add") || (item <= 3 && action == "del")) {
		document.getElementById("span_search_delrow").style.display = "none";
	} else {
		document.getElementById("span_search_delrow").style.display = "";
	}

}


//****************
//XML HTTP functions
//****************

var req;
var fromsource;
var spansource;

function loadXMLDoc(url,from,spanid) {
    // branch for native XMLHttpRequest object
    
    document.getElementById(spanid).innerHTML = "Searching...";
    
    fromsource = from;
    spansource = spanid;
    
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}


function processReqChange() {
    if (req.readyState == 4) {
        if (req.status == 200) {
			if (fromsource == "cbs" || fromsource == "customer" || fromsource == "session") {
				document.getElementById(spansource).innerHTML = req.responseText;
				//alert(req.responseText);
			}
        } else {
            alert("There was a problem retrieving the XML data:\n" + req.statusText);
        }
    }
}