/**
 * 1. Checks 'Other' checkbox if user focuses on 'Other' input field
 * 2. Focus on 'Other' input field if user checks 'Other' checkbox
 */
function toggle_talent_other_cb(inputObj, inputObj_event, inputObj_value, inputObj_name) {
	//alert(inputObj.type);
	// get all elements with input tag
	var inputTags = document.getElementsByTagName('input');
	// count all elements with input tag
	var inputTagsLen = inputTags.length;
	// iterate through input tag elements
	for( var i = 0; i < inputTagsLen; i++ ) {
		// check the input tag if its value and name matches the passed parameters' inputObj_value and inputObj_name respectively. In case of checkbox toggle input tag id = inputObj_value
		if( (inputTags[i].value == inputObj_value && inputTags[i].name == inputObj_name) || (inputTags[i].id == inputObj_value && inputTags[i].name == inputObj_name) ) {
			switch( inputObj_event ) {
				// checks if input field value had something in it, if not uncheck the 'Other' checkbox
				// **blur event doesn't work well with checkbox click event. commented out to prevent checkbox uncheckable when input field is empty.
				case 'blur':  (inputObj.value.length > 0) ? inputTags[i].checked = true : inputTags[i].checked = false; break;
				// checks the input tag that matched the criteria on focus event
				case 'focus': inputTags[i].checked = true; break;
				// focuses on the input field if checked, erases the value and unfocuses the input field if unchecked.
				case 'click': 	if(inputObj.checked == true ){
										inputTags[i].focus();
								} 
								else {
									inputTags[i].value = '';
									inputTags[i].blur();
								}; break;
			}
		}
	}
} // END OF toggle_talent_other_cb FUNCTION


//Validate if Value is an Email
function validate_email(email) 
{
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email) == false) 
   {return false;}
   return true;
}

// Validate if Value is a number
function validate_is_number(n) {return !isNaN(parseFloat(n)) && isFinite(n);}

//Validate if String is_long enough
function validate_length(string,min_length)
{
	if(string.length>=min_length)
	{return true;}
	return false;
}
//validate if string is between these two numbers, inclusive
function validate_length_range(string,min_length,max_length)
{
	if(string.length>=min_length && string.length<=max_length)
	{return true;}
	return false;
}

//Validates if a string is empty or not
function validate_is_not_empty(string)
{
	check=string.split(" ").join("");
	if(check.length==0){return false;}
	return true;
}

//Check if string contains a numerical digit
function validate_has_digit(string)
{return /\d/.test(string);}

//Checks if string contains at least 1 number and one character
function validate_has_digit_and_alpha(string)
{return /\d[ \t\r\n!@#$%\^&*()\[\]`~"':;,\.\/\\\?><_]*\s*[a-z_]|[a-z_]\s*[ \t\r\n!@#$%\^&*()\[\]~`"':;,\.\/\\\?><_]*\s*\d/i.test(string);}
