function requireInput( id){
	var obj = document.getElementById(id);
	if (document.getElementById(id).value == ''){
		return false;
	}else{
		return true;
	}
}
function emailInput(id){
	regex=/^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
	return regex.test(document.getElementById(id).value);
}
function numericInput(id){
	regex=/^(\d|-)?(\d|,)*\.?\d*$/;
	return regex.test(document.getElementById(id).value);
}

function showMsg(final_msg){

	if (final_msg != ''){
		//		jQuery('.message').show();
		jQuery('.message').html('<div class="message_error_small"><ul>'+final_msg+'</ul></div>');
		//		jQuery('.message').fadeOut(8000);
		return false;
	}else{
		return true;
	}
}
function leftShowMsg(final_msg){

	if (final_msg != ''){
		//		jQuery('.message').show();
		jQuery('#an_message').html('<div class="message_error_left"><ul>'+final_msg+'</ul></div>');
		//		jQuery('.message').fadeOut(8000);
		return false;
	}else{
		return true;
	}
}

// specificaly called
function setUsername(){
	document.getElementById('username').value = document.getElementById('email').value;
}
function Registration(logged){
	setUsername();
	final_msg = '';
	if(!requireInput('first_name')){
		final_msg = final_msg + '<li>Please enter your first name.</li>';
	}
	if(!requireInput('last_name')){
		final_msg = final_msg + '<li>Please enter your last name.</li>';
	}
	if(!requireInput('email')){
		final_msg = final_msg + '<li>Please enter an email address.</li>';

	}
	if(!emailInput('email')){
		final_msg = final_msg + '<li>Please enter a valid email address.</li>';
	}
	if(!requireInput('re_email')){
		final_msg = final_msg + '<li>Please repeat your email address.</li>';

	}
	if(!emailInput('re_email')){
		final_msg = final_msg + '<li>Please enter valid Email address</li>';
	}
	if(requireInput('re_email') && requireInput('email')){
		if(document.getElementById('email').value != document.getElementById('re_email').value){
			final_msg = final_msg + '<li>Please check that your email address has been entered and repeated correctly.</li>';
		}
	}

	if(logged == 1){

		if(!requireInput('password')){
			final_msg = final_msg + '<li>Please enter a password.</li>';
		}
		if(!requireInput('password2')){
			final_msg = final_msg + '<li>Please repeat your password.</li>';
		}
		if(document.getElementById('password').value != document.getElementById('password2').value || !requireInput('password2') || !requireInput('password')){
			final_msg = final_msg + '<li>Please check your password has been entered and repeated correctly.</li>';
		}
	}
	if(document.getElementById('i_agree').checked == false){
		final_msg = final_msg + '<li>You will need to agree to our terms and conditions to register with Business Change Jobs.</li>';
	}
	return showMsg(final_msg);
}
function RegisterCV_1(){
	final_msg = '';

	if(!requireInput('cv_title')){
		final_msg = final_msg + '<li>Please enter the CV title</li>';
	}
	temp = document.getElementById('getSpecialisationCount').value;
	var SpecialisationFlag = 0;
	for(i = 0 ; i <temp ; i++){
		if(document.getElementById("getSpecialisation_"+i).checked == true){
			SpecialisationFlag = 1;
		}
	}
	if(SpecialisationFlag == 0){
		final_msg = final_msg + "<li>Please select at least one Specialisation.</li>";
	}

	if(document.getElementById('Permanent').checked == true || document.getElementById('Contract').checked == true){
	}else{
		final_msg = final_msg + "<li>Please select at least one Position</li>";
	}

	temp = document.getElementById('getLocationCount').value;
	var LocationFlag = 0;
	for(i = 0 ; i <temp ; i++){
		if(document.getElementById("getLocation_"+i).checked == true){
			LocationFlag = 1;
		}
	}
	if(LocationFlag == 0){
		final_msg = final_msg + "<li>Please select at least one Location</li>";
	}

	if(!requireInput('desired_salary')){
		final_msg = final_msg + '<li>Please enter the desired salary</li>';
	}
	if(!requireInput('desired_title')){
		final_msg = final_msg + '<li>Please enter the desired title</li>';
	}

	return showMsg(final_msg);
}
function RegisterCV_2(){
	final_msg = '';
	var sector_exp = document.getElementById('sector_exp');
	var sector_exp_flag = 0;
	for (var j = 0; j < sector_exp.length; j++){
		if(sector_exp.options[j].selected == true){
			sector_exp_flag = 1;
		}
	}
	if(sector_exp_flag == 0){
		final_msg = final_msg + '<li>Please select at least one sector experience</li>';
	}

	var highest_qualification = document.getElementById('highest_qualification');
	var highest_qualification_flag =0;
	for (var j = 0; j < highest_qualification.length; j++){
		if(highest_qualification.options[j].selected == true){
			highest_qualification_flag = 1;
		}
	}
	if(highest_qualification_flag == 0){
		final_msg = final_msg + '<li>Please select at least one highest qualification</li>';
	}

	if(!requireInput('current_job_title')){
		final_msg = final_msg + '<li>Please enter the current job title</li>';
	}if(!requireInput('current_salary')){
		final_msg = final_msg + '<li>Please enter the current salary</li>';
	}
	if(document.getElementById('eligibility_yes').checked == true || document.getElementById('eligibility_no').checked == true){
	}else{
		final_msg = final_msg + '<li>Please select at least one work eligibility</li>';
	}
	return showMsg(final_msg);
}
function RegisterCV_3(){
	final_msg = '';
	if(!requireInput('mobile_phone') && !requireInput('office_phone') && !requireInput('home_phone') ){
		final_msg = final_msg + '<li>Please enter at least one phone number</li>';
	}
	if(document.getElementById('edit').value == 'false'){
		if(!requireInput('cv_url')){
			final_msg = final_msg + '<li>Please choose upload your CV</li>';
		}
	}
	if(document.getElementById('cv_url').value != ''){
		if(document.getElementById('cv_url').value.lastIndexOf(".doc")==-1){
			final_msg = final_msg + '<li>Only *.doc files are allowed</li>';
		}
	}

	if(document.getElementById('privacy_o').checked == true || document.getElementById('privacy_h').checked == true
	|| document.getElementById('privacy_c').checked == true){

	}else{
		final_msg = final_msg + '<li>Please select at least one privacy setting</li>';
	}
	return showMsg(final_msg);
}

