var NMCI = {
	HAL:function(id) {
		new Effect.Highlight( $(id) );
		$(id).focus();
	},
	Booking : {
		Company : {
			Validate:function() {
				if( $("companyName") && $("companyAddress") ) {
					if( $("companyName").value.blank() ) {
						NMCI.HAL("companyName");
						return false;
					}
					if( $("companyAddress").value.blank() ) {
						NMCI.HAL("companyAddress");
						return false;
					}
					if( $("companyPurchaseOrder").value.blank() ) {
						NMCI.HAL("companyPurchaseOrder");
						return false;
					}
				}
				return true;
			}
		},
		Individual : {
			Validate:function() {
				if( $("prerequisites") ) {
					var cbs = $$(".prereq");
					var cbsChecked = $$(".prereq:checked");
					if( cbs.length!=cbsChecked.length ) {
						alert("You must qualify for this course by ensuring you meet the pre-requisites listed.\n\nIf you qualify, please check all the boxes");
						return false;
					} else {
						return true;
					}
				} else {
					return true;
				}
			}				
		},
		Group : {
			PreRequisites:function() {
				if( $("prerequisites") ) {
					var cbs = $$(".prereq");
					var cbsChecked = $$(".prereq:checked");
					if( cbs.length!=cbsChecked.length ) {
						alert("You and all the attendees must qualify for this course by ensuring you meet the pre-requisites listed.\n\nIf you and all the attendees qualify, please check all the boxes");
						return false;
					} else {
						return true;
					}
				} else {
					return true;
				}
			},
			Validate:function(numberOfPeople) {
				for(i=1;i<=numberOfPeople;i++) {
					if( $("firstName_"+i).value.blank() ) {
						NMCI.HAL("firstName_" + i);
						return false;
					}
					if( $("lastName_"+i).value.blank() ) {
						NMCI.HAL("lastName_" + i);
						return false;
					}
					if( $("email_"+i).value.blank() ) {
						NMCI.HAL("email_" + i);
						return false;
					}/*
					if( $("ppsNumber_"+i).value.blank() ) {
						NMCI.HAL("ppsNumber_" + i);
						return false;
					}*/
					if( $("telephone_"+i).value.blank() ) {
						NMCI.HAL("telephone_" + i);
						return false;
					}
				}
				return true;
			}
		}
	},
	Accounts : {
		MyProfile : {
			Validate:function() {
				if( $("firstName").value.blank() ) {
					NMCI.HAL("firstName");
					return false;
				}
				if( $("lastName").value.blank() ) {
					NMCI.HAL("lastName");
					return false;
				}
				if( $("identificationNO").value.blank() ) {
					NMCI.HAL("identificationNO");
					return false;
				}
				if( $("nationality").value.blank() ) {
					NMCI.HAL("nationality");
					return false;
				}
				if( $("address").value.blank() ) {
					NMCI.HAL("address");
					return false;
				}
				if( $("phoneNumber").value.blank() ) {
					NMCI.HAL("phoneNumber");
					return false;
				}
				if( $("mobileNumber").value.blank() ) {
					NMCI.HAL("mobileNumber");
					return false;
				}
				return true;
			}
		},
		Signup : {
			Validate:function() {
				if( $("firstName").value.blank() ) {
					NMCI.HAL("firstName");
					return false;
				}
				if( $("lastName").value.blank() ) {
					NMCI.HAL("lastName");
					return false;
				}
				/*if( $("identificationNO").value.blank() ) {
					NMCI.HAL("identificationNO");
					return false;
				}
				if( $("nationality").value.blank() ) {
					NMCI.HAL("nationality");
					return false;
				}*/
				if( $("address").value.blank() ) {
					NMCI.HAL("address");
					return false;
				}
				if( $("phoneNumber").value.blank() ) {
					NMCI.HAL("phoneNumber");
					return false;
				}
				if( $("mobileNumber").value.blank() ) {
					NMCI.HAL("mobileNumber");
					return false;
				}
				if( $("email").value.blank() ) {
					NMCI.HAL("email");
					return false;
				}
				if( $("email2").value.blank() ) {
					NMCI.HAL("email2");
					return false;
				}
				if( $("email").value != $("email2").value) {
					alert("Your email address and confirmation email address do not match");
					return false;
				}
				if( $("password").value.blank() ) {
					NMCI.HAL("password");
					return false;
				}
				if( $("password2").value.blank() ) {
					NMCI.HAL("password2");
					return false;
				}
				if( $("password").value != $("password2").value) {
					alert("Your password and confirmation password do not match");
					return false;
				}
				return true;
			}
		}
	}
}





























