
function confirmDelete(URL,ObjectName) { 
	if(confirm('Confirm remove \n\n' + ObjectName + '?')) { 
		window.location.href = URL;
	}	
}

	
/* Set focus in first field if there is a form */
function firstFocus() {
   if (document.forms.length > 0) {
      
	  var TForm = document.forms[0];

	  for (i=0;i<TForm.length;i++) {
	  
         if ( (TForm.elements[i].disabled != true) && (TForm.elements[i].type=="text")||
		 									(TForm.elements[i].type=="textarea")
											)
											//||
											//(TForm.elements[i].type.toString().charAt(0)=="s") )
         {
            document.forms[0].elements[i].focus();
            break;
         }
      }
   }
}




function formUserForm(theForm) {

	if (theForm.firstname.value.length == 0) {
		alert('Firstname is a required field!');
		theForm.firstname.focus();
		return false;
	}
		
	if (theForm.lastname.value.length == 0) {
		alert('Last name is a required field');
		theForm.lastname.focus();
		return false;
	}
		
	if (theForm.phone_1.value.length == 0) {
		alert('Mobile is a required field');
		theForm.phone_1.focus();
		return false;
	}
	
	if (theForm.email_1.value.length == 0) {
		alert('Email 1 is a required field');
		theForm.email_1.focus();
		return false;
	}
	
	if (!isValidEmail(theForm.email_1.value)) {
		alert('Please check Email 1 address');
		theForm.email_1.focus();
		return false;
	}
	
	if (theForm.email_2.value.length != 0) {

		if (!isValidEmail(theForm.email_2.value)) {
			alert('Please check Email 2 address');
			theForm.email_2.focus();
			return false;
		}

	}
	
	// Check username, password 1, password 2 if this is a new member
	if (theForm.usr) {
	
		if (!validateUserPassword(theForm)) {
			return false;
		}
	
	}
	
	
	
	return true; 
		
}

function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

// Check change username and password form
function validateUserPassword(theForm) {

		if (theForm.usr.value.length == 0) {
			alert('Username is a required field');
			theForm.usr.focus();
			return false;
		}
		
		if (theForm.old_pwd) {
		
			if (theForm.old_pwd.value.length == 0) {
				alert('Old password is a required field');
				theForm.old_pwd.focus();
				return false;
			}
		
		}
	
		if (theForm.pwd_1.value.length == 0) {
			alert('Password 1 is a required field');
			theForm.pwd_1.focus();
			return false;
		}
		
		if (theForm.pwd_1.value.length < 5) {
			alert('Password most contain at least 5 characters');
			theForm.pwd_1.focus();
			return false;
		}
		
		if (theForm.pwd_2.value.length == 0) {
			alert('Password 2 is a required field');
			theForm.pwd_1.focus();
			return false;
		}
		
		if (theForm.pwd_2.value.length < 5) {
			alert('Password most contain at least 5 characters');
			theForm.pwd_2.focus();
			return false;
		}
		
		if (theForm.pwd_1.value != theForm.pwd_2.value) {
			alert('Mismatch, check Password 1 and Password 2');
			theForm.pwd_2.focus();
			return false;
		}

	return true; 

}

// Check Event form
function formEventForm(theForm) {

		if (theForm.title.value.length == 0) {
			alert('Title is a required field');
			theForm.title.focus();
			return false;
		}
	
		if (theForm.start_date.value.length == 0) {
			alert('Start date is a required field');
			theForm.start_date.focus();
			return false;
		}
		
		if (theForm.end_date.value.length == 0) {
			alert('End date is a required field');
			theForm.end_date.focus();
			return false;
		}
		
		
		if (theForm.start_date.value > theForm.end_date.value) {
			alert('Start date cannot be later than End date. Check end date.');
			theForm.end_date.focus();
			return false;
		}
		

	return true; 

}



// Check Event detail form
function formEventDetailForm(theForm) {

		if (theForm.title.value.length == 0) {
			alert('Title is a required field');
			theForm.title.focus();
			return false;
		}
	
		if (theForm.url.value.length == 0) {
			alert('URL is a required field');
			theForm.url.focus();
			return false;
		}

	return true; 

}



function openWindow(ScriptName,WindowName,Width,Height,URL){
	
	// Reload parent window
	if (URL != "") {
		window.location.href = URL;
	}

	// Center window
	var win = null; 
	LeftPosition = (screen.width) ? (screen.width-Width)/2 : 0; 
	TopPosition = (screen.height) ? (screen.height-Height)/2 : 0; 

	//name the current window
	self.name = "main";
		
	// Properties for window
	var windowProps = 'width='+Width+',height='+Height+',top='+TopPosition+',left='+LeftPosition+',toolbar=0,status=1,location=0,resizable=1,scrollbars=1,directories=0,menubar=0'
	var newWindow = window.open(ScriptName,WindowName,windowProps);
	newWindow.focus();

}


function closeReloadWindow() {
	window.opener.location.reload();
	window.close();
	return true;
}
