/*******************************************************************************/
/*                           Miscellaneous Functions                           */
/*******************************************************************************/

// 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.options[cbo.selectedIndex].value!="")
		isGood=true;
		
	return isGood;
}

//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');
} 

// 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;		
}


function numbersOnly(e){
	var unicode=e.charCode? e.charCode : e.keyCode;
	if (unicode!=8&& unicode!=9){ //if the key isn't the backspace or tab key (which we should allow) 
		if (unicode<48||unicode>57){ //if not a number return false
			//e.preventDefault( );
			return false;
		}
	}
	return true; 
}

function postalFormat(e,txt){
	var len=txt.value.length;
	var unicode=e.charCode? e.charCode : e.keyCode;
	if (unicode!=8&& unicode!=9){ //if the key isn't the backspace or tab key (which we should allow) 
		if(len%2>0){ //need a number
			if (unicode<48||unicode>57){ //if not a number return false
				return false;
			}
		}
		else{ // need a letter
			if (unicode<65||(unicode>90&&unicode<97)||unicode>122){ //if not a number return false
				return false;
			}
		}
	}
	return true; 
}

/*******************************************************************************/
/*                             Validation Functions                            */
/*******************************************************************************/
// This function validates calendar entry submissions
function validateCareer(thisForm){
	if(thisForm.careerName.value==""){
		alert("You must provide a title for this career!");
		thisForm.careerName.focus()
		return false;
	}
	if(thisForm.careerShow.value==""){
		alert("You must provide a show date for this career!");
		return false;
	}
	if(thisForm.careerDescription.value==""){
		alert("You must provide a description for this career!");
		return false;
	}
	
	return true;
}