var isAnyEmailExists = false;
var numOfEmailExists = 0;

var CommercialCourse ={
	
	CourseList : {
		ShowCourseList:function()
		{
			var url = "index.cfm?action=commercial_CourseList&d=" + escape(new Date());
			Lightbox.showBoxByAJAX( url, 900 , 900, true );
		}
	},
	
	Prerequisites : {
		PrerequisiteInfo:function( courseId, id ){
			var url = "index.cfm?action=prerequisiteinfo&courseId="+courseId+"&id="+id;
			Lightbox.showBoxByAJAX( url, 900 , 700, true );
		}
	},
	
	CheckIfEmailIsExisting : {
		LoginForm_Load:function( id )
		{
			var email = $(id).value;
			var url = "index.cfm?action=checkemail&email="+email;
			new Ajax.Request( url, {asynchronous:true, evalScripts:false, onSuccess:CommercialCourse.CheckIfEmailIsExisting.LoginForm_Load_onSuccess, onFailure:errFunc});	
		},
		LoginForm_Load_onSuccess:function( t )
		{
			z = parseJSON( t.responseText );
			if(!z.text.blank())
			{
				$("emailDiv").update(z.text);
				$("radioOldCustomer").checked = true;
			}
			else
			{
				$("emailDiv").update("");
				$("radioNewCustomer").checked = true;
			}
		},
		DetailForm_Load:function( id, thisfield, userId, courseDateId, change )
		{
			var email = $(id).value;
			
			if( thisfield && userId && !change)
			{
				var url = "index.cfm?action=checkemailOnCourseDate&email="+email+"&id="+thisfield+"&userId="+userId+"&courseDateId="+courseDateId;
			}
			else if ( thisfield && userId && change )
			{	
				var url = "index.cfm?action=checkemailOnCourseDate&email="+email+"&id="+thisfield+"&userId="+userId+"&courseDateId="+courseDateId+"&change="+change;
			}
			
			new Ajax.Request( url, {asynchronous:true, evalScripts:false, onSuccess:CommercialCourse.CheckIfEmailIsExisting.DetailForm_Load_onSuccess, onFailure:errFunc});	
		},
		DetailForm_Load_onSuccess:function( t )
		{
			z = parseJSON( t.responseText );
			
			if( !z.tableHTML.blank() )
			{
				$("attendee"+z.id).update( z.tableHTML );	
			}
			
			if( !z.text.blank() && z.id )
			{
				$("emailDiv"+z.id).update(z.text);
				
				if( !isAnyEmailExists )
				{
					isAnyEmailExists = true;
				}
				numOfEmailExists++;
				
			}
			else
			{
				$("emailDiv"+z.id).update("");
				
				if( numOfEmailExists > 0)
				{
					numOfEmailExists--;
				}
				if( numOfEmailExists==0 )
				{
					isAnyEmailExists = false;
				}		
			}

		}
	},
	
	Payment : {
		ShowDatesLightBox:function( courseDateId ){
			var url = "index.cfm?action=showotherdatesavailable&courseDateId="+courseDateId;
			Lightbox.showBoxByAJAX( url, 700, 500, true );
		}
	},
	
	CourseBooking : {
		CourseBookingLightBox:function( courseId, courseDateId ) {
			var url = "index.cfm?action=courseBooking&courseId="+courseId+"&courseDateId="+courseDateId;
			Lightbox.showBoxByAJAX( url, 700, 700, true, "CommercialCourse.CourseBooking.OnDisplayCourseBookingLightBox()" );
		},
		Booking_SignIn:function( typeOfBooking ) {
			if( typeOfBooking == "individual")
			{
				$('signInDiv_IndividualBK').show();
				$("signInDiv_GroupBK").update("");
			}else if( typeOfBooking == "group")
			{	
				$('signInDiv_GroupBK').show();
				$("signInDiv_IndividualBK").update("");
			}
			$("selectBKType").hide();
			if( $("loginEmail") && $("loginEmail").value == "" ) $("loginEmail").focus();
			else if( $("loginPassword") ) $("loginPassword").focus();
		},
		SignIn_Form:function() 
		{
			var userType = "";
				
			var cbObjs = $$("input").each
			(
				function(name,index) 
				{
					if( name.type=="radio" && name.checked ) 
					{
						userType = name.value;	
					}
				}
			);
			
			if( userType == "new-user")
			{
				$("courseSigninForm").submit();
			}
			else
			{		
				if(CommercialCourse.Login.ValidateLogin())
				{
					$("courseSigninForm").submit();
				}
				else
				{
					return false;
				}
			}
		}
	},		
	
	IndividualTransaction : {
		IndividualPayment:function()
		{
			var url = "index.cfm?action=individualpaymentinfo";
			new Ajax.Request( url, {asynchronous:true, evalScripts:false, onSuccess:CommercialCourse.IndividualTransaction.IndividualPayment_onSuccess, onFailure:errFunc});	
		},
		IndividualPayment_onSuccess:function(t){
			isAnyEmailExists = false;
			z = parseJSON( t.responseText );
			$("grouppaymentDiv").update(z.text);
		},
		RenderGroupPayment:function( courseDateId,placesLeft,statusid )
		{	
			var url = "index.cfm?action=rendergrouppaymenthtml&courseDateId="+courseDateId+"&statusid="+statusid+"&placesLeft="+placesLeft;
			new Ajax.Request( url, {asynchronous:true, evalScripts:false, onSuccess:CommercialCourse.IndividualTransaction.RenderGroupPayment_onSuccess, onFailure:errFunc});				
		},
		RenderGroupPayment_onSuccess:function(t)
		{	
			isAnyEmailExists = false;
			z = parseJSON( t.responseText );
			$("grouppaymentDiv").update(z.text);
		}
	},
	
	GroupAttendeesInfo : {
		Load:function(divId, userId, courseDateId, statusid)
		{
			var num = $(divId).value;
			var max_num = parseInt($("maxNumberOfAttendees").innerHTML,10);
			if( num != -1)
			{
				var url = "index.cfm?action=groupattendees_info_dropdown&numOfAttendees="+num+"&courseDateId="+courseDateId+"&userId="+userId+"&statusid="+statusid;
	
				$("numberSelectionDiv").hide();
				$("deleteAttendee").show();
				
				if ( num == max_num ){
					$("addAttendee").hide();
				}
				
				$("numberOfAttendeesSelected").textContent = $(divId).value;
				new Ajax.Request( url, {asynchronous:true, evalScripts:false, onSuccess:CommercialCourse.GroupAttendeesInfo.Load_onSuccess, onFailure:errFunc});	
			}
			else
			{
				$("attendeesInfo").update("");
			}
		},
		Load_onSuccess:function(t)
		{
			z = parseJSON( t.responseText );
			$("attendeesInfo").update(z.handleOption);
		},
		SelectOperationType:function(id,divid)
		{
			if( $(id).value == "later")
			{
				Effect.BlindUp(divid);
			}
			else if( $(id).value == "now" )
			{
				Effect.BlindDown(divid);
			}
		},
		CheckDetail:function()
		{
			// $("personalBook") will only come up when the user chooses to pay for only himeself
			// There is no need to check for the form at that moment.
			if( $("personalBook") )
			{
				return true;
			}
			// !$("minNumberOfAttendees") will only come up when the user chooses to pay for a group
			if( !$("minNumberOfAttendees") )
			{
				return false;
			}
			
			var min_num = parseInt($("minNumberOfAttendees").innerHTML,10);
			var num = $("places").value;
			
			if( !$("attendee_"+num) )
			{
				$("places").value = min_num;
			} 
			if( isAnyEmailExists ){
				return false;
			}
			for( i=1; i <= $("places").value; i++ )
			{
				if( $("attendee_"+i).value == "now" )
				{
				
					if( $("email"+i) && $("email"+i).value.blank())
					{
						CommercialCourse.HighlightAndFocus("email"+i);
						return false;
					}				
					if( $("email"+i) && !$("email"+i).value.blank() )
					{
						if(!isEmail($("email"+i).value) )
						{
							alert("Please make sure that the format of email you entered is correct ");
							CommercialCourse.HighlightAndFocus("email"+i);
							return false;
						}
					}
					if( $("firstName"+i).value.blank())
					{
						CommercialCourse.HighlightAndFocus("firstName"+i);
						return false;
					}					
					if( $("lastName"+i).value.blank())
					{
						CommercialCourse.HighlightAndFocus("lastName"+i);
						return false;
					}				
					if( $("identificationNO"+i).value.blank())
					{
						CommercialCourse.HighlightAndFocus("identificationNO"+i);
						return false;
					}
					if( $("phone"+i).value.blank())
					{
						CommercialCourse.HighlightAndFocus("phone"+i);
						return false;
					}
					if( $("mobile"+i).value.blank())
					{
						CommercialCourse.HighlightAndFocus("mobile"+i);
						return false;
					}	
					if( $("identificationNO"+i).value.length > 10)
					{
						alert("The length of PPS number/National Identification Number has to be less than or equal to 10");
						CommercialCourse.HighlightAndFocus("identificationNO"+i);
						return false;
					}
					if( !$("phone"+i).value.blank() && !isPhoneNumber($("phone"+i).value) )
					{
						alert( "The phone number should only contain numbers (0-9), spaces and symbol (+), with maximum length of 15 characters." );
						CommercialCourse.HighlightAndFocus("phone"+i);
						return false;
					}
					if( !$("mobile"+i).value.blank() && !isPhoneNumber($("mobile"+i).value) )
					{
						alert( "The mobile number should only contain numbers (0-9), spaces and symbol (+), with maximum length of 15 characters." );
						CommercialCourse.HighlightAndFocus("mobile"+i);
						return false;
					}
				}
			}
		},
		AddAttendee:function( courseDateId )
		{
			var num = parseInt($("numberOfAttendeesSelected").innerHTML,10)+1;
			var min_num = parseInt($("minNumberOfAttendees").innerHTML,10);
			var max_num = parseInt($("maxNumberOfAttendees").innerHTML,10);

			if( num == max_num )
			{
				$("addAttendee").hide();
				$("deleteAttendee").show();
			}
			else if( num == (min_num+1) )
			{	
				$("deleteAttendee").show();
			}	 	
			else if( num > max_num )
			{
				return false;
			}
			$("numberOfAttendeesSelected").innerHTML = num;
			$("places").value = num;
			var url = "index.cfm?action=groupattendees_AddAttendee&numOfAttendees="+num+"&courseDateId="+courseDateId;
			new Ajax.Request( url, {asynchronous:true, evalScripts:false, onSuccess:CommercialCourse.GroupAttendeesInfo.AddAttendee_onSuccess, onFailure:errFunc});	
		},
		AddAttendee_onSuccess:function(t)
		{	
			z = parseJSON( t.responseText );
			$("attendeesInfo").insert({ bottom: z.handleOption} );
		},
		DeleteAttendee:function()
		{
			var num = parseInt($("numberOfAttendeesSelected").innerHTML,10);
			var min_num = parseInt($("minNumberOfAttendees").innerHTML,10);
			var max_num = parseInt($("maxNumberOfAttendees").innerHTML,10);
			
			if( (num-1) == min_num )
			{
				$("deleteAttendee").hide();
				$("addAttendee").show();
			}
			else if( num == max_num )
			{
				$("addAttendee").show();
			}
			else if( num < min_num )
			{
				return false;
			}	
			
			$("attendee"+num).remove();
			$("numberOfAttendeesSelected").innerHTML = num-1;			
			$("places").value = num-1;
		}			
	},
		
	Login : {
		ValidateLogin:function() {
			if($("loginEmail").value.blank()) {
				CommercialCourse.HighlightAndFocus("loginEmail");
				return false;
			}
			if($("loginPassword").value.blank()) {
				CommercialCourse.HighlightAndFocus("loginPassword");
				return false;
			}
			return true;
		}
	},
	
	PaymentSubmit : {
		InvoiceUs:function( id,courseDateId ){
			var newUrl = "index.cfm?action=payment&courseDateId="+courseDateId;
			$(id).action = newUrl;
			var url = "index.cfm?action=prerequisites_checkbox&courseDateId="+courseDateId+"&id="+id;
			Lightbox.showBoxByAJAX( url, 700, 700, true );
		},
		PayNow:function( id,courseDateId ){
			var newUrl = "index.cfm?action=onlinepaymentsredirect&courseDateId="+courseDateId;
			$(id).action = newUrl;			
			var url = "index.cfm?action=prerequisites_checkbox&courseDateId="+courseDateId+"&id="+id;
			Lightbox.showBoxByAJAX( url, 700, 700, true );
		},
		InvoiceUs2:function( id,courseDateId ){
			var newUrl = "index.cfm?action=payment&courseDateId="+courseDateId;
			$(id).action = newUrl;
			var url = "index.cfm?action=prerequisites_checkbox&courseDateId="+courseDateId+"&id="+id;
			$(id).submit();
		},
		PayNow2:function( id,courseDateId ){
			var newUrl = "index.cfm?action=onlinepaymentsredirect&courseDateId="+courseDateId;
			$(id).action = newUrl;			
			var url = "index.cfm?action=prerequisites_checkbox&courseDateId="+courseDateId+"&id="+id;
			$(id).submit();
		},
		InvoiceMyCompany:function( id,courseDateId ){
			var newUrl = "index.cfm?page=invoicemycompany&courseDateId="+courseDateId;
			$(id).action = newUrl;
			var url = "index.cfm?action=prerequisites_checkbox&courseDateId="+courseDateId+"&id="+id;
			$(id).submit();
		}
	},
	
	Prerequisite : {
		Check_Prerequisites:function( id ){
				$(id).submit();
		}
	},
	
	Registration : {
		ValidateDetails:function(){
			if( $("companyName") && $("companyAddress") ){
				if($("companyName").value.blank()) {
					CommercialCourse.HighlightAndFocus("companyName");
					return false;
				}
				if($("companyAddress").value.blank()) {
					CommercialCourse.HighlightAndFocus("companyAddress");
					return false;
				}
			}
			
			if($("firstName").value.blank()) {
				CommercialCourse.HighlightAndFocus("firstName");
				return false;
			}
			if($("lastName").value.blank()) {
				CommercialCourse.HighlightAndFocus("lastName");
				return false;
			}		
			if($("birthDay").value.blank()) {
				CommercialCourse.HighlightAndFocus("birthDay");
				return false;
			}
			if($("birthMonth").value.blank()){
				CommercialCourse.HighlightAndFocus("birthMonth");
				return false;
			}
			if($("birthYear").value.blank()){
				CommercialCourse.HighlightAndFocus("birthYear");
				return false;
			}		
			if( !$("birthDay").value.blank() && !$("birthMonth").value.blank() && !$("birthYear").value.blank()){
				if( !isValidatedBirthDate("birthYear", "birthMonth", "birthDay") )
				return false;
			}	
			if($("identificationNO").value.blank()) {
				CommercialCourse.HighlightAndFocus("identificationNO");
				return false;
			}			
			if($("nationality").value.blank()) {
				CommercialCourse.HighlightAndFocus("nationality");
				return false;
			}	
			if( !isValidateNationality($("nationality").value) ){
				alert("Invalid nationality, should only contain alphabetic characters, with a maximum length of 15 characters.");
				CommercialCourse.HighlightAndFocus("nationality");
				return false;
			}
			if($("address").value.blank()) {
				CommercialCourse.HighlightAndFocus("address");
				return false;
			}	
			if($("phoneNumber").value.blank() ) {
				CommercialCourse.HighlightAndFocus("phoneNumber");
				return false;
			}
			if(!isPhoneNumber($("phoneNumber").value)) {
				alert( "Invalid phone number, should only contain numbers (0-9), spaces and symbol (+), with maximum length of 15 characters." );
				CommercialCourse.HighlightAndFocus("phoneNumber");
				return false;
			}
			if($("mobileNumber").value.blank()) {
				CommercialCourse.HighlightAndFocus("mobileNumber");
				return false;
			}
			if( !isPhoneNumber($("mobileNumber").value)) {
				alert( "Invalid mobile number, should only contain numbers (0-9), spaces and symbol (+), with maximum length of 15 characters." );
				CommercialCourse.HighlightAndFocus("mobileNumber");
				return false;
			}
			if($("email").value.blank()) {
				CommercialCourse.HighlightAndFocus("email");
				return false;
			}
			if( !isEmail($("email").value) ){
				alert( "Invalid email format." );
				CommercialCourse.HighlightAndFocus("email");
				return false;
			}
			if( $("email2") ){
				if($("email2").value != $("email").value) {
					CommercialCourse.HighlightAndFocus("email2");
					return false;
				}
			}
			if( $("newEmail")  ){
				if( !isEmail($("newEmail").value) && !$("newEmail").value.blank() ){
					alert( "Invalid email format." );
					CommercialCourse.HighlightAndFocus("newEmail");
					return false;
				}
			}	
			if( $("password") && $("password2") ){
				if($("password").value.blank()) {
					CommercialCourse.HighlightAndFocus("password");
					return false;
				}
				if($("password2").value != $("password").value) {
					CommercialCourse.HighlightAndFocus("password2");
					return false;
				}
			}	
			
			return true;
		}
	},
	
	Change_Password : {
		CheckForm:function()
		{	
			if(!$("password").value.blank() && $("password").value.length < 5 ){
				alert("The length of password must be greater than or equal to 5.");
				return false;
			}
			if($("password").value.blank()) {
				CommercialCourse.HighlightAndFocus("password");
				return false;
			}
			if($("password2").value != $("password").value) {
				CommercialCourse.HighlightAndFocus("password2");
				return false;
			}		
		}
	},
	
	Upgrade_To_ComapnyAccount : {
		ValidateDetails:function(){
			if($("companyName").value.blank()) {
				CommercialCourse.HighlightAndFocus("companyName");
				return false;
			}
			if($("companyAddress").value.blank()) {
				CommercialCourse.HighlightAndFocus("companyAddress");
				return false;
			}
		},
		SearchCompanyById:function(){
			if( $("companyCode").value != -1){
				var code = $("companyCode").value;
				var url = "index.cfm?action=searchcompany&companyCode="+code;
				new Ajax.Request( url, {asynchronous:true, evalScripts:false, onSuccess:CommercialCourse.Upgrade_To_ComapnyAccount.SearchCompany_onSuccess, onFailure:errFunc});	
			}
		},
		SearchCompanyByCompany:function(){
			var company =  $("companyName").value
			var url = "index.cfm?action=searchcompany&company="+company;
			new Ajax.Request( url, {asynchronous:true, evalScripts:false, onSuccess:CommercialCourse.Upgrade_To_ComapnyAccount.SearchCompany_onSuccess, onFailure:errFunc});	
		},
		SearchCompany_onSuccess:function( t ){
			z = parseJSON( t.responseText );
			$("companyAddress").value = z.companyAddress;
			if( z.companyName ){
				$("companyName").value = z.companyName;
			}	
			if( z.companyCode ){
				$("companyCode").value = z.companyCode;
			}	
		}
	},
	
	invoiceCompany : {
		ValidateDetails:function(){
			if($("companyName").value.blank()) {
				CommercialCourse.HighlightAndFocus("companyName");
				return false;
			}
			if($("companyAddress").value.blank()) {
				CommercialCourse.HighlightAndFocus("companyAddress");
				return false;
			}
		}
	},
	
	InitSignUpForm:function(){
		new LiveValidation('email',{validMessage:"OK"}).add( Validate.Email );
		new LiveValidation('email2',{validMessage:"OK"}).add( Validate.Email );
		new LiveValidation('identificationNO',{validMessage:"OK"}).add( Validate.Length, { maximum: 10 } );
		new LiveValidation('password',{validMessage:"OK"}).add( Validate.Length, { minimum: 5 } );
		new LiveValidation('password2',{validMessage:"OK"}).add( Validate.Length, { minimum: 5 } );
	},
	HighlightAndFocus:function(id) {
		new Effect.Highlight($(id));
		$(id).focus();
	}
		
}

