<!--
// These Functions should be assigned
// to the onFocus() and onBlur() methods,
// respectively. GH_Highlight() creates
// a red border around the selected object,
// and GH_Obscure returns the object to
// its original state, as defined by the 
// style class .textbox (located in 
// "/include/sitestyle.css"

function GH_Highlight(objName) {
	objName.style.borderColor = "#FF0000";
	objName.style.borderStyle = "solid";
	objName.style.borderWidth = "4px";
}

function GH_Obscure(objName) {
	objName.style.borderColor = "#000000";
	objName.style.borderStyle = "solid";
	objName.style.borderWidth = "1px";
}

function GH_addToFavorites(planid) {
	strURL = "/admin/addtofavorites.php?planid=" + planid;
	MM_openBrWindow(strURL, 'wndAddFav', 'width=150,height=95');
}

function handleError() {
	return true;
}

function GH_updatePos() {
	document.all["gallPos"].innerHTML = intLocation + 1;
	document.all["gallMax"].innerHTML = arrImages.length;
	/*
		document.gallPos.innerHTML = intLocation + 1;
		document.gallMax.innerHTML = arrImages.length;
	*/
}

function GH_loadImg(intPos) {
	intLocation = intPos;
	document.imgDynamic.src = "/images/clearbox.gif";
	document.imgDynamic.src = arrImages[intPos];
	// GH_updatePos();
}

function GH_loadImgSingle(intPos) {
	document.imgDynamicSingle.src = "/images/clearbox.gif";
	document.imgDynamicSingle.src = arrImagesSingle[intPos];
}

// Function GH_getNext()
// Action: loads next image in display

function GH_getNext() {
	// Looks at global intLocation to determine
	// position in array
	if (document.images) {
		if ((intLocation + 1) < arrImages.length) { 
			intLocation++;
		} else {
			intLocation = 0;
		}
		
		document.imgDynamic.src = arrImages[intLocation];
		// GH_updateMarquee(arrDescription[intLocation]);
		
		GH_updatePos();
	}
}

function GH_getPrevious() {
	// Looks at global intLocation to determine
	// position in array
	if (document.images) { 		
		if ((intLocation) > 0) {
			intLocation--;
		} else {
			intLocation = arrImages.length - 1;
		}	
	
		document.imgDynamic.src = arrImages[intLocation];
		// GH_updateMarquee(arrDescription[intLocation]);
		
		GH_updatePos();
	}
}	

function GH_openFlashMovieWindow(width, height, strMovieName) {
	strParameters = "width=" + width + ", height=" + height + ", top=" + ((screen.height - height) / 2) + ", left=" + ((screen.width - width)/2);
	var targetURL = "/images/flash/popup_Flash.php?strMovieName=" + strMovieName;
	MM_openBrWindow(targetURL,'popup',strParameters);
}


function GH_selectAllUsers(frmName, strBaseName, intNumElements, objCheckBox) {
	if (objCheckBox.checked == true) {
		var value = true;
	} else {
		var value = false;
	}
	
	var blnNULL = false;
	var i = 1;
	
	while (!blnNULL) {
		objElement = eval("document." + frmName + "." + strBaseName + i);
		if (objElement.checked == null) {
			$blnNULL = true;
		} else {
			objElement.checked = value;
		}
		
		i++;
	}
	
	/*
		for (i = 1; i <= intNumElements; i++) {
			objElement = eval("document." + frmName + "." + strBaseName + i);
			objElement.checked = value;
		}
	*/		
}

// A Function to give focus to the passed
// object

function GH_GiveFocus(frmName, objName) {
//	objForm = eval("document." + frmName);
	objElement = eval("document." + frmName + "." + objName);
	objElement.focus();
}

// GH modified to auto-center the popup window

