// Place your application-specific JavaScript functions and classes here
var GB_ROOT_DIR = "http://www.maritimejobsearch.com/js/greybox/";

function punctuated(n){
	n = n.toFixed(2);
	var s=(''+n).split('.');
	s[0]=s[0].split('').reverse().join('').match(/\d{1,3}/gi).join(',').split('').reverse().join('');
	return(s.join('.'));
}

// js trim
function trim(value) {
return value.replace(/^\s+/,'').replace(/\s+$/,''); 
}
// Copy visitor address to postal address in employer's profile
function copy_address() {
	$('postal_address').value            = $('visitor_address').value
	$('postal_address2').value           = $('visitor_address2').value
	$('postal_zipcode').value            = $('visitor_zipcode').value
	$('postal_city').value               = $('visitor_city').value
	$('postal_state').value              = $('visitor_state').value
	$('postal_country_id').selectedIndex = $('visitor_country_id').selectedIndex
}

function toggleSelectAll(section, checked) {
	var checkboxes;
	var checkboxes = document.getElementsByName(section);
	for (i =0; i<checkboxes.length; i++) {
		checkboxes[i].checked = checked;
	}
}

function toggleSelectAllCheckBox(selectAllCheckbox, section) {
	var checkboxes;
	var checkboxes = document.getElementsByName(section);
	var selectAllCheckbox = document.getElementsByName(selectAllCheckbox);
	var aantalCheckBoxesChecked = 0;
	for (i = 0; i < checkboxes.length; i++) {
		if(!checkboxes[i].checked) {
			for(j = 0; j < selectAllCheckbox.length; j++) {
				selectAllCheckbox[j].checked = false;
			}
		}
	}
	for (i = 0; i < checkboxes.length; i++) {
		if(checkboxes[i].checked) {
			aantalCheckBoxesChecked++;
		}
	}
	if(aantalCheckBoxesChecked == checkboxes.length) {
		for(i = 0; i<selectAllCheckbox.length; i++) {
			selectAllCheckbox[i].checked = true;
		}
	}
}
function checkForm() {
	if (document.signup_form.email.value != '' && document.signup_form.email2.value != '' && document.signup_form.password_orig.value != '' && document.signup_form.password_check.value != '' && document.signup_form.password_orig.value != '' && document.signup_form.password_orig.value == document.signup_form.password_check.value && document.signup_form.password_check.value.length >= 6 && document.signup_form.agree.checked && checkEmail(document.signup_form.email.value)) {
		return true;
	} else {
		if (document.signup_form.email.value == '') {
			if($('email_error').style.display == 'none')
			new Effect.BlindDown($('email_error'));
		} else {
			$('email_error').style.display = 'none';
		}
		if (document.signup_form.email2.value == '') {
			if($('email2_error').style.display == 'none')
			new Effect.BlindDown($('email2_error'));
		} else {
			$('email2_error').style.display = 'none';
		}
		if (document.signup_form.password_orig.value == '') {
			if($('pw_error').style.display == 'none')
			new Effect.BlindDown($('pw_error'));
		} else {
			$('pw_error').style.display = 'none';
		}
		if (document.signup_form.password_check.value == '') {
			if($('pw_check_error_empty').style.display == 'none')
			new Effect.BlindDown($('pw_check_error_empty'));
		} else {
			$('pw_check_error_empty').style.display = 'none';
		}
		if (document.signup_form.password_check.value != '' && document.signup_form.password_check.value != document.signup_form.password_orig.value) {
			if($('pw_check_error').style.display == 'none')
			new Effect.BlindDown($('pw_check_error'));
		} else {
			$('pw_check_error').style.display = 'none';
		}
		if (document.signup_form.password_check.value != '' && document.signup_form.password_orig.value.length < 6) {
			if($('pw_length_error').style.display == 'none')
			new Effect.BlindDown($('pw_length_error'));
		} else {
			$('pw_length_error').style.display = 'none';
		}
		if (!document.signup_form.agree.checked) {
			if($('terms_check').style.display == 'none')
			new Effect.BlindDown($('terms_check'));
		} else {
			$('terms_check').style.display = 'none';
		}
		if (document.signup_form.email.value != '' && !checkEmail(document.signup_form.email.value)) {
			if($('email_format_error').style.display == 'none')
			new Effect.BlindDown($('email_format_error'));
		} else {
			$('email_format_error').style.display = 'none';
		}
		if(document.signup_form.email.value != document.signup_form.email2.value) {
			if($('email_mismatch_error').style.display == 'none')
			new Effect.BlindDown($('email_mismatch_error'));
		} else {
				$('email_mismatch_error').style.display = 'none';
		}
		
		return false;
	}
}
function checkInfoForm(info_type) {

	tinyMCE.triggerSave();
	
	if(info_type == 'company') {
		if(document.information_form.company_name.value != '' && document.information_form.visitor_address.value != '' && document.information_form.visitor_zipcode.value != '' && (document.information_form.state.value != '' || $('state_div').style.display == 'none') && document.information_form.visitor_city.value != '' && document.information_form.visitor_country_id.value != '' && document.information_form.job_sector_id.value != '' && document.information_form.contact_name.value != '' && document.information_form.contact_email.value != '') {
			$('label_contact_email').style.color = '#000';
			$('label_contact_phone').style.color = '#000';
			$('label_contact_name').style.color = '#000';
			$('label_job_sector').style.color = '#000';
			//$('label_phone').style.color = '#000';
			$('label_visitor_country').style.color = '#000';
			$('label_state').style.color = '#000';
			$('label_visitor_city').style.color = '#000';
			$('label_visitor_zipcode').style.color = '#000';
			$('label_visitor_address').style.color = '#000';
			$('label_company_name').style.color = '#000';
			return true;
		} else {
			if(document.information_form.contact_email.value == '') {
				$('label_contact_email').style.color = '#CC0000';
				window.scroll(0,929);
			} else {
				$('label_contact_email').style.color = '#000';
			}
			if(document.information_form.contact_name.value == '') {
				$('label_contact_name').style.color = '#CC0000';
				window.scroll(0,889);
			} else {
				$('label_contact_name').style.color = '#000';
			}
			if(document.information_form.job_sector_id.value == '') {
				$('label_job_sector').style.color = '#CC0000';
				window.scroll(0,777);
			} else {
				$('label_job_sector').style.color = '#000';
			}
			/*if(document.information_form.phone.value == '') {
				$('label_phone').style.color = '#CC0000';
				window.scroll(0,593);
			} else {
				$('label_phone').style.color = '#000';
			}*/
			if(document.information_form.visitor_country_id.value == '') {
				$('label_visitor_country').style.color = '#CC0000';
				window.scroll(0,387);
			} else {
				$('label_visitor_country').style.color = '#000';
			}
			if(document.information_form.visitor_city.value == '') {
				$('label_visitor_city').style.color = '#CC0000';
				window.scroll(0,342);
			} else {
				$('label_visitor_city').style.color = '#000';
			}
			if(document.information_form.visitor_zipcode.value == '') {
				$('label_visitor_zipcode').style.color = '#CC0000';
				window.scroll(0,316);
			} else {
				$('label_visitor_zipcode').style.color = '#000';
			}
			if(document.information_form.state.value == '') {
				$('label_state').style.color = '#CC0000';
				window.scroll(0,316);
			} else {
				$('label_state').style.color = '#000';
			}
			if(document.information_form.visitor_address.value == '') {
				$('label_visitor_address').style.color = '#CC0000';
				window.scroll(0,264);
			} else {
				$('label_visitor_address').style.color = '#000';
			}
			if(document.information_form.company_name.value == '') {
				$('label_company_name').style.color = '#CC0000';
				window.scroll(0,235);
			} else {
				$('label_company_name').style.color = '#000';
			}
			return false;
		}
	} else 
	if(info_type == 'personal') {
		if(document.information_form.name.value != '' && document.information_form.address.value != '' && document.information_form.zipcode.value != '' && document.information_form.city.value != '' && (document.information_form.state.value != '' || $('state_div').style.display == 'none') && document.information_form.country_id.value != '') {
			
			return true;
			
		} else {
			/*if(!radio_button_checker(document.information_form.gender)) {
				$('label_gender').style.color = '#CC0000';
				window.scroll(0,593);
			} else {
				$('label_gender').style.color = '#000';
			}*/
			if(document.information_form.country_id.value == '') {
				$('label_country').style.color = '#CC0000';
				window.scroll(0,387);
			} else {
				$('label_country').style.color = '#000';
			}
			if(document.information_form.city.value == '') {
				$('label_city').style.color = '#CC0000';
				window.scroll(0,342);
			} else {
				$('label_city').style.color = '#000';
			}
			if(document.information_form.state.value == '') {
				$('label_state').style.color = '#CC0000';
				window.scroll(0,325);
			} else {
				$('label_state').style.color = '#000';
			}
			if(document.information_form.zipcode.value == '') {
				$('label_zipcode').style.color = '#CC0000';
				window.scroll(0,316);
			} else {
				$('label_zipcode').style.color = '#000';
			}
			if(document.information_form.address.value == '') {
				$('label_address').style.color = '#CC0000';
				window.scroll(0,264);
			} else {
				$('label_address').style.color = '#000';
			}
			if(document.information_form.name.value == '') {
				$('label_name').style.color = '#CC0000';
				window.scroll(0,235);
			} else {
				$('label_name').style.color = '#000';
			}
			return false;
		}
	} else
	if(info_type == 'resume') {
		//alert($('job_category_id').value);
		
		// job sectors
		var job_sectors = document.getElementsByName('job_sectors[]');
		var job_sectors_empty = true;

		for (i=0;i<job_sectors.length;i++) {
			
			if (job_sectors[i].checked) {
				job_sectors_empty = false;
				break;
			}
		}
		
		// job categories
		var job_categories = document.getElementsByName('job_categories[]');
		var job_categories_empty = true;
		for (i=0;i<job_categories.length;i++) {
			if (job_categories[i].checked) {
				job_categories_empty = false;
				break;
			}
		}
		
		if(document.information_form.title.value != '' && document.information_form.intro.value != '' && !job_categories_empty && !job_sectors_empty && (document.information_form.state.value != '' || $('state_div').style.display == 'none') && document.information_form.country_id.value != '') {
			$('label_title').style.color = '#000';
			$('label_intro').style.color = '#000';
			$('label_job_category').style.color = '#000';
			$('label_job_sector').style.color = '#000';
			$('label_country').style.color = '#000';
			return true;
		} else {
			if(job_sectors_empty) {
				$('label_job_sector').style.color = '#CC0000';
				window.scroll(0,400);
			} else {
				$('label_job_sector').style.color = '#000';
			}
			if(job_categories_empty) {
				$('label_job_category').style.color = '#CC0000';
				window.scroll(0,387);
			} else {
				$('label_job_category').style.color = '#000';
			}
			if(document.information_form.intro.value == '') {
				$('label_intro').style.color = '#CC0000';
				window.scroll(0,240);
			} else {
				$('label_intro').style.color = '#000';
			}
			if(document.information_form.title.value == '') {
				$('label_title').style.color = '#CC0000';
				window.scroll(0,200);
			} else {
				$('label_title').style.color = '#000';
			}
			if(trim(document.information_form.country_id.value) == '') {
				$('label_country').style.color = '#CC0000';
				window.scroll(0,363);
			}
			else if(trim(document.information_form.state.value) == '') {
				$('label_country').style.color = '#CC0000';
				window.scroll(0,393);
			} else {
				$('label_country').style.color = '#000';
			}
			
			return false;
		}
	} else
	if(info_type == 'job_opening') {
		if(document.job_opening_form.title.value != '' && document.job_opening_form.job_description.value != '' &&  (document.job_opening_form.state.value != '' || $('state_div').style.display == 'none')  && document.job_opening_form.job_sector_id.value != '' && document.job_opening_form.country_id.value != '' && document.job_opening_form.job_category_id.value != '' && document.job_opening_form.contact_name.value != '' && document.job_opening_form.contact_phone.value != '' && document.job_opening_form.contact_email.value != '') {
			return true;
		} else {
			if(trim(document.job_opening_form.contact_email.value) == '') {
				$('label_contact_email').style.color = '#CC0000';
				window.scroll(0,845);
			} else {
				$('label_contact_email').style.color = '#000';
			}
			if(trim(document.job_opening_form.contact_phone.value) == '') {
				$('label_contact_phone').style.color = '#CC0000';
				window.scroll(0,820);
			} else {
				$('label_contact_phone').style.color = '#000';
			}
			if(trim(document.job_opening_form.contact_name.value) == '') {
				$('label_contact_name').style.color = '#CC0000';
				window.scroll(0,801);
			} else {
				$('label_contact_name').style.color = '#000';
			}
			if(trim(document.job_opening_form.job_category_id.value) == '') {
				$('label_job_category').style.color = '#CC0000';
				window.scroll(0,445);
			} else {
				$('label_job_category').style.color = '#000';
			}
			if(trim(document.job_opening_form.job_sector_id.value) == '') {
				$('label_job_sector').style.color = '#CC0000';
				window.scroll(0,420);
			} else {
				$('label_job_sector').style.color = '#000';
			}
			if(trim(document.job_opening_form.state.value) == '') {
				$('label_region').style.color = '#CC0000';
				window.scroll(0,393);
			} else {
				$('label_region').style.color = '#000';
			}
			if(trim(document.job_opening_form.country_id.value) == '') {
				$('label_country').style.color = '#CC0000';
				window.scroll(0,363);
			} else {
				$('label_country').style.color = '#000';
			}
			if(document.job_opening_form.job_description.value == '') {
				$('label_description').style.color = '#CC0000';
				window.scroll(0,240);
			} else {
				$('label_description').style.color = '#000';
			}
			if(trim(document.job_opening_form.title.value) == '') {
				$('label_title').style.color = '#CC0000';
				window.scroll(0,213);
			} else {
				$('label_title').style.color = '#000';
			}
			return false;
		}
	}
	else 
	if(info_type == 'reply') {
		if(document.reply_form.contact_name.value != '' && document.reply_form.contact_phone.value != '' && document.reply_form.contact_email.value != '') {
			return true;
		} else {
			if(trim(document.reply_form.contact_email.value) == '') {
				$('label_contact_email').style.color = '#CC0000';
				window.scroll(0,845);
			} else {
				$('label_contact_email').style.color = '#000';
			}
			if(trim(document.reply_form.contact_phone.value) == '') {
				$('label_contact_phone').style.color = '#CC0000';
				window.scroll(0,820);
			} else {
				$('label_contact_phone').style.color = '#000';
			}
			if(trim(document.reply_form.contact_name.value) == '') {
				$('label_contact_name').style.color = '#CC0000';
				window.scroll(0,801);
			} else {
				$('label_contact_name').style.color = '#000';
			}
			return false;
		}
	}
	else 
	if(info_type == 'reply_maritimecompany') {
		
		var captcha_valid = false;
		
		// Check captcha
		new Ajax.Request('/extra/captcha_check.php',
			{
				method: 'get',
				parameters: 'captcha='+document.reply_form.contact_captcha.value,
				asynchronous: false,
				onSuccess: function(response) {
					captcha_valid = true;
				}
			}
		);
		
		if(captcha_valid && document.reply_form.contact_name.value != '' && document.reply_form.contact_phone.value != '' && document.reply_form.contact_email.value != '' && document.reply_form.contact_file.value != '') {
			return true;
		} else {
			if(trim(document.reply_form.contact_email.value) == '') {
				$('label_contact_email').style.color = '#CC0000';
				window.scroll(0,845);
			} else {
				$('label_contact_email').style.color = '#000';
			}
			if(trim(document.reply_form.contact_phone.value) == '') {
				$('label_contact_phone').style.color = '#CC0000';
				window.scroll(0,820);
			} else {
				$('label_contact_phone').style.color = '#000';
			}
			if(trim(document.reply_form.contact_name.value) == '') {
				$('label_contact_name').style.color = '#CC0000';
				window.scroll(0,801);
			} else {
				$('label_contact_name').style.color = '#000';
			}
			if(trim(document.reply_form.contact_file.value) == '') {
				$('label_contact_file').style.color = '#CC0000';
				window.scroll(0,801);
			} else {
				$('label_contact_file').style.color = '#000';
			}
			
			if(!captcha_valid) {
				$('label_contact_captcha').style.color = '#CC0000';
				window.scroll(0,801);
			} else {
				$('label_contact_captcha').style.color = '#000';
			}
			
			
			return false;
		}
	}
	else {
		return false;
	}
}