function validateVacancyForm(preview){
	final_msg = '';
	if(!requireInput('title')){
		final_msg = final_msg + '<li>Please enter title of the vacancy</li>';
	}
	if(!requireInput('location_detail')){
		final_msg = final_msg + '<li>Please enter Location detail</li>';
	}

	var location_category = document.getElementById('location_category');
	var location_category_flag =0;
	for (var j = 0; j < location_category.length; j++){
		if(location_category.options[j].selected == true){
			location_category_flag = 1;
		}
	}
	if(location_category_flag == 0){
		final_msg = final_msg + '<li>Please select at least one location category</li>';
	}

	if(!requireInput('compensation_detail')){
		final_msg = final_msg + '<li>Please enter compensation detail</li>';
	}
	if(!requireInput('job_type_detail')){
		final_msg = final_msg + '<li>Please enter job type detail</li>';
	}


	var specialisation = document.getElementById('specialisation');
	var specialisation_flag =0;
	for (var j = 0; j < specialisation.length; j++){
		if(specialisation.options[j].selected == true){
			specialisation_flag = 1;
		}
	}
	if(specialisation_flag == 0){
		final_msg = final_msg + '<li>Please select at least one specialisation</li>';
	}
	if(!requireInput('start_date')){
		final_msg = final_msg + '<li>Please enter start date</li>';
	}
	if(!requireInput('end_date')){
		final_msg = final_msg + '<li>Please enter end date</li>';
	}
	if (document.getElementById('application_mode_link').checked == true){
		if(!validateURL2(document.getElementById('application_link').value)){
			final_msg = final_msg + '<li>Please enter a valid URL.</li>';

		}
	}
	if (final_msg != ''){
		window.location="#error";
	}
	if(preview){ // if preview is asked
		showPreview(final_msg);
	}else{ // user enters the submit button
		return leftShowMsg(final_msg);
	}

}

