var win_send;
var win_news;
var win_pass;
var win_subscribe;

function print_news_window(id){
	try{ // for the case that the window is not open yet
		win_news.close();
	}
	catch(e){}
	win_news = window.open("activities_print.php?id="+id,"","height=600,width=600,status=no,toolbar=no,menubar=no,location=no")
}
function send_a_friend_window(id){
	try{ // for the case that the window is not open yet
		win_send.close();
	}
	catch(e){}
	
	win_send = window.open("activities_send_a friend.php?id="+id,"","height=400,width=550,status=no,toolbar=no,menubar=no,location=no")
}
function send_a_friend(news_id){
	if (validity_check() == true){
		document.frm1.submit();
	}
	else
		return false;
}
function validity_check(){
	var validity = true;
	
	if(document.getElementById("T1").value==""){
		alert("Your email is empty!")
		document.getElementById("T1").focus();
		validity = false;
	}
	else if(document.getElementById("T2").value==""){
		alert("Friend's email is empty!")
		document.getElementById("T2").focus();
		validity = false;
	}
	/*else if(document.getElementById("S1").value==""){
		alert("The message to your friend is empty!")
		document.getElementById("S1").focus;
		validity = false;
	}*/
	
	return validity;
}



function search_validity(){
	if(document.getElementById("search_box").value==""){
		alert("Empty Search");
		return false;
	}
	else
		return true
	/*else{
		window.location = "index.php?page=search_results"
	}*/
}


function forgotten_pass_window(){
	nickname = document.getElementById("nickname").value;
	if(nickname.value==""){
		alert("Insert your nickname in the appropriate textbox, and try again !")
		nickname.focus();
	}
	else{
		try{ // for the case that the window is not open yet
			win_pass.close();
		}
		catch(e){}
		win_pass = window.open("forgotten_pass.php?nickname="+nickname,"","height=300,width=400,status=no,toolbar=no,menubar=no,location=no")
	}
}
function change_pass_window(){
	nickname = document.getElementById("nickname");
	if(nickname.value==""){
		alert("Insert your nickname in the appropriate textbox, and try again !")
		nickname.focus();
	}
	else{
		try{ // for the case that the window is not open yet
			win_pass.close();
		}
		catch(e){}
		win_pass = window.open("change_pass.php?nickname="+nickname.value,null,"height=300,width=400,status=no,toolbar=no,menubar=no,location=no")
	}
}
function change_pass(){
	var ret = false;

	if(document.getElementById("old_pass").value == ""){
		alert("Old password is empty !")
		document.getElementById("old_pass").focus();
	}
	else if(document.getElementById("pass").value == ""){
		alert("New password is empty !")
		document.getElementById("pass").focus();
	}
	else if(document.getElementById("pass").value != document.getElementById("confirm_pass").value){
		alert("Password not confirmed")
		document.getElementById("confirm_pass").focus();
	}
	else{
		ret = true;
		
		document.getElementById("pass_2").value = MD5(document.getElementById("pass").value)
		document.getElementById("old_pass_2").value = MD5(document.getElementById("old_pass").value)
		document.frm1.submit();
	}

	return ret;
}
function login(){
	if(document.getElementById("nickname").value==""){
		alert("Nickname is null!")
		document.getElementById("nickname").focus();
	}
	else{
		document.getElementById("pass_2").value = MD5(document.getElementById("pass").value)
		document.frm1.submit();
	}
}

function register_new_cv(){
	window.location="index.php?page=careers&subpage=new_resume";
}

