var currentAdminPage = "OverviewOptions";
var currentMemberPage = "OverviewOptions";
var currentMessDeck = "Scuttlebutt";
var currentShop = "default";
var currentShopTab = "description";

var totalImages = 1;
var totalParagraph = 1;
var totalExtra = 1;

function switchAdminOption(request)
{
	var ele = document.getElementById(request);
	var currentEle = document.getElementById(currentAdminPage);
	if(currentAdminPage != request)
	{
		ele.style.display = "block";
		currentEle.style.display = "none";

	}
	currentAdminPage = request;
}

function switchMemberOption(request)
{
	var ele = document.getElementById(request);
	var currentEle = document.getElementById(currentMemberPage);
	if(currentMemberPage != request)
	{
		ele.style.display = "block";
		currentEle.style.display = "none";

	}
	currentMemberPage = request;
}

function switchMessDeck(request)
{
	var elem = document.getElementById(request);
	var currentElem = document.getElementById(currentMessDeck);
	if(currentMessDeck != request)
	{
		elem.style.display = "block";
		currentElem.style.display = "none";
	}
	if(request == "Scuttlebutt")
	{
		document.getElementById("chromenav").src="images1/chromeNav1.png";
	}
	else if(request == "recentEvents")
	{
		document.getElementById("chromenav").src="images1/chromeNav2.png";
	}
	else
	{
		document.getElementById("chromenav").src="images1/chromeNav3.png";
	}
	currentMessDeck = request;
}

function switchShop(request)
{
	var ele = document.getElementById(request);
	var currentEle = document.getElementById(currentShop);
	var currentNav = request + "Nav";
	var colorId = document.getElementById(currentNav);
	var oldNav = currentShop + "Nav";
	var oldColorId = document.getElementById(oldNav);
	if(currentShop != request)
	{
		ele.style.display = "block";
		currentEle.style.display = "none";
		oldColorId.style.color = "black";
		colorId.style.color = "#0066FF";
	}
	else
	{
		ele.style.display = "block";
	}
	currentShop = request;
}

function switchShopTab(request)
{
	var ele = document.getElementById(request);
	var currentEle = document.getElementById(currentShopTab);
	var currentNav = request + "Nav";
	var colorId = document.getElementById(currentNav);
	var oldNav = currentShopTab + "Nav";
	var oldColorId = document.getElementById(oldNav);
	if(currentShopTab != request)
	{
		ele.style.display = "block";
		currentEle.style.display = "none";
		oldColorId.style.color = "black";
		colorId.style.color = "#0066FF";
	}
	else
	{
		ele.style.display = "block";
	}
	currentShopTab = request;
}

//function on roll over
function move_in(img_name,img_src) 
{
	document[img_name].src=img_src;
}
//function on roll out
function move_out(img_name,img_src) 
{
	document[img_name].src=img_src;
}

function submitform(myform)
{
	if(document.getElementById(myform).onsubmit())
	{	
		document.getElementById(myform).submit();
	}
}

function toggle1(name1)
{
	var ele = document.getElementById(name1);
	
	if(ele.style.display == "none")
	{
		ele.style.display = "block";
	}
	else
	{
		ele.style.display = "none";
	}
}

//Toggles One item
//set the display styles of divs between visible and non-visible
function toggle(name1, name2) 
{
	var ele = document.getElementById(name1);
	var ele2 = document.getElementById(name2);
	
	ele.style.display = "none";
	ele2.style.display = "block";
}

function checkLogin(userName, password)
{
	//Warning message
	msg = "";
	if(password.length < 5 || userName.length < 5)
	{
		msg = "your username or password are too short";
	}
	//there is no username
	 if(userName.length == 0)
		msg = "username cannot be empty";
	//there is no password
	if(password.length == 0)
		msg = "password cannot be empty";
	//there is no password or username
	if(password.length == 0 & userName.length == 0)
		msg = "username and password cannot be empty";
		
	
	//there was no error
	if(msg == "")
	{
        msg = "";
		return true;
	}
    else
	{
        alert("Warning: " + msg + ".");
		return false;
	}

}


