//Here we validate the Event form
function validateAddUser (theform)
{
	var error=0;
	
	if ((document.getElementById('username').value == null) || (document.getElementById('username').value == ''))
	{
		document.getElementById('usernameErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/warning.jpg" height="16" width="16" alt="icon" class="info"/>';
		error = 1;
	}
	else
	{
		document.getElementById('usernameErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/clear.jpg" height="16" width="16" alt="icon" class="info"/>';
	}		

	if (document.getElementById('name').value == null || document.getElementById('name').value == '')
	{
		document.getElementById('nameErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/warning.jpg" height="16" width="16" alt="icon" class="info"/>';
		error = 1;
	}
	else
	{
		document.getElementById('nameErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/clear.jpg" height="16" width="16" alt="icon" class="info"/>';
	}		

	if (document.getElementById('email').value == null || document.getElementById('email').value == '')
	{
		document.getElementById('emailErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/warning.jpg" height="16" width="16" alt="icon" class="info"/>';
		error = 1;
	}
	else if (emailcheck(document.getElementById('email').value)==false)
	{
		document.getElementById('emailErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/warning.jpg" height="16" width="16" alt="icon" class="info"/>';
		error = 1;
	}
	else
	{
		document.getElementById('emailErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/clear.jpg" height="16" width="16" alt="icon" class="info"/>';
	}
	
	if (document.getElementById('bio').value == null || document.getElementById('bio').value == '')
	{
		document.getElementById('bioErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/warning.jpg" height="16" width="16" alt="icon" class="info"/>';
		error = 1;
	}
	else
	{
		document.getElementById('bioErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/clear.jpg" height="16" width="16" alt="icon" class="info"/>';
	}

	if (document.getElementById('password').value == null || document.getElementById('password').value == '')
	{
		document.getElementById('passwordErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/warning.jpg" height="16" width="16" alt="icon" class="info"/>';
		error = 1;
	}
	else
	{
		document.getElementById('passwordErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/clear.jpg" height="16" width="16" alt="icon" class="info"/>';
	}

	if (document.getElementById('confpassword').value == null || document.getElementById('confpassword').value == '')
	{
		document.getElementById('confpasswordErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/warning.jpg" height="16" width="16" alt="icon" class="info"/>';
		error = 1;
	}
	else
	{
		document.getElementById('confpasswordErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/clear.jpg" height="16" width="16" alt="icon" class="info"/>';
	}
	
	if (document.getElementById('password').value != document.getElementById('confpassword').value)
	{
		error = 2;
	}
	
	//If there has been an error return false so form doesn't submit
	if (error==1)
	{
		alert("Please enter all the required information.");
		return false;
	}
	else if (error==2)
	{
		alert("Passwords do not match.");
		return false;
	}
	else
	{
		return true;
	}
}


function menu_goto( menuform )
{
	// Generated by thesitewizard Navigation Menu Wizard 2.2
	// Visit http://www.thesitewizard.com/ to get your own
	// customized navigation menu FREE!
	var baseurl = 'http://www.emiratesmac.com/eventreg/admin/' ;
	selecteditem = menuform.url.selectedIndex ;
	newurl = menuform.url.options[ selecteditem ].value ;
	if (newurl.length != 0)
	{
		location.href = baseurl + newurl ;
	}
}

//Here we validate the Event form
function validateEvent (theform)
{
	var error=0;
	
	if ((document.getElementById('title').value == null) || (document.getElementById('title').value == ''))
	{
		document.getElementById('titleErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/warning.jpg" height="16" width="16" alt="icon" class="info"/>';
		error = 1;
	}
	else
	{
		document.getElementById('titleErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/clear.jpg" height="16" width="16" alt="icon" class="info"/>';
	}		

	if (document.getElementById('date').value == null || document.getElementById('date').value == '')
	{
		document.getElementById('dateErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/warning.jpg" height="16" width="16" alt="icon" class="info"/>';
		error = 1;
	}
	else
	{
		document.getElementById('dateErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/clear.jpg" height="16" width="16" alt="icon" class="info"/>';
	}		

	if (document.getElementById('time').value == null || document.getElementById('time').value == '')
	{
		document.getElementById('timeErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/warning.jpg" height="16" width="16" alt="icon" class="info"/>';
		error = 1;
	}
	else
	{
		document.getElementById('timeErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/clear.jpg" height="16" width="16" alt="icon" class="info"/>';
	}
	
	if (document.getElementById('venue').value == null || document.getElementById('venue').value == '')
	{
		document.getElementById('venueErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/warning.jpg" height="16" width="16" alt="icon" class="info"/>';
		error = 1;
	}
	else
	{
		document.getElementById('venueErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/clear.jpg" height="16" width="16" alt="icon" class="info"/>';
	}

	if (document.getElementById('seats').value == null || document.getElementById('seats').value == '')
	{
		document.getElementById('seatsErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/warning.jpg" height="16" width="16" alt="icon" class="info"/>';
		error = 1;
	}
	else
	{
		document.getElementById('seatsErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/clear.jpg" height="16" width="16" alt="icon" class="info"/>';
	}

	if (document.getElementById('seatsmax').value == null || document.getElementById('seatsmax').value == '')
	{
		document.getElementById('seatsmaxErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/warning.jpg" height="16" width="16" alt="icon" class="info"/>';
		error = 1;
	}
	else
	{
		document.getElementById('seatsmaxErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/clear.jpg" height="16" width="16" alt="icon" class="info"/>';
	}	
	
	//If there has been an error return false so form doesn't submit
	if (error==1)
	{
		alert("Please enter all the required information.");
		return false;
	}
	else
	{
		return true;
	}
}

//Here we validate the Login form
function validateLogin (theform)
{
	var error=0;
	
	if ((document.getElementById('username').value == null) || (document.getElementById('username').value == ''))
	{
		document.getElementById('usernameErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/warning.jpg" height="16" width="16" alt="icon" class="info"/>';
		error = 1;
	}
	else
	{
		document.getElementById('usernameErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/clear.jpg" height="16" width="16" alt="icon" class="info"/>';
	}		

	if (document.getElementById('password').value == null || document.getElementById('password').value == '')
	{
		document.getElementById('passwordErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/warning.jpg" height="16" width="16" alt="icon" class="info"/>';
		error = 1;
	}
	else
	{
		document.getElementById('passwordErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/clear.jpg" height="16" width="16" alt="icon" class="info"/>';
	}		

	//If there has been an error return false so form doesn't submit
	if (error==1)
	{
		alert("Please enter username and password!");
		return false;
	}
	else
	{
		return true;
	}
}

//This function validates an email address
//returns false if it doesn't seem like a valid email address
function emailcheck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false;
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}
		if (str.indexOf(at,(lat+1))!=-1){
		   return false
		}
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   return false
		}
		if (str.indexOf(dot,(lat+2))==-1){
		   return false
		}
		if (str.indexOf(" ")!=-1){
		   return false
		}
 		return true					
}


//Validates the form on the Registration form
function validateReg (theform)
{
	//Here we validate the form
	var error=0;
	
	if ((document.getElementById('name').value == null) || (document.getElementById('name').value == ''))
	{
		document.getElementById('nameErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/warning.jpg" height="16" width="16" alt="icon" class="info"/>';
		error = 1;
	}
	else
	{
		document.getElementById('nameErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/clear.jpg" height="16" width="16" alt="icon" class="info"/>';
	}		

	if (document.getElementById('mobile').value == null || document.getElementById('mobile').value == '')
	{
		document.getElementById('mobileErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/warning.jpg" height="16" width="16" alt="icon" class="info"/>';
		error = 1;
	}
	else
	{
		document.getElementById('mobileErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/clear.jpg" height="16" width="16" alt="icon" class="info"/>';
	}		

	if (document.getElementById('email').value == null || document.getElementById('email').value == '')
	{
		document.getElementById('emailErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/warning.jpg" height="16" width="16" alt="icon" class="info"/>';
		error = 1;
	}
	else if (emailcheck(document.getElementById('email').value)==false)
	{
		document.getElementById('emailErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/warning.jpg" height="16" width="16" alt="icon" class="info"/>';
		error = 1;
	}
	else
	{
		document.getElementById('emailErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/clear.jpg" height="16" width="16" alt="icon" class="info"/>';
	}		
	
	if (document.getElementById('city').value == null || document.getElementById('city').value == '')
	{
		document.getElementById('cityErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/warning.jpg" height="16" width="16" alt="icon" class="info"/>';
		error = 1;
	}
	else
	{
		document.getElementById('cityErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/clear.jpg" height="16" width="16" alt="icon" class="info"/>';
	}		

	if (document.getElementById('pobox').value == null || document.getElementById('pobox').value == '')
	{	
		document.getElementById('poboxErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/warning.jpg" height="16" width="16" alt="icon" class="info"/>';
		error = 1;
	}
	else
	{
		document.getElementById('poboxErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/clear.jpg" height="16" width="16" alt="icon" class="info"/>';
	}		

	if (document.getElementById('country').value == null || document.getElementById('country').value == '')
	{
		document.getElementById('countryErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/warning.jpg" height="16" width="16" alt="icon" class="info"/>';
		error = 1;
	}
	else
	{
		document.getElementById('countryErr').innerHTML='<img src="http://www.emiratesmac.com/eventreg/clear.jpg" height="16" width="16" alt="icon" class="info"/>';
	}		

	//If there has been an error return false so form doesn't submit
	if (error==1)
	{
		alert("Please check the information in the form and provide complete and accurate information.");
		return false;
	}
	else
	{
		return true;
	}
}


