function openWin(url) {
  popUpWin = window.open(url,
                         'HelpWin',
                         'titlebar=0,toolbar=0,location=no,top=30,left=340,directories=0,status=0,'+
                         'menubar=no,scrollbars=0,resizable=no,'+
                         'Height=450,Width=420');
}

function openHelpWindow(url) {
  popUpWin = window.open(url,
                         'HelpWin',
                         'titlebar=0,toolbar=0,location=no,top=30,left=340,directories=0,status=0,'+
                         'menubar=no,scrollbars=1,resizable=no,'+
                         'Height=450,Width=700');
}

function openMapWindow(url) {
  popWin = window.open(url,
                         'ERWin',
                         'titlebar=0,toolbar=0,location=no,top=30,left=340,directories=0,status=0,'+
                         'menubar=no,scrollbars=0,resizable=no,'+
                         'Height=468,Width=600');
}

function BuildMailTo() {
	sFullPath = location.href;
	return "<A href='#' onClick=javascript:openWin('/tell-a-friend.asp?page="+sFullPath+"')>";
}

function IsNumeric(sText) {
   var ValidChars = "0123456789.-";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
 
function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}

function isValidDate(dateStr) {
// Date validation function courtesty of 
// Sandeep V. Tamhankar (stamhankar@hotmail.com) -->

// Checks for the following valid date formats:
// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY

var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2,4})$/; // requires 4 digit year

var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
alert("Date is not in a valid format.")
return false;
}
month = matchArray[1]; // parse date into variables
day = matchArray[3];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
alert("Month must be between 1 and 12.");
return false;
}
if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn't have 31 days!")
return false;
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
alert("February " + year + " doesn't have " + day + " days!");
return false;
   }
}
return true;
}   

function check(form) {
	if (form.firstName.value == "") 
	{
		alert("Please enter your first name.")
		form.firstName.focus();
		return;
	}
	
/*	if (form.mi.value == "") 
	{
		alert("Please enter your MI.")
		form.mi.focus();
		return;
	}*/
	
	if (form.lastName.value == "") 
	{
		alert("Please enter your last name.")
		form.lastName.focus();
		return;
	}
	
	if (form.occupation.value == "") {
		alert("Please enter your occupation.")
		form.occupation.focus();
		return;
	}
	
/*	if (form.IDbirthday.value == "") {
		alert("Please enter your birth day and month.")
		form.IDbirthday.focus();
		return;
	}	
	
	if (!IsNumeric(form.IDbirthday.value)) {
		alert("Please enter a valid birth day and month. Ex: 0821")
		form.IDbirthday.focus();
		return;
	}	

	if (form.IDssn.value == "") {
		alert("Please enter your SSN (last four digits).")
		form.IDssn.focus();
		return;
	}
	
	if (!IsNumeric(form.IDssn.value)) {
		alert("Please enter a valid SSN (last four digits).")
		form.IDssn.focus();
		return;
	}	

	var btni01 = valButton(form.gender);
	if (btni01 == null) {
		alert('Please select your gender.')
		return;	
	}
	
	if (form.race.value == "") {
		alert("Please select your race.")
		form.race.focus();
		return;
	}	

	if (form.dob.value == "") {
		alert("Please enter your date of birth.")
		form.dob.focus();
		return;
	}	
	
	if (!(isValidDate(form.dob.value))) {
		alert("Please enter a valid date.")
		thisForm.dob.focus();
		return;
	}		
	*/
	var stremail=form.email.value
	var emailchar=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (!emailchar.test(stremail)) {


	alert("Please enter a valid email address.");
	form.email.focus();
	return
	}	
	
	if (form.homePhone.value == "") {
		alert("Please enter your home telephone number.")
		form.homePhone.focus();
		return;
	}		
	
	if (!IsNumeric(form.homePhone.value)) {
		alert("Please enter a valid home telephone number.")
		form.homePhone.focus();
		return;
	}
	
	if (form.workPhone.value == "") {
		alert("Please enter your work telephone number.")
		form.workPhone.focus();
		return;
	}			
	
	if (!IsNumeric(form.workPhone.value)) {
		alert("Please enter a valid work telephone number.")
		form.workPhone.focus();
		return;
	}		

	if (form.homeAddress.value == "") {
		alert("Please enter your street address.")
		form.homeAddress.focus();
		return;
	}
	if (form.homeCity.value == "") {
		alert("Please enter your city.")
		form.homeCity.focus();
		return;
	}
	if (form.homeState.value == "") {
		alert("Please enter your state.")
		form.homeState.focus();
		return;
	}
	if (form.homeZip.value == "") {
		alert("Please enter your zip.")
		form.homeZip.focus();
		return;
	}
	if (!IsNumeric(form.homeZip.value)) {
		alert("Please enter a valid zip.")
		form.homeZip.focus();
		return;
	}		
	
/*	if (form.employer.value == "") 
	{
		alert("Please enter your employer.")
		form.employer.focus();
		return;
	}
	
	if (form.employerDept.value == "") 
	{
		alert("Please enter your department.")
		form.employerDept.focus();
		return;
	}
	
	if (form.licensure.value == "") 
	{
		alert("Please enter your licensure.")
		form.licensure.focus();
		return;
	}
	
	if (form.position.value == "") 
	{
		alert("Please enter your position.")
		form.position.focus();
		return;
	}
	
	if (form.profession.value == "") 
	{
		alert("Please enter your profession.")
		form.profession.focus();
		return;
	}
	
	if (form.employerCounty.value == "") 
	{
		alert("Please enter your employer county.")
		form.employerCounty.focus();
		return;
	}
	
	if (form.workAddress.value == "") {
		alert("Please enter your work street address.")
		form.workAddress.focus();
		return;
	}
	if (form.workCity.value == "") {
		alert("Please enter your work city.")
		form.workCity.focus();
		return;
	}
	if (form.workState.value == "") {
		alert("Please enter your work state.")
		form.workState.focus();
		return;
	}
	if (form.workZip.value == "") {
		alert("Please enter your work zip.")
		form.workZip.focus();
		return;
	}
	if (!IsNumeric(form.workZip.value)) {
		alert("Please enter a valid work zip.")
		form.workZip.focus();
		return;
	}		*/

	else
	{
		form.submit();
	}
}


function menu_goto( menuform )
{
    // see http://www.thesitewizard.com/archive/navigation.shtml
    // for an explanation of this script and how to use it on your
    // own site

    var baseurl = "http://www.carolinashospital.com/" ;
    selecteditem = menuform.newurl.selectedIndex ;
    newurl = menuform.newurl.options[ selecteditem ].value ;
    if (newurl.length != 0) {
      location.href = baseurl + newurl ;
    }
}
