function openUser(url) {
  var cdsWindow;
  if (!cdsWindow  || cdsWindow.closed) 
		cdsWindow = open(url, 'cdsfloater', 'left=50,top=0,height=375,width=450,menubar=no,scrollbars=yes,resizable=yes');
  else
		cdsWindow.focus();
}

function userfillin(uid, user_name, form_number) {
  if(self.opener.document.forms[form_number].uid) {
	self.opener.document.forms[form_number].uid.value = uid; 
  } else {
	alert("User object is missing in opener window.");
  }
  if(self.opener.document.forms[form_number].user_name) {
	self.opener.document.forms[form_number].user_name.value = user_name; 
  }
  wrapup();
}

function checkNotificationEmail() {

	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.notifyForm.email.value)) {
		
		return (true)
	
	} else {
		
		return (false)
		
	}
	
}

function checkForgotPassword() {
	
	missinginfo = "";
	if (document.forgot_password.email.value == "") {
		
		missinginfo += "\n     -  Email";
		
		} else {
		
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.forgot_password.email.value)) {
			
			} else {
			
				missinginfo += "\n     -  Invalid Email Address";
				missinginfo += "\n        (your_name@your_domain)";
				
			}
		
		}
	
	if (missinginfo != "") {
		missinginfo ="_____________________________\n" +
		"You failed to correctly fill in your:\n" +
		missinginfo + "\n_____________________________" +
		"\nPlease re-enter and submit again!";
		alert(missinginfo);
		return false;
	}
	else return true;
}


function checkNotfication() {
	missinginfo = "";
	if (document.notifyForm.first_name.value == "") {
		missinginfo += "\n     -  First Name";
		}
	if (document.notifyForm.last_name.value == "") {
		missinginfo += "\n     -  Last Name";
		}
	if (document.notifyForm.email.value == "") {
		
		missinginfo += "\n     -  Email";
		
		} else {
			
			if (checkNotificationEmail()) {
			
			} else {
			
				missinginfo += "\n     -  Invalid Email Address";
				missinginfo += "\n        (your_name@your_domain)";
				
			}
		
		}
	
	if (missinginfo != "") {
		missinginfo ="_____________________________\n" +
		"You failed to correctly fill in your:\n" +
		missinginfo + "\n_____________________________" +
		"\nPlease re-enter and submit again!";
		alert(missinginfo);
		return false;
	}
	else return true;
}

function openWindow(url) {

	popupWin = window.open (url, "", "width=375, height=350, left=10, top=10, scrollbars=yes, titlebar=no");

}

function openVideoWindow(url) {

	popupWin = window.open (url, "", "width=675, height=450, left=10, top=10, scrollbars=yes, titlebar=no");

}

function openReport(url) {

	popupWin = window.open (url, "", "width=500, height=600, left=10, top=10, scrollbars=yes, titlebar=no, resizable=yes");

}

function color_builder(COLOR_VALUE) {

	document.color_selector.color_value.value = COLOR_VALUE; 

}

function checkEmail() {

	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.register.email.value)) {
		
		return (true)
	
	} else {
		
		return (false)
		
	}
	
}

function checkLogin() {
	missinginfo = "";
	if (document.login.login.value == "") {
		
		missinginfo += "\n     -  Email";
		
		} else {
			
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.login.login.value)) {
			
			} else {
			
				missinginfo += "\n     -  Invalid Email Address";
				missinginfo += "\n        (your_name@your_domain)";
				
			}
		
		}
	if (document.login.password.value == "") {
		missinginfo += "\n     -  Password";
		}
	if (missinginfo != "") {
		missinginfo ="_____________________________\n" +
		"You failed to correctly fill in your:\n" +
		missinginfo + "\n_____________________________" +
		"\nPlease re-enter and submit again!";
		alert(missinginfo);
		return false;
	}
	else return true;
}

function checkRegister() {
	missinginfo = "";
	if (document.register.first_name.value == "") {
		missinginfo += "\n     -  First Name";
		}
	if (document.register.last_name.value == "") {
		missinginfo += "\n     -  Last Name";
		}
	if (document.register.email.value == "") {
		
		missinginfo += "\n     -  Email";
		
	} else {
		
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.register.email.value)) {
		
		} else {
		
			missinginfo += "\n     -  Invalid Email Address";
			missinginfo += "\n        (your_name@your_domain)";
			
		}
	
	}
	if (document.register.CDS_CODE.value == "") {
		missinginfo += "\n     -  County/School/District";
		}
	if (document.register.CDS_CODE.value == "00000000000000" && document.register.CDS_OTHER.value == "") {
		missinginfo += "\n     -  School/District Other";
		}
	if (document.register.password_01.value == "") {
		missinginfo += "\n     -  Password";
	}
	if (document.register.password_02.value == "") {
		missinginfo += "\n     -  Please Verify the Password you selected.";
	}
	if (document.register.password_01.value != document.register.password_02.value) {
		missinginfo += "\n     -  Passwords do not match.";
	}
	if (missinginfo != "") {
		missinginfo ="_____________________________\n" +
		"You failed to correctly fill in your:\n" +
		missinginfo + "\n_____________________________" +
		"\nPlease re-enter and submit again!";
		alert(missinginfo);
		return false;
	}
	else return true;
}

function checkPrivateRegister() {
	missinginfo = "";
	if (document.private_register.code.value == "") {
		missinginfo += "\n     -  Access Code";
		}
	if (missinginfo != "") {
		missinginfo ="_____________________________\n" +
		"You failed to correctly fill in your:\n" +
		missinginfo + "\n_____________________________" +
		"\nPlease re-enter and submit again!";
		alert(missinginfo);
		return false;
	}
	else return true;
}

