function toggle(obj) {
// Moz. or IE
var sibling=(obj.nextSibling.nodeType==3)? obj.nextSibling.nextSibling : obj.nextSibling;
// hide or show
if(sibling.style.display=='' || sibling.style.display=='block') {
	sibling.style.display='none';
    obj.firstChild.firstChild.data='';
    }
else {
	sibling.style.display='block';
    obj.firstChild.firstChild.data='';
    }
}
//
function initCollapse() {
	
var oDT=document.getElementById('version').getElementsByTagName('dt');
for (var i=0; i < oDT.length; i++) {
	oDT[i].onclick=function() {toggle(this)};
    var oSpan=document.createElement('span');
    var sign=document.createTextNode('');
    oSpan.appendChild(sign);
    oDT[i].insertBefore(oSpan, oDT[i].firstChild);
    oSpan.style.fontFamily='arial';
    oSpan.style.paddingRight='10px';
    oSpan.style.paddingLeft='10px';
    oSpan.style.paddingTop='2px';
    oSpan.style.paddingBottom='0px';
    oDT[i].style.cursor='pointer';
    toggle(oDT[i]);
	}
oDT=null;
}

function validateCompanyRegistration(){
	
	var root = document.edit;
	
	var username = root.username;
	var passwd = root.password;
	var conf_passwd = root.confirm_password;
	var name = root.name;
	var email = root.email;
	var phone = root.phone;
	var fax = root.fax;
	var business = root.job_category_types;
	var location = root.location;
	var profile = root.profile;
	var logo = root.logo;
	
	if (username.value == '' || passwd.value == '' || conf_passwd.value == '' || name.value == '' || email.value == '' || phone.value == '' || fax.value == '' || business.value == '' || location.value == '' || profile.value == ''){
		alert('Please fill all the fields');
		return false;
	}
	
	if (passwd.value != conf_passwd.value){
		alert('Your password and its confirmation do not match');
		passwd.focus();
		return false;
	}
	
	var passwordMD5 = hex_md5(passwd.value);
	passwd.value = passwordMD5;
	conf_passwd.value = passwordMD5;
	root.hashed.value = 'yes';
	return true;
}

function validateAddReferences(){
	
	var root = document.add;
	
	if (root.name.value == '' || root.email.value == ''){
		alert('Please fill all the obligatery fields');
		return false;
	}
	
	return true;
	
}

function validateAddReference(){
	
	var root = document.add;
	
	if (root.name.value == '' || root.email.value == ''){
		alert('Please fill all the obligatery fields');
		return false;
	}
	
	return true;
	
}

function validatePersonalInformation(){
	//alert('here');
	var root = document.edit;
	
	if (root.first_name.value == '' || root.last_name.value == '' || root.country.value == '' || root.year.value == '' || root.month.value == '' || root.day.value == '' || root.gender.value == '' || root.ms.value == '' || root.nb_o_d.value == '' || root.references.value == '' || root.username.value == ''){
		alert('Please fill all the fields');
		return false;
	}
	
	return true;
	
}

function validateAddSkills(){
	
	var root = document.add;
	
	if (root.skill.value == '' || root.skill_level.value == '' || root.years_of_experience.value == '' || root.last_used.value == ''){
		alert('Please fill all the fields');
		return false;
		
	}
	return true
	
}

function validateActivateCV1(){
	
	var root = document.edit;
	
	if (root.reference.value == ''){
		alert('Please insert your CV reference number.');
		root.reference.focus();
		return false;
	}
	
	if (root.payment[0].checked == false && root.payment[1].checked == false && root.payment[2].checked == false){
		alert('Please choose a payment method');
		return false;
	}
	
}

function validateRef(){
	if(document.check1.reference.value==''){
		alert('please insert reference number');
		document.check1.reference.focus();
		return false;
	}
}

function validateRef2(){
	if(document.check2.f_name.value==''){
		alert('please insert your first name');
		document.check2.f_name.focus();
		return false;
	}
	if(document.check2.l_name.value==''){
		alert('please insert your last name');
		document.check2.l_name.focus();
		return false;
	}
	var email=document.check2.email.value;
	if(email==''){
		alert("Please specify an email address.");
		document.check2.email.focus();
		return false;
	}
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	flag=email.match(pattern);
	if(!flag){
		alert('Please insert a valid email address.');
		document.check2.email.focus();
		return false;
	}
}

function validatePhoto(){
	if (document.upload_photo.photo.value == ''){
		alert('Please browse your photo.');
		return false;
	}
}

function validateRequest(){
	var root = document.request;
	var name = root.name;
	if(name.value==''){	
		alert('Please enter your name.');
		root.name.focus();
		return false;	
	}
	var nationality = root.nationality[root.nationality.selectedIndex].value;
	if(nationality == ''){
		alert('Please select your nationality.')
		root.nationality.focus();
		return false;
	}
	var address = root.address;
	if(address.value==''){	
		alert('Please enter your address.');
		root.address.focus();
		return false;	
	}
	var email=root.email.value;
	if(email==''){
		alert("Please enter your email address.");
		root.email.focus();
		return false;
	}
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	flag=email.match(pattern);
	if(!flag){
		alert('Please enter a valid email address.');
		root.email.focus();
		return false;
	}
	var phone = root.phone;
	if(phone.value==''){	
		alert('Please enter your phone number.');
		root.phone.focus();
		return false;	
	}
	c = 0;
	var countriesRep = root.elements[8].length;
		for(i=0;i<countriesRep;i++){
			if(root.elements[8][i].selected == true){
				c++;
			}
		}
	if(c == 0){
		alert('Please choose the Cities / Countries you would like to represent.');
		root.elements[8].focus();
		return false;	
	}
	var comment = root.comments;
		if(comment.value==''){	
			alert('please enter your comments.');
			root.comments.focus();
			return false;	
	}

}