function checkFreeSignUp(username, password, password2, firstName, lastName, dob, email, address, suburb, phone, state, userNameTaken, userId, emailInvaild, emailTaken, postcode)
{
	 //msg 1 is to set the empty error msgs while msg2 is more related to formating 
	  var msg =new Array(); 
	  var msg2 = new Array();
	  counter = 0;
	  counter2 = 0;
	  dateFormat: false;
	  txt = "You must have a ";
	  //check if the following boxes are empty
	  
	 if(username.length < 6 && username.length != 0)
	 {
		msg2[counter2] = "\n \t \t Usernames must have at least 6 characters ";
		counter2 = counter2 + 1;
	 }
	  
	if(password.length < 6 && password.length != 0)
	 {
		msg2[counter2] = "\n \t \t Passwords must have at least 6 characters ";
		counter2 = counter2 + 1;
	 }
	  
	  if(userNameTaken.length != 0)
	  {
		msg2[counter2] = "\n \t \t Your Chosen Username is Already Taken ";
		counter2 = counter2 + 1;
	  }
	  
	  if(emailTaken.length != 0)
	  {
		msg2[counter2] = "\n \t \t Your Email Address is Already Used on Another Account. ";
		counter2 = counter2 + 1;
	  }
	  
	  if(emailInvaild.length != 0)
	  {
		msg2[counter2] = "\n \t \t Your Email Could not be reached. ";
		counter2 = counter2 + 1;
	  }
	  
	  
	  if(userId.length != 0)
	  {
		msg2[counter2] = "\n \t \t You must log out of the current account before making another ";
		counter2 = counter2 + 1;
	  }
	  
	   if(postcode.length == 0)
	 {
		msg[counter] = "postcode"; 
		counter = counter + 1;
	 }
	  
	  
	 if(username.length == 0)
	 {
		msg[counter] = "username"; 
		counter = counter + 1;
	 }
	 if(firstName.length == 0)
	 {
		msg[counter] = "first name"; 
		counter = counter + 1;
	 }
	 if(lastName.length == 0)
	 {
		msg[counter] = "last name"; 
		counter = counter + 1;
	 }
	 if(dob.length == 0)
	 {
		msg[counter] = "date of birth";
		counter = counter + 1;
	 }
	 if(email.length == 0)
	 {
		msg[counter] = "email address";
		counter = counter + 1;
	 }
	 if(password.length == 0)
	 {
		msg[counter] = "password";
		counter = counter + 1;
	 }
	 if(address.length == 0)
	 {
		msg[counter] = "address";
		counter = counter + 1;
	 }
	 if(suburb.length == 0)
	 {
		msg[counter] = "suburb";
		counter = counter + 1;
	 }
	 if(phone.length == 0)
	 {
		msg[counter] = "phone number";
		counter = counter + 1;
	 }
	 if(password2 != password)
	 {
		msg2[counter2] = "\n \t \t Your Passwords Do Not Match! ";
		counter2 = counter2 + 1;
	 }
	if(email.length != 0) 
	{
		var emailAddress = document.forms["signUpFree"]["email"].value;
		var atpos= emailAddress.indexOf("@");
		var dotpos= emailAddress.lastIndexOf(".");
		
		if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= emailAddress.length)
		{
			msg2[counter2] = "\n \t \t Your email address: " + email + " is not vaild!";
			counter2 = counter2 + 1;
		}
	}
	if(dob.length != 0)
	{
		//is the dob in the correct format....eg 4 numbers before the 1st dash between 0-9
		if(dob.match(/^[0-9]{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])/))
		{
			
			//i then spilt the year up to ensure that a invaild comb is made
			var yearfield=dob.split("-")[0];
			var monthfield=dob.split("-")[1];
			var dayfield=dob.split("-")[2];
			//make a date with my inputs if any of them are null it means the data is invaild.
			var dayobj = new Date(yearfield, monthfield-1, dayfield)
			if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
			
			if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
			{
				msg2[counter2] = "\n \t \t The DOB entered: " + dob + " is not in the correct format!. Invalid Day, Month, or Year Detected! ";
				counter2 = counter2 + 1;
			}
			
				//to see if the user is over 18
				
				var currentDate=new Date();
				var day = currentDate.getDate();
				var month = currentDate.getMonth()  + 1;
				var year = currentDate.getFullYear();
				
				var age = (year - yearfield) - 1;
				
				
				if(monthfield  <=  month)
					age += 1;
					
				else if(monthfield == month && dayfield <= day)
					age += 1;
				
				
				if(age < 18)
				{
					msg2[counter2] = "\n \t \t You must be 18 to sign up to become a member ";
					counter2 = counter2 + 1;
				}
				
			
		}
		else
		{
			msg2[counter2] = "\n \t \t The DOB entered: " + dob + " is not in the correct format.";
			counter2 = counter2 + 1;
		}
	}
	
	var checkFound = false;
	if (document.getElementById('mychk[]').checked)
	{
		checkFound = true;
	}
	
	if (checkFound != true) 
	{
		msg2[counter2] = "\n \t \t You must agree to the Terms and Conditions of the Website! ";
		counter2 = counter2 + 1;
	}
	if(msg.length == 0 && msg2.length == 0)
	{
       return true; 
	}
    else
	{
		for(i = 0; i < msg.length ; i++)
		{
			if( i + 1 != msg.length)
				txt += (msg[i] + ", ");
			else
				txt += (msg[i] + ".");
		}
		if(msg.length != 0 && msg2.length != 0)
		{
			txt += "\n \n \t Please also Note that:"
		}
		else if(msg2.length != 0 && msg.length == 0)
		{
			txt = "";
			
		}
		for (j = 0; j < msg2.length; j++)
		{
			txt += (msg2[j]);
		}
		alert("Warning: " + txt);
		return false;
	}
	 
}

function checkPaidedSignUp(username, password, password2, firstName, lastName, dob, email, address, suburb, phone, state, userNameTaken, userId, emailInvaild, emailTaken, postcode)
{
	 //msg 1 is to set the empty error msgs while msg2 is more related to formating 
	  var msg =new Array(); 
	  var msg2 = new Array();
	  counter = 0;
	  counter2 = 0;
	  dateFormat: false;
	  txt = "You must have a ";
	  //check if the following boxes are empty
	  
	  
	  
	 if(username.length < 6 && username.length != 0)
	 {
		msg2[counter2] = "\n \t \t Usernames must have at least 6 characters ";
		counter2 = counter2 + 1;
	 }
	  
	if(password.length < 6 && password.length != 0)
	 {
		msg2[counter2] = "\n \t \t Passwords must have at least 6 characters ";
		counter2 = counter2 + 1;
	 }
	 
	  if(userNameTaken.length != 0)
	  {
		msg2[counter2] = "\n \t \t Your Chosen Username is Already Taken ";
		counter2 = counter2 + 1;
	  }
	  
	  if(emailTaken.length != 0)
	  {
		msg2[counter2] = "\n \t \t Your Email Address is Already Used on Another Account. ";
		counter2 = counter2 + 1;
	  }
	  
	  if(emailInvaild.length != 0)
	  {
		msg2[counter2] = "\n \t \t Your Email Could not be reached. ";
		counter2 = counter2 + 1;
	  }
	  
	  
	  if(userId.length != 0)
	  {
		msg2[counter2] = "\n \t \t You must log out of the current account before making another ";
		counter2 = counter2 + 1;
	  }
	  
	 if(username.length == 0)
	 {
		msg[counter] = "username"; 
		counter = counter + 1;
	 }
	 if(postcode.length == 0)
	 {
		msg[counter] = "postcode"; 
		counter = counter + 1;
	 }
	 if(firstName.length == 0)
	 {
		msg[counter] = "first name"; 
		counter = counter + 1;
	 }
	 if(lastName.length == 0)
	 {
		msg[counter] = "last name"; 
		counter = counter + 1;
	 }
	 if(dob.length == 0)
	 {
		msg[counter] = "date of birth";
		counter = counter + 1;
	 }
	 if(email.length == 0)
	 {
		msg[counter] = "email address";
		counter = counter + 1;
	 }
	 if(password.length == 0)
	 {
		msg[counter] = "password";
		counter = counter + 1;
	 }
	 if(address.length == 0)
	 {
		msg[counter] = "address";
		counter = counter + 1;
	 }
	 if(suburb.length == 0)
	 {
		msg[counter] = "suburb";
		counter = counter + 1;
	 }
	 if(phone.length == 0)
	 {
		msg[counter] = "phone number";
		counter = counter + 1;
	 }
	 if(password2 != password)
	 {
		msg2[counter2] = "\n \t \t Your Passwords Do Not Match! ";
		counter2 = counter2 + 1;
	 }
	if(email.length != 0) 
	{
		var emailAddress = document.forms["signUpPaid"]["emailPaid"].value;
		var atpos= emailAddress.indexOf("@");
		var dotpos= emailAddress.lastIndexOf(".");
		
		if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= emailAddress.length)
		{
			msg2[counter2] = "\n \t \t Your email address: " + email + " is not vaild!";
			counter2 = counter2 + 1;
		}
	}
	if(dob.length != 0)
	{
		//is the dob in the correct format....eg 4 numbers before the 1st dash between 0-9
		if(dob.match(/^[0-9]{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])/))
		{
			
			//i then spilt the year up to ensure that a invaild comb is made
			var yearfield=dob.split("-")[0];
			var monthfield=dob.split("-")[1];
			var dayfield=dob.split("-")[2];
			//make a date with my inputs if any of them are null it means the data is invaild.
			var dayobj = new Date(yearfield, monthfield-1, dayfield)
			if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
			
			if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
			{
				msg2[counter2] = "\n \t \t The DOB entered: " + dob + " is not in the correct format!. Invalid Day, Month, or Year Detected! ";
				counter2 = counter2 + 1;
			}
			
				//to see if the user is over 18
				
				var currentDate=new Date();
				var day = currentDate.getDate();
				var month = currentDate.getMonth()  + 1;
				var year = currentDate.getFullYear();
				
				var age = (year - yearfield) - 1;
				
				
				if(monthfield  <=  month)
					age += 1;
					
				else if(monthfield == month && dayfield <= day)
					age += 1;
				
				
				if(age < 18)
				{
					msg2[counter2] = "\n \t \t You must be 18 to sign up to become a member ";
					counter2 = counter2 + 1;
				}
				
			
		}
		else
		{
			msg2[counter2] = "\n \t \t The DOB entered: " + dob + " is not in the correct format.";
			counter2 = counter2 + 1;
		}
	}

	var checkFound = false;
	if (document.getElementById('mychk2[]').checked)
	{
		checkFound = true;
	}
    
	
	if (checkFound != true) 
	{
		msg2[counter2] = "\n \t \t You must agree to the Terms and Conditions of the Website! ";
		counter2 = counter2 + 1;
	}
	if(msg.length == 0 && msg2.length == 0)
	{
       return true; 
	}
    else
	{
		for(i = 0; i < msg.length ; i++)
		{
			if( i + 1 != msg.length)
				txt += (msg[i] + ", ");
			else
				txt += (msg[i] + ".");
		}
		if(msg.length != 0 && msg2.length != 0)
		{
			txt += "\n \n \t Please also Note that:"
		}
		else if(msg2.length != 0 && msg.length == 0)
		{
			txt = "";
			
		}
		for (j = 0; j < msg2.length; j++)
		{
			txt += (msg2[j]);
		}
		alert("Warning: " + txt);
		return false;
	}
	 
}



