function checkEmail(){
	var email = $('advertiser_login').value;
	if (email.blank()) {
		var msg = 'Please enter your email address.'
		Modalbox.show('<div class=\'warning\' style=\'text-align:center\'>' + msg + '<br /><br /><input type=\'button\' value=\'OK\' onclick=\'Modalbox.hide()\' /></div>', {title: 'NOTICE:', width: 400});
		return false;
	}
	var url = '/opportunities/check_email';
	var params = 'authenticity_token=' + authenticity_token + '&email='+ email;
	new Ajax.Request(url,{method: 'post', postBody: params, onSuccess: emailGood, onFailure: emailBad})

}

function emailGood(obj) {
	
}

function emailBad(obj) {
	
}

function doChallenge() {
	//checkEmail()
	//alert(Recaptcha.get_challenge())
	//alert(Recaptcha.get_response())
}
function validateStep2Form(){
	try {
		test = previous_button;
	} catch(e) { previous_button = 0;}
	
	if (previous_button == 1) {
		return true;
	}


	var errorMessage = '';
	
	if ($('form_step_2_organization_name').value.blank()){
		errorMessage += message['PleaseEnterOrganizationName'] 
	}
	
	if ($('form_step_2_contact_details').value.blank()){
		errorMessage += message['PleaseEnterContactDetails'] 
	}

	var is_checked = false;
	for (var x = 0; x < language_array.length; x++ ) {
		if ($('form_step_2_' + language_array[x].toLowerCase()).checked) {
			is_checked = true;
		}
	}

	if (!is_checked)	{
		errorMessage += message['InWhichLanguages'] 
	}
	if (!errorMessage.empty()) {
		try {
		$$(".BannerAdHolder")[0].hide();
		} catch (e) {}
		Modalbox.show('<div class=\'warning\' style=\'text-align:center\'><strong>' + message['PleaseCorrect'] + ':</strong><div style=\'text-align:left;\'><ul>' + errorMessage + '</ul></div> <input type=\'button\' value=\'' + message['OK'] + '\' onclick=\'Modalbox.hide()\' /></div>', {title: message['DataEntryProblem'] + ':', width: 400, afterHide: function(){$$(".BannerAdHolder")[0].show();} });

		return false;
		
	}
	return true;
			
}

function validateForm() {
	try {
		test = previous_button;
	} catch(e) { previous_button = 0;}

	if (previous_button == 1) {
		return true;
	}

	var errorMessage = '';
	
	if ($('form_admin_for_women').checked == 0 && $('form_admin_for_men').checked == 0){
		errorMessage += message['ErrorMenWomen']
	}
	
	if ($('form_admin_address_line1').value.blank()){
		errorMessage += message['EnterStreetAddress'] 
	}

	if ($('countrySelect').selectedIndex == 0){
		errorMessage += message['SelectACountry']
	}

	if ($('stateSelect').nodeName.toUpperCase() == 'INPUT') {
		if ($('stateSelect').value == '') {
			errorMessage += message['EnterState']
		}
	}
	if ($('stateSelect').nodeName.toUpperCase() == 'SELECT') {
		if ($('stateSelect').selectedIndex == 0 && $('stateSelect').selectedIndex != undefined ) {
			errorMessage += message['SelectEnterState']
		}
	}
	if ($('form_admin_zip').value.blank()){
		errorMessage += message['EnterPostalCode']
	}

		try {
			if ($('content_english_title').value.blank()){
				errorMessage += message['OpportunityTitleEnglish'] 
			}
		} catch(e) {}

		try {
			if ($('content_english_details').value.blank()){
				errorMessage += message['OpportunityDetailsEnglish']
			}
		} catch(e) {}
		
		try {
			if ($('content_english_description').value.blank()){
				errorMessage += message['OpportunityDescriptionEnglish']
			}
		} catch(e) {}

		try {
			if ($('content_english_event_dates').value.blank()){
				errorMessage += message['OpportunityEventDatesEnglish']
			}
		} catch(e) {}
		

		try {
			if ($('content_spanish_title').value.blank()){
				errorMessage += message['OpportunityTitleSpanish'] 
			}
		} catch(e) {}

		try {
			if ($('content_spanish_details').value.blank()){
				errorMessage += message['OpportunityDetailsSpanish']
			}
		} catch(e) {}
		
		try {
			if ($('content_spanish_description').value.blank()){
				errorMessage += message['OpportunityDescriptionSpanish'] 
			}
		} catch(e) {}

		try {
			if ($('content_spanish_event_dates').value.blank()){
				errorMessage += message['OpportunityEventDatesSpanish'] 
			}
		} catch(e) {}

		try {
			if ($('content_french_title').value.blank()){
				errorMessage += message['OpportunityTitleFrench']  
			}
		} catch(e) {}

		try {
			if ($('content_french_details').value.blank()){
				errorMessage += message['OpportunityDetailsFrench']
			}
		} catch(e) {}
		
		try {
			if ($('content_french_description').value.blank()){
				errorMessage += message['OpportunityDescriptionFrench'] 
			}
		} catch(e) {}

		try {
			if ($('content_french_event_dates').value.blank()){
				errorMessage += message['OpportunityEventDatesFrench'] 
			}
		} catch(e) {}
      /////seccion para saber cuantas regiones fueron asignadas
	//errorMessage += checkChecker("form_admin_country_zone_",31,message['OpportunityRegion'])
	region = checkChecker("form_admin_country_zone_",31,message['OpportunityRegion'])
	if (region == 0){
	 errorMessage += message['OpportunityRegion']
	}
			
	if (!errorMessage.empty()) {
		if (region >= 2){
		 errorMessage +=  '<br />' + message['LengthRegion']
		}
		try {
		$$(".BannerAdHolder")[0].hide();
		} catch (e) {}
		Modalbox.show('<div class=\'warning\' style=\'text-align:center\'><strong>' + message['Please'] + ':</strong><div style=\'text-align:left;\'><ul>' + errorMessage + '</ul></div> <input type=\'button\' value=\'' + message['OK'] + '\' onclick=\'Modalbox.hide()\' /></div>', {title: message['DataEntryProblem'] + ':', width: 400, afterHide: function(){$$(".BannerAdHolder")[0].show();} });

		return false;
		
	}
	
	if (region >= 2){
	        if(confirm(message['LengthRegion2'])){
			return true;
		}
		return false;
	}
	return true;

}

function checkChecker(item,max,message,has_99){
	var has_99 = (has_99 == null) ? false : true;
	var is_checked = false;
	var length_region = 0;
	for (var x = 1; x <= max; x++ ) {
		if ($(item + x).checked) {
		//alert(x);
			is_checked = true;
	          length_region = length_region + 1
		}
	}
	if (has_99 && $(item + '99').checked) {
		is_checked = true;
	}

	if (!is_checked) {
		return 0;
	}else{
		return length_region
	}
	return ""
}