function checkCaptcha(element) {

	
	return false;
}

function max3checks(name) {
	// job sectors
	var items = document.getElementsByName(name);
	var item_count = true;

	for (i=0;i<items.length;i++) {
		
		if (items[i].checked) {
			item_count = item_count + 1;
		}
	}
	
	if (item_count > 4) {
		alert("Please select up to 3 categories.");
		return false;
	}
	else {
		return true;
	}
}

// functies
function radio_button_checker(buttons) {
	for (counter = 0; counter < buttons.length; counter++) {
		if(buttons[counter].checked) 
			return true; 
	}
	return false;
}
function checkEmail(email) {
	var validationExpression = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,4})$/;
	/*if(action_type == 'reset') {
		var email = document.password_reset_form.email_ww_vergeten.value;
	} 
	else if(action_type == 'signup') {
		var email = document.signup_form.email.value;
	}
	else {
		var email = document.information_form.email.value;
	}*/
	if(email.match(validationExpression)) {
		return true;
	}
	else {
		//$('pass_error').style.display = 'block';
		return false;
	}
}
function deletePicture(id) {
	if(confirm("Are you sure to delete this picture?")) {
		var params = 'action=delete_upload&id='+id;
		new Ajax.Request('/extra/actions.php',
			{
			method: 'get',
			parameters: params,
			onSuccess: pictureDeleted
			}
		);
	}
}
function pictureDeleted(request) {
	 $('input_picture').style.display = "inline";
	 $('show_picture').style.display = "none";
	 $('delete_picture_p').style.display = "none";
	
}
function deleteFile(id) {
	if(confirm("Are you sure to delete this document?")) {
		var params = 'action=delete_resume_upload&id='+id;
		new Ajax.Request('/extra/actions.php',
			{
			method: 'get',
			parameters: params,
			onSuccess: docDeleted
			}
		);
	}
}
function deleteFolder(id) {
	if(confirm("Are you sure to delete this document?")) {
		var params = 'action=delete_apprentice_upload&id='+id;
		new Ajax.Request('/extra/actions.php',
			{
			method: 'get',
			parameters: params,
			onSuccess: docDeleted
			}
		);
	}
}
function docDeleted(request) {
	 $('input_file').style.display = "block";
	 $('show_file').style.display = "none";
}