//this function is used to print error msg from my php scripts on page load
function printError(msg)
{
	 alert("Warning: " + msg + ".");
}

function printSuccess(msg)
{
	 alert(msg);
}


//Animate

function doMove(fooObject) 
{
	 foo = document.getElementById(fooObject);
     foo.style.left = (foo.style.left+10)+'px'; // pseudo-property code: Move right by 10px
     setTimeout(doMove,20); // call doMove() in 20 msec
}


//Check to see if a correct format for the photo was chosen
//check on the upload page to ensure a photo was chosen
function checkPhoto(photo)
{
	var msg =new Array(); 
	var counter = 0;
	var txt = "";
	
	 if(photo.length == 0)
	 {
		msg[counter] = "You must pick a photo";
		counter = counter + 1;
		
	 }
	 else
	 {
		var fileName = document.forms["photoUpload"]["userPhoto"].value;
		dot = fileName.lastIndexOf(".");
		var fileType = fileName.substring(dot + 1);
		fileType = fileType.toLowerCase();
		
		if(fileType != "jpeg" && fileType != "gif" && fileType != "png" && fileType != "png" && fileType != "jpg")
		{
			msg[counter] = "The file type of " + fileType + " is not supported. We accept GIF, PNG or JPEG!";
			counter = counter + 1;
		}
		
		if(msg.length == 0)
		{
			return true; 
		}
		
	 }
	for (j = 0; j < msg.length; j++)
	{
		txt += (msg[j]);
	}
	 alert("Warning: " + txt);
	return false;

}

function checkChangePassword (oldPassword, newPassword, newPassword2)
{

	 var msg =new Array(); 
	 var msg2 = new Array();
	 counter = 0;
	 counter2 = 0;
     txt = "You must enter your ";
	 if(oldPassword.length == 0)
	 {
		msg[counter] = "Old Password"; 
		counter = counter + 1;
	 }
	 if(newPassword.length == 0 || newPassword2.length == 0)
	 {
		msg[counter] = "New Password and confirm it"; 
		counter = counter + 1;
	 }
	 if(newPassword2 != newPassword)
	 {
		msg2[counter2] = "\n \t \t Your Passwords Do Not Match! ";
		counter2 = counter2 + 1;
	 }
	 if(newPassword == oldPassword)
	 {
		msg2[counter2] = "\n \t \t Your new Password cannot be the same as your old! ";
		counter2 = counter2 + 1;
	 }
	 
	if(msg.length == 0 && msg2.length == 0)
	{
       return true; 
	}
    else
	{
		for(i = 0; i < msg.length ; i++)
		{
			if( i + 1 != msg.length)
				txt += (msg[i] + ", ");
			else
				txt += (msg[i] + ".");
		}
		if(msg.length != 0 && msg2.length != 0)
		{
			txt += "\n \n \t Please also Note that:"
		}
		else if(msg2.length != 0 && msg.length == 0)
		{
			txt = "";
			
		}
		for (j = 0; j < msg2.length; j++)
		{
			txt += (msg2[j]);
		}
		alert("Warning: " + txt);
		return false;
	}
}

function checkChangeUsername (userNameTaken, username, confirmUsername)
{
	var msg =new Array(); 
	var msg2 = new Array();
	counter = 0;
	counter2 = 0;
	txt = "You must enter your ";
	
	if(username != confirmUsername)
	{
		msg2[counter2] = "\n \t \t Your Usernames Do Not Match! ";
		counter2 = counter2 + 1;
	}
	if(username.length < 6 && username.length != 0)
	{
		msg2[counter2] = "\n \t \t Usernames must have at least 6 characters ";
		counter2 = counter2 + 1;
	}
	if(userNameTaken.length != 0)
	{
		msg2[counter2] = "\n \t \t Your Chosen Username is Already Taken ";
		counter2 = counter2 + 1;
	}
	if(username.length == 0 && confirmUsername.length != 0)
	{
		msg[counter] = "new username"; 
		counter = counter + 1;
	}
	else if(username.length == 0 || confirmUsername.length == 0)
	{
		msg[counter] = "New username and confirm it"; 
		counter = counter + 1;
	}
	if(msg.length == 0 && msg2.length == 0)
	{
       return true; 
	}
    else
	{
		for(i = 0; i < msg.length ; i++)
		{
			if( i + 1 != msg.length)
				txt += (msg[i] + ", ");
			else
				txt += (msg[i] + ".");
		}
		if(msg.length != 0 && msg2.length != 0)
		{
			txt += "\n \n \t Please also Note that:"
		}
		else if(msg2.length != 0 && msg.length == 0)
		{
			txt = "";
			
		}
		for (j = 0; j < msg2.length; j++)
		{
			txt += (msg2[j]);
		}
		alert("Warning: " + txt);
		return false;
	}
	
}

