function hello(){
	window.alert("hello");
}

function setFieldVal(theVal,theFld){
	fldList = theFld.split("~");
	valList = theVal.split("~");
	for(i=0; i<fldList.length; i++){
		//alert(i+": "+fldList[i]+" = "+valList[i]);
		document.getElementById(fldList[i]).value = valList[i];
	}
}

function setSelectVal(theObject,theOp,theStyle,theSet){
	//alert("\""+theObject+"\" - \""+theOp+"\"");
	mySelect = document.getElementById(theObject);
	//mySelect = document.pageform.theObject;
	//alert(mySelect);
	//alert(mySelect.name);
	//alert(mySelect.options[theOp].text);
	//alert(mySelect.options[theOp].value);
	styleList = theStyle.split("~");
	setList = theSet.split("~");
	for(i=0; i<styleList.length; i++){
		myAct = styleList[i];
		mySet = setList[i];	
		//alert(myAct+" - "+mySet+" = "+(myAct == "disabled" && mySet == "true"));
		if(myAct == "disabled" && mySet == "true"){
			mySelect.disabled=true;
		}
		if(myAct == "disabled" && mySet == "false"){
			mySelect.disabled=false;
		}
		if(myAct == "value"){
			mySelect.options[theOp].value=mySet;
		}
		if(myAct == "selected"){
			//mySelect.options[theOp].selectedIndex=(Number(mySet));
			mySelect.options[theOp].selected=true;
		}
	}
}

function setTotal(theFld,theState,theAmt){
	if(theState == false){
		document.getElementById(theFld).value = (Number(document.getElementById(theFld).value) + Number(theAmt)).toFixed(2);
	}else{
		document.getElementById(theFld).value = (Number(document.getElementById(theFld).value) - Number(theAmt)).toFixed(2);
	}
}

function fieldsMul(multiple,totalField,fieldList){
	//get total of fields
	//alert(totalField);
	fieldList = fieldList.split(',');
	//alert(fieldList.length);
	fieldTotal = 0;
	for(fl=0; fl<fieldList.length; fl++){
		//alert(document.getElementById(fieldList[fl]).value);
		fieldTotal = Number(fieldTotal)+Number(document.getElementById(fieldList[fl]).value);
		//document.getElementById(totalField).value = Number(fieldTotal) * Number(multiple);
	}
	document.getElementById(totalField).value = Number(fieldTotal) * Number(multiple);
}
function fieldsAdd(totalField,fieldList){
	//get total of fields
	//alert(totalField);
	fieldList = fieldList.split(',');
	//alert(fieldList.length);
	fieldTotal = 0;
	for(fl=0; fl<fieldList.length; fl++){
		//alert(document.getElementById(fieldList[fl]).value);
		fieldTotal = Number(fieldTotal)+Number(document.getElementById(fieldList[fl]).value);
		//document.getElementById(totalField).value = Number(fieldTotal) * Number(multiple);
	}
	document.getElementById(totalField).value = Number(fieldTotal);
}

function plusTimeNum(thisField,theIncrement,theMin,theLimit){
	if(Number(thisField.value) == theLimit){
		thisField.value = checkNum(theMin);
	}else{
		//alert(thisField.value);
		if(thisField.value == ''){
			thisField.value = checkNum(Number(theMin));
		}else{
			thisField.value = checkNum(Number(thisField.value) + theIncrement);
		}
	}
	
}
function minusTimeNum(thisField,theIncrement,theMin,theLimit){
	if(Number(thisField.value) == theMin){
		thisField.value = checkNum(theLimit);
	}else{
		if(thisField.value == ''){
			thisField.value = checkNum(Number(theMin));
		}else{
			thisField.value = checkNum(Number(thisField.value) - theIncrement);
		}
	}
}

function checkNum(theNum){
	//alert(theNum);
	if (theNum < "10"){
		theVal = theNum.toString();
		//alert("0"+theVal);
		return "0"+theVal;
	}else{
		return theNum;
	}
}