var myProfile = {

	showNewEmailInputField:function(){
		$("newEmailLink").hide();
		$("newEmailLabel").show();
		$("newEmail").show();
	},
	checkDetailBeforeUpdatingComUsers:function( num )
	{
		for( i=1; i <= num ; i++ )
		{
			if( $("attendee_"+i).value == "now" )
			{
			
				if( $("email"+i) && $("email"+i).value.blank())
				{
					CommercialCourse.HighlightAndFocus("email"+i);
					return false;
				}				
				if( $("email"+i) && !$("email"+i).value.blank() )
				{
					if(!isEmail($("email"+i).value) )
					{
						alert("Invalid email. Please make sure that the format of email you entered is correct ");
						CommercialCourse.HighlightAndFocus("email"+i);
						return false;
					}
				}
				if( $("firstName"+i).value.blank())
				{
					CommercialCourse.HighlightAndFocus("firstName"+i);
					return false;
				}					
				if( $("lastName"+i).value.blank())
				{
					CommercialCourse.HighlightAndFocus("lastName"+i);
					return false;
				}				
				if( $("identificationNO"+i).value.blank())
				{
					CommercialCourse.HighlightAndFocus("identificationNO"+i);
					return false;
				}
				if( $("phone"+i).value.blank())
				{
					CommercialCourse.HighlightAndFocus("phone"+i);
					return false;
				}
				if( $("mobile"+i).value.blank())
				{
					CommercialCourse.HighlightAndFocus("mobile"+i);
					return false;
				}				
				if( !$("phone"+i).value.blank() && !isPhoneNumber($("phone"+i).value) )
				{
					alert("Invalid phone number, should only contain numbers (0-9), spaces and symbol (+), with maximum length of 15 characters.");
					CommercialCourse.HighlightAndFocus("phone"+i);
					return false;
				}
				if( !$("mobile"+i).value.blank() && !isPhoneNumber($("mobile"+i).value) )
				{
					alert("Invalid mobile number, should only contain numbers (0-9), spaces and symbol (+), with maximum length of 15 characters.");
					CommercialCourse.HighlightAndFocus("mobile"+i);
					return false;
				}
			}
		}
	}		
}