function checkCredits() {
	var params = 'action=check_credits';
	new Ajax.Request('/extra/actions.php',
		{
		method: 'get',
		parameters: params,
		onComplete: creditsChecked
		}
	);
}
function creditsChecked(request) {
	$('credits').innerHTML = request.responseText;
}
function billCredits() {
	var params = 'action=bill_credits';
	if(confirm('The job posting will be published and set active (1 credit). Are you sure?')) {
		new Ajax.Request('/extra/actions.php',
			{
			method: 'get',
			parameters: params,
			onComplete: creditsBilled
			}
		);
	}
}
function creditsBilled(request) {
	if(request.responseText) {
		alert('Job posting posted.');
		closeBox();
		$('job_opening_form').submit();
	}
	else {
		alert('Job posting not posted.');
	}
}

function showTotaal() {
	discount = parseFloat($('ajax_multiplier').innerHTML);
	tip_quantity = parseFloat($('tip_quantity').value);
			if (isNaN(tip_quantity)) {
			tip_quantity = 0.00;
			}
	$('subtotal_price').innerHTML = '$ '+punctuated(   parseFloat($('pr_jo').innerHTML) +  parseFloat($('pr_tip').innerHTML)  * tip_quantity   +   parseFloat($('pr_rs').innerHTML)  );
	$('discount_percentage').innerHTML = "-" + ((1 - discount) * 100).toFixed(1) + " %";
	$('total_price').innerHTML = '$ '+punctuated(( parseFloat($('pr_jo').innerHTML)  +  parseFloat($('pr_tip').innerHTML) *tip_quantity+  parseFloat($('pr_rs').innerHTML)  )*discount);
}