function addDetail(sourceHtml,snippitHtml){
	//alert(sourceHtml+","+snippitHtml);
	myTitles = "";
	myDetails = "";
	myState = 0;
	for(x=1; myState <= 0; x++){
		thisTitle = "title_" + x;
		thisDetail = "detail_" + x;
		//alert(thisTitle + " - " + thisDetail);
		//alert("field = " + document.pageform.elements[thisTitle] + " -- \"" + document.pageform.elements[thisTitle].value + "\"");
		//alert("field = " + document.pageform.elements[thisTitle]);
		//alert("field = " + (document.pageform.elements[thisTitle] != undefined));
		if(document.pageform.elements[thisTitle] != undefined){
			//alert("field values = \"" + document.pageform.elements[thisTitle].value + " - " + document.pageform.elements[thisDetail].value + "\"");
			myTitles += "|" + stripRestrictedChar(document.pageform.elements[thisTitle].value,"\|","/");
			myDetails += "|" + stripRestrictedChar(document.pageform.elements[thisDetail].value,"\|","/");
			//alert("field arrays = " + myTitles + " - " + myDetails);
		}else {
			myState = 1;
			x--;
		}
	}
	//alert("x = " + x);
	thisSnip = document.getElementById(snippitHtml).innerHTML;
	//alert(thisSnip);
	replacementHtml = "";
	thisTitleArray = myTitles.split('|');
	thisDetailArray = myDetails.split('|');
	//alert(thisTitleArray[1] + " - " + thisDetailArray[1] + " - " + thisTitleArray.length);
	for(y=1; y <=x; y++){
		//alert(thisTitleArray[y] + " - " + thisDetailArray[y]);
		thisTitle = "title_" + y;
		thisDetail = "detail_" + y;
		newSnip = thisSnip.replace(/\[t\]/g,thisTitle);
		nextSnip = newSnip.replace(/\[d\]/g,thisDetail);
		newSnip = nextSnip.replace(/\[num\]/g,y);
		//alert(thisTitle + " - " + (thisTitleArray[y] != undefined) + " - " + (thisDetailArray[y] != undefined));
		if(thisTitleArray[y] != undefined){
			nextSnip = newSnip.replace(/Your_Title_Here/g,thisTitleArray[y]);
		}else{
			nextSnip = newSnip.replace(/Your_Title_Here/g,'');
		}
		if(thisDetailArray[y] != undefined){
			newSnip = nextSnip.replace(/Your_Text_Here/g,thisDetailArray[y]);
		}else{
			newSnip = nextSnip.replace(/Your_Text_Here/g,'');
		}
		replacementHtml += newSnip + "\n";
	}
	document.getElementById(sourceHtml).innerHTML = "";
	document.getElementById(sourceHtml).innerHTML = replacementHtml;
}
function removeDetail(sourceHtml,snippitHtml,removeHtml){
	myTitles = "";
	myDetails = "";
	myState = 0;
	for(x=1; myState <= 0; x++){
		thisTitle = "title_" + x;
		thisDetail = "detail_" + x;
		if(document.pageform.elements[thisTitle] != undefined){
			if(document.pageform.elements[thisTitle].name != removeHtml){
				myTitles += "|" + stripRestrictedChar(document.pageform.elements[thisTitle].value,"\|","/");
				myDetails += "|" + stripRestrictedChar(document.pageform.elements[thisDetail].value,"\|","/");
			}
		}else{
			myState = 1;
			x--;
			//alert("myState = " +myState);
		}
	}
	//alert(myTitles + " - " + myDetails);
	thisSnip = document.getElementById(snippitHtml).innerHTML;
	//build replacement html
	replacementHtml = "";
	thisTitleArray = myTitles.split('|');
	thisDetailArray = myDetails.split('|');
	//alert(thisTitleArray + " - " + thisDetailArray + " - " + thisTitleArray.length);
	for(y=1; y <thisTitleArray.length; y++){
		thisTitle = "title_" + y;
		thisDetail = "detail_" + y;
		newSnip = thisSnip.replace(/\[t\]/g,thisTitle);
		nextSnip = newSnip.replace(/\[d\]/g,thisDetail);
		newSnip = nextSnip.replace(/\[num\]/g,y);
		if(thisTitleArray[y] != undefined){
			nextSnip = newSnip.replace(/Your_Title_Here/g,thisTitleArray[y]);
		}else{
			nextSnip = newSnip.replace(/Your_Title_Here/g,'');
		}
		if(thisDetailArray[y] != undefined){
			newSnip = nextSnip.replace(/Your_Text_Here/g,thisDetailArray[y]);
		}else{
			newSnip = nextSnip.replace(/Your_Text_Here/g,'');
		}
		replacementHtml += newSnip + "\n";
	}
	//alert(replacementHtml);
	document.getElementById(sourceHtml).innerHTML = "";
	document.getElementById(sourceHtml).innerHTML = replacementHtml;
}

 
function popAvalue(listObj,fieldObj){
	for(ri = 0; ri <= listObj.options.length; ri++){
		if(listObj.options[ri].selected){
			listData = listObj.options[ri].text;
			if	(listData != "select here"){
				re = "/[" + listData + "]/";
				if(fieldObj.value.match(listData)){
					//
				}else{
					if(fieldObj.value == ""){
						fieldObj.value = listData;
					}else{
						holdField = fieldObj.value;
						fieldObj.value = "";
						fieldObj.value = holdField + "," + listData;
					}
				}
			}
		}
	}
}

function pullAvalue(fieldObj){
	nameList = document.getElementById(fieldObj).value.split(",");
	if(nameList.length > 1){
		nameAlert = "Which value do you want to delete?\n\n";
		for(i=0; i<nameList.length; i++){
			nameAlert += i + ") " + nameList[i] + "\n";
		}
		nameAlert += "\n\n\n";
		thePrompt = prompt(nameAlert);
		if(Number(thePrompt) != "NaN" && thePrompt < nameList.length ){
			if(thePrompt == "0"){
				nameList.shift();
				document.getElementById(fieldObj).value = nameList.join(",");
			}else if(thePrompt == (nameList.length - 1)){
				nameList.pop();
				document.getElementById(fieldObj).value = nameList.join(",");
			}else{
				start = nameList.slice(0,Number(thePrompt));
				end = nameList.slice(Number(thePrompt));
				end.shift();
				start.push(end);
				document.getElementById(fieldObj).value = start.join(",");
			}
		}else{
			alert("You must enter a number only.");
		}
	}else{
		alert("You must have at least one value.");
	}
}


