var popUp; 

function OpenCalendar(idname, postBack)
{
	popUp = window.open('Calendar.aspx?formname=' + document.forms[0].name + 
		'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value + '&postBack=' + postBack, 
		'popupcal', 
		'width=165,height=250,left=200,top=250');
}

function SetDate(formName, id, newDate, postBack)
{
	eval('var theform = document.' + formName + ';');
	popUp.close();
	theform.elements[id].value = newDate;
	if (postBack)
		__doPostBack(id,'');
}		

function isCorrectEmail(email) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){
		return (true);
	}
	return (false);
}

function validateUSPhone( strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains valid
  US phone pattern.
  Ex. (999) 999-9999 or (999)999-9999

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.
*************************************************/
  //var objRegExp  = /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/;
   //var objRegExp  = /^[1-9]\d{3}\-\d{3}\-\d{4}$/;
   var objRegExp = /^((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}$/;
  //check for valid us phone with or without space between
  //area code
  return objRegExp.test(strValue);
}


function ValidateRegForm(which)
{
	
	if (which.FNameTxt.value == "")
	{
		alert('First Name field is required for this form');
		return false;
	}
	
	if (!(document.Form1.SalutationList[0].checked || document.Form1.SalutationList[1].checked || document.Form1.SalutationList[2].checked  || document.Form1.SalutationList[3].checked  || document.Form1.SalutationList[4].checked || document.Form1.SalutationList[5].checked || document.Form1.SalutationList[6].checked )){
		alert('You have to choose your Salutation');
		return false
	}	
	if (document.Form1.FNameTxt.value == "")
	{
		alert('First Name field is required');
		return false;
	}
	if (document.Form1.LNameTxt.value == "")
	{
		alert('Last Name field is required');
		return false;
	}
	if (document.Form1.EmailTxt.value == "")
	{
		alert('Email field is required');
		return false;
	}
	
	if (isCorrectEmail(document.Form1.EmailTxt.value) == false)
	{
		alert ('Email address does not have the right format');
		return false;
	}
	
	if (document.Form1.AddressTxt.value == "")
	{
		alert('Address field is required');
		return false;
	}
	
	if (document.Form1.CityTxt.value == "")
	{
		alert('City field is required');
		return false;
	}
	
	if (document.Form1.StateTxt.value == "")
	{
		alert('State field is required');
		return false;
	}
	
	if (document.Form1.ZipCodeTxt.value == "")
	{
		alert('ZipCode field is required');
		return false;
	}
	
	if (document.Form1.PhoneTxt.value == "")
	{
		alert('Contact Phone field is required');
		return false;
	}
	
	if (document.Form1.PhoneTxt.value != ""  & validateUSPhone(document.Form1.PhoneTxt.value) == false)
	{
		alert ('Phone number is not valid.  Phone format is xxx-xxx-xxxx')
		return false;
	}
	
	if (document.Form1.HomePhoneTxt.value != ""  & validateUSPhone(document.Form1.HomePhoneTxt.value) == false)
	{
		alert ('Home phone number is not valid.  Phone format is xxx-xxx-xxxx')
		return false;
	}
	return true;
}

function ValidateLocationForm()
{
	if (document.Form1.LocationTxt.value == "")
	{
		alert('Location Name is required');
		return false;
	}
	if (document.Form1.AddressTxt.value == "")
	{
		alert('Address field is required');
		return false;
	}
	if (document.Form1.CityTxt.value == "")
	{
		alert('City field is required');
		return false;
	}
	if (document.Form1.StateTxt.value == "")
	{
		alert('State field is required');
		return false;
	}
	if (document.Form1.ZipCodeTxt.value == "")
	{
		alert('ZipCode field is required');
		return false;
	}
	return true;
}

function ValidateRoomForm()
{
	if (document.Form1.LocationList.selectedIndex <= 0){
		alert ('You must choose a Location');
		return false;
	}
	if (document.Form1.RoomTxt.value == ""){
		alert ('Room Name is required');
		return false;
	}
	return true;
}


/*--------------------------------------------*/
function getconfirm() 
	{ 
			if (confirm("Do you want to delete record?")==true) 
			return true; 
			else 
			return false; 
	}
/*--------------------------------------------*/	
function Cancelconfirm() 
	{ 
			if (confirm("Do you want to cancel the workshop?")==true) 
			return true; 
			else 
			return false; 
	}
/*--------------------------------------------*/	
function DeleteInstructorconfirm()
	{
		if (confirm("Deleting the instructor will take his/her name out of all their classes.  Do you want to continue?")==true) 
			return true; 
			else 
			return false; 
	}
/*--------------------------------------------*/

function CatchKeyPress(KeyCode, Sender) { 
      var btnToBeClicked = null; 
      RemoveEnterAndEscEvents(); 
      if(KeyCode == '13') { 
			var ButtonName = Sender.getAttribute("TargetButton"); 		
			btnToBeClicked = document.getElementById(ButtonName); 
			if(btnToBeClicked) { 
					btnToBeClicked.click(); 
				} 
		} 
} 

		
function RemoveEnterAndEscEvents() { 
		if (event.keyCode == 13 || event.keyCode == 27) { 
				event.cancelBubble = true; 
				event.returnValue = false; 				
		} 
} 		