function applyEmailJob(){

	i_agree = document.getElementById('i_agree').checked;
	email = document.getElementById('email').value;
	re_email = document.getElementById('re_email').value;
	final_msg = '';
	if(!requireInput('first_name')){
		final_msg = final_msg + '<li>Please enter your first name.</li>';
	}
	if(!requireInput('last_name')){
		final_msg = final_msg + '<li>Please enter your last name.</li>';
	}
	if(!requireInput('email')){
		final_msg = final_msg + '<li>Please enter your email address.</li>';

	}else {
		if(!emailInput('email')) {
			final_msg = final_msg + '<li>Please enter valid email address.</li>';
		}
	}
	if(!requireInput('re_email')){
		final_msg = final_msg + '<li>Please re-enter your email address.</li>';
	}else {
		if(!emailInput('re_email')) {
			final_msg = final_msg + '<li>Please re-enter valid email address.</li>';
		}
	}
	if(email != re_email){
		final_msg = final_msg + '<li>Both the email addresses should be same.</li>';
	}
	if(!requireInput('cv_url')){
		final_msg = final_msg + '<li>Please choose CV to upload.</li>';
	}

	if(i_agree != true){
		final_msg = final_msg + '<li>Please agree terms and conditions.</li>';
	}
	return leftShowMsg(final_msg);
}

function showPreview(final_msg){
	/*
	'adminFormMainDivPreview'
	'adminFormMainDiv'
	*/
	if (final_msg != ''){
		jQuery('#an_message').html('<div class="message_error_left"><ul>'+final_msg+'</ul></div>');
		return false;
	}else{
		/*
		title = document.getElementById('title').value;
		location_detail = document.getElementById('location_detail').value;
		job_type_category = document.getElementById('job_type_category');
		job_type_category_str = '';
		for (var j = 0; j < job_type_category.length; j++){
		if(job_type_category.options[j].selected == true){
		job_type_category_str = job_type_category.options[j].text;
		if(job_type_category.options[j].value == 1){
		temp_cat = document.getElementById('compensation_cat_p');
		compensation_cat = temp_cat.options[temp_cat.selectedIndex].text;
		}else{
		temp_cat = document.getElementById('compensation_cat_c');
		compensation_cat = temp_cat.options[temp_cat.selectedIndex].text;
		}
		}
		}




		job_type_detail = document.getElementById('job_type_detail').value;
		compensation_detail = document.getElementById('compensation_detail').value;
		start_date = document.getElementById('start_date').value;
		end_date = document.getElementById('end_date').value;
		application_link = document.getElementById('application_link').value;
		application_email = document.getElementById('application_email').value;
		body = tinyMCE.getContent('body');


		specialisation = document.getElementById('specialisation');
		specialisation_arr = new Array();
		for (var j = 0; j < specialisation.length; j++){
		if(specialisation.options[j].selected == true){
		specialisation_arr.push(specialisation.options[j].text);
		}
		}

		location_category = document.getElementById('location_category');
		location_category_arr = new Array();
		for (var j = 0; j < location_category.length; j++){
		if(location_category.options[j].selected == true){
		location_category_arr.push(location_category.options[j].text);
		}
		}

		jQuery('#adminFormMainDiv').hide();
		var html = "<table class='admintable' cellspacing='10px' width='480px' border='0'>";
		html = html + "<tr>";
		html = html + "<td><label>Vacancy Title</label></td>";
		html = html + "<td>"+title+"</td>";
		html = html + "</tr>";
		html = html + "<tr>";
		html = html + "<td><label>Location</label></td>";
		html = html + "<td>"+location_category_arr.join(', ')+"</td>";
		html = html + "</tr>";
		html = html + "<tr>";
		html = html + "<td><label>Location Detail</label></td>";
		html = html + "<td>"+location_detail+"</td>";
		html = html + "</tr>";
		html = html + "<tr>";
		html = html + "<td><label>Job Type</label></td>";
		html = html + "<td>"+job_type_category_str+"</td>";
		html = html + "</tr>";
		html = html + "<tr>";
		html = html + "<td><label>Job Type Detail</label></td>";
		html = html + "	<td>"+job_type_detail+"</td>";
		html = html + "</tr>";
		html = html + "<tr>";
		html = html + "<td><label>Compensation</label></td>";
		html = html + "<td>"+compensation_cat+"</td>";
		html = html + "</tr>";
		html = html + "<tr>";
		html = html + "<td><label>Compensation Detail</label></td>";
		html = html + "<td>"+compensation_detail+"</td>";
		html = html + "</tr>";
		html = html + "<tr>";
		html = html + "<td><label>Specialisation</label></td>";
		html = html + "<td>"+specialisation_arr.join(', ')+"</td>";
		html = html + "</tr>";
		html = html + "<tr>";
		html = html + "<td><label>Start Date</label></td>";
		html = html + "<td>"+start_date+"</td>";
		html = html + "</tr>";
		html = html + "<tr>";
		html = html + "<td><label>End Date</label></td>";
		html = html + "<td>"+end_date+"</td>";
		html = html + "</tr>";
		html = html + "<tr>";
		html = html + "<td><label>Application Link</label></td>";
		html = html + "<td>"+application_link+"</td>";
		html = html + "</tr>";
		html = html + "<tr>";
		html = html + "<td><label>Your advertisement</label></td>";
		html = html + "<td>"+body+"</td>";
		html = html + "</tr>";
		html = html + "<tr>";
		html = html + "<td></td>";
		html = html + '<td><input type="button" onclick="previewClose();" value="&nbsp;" class="button-edit" />&nbsp;&nbsp;<input type="button" id="submit2" name="submit2" onclick="document.adminForm.submit();" value="&nbsp;" class="button_reg_logged" /></td>';
		html = html + "</tr>";
		html = html + "</table>";*/
		//		jQuery('#adminFormMainDivPreview').html(html);
		//		jQuery('#adminFormMainDivPreview').show();
		//		var newWindow = window.open('index.php?option=com_vacancy&Itemid=57&task=preview_job', '_blank');
		jQuery('#adminForm').attr({target:"_blank", action:"index.php?option=com_vacancy&Itemid=53"});
		document.getElementById('task').value = "preview_job";
		document.adminForm.submit();
		jQuery('#adminForm').attr({target:"", action:"index.php"});
		document.getElementById('task').value = "saveVacancy";
		return true;
	}
}
function previewClose(){
	jQuery('#adminFormMainDivPreview').hide();
	jQuery('#adminFormMainDiv').show();
}

