//jumps to selected URL 'onchange' pulldown
function pullDownToURL(url) {
	if (url.length == 0) {
		return false;
	}
	else {
		document.location.href = url;
	}
}

//displays Flash intro (uses Flash detection 'hasFlash()'-see 'sfir.js')
function embedFlashIntro() {
	if (window.hasFlash == false) {
		document.write("<img src=\"images/home_photo1.jpg\" alt=\"Image of elderly female patient being cared for by nurse practitioner\" width=\"284\" height=\"284\" />");
	} else {
		document.write("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" width=\"284\" height=\"284\" id=\"slideshow_as1\" align=\"middle\">");
		document.write("<param name=\"allowScriptAccess\" value=\"sameDomain\" />");
		document.write("<param name=\"movie\" value=\"slideshow_as1.swf\" />");				
		document.write("<param name=\"quality\" value=\"high\" />");				
		document.write("<param name=\"bgcolor\" value=\"#D5E2AF\" />");	
		document.write("<embed src=\"slideshow_as1.swf\" quality=\"high\" bgcolor=\"#D5E2AF\" width=\"284\" height=\"284\" name=\"slideshow_as1\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />");				
		document.write("</object>");	
	}
}



//from CNYGEC site
function MM_findObj(n, d) { //v4.01

  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 && d.getElementById) x=d.getElementById(n); return x;

}


//from CNYGEC site
function MM_validateForm() { //v4.0

  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;

  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);

    if (val) { nm=val.name; if ((val=val.value)!="") {

      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');

        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';

      } else if (test!='R') { num = parseFloat(val);

        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';

        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');

          min=test.substring(8,p); max=test.substring(p+1);

          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';

    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }

  } if (errors) alert('The following error(s) occurred:\n'+errors);

  document.MM_returnValue = (errors == '');

}

// TRIM FUNCTION FOR FORM VALIDATION
function trim(inputString) {
	if (typeof inputString != "string") { return inputString; }
	
	var retValue = inputString;
	var ch = retValue.substring(0, 1);
	
	while (ch == " ") { // Check for spaces at the beginning of the string
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}
	
	ch = retValue.substring(retValue.length-1, retValue.length);
	
	while (ch == " ") { // Check for spaces at the end of the string
		retValue = retValue.substring(0, retValue.length-1);
		ch = retValue.substring(retValue.length-1, retValue.length);
	}
	
	while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
		retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
	}
	
	return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

function isFilled(elm) {
	if (elm.value !="" || elm.value == null){
		return true;
	}
	else return false;
}

function isSelected(elm) {
	if (elm.selectedIndex != 0)
	return true;
	else return false;
}

function isEmail(elm) {
	if (elm.value.indexOf("@")!=-1 && elm.value.indexOf(".")!= "-1" && elm.value !="")
	return true;
	else return false;
}

function validateCheckboxes(checkboxes) {

	var isChecked = false;
	// var checkboxes = document.forms[0].foo;
	
	for(var i = 0; i< checkboxes.length; ++i)
	if(checkboxes[i].checked) isChecked = true;
	
	if(isChecked) { return true; }
	else { return false; }

}

function close_confirm() {
	if (confirm("Are you sure you want to close this window? \nYou will only lose any information added.")) {
		self.close();
	}
}

function close_confirm_custom(text_alert) {
	if (confirm(text_alert)) {
		self.close();
	}
}

function confirm_delete(url) {
	if (confirm("Are you sure you want to delete this item")) {
		document.location.href = url;
	}
}

// BEGIN: CONFIRM ACTION
function confirm_action(url,text_alert) {
	if (confirm(text_alert)) {
		document.location.href = url;
	}
}
// END: CONFIRM ACTION

function open_new_pop_up(url,width,height) {
	new_pop_up = window.open(url,"new_pop_up","width=" + width + ",height=" + height + ",menubar=no,status=yes,toolbar=no,scrollbars=yes,resizable=no,location=no,left=300,top=300");  
	new_pop_up.focus();
}

//JUMPS TO SELECTED POP-UP WINDOW 'ONCHANGE' PULLDOWN
function pullDownToPopUp(url) {
	if (url.length == 0) {
		return false;
	}
	else {
		open_new_pop_up(url,500,600);
	}
}

//LIMIT TEXTAREA FIELDS
function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}