function updatePackageForm(package_name, package_number, package_amount, tip_quantity, tip_amount, rs_name, rs_item_number, rs_amount) {
	
	resetPurchaseBackgrounds();
	
	if (package_name != "" && package_number != "" && package_amount != "") {
		$('pp_item_name_1').name = "item_name_1";
		$('pp_item_number_1').name = "item_number_1";
		$('pp_amount_1').name = "amount_1";
		$('pp_item_name_1').value = package_name;
		$('pp_item_number_1').value = package_number;
		$('pp_amount_1').value = (parseFloat(package_amount) * parseFloat($('ajax_multiplier').innerHTML)).toFixed(2);
		var tip_number = 2;
		$('package_div_' + package_number).style.backgroundColor = '#dcf3df';
	}
	else {
		$('pp_item_name_1').name = "item_name_1_undefined";
		$('pp_item_number_1').name = "item_number_1_undefined";
		$('pp_amount_1').name = "amount_1_undefined";
		var tip_number = 1;
	}
	
	if (tip_quantity != undefined && parseInt(tip_quantity) > 0) {
		$('pp_item_name_2').name = "item_name_"+tip_number;
		$('pp_item_number_2').name = "item_number_"+tip_number;
		$('pp_amount_2').name = "amount_"+tip_number;
		$('pp_quantity_2').name = "quantity_"+tip_number;
		
		$('pp_amount_2').value = (parseFloat(tip_amount) * parseFloat($('ajax_multiplier').innerHTML)).toFixed(2);
		$('pp_quantity_2').value = parseInt(tip_quantity);
		var rs_number = tip_number + 1;
		$('package_div_' + $('pp_item_number_2').value).style.backgroundColor = '#dcf3df';
	}
	else {
		$('pp_item_name_2').name = "item_name_2_undefined";
		$('pp_item_number_2').name = "item_number_2_undefined";
		$('pp_amount_2').name = "amount_2_undefined";
		$('pp_quantity_2').name = "quantity_2_undefined";
		var rs_number = tip_number;
	}
	
	if (rs_name != "" && rs_item_number != "" && rs_amount != "") {
		$('pp_item_name_3').name = "item_name_"+rs_number;
		$('pp_item_number_3').name = "item_number_"+rs_number;
		$('pp_amount_3').name = "amount_"+rs_number;
		
		$('pp_item_name_3').value = rs_name;
		$('pp_item_number_3').value = rs_item_number;
		$('pp_amount_3').value = (parseFloat(rs_amount) * parseFloat($('ajax_multiplier').innerHTML)).toFixed(2);;
		$('package_div_' + rs_item_number).style.backgroundColor = '#dcf3df';
	}
	else {
		$('pp_item_name_3').name = "item_name_3_undefined";
		$('pp_item_number_3').name = "item_number_3_undefined";
		$('pp_amount_3').name = "amount_3_undefined";
	}
}

function packageClicked(price, id, name, element) {
	/*if($('pp_voucher').value == '2for1' && $('package_1').checked) {
		$('discount_tr_3').style.display = "";
		$('discount_tr_4').style.display = "";
	}
	else {
		$('discount_tr_3').style.display = "none";
		$('discount_tr_4').style.display = "none";
	}*/
	if (parseInt(id) == parseInt($('nu_jo').innerHTML)) {
		element.checked = false;
		$('na_jo').innerHTML = "";
		$('nu_jo').innerHTML = "";
		$('pr_jo').innerHTML = "0";

		showTotaal();
		updatePackageForm("","","",$('tip_quantity').value, $('pr_tip').innerHTML, trim($('na_rs').innerHTML), trim($('nu_rs').innerHTML), trim($('pr_rs').innerHTML));
	} else {
		packageChanged(price,id,name);
	}		
}

function resumesearchClicked(price, id, name, element) {
	if (parseInt(id) == parseInt($('nu_rs').innerHTML)) {
	       element.checked = false;
	       $('na_rs').innerHTML = "";
	       $('nu_rs').innerHTML = "";
	       $('pr_rs').innerHTML = "0";

	       showTotaal();
	       updatePackageForm(trim($('na_jo').innerHTML), trim($('nu_jo').innerHTML), trim($('pr_jo').innerHTML),$('tip_quantity').value, $('pr_tip').innerHTML,"","","");
	} else {
		resumesearchChanged(price,id,name);
	}		
}

function packageChanged(price, id, name) {
	$('na_jo').innerHTML = name;
  $('nu_jo').innerHTML = id;
  $('pr_jo').innerHTML = parseFloat(price); 
	
	showTotaal();
	updatePackageForm(name, id, price, $('tip_quantity').value, $('pr_tip').innerHTML, trim($('na_rs').innerHTML), trim($('nu_rs').innerHTML), trim($('pr_rs').innerHTML));
}

function resumesearchChanged(price, id, name) {
	$('na_rs').innerHTML = name;
  $('nu_rs').innerHTML = id;
  $('pr_rs').innerHTML = parseFloat(price);
	
	showTotaal();
	updatePackageForm(trim($('na_jo').innerHTML), trim($('nu_jo').innerHTML), trim($('pr_jo').innerHTML), $('tip_quantity').value, $('pr_tip').innerHTML,name,id,price);
}

function tipQuantityChanged(element, unit_price, package_name, package_number, package_amount) {
	var quantity = parseInt(element.value);
	if (quantity > 0) {
		$('tip_price').innerHTML = '$ '+ punctuated(parseFloat(unit_price * quantity));
		$('pr_tip').innerHTML = parseFloat(unit_price);
	}
	else {
		$('tip_price').innerHTML = '$ 0.00';
		$('pr_tip').innerHTML = '0';
	}
	
	showTotaal();
	updatePackageForm(trim($('na_jo').innerHTML), trim($('nu_jo').innerHTML), trim($('pr_jo').innerHTML), $('tip_quantity').value, $('pr_tip').innerHTML, trim($('na_rs').innerHTML), trim($('nu_rs').innerHTML), trim($('pr_rs').innerHTML));
}

function checkSponsored(job_opening_id) {
	var params = 'job_opening_id=' + parseInt(job_opening_id);
	
	new Ajax.Request('/extra/sponsored_check.php',
		{
		method: 'get',
		parameters: params,
		asynchronous: false,
		onSuccess: function(response) {		// Set in-HTML status to OK if successful
				if (response.responseText == 'WARN') {
					if (confirm("WARNING:\n\nThis job posting is listed in one or more sponsored locations. When making a job posting inactive, it will be permanently REMOVED from these sponsored locations.\n\nAre you absolutely sure you want to deactivate this job posting?")) {
						setAjaxStatus('ajax_status_sponsored', 'OK');
					}
					else {
						setAjaxStatus('ajax_status_sponsored', 'CANCELLED');
					}
				}
				else {
					setAjaxStatus('ajax_status_sponsored', response.responseText);
				}
			},
		onFailure: function(response) {
				setAjaxStatus('ajax_status_sponsored', response.responseText);
			}
		}
		
	);
	
	
	// Check in-HTML value after the synchronous AJAX request and return the result
	if (getAjaxStatus('ajax_status_sponsored') == 'OK') {
		return true;
	} else {
		if (getAjaxStatus('ajax_status_sponsored') != 'CANCELLED') {
			alert('Error\n\n' + getAjaxStatus('ajax_status_sponsored'));
		}
		return false;
	}
}