function register_resume(){
	var ret = false;
	if(document.getElementById("nickname").value==""){
		alert("Nickname empty!")
		document.getElementById("nickname").focus();
	}
	else if(document.getElementById("name").value==""){
		alert("Name empty!")
		document.getElementById("name").focus();
	}
	else if(document.getElementById("surname").value==""){
		alert("Surname empty!")
		document.getElementById("surname").focus();
	}
	else if(document.getElementById("pass").value==""){
		alert("Password empty!")
		document.getElementById("pass").focus();
	}
	else if(document.getElementById("pass_conf").value==""){
		alert("Password not confirmed!")
		document.getElementById("pass_conf").focus();
	}
	else if(document.getElementById("pass").value != document.getElementById("pass_conf").value){
		alert("Password not confirmed!")
		document.getElementById("pass_conf").focus();
	}
	else{
		ret = true;
		
		document.getElementById("pass_2").value = MD5(document.getElementById("pass").value)
		document.new_resume.submit();
	}
	
	return ret;
}
/*function register_resume_general_data(){
	document.new_resume.submit();
}
function register_resume_education(){
	document.new_resume.submit();
}
function register_resume_career(){
	document.new_resume.submit();
}
function register_resume_experience(){
	document.new_resume.submit();
}
function register_resume_skills(){
	document.new_resume.submit();
}
function register_resume_references(){
	document.new_resume.submit();
}*/


// UPDATE GENERAL DATA
function save_general_data(){
	document.getElementById('_operation').value = "general_data";
	document.general_data.submit();
}

//      UPDATE/INSERT RESUME EDUCATION  
function prepare_education(op, id){
	document.getElementById('_operation').value = "education_"+op;
	document.getElementById('_id').value = id;
	
	if(op == "edit")
		window.location = "index.php?page=careers&subpage=cv_reg_education&op=education_"+op+"&id="+id
	else{
		document.getElementById("institution").value="";
		document.getElementById("since").value="0";
		document.getElementById("until").value="0";
		document.getElementById("graduated").value="";
		document.getElementById("courses").value="";
		document.getElementById("add_education").style.display = "block";
		document.getElementById("institution").focus();
	}
}
function save_education(op){
	// op = update/insert
	var ret = false;
	if(document.getElementById("institution").value==""){
		/*alert("Empty 'intitution' field!")*/
		/*document.getElementById("institution").focus();*/
	}
	else{
		ret = true;
		document.education.submit();
	}
	
	return ret;
}

//      UPDATE/INSERT RESUME CAREER 
function prepare_career(op, id){
	document.getElementById('_operation').value = "career_"+op;
	document.getElementById('_id').value = id;
	
	if(op == "edit")
		window.location = "index.php?page=careers&subpage=cv_reg_career&op=career_"+op+"&id="+id
	else{ // add
		document.getElementById("employer").value="";
		document.getElementById("since_year").value="0";
		document.getElementById("since_month").value="0";
		document.getElementById("until_year").value="0";
		document.getElementById("until_month").value="0";		
		document.getElementById("job").value="";
		document.getElementById("responsabilities").value="";
		document.getElementById("city").style.display = "block";
		
		document.getElementById('add_career').style.display='block'
		document.getElementById('employer').focus();
	}
	
}
function save_career(op){
	// op = update/insert
	var ret = false;
	
	if(document.getElementById("employer").value==""){
		/* alert("Empty 'employer' field!") */
		/*document.getElementById("employer").focus();*/
	}
	else{ // OK data
		ret = true;
		document.career.submit();
	}
	
	return ret;
}


//      UPDATE/INSERT RESUME REFERENCE
function prepare_reference(op, id){
	document.getElementById('_operation').value = "reference_"+op;
	document.getElementById('_id').value = id;
	
	if(op == "edit")
		window.location = "index.php?page=careers&subpage=cv_reg_references&op=reference_"+op+"&id="+id
	else{ // add
		document.getElementById("institution").value="";
		document.getElementById("person").value="";
		document.getElementById("position").value="";
		document.getElementById("phone").value="";
		document.getElementById("email").value="";		

		document.getElementById('add_reference').style.display='block'
		document.getElementById('institution').focus();
	}
	
}
function save_reference(op){
	// op = update/insert
	var ret = false;
	
	if(document.getElementById("institution").value==""){
		/*alert("Empty 'institution' field!")*/
		/*document.getElementById("institution").focus();*/
	}
	else if(document.getElementById("person").value=="0"){
		/*alert("Empty 'person name' field!")*/
		/*document.getElementById("person").focus();*/
	}
	else{ // OK data
		ret = true;
		document.reference.submit();
	}
	
	return ret;
}



// UPDATE EXPERIENCE
function save_experience(){
	document.experience.submit();
}

function drv_license_changed(i){
	if(i==0)
		document.getElementById("drv_categ").disabled = true;
	else
		document.getElementById("drv_categ").disabled = false;
}	

