var win = null;
function openWindow(URL,name,w,h,scroll) {
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',toolbar=no,location=no,directories=no,maximise=no,resizable=no,status=no,menubar=no','scroll','keep'
	win = window.open(URL,name,settings)
	if(win.window.focus){win.window.focus();}
}

function showOffer(idOffer) {
	openWindow('/offer.asp?idOffer=' + idOffer, '_blank', 400, 500, 'no')
}

function validate(form) {
	if (form.usersPassword1.value = form.usersPassword2.value) {
		form.submit();
	} else {
		alert("password fields are not the same !");
	}

}

function validateUser(form) {
	var msg = "";
	if(form.usersName.value=="") {
		msg += "You must give a name to this user\n";
	}
	
	if(form.usersLogin.value=="") {
		msg += "You must give a login to this user\n";
	}
	
	if (form.usersPassword1.value != form.usersPassword2.value) {
		msg += "Password fields are not the same !\n";
	}
	
	if(form.idCountry.value==0) {
		msg += "you must choose a country\n";
	}
	
	if(msg=="") {
		form.submit();
	} else {
		alert("the following error(s) occured:\n\n" + msg);
	}

}

function check_email(e) {
	ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm./@-_QWERTYUIOPASDFGHJKLZXCVBNM";
	for(i=0; i < e.length ;i++) {
		if(ok.indexOf(e.charAt(i))<0) { 
			return (false);
		}	
	} 
	if (document.images) {
		re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two)) {
			return (-1);		
		} 
	}
}

function applyJob(form) {
	var msg = "";
	if (form.elements["firstName"].value == "") {
		msg += "You must fill the first name field\n";
	}
	if (form.elements["name"].value == "") {
		msg += "You must fill the name field\n";
	}
	if (form.elements["email"].value == "") {
		msg += "You must fill the email field\n";
	} else {
		if (!check_email(form.elements["email"].value)) {
			msg += "You email address is not correct\n"
		}
	}
	if (form.elements["country"].value == "") {
		msg += "You must fill the country field\n";
	}
	if (form.elements["resume"].value == "") {
		msg += "You must attach a resume\n";
	}
	
	if (msg == "") {
		form.submit();
	} else {
		alert(msg);
	}
}


function DeActiveDate(_f, _b) {
	_f.elements["websiteDiffusionDateYear"].disabled = _b;
	_f.elements["websiteDiffusionDateMonth"].disabled = _b;
	_f.elements["websiteDiffusionDateDay"].disabled = _b;
	_f.elements["endDiffusionDateYear"].disabled = _b;
	_f.elements["endDiffusionDateMonth"].disabled = _b;
	_f.elements["endDiffusionDateDay"].disabled = _b;
}

function DeActiveCorporateDate(_f, _b) {
	_f.elements["corporateDiffusionDateYear"].disabled = _b;
	_f.elements["corporateDiffusionDateMonth"].disabled = _b;
	_f.elements["corporateDiffusionDateDay"].disabled = _b;
	_f.elements["endCorporateDiffusionDateYear"].disabled = _b;
	_f.elements["endCorporateDiffusionDateMonth"].disabled = _b;
	_f.elements["endCorporateDiffusionDateDay"].disabled = _b;
}

function DeActiveLocalDate(_f, _b) {
	_f.elements["localDiffusionDateYear"].disabled = _b;
	_f.elements["localDiffusionDateMonth"].disabled = _b;
	_f.elements["localDiffusionDateDay"].disabled = _b;
	_f.elements["endLocalDiffusionDateYear"].disabled = _b;
	_f.elements["endLocalDiffusionDateMonth"].disabled = _b;
	_f.elements["endLocalDiffusionDateDay"].disabled = _b;
}

function CheckPubli(_f) {
	var msg = "";
	if (_f.elements["offersReference"].value == "") {
		msg += "You must fill the reference field\n";
	}
	if (_f.elements["offersTitle"].value == "") {
		msg += "You must fill the title field\n";
	}
	if (_f.elements["offersPositionStatus"].value == "") {
		msg += "You must fill the position status field\n";
	}
	if (_f.elements["offersMission"].value == "") {
		msg += "You must fill the job description field\n";
	}
	if (_f.elements["offersProfile"].value == "") {
		msg += "You must fill the profile field\n";
	}
	if (msg != "") {
		alert(msg);
		return false;
	} else {
		return true;
	}
}

function preview(_f) {
	_f.target = "_blank";
	_f.enctype="multipart/form-data"
	_f.action = "/admin/edit_offer.asp?ok=prev";
	_f.submit();
	_f.enctype="multipart/form-data"
	_f.action = "/admin/edit_offer.asp?ok=1";
	_f.target = "_self";
}
