// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  COMMON FUNCTIONS ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	
function EnableProgramType(val){
	var typeText = document.getElementById('txtProgrammingType');
	var typeInput = document.getElementById('Ptype');
	if(val){
		typeText.disabled = false;
		typeInput.disabled = false;
		typeInput.style.borderColor = "#000";
		typeInput.focus();
	}else{
		typeText.disabled = true;
		typeInput.innerText = "";
		typeInput.disabled = true;
		typeInput.style.borderColor = "#ccc";
	}
}


// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  MENU FUNCTIONS ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
function HighlightMe(id, val){
	var menuItem = 'menu_' + id;
	var item = document.getElementById(menuItem);
		if(val){
			item.className = menuItem + '_over';
		}else{
			item.className = menuItem;
		}
}
 
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  SAMPLE VIDEO/MESSAGE FUNCTIONS ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
function PlayVideo(){
	window.open('homeplayer.html','', 'width=486px, height=412px, toolbar=no, titlebar=no,  location=no, scrollbar=no, resizable=no, status=no, menubar=no');
}
function ViewCustMsg(MsgNumber){
	var title = 'customTitle=';
	var message = 'customMessage=';
	var img = 'customImage=http%3A//www.everwelltv.com/images/';
	var url = 'http://www.everwelltv.com/fla/'; 
	var attr = 'width=400, height=227';
	switch(MsgNumber){
		case 1:
			title += 'Eau%20Gallie%20Internal%20Medicine';
			message += 'Join%20us%20in%20welcoming%20Jane%20Sanborn,%20MD%20to%20EGIM.%20';
			message += 'Dr.%20Sanborn%20is%20board-certified%20in%20family%20medicine,%20fellowship-trained%20in%20sports%20medicine,'
			message += '%20and%20has%20considerable%20experience.';
			url += 'CustomMessageTemplate.swf' + '?' + title + '&' + message + '&';
			window.open(url , '', attr);
			break;
		case 2:
			title += 'Bakersfield%20Family%20Medicine';
			message += 'Welcome%20to%20our%20practice.';
			message += '%20We%60re%20open%20Mon.-Fri.,%208am-5pm.%20Bakersfield%20provides%20evening%20and%20weekend%20services%20at%20';
			message += 'our%20urgent%20care%20center%20at%20123%20Main%20Street.';
			img += 'cm_sample01.jpg';
			url += 'CustomMessageTemplate.swf' + '?' + title + '&' + message + '&' + img + '&';
			window.open(url , '', attr);
			break;
		case 3:
			title += 'Chatsworth%20Internal%20Medicine';
			message += '%20Did%20you%20know%20that%20Chatsworth%20Internal%20Medicine%20has%20an%20Internet%20site%20for%20prescription%20refills,%20appointments%20and%20referrals?';
			message += '%20Ask%20the%20receptionist%20for%20a%20brochure,%20which%20includes%20the%20Web%20address.';
			url += 'CustomMessageNoImage.swf' + '?' + title + '&' + message + '&';
			window.open(url , '', attr);
			break;
		case 4:
			title += 'Magnolia%20Medical';
			message += 'From%20DEXA%20precision%20body-fat%20analysis%20to%20customized%20dietary%20programs%20and%20prescription%20';
			message += 'weight%20loss%20medication,%20we%20can%20help%20you%20shed%20unwanted%20pounds.%20';
			message += 'Ask%20your%20provider%20for%20details%20today.';
			img += 'cm_sample02.jpg';
			url += 'CustomMessageWithImage.swf' + '?' + title + '&' + message + '&' + img + '&';
			window.open(url , '', attr);
			break;
		default:
			break;
	}

}

// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  VALIDATION FUNCTIONS ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
function ValidateCUForm(){
	if(ValidEntry('txt_name', 1)){
		if(ValidEmail('txt_email')){
			document.contact.action = "php/contact_form.php";
			document.contact.submit();
		}else{
			DisplayError('email address');
		}
	}else{
		DisplayError('name');
	}
}

function ValidEmail(txtbox){
	var at="@"
	var dot="."
	var txt = document.getElementById(txtbox);
	var str = txt.value;
	var lat = str.indexOf(at);
	var ldot = str.indexOf(dot);
	
	// Check for valid length in entry field
	if (str.length <=0) { txt.className = "invalid"; txt.focus(); return false; }
	// Check for @ symbol
	if (str.indexOf(at)==-1 || str.indexOf(at)==0){ txt.className = "invalid"; txt.focus(); return false; }
	//Check for . symbol
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0){ txt.className = "invalid"; txt.focus(); return false; }
	//Check for valid .com/.org/etc
	if (str.indexOf(at,(lat+1))!=-1){ txt.className = "invalid"; txt.focus(); return false }
		/*
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){ return false }
		 if (str.indexOf(dot,(lat+2))==-1){ return false }
		 if (str.indexOf(" ")!=-1){ return false }
		 */
	txt.className = "valid"; 
 	return true;			
}

function ValidateKey(id, val){
	var txtbox = document.getElementById(id);
	var val = txtbox.value;
	var key = val.substring(val.length-1, val.length);
	var invalidKeys = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+?/<.>:;'";
	//alert('val=' + val + 'indexOf=' + invalidKeys.indexOf(key));
	if(invalidKeys.indexOf(key) >= 0){
		//alert(txtbox.innerText.subStr(0, txtbox.length-1));
		document.getElementById(id).value = val.substring(0, val.length-1);
	}
}

function ValidEntry(txtBoxId, minLen){
	var txt = document.getElementById(txtBoxId);
		if(minLen > 0){
			if(txt.value.length < minLen){
				txt.className = "invalid";
				txt.focus();
			}else{
				txt.className = "valid";
				return true;
			}
		}else{
			if(txt.value.length <= 0){
				txt.className = "invalid";
				txt.focus();
			}else{
				txt.className = "valid";
				return true;
			}
		}
	return false;
}

function ValidateApplication(){
	// Check required fields for data entry
	if(ValidEntry('Cname', 0)){
		if(ValidEntry('Pname', 0)){
			if(ValidEntry('Pphone', 14)){
				if(ValidEmail('Pemail')){
					document.signup.action = "php/form.php";
					document.signup.submit();
				}else{
					DisplayError('email address');
				}
			}else{
				DisplayError('phone number');
			}
		}else{
			DisplayError('practice name');
		}
	}else{
		DisplayError('contact name');
	}
}

function ValidatePlus(){
	// Check required fields for data entry
	if(ValidEntry('Cname', 0)){
		if(ValidEntry('Pname', 0)){
			if(ValidEntry('Pphone', 14)){
				if(ValidEmail('Pemail')){
					document.signup.action = "php/form_plus.php";
					document.signup.submit();
				}else{
					DisplayError('email address');
				}
			}else{
				DisplayError('phone number');
			}
		}else{
			DisplayError('practice name');
		}
	}else{
		DisplayError('contact name');
	}
}



// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  ERROR HANDLING   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
function DisplayError(type){
	var msg= 'Invalid ' + type + '!\r\n\r\n';
		msg+= 'A valid ' + type + ' is required before attempting\r\n';
		msg+= 'to submit the online application';
		alert(msg);
}