// UPDATE SKILLS
function save_skills(){
	document.getElementById('_operation').value = "skills";
	document.skills.submit();
}

// go to RESUME page


function resume_goto_page(page,func){
	eval(func);
	if(page != "")
		window.location = "index.php?page=careers&subpage="+page;
}

function unsubscribe_win(){
	try{ // for the case that the window is not open yet
			win_unsubscribe.close();
		}
	catch(e){}
	
	win_unsubscribe = window.open("unsubscribe.php?operation=unsubscribe","","height=420,width=550,status=no,toolbar=no,menubar=no,location=no, scrollbars=0")
}
function unsubscribe(){
	var ret = false;
	
	if(document.getElementById("reason").value==""){
		alert("No reason entered !")
		document.getElementById("reason").focus();
	}
	else if(document.getElementById("email").value==""){
		alert("Email address empty!")
		document.getElementById("email").focus();
	}
	else
		ret=true;
		
	return ret;
}


function subscribe_win(){
	try{ // for the case that the window is not open yet
			win_subscribe.close();
		}
	catch(e){}
	
	win_subscribe = window.open("subscribe.php?operation=subscribe","","height=590,width=580,status=no,toolbar=no,menubar=no,location=no, scrollbars=1")
}
function subscribe(){
	var ret = false;
	
	if(document.getElementById("firstname").value==""){
		alert("First name is empty !")
		document.getElementById("firstname").focus();
	}
	else if(document.getElementById("lastname").value==""){
		alert("Last name is empty !")
		document.getElementById("lastname").focus();
	}
	else if(document.getElementById("email").value==""){
		alert("Email address is empty !")
		document.getElementById("email").focus();
	}
	else if(document.getElementById("countries").value==""){
		alert("Country not selected !")
		document.getElementById("countries").focus();
	}
	else if(document.getElementById("company").value==""){
		alert("Company name is empty !")
		document.getElementById("company").focus();
	}
	else if(document.getElementById("functions").options[document.getElementById("functions").selectedIndex].text=="Other" || document.getElementById("functions").options[document.getElementById("functions").selectedIndex].text=="..."){
		if(document.getElementById("other_function").value==""){
			ret = false;
			alert("Function is empty !")
			document.getElementById("functions").focus();
		}
		else
			ret = true;
	}
	else
		ret = true;
	
	if(ret){
		if(document.getElementById("domains").options[document.getElementById("domains").selectedIndex].text=="Other" || document.getElementById("domains").options[document.getElementById("domains").selectedIndex].text=="..."){
			if(document.getElementById("other_domain").value==""){
				ret = false;
				alert("Industry is empty !")
				document.getElementById("domains").focus();
			}
			else
				ret = true;
		}
	}
	
	/*if(ret){
		if(document.getElementById("interests").options[document.getElementById("interests").selectedIndex].text=="Other" || document.getElementById("interests").options[document.getElementById("interests").selectedIndex].text=="..."){
			if(document.getElementById("other_interest").value==""){
				ret = false;
				alert("Interest is empty !")
				document.getElementById("interests").focus();
			}
			else
				ret = true;
		}
	}
	
	if(ret){
		if(document.getElementById("levels").options[document.getElementById("levels").selectedIndex].text=="Other" || document.getElementById("levels").options[document.getElementById("levels").selectedIndex].text=="..."){
			if(document.getElementById("other_level").value==""){
				ret = false;
				alert("Decision level is empty !")
				document.getElementById("levels").focus();
			}
			else
				ret = true;
		}
	}
	*/
	return ret;
}

function show_other_txt(list_name, txt_name){
	var comp = document.getElementById(txt_name);

	if(document.getElementById(list_name).options[document.getElementById(list_name).selectedIndex].text=="Other"){
		comp.style.visibility = 'visible';
		comp.focus();
	}
	else
		comp.style.visibility = 'hidden';
}

function prepare_dept(dept){
	window.location = "index.php?page=careers&subpage=meet_our_people&dept="+dept
}

function prepare_pers(dept,oid){
		window.location = "index.php?page=careers&subpage=meet_our_people&dept="+dept+"&po="+oid
}