function isValidatedBirthDate( yId, mId, dId){
	var y = $(yId).value;	
	var m = $(mId).value-1;	
	var d = $(dId).value;	
	var dateMonth = new Date(y,m,d).getMonth();	
	if( y < 1900 ){
		alert("Invalid entry, please check birth year.");
		CommercialCourse.HighlightAndFocus( yId );
		return false;
	}
	if( m < 0 || m > 11){
		alert("Invalid entry, please check birth month.");
		CommercialCourse.HighlightAndFocus( mId );
		return false;
	}
 	if( m != dateMonth){
		alert("Invalid entry, please check birth day.");
		CommercialCourse.HighlightAndFocus( dId );
		return false;
	}
	return true;
}

function LoadingAjax(txt) {
	if(typeof(txt)=="undefined") {
		txt = "Loading...";
	}
	return "<div class='ajaxMsg' id='widgetAjaxMsg'> "+txt+"</div>";
}

function parseJSON( json ){
	var o = eval('(' + json + ')');
	if( o.js )
	{
		window.o = o;
		('<script>'+o.js+'</script>').evalScripts();
	}
	if( o.redirectURL )
	{
		document.location = o.redirectURL;
		return;
	}
	if( $("message") != null ) new Element.remove( "message" );
	if( o.errMsg )
	{
		if( o.errMsgTitle == null ) o.errMsgTitle = "Error";
		if( o.errMsgTimer == null ) o.errMsgTimer = 5000;
		tw.ShowMessage( o.errMsgTitle, o.errMsg, "error", o.errMsgTimer, o.errMsgPosition );
		return o;
	}
	if( o.msgTitle || o.msg )
	{
		if( o.msgTimer == null ) o.msgTimer = 5000;
		tw.ShowMessage( o.msgTitle, o.msg, o.msgClass, o.msgTimer, o.msgPosition );
	}
	return o;
}