// AJAX call voor het opvragen en bijwerken van de discount in het bestelformulier
function updateDiscount(package_name, package_number, package_amount) {
		var params = 'code=' + $('pp_voucher').value;
		
		new Ajax.Request('/extra/voucher.php',
			{
			method: 'get',
			parameters: params,
			onSuccess: function(response) {		// Set in-HTML status to OK if successful
					//if($('pp_voucher').value == '2for1' && $('package_1').checked) {
					//	$('discount_tr_3').innerHTML = '<td colspan="4" align="center" bgcolor="#EAFFE1" style="font-weight: bold; padding: 4px;">After the payment has been completed,<br />we will double your credit within 4 hours.</td>';
					//	$('ajax_multiplier').innerHTML = response.responseText;
					//	$('discount_tr_3').style.display = "";
					//	$('discount_tr_4').style.display = "";
					//}
					//else {
						$('ajax_multiplier').innerHTML = response.responseText;
					//	$('discount_tr_1').style.display = "";
					//$('discount_tr_2').style.display = "";
					//}
					showTotaal();
					updatePackageForm(trim($('na_jo').innerHTML), trim($('nu_jo').innerHTML), trim($('pr_jo').innerHTML), $('tip_quantity').value, $('pr_tip').innerHTML, trim($('na_rs').innerHTML), trim($('nu_rs').innerHTML), trim($('pr_rs').innerHTML));
				},
			onFailure: function(response) {
					$('ajax_multiplier').innerHTML = '1';
					//$('discount_tr_1').style.display = "none";
					//$('discount_tr_2').style.display = "none";
					//$('discount_tr_3').style.display = "none";
					//$('discount_tr_4').style.display = "none";
					
					showTotaal();
					updatePackageForm(trim($('na_jo').innerHTML), trim($('nu_jo').innerHTML), trim($('pr_jo').innerHTML), $('tip_quantity').value, $('pr_tip').innerHTML, trim($('na_rs').innerHTML), trim($('nu_rs').innerHTML), trim($('pr_rs').innerHTML));
				}
			}
			
		);
	//}
}

function optionCheckedMarkII(element) {
	if (element.value==14 && element.checked) {
		$('cb15').checked = false;
		$('cb16').checked = false;	
	}
	
	if (element.value==15 && element.checked) {
		$('cb14').checked = false;
		$('cb16').checked = false;
	}
	
	if (element.value==16 && element.checked) {
		$('cb14').checked = false;
		$('cb15').checked = false;
	}
	
	// vul alle hidden formulieropties
	var form_index = 1;
	var option_selected = false;
	var total_price = 0.00;
	var tips = parseInt($('tip_credit').innerHTML);

	for(i=10;i<17;i++) {
		
		if ($('cb' + i) != undefined && $('cb' + i).checked) {
			option_selected = true;
		
			if(!(i==10 && tips>0)) {
				$('pp_item_number_'+form_index).value = i;
				$('pp_item_number_'+form_index).name = "item_number_" + form_index;
				$('pp_amount_'+form_index).value = $('p_amount_'+i).innerHTML;
				$('pp_amount_'+form_index).name = "amount_" + form_index;
				$('pp_item_name_'+form_index).value = $('p_name_'+i).innerHTML;
				$('pp_item_name_'+form_index).name = "item_name_" + form_index;
				total_price = total_price + parseFloat($('p_amount_'+i).innerHTML);
				form_index++;
			}

		}
	}
	
	// zet de rest op 'undefined' zodat ze niet door paypal worden opgenomen
	for(i=form_index;i<6;i++) {
		$('pp_item_number_'+i).name = "item_number_undefined"+i;
		$('pp_amount_'+i).name = "amount_undefined"+i;
	}

	// zet totale prijs
	$('total_price').innerHTML = total_price.toFixed(2);
	
	// enable checkout button als we opties hebben geselecteerd
	if (option_selected) {
		$('check_out_button').disabled = '';
	}
	else {
		$('check_out_button').disabled = 'disabled';
	}
}

function testData() {
	$('title').value = "test";
	//$('description').innerHTML = "test";
	//tinyMCE.mce_editor_0.setContent("test");
	$('region_id').value = "24";
	$('job_sector_id').value = "23";
	$('job_category_id').value = "20";
}
/**
 * Enter package order information into the database using a synchronous AJAX call
 */
function enterPackageOrder(job_opening_id, voucher) {
	// Construct and execute the request
	
	var params = '';
	
	if (voucher != undefined) {
		params = params + 'voucher='+voucher+'&';
	}
	
	if(job_opening_id == undefined) {

		// Determine the values to send
		if ($('pp_amount_1').name == "amount_1") {
			params = params + 'item_number[0]=' + $('pp_item_number_1').value + '&';
		}
		
		if ($('pp_amount_2').name == "amount_1" || $('pp_amount_2').name == "amount_2") {
			params = params + 'item_number[1]='+$('pp_item_number_2').value+'&quantity[1]='+$('pp_quantity_2').value+'&';
		}
		
		if ($('pp_amount_3').name == "amount_1" || $('pp_amount_3').name == "amount_2" || $('pp_amount_3').name == "amount_3") {
			params = params + 'item_number[2]='+$('pp_item_number_3').value+'&';
			/*alert($('pp_item_number_3').value);*/
		}

		params = params + 'order_type='+$('order_type').value;
	}
	else {
		for (i = 0;i<5;i++) {
			if ($('pp_item_number_' + (i + 1)) == undefined || $('pp_item_number_' + (i + 1)).value == '') {
				break;
			}
			
			params = params + 'item_number['+i+']=' + $('pp_item_number_' + (i + 1)).value + '&';
		}
		
		params = params + 'order_type='+$('order_type').value+'&job_opening_id='+job_opening_id;
	}
	new Ajax.Request('/extra/order.php',
		{
		method: 'post',
		parameters: params,
		asynchronous: false,
		onSuccess: function(response) {		// Set in-HTML status to OK if successful
				setAjaxStatus('ajax_status', 'OK');
				$('pp_custom').value = response.responseText;
			},
		onFailure: function(response) {
			setAjaxStatus('ajax_status', response.responseText);
		}
		}
		
	);
	
	// Check in-HTML value after the synchronous AJAX request and return the result
	
	if (getAjaxStatus('ajax_status') == 'OK') {
		/*alert($('pp_quantity_2').value);*/
		return true;
	} else {
		alert('Error\n\n' + getAjaxStatus('ajax_status'));
		return false;
	}
}
function setOptions(job_opening_id) {
	// Construct and execute the request
	var params = 'job_opening_id='+job_opening_id;

	new Ajax.Request('/extra/set_options.php',
		{
		method: 'post',
		parameters: params,
		asynchronous: false,
		onSuccess: function(response) {		// Set in-HTML status to OK if successful
				// $return_value = $featured_job.'|'.$top3_search.'|'.$show_all.'|'.$top5_company.'|'.$tip_credit;
				var result = response.responseText.split('|');
				//alert(result[4]);
				if(result[0] == 0) {
					$('featured_job_option').style.color = '#CCC';
					$('featured_job_available').style.color = '#CCC';
					$('featured_job_available').style.backgroundColor = '#cfa1a1';
					$('featured_job_available').innerHTML = '<span style="font-size: 15px;">Unavailable</span>';
				}
				if(result[1] == 0) {
					$('top3_search_option').style.color = '#CCC';
					$('top3_search_available').style.color = '#CCC';
					$('top3_search_available').style.backgroundColor = '#cfa1a1';
					$('top3_search_available').innerHTML = '<span style="font-size: 15px;">Unavailable</span>';
				}
				if(result[2] == 0) {
					$('show_all_option').style.color = '#CCC';
					$('show_all_available').style.color = '#CCC';
					$('show_all_available').style.backgroundColor = '#cfa1a1';
					$('show_all_available').innerHTML = '<span style="font-size: 15px;">Unavailable</span>';
				}
				if(result[3] == 0) {
					$('company_option').style.color = '#CCC';
					$('company_avail2').style.color = '#CCC';
					$('company_avail2').style.backgroundColor = '#cfa1a1';
					$('company_avail2').innerHTML = '<span style="font-size: 15px;">Unavailable</span>';
					$('company_avail3').style.color = '#CCC';
					$('company_avail3').style.backgroundColor = '#cfa1a1';
					$('company_avail3').innerHTML = '<span style="font-size: 15px;">Unavailable</span>';
					$('company_avail6').style.color = '#CCC';
					$('company_avail6').style.backgroundColor = '#cfa1a1';
					$('company_avail6').innerHTML = '<span style="font-size: 15px;">Unavailable</span>';
				}
				$('tip_credit').innerHTML = '0';
				if(result[4] > 0) {
					$('tip_payment').innerHTML = '<br />Your TIP credit: '+result[4];
					$('tip_credit').innerHTML = result[4];
				}
				setAjaxStatus('ajax_status', 'OK');
				//$('pp_custom').value = response.responseText;
			},
		onFailure: function(response) {
				setAjaxStatus('ajax_status', response.responseText);
			}
		}
		
	);
	
	// Check in-HTML value after the synchronous AJAX request and return the result
	if (getAjaxStatus('ajax_status') == 'OK') {
		return true;
	} else {
		alert('Error\n\n' + getAjaxStatus('ajax_status'));
		return false;
	}
}