function MM_openBrWindow(theURL,winName,features) { //v2.0
	var startpos, endpos, intWidth, intHeight, top, left, length;
	
	// Get Width
	startpos = features.indexOf("width=") + 6;
	endpos = startpos;
	
	while ((features.charCodeAt(endpos) >= 48) && (features.charCodeAt(endpos) <= 57)) {
		endpos++;
	}

	intWidth = features.substring(startpos, endpos);

	// Get Height
	startpos = features.indexOf("height=") + 7;
	endpos = startpos;
	
	while ((features.charCodeAt(endpos) >= 48) && (features.charCodeAt(endpos) <= 57)) {
		endpos++;
	}
	
	intHeight = features.substring(startpos, endpos);
	
	// Now determine top and left positions (centering) based on height and width
	top = (screen.height - intHeight) / 2;
	left = (screen.width - intWidth) / 2;
	
	features += ", top=" + top + ", left=" + left;
	
  window.open(theURL,winName,features);
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

// Retrieves Parent URL,
// refreshes it and closes the current window
function GH_RefreshOpener(page) {

		// Refresh Opener
		var newURL = page;
		opener.location.href = newURL;
		
		// Close Current Window
		window.close();	
}

function GH_CheckPass(field1, field2, frmName) {
	// Get Values of Objects and compare
	objElement1 = eval("document." + frmName + "." + field1);
	objElement2 = eval("document." + frmName + "." + field2);
	
	objVal1 = objElement1.value;
	objVal2 = objElement2.value;
	
	if (objVal1 == objVal2) {
		objForm = eval("document." + frmName);
		objForm.submit();
	} else { 
		alert("Password Fields Don't Match");
		GH_GiveFocus(frmName, field1);
	} 
}

function GH_setText(frmName, frmField, strText) {
	objTarget = eval("document." + frmName + "." + frmField);
	
	objTarget.value = strText;
}

/* 	
	Function: Formats the following fields:
	social; dob; state; email; 
	
	If lnLglGuard == "yes", then requires that
	grdFname && grdLname != ""
	
	Action: If everything's fine, submits the form,
	otherwise, displays popup with details
*/
 
 function GH_ValidateAddUser(frmName) {
	var blnError, strError, strSocial, strDOB, strState, strEmail;
	var strBlnLglGuard, strGrdFname, strGrdLname;
	var intSelected, intValue;
	
	blnError = 0;
	strError = "";
	
	// get form object
	objForm = eval("document." + frmName);
	
	// Determine User Type and Proceed
	intSelected = objForm.userlevel.selectedIndex;
	intValue = objForm.userlevel[intSelected].value;
	
	switch (parseInt(intValue)) {
		case 5 :	// Client User
		
			
			
			// get needed values
				strSocial = new String(objForm.social.value);
				strDOB = new String(objForm.dob.value);
				strState = new String(objForm.state.value);
				strEmail = new String(objForm.email.value);
				strGrdFname = new String(objForm.grdFname.value);
				strGrdLname = new String(objForm.grdLname.value);
				
				
				// Format Social
					// 	first, remove all non-numeric characters
					var	strSocialTemp = new String();
					strSocialTemp = "";
					// alert("strSocial.length: " + strSocial.length);
					for (i = 0; i < strSocial.length; i++) {
						if ((strSocial.charCodeAt(i) <= 57) && (strSocial.charCodeAt(i) >= 48)) {
							// alert("strSocial.charCodeAt(" + i + "): " + strSocial.charCodeAt(i));
							strSocialTemp += strSocial.substr(i,1);
							// alert("strSocialTemp: " + strSocialTemp);
						}
					}
					
					// now Check length
					if (strSocialTemp.length != 9) {
						strError = strError + "Social Security Number not formatted properly: xxx-xx-xxxx\n";
						blnError = 1;
					} else {
						// length ok, now format it and assign it to the form field
						objForm.social.value = strSocialTemp.substr(0,3) + "-" + strSocialTemp.substr(3,2) + "-" + strSocialTemp.substr(5,4);
					}
					
					
				// Format DOB
					// 	first, remove all non-numeric characters
					var	strDOBTemp = new String();
					strDOBTemp = "";
					for (i = 0; i < strDOB.length; i++) {
						if ((strDOB.charCodeAt(i) <= 57) && (strDOB.charCodeAt(i) >= 48)) {
							strDOBTemp += strDOB.substr(i,1);
						}
					}
					
					// now Check length
					if (strDOBTemp.length != 8) {
						strError = strError + "DOB not formatted properly: xx/xx/xxxx\n";
						blnError = 1;
					} else {
						// length ok, now format it and assign it to the form field
						objForm.dob.value = strDOBTemp.substr(0,2) + "/" + strDOBTemp.substr(2,2) + "/" + strDOBTemp.substr(4,4);
					}
					
				// Format State
					if (strState.length != 2) {
						strError = strError + "You must enter a two-character state code.\n";
						blnError = 1;
					} else {
						objForm.state.value = strState.toUpperCase();
					}
				
				// Check Legal Guardian Status
			
					if (objForm.blnLglGuard[0].checked) {
						// First name and last name can't be null
						if ((strGrdFname.length == 0) || (strGrdLname.length == 0)) {
							strError = strError + "Legal Guardian first name and last name must be completed.\n";
							blnError = 1;
						}
					}		
					
			 	
				// Check length on all of these fields to make sure they're not blank
				var arrFields = new Array("Fname", "Lname", "address", "city", "state", "zip");
										  // "phone1", "phone2", "phone3");
										  
				for (i = 0; i < arrFields.length; i++) {
					objField = eval("document." + frmName + "." + arrFields[i]);
					strField = new String(objField.value);
					if (strField.length == 0) {
						strError = strError + arrFields[i] + " cannot be left blank.\n";
						blnError = 1;
					}
				}
			
				// Make sure one of two radio buttons is checked in the following fields
				var arrFields = new Array("gender", "blnSMI", "blnActive");
				for (i = 0; i < arrFields.length; i++) {
					objField = eval("document." + frmName + "." + arrFields[i]);
					if (!objField[0].checked && !objField[1].checked) {
						strError = strError + arrFields[i] + ": must select either 'yes' or 'no'.\n";
						blnError = 1;
					}
				}
				
			break;		
				
		
		case 4 :	// FMH User, email required
		
			// Check length on all of these fields to make sure they're not blank
			var arrFields = new Array("Fname", "Lname", "username", "password", "email");
									  
			for (i = 0; i < arrFields.length; i++) {
				objField = eval("document." + frmName + "." + arrFields[i]);
				strField = new String(objField.value);
				if (strField.length == 0) {
					strError = strError + arrFields[i] + " cannot be left blank.\n";
					blnError = 1;
				}
			}		
		
			break;
			
		default :	// All Other Users

			// Check length on all of these fields to make sure they're not blank
			var arrFields = new Array("Fname", "Lname", "username", "password");
									  
			for (i = 0; i < arrFields.length; i++) {
				objField = eval("document." + frmName + "." + arrFields[i]);
				strField = new String(objField.value);
				if (strField.length == 0) {
					strError = strError + arrFields[i] + " cannot be left blank.\n";
					blnError = 1;
				}
			}		

			break;
	}
	
	
		
	// Check to see if error flag has been set and prompt or submit accordingly
	
		if (blnError == 1) {
			alert(strError);
		} else {
			objForm.submit();
		}
			
}

/* 
	Used on Form 1
*/

function GH_updateLayout() {

	// look at current usertype, then display or hide 
	// appropriate sections
	
	// retrieve selected index of iv_reviewtype
	var intSelected, intValue;
	blnShowVIII = '0';
	intSelected = document.form1.userlevel.selectedIndex;
	intValue = document.form1.userlevel[intSelected].value;
	
	switch (parseInt(intValue)) {
		// alert(blnSMI);
		case 5 :
			// Client Level User
			MM_showHideLayers('layerLogin', '', 'hide');
			MM_showHideLayers('layerAddInfo', '', 'show');
			break;

		default :
			// All other users
			MM_showHideLayers('layerLogin', '', 'show');
			MM_showHideLayers('layerAddInfo', '', 'hide');
			break;
			
	}	
}


function ActiveBG(srcElement, Type) {
	if (Type == 0)
	{
	   if(srcElement.bgColor == "#CCCCCC")
	  {
   	   srcElement.bgColor = "#999999";
	  }else{
   	   srcElement.bgColor = "#CCCCCC";
	  }
	}else{
	   if(srcElement.bgColor == "#CCCCCC")
	  {
   	   srcElement.bgColor = "#999999";
	  }else{
   	   srcElement.bgColor = "#CCCCCC";
	  }	
	}
}

// Dynamic creates Axis elements for display based on the form value
// document.form1.intNumAxis. The innerHTML property of dynAxisArea is replaced
function GH_dynAxis(strForm, strField, strLayer, intLabel) {

	// Retrieve Objects && Values
	
	objField = eval("document." + strForm + "." + strField);
	intCount = parseInt(objField.value);
	
	objLayer = eval(strLayer);
	
	var i, strInnerHTML;
	strInnerHTML = '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
	//	alert(document.form1.intNumAxis.value);
	for (i = 1; i <= intCount; i++) {
        strInnerHTML += '  <tr> ';
        strInnerHTML += '    <td width="8%">&nbsp;</td>';
        strInnerHTML += '    <td width="19%" align="left" valign="top">Code:</td>';
        strInnerHTML += '    <td width="70%" align="left" valign="top"> ';
        strInnerHTML += '      <input type="text" class="textbox" onFocus="GH_Highlight(this)" onBlur="GH_Obscure(this)" name="axis' + intLabel + '_code_' + i + '" value="">';
        strInnerHTML += '    </td>';
        strInnerHTML += '  </tr>';
        strInnerHTML += '  <tr> ';
        strInnerHTML += '    <td width="8%">&nbsp;</td>';
        strInnerHTML += '    <td width="19%" align="left" valign="top">Description:</td>';
        strInnerHTML += '    <td width="70%" align="left" valign="top"> ';
        strInnerHTML += '      <input type="text" class="textbox" onFocus="GH_Highlight(this)" onBlur="GH_Obscure(this)" name="axis' + intLabel + '_description_' + i + '" value="">';
        strInnerHTML += '    </td>';
        strInnerHTML += '  </tr>';
        strInnerHTML += '  <tr>';
        strInnerHTML += '    <td width="8%">&nbsp;</td>';
        strInnerHTML += '    <td width="19%" align="left" valign="top">&nbsp;</td>';
        strInnerHTML += '    <td width="70%" align="left" valign="top">&nbsp;</td>';
        strInnerHTML += '  </tr>';
	}
	strInnerHTML += '</table>';
	
	// Update Text
	objLayer.innerHTML = strInnerHTML;
}
// -->