var errFunc = function(t) {
	var win = window.open("", "win", "width=1024,height=700,resizable=yes,scrollbars=yes,status=no"); // a window object
	win.document.open("text/html", "replace");
	win.document.write( "<html><body style='margin:0'><div style='border-bottom:1px solid #222;background:#666;padding:10px;'><h1 style='color:#FFF;margin:0;padding:0;'>Digital Crew Ajax Error</h1></div><div style='padding:10px;'>"+t.responseText.replace(/^\s+|\s+$/, '') + "</div></body></html>" );
	win.document.close();
	win.focus();
}

var LightboxHolder = {	
	DestroyCreate:function( id ) {
		if( $('boxContents') ) {
			$('boxContents').update("&nbsp;")
		}
		
		if( $( id ) ) {
			$( id ).remove();			
		}
		if( !$( id ) ) {
			Element.extend( document.getElementsByTagName("body")[0] ).insert("<div id='" + id + "' style='display:none'></div>");
		}
	},
	Close:function() {
		Element.hide('box');
		Element.hide('overlay');
	}
}

function onCheckPrerequisites(){
	var allChecked = true;
	$$('#prereqsChecksDiv input.prereqCb').each(function(elm){
		if( elm.checked == false ) allChecked = false;
	})
	$("prerequisites_confirm").disabled = !allChecked;
}

