// ---- ShowHideDivs ------------------------------------------------------------ SRM
// Function: change visibility of x number of DIVS passed in CSV
// This actually closes the div and returns used real estate
// Usage: 
//      flag = "none" or "off" to hide, "block" or "on" to show
//      divs = the name or names of divs to perform action.  CSV for multiple
function showhidedivs(flag,divs) {
	if (flag=="off") {
		flag="none";
	}
	if (flag=="on") {
		flag="block";
	}
	
	if (divs.indexOf(",") != -1) {
		arrValues=divs.split(",");
		for(t=0;t<arrValues.length;t++) {
			eval("document.all." + arrValues[t] + ".style.display='" + flag + "'");
		}
	} else {
		eval("document.all." + divs + ".style.display='" + flag + "'");
	}
}
// ---- End ShowHideDivs --------------------------------------------------------

// ---- Toggle Disabled ----------------------------------------------------------- SRM
// Function: change the disabled attribute of one or more form fields
// Usage: 
//      flag = "false" or "on" to enable, "true" or "off" to show
//      formname = what form the fields reside in
//      fields = form field or fields to perform action on.  CSV for multiple
// Note: Uses standard ITG CSS values 'forms' and 'formsDisabled'
//       to toggle the visual state of the field.  If you do not have this CSS
//       this function WILL throw an error.
function toggleDisabled(flag,formname,fields) {
	if (flag=="off") {
		flag="false";
		flagclass="forms";
	}
	if (flag=="on") {
		flag="true";
		flagclass="formsDisabled";		
	}
	
	if (fields.indexOf(",") != -1) {
		arrValues=fields.split(",");
		for(t=0;t<arrValues.length;t++) {
			eval("document." + formname + "." + arrValues[t] + ".disabled=" + flag + "");
			eval("document." + formname + "." + arrValues[t] + ".className='" + flagclass + "'");
		}
	} else {
		eval("document." + formname + "." + fields + ".disabled=" + flag + "");
		eval("document." + formname + "." + fields + ".className='" + flagclass + "'");		
	}
}
// ---- End Toggle Fields -------------------------------------------------------

// ---- Toggle Required --------------------------------------------------------- SRM
// Function: toggle fields required or not required and changes the required *
// to on or off as required based on ITG tool standards
// Usage:
//      flag = required "on" or "off" 
//      spans = span or spans holding the * character to show on or off. This works by making the * the color of the
//              background within the span.  You can put whatever you want in the span.
//            Note: You may leave this blank and it will not attempt to
//                  change any spans. CSV for multiple
//            Sample: <span id=spnFirstName name=spnFirstName>*</span>
//                  then you would pass spnFirstName as the span name to toggle
//      formname = the name of the form that contains the fields; 
//            NOTE: leave blank if there are no fields
//      fields = form field or fields to mark as required or not required
//            Note: You may leave this blank and it will not attempt to
//                  change any fields
function toggleRequired(flag,formname,spans,fields) {
	if (formname != "") {
		if (flag=="off") {
			flagfield="formsDisabled";
		}
		if (flag=="on") {
			flagfield="formsRequired";
		}
	}
	if (flagfield !="") {
		if (fields.indexOf(",") != -1) {
			// break the divs passed into an array
			arrValues=fields.split(",");
			for(t=0;t<arrValues.length;t++) {
				eval("document." + formname + "." + arrValues[t] + ".className='" + flagfield + "'");
			}
		} else {
			eval("document." + formname + "." + fields + ".className='" + flagfield + "'");
		}
	}
	if (spans != "") {
		if (spans.indexOf(",") != -1) {
			// break the divs passed into an array
			arrValues=spans.split(",");
			for(t=0;t<arrValues.length;t++) {
				eval("document.all." + arrValues[t] + ".className='required" + flag + "'");
			}
		} else {
			eval("document.all." + spans + ".className='required" + flag + "'");
		}	
	}	

}
// ---- End Toggle Required -----------------------------------------------------

// ---- Get Index Value --------------------------------------------------------- SRM
// Function: returns the VALUE of the selected list box
// Usage:
//      formname = the form's name that contains the dropdown
//      field = the drop down form field
function getIndexValue(formname,field) {
	return eval("document." + formname + "." + field + ".options[document." + formname + "." + field + ".selectedIndex].value");
}
// ---- End Get Index Value -----------------------------------------------------

// ---- Put Index Value --------------------------------------------------------- SRM
// Function: Populates a LISTBOX with the desired value
// Usage:
//      formname = the form's name that contains the dropdown
//      field = the drop down form field
//		setvalue = the VALUE of the item in the list box - THIS IS NOT THE TEXT
//
//		Example:
//		HTML CODE:
//		 <option value="1">Financial Services</option>
//		 <option value="2">Admin Services</option>
//		 <option value="test">This is just a test</option>

// 		 If you wanted to populate this drop down with ...
//		 Financial Services .... setvalue='2' ...
//		 Admin Services .... setvalue='3' ...
//		 This is just a test ... setvalue='text' ...

function putIndexValue(formname,field,setvalue) {
	eval("document." + formname + "." + field + ".value='" + setvalue +"';");
}
// ---- End Put Index Value -----------------------------------------------------

// ---- Put Index Value --------------------------------------------------------- SRM
// Function: Populates a LISTBOX with the desired value
// Usage:
//      formname = the form's name that contains the dropdown
//      field = the drop down form field
//		setvalue = the VALUE of the item in the list box - THIS IS NOT THE TEXT
//
//		Example:
//		HTML CODE:
//		 <option value="1">Financial Services</option>
//		 <option value="2">Admin Services</option>
//		 <option value="test">This is just a test</option>