function recruiter_detail(){
	final_msg = '';
	var obj_value  = document.getElementById('r_logo_img_path').value;
	if(obj_value != ''){
		extenstion = obj_value.split('.');
		if(extenstion[1] == 'jpeg' || extenstion[1] == 'jpg' || extenstion[1] == 'gif' || extenstion[1] == 'png'){
		}else{
			final_msg = final_msg + 'Only *.jpeg, *.jpg, *.gif, *.png  files are allowed<br />';
		}
	}
	return leftShowMsg(final_msg);
	//	return showMsg(final_msg);
}


function ValidateRegiterForm(){
	final_msg = '';

	return showMsg(final_msg);
}

function change_pass(){
	final_msg ='';
	if(!requireInput('password')){
		final_msg = final_msg + 'Please enter new password<br />';
	}
	if(!requireInput('re_password')){
		final_msg = final_msg + 'Please re-enter password<br />';
	}
	if(document.getElementById('password').value != document.getElementById('re_password').value){
		final_msg = final_msg + 'Password and confirmation Password doesn\'t match <br />';
	}
	return showMsg(final_msg);
}
function getaccount(){
	final_msg ='';
	if(!requireInput('first_name')){
		final_msg = final_msg + 'Please enter your first name<br />';
	}
	if(!requireInput('last_name')){
		final_msg = final_msg + 'Please enter your last name<br />';
	}
	return showMsg(final_msg);
}

function validateURL2(value) {
	var v = new RegExp();
	v.compile("^[A-Za-z]+://[A-Za-z0-9-]+\.[A-Za-z0-9]+");
	if (!v.test(value)) {
		return false;
	}else{
		return true;
	}
}