function checkUserContact() {
	missinginfo = "";
	if (document.update_user_contact_information.email_primary.value == "") {
		
		missinginfo += "\n     -  Primary Email Address";
		
	} else {
			
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.update_user_contact_information.email_primary.value)) {
		
		} else {
		
			missinginfo += "\n     -  Invalid Primary Email Address";
			missinginfo += "\n        (your_name@your_domain)";
			
		}
		
	}

	if (missinginfo != "") {
		missinginfo ="_____________________________\n" +
		"You failed to correctly fill in your:\n" +
		missinginfo + "\n_____________________________" +
		"\nPlease re-enter and submit again!";
		alert(missinginfo);
		return false;
	}
	else return true;
}

function checkUserPassword() {

	missinginfo = "";
	if (document.user_password_reset.password_01.value == "") {
		missinginfo += "\n     -  Password";
	}
	if (document.user_password_reset.password_02.value == "") {
		missinginfo += "\n     -  Please Verify the Password you selected.";
	}
	if (document.user_password_reset.password_01.value != document.user_password_reset.password_02.value) {
		missinginfo += "\n     -  Passwords do not match.";
	}
	
	if (missinginfo != "") {
		missinginfo ="_____________________________\n" +
		"You failed to correctly fill in your:\n" +
		missinginfo + "\n_____________________________" +
		"\nPlease re-enter and submit again!";
		alert(missinginfo);
		return false;
	}
	else return true;
}

function checkUserShare() {

	missinginfo = "";
	if (document.user_sharing_add.uid.value == "") {
		missinginfo += "\n     -  Please Select a User";
	}
	
	if (missinginfo != "") {
		missinginfo ="_____________________________\n" +
		"You failed to correctly fill in your:\n" +
		missinginfo + "\n_____________________________" +
		"\nPlease re-enter and submit again!";
		alert(missinginfo);
		return false;
	}
	else return true;
}


function opencds(url) {
  var cdsWindow;
  if (!cdsWindow  || cdsWindow.closed) 
		cdsWindow = open(url, 'cdsfloater', 'left=50,top=0,height=375,width=450,menubar=no,scrollbars=yes,resizable=yes');
  else
		cdsWindow.focus();
}

function cds_fillin_address(CDS_CODE, school, address, city, st, zip, form_number) {

  if(self.opener.document.forms[form_number].CDS_CODE) {
	self.opener.document.forms[form_number].CDS_CODE.value = CDS_CODE; 
  } else {
	alert("CDS_CODE object is missing in opener window.");
  }
  if(self.opener.document.forms[form_number].CDS_NAME) {
	self.opener.document.forms[form_number].CDS_NAME.value = school; 
  }
  if(self.opener.document.forms[form_number].address_primary_01) {
	self.opener.document.forms[form_number].address_primary_01.value = address; 
  }
  if(self.opener.document.forms[form_number].city_primary) {
	self.opener.document.forms[form_number].city_primary.value = city; 
  }
  if(self.opener.document.forms[form_number].st_primary) {
	self.opener.document.forms[form_number].st_primary.value = st; 
  }
  if(self.opener.document.forms[form_number].zip_primary) {
	self.opener.document.forms[form_number].zip_primary.value = zip; 
  }
  wrapup();
  
}

function cds_fillin_register(CDS_CODE, school, form_number) {

  if(self.opener.document.forms[form_number].CDS_CODE) {
	self.opener.document.forms[form_number].CDS_CODE.value = CDS_CODE; 
  } else {
	alert("CDS_CODE object is missing in opener window.");
  }
  if(self.opener.document.forms[form_number].CDS_NAME) {
	self.opener.document.forms[form_number].CDS_NAME.value = school; 
  }
  wrapup();
  
}

function wrapup(){
  self.opener.focus();
  self.close();
}

function selectall(obj) { 
	var checkboxes = document.getElementsByTagName('input'); 
	for (i = 0; i < checkboxes.length; i++) { 
		if (obj.checked == true) { 
			checkboxes[i].checked = true; // this checks all the boxes 
		} else { 
			checkboxes[i].checked = false; // this unchecks all the boxes 
		}
	}
}

function getRandomNum(lbound, ubound) {

	return (Math.floor(Math.random() * (ubound - lbound)) + lbound);

}
	
function getRandomChar(number, lower, upper, other, extra) {

	var numberChars = "0123456789";
	var lowerChars = "abcdefghijklmnopqrstuvwxyz";
	var upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var otherChars = "`~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/? ";
	var charSet = extra;
	
	if (number == true)
	charSet += numberChars;
	if (lower == true)
	charSet += lowerChars;
	if (upper == true)
	charSet += upperChars;
	if (other == true)
	charSet += otherChars;
	
	return charSet.charAt(getRandomNum(0, charSet.length));
}

function getPassword(length, extraChars, firstNumber, firstLower, firstUpper, firstOther, latterNumber, latterLower, latterUpper, latterOther) {
	
	var rc = "";
	if (length > 0)
	
	rc = rc + getRandomChar(firstNumber, firstLower, firstUpper, firstOther, extraChars);
	
	for (var idx = 1; idx < length; ++idx) {
	
		rc = rc + getRandomChar(latterNumber, latterLower, latterUpper, latterOther, extraChars);
		
	}
	
	return rc;
	
}

function hide_msg_box() {
			
	document.getElementById("msg_box").innerHTML = '';

}