// AJAX call om job on the fly te publishen na het klikken op publish in de template lijst
function publishJob(job_opening_id) {
	var params = 'job_opening_id=' + parseInt(job_opening_id);
	
	new Ajax.Request('/extra/publish_job.php',
		{
		method: 'post',
		parameters: params,
		asynchronous: false,
		onSuccess: function(response) {		// Set in-HTML status to OK if successful
				setAjaxStatus('ajax_status', 'OK');
				setAjaxStatus('job_opening_id', parseInt(response.responseText));
			},
		onFailure: function(response) {
			setAjaxStatus('ajax_status', response.responseText);
		}
		}
		
	);
	
	// Check in-HTML value after the synchronous AJAX request and return the result
	
	if (getAjaxStatus('ajax_status') == 'OK') {
		return true;
	} else {
		alert('PUBLISH_JOB Error\n\n' + getAjaxStatus('ajax_status'));
		return false;
	}
}

// AJAX call om job on the fly te posten na het klikken op send in het keuze overzicht (tip, top 8 spot, etc)
function postJob() {
	// Construct and execute the request
	var params = 'title='+$('title').value+'&description='+escape($('job_description').value)+'&region[id]='+$('state').value+'&job_sector[id]='+$('job_sector_id').value+'&job_category[id]='+$('job_category_id').value+'&experience[id]='+$('experience_id').value+'&salary[id]='+$('salary_id').value+'&comment='+escape($('comment').value)+'&contact_name='+$('contact_name').value+'&contact_phone='+$('contact_phone').value+'&contact_fax='+$('contact_fax').value+'&contact_email='+$('contact_email').value+'&education[id]='+$('education_id').value+'&country[id]='+$('country_id').value+'&keywords='+escape($('keywords').value);
	if ($('on_board_a_ship').checked) {
		params = params + '&on_board_a_ship=1';
	}
	
	//'item_number1='+$('pp_item_number_1').value+'&item_number2='+$('pp_item_number_2').value+'&quantity1=1&quantity2='+$('pp_quantity_2').value;
	//alert(params);
	new Ajax.Request('/extra/post_job.php',
		{
		method: 'post',
		parameters: params,
		asynchronous: false,
		onSuccess: function(response) {		// Set in-HTML status to OK if successful
				/*var ajax_status = document.getElementById('ajax_status');
				var ajax_text = document.creatTextNode('OK');
				var job_opening_id = document.getElementById('job_opening_id');
				var job_opening_id_text = document.creatTextNode(response.responseText);
				ajax_status.appendChild(ajax_text); // = 'OK';
				job_opening_id.appendChild(job_opening_id_text); //innerHTML = response.responseText;*/
				setAjaxStatus('ajax_status', 'OK');
				setAjaxStatus('job_opening_id', response.responseText);
				//$('ajax_status').innerHTML = 'OK';
				//$('job_opening_id').innerHTML = response.responseText;
				//$('pp_custom').value = response.responseText;
			},
		onFailure: function(response) {
			/*var ajax_status = document.getElementById('ajax_status');
			var ajax_text = document.creatTextNode(response.responseText);
			ajax_status.appendChild(ajax_text); //innerHTML = response.responseText;*/
			setAjaxStatus('ajax_status', response.responseText);
			//$('ajax_status').innerHTML = response.responseText;
		}
		}
		
	);
	
	// Check in-HTML value after the synchronous AJAX request and return the result
	
	if (getAjaxStatus('ajax_status') == 'OK') {
		return true;
	} else {
		alert('POST_JOB Error\n\n' + getAjaxStatus('ajax_status'));
		return false;
	}
}
// AJAX call om een TOP 8 featured job (bijvoorbeeld) te locken, returnt false als er geen plaats meer vrij is.
function lockSpot(type, job_opening_id) {
	
	if(type == 17) {
		return true;
	}
	
	// Construct and execute the request
	var params = 'type='+type;
	if(job_opening_id != undefined) {
		params += '&job_opening_id='+job_opening_id;
	}

	new Ajax.Request('/extra/lock.php',
		{
		method: 'post',
		parameters: params,
		asynchronous: false,
		onSuccess: function(response) {		// Set in-HTML status to OK if successful
				setAjaxStatus('ajax_status_lock', 'OK');
				//$('pp_custom').value = response.responseText;
			},
		onFailure: function(response) {
			setAjaxStatus('ajax_status_lock', response.responseText);
		}
		}
		
	);
	
	// Check in-HTML value after the synchronous AJAX request and return the result
	
	if (getAjaxStatus('ajax_status_lock') == 'OK') {
		return true;
	} else {
		alert('LOCK Error\n\n' + getAjaxStatus('ajax_status_lock'));
		return false;
	}
}

function placeTip(job_opening_id) {
	// Construct and execute the request
	var params = 'job_opening_id='+job_opening_id;

	new Ajax.Request('/extra/tip.php',
		{
		method: 'post',
		parameters: params,
		asynchronous: false,
		onSuccess: function(response) {		// Set in-HTML status to OK if successful
				setAjaxStatus('ajax_status_tip', 'OK');
				//$('pp_custom').value = response.responseText;
			},
		onFailure: function(response) {
			setAjaxStatus('ajax_status_tip', response.responseText);
		}
		}
		
	);
	
	// Check in-HTML value after the synchronous AJAX request and return the result
	
	if (getAjaxStatus('ajax_status_tip') == 'OK') {
		return true;
	} else {
		alert('TIP Error\n\n' + getAjaxStatus('ajax_status_tip'));
		return false;
	}
}

