var oFullName,
	oPhone,
	oEmail;

var	oMessage;

var oEName,
	oECountry,
	oECity,
	oEVenue,
	oEd,
	oEm,
	oEy,
	oEComments;

	
	
function cu_init()
{
	oFullName 	= document.getElementById('fullname');
	oPhone		= document.getElementById('phone');
	oEmail		= document.getElementById('email');
	oMessage	= document.getElementById('message');

	AutoTrim();
}

function cu_validate_form()
{	
	
	
	if(!oFullName.value.length)
	{
		showErrorMessage(oUIMessage_1021);
		oFullName.focus();
		return false;
	}
	
	//	validate only if it a required input
	if(oEmail.getAttribute('required') != null)
	{
		if(!oEmail.value.length)
		{
			showErrorMessage(oUIMessage_1018);
			oEmail.select();
			oEmail.focus();
			return false;		
		}
	}
	
	//	check email syntax if entered
	if(oEmail.value.length && !email_validation(oEmail.value))
	{
		showErrorMessage(oUIMessage_1018);
		oEmail.select();
		oEmail.focus();
		return false;		
	}	
	
	//	validate only if it a required input
	if(oPhone.getAttribute('required') != null)
	{
		if(!oPhone.value.length)
		{
			showErrorMessage(oUIMessage_1019);
			oPhone.select();
			oPhone.focus();
			return false;		
		}
	}
	if(!oMessage.value.length)
	{
			showErrorMessage(oUIMessage_1020);
			oMessage.select();
			oMessage.focus();
			return false;		
	}

	return true;
}

function cu_SendForm(oForm)
{
	if(oForm)
	{
		oForm.action = "ex/";
		oForm.method = "POST";
		return cu_validate_form(oForm);
	}
	else
	{
		oForm.action = "";
		return false;
	}
}

function showErrorMessage(sMsg)
{
	if(sMsg.length)
	{
		alert('' + sMsg);
	}
}

function report_init()
{
	oFullName 	= document.getElementById('fullname');
	oPhone		= document.getElementById('phone');
	oEmail		= document.getElementById('email');
	
	oEName		= document.getElementById('ename');
	oECountry	= document.getElementById('ecountry');
	oECity		= document.getElementById('ecity');
	oEVenue		= document.getElementById('evenue');
	oEd			= document.getElementById('d');
	oEm			= document.getElementById('m');
	oEy			= document.getElementById('y');
	
}

function report_validate_form()
{
	if(!oFullName.value.length)
	{
		showErrorMessage(oUIMessage_1021);
		oFullName.focus();
		return false;
	}
	
	if(!oEmail.value.length)
	{
		showErrorMessage(oUIMessage_1022);
		oEmail.focus();
		return false;
	}
	else
	{
		if(!email_validation(oEmail.value))
		{
			showErrorMessage(oUIMessage_1021);
			oEmail.select();
			oEmail.focus();
			return false;		
		}
	}
	
	if(!oEName.value.length)
	{
			showErrorMessage(oUIMessage_1023);
			oEName.focus();
			return false;		
	}
	

	if(!oECountry.value.length)
	{
			showErrorMessage(oUIMessage_1024);
			oECountry.focus();
			return false;		
	}	
	

	if(!oEd.selectedIndex || !oEm.selectedIndex || !oEy.selectedIndex)
	{
			showErrorMessage(oUIMessage_1025);
			oEName.focus();
			return false;		
	}	
	
	return true;
}

function report_SendForm(oForm)
{
	if(oForm)
	{
		oForm.action = "ex/";
		oForm.method = "POST";
		return report_validate_form();
	}
	else
	{
		oForm.action = "";
		return false;
	}
}


function email_validation(sEmail)
{
	if(sEmail)
	{
		if(sEmail.indexOf('@') <= 0) return false;								// a '@' must present at least as a second character
		if(sEmail.indexOf('.') <= 0) return false;								// a '.' must present at least as a second character
		if(sEmail.indexOf('@.') >=0 || sEmail.indexOf('.@') >=0) return false;	// a '@.' or '.@' combination must not present
					
		if(sEmail.lastIndexOf('.') <= sEmail.indexOf('@')) return false;		// at lease on '.' must present after the '@' but not immediately after it
		if(sEmail.indexOf('@') != sEmail.lastIndexOf('@')) return false;		// one '@' only permitted
		if(sEmail.lastIndexOf('.') >= (sEmail.length - 2)) return false;		// after the last '.' must present at least 2 characters
		
		
		
		/* scan the email string for any forbidden character */
		
		var sAllowed = "abcdefghijklmnopqrstuvwxyz"								// set all allowed characters
					+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
					+ "0123456789"
					+ "_-.";
		
		var ch;															
				
		for(var i=0; i < sEmail.length; i++)
		{
			ch = sEmail.charAt(i);
			
			if(ch != '@')
			{
				if (sAllowed.indexOf(ch) == -1)									// if a character was not found in 
				{																// the allowed set it is probably unallowed
					return false;												// return false
				}					
			}
		}
		
		
		/* email is in the right format and content */
		
		return true;
		
	}
	
	return false;
}