var captcha = false;

function addCollab()
{
	var template = document.getElementById('collab_template');
	var nb       = document.getElementById('nbcollab');
	var collabs  = document.getElementById('collaborators');
	
	var num = parseInt(nb.value, 10);
	
	nb.value = num + 1;
	
	var html = template.innerHTML;
	html = html.replace("collab_firstname","collab_firstname" + num);
	html = html.replace("collab_lastname","collab_lastname" + num);
	html = html.replace("collab_email","collab_email" + num);
	html = html.replace("collab_ny","collab_ny" + num);
	html = html.replace("collab_ny","collab_nv" + num);
	
	var div = document.createElement('div');
	div.innerHTML = html;
	
	collabs.appendChild(div);
	
}



function validateattendee()
{
	var form     = document.getElementById('formattendee');
	var strAlert = '';
	
	

	if( document.formattendee.regfrom != null && document.formattendee.regfrom.selectedIndex == 0 )
	{
		strAlert += '-  I am registering because I received a\n';
	}
	
	if( document.formattendee.email != null )
	{
		if (document.formattendee.email.value == '') {strAlert += '- Email\n';}
	
		if (document.formattendee.password.value == '') {strAlert += '- Password\n';}
		if (document.formattendee.password.value != '')
		{
			if (document.formattendee.repassword.value != document.formattendee.password.value)
			{
				strAlert += '- Passwords do not match\n';
			}
		}
	
	}
	
	if (document.formattendee.company.value == '') {strAlert += '- Company\n';}
	if (document.formattendee.firstname.value == '') {strAlert += '- First Name\n';}
	if (document.formattendee.lastname.value == '') {strAlert += '- Last Name\n';}
	if (document.formattendee.title.value == '') {strAlert += '- Title\n';}

	if (document.formattendee.title.value == 'Other') {
		if (document.formattendee.titleother.value == '') {strAlert += '- Other Title\n';}
	}

	if (document.formattendee.addr1.value == '') {strAlert += '- Address 1\n';}
	if (document.formattendee.city.value == '') {strAlert += '- City\n';}
	if (document.formattendee.state.value == '') {strAlert += '- State\n';}
	if (document.formattendee.zipcode.value == '') {strAlert += '- Zipcode\n';}
	if (document.formattendee.country.value == '') {strAlert += '- Country\n';}
	if (document.formattendee.phone.value == '') {strAlert += '- Telephone\n';}
	
	if (document.formattendee.profile.value == 'Other') {
		if (document.formattendee.profileother.value == '') {strAlert += '- Other Profile\n';}
	}
	
	if( form.nbcollab != null && form.nbcollab.value > 0)
	{
		var fields = ['collab_firstname', 'collab_lastname', 'collab_email'];
		
		function checkFieldSet(form, idx)
		{
			var set = false;
			
			for(var i = 0; i < fields.length; i ++)
			{
				var field = fields[i];
				
				if( form[field + idx] != null && form[field + idx].value != '' )
				{
					set = true;
					break;
				}
			}
			
			return set;
		}
		
		function checkAllFieldsSet(form, idx)
		{
			var nb = 0;
			
			for(var i = 0; i < fields.length; i ++)
			{
				var field = fields[i];
				
				if( form[field + idx] != null && form[field + idx].value != '' )
				{
					nb++;
				}
			}
			
			return (nb > 0 && nb == fields.length);
		}
		
		for(var i = 0; i < form.nbcollab.value; i ++)
		{
			if( checkFieldSet(form, i) && !checkAllFieldsSet(form, i) && ( form['collab_ny'.$i].checked || form['collab_nv'.$i].checked) )
			{
				strAlert += '- First name, last name and email for your colleague.';
			}
			
		}
	}
	
	if (document.formattendee.brands.value == '') {strAlert += '- Brands\n';}

	if (strAlert != '') {
		strAlert = 'We will need the following information to continue:\n' + strAlert;
		window.alert(strAlert);
		return false;
	}
}

function validateexhibitor() {

	var strAlert = '';
	
	if( !captcha )
	{
		alert("Please check the verification code");
		return false;
	}

	if (document.formexhibitor.brandname.value == '') {strAlert += '- Brand name\n';}
	if (document.formexhibitor.company.value == '') {strAlert += '- Company\n';}
	if (document.formexhibitor.usaddr1.value == '') {strAlert += '- Address 1\n';}
	if (document.formexhibitor.uscity.value == '') {strAlert += '- City\n';}
	if (document.formexhibitor.usstate.value == '') {strAlert += '- State\n';}
	if (document.formexhibitor.uszipcode.value == '') {strAlert += '- Zipcode\n';}
	if (document.formexhibitor.uscountry.value == '') {strAlert += '- Country\n';}
	if (document.formexhibitor.uscontact.value == '') {strAlert += '- Contact\n';}
	if (document.formexhibitor.usphone.value == '') {strAlert += '- Telephone\n';}
	if (document.formexhibitor.usemail.value == '') {strAlert += '- Email Address\n';}
	if (document.formexhibitor.uswebsite.value == '') {strAlert += '- Website URL\n';}
	
	/*
	if( document.formexhibitor.logofile != null )
	{
		if( document.getElementById('currentLogo') == null )
		{
			if( document.formexhibitor.logofile.value == '' )
			{
				alert('Please select your logo');
				return false;
			}
		}
		
		if( document.formexhibitor.logofile.value != '' && !checkLogo() )
		{
			return false;
		}
	}
	*/

	if (strAlert != '') {
		strAlert = 'We will need the following information to continue:\n' + strAlert;
		window.alert(strAlert);
		return false;
	}
}

function validatepress() {

	var strAlert = '';

	if (document.formpress.firstname.value == '') {strAlert += '- First Name\n';}
	if (document.formpress.lastname.value == '') {strAlert += '- Last Name\n';}
	if (document.formpress.title.value == '') {strAlert += '- Title\n';}
	if (document.formpress.publication.value == '') {strAlert += '- Publication Name\n';}
	if (document.formpress.addr1.value == '') {strAlert += '- Address 1\n';}
	if (document.formpress.city.value == '') {strAlert += '- City\n';}
	if (document.formpress.state.value == '') {strAlert += '- State\n';}
	if (document.formpress.zipcode.value == '') {strAlert += '- Zipcode\n';}
	if (document.formpress.country.value == '') {strAlert += '- Country\n';}
	if (document.formpress.phone.value == '') {strAlert += '- Telephone\n';}
	if (document.formpress.email.value == '') {strAlert += '- Email\n';}

	if (strAlert != '') {
		strAlert = 'We will need the following information to continue:\n' + strAlert;
		window.alert(strAlert);
		return false;
	}
}

function validatechangepass() {

	var strAlert = '';

	if (document.formchangepass.username.value == '') {strAlert += '- Username\n';}
	if (document.formchangepass.curpass.value == '') {strAlert += '- Current Password\n';}
	if (document.formchangepass.newpass.value == '') {strAlert += '- New Password\n';}
	
	if (document.formchangepass.newpass.value !='') {
		if (document.formchangepass.newpass.value == document.formchangepass.curpass.value) {
			strAlert = 'The new password you entered is the same as the old password entered. There is no need to continue.\n\n';
			window.alert(strAlert);
			return false;
		}
	}
	
	if (strAlert != '') {
		strAlert = 'We will need the following information to continue:\n' + strAlert;
		window.alert(strAlert);
		return false;
	}
}