function lock_order() {
	var n = 0;
	var checks = document.getElementsByClassName('option_check');
	for(var i=0; i < checks.length; i++) {
		if(checks[i].checked) {
			if(!(parseInt(checks[i].value) == 10 && parseInt($('tip_credit').innerHTML) > 0)) {
				n++;
			}
			// if we have a tip, place it directly using credit... else order it
			if(parseInt(checks[i].value) == 10 && parseInt($('tip_credit').innerHTML) > 0) {
				if (!placeTip(getAjaxStatus('job_opening_id'))) {
					return false;
				}
			}
			else if(parseInt(checks[i].value) == 14 || parseInt(checks[i].value) == 15 || parseInt(checks[i].value) == 16) {
				if(!lockSpot(checks[i].value, undefined)) {
					return false;
				}
			}
			else {
				if (parseInt(checks[i].value) != 10) {
					if(!lockSpot(checks[i].value, getAjaxStatus('job_opening_id'))) {
						return false;
					}
				}
			}
		}
	}
	//alert(n);
	// return to job opening when we only have a 'prepaid' tip to place
	if (n == 0) {
		location.href = "/job-openings/show/" + getAjaxStatus('job_opening_id');
		return false;
	}
	
	return enterPackageOrder(getAjaxStatus('job_opening_id'), undefined);
}

function publish(id) {
	if(confirm('Your template will be published as a job posting and wil cost you 1 credit. Are you sure?')) {
		window.location="/job-openings/templates/publish/"+id;
	}
}
function delete_template(id) {
	if(confirm('Your template will be deleted. Are you sure?')) {
		window.location="/job-openings/templates/delete/"+id;
	}
}
function clearField() {
	if(document.signup_form.captcha.value == 'Enter safety code here') {
		document.signup_form.captcha.value = '';
		document.signup_form.captcha.style.color = '#000';
	}
}
function chooseCompanyMonths(element, item_nr, item_name, amount ) {
	if(element.checked) {
		$('pp_item_name_1').value = item_name;
		$('pp_item_number_1').value = item_nr;
		$('pp_amount_1').value = amount;
		$('check_out_button').disabled = '';
		$('total_price').innerHTML = amount;
	}
	else {
		$('check_out_button').disabled = 'disabled';
	}
	
}
function checkOptionsSet() {
	if($('pp_quantity_1').value !=0 || $('pp_quantity_2').value !=0 || $('pp_quantity_3').value !=0 || $('pp_quantity_4').value !=0) {
		return true;
		//enterPackageOrder();
		//document.job_opening_shopping_card.submit();
	}
}
function hideShowSelect(hide_show) {
	var selectList = document.getElementsByTagName('select');
	for (i = 0; i<selectList.length; i++) {
		selectList[i].style.visibility = hide_show; 
    } 
	var bodyTag = document.getElementsByTagName('body');
	bodyTag[0].style.overflow = hide_show;
	var htmlTag = document.getElementsByTagName('html');
	htmlTag[0].style.overflow = hide_show;
}

/**
 * Trek m.b.v. AJAX de states van het geselecteerde land uit de database en
 * duw deze in het state pulldown menu. WERKGEVERS
 */
function updateVisitorStates(country_menu) {

	
	var params = 'country_id='+country_menu.options[country_menu.selectedIndex].value;
	
	
	new Ajax.Request('/extra/states.php',
		{
		method: 'get',
		parameters: params,
		onSuccess:
		function(transport) {
			var state_menu = $('visitor_state');
			
			if (transport.responseText == "") {
				alert("Error occurred while fetching states");
				return;
			}
			
			while (state_menu.length > 0) {
	                state_menu.remove(0);
	        }
			
			if (transport.responseText == "EMPTY") {
				$('visitor_state_div').style.display="none";
				return;
			}
			
			var states = transport.responseText.split("\n");
			
			
			
			
			// Reset the account drop down menu first
			        
	        while (state_menu.length > 0) {
	                state_menu.remove(0);
	        }
	        var initial_option = document.createElement("option");


	        initial_option.value = "";
	        initial_option.text = "-- Choose State/Region --";

	        state_menu[state_menu.length] = initial_option;

					for (var j = 0; j < states.length; j++) {
						var state_info = states[j].split("|");


				if (state_info.length < 2) {
					continue;
				}

				// Compile the name.
				var state_info_name = "";
				for (var i = 1; i < state_info.length; i++) {
					state_info_name = state_info_name + state_info[i];
					if (i < state_info.length - 1) {
						state_info_name = state_info_name + "|";
					}
				}

				// Now that we have the id and name, add them to the account drop down menu
				var state_option = document.createElement("option");
				state_option.value = state_info[0];
				state_option.text = state_info_name;

				state_menu[state_menu.length] = state_option;

				// Enable the menu
				$('visitor_state_div').style.display="block";
			}
			
			
		}
		}
	);
}

/**
 * Trek m.b.v. AJAX de states van het geselecteerde land uit de database en
 * duw deze in het state pulldown menu.
 */
function updateStates(country_menu, national) {

	
	var params = 'country_id='+country_menu.options[country_menu.selectedIndex].value;
	if (national) {
		params = params + '&national=1';
	}
	
	new Ajax.Request('/extra/states.php',
		{
		method: 'get',
		parameters: params,
		onSuccess:
		function(transport) {
			var state_menu = $('state');
			
			if (transport.responseText == "") {
				alert("Error occurred while fetching states");
				return;
			}
			
			while (state_menu.length > 0) {
	                state_menu.remove(0);
	        }
			if (transport.responseText == "EMPTY") {
				$('state_div').style.display="none";
				return;
			}
			
			var states = transport.responseText.split("\n");
			
			// Reset the account drop down menu first
			        
       while (state_menu.length > 0) {
               state_menu.remove(0);
       }
       var initial_option = document.createElement("option");


       initial_option.value = "";
       initial_option.text = "-- Choose State/Region --";

       state_menu[state_menu.length] = initial_option;
      
			for (var j = 0; j < states.length; j++) {
				var state_info = states[j].split("|");


				if (state_info.length < 2) {
					continue;
				}

				// Compile the name.
				var state_info_name = "";
				for (var i = 1; i < state_info.length; i++) {
					state_info_name = state_info_name + state_info[i];
					if (i < state_info.length - 1) {
						state_info_name = state_info_name + "|";
					}
				}

				// Now that we have the id and name, add them to the account drop down menu
				var state_option = document.createElement("option");
				state_option.value = state_info[0];
				state_option.text = state_info_name;

				state_menu[state_menu.length] = state_option;
				
				if ($('state_div').style.display!="block") {
					$('state_div').style.display="block";
				}
			}

			
			
		}
		}
	);
}

/**
 * Trek m.b.v. AJAX de states van het geselecteerde land uit de database en
 * duw deze in het search formulier.
 */