// 		 If you wanted to populate this drop down with ...
//		 Financial Services .... setvalue='2' ...
//		 Admin Services .... setvalue='3' ...
//		 This is just a test ... setvalue='text' ...

function putIndexValue(formname,field,setvalue) {
	eval("document." + formname + "." + field + ".value='" + setvalue +"';");
}
// ---- End Put Index Value -----------------------------------------------------

// ---- Validate Fields --------------------------------------------------------- SRM
// Function: checks to ensure all passed fields have SOMETHING in the field; returns true if all pass.
//         Note: There is no FIELD TYPE validation.  If there is anything in there, it passes the check
//               If you need specifics, use DW's ValidateForm behavior or couple this with your own code.
// Usage:
//      formname = the form's name that contains the dropdown
//      fields = the field or fields (CSV) to validate
function validateFields(formname,fields) {
	strTemp=true;
	if (fields.indexOf(",") != -1) {
		arrValues=fields.split(",");
		for(t=0;t<arrValues.length;t++) {
			strTempEval=eval("document." + formname + "." + arrValues[t] + ".value");
			if (strTempEval == "") {
				strTemp=false;
			}
		}
	} else {
		strTempEval=eval("document." + formname + "." + fields + ".value");
		if(strTempEval== "") {
			strTemp=false;
		}
	}
	return strTemp;
}
// ---- End Validate Fields -----------------------------------------------------

// ---- Validate A Field --------------------------------------------------------- SRM
// Function: Validate a SINGLE field against several possible types as well as
//           comparing against a not-equal value (think list box or radio box)
// Usage: 
//      type="email", "number" (integer), "alpha" (letters), "alphanum" (no symbols), "float" (floating num)
//      , "single" (one letter or number), "listbox" (if you're checking a listbox)
//      notequal = a value that the listbox cannot be equal to to pass validation (i.e. 0)
//                 Leave blank if not a listbox validation
//      formname = the form the field is in
//      field = name of field
function validateAField(type,notequal,formname,field) {

	strTemp=true;
	if(type=="listbox") {
		if(getIndexValue(formname,field) != notequal) {
			return true;
		} else {
			return false;
		}
	} else {
		strTempEval=eval("document." + formname + "." + field + ".value");
	  switch (type)
	  {
		case "email": { 
			strMatch=strTempEval.match(/^.+\@.+\..+$/);
		break;
		}
		case "number": { 
			strMatch=strTempEval.match(/^\d+$/);	
		break;
		}
		case "alpha": { 
			sstrMatch=strTempEval.match(/^[a-zA-Z]+$/);								
		break;
		}
		case "alphanum": { 
			strMatch=strTempEval.match(/^[a-zA-Z0-9]+$/);								
		break;
		}
		case "float": { 
			strMatch=strTempEval.match(/^((\d+(\.\d*)?)|((\d*\.)?\d+))$/);								
		break;
		}
		case "single": { 
			strMatch=strTempEval.match(/^([a-zA-Z]|\d)$/);								
		break;
		}	
	  }	
		return strMatch;
	}

}
// ---- End Validate A Field  ---------------------------------------------------

// ---- Center Window --------------------------------------------------------- SRM
// Function: Center the current window on any browser screen
// Usage: Call function
function centerWindow() {
//	intWinWidth=document.documentElement.clientWidth;
	intWinWidth=document.body.clientWidth;
	intWinHeight=document.body.clientHeight;
	intWidth=screen.width;
	intHeight=screen.height;
	window.moveTo((intWidth/2)-(intWinWidth/2),(intHeight/2)-(intWinHeight/2));
}
// ---- End Center Window -----------------------------------------------------

// ---- Centered PopUp Window --------------------------------------------------------- SRM

// Function: Opens a new window automatically positioned in the center of the screen
//           based on the browser size.
// Usage: 
//      url=URL to the page to open in the window
//      windowname = a valid window name (no spaces or special characters)
//      resize = No, Yes (optional)
//      scrollbars = No, Yes, Auto (optional)
//		width = window width
//		height = window height
//		misc = any misc parameter not covered (optional)
function centerPopup(url,windowname,width,height,scrollbars,resize,misc) {
	xoffset=(screen.width/2)-(width/2);
	yoffset=(screen.height/2)-(height/2);
	strParameters="";
		if (resize != "") {
			strParameters = strParameters + "resizable=" + resize + ",";
		}

		if (scrollbars != "") {
			strParameters = strParameters + "scrollbars=" + scrollbars + ",";
			xoffset=xoffset-7;
			yoffset=yoffset-7;
		}
		
		if (misc != "") {
			strParameters = strParameters + misc + ",";
		}
		
	strParameters=strParameters + "width=" + width + ", height=" + height + ",";
	


	strParameters=strParameters + "left=" + xoffset + ", top=" + yoffset;
	//strParameters=strParameters+"'";
	window.open(url,windowname,strParameters);
}
// ---- End Center PopUp -----------------------------------------------------

// ---- PopupHelp --------------------------------------------------------- SRM

// Function: Opens a new help window centered on the screen
// Usage: 
//      helpid=ID of the help row in the database to display
function popupHelp(helpid) {
	centerPopup("helptopic.asp?id=" + helpid,"HelpTopic",500,300,"yes","yes","");
}
// ---- End Center PopUp -----------------------------------------------------

// ---- CopytoClipboard -------------------------------------------------- SRM

// Function: copies passed text to clipboard
// Usage: 
//      formname=form name the field sits in
//		field= form field to copy to clipboard
//		responsetext= text to post in an alertbox after the copy takes place - leave blank for no response
// Note: This ONLY works on IE.
function copyToClipboard(formname,field,responsetext) {
copied=eval("document." + formname + "." + field + ".createTextRange()");
copied.execCommand("Copy");
	if (responsetext != "") {
		alert(responsetext);
	}
}