function checkTerms(currentTerms, NewTerms)
{
	 var msg =new Array(); 
	 var msg2 = new Array();
	 counter = 0;
	 counter2 = 0;
     txt = "You must enter ";
	 
	if(currentTerms == NewTerms)
	{
		msg2[counter2] = "\n \t \t The new terms and conditions must not be the same as the current terms and conditions";
		counter2 = counter2 + 1;
	}
	if(NewTerms.length == 0)
	{
		msg[counter] = "a set of new terms and conditons"
	}
	if(msg.length == 0 && msg2.length == 0)
	{
       return true; 
	}
    else
	{
		for(i = 0; i < msg.length ; i++)
		{
			if( i + 1 != msg.length)
				txt += (msg[i] + ", ");
			else
				txt += (msg[i] + ".");
		}
		if(msg.length != 0 && msg2.length != 0)
		{
			txt += "\n \n \t Please also Note that:"
		}
		else if(msg2.length != 0 && msg.length == 0)
		{
			txt = "";
			
		}
		for (j = 0; j < msg2.length; j++)
		{
			txt += (msg2[j]);
		}
		alert("Warning: " + txt);
		return false;
	}
	
}
function clear(id)
{
	document.getElementById(id).value = "";
}


function checkDelete()
{
	/*var checkFound = false;
	var msg = new Array(); 
	var counter = 0;
	txt = "You must have selected ";
	alert(document.getElementsByName.('mychk[]').length);
	return false;
	for (var k = 0; k < document.DeleteOldTerms.elements['mychk[]'].length; k++) 
	{
		if (document.DeleteOldTerms.elements['mychk[]'][k].checked == true)
		{
			checkFound = true;
		}
    }
	for (var h = 0; h < document.DeleteOldTerms.elements['mychk1[]'].length; h++) 
	{
		if (document.DeleteOldTerms.elements['mychk1[]'][h].checked == true)
		{
			checkFound = true;
		}
    }
	
	
	//No Checkbox was selected
	if (checkFound != true)
	{
		msg[counter] = "at least one Term and Conditions to Delete";
		counter = counter + 1;
	}
	if(msg.length == 0)
	{ */
		//Confirm Box
		var confirmDel = confirm("Are you sure you want to delete the selected Terms and Conditions?");
		if (confirmDel == true)
		{
			return true;
		}
		else
		{
			return false;
		}
	/*}
	else
	{
		txt += (msg[0] + "!");
		alert("Warning: " + txt);
		return false;
	}*/
}
function CheckSendEmail(subject, msg1)
{
	var msg =new Array(); 
	var msg2 = new Array();
	
	counter = 0;
	counter2 = 0;
	txt = "You Must Have ";
	var checkFound = false;
	var groupCheck = false;
	
	if(subject.length == 0)
	{
		msg[counter] = "A Subject";
		counter = counter + 1;
	}
	if(msg1.length == 0)
	{
		msg[counter] = "A Message to Send";
		counter = counter + 1;
	}
	for (var k=0; k < document.SendEmail.elements['recipients[]'].length; k++) 
	{
		if (document.SendEmail.elements['recipients[]'][k].checked == true)
		{
			checkFound = true;
		}
    }
	for (var k=0; k < document.SendEmail.elements['groupSelection'].length; k++) 
	{
		if (document.SendEmail.elements['groupSelection'][k].checked == true)
		{
			groupCheck = true;
		}
    }
	if(checkFound == false && groupCheck == false)
	{
		msg[counter] = "Recipients";
		counter = counter + 1;
	}
	if(checkFound && groupCheck)
	{
		msg2[counter2] = "\n \t \t You cannot manually select recipients if you have clicked a group selection."
		counter2 = counter2 + 1;
	}
	
	for(var i = 0; i < totalExtra; i++)
	{
		var attachment = "";
		var currentAttachment = "";
		currentAttachment += "Attachment";
		currentAttachment += i;
		attachment = document.forms["SendEmail"][currentAttachment].value
		if(attachment.length != 0)
		{
			//is what is typed after the last dot a acceptable file type. I also make it lower case just to be safe
			var fileName = document.forms["SendEmail"][currentAttachment].value;
			dot = fileName.lastIndexOf(".");
			var fileType = fileName.substring(dot + 1);
			fileType = fileType.toLowerCase();
			if(fileType == "exe")
			{
				msg2[counter2] = "\n \t \t The file type of " + fileType + " is not supported for email attachments.";
				counter2 = counter2 + 1;
			}
		}
	}
	
	if(msg.length == 0 && msg2.length == 0)
	{
       return true; 
	}
    else
	{
		for(i = 0; i < msg.length ; i++)
		{
			if( i + 1 != msg.length)
				txt += (msg[i] + ", ");
			else
				txt += (msg[i] + ".");
		}
		if(msg.length != 0 && msg2.length != 0)
		{
			txt += "\n \n \t Please also Note that:"
		}
		else if(msg2.length != 0 && msg.length == 0)
		{
			txt = "";
			
		}
		for (j = 0; j < msg2.length; j++)
		{
			txt += (msg2[j]);
		}
		alert("Warning: " + txt);
		return false;
	}
		
}
function groupRadioClear()
{
	
	for (var k=0; k < document.SendEmail.elements['groupSelection'].length; k++) 
	{
		if (document.SendEmail.elements['groupSelection'][k].checked == true)
		{
			document.SendEmail.elements['groupSelection'][k].checked = false;
		}
    }
}

function groupCheckBoxClear()
{
	
	for (var k=0; k < document.SendEmail.elements['recipients[]'].length; k++) 
	{
		if (document.SendEmail.elements['recipients[]'][k].checked == true)
		{
			document.SendEmail.elements['recipients[]'][k].checked = false;
		}
    }
}


$(
function()
{
		// Get the add new upload link.
		var jAddNewUpload = $( "#add-file-upload" );
 
		// Hook up the click event.
		jAddNewUpload.attr( "href", "javascript:void( 0 )" ).click(function( objEvent )
		{
			AddNewUpload();
 
			// Prevent the default action.
			objEvent.preventDefault();
			return( false );
		}
	);
 
}
)
// This adds a new file upload to the form.
function AddNewUpload()
{
	// Get a reference to the upload container.
	var jFilesContainer = $( "#extra" );
 
	// Get the file upload template.
	var jUploadTemplate = $( "#element-templates div.row" );
	var jUpload = jUploadTemplate.clone();
	var strNewHTML = jUpload.html();
 
	var intNewFileCount = (jFilesContainer.find( "div.row" ).length + 1);
 
	// Set the proper ID.
	jUpload.attr( "id", ("Attachment" + intNewFileCount) );
 
	//Replace the values.
	strNewHTML = strNewHTML
	.replace(
	new RegExp( "::FIELD2::", "i" ),
	intNewFileCount
	)
	.replace(
	new RegExp( "::FIELD3::", "i" ),
	("Attachment" + intNewFileCount)
	)
	;
 
	// Now that we have the new HTML, we can replace the
	// HTML of our new upload element.
	jUpload.html( strNewHTML );
	 
	// At this point, we have a totally intialized file upload
	// node. Let's attach it to the DOM.
	jFilesContainer.append( jUpload );
	totalExtra++;
	addAttachmentTotal();
	
}

function addAttachmentTotal()
{
	document.forms["SendEmail"]["extraAttachments"].value = totalExtra;
}



function addParagraphTotal()
{
	document.forms["CreatePage"]["numberParagraphs"].value = totalParagraph;
}

function addImageTotal()
{
	document.forms["CreatePage"]["numberImages"].value = totalImages;
}


function checkUpdatePrice(newPrice)
{
	var msg =new Array();
	var txt = "";	
	counter1 = 0;
	
	if(newPrice.length == 0)
	{
		msg = "You must enter a new price"
	}
	
	if(newPrice == ".")
	{
		msg = "Input is not a number"
	}
	
	if(IsNumeric(newPrice) == false)
	{
		msg = "Input is not a number"
	}
	if(msg.length == 0)
	{
		return true; 
	}
	alert("Warning: " + msg);
	return false;
	
}

function checkUpdateGroup(newPrice)
{
	var msg =new Array();
	var txt = "";	
	counter1 = 0;
	
	if(newPrice.length == 0)
	{
		msg = "You must enter a new rate"
	}
	
	if(newPrice == ".")
	{
		msg = "Input is not a number"
	}
	
	if(IsNumeric(newPrice) == false)
	{
		msg = "Input is not a number"
	}
	if(msg.length == 0)
	{
		return true; 
	}
	alert("Warning: " + msg);
	return false;
	
}


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 checkCreatePrice(type, databaseValue, price)
{
	var msg =new Array();
	var txt = "You must input ";	
	counter1 = 0;
	
	if(type.length == 0)
	{
		msg[counter1] = "A Membership Type";
		counter1++;
	}
	
	if(databaseValue.length == 0)
	{
		msg[counter1] = "A Database Value";
		counter1++;
	}
	
	if(price.length == 0)
	{
		msg[counter1] = "A Membership Price";
		counter1++;
	}
	if(price == ".")
	{
		msg[counter1] = "A Membership Price";
		counter1++;
	}
	
	if(IsNumeric(price) == false)
	{
		msg[counter1] = "A Membership Price"
		counter1++;
	}
	
	if(msg.length == 0)
	{
       return true; 
	}
    else
	{
		for(i = 0; i < msg.length ; i++)
		{
			if( i + 1 != msg.length)
				txt += (msg[i] + ", ");
			else
				txt += (msg[i] + ".");
		}
		alert("Warning: " + txt);
		return false;
	}
		
}

function checkDeletePrices()
{
	
	var priceCheck = false;
	var msg = "";
	
	for (var k=0; k < document.deletePrices.elements['allPrices[]'].length; k++) 
	{
		if (document.deletePrices.elements['allPrices[]'][k].checked == true)
		{
			priceCheck = true;
		}
    }
	if(priceCheck == false)
	{
		msg = "You must select at least one item to delete";
	}
	if(msg.length == 0)
	{
		var confirmDel = confirm("Are you sure you want to delete the selected Prices?");
		if (confirmDel == true)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
    else
	{
		alert("Warning: " + msg);
		return false;
	}
	
	
	
}

function AddNewParagraph()
{
	// Get a reference to the upload container.
	var jFilesContainer = $( "#extraParagraphs" );
 
	// Get the file upload template.
	var jUploadTemplate = $( "#paragraph-templates div.row1" );
	var jUpload = jUploadTemplate.clone();
	var strNewHTML = jUpload.html();
 
	var intNewFileCount = (jFilesContainer.find( "div.row1" ).length + 1);
 
	// Set the proper ID.
	jUpload.attr( "id", ("Paragraph" + intNewFileCount) );
 
	//Replace the values.
	strNewHTML = strNewHTML
	.replace(
	new RegExp( "::FIELD2::", "i" ),
	intNewFileCount
	)
	.replace(
	new RegExp( "::FIELD3::", "i" ),
	("Paragraph" + intNewFileCount)
	)
	;
 
	// Now that we have the new HTML, we can replace the
	// HTML of our new upload element.
	jUpload.html( strNewHTML );
	 
	// At this point, we have a totally intialized file upload
	// node. Let's attach it to the DOM.
	jFilesContainer.append( jUpload );
	totalParagraph++;
	addParagraphTotal();
	
}

$(
function()
{
		// Get the add new upload link.
		var jAddNewUpload = $( "#add-paragraph" );
 
		// Hook up the click event.
		jAddNewUpload.attr( "href", "javascript:void( 0 )" ).click(function( objEvent )
		{
			AddNewParagraph();
 
			// Prevent the default action.
			objEvent.preventDefault();
			return( false );
		}
	);
 
}
)


function remove(type)
{
	
	if(type == "paragraph")
	{
		if(totalParagraph != 1)
		{
			totalParagraph--;
			addParagraphTotal();
			childDiv = "Paragraph" + totalParagraph;
			var child = document.getElementById(childDiv);
			var parent = document.getElementById("extraParagraphs");
			
			parent.removeChild(child);
		}
	}
	if(type == "image")
	{
		if(totalImages != 1)
		{
			totalImages--;
			addImageTotal();
			childDiv = "Image" + totalImages;
			var child = document.getElementById(childDiv);
			var parent = document.getElementById("extraImages");
			parent.removeChild(child);
			
			childDiv = "LargeImage" + totalImages;
			var child = document.getElementById(childDiv);
			var parent = document.getElementById("extraImages");
		}
	}
}


$(
function()
{
		var jAddNewUpload = $( "#add-image" );
 
		// Hook up the click event.
		jAddNewUpload.attr( "href", "javascript:void( 0 )" ).click(function( objEvent )
		{
			AddNewImage();
 
			// Prevent the default action.
			objEvent.preventDefault();
			return( false );
		}
	);
 
}
)

function AddNewImage()
{
	if(totalImages != 3)
	{
		// Get a reference to the upload container.
		var jFilesContainer = $( "#extraImages" );
	 
		// Get the file upload template.
		var jUploadTemplate = $( "#images-templates div.row2" );
		var jUpload = jUploadTemplate.clone();
		var strNewHTML = jUpload.html();
	 
		var intNewFileCount = (jFilesContainer.find( "div.row2" ).length + 1);
	 
		// Set the proper ID.
		jUpload.attr( "id", ("Image" + intNewFileCount) );
	 
		//Replace the values.
		strNewHTML = strNewHTML
		.replace(
		new RegExp( "::FIELD2::", "i" ),
		intNewFileCount
		)
		.replace(
		new RegExp( "::FIELD3::", "i" ),
		("Image" + intNewFileCount)
		)
		.replace(
		new RegExp( "::FIELD4::", "i" ),
		("LargeImage" + intNewFileCount)
		)
		;
	 
		// Now that we have the new HTML, we can replace the
		// HTML of our new upload element.
		jUpload.html( strNewHTML );
		 
		// At this point, we have a totally intialized file upload
		// node. Let's attach it to the DOM.
		jFilesContainer.append( jUpload );
		totalImages++;
		addImageTotal();
	}
	
}

function CheckCreatepage(title, META, fileName, defaultParagraph)
{
	var msg =new Array(); 
	var msg2 = new Array();
	var emptyPara = false;
	counter1 = 0;
	counter2 = 0;
	txt = "The new page must have ";
	
	if(title.length == 0)
	{
		msg[counter1] = "a Page Title";
		counter1++;
	}
	if(META.length == 0)
	{
		msg[counter1] = "Meta data key terms";
		counter1++;
	}
	if(fileName.length == 0)
	{
		msg[counter1] = " a file name";
		counter1++;
	}
	if(fileName.lastIndexOf(".") != -1)
	{
		msg2[counter2] = " A Invaild File Name Has Been Given";
		counter2++;
	}
	if(defaultParagraph.length == 0)
	{
		msg[counter1] = "Introduction Paragraph";
		counter1++;
	}
	
	if(totalParagraph != 1)
	{
		var currentPara;
		var testPara;
		for(i = 1; i < totalParagraph; i++)
		{
			currentPara = "";
			currentPara = "Paragraph" + i;
			testPara = document.forms["CreatePage"][currentPara].value;	
			if(testPara.length == 0)
			{
				emptyPara = true;
			}
		}
	}
	if(emptyPara == true)
	{
		msg2[counter2] = " \n \n \t A Empty Paragraph was found please correct this!";
		counter2++;
	}
	
	var invaildFile = false;
	var aloneLarge = false;
	
	for(i = 0; i < totalImages; i++)
	{	
		var currentImage = "";
		currentImage = "Image" + i;
		var fileName = document.forms["CreatePage"][currentImage].value;
		
		if(fileName.length != 0)
		{
			dot = fileName.lastIndexOf(".");
			var fileType = fileName.substring(dot + 1);
			fileType = fileType.toLowerCase();
			
			if(fileType != "jpeg" && fileType != "gif" && fileType != "png" && fileType != "png" && fileType != "jpg")
			{
				invaildFile = true;
			}
			
			var currentImage = "";
			currentImage = "LargeImage" + i;
			fileName = document.forms["CreatePage"][currentImage].value;
			dot = fileName.lastIndexOf(".");
			fileType = fileName.substring(dot + 1);
			fileType = fileType.toLowerCase();
			
			
		}
		if (fileName.length == 0 && document.forms["CreatePage"]["LargeImage" + i].value.length != 0)
		{
			aloneLarge = true;
		}
	}
	
	if(invaildFile == true)
	{
		msg2[counter2] = " \n \n \t A Invaild File was found please correct this!";
		counter2++;
	}
	
	if(aloneLarge == true)
	{
		msg2[counter2] = " \n \n \t A Large Image File was found but no Thumbnail!  please correct this!";
		counter2++;
	}
	
	if(msg.length == 0 && msg2.length == 0)
	{
       return true; 
	}
    else
	{
		for(i = 0; i < msg.length ; i++)
		{
			if( i + 1 != msg.length)
				txt += (msg[i] + ", ");
			else
				txt += (msg[i] + ".");
		}
		if(msg.length != 0 && msg2.length != 0)
		{
			txt += "\n \n \t Please also Note that:"
		}
		else if(msg2.length != 0 && msg.length == 0)
		{
			txt = "";
			
		}
		for (j = 0; j < msg2.length; j++)
		{
			txt += (msg2[j]);
		}
		alert("Warning: " + txt);
		return false;
	}
	
}

function checkLink(link)
{
	var msg = "";
	
	if(link.length == 0)
	{
		msg = "Link Cannot be empty";
		
	}
	if(msg.length == 0)
	{
		return true;
	}
	else
	{
		alert("Warning: " + msg);
		return false;
	}
} 

function CheckUsernameSearch(link)
{
	var msg = "";
	
	if(link.length == 0)
	{
		msg = "Username Cannot Be Empty.";
		
	}
	if(msg.length == 0)
	{
		return true;
	}
	else
	{
		alert("Warning: " + msg);
		return false;
	}
} 


function CheckNameSearch(first, last)
{
	var msg = "";
	if(first.length == 0 && last.length == 0)
	{
		msg = "First Name and Last Name Cannot Be Empty.";
	}
	else if(first.length == 0)
	{
		msg = "First Name Cannot Be Empty.";
		
	}
	else if(last.length == 0)
	{
		msg = "Last Name Cannot Be Empty.";
		
	}
	if(msg.length == 0)
	{
		return true;
	}
	else
	{
		alert("Warning: " + msg);
		return false;
	}
}

function checkChangeEmail(emailTaken, emailInvalid, oldEmail, email)
{
	//msg 1 is to set the empty error msgs while msg2 is more related to formating 
	var msg =new Array(); 
	var msg2 = new Array();
	counter = 0;
	counter2 = 0;
	txt = "You must have a ";
	//check if the following boxes are empty

	if(emailTaken.length != 0)
	{
		msg2[counter2] = "\n \t \t Your Email Address is Already Used on Another Account. ";
		counter2 = counter2 + 1;
	}

	if(emailInvaild.length != 0)
	{
		msg2[counter2] = "\n \t \t Your Email Could not be reached. ";
		counter2 = counter2 + 1;
	}
	if(oldEmail.length == 0)
	{
		msg[counter] = "Old Email"; 
		counter = counter + 1;
	}
	if(email.length == 0)
	{
		msg[counter] = "New Email"; 
		counter = counter + 1;
	}

	if(email.length != 0) 
	{
		var emailAddress = document.forms["signUpPaid"]["emailPaid"].value;
		var atpos= emailAddress.indexOf("@");
		var dotpos= emailAddress.lastIndexOf(".");

		if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= emailAddress.length)
		{
			msg2[counter2] = "\n \t \t Your email address: " + email + " is not vaild!";
			counter2 = counter2 + 1;
		}
	}
	if(msg.length == 0 && msg2.length == 0)
	{
		return true; 
	}
	else
	{
		for(i = 0; i < msg.length ; i++)
		{
			if( i + 1 != msg.length)
				txt += (msg[i] + ", ");
			else
				txt += (msg[i] + ".");
		}
		if(msg.length != 0 && msg2.length != 0)
		{
			txt += "\n \n \t Please also Note that:"
		}
		else if(msg2.length != 0 && msg.length == 0)
		{	
			txt = "";
		}
		for (j = 0; j < msg2.length; j++)
		{
			txt += (msg2[j]);
		}
		alert("Warning: " + txt);
		return false;
	}
}

function checkAddress(street, suburb, postcode)
{
	//msg 1 is to set the empty error msgs while msg2 is more related to formating 
	var msg =new Array(); 
	var msg2 = new Array();
	counter = 0;
	counter2 = 0;
	txt = "You must have a ";
	//check if the following boxes are empty

	if(street.length == 0)
	{
		msg[counter] = "street";
		counter = counter + 1;
	}
	if(suburb.length == 0)
	{
		msg[counter] = "suburb";
		counter = counter + 1;
	}
	if(postcode.length == 0)
	{
		msg[counter] = "postcode";
		counter = counter + 1;
	}
	if(msg.length == 0 && msg2.length == 0)
	{
		return true; 
	}
	else
	{
		for(i = 0; i < msg.length ; i++)
		{
			if( i + 1 != msg.length)
				txt += (msg[i] + ", ");
			else
				txt += (msg[i] + ".");
		}
		if(msg.length != 0 && msg2.length != 0)
		{
			txt += "\n \n \t Please also Note that:"
		}
		else if(msg2.length != 0 && msg.length == 0)
		{
			txt = "";
		}
		for (j = 0; j < msg2.length; j++)
		{
			txt += (msg2[j]);
		}
			alert("Warning: " + txt);
			return false;
	}
}

function checkAddEvent(date, where, whatsOn, time)
{
	var msg =new Array();
	counter = 0;
	txt = "You must have enter a ";

	if(date.length == 0)
	{
		msg[counter] = "date of event";
		counter = counter + 1;
	}
	else
	{
		if(date.match(/^[0-9]{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])/))
		{	
				
			//i then spilt the year up to ensure that a invaild comb is made
			var yearfield=date.split("-")[0];
			var monthfield=date.split("-")[1];
			var dayfield=date.split("-")[2];
			//make a date with my inputs if any of them are null it means the data is invaild.
			var dayobj = new Date(yearfield, monthfield-1, dayfield)
			if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
			
			if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
			{
				msg[counter] = "\n \t \t The Date entered: " + date + " is not in the correct format!. Invalid Day, Month, or Year Detected! ";
				counter = counter + 1;
			}
		}
		else
		{
			
			msg[counter] = "vaild date of the event";
			counter = counter + 1;
			
		}
	}
	if(where.length == 0)
	{
		msg[counter] = "location";
		counter = counter + 1;
	}
	if(whatsOn.length == 0)
	{
		msg[counter] = "sentence about the event";
		counter = counter + 1;
	}
	if(time.length == 0)
	{
		msg[counter] = "event start time";
		counter = counter + 1;
	}
	if(msg.length == 0)
	{
       return true; 
	}
    else
	{
		for(i = 0; i < msg.length ; i++)
		{
			if( i + 1 != msg.length)
				txt += (msg[i] + ", ");
			else
				txt += (msg[i] + ".");
		}
		alert("Warning: " + txt);
		return false;
	}
}

function checkAddRecentEvent(recentTitles, recentText)
{
	var msg =new Array();
	counter = 0;
	txt = "You must have enter a ";
	
	if(recentTitles.length == 0)
	{
		msg[counter] = "title for the recent event";
		counter = counter + 1;
	}
	if(recentText.length == 0)
	{
		msg[counter] = "information about recent event";
		counter = counter + 1;
	}
	if(msg.length == 0)
	{
       return true; 
	}
    else
	{
		for(i = 0; i < msg.length ; i++)
		{
			if( i + 1 != msg.length)
				txt += (msg[i] + ", ");
			else
				txt += (msg[i] + ".");
		}
		alert("Warning: " + txt);
		return false;
	}
	
}

function checkComment(comment)
{
	msg = "";
	if(comment.length == 0)
	{
		msg = "You cannot post a empty comment!"
	}
	
	if(msg.length == 0)
	{
		return true; 
	}
	 alert("Warning: " + msg);
	return false;
}

function checkPDFUpload(title, file)
{
	var msg =new Array();
	counter = 0;
	txt = "you must enter a vaild";
	if(title.length == 0)
	{
		msg[counter] = " Issue Title"
		counter = counter + 1;
	}
	if(file.length == 0)
	{
		msg[counter] = "PDF file"
		counter = counter + 1;
	}
	if(file.length != 0)
	{
		dot = file.lastIndexOf(".");
		var fileType = file.substring(dot + 1);
		fileType = fileType.toLowerCase();
		if(fileType != "pdf")
		{
			msg[counter] = " PDF file";
			counter = counter + 1;
		}
	}
	if(msg.length == 0)
	{
       return true; 
	}
    else
	{
		for(i = 0; i < msg.length ; i++)
		{
			if( i + 1 != msg.length)
				txt += (msg[i] + ", ");
			else
				txt += (msg[i] + ".");
		}
		alert("Warning: " + txt);
		return false;
	}
	
}

function checkSearchTerm(term)
{
	var msg =new Array();
	counter = 0;
	txt = "you must enter a vaild ";
	checkFound = false;
	
	if(term.length == 0)
	{
		msg[counter] = "search term"
		counter++;
	}
	
	for (var k=0; k < document.addSearchTerms.elements['pages[]'].length; k++) 
	{
		if (document.addSearchTerms.elements['pages[]'][k].checked == true)
		{
			checkFound = true;
		}
    }
	
	if(checkFound == false)
	{
		msg[counter] = "term link"
		counter++;
	}
	
	if(msg.length == 0)
	{
       return true; 
	}
    else
	{
		for(i = 0; i < msg.length ; i++)
		{
			if( i + 1 != msg.length)
				txt += (msg[i] + ", ");
			else
				txt += (msg[i] + ".");
		}
		alert("Warning: " + txt);
		return false;
	}
}


function checkPaypalBox(request)
{
	if(request != "")
	{
		return true;
	}
	else
	{
		alert("Warning: The code box must not be empty.");
		return false;
	}
}

function checkSearch(query)
{
	if(query != "")
	{
		return true;
	}
	else
	{
		alert("Warning: The Search Term Box Must Not Be Empty.");
		return false;
	}
}

function checkSponsor(query)
{
	if(query != "")
	{
		return true;
	}
	else
	{
		alert("Warning: The Sponsor Name Box Must Not Be Empty.");
		return false;
	}
}

function checkSponsor(query)
{
	if(query != "")
	{
		return true;
	}
	else
	{
		alert("Warning: The Sponsor Name Box Must Not Be Empty.");
		return false;
	}
}

function CheckCategory(query)
{
	if(query != "")
	{
		return true;
	}
	else
	{
		alert("Warning: The Category Box Must Not Be Empty.");
		return false;
	}


}

function checkPhoto2(photo, photo2)
{
	var msg =new Array(); 
	var check = false;
	var counter = 0;
	var txt = "";
	
	 if(photo.length == 0 || photo2.length == 0)
	 {
		msg[counter] = "You must pick a photo";
		counter = counter + 1;
		
	 }
	 else
	 {
		var fileName = photo;
		dot = fileName.lastIndexOf(".");
		var fileType = fileName.substring(dot + 1);
		fileType = fileType.toLowerCase();
		
		if(fileType != "jpeg" && fileType != "gif" && fileType != "png" && fileType != "png" && fileType != "jpg")
		{
			msg[counter] = "The file type of " + fileType + " is not supported. We accept GIF, PNG or JPEG!";
			counter = counter + 1;
			check = true;
		}
		
		fileName = photo2;
		dot = fileName.lastIndexOf(".");
		fileType = fileName.substring(dot + 1);
		fileType = fileType.toLowerCase();
		if(check == false)
		{
			if(fileType != "jpeg" && fileType != "gif" && fileType != "png" && fileType != "png" && fileType != "jpg")
			{
				
				msg[counter] = "The file type of " + fileType + " is not supported. We accept GIF, PNG or JPEG!";
				counter = counter + 1;
			}
		}
			
		if(msg.length == 0)
		{
			return true; 
		}
		
	 }
	for (j = 0; j < msg.length; j++)
	{
		txt += (msg[j]);
	}
	 alert("Warning: " + txt);
	return false;

}

function checkNewPassword(password, password2, dob, email)
{
	var msg = new Array(); 
	var msg2 = new Array();
	counter = 0;
	counter2 = 0;
	dateFormat: false;
	txt = "You must have a ";

	if(password.length < 6 && password.length != 0)
	{
		msg2[counter2] = "\n \t \t Passwords must have at least 6 characters ";
		counter2 = counter2 + 1;
	}

	if(dob.length == 0)
	{
		msg[counter] = "date of birth";
		counter = counter + 1;
	}
	
	if(email.length == 0)
	{
		msg[counter] = "email address";
		counter = counter + 1;
	}
	
	if(password.length == 0)
	{
		msg[counter] = "password";
		counter = counter + 1;
	}

	if(password2 != password)
	{
		msg2[counter2] = "\n \t \t Your Passwords Do Not Match! ";
		counter2 = counter2 + 1;
	}
	
	if(email.length != 0) 
	{
		var emailAddress = document.forms["resetPassword"]["email"].value;
		var atpos= emailAddress.indexOf("@");
		var dotpos= emailAddress.lastIndexOf(".");

		if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= emailAddress.length)
		{
			msg2[counter2] = "\n \t \t Your email address: " + email + " is not vaild!";
			counter2 = counter2 + 1;
		}
	}
	
	if(dob.length != 0)
	{
		//is the dob in the correct format....eg 4 numbers before the 1st dash between 0-9
		if(dob.match(/^[0-9]{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])/))
		{
			var yearfield=dob.split("-")[0];
			var monthfield=dob.split("-")[1];
			var dayfield=dob.split("-")[2];
			//make a date with my inputs if any of them are null it means the data is invaild.
			var dayobj = new Date(yearfield, monthfield-1, dayfield)
			if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
				if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
				{
					msg2[counter2] = "\n \t \t The DOB entered: " + dob + " is not in the correct format!. Invalid Day, Month, or Year Detected! ";
					counter2 = counter2 + 1;
				}

				var currentDate=new Date();
				var day = currentDate.getDate();
				var month = currentDate.getMonth()  + 1;
				var year = currentDate.getFullYear();

				var age = (year - yearfield) - 1;

				if(monthfield  <=  month)
					age += 1;
				else if(monthfield == month && dayfield <= day)
					age += 1;

				if(age < 18)
				{
					msg2[counter2] = "\n \t \t You must be 18 to sign up to become a member ";
					counter2 = counter2 + 1;
				}
		}
		else
		{
			msg2[counter2] = "\n \t \t The DOB entered: " + dob + " is not in the correct format.";
			counter2 = counter2 + 1;
		}
	}
    
	if(msg.length == 0 && msg2.length == 0)
	{
       return true; 
	}
    else
	{
		for(i = 0; i < msg.length ; i++)
		{
			if( i + 1 != msg.length)
				txt += (msg[i] + ", ");
			else
				txt += (msg[i] + ".");
		}
		if(msg.length != 0 && msg2.length != 0)
		{
			txt += "\n \n \t Please also Note that:"
		}
		else if(msg2.length != 0 && msg.length == 0)
		{
			txt = "";
			
		}
		for (j = 0; j < msg2.length; j++)
		{
			txt += (msg2[j]);
		}
		alert("Warning: " + txt);
		return false;
	}
}


function CheckAddItem(itemName, stock, itemIamge, price, itemDesc, fullPrice, discountPrice)
{
	var msg = new Array();
	var msg2 = new Array();
	counter = 0;
	counter2 = 0;
	var invaildFile = false;
	txt = "You a new item must have ";

	if(itemName.length == 0)
	{
		msg[counter] = "name";
		counter = counter + 1;
	}
	if(stock.length == 0)
	{
		msg[counter] = "stock amount";
		counter = counter + 1;
	}
	
	stock = Number(stock);
	if(isNaN(stock) || stock < 0)
	{
		msg2[counter2] = "\n \t \t The Stock Number entered: " + stock + " is not vaild.";
		counter2 = counter2 + 1;
	}
	
	if(itemIamge.length == 0)
	{
		msg[counter] = "image";
		counter = counter + 1;
	}
	if(price.length == 0)
	{
		msg[counter] = "price";
		counter = counter + 1;
	}
	if(itemDesc.length == 0)
	{
		msg[counter] = "description";
		counter = counter + 1;
	}
	if(fullPrice.length == 0)
	{
		msg[counter] = "full price paypal code";
		counter = counter + 1;
	}
	if(discountPrice.length == 0)
	{
		msg[counter] = "discount price paypal code";
		counter = counter + 1;
	}
	price = Number(price);

	if(isNaN(price) || price <= 0)
	{
		msg2[counter2] = "\n \t \t The Price entered: " + price + " is not vaild.";
		counter2 = counter2 + 1;
	}
	
	var fileName = itemIamge;
	dot = fileName.lastIndexOf(".");
	fileType = fileName.substring(dot + 1);
	fileType = fileType.toLowerCase();
		
	if(fileName.length != 0)
	{
		dot = fileName.lastIndexOf(".");
		var fileType = fileName.substring(dot + 1);
		fileType = fileType.toLowerCase();
		
		if(fileType != "jpeg" && fileType != "gif" && fileType != "png" && fileType != "png" && fileType != "jpg")
		{
			invaildFile = true;
		}		
	}
	
	if(invaildFile == true)
	{
		msg2[counter2] = " \n \t \t A Invaild File was found please correct this!";
		counter2++;
	}
	
	
	
	
	if(msg.length == 0 && msg2.length == 0)
	{
       return true; 
	}
    else
	{
		for(i = 0; i < msg.length ; i++)
		{
			if( i + 1 != msg.length)
				txt += (msg[i] + ", ");
			else
				txt += (msg[i] + ".");
		}
		if(msg.length != 0 && msg2.length != 0)
		{
			txt += "\n \n \t Please also Note that:"
		}
		else if(msg2.length != 0 && msg.length == 0)
		{
			txt = "";
			
		}
		for (j = 0; j < msg2.length; j++)
		{
			txt += (msg2[j]);
		}
		alert("Warning: " + txt);
		return false;
	}

}
   