function validateContactInformation(){
	
	var root = document.edit;
	
	if (root.location.value == ''){
		
		alert('Please select your location.');
		root.location.focus();
		return false;
	}
	
	if (root.email.value == ''){
		
		alert('Please enter your email.');
		root.email.focus();
		return false;
	}
	
	var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;

	flag = root.email.value.match(pattern);
	
	if(!flag){
		alert('Please insert a valid email address.');
		root.email.focus();
		return false;
	}
	
	return true;
	
}

function validateCareerObjectives(){
	
	var root = document.edit;
	
	if (root.position_sought.value == ''){
		alert('Please enter the sought position');
		root.position_sought.focus();
		return false;
	}
	
	if (root.career_level.value == ''){
		alert('Please select your career level');
		root.career_level.focus();
		return false;
	}
	
	return true;
	
}

function validateAddEducation(){
	
	var root = document.add;
	
	var institution = root.institution.value;
	var country = root.country_id.value;
	var degree = root.degree.value;
	var year = root.year.value;
	var month = root.month.value;
	
	if (institution == '' || country == '' || degree == '' || year == '' || month == ''){
		alert('Please fill all the required fields');
		return false;
	}
	
	return true;
	
	
}

function validateAddPE(){
	
	var root = document.add;
	
	var position = root.position.value;
	
	var location = root.location.value;
	var startMonth = root.start_month.value;
	var startYear = root.start_year.value;
	var endMonth = root.end_month.value;
	var endYear = root.end_year.value;
	var workDescription = root.work_description.value;
	
	if (endMonth == 'Present') endYear = 'aadsf';
	
	if (position == '' || location == '' || startMonth == '' || startYear == '' || endMonth == '' || endYear == '' || workDescription == ''){
		alert('Please fill all the required fields');
		return false;
	}
	return true;

}

function validateAddLanguage(){
	
	var root = document.add;
	
	if (root.language.value == '' || root.skill_level.value == '' || root.years_of_experience.value == '' || root.last_used.value == ''){
		alert('Please fill all the fields');
		return false;
	}
	return true;
	
}


function checkContactform(){
	var root=document.contactForm;

	var name=root.name;
	var company=root.company;
	var street=root.street;
	var city=root.city;
	var state=root.state;
	var country=root.country;
	var phone=root.phone;
	var mobile=root.mobile;
	var email=root.email;
	var department=root.department;
	var subject=root.subject;
	var message=root.message;

	if(name.value==""){
		alert('Please enter your full name.');
		name.focus();
		return false;
	}
	if(country.value==""){
		alert('Please select a country from the list.');
		country.focus();
		return false;
	}
	if(phone.value==""){
		alert('Please enter your home phone number.');
		phone.focus();
		return false;
	}
	if(isNaN(phone.value)){
		alert('The phone number should only contain digits.');
		phone.select();
		return false;
	}
	if(isNaN(mobile.value) && mobile.value!=""){
		alert('The mobile phone number should only contain digits');
		mobile.select();
		return false;
	}
	if(email.value==""){
		alert('Please enter an email address.');
		email.focus();
		return false;
	}
	if(department.value==""){
		alert('Please select the department you wish to contact.');
		department.focus();
		return false;
	}
	if(subject.value==""){
		alert('Please enter the subject.');
		subject.focus();
		return false;
	}
	if(message.value==""){
		alert('Please enter your message.');
		message.focus();
		return false;
	}
}


function clearContactForm(){
	var root=document.contactForm;

	var name=root.name;
	var company=root.company;
	var street=root.street;
	var city=root.city;
	var state=root.state;
	var country=root.country;
	var phone=root.phone;
	var mobile=root.mobile;
	var email=root.email;
	var department=root.department;
	var subject=root.subject;
	var message=root.message;

	if(confirm('Are you sure you want to clear this form?')){
		name.value="";
		company.value="";
		street.value="";
		city.value="";
		state.value="";
		country.value="";
		phone.value="";
		mobile.value="";
		email.value="";
		department.value="";
		subject.value="";
		message.value="";

		return false;
	}

	return false;
}

function validateLogIn(){
	
	var root = document.login;
	var username = root.username;
	var password = root.password;
	
	if (username.value == ''){
		alert('Please enter your username');
		username.focus();
		return false;
	}
	if (password.value == ''){
		alert('Please enter your password');
		password.focus();
		return false;
	}
	
	var md5Password = hex_md5(password.value);
	password.value = md5Password;
	root.hashed.value = 'yes';
	return true;
	
	
}

function boomEmail(){
	
	var jc = document.edit.job_category_types[document.edit.job_category_types.selectedIndex].value;
	var loc = document.edit.location[document.edit.location.selectedIndex].value;
	
	radar(jc,loc);
	return false;
	
}