function updateStatesSearch(country_menu, national) {

	$('div_regions').style.display="none";
	//$('p_regions_intl').style.display="none";
	//$('p_regions_empty').style.display="none";
	//$('p_regions_all').style.display="none";
	$('p_regions_sa').style.display="none";
	$('i_regions_sa').style.display="none";

	// Alles
	/*if (country_menu.value == '') {
		$('p_regions_all').style.display="block";
		return;
	}*/
	
	// Internationaal
	/*if (country_menu.value == '0') {
		$('p_regions_intl').style.display="block";
		return;
	}*/
	
	// Vraag regio's op
	var params = 'country_id='+country_menu.options[country_menu.selectedIndex].value;
	if (national) {
		params = params + '&national=1';
	}
	
	new Ajax.Request('/extra/states.php',
		{
		method: 'get',
		parameters: params,
		onSuccess:
		function(transport) {
			var state_menu = $('state');
			
			if (transport.responseText == "") {
				alert("Error occurred while fetching states");
				return;
			}
			
			if (transport.responseText == "EMPTY") {
				//$('p_regions_empty').style.display="block";
				return;
			}
			
			$('p_regions_sa').style.display="block";
			$('i_regions_sa').checked = false;
			$('i_regions_sa').style.display="block";
			
			var states = transport.responseText.split("\n");
			
			 $('regions_list').innerHTML = '';
      
			for (var j = 0; j < states.length; j++) {
				var state_info = states[j].split("|");
				
				if (state_info.length < 2) {
					continue;
				}

				// Compile the name.
				var state_info_name = "";
				for (var i = 1; i < state_info.length; i++) {
					state_info_name = state_info_name + state_info[i];
					if (i < state_info.length - 1) {
						state_info_name = state_info_name + "|";
					}
				}

		    $('regions_list').innerHTML = $('regions_list').innerHTML + '<p class="search"><input id="region[]" name="region[]" onclick=" toggleSelectAllCheckBox(\'region_select_all\', \'region[]\')" type="checkbox" value="'+state_info[0]+'" /> '+state_info_name+'</p>';

				
				if ($('div_regions').style.display!="block") {
					$('div_regions').style.display="block";
				}
			}

			
			
		}
		}
	);
}

function showExtraOptions() {
	$('job_posted').style.display = 'none';
	$('job_posting_card').style.height = '546px';
	$('extra_options').style.display = 'block';
}
function enableCheckOut() {
	if($('job_opening_id').value != '') {
		//$('check_out_button_disabled').style.display = 'none';
		$('check_out_button').disabled = '';
	}
	else {
		//$('check_out_button_disabled').style.display = 'block';
		$('check_out_button').disabled = 'disabled';
	}
}

function showPriceTable() {
	$('price_table').width = '100%';
	$('price_table').style.width = '100%';
	$('price_table').style.display = 'inline';
	
}
function openBox() {
	hideShowSelect('hidden');
	window.scroll(0,0);
	$('overlay').style.display = 'block';
	$('job_posting_card').style.display = 'block';
}
function closeBox() {
	hideShowSelect('');
	$('overlay').style.display = 'none';
	$('job_posting_card').style.display = 'none';
}

function showCourses(el) {
	if (el.value != '') {
		new Ajax.Request('/extra/courses.php',
			{
				method: 'post',
				parameters: 'school_id='+el.value,
				asynchronous: true,
				onSuccess: function(response) {		
					// Set in-HTML status to OK if successful
					//$('ajax_status').innerHTML = 'OK';
					$('select_courses').innerHTML = response.responseText;
				},
				onFailure: function(response) {
					$('select_courses').innerHTML = response.responseText;
				}
			}
		);
	}
}

function showSchools(el) {
	if (el.value != '') {
		new Ajax.Request('/extra/schools.php',
			{
				method: 'post',
				parameters: 'country_id='+el.value,
				asynchronous: true,
				onSuccess: function(response) {		
					// Set in-HTML status to OK if successful
					//$('ajax_status').innerHTML = 'OK';
					$('select_schools').innerHTML = response.responseText;
				},
				onFailure: function(response) {
					$('select_schools').innerHTML = response.responseText;
				}
			}
		);
	}
}



/*function hideShowSelect(hide_show) {
	var selectList = document.getElementsByTagName('select');
	for (i = 0; i<selectList.length; i++) {
		selectList[i].style.visibility = hide_show; 
    } 
	var bodyTag = document.getElementsByTagName('body');
	bodyTag[0].style.overflow = hide_show;
	var htmlTag = document.getElementsByTagName('html');
	htmlTag[0].style.overflow = hide_show;
}*/


function updatePrefStates(country_menu, national) {

	$('region_id').style.display="none";

	var params = 'country_id='+country_menu.options[country_menu.selectedIndex].value;
	if (national) {
		params = params + '&national=1';
	}
	
	new Ajax.Request('/extra/states.php',
		{
		method: 'get',
		parameters: params,
		onSuccess:
		function(transport) {
			var state_menu = $('region_id');
			
			if (transport.responseText == "") {
				alert("Error occurred while fetching states");
				return;
			}
			
			if (transport.responseText == "EMPTY") {

				return;
			}
			
			//$('p_regions_sa').style.display="block";
			//$('i_regions_sa').checked = false;
			//$('i_regions_sa').style.display="block";
			
			var states = transport.responseText.split("\n");
			
			 //$('regions_list').innerHTML = '';
      		$('region_id').innerHTML = '<option value="">-- Choose State --</option><option value="1">Worldwide</option><option value="55">National</option><option value="53">US</option>'
			for (var j = 0; j < states.length; j++) {
				var state_info = states[j].split("|");
				
				if (state_info.length < 2) {
					continue;
				}

				// Compile the name.
				var state_info_name = "";
				for (var i = 1; i < state_info.length; i++) {
					state_info_name = state_info_name + state_info[i];
					if (i < state_info.length - 1) {
						state_info_name = state_info_name + "|";
					}
				}

		    $('region_id').innerHTML += '<option value="'+state_info[0]+'" > '+state_info_name+'</option>';

				
				if ($('region_id').style.display!="block") {
					$('region_id').style.display="block";
				}
			}
			$('region_id').innerHTML += '<option value="52">Other</option>';

			
			
		}
		}
	);
}

function setAjaxStatus(status_name, status_value) {
	if ($('ajax_status_field_' + status_name) == undefined) {	// Bestaat niet, maak nieuwe

		var container = $('ajax_status_container');
	
		var element = document.createElement('span');
		element.id = "ajax_status_field_" + status_name;
	
		var text = document.createTextNode(status_value);
	
		element.appendChild(text);
	
		container.appendChild(element);
	}
	else {	// Bestaat al, vervang oude waarde
		$('ajax_status_field_' + status_name).firstChild.nodeValue = status_value;
	}
}

function getAjaxStatus(status_name) {
	var status = $('ajax_status_field_' + status_name);

	return status.firstChild.nodeValue;
}

function countKeywords(e, string) {
	var keynum;
	var keychar;
	var numcheck;

	if(window.event) { // IE
		keynum = e.keyCode;
	}
	else if(e.which) {// Netscape/Firefox/Opera
		keynum = e.which;
	}
	keychar = String.fromCharCode(keynum);
	
	if(keychar == ',') {
		var arr   = string.split(',');
		var count = arr.length;
		if(count + 1 > 10) {
			alert('You can enter up to 10 unique keywords, separated by comma.');
			return false;
		}
	}
}

function openVoucherPanel() {
	new Effect.Fade($('voucher_closed'), {duration: 0.5, queue: 'end'});
	new Effect.Appear($('voucher_opened'), {duration: 0.5, queue: 'end'});
}

function resetPurchaseBackgrounds() {
	var divs = document.getElementsByClassName('package_div');
	var i;
	for (i =0; i<divs.length; i++) {
		divs[i].style.backgroundColor = '#f4f4f4';
	}
}