/*******************************************************************************/
/*                           Miscellaneous Functions                           */
/*******************************************************************************/
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// This function checks to see if a selection was made in a checkbox group
function cbxSelectionMade(cbx){
	var isGood=false;
	if(cbx.checked){
		isGood=true;
	}
	for(i=0;i<cbx.length && !isGood;i++){
		if(cbx[i].checked){
			isGood=true;
		}
	}
	return isGood;
}

// This function checks to see if a selection was made in a dropdown box
function cboSelectionMade(cbo){
	var isGood=false;
	
	if(cbo.selectedIndex>0&&cbo.options[cbo.selectedIndex].value!="")
		isGood=true;
		
	return isGood;
}

// This function ensures the remove checkbox is unchecked if the keep box is checked
// on the newComments.cfm form
function keepIt(idx){
	var thisForm=document.fComment;
	if(thisForm.keep.checked){
		thisForm.remove.checked=false;
		return 0;
	}
	if(thisForm.keep[idx].checked)
		thisForm.remove[idx].checked=false;
}

// This function ensures the keep checkbox is unchecked if the remove box is checked
// on the newComments.cfm form
function dumpIt(idx){
	var thisForm=document.fComment;
	if(thisForm.remove.checked){
		thisForm.keep.checked=false;
		return 0;
	}
	if(thisForm.remove[idx].checked)
		thisForm.keep[idx].checked=false;
}

//call a calendar
var calendar;
function ShowCalendar(formname,boxname,boxdate){
	calendar=window.open('show_calendar.cfm?boxname='+boxname+'&boxdate='+boxdate+'&formname='+formname,'calendar','scrollbars=0,width=230,height=190, top=40,left=40');
} 

function changeImage(obj,ele,state){
	if(state==1){
	docuemnt.obj.getElementById(ele).src='images/edit_purple.gif';
	}
	else
	{
	docuemnt.getElementById(ele).src='images/edit_white.gif';
	}
}

//This function checks the size of a text filed.
function textareaMaxLength(obj,mlen) {

  var maxlen=mlen;
  if (obj.value.length>maxlen) {
    obj.value=obj.value.substring(0, maxlen)
    alert('You have reached your maximum length');
  }
  
}
// This function pops the color picker window
function popColorPicker(){
	window.open('colorpic.html','colorpic','width=300,height=220');
}

/*******************************************************************************/
/*                             Validation Functions                            */
/*******************************************************************************/

// This function is used to validate email entries
function isValidEmail(thisEmail){
	var emailexp = /.*\@.*\..*/;
	if (!emailexp.test(thisEmail)) {
		return false;
	} 
	return true;
}

// function checks a date value to make sure its valid
function isValidDate(aDate) {
	var dateexp = /^(\d{1,2}\/\d{1,2}\/\d{4})$/;
    if (!dateexp.test(aDate)) { return false; } 	
	var	temp = new String(aDate), m = 0, d = 0;
	
	for (i=0; i < temp.length; i++){ 
		var str = temp.charAt(i); 
		if (str == "/") { if (m == 0) { m = i; } else { d = i; break; }}			
	}
	
	var month = parseInt(temp.substring(0, m), 10);
	var day = parseInt(temp.substring(m + 1, d), 10); 
	var year = parseInt(temp.substring(d + 1, temp.length), 10);								
					
	switch (month) {
		case 1:	case 3:	case 5:	case 7:	case 8:	case 10: case 12:					
			if ((day < 1) || (day > 31)) {  return false;	} break;
		case 2:		
			if ((year % 400 == 0) || (year % 4 == 0)) {	if ((day < 1) || (day > 29)) {  return false;	} break}
			if ((day < 1) || (day > 28)) {  return false; } break;
		case 4:	case 6:	case 9: case 11:
			if ((day < 1) || (day > 30)) {	 return false; } break;
		default: return false;			
	}		
	return true;		
}

//This function is to validate users login
function validateLogin(thisForm){
	if(thisForm.username.value==""){
		alert("You must enter in you email.");	
		thisForm.username.focus();
		return false;
	}
	if(thisForm.password.value==""){
		alert("You must enter in your password");
		thisForm.password.focus();
		return false;
	}
	return true;
}

//This function is to validate users login
function validateRecover(thisForm){
	if(thisForm.retemail.value==""){
		alert("You must enter in your email.");	
		thisForm.retemail.focus();
		return false;
	}
	return true;
}

//This function is to validate team info update
function validateTeamInfo(thisForm){
	if(thisForm.teamName.value==""){
		alert("Please enter in your team name.");
		thisForm.teamName.focus();
		return false;
	}
	return true;
}
//This function is to validate team info update
function validateBlogCategory(thisForm){
	if(thisForm.blogCategoryName.value==""){
		alert("Please enter in a name for the blog category.");
		thisForm.blogCategoryName.focus();
		return false;
	}
	return true;
}
//This function is to validate team member
function validateMember(thisForm){
	if(thisForm.memberName.value==""){
		alert("Please enter in a name for the team member.");
		thisForm.memberName.focus();
		return false;
	}
	if(thisForm.memberEmail.value=="" || !isValidEmail(thisForm.memberEmail.value)){
		alert("Please enter in a valid email address for the team member.");
		thisForm.memberEmail.focus();
		return false;
	}
	
	
	return true;
}

//This function is to validate add blog
function validateBlog(thisForm){
	if(!cboSelectionMade(thisForm.blogCategory)){
		alert("You must select a blog category.");
		thisForm.blogCategory.focus();
		return false;
	}
	if(thisForm.blogTitle.value==""){
		alert("You must enter in a blog title.");
		thisForm.blogTitle.focus();
		return false;
	}
	return true;
}

//This function is to validate cal categories
function validateCalCat(thisForm){
	if(thisForm.calCatName.value==""){
		alert("You must enter in a category name.");
		thisForm.calCatName.focus();
		return false;
	}
	if(!cboSelectionMade(thisForm.calCatColor)){
		alert("You must select a color for this category.");
		thisForm.calCatColor.focus();
		return false;
	}
	return true;
}

//This function is to validate cal event
function validateEvent(thisForm){
	if(!cboSelectionMade(thisForm.eventColor)){
		alert("You must select a event category.");
		thisForm.eventColor.focus();
		return false;
	}
	if(thisForm.ceventDate.value==""){
		alert("You must enter in the event date.");
		thisForm.ceventDate.focus();
		return false;
	}
	if(thisForm.ceventHeadline.value==""){
		alert("You must enter in a headline for the event");
		thisForm.ceventHeadline.focus();
		return false;
	}
	return true;
}

//This function is to validate cal event
function validateMyProfile(thisForm){
	if(thisForm.fullName.value==""){
		alert("You must enter in your Full Name.");
		thisForm.fullName.focus();
		return false;
	}
	if(!cboSelectionMade(thisForm.position)){
		alert("You must enter in the Position.");
		thisForm.position.focus();
		return false;
	}
	if(!cboSelectionMade(thisForm.experience)){
		alert("You must enter in the Experience.");
		thisForm.experience.focus();
		return false;
	}
	if(thisForm.emgContact.value==""){
		alert("You must enter in the Emergency Contact.");
		thisForm.emgContact.focus();
		return false;
	}
	if(thisForm.emgPhone.value==""){
		alert("You must enter in the Emergency Phone.");
		thisForm.emgPhone.focus();
		return false;
	}
	return true;
}