function addSubMenuGroup(fieldObj){
	//document.forms['testform'].testselect.options[i] = new Option('new text','new value')
	newMenu = "";

	newGroup = confirm("Create new submenue group. \n\nThink of a document group " + 
						"as a multi-page document that is displaid one page at a time. The parent is the first document in the" + 
						" group and is listed in one of the left hand menus. By starting a new group you are also " + 
						"starting a new menu or menu link.\n\nDo you want to continue?\n\nIf you are not sure select cancel" + 
						" from this window and then select none in the pop-down-menu. You can always add the group" + 
						" at another time.\n\n\n");
	
	
	if(newGroup){
		promptTest = true;
		while(promptTest){
			//start prompt for selection of a menu
			nameAlert = "Enter the number for the main menu this parent will be part of, or enter the name for a new menu. Choose cancel to stop this process.\n\n";
			//alert(fieldObj.options.length);
			//find the menus
			menuArray = "";
			for(fo = 0; fo<=fieldObj.options.length; fo++){
				//alert(fieldObj.options[fo]);
				if (fieldObj.options[fo] != null && fieldObj.options[fo] != undefined && fieldObj.options[fo] != ""){
					//get just the menus
					thisMenuArray = fieldObj.options[fo].value.split(",");
					if(thisMenuArray.length == 3){
						thisMenu = thisMenuArray[1];
					}else{
						thisMenu = thisMenuArray[0];
					}
					if(menuArray.match(thisMenu)){
					}else{
						if(thisMenu != "" &&  thisMenu != null &&  thisMenu != undefined &&  thisMenu != "none"){
								menuArray += thisMenu + ",";
						}	
					}
				}
			}
			//finish prompt message
			menuList = menuArray.split("\,");
			newMenuList = new Array();
			theCnt = 0;
			for(ml=0; ml<=menuList.length; ml++){
				if( menuList[ml] != "" &&  menuList[ml] != null &&  menuList[ml] != undefined &&  menuList[ml] != "none"){
					newMenuList[theCnt] = menuList[ml];
					theCnt ++;
					nameAlert += theCnt + ") \"" + menuList[ml] + "\"\n";
				}
			}
			nameAlert += "\n\n\n";
			newGroup = prompt(nameAlert);
			
			confirmTest = "";
			passValue = "";
			if (newGroup == null || newGroup == "" || newGroup == undefined){
				alert("Ok, I'll cancel the request.");
				promptTest = false;
			}else{
				if(newGroup < newMenuList.length){
					newGroup --;
					confirmTest = prompt("Your new menu group will be part of the \n\n\"" + newMenuList[newGroup] + "\" menu. \n\nEnter:\n1) for yes and\n2) for no\n\n\n", passValue); 
					if(confirmTest == 1){
						newMenu = newMenuList[newGroup];
						promptTest = false;
					}
				}else if(newGroup.match("[a-z]+")){
					passValue = newGroup;
					confirmTest = prompt("Your new menu group is:\n\n\"" + newGroup + "\"\n\nEnter:\n1) for yes\n2) for no\n\n\n"); 
					if(confirmTest == 1){
						newMenu = newGroup;
						promptTest = false;
					}
				}else{
						alert("I could not complete your entry... you may try again.");
						promptTest = false;
			
				}
			}
		}
	}else{
		alert("Ok, I'll cancel the request.");
	}
	
	//alert("\""+newMenu+"\"");
	if(newMenu != ""){
		promptTest = true;
		passValue = "";
		while(promptTest){
			newMenuName = prompt("Enter a menu listing for this group. Remember this is the menu item people will choose to get to your document group. \n(letters and numbers only)\n\n", passValue);
			if (newMenuName == null || newGroup == "" || newGroup == undefined){
				alert("Ok, I'll cancel the request.");
				promptTest = false;
			}else{
			
				if(newMenuName.match("[^A-Za-z0-9\s ]")){
					passValue = newMenuName;
					alert("letters and numbers only.");
				}else{
					passValue = newMenuName;
					confirmTest = prompt("Your new menu listing is:\n\n\"" + newMenuName + "\" \n\nEnter:\n1) for yes\n2) for no\n\n\n"); 
						if(confirmTest == 1){
							fieldObj.options[fieldObj.options.length] = new Option(newMenu+","+newMenuName,"new,"+newMenu+","+newMenuName,true,true);
							fieldObj.options[fieldObj.options.length].selected;
							promptTest = false;
						}
				}
			}
		}	
	}
}

function stripRestrictedChar(theString,removeString,replaceString){
	return theString.replace(removeString,replaceString);
}