function dummy() {
}	

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name, "", -1);
}

var inputElementsEmpty = new Array();
var inputElementsText = new Array('text', 'textarea', 'password');
var inputElementsList = new Array('select-one', 'select-multiple');
var inputElementsCheck = new Array('radio', 'checkbox');
var inputElements = inputElementsEmpty
	.concat(inputElementsText)
	.concat(inputElementsList)
	.concat(inputElementsCheck);

function isInputElement(element, inputType) {	
	var result = false;	
	for (var i = 0; i < inputType.length; i ++) {
		if (element.type == inputType[i]) {
			result = true;
		}
	}	
	return result;
}

function clearInputElement(element) {
	if (isInputElement(element, inputElementsText)) {
		element.value = '';
	} else if (isInputElement(element, inputElementsList)) {
		var options = element.options;
		for (var i = 0; i < options.length; i ++) {
			var option = options[i];
			option.selected = option.value == '';
		}
	} else if (isInputElement(element, inputElementsCheck)) {
		element.checked = false;
	}		
}

function submitForm(form) {	
	form.submit();
}
function clearForm(form) {
	//form.reset();
	var length = form.length;
	for (var i = 0; i < length; i ++) {		
		var element = form[i];
		if (isInputElement(element, inputElements)) {			
			clearInputElement(element);
		}
	}
}
function getActionByPerspective(currentPersp) {
	switch (currentPersp) {
		case 1: return 'listPersonalObjects.do';
		case 2: return 'listTeamsObjects.do';
		case 3: return 'listInstitutionObjects.do';
		case 5: return 'listAdministrationObjects.do';
		case 10: return 'semanticSearch.do';
		case 7: return 'getAdvancedSearchResults.do';
	}
}

function go_top () {
		parent.location='#pageTop';  
	}
	
	function do_submit() {
		document.modifyUserProfileForm.submit();
	}

	function do_submit_1(saveScrollPos) {
		if (saveScrollPos) saveScrollCoordinates_1();
		document.forms[0].submit();
	}

	function do_delete_search_profile(text) {
		//alert("val21=" + document.profileBasicForm.chosenSearch.checked);
		//alert("val31=" + document.profileBasicForm.savser1041.checked);
		//if (question == true) {
		//	do_submit_1(1);	
		//} else {
			do_submit_delete (text);
		//}
	}

	function do_save() {
		check_action(8);
		do_submit_1(1);
	}

	function do_submit_delete (text) {
		question = confirm(text); //Your question.
		if (question == true) {
			do_submit_1(1);	
		} else {
			do_clear_1();
		}
	}

	function do_submit_delete_1 (text) {
		question = confirm(text); //Your question.
		if (question == true) do_submit_1(1);			
	}

	function do_clear_1() {
		document.forms[0].reset();
	}

	function do_clear_myProfile() {
		bi_gender = document.forms[0].main_gender.value;
		bi_nationalities = document.forms[0].main_nationality.value;
		bi_language = document.forms[0].main_nationality.value;
		bi_defaultlanguage = document.forms[0].main_defaultlanguage.value;
		add_country = document.forms[0].main_address_country.value;
		bi_password = document.forms[0].confirmpassword.value;

		document.forms[0].reset();

		document.forms[0].gender_.value = bi_gender;
		document.forms[0].main_gender.value = bi_gender;
		document.forms[0].nationality_.value = bi_nationalities;
		document.forms[0].main_nationality.value = bi_nationalities;
		document.forms[0].main_defaultlanguage.value = bi_defaultlanguage;
		document.forms[0].defaultlanguage.value = bi_defaultlanguage;
		document.forms[0].main_address_country.value = add_country;
		document.forms[0].country_.value = add_country;
		document.forms[0].confirmpassword.value = bi_password;
				
		//setOrgID("");
		//setOrgName("");
		document.forms[0].sectionNumber.value = "";
		document.forms[0].actionNumber.value = "";
	}

	function do_upload() {
		document.forms[0].submit();
	}
	
	function do_clear() {
		modifyUserProfileForm.reset();
	}
	
	function back_() {
		history.back();
	}
	
	function to_top() {
		page.top();
	}
	
	function cursor_hand() {
		document.body.style.cursor = 'pointer'; // PAA: That's the only way how it works in both IE and Mozilla.
	}

	function cursor_def() {
		document.body.style.cursor = 'default';	
	}
	
	function sow_projects() {
		divProj.style.display = "block";
		divRes.style.display = "none";
		divOrg.style.display = "none";
	}
	
	function sow_researchers() {
		divProj.style.display = "none";
		divRes.style.display = "block";
		divOrg.style.display = "none";
	}

	function sow_organisations() {
		divProj.style.display = "none";
		divRes.style.display = "none";
		divOrg.style.display = "block";
	}

	function to_print() {
		window.print();
	}

	function scrollToCoordinates_1() { 
		if (document.forms[0] &&
			document.forms[0].scroll &&
			document.forms[0].scroll.value == 1) {
		    window.scrollTo(document.forms[0].scrollx.value, document.forms[0].scrolly.value); 
		}
	} 

	function saveScrollCoordinates_1() { 
	    document.forms[0].scrollx.value = (document.all)?document.body.scrollLeft:window.pageXOffset; 
	    document.forms[0].scrolly.value = (document.all)?document.body.scrollTop:window.pageYOffset; 
	    document.forms[0].scroll.value = 1;
	    return true;
	} 	

    
/* ************************************************************************    */
/* ************************************************************************    */
/* **********************   Manage Profile functions    *******************    */
/* ************************************************************************    */

    var allVisible = true;
    //var orgName;
    //var orgID;

	function do_delete_address(lng) {
		if(document.forms[0].defAddrFlag_.checked == true) {
			alert( getTranslStr('msg.MyProfile.delContactAddress',lng) );
			do_clear_myProfile();
		} else {
			do_submit_delete(getTranslStr('msg.MyProfile.askDelAddress',lng));
		}
	}

	function do_delete_cv(cvID, lng) {
		if(document.forms[0].cv_.checked == true) {
			alert( getTranslStr('msg.MyProfile.delDefaultCV',lng) );
			do_clear_myProfile();		
		} else {
			question = confirm( getTranslStr('msg.MyProfile.askDelCV',lng) ); //Your question.
			if (question == true) {
				address = 'deleteCV.do?cvid=' + cvID;
				parent.location=address;
			} else {
				do_clear_myProfile();
			}
		}
	}

	function set_defAddrFlag_disable_status() {
		if (document.forms[0].defAddrFlag_.disabled == true) {
			document.forms[0].defAddrFlag_.disabled = false;
		} else {
			document.forms[0].defAddrFlag_.disabled = true;
		}
	}

	function toggle_element_visible(elementName, notVisible) {
	    if (document.getElementById(elementName+'R').style.display == 'none') {
	    	if (notVisible == null) {
	    		setElementVisible(elementName, 'block');
	    	}
	    	return('block');
    	} else {
	    	if (notVisible == null) {
    			setElementVisible(elementName, 'none');
    		}
	    	return('none');
    	}
	}
	
	function setElementVisible(elementName, visible) {
	    if (visible == 'none') {
	        document.getElementById(elementName+'W').style.display = 'block';
    	    document.getElementById(elementName+'R').style.display = 'none';
		} else {
	        document.getElementById(elementName+'R').style.display = 'block';
    	    document.getElementById(elementName+'W').style.display = 'none';
    	}
	}

	function openInputField() {
		if (inputField.style.display == 'none') {
			inputField.style.display = 'block';
		} else if (inputField.style.display == 'block') {
			inputField.style.display = 'none';
		} 
	}

	function openInputField2() {
		if (inputField2.style.display == 'none') {
			inputField2.style.display = 'block';
		} else if (inputField2.style.display == 'block') {
			inputField2.style.display = 'none';
		} 
	}
	
	function openListBoxField() {
		if (listBoxField.style.display == 'none') {
			listBoxField.style.display = 'block';
		} else if (listBoxField.style.display == 'block') {
			listBoxField.style.display = 'none';
		} 
	}

	function toggle_section_visible_all() {
	    allVisible = !allVisible;
		
		set_section_visible('section0', allVisible);
		set_section_visible('section1', allVisible);
		set_section_visible('section2', allVisible);
		set_section_visible('section3', allVisible);
		set_section_visible('section4', allVisible);
		set_section_visible('section5', allVisible);
		
		if (allVisible) {
			document.getElementById('expAll').style.display = 'block'
			document.getElementById('colAll').style.display = 'none'
		} else {
			document.getElementById('expAll').style.display = 'none'
			document.getElementById('colAll').style.display = 'block'
		}
	}
	
	
	function toggle_section_visible(sectionName) {
	    if (document.getElementById(sectionName).style.display == 'none') {
	    	set_section_visible(sectionName, 1);
	    } else {
	        set_section_visible(sectionName, 0);
	    }
	}

	function check_action(sectionNumber, actionNumber) {
		// Section numbers:
		// 0 - Basic information
		// 1 - Addresses
		// 4 - Subscriptions

		// Action numbers:
		// 0 - delete
		// 1 - modify
		// 2 - add
		// 3 - narrow classificator
		// 4 - add to selection
		// 5 - remove from selection
		// 6 - close
		// 7 - save
		// 8 - view
		if(document.forms[0].sectionNumber != null)
			document.forms[0].sectionNumber.value = sectionNumber;
		document.forms[0].actionNumber.value = actionNumber;
	}

	function setAddressID(AddressID) {
		document.getElementById('AddressID').value = AddressID;
		do_submit_1(1);
	}

	function setOrgID(OrgID) {
		document.getElementById('OrgID').value = OrgID;
	}

	function setOrgName(Name) {
		document.getElementById('neworgname').value = Name;
	}

	function saveOrg() {
		save_OrgID = document.getElementById('OrgID').value;
		save_OrgName = document.getElementById('neworgname').value;
	}
 
 	function setCVID(CVID) {
		document.getElementById('CVID').value = CVID;
		do_submit_1(1);
	}
		
	function setCVWorkExp(work_id, work_period, work_position, work_activities, work_employer, work_businesssector) {
		document.getElementById('workID').value = work_id;
		document.getElementById('workDay').value = work_period;
		document.getElementById('workOccup').value = work_position;
		document.getElementById('workActivit').value = work_activities;
		document.getElementById('workEmpl').value = work_employer;
		document.getElementById('workBussType').value = work_businesssector;
	}

	function setCVWorkExpAction(actionNumber) {
		// Action numbers:
		// 0 - add
		// 1 - edit
		// 2 - delete
		if (actionNumber == 0) {
			document.getElementById('workID').value = 0;
		}
		document.getElementById('CVWorkExpAction').value = actionNumber;
		do_submit_1(1);
	}
	
	function setCVEducAction(actionNumber) {
		// Action numbers:
		// 0 - add
		// 1 - edit
		// 2 - delete
		if (actionNumber == 0) {
			document.getElementById('EducID').value = 0;
		}
		document.getElementById('CVEducAction').value = actionNumber;
		do_submit_1(1);
	}

	function setCVEduc(educ_id, educ_period, educ_qualification, educ_skills, educ_organisation, educ_traininglevel) {
		document.getElementById('EducID').value = educ_id;
		document.getElementById('EducDate').value = educ_period;
		document.getElementById('EducTitle').value = educ_qualification;
		document.getElementById('EducSubj').value = educ_skills;
		document.getElementById('EducType').value = educ_organisation;
		document.getElementById('EducLevel').value = educ_traininglevel;
	}	
	
	function setCVLang(	lang_id, 
						lang_code, 
						lang_understandingListen, 
						lang_understandingRead, 
						lang_speakingInteraction, 
						lang_speakingProduction, 
						lang_writing) {
		document.getElementById('LangKey').value = lang_code;
		document.getElementById('LangID').value = lang_id;
		document.getElementById('LangListSkill').value = lang_understandingListen;
		document.getElementById('LangReadSkill').value = lang_understandingRead;
		document.getElementById('LangSpokenInteractSkill').value = lang_speakingInteraction;
		document.getElementById('LangSpokenProdSkill').value = lang_speakingProduction;
		document.getElementById('LangWriteSkill').value = lang_writing;
	}
	
	function setCVLangAction(actionNumber) {
		// Action numbers:
		// 0 - add
		// 1 - edit
		// 2 - delete
		if (actionNumber == 0) {
			document.getElementById('EducID').value = 0;
		}
		document.getElementById('CVLangAction').value = actionNumber;
		do_submit_1(1);
	}
	
	function setCVSocSkillAction(actionNumber) {
		// Action numbers:
		// 0 - add
		// 1 - edit
		// 2 - delete
		if (actionNumber == 0) {
			document.getElementById('SocSkillID').value = 0;
		}
		document.getElementById('CVSocSkillAction').value = actionNumber;
		do_submit_1(1);
	}
	
	function setCVSocSkill(	socSkill_personalskillid, 
							socSkill_description) {
		document.getElementById('SocSkillID').value = socSkill_personalskillid;
		document.getElementById('SocSkillDescr').value = socSkill_description;
	}
	
	function setCVOrgSkillAction(actionNumber) {
		// Action numbers:
		// 0 - add
		// 1 - edit
		// 2 - delete
		if (actionNumber == 0) {
			document.getElementById('OrgSkillID').value = 0;
		}
		document.getElementById('CVOrgSkillAction').value = actionNumber;
		do_submit_1(1);
	}
	
	function setCVOrgSkill(	orgSkill_personalskillid, 
							orgSkill_description) {
		document.getElementById('OrgSkillID').value = orgSkill_personalskillid;
		document.getElementById('OrgSkillDescr').value = orgSkill_description;
	}
	
	function setCVCompSkillAction(actionNumber) {
		// Action numbers:
		// 0 - add
		// 1 - edit
		// 2 - delete
		if (actionNumber == 0) {
			document.getElementById('CompSkillID').value = 0;
		}
		document.getElementById('CVCompSkillAction').value = actionNumber;
		do_submit_1(1);
	}
	
	function setCVCompSkill(compSkill_personalskillid, 
							compSkill_description) {
		document.getElementById('CompSkillID').value = compSkill_personalskillid;
		document.getElementById('CompSkillDescr').value = compSkill_description;
	}
	
	
	function setDefAddrFlag() {
		if (document.getElementById('defAddrFlag').value == "on") {
			document.getElementById('defAddrFlag').value = "";
		} else {
			document.getElementById('defAddrFlag').value = "on";
		}
	}

	function setNewAddressStatus() {
		document.getElementById('NewAddress').value = "on";
		document.getElementsByName('defAddrFlag')[0].value = "";
		document.getElementById('defAddrFlag_').checked = false;
		//document.getElementsByName('contacttype')[0].value = "";
		document.getElementsByName('addressline1')[0].value = "";
		document.getElementsByName('citytown')[0].value = "";
		document.getElementsByName('state')[0].value = "";
		document.getElementsByName('postcode')[0].value = "";
		document.getElementsByName('country')[0].value = "";
		document.getElementsByName('country_')[0].value = "";
		document.getElementsByName('tel')[0].value = "";
		//document.getElementsByName('mobile')[0].value = "";
		document.getElementsByName('fax')[0].value = "";
		document.getElementsByName('email')[0].value = "";
		document.getElementsByName('uri')[0].value = "";
		document.getElementsByName('tel')[0].value = "";	}
	
	function setDefaultStatus() {
		document.getElementById('sectionNumber').value = "";
		document.getElementById('actionNumber').value = "";
		document.getElementById('AddressID').value = "";
		document.getElementById('NewAddress').value = "";
		//document.getElementById('OrgID').value = "";
		document.getElementById('CVID').value = "";
		//document.getElementById('neworgname').value = "";
	}

	String.prototype.trim = function() {
		return this.replace(/^\s+|\s+$/g,"");
	}
	
	function getObjectById(objectid) {
    	return document.all?document.all[objectid]:document.getElementById?document.getElementById(objectid):null;
	}
	
	function isInternetExplorer(){ 
	    if ( navigator.appName.toLowerCase().indexOf( 'internet explorer' ) > -1 ) {
	        return true; 
	    } 
	    return false;
	}	
	
	function hideInactiveRelations() {
		var div;
		if (isInternetExplorer()) {
			div = getObjectById('sliderAwards');
			if (div != null) { collapseSlideAwards(); }
			div = getObjectById('sliderEquipments');
			if (div != null) { collapseSlideEquipments(); }
			div = getObjectById('sliderEvents');
			if (div != null) { collapseSlideEvents(); }
			div = getObjectById('sliderExpertiseSkills');
			if (div != null) { collapseSlideExpertiseSkills(); }
			div = getObjectById('sliderFacilities');
			if (div != null) { collapseSlideFacilities(); }
			div = getObjectById('sliderFundingProgrammes');
			if (div != null) { collapseSlideFundingProgrammes(); }
			div = getObjectById('sliderOrganisations');
			if (div != null) { collapseSlideOrganisations(); }
			div = getObjectById('sliderPatents');
			if (div != null) { collapseSlidePatents(); }
			div = getObjectById('sliderPersons');
			if (div != null) { collapseSlidePersons(); }
			div = getObjectById('sliderProducts');
			if (div != null) { collapseSlideProducts(); }
			div = getObjectById('sliderProjects');
			if (div != null) { collapseSlideProjects(); }
			div = getObjectById('sliderPublications');
			if (div != null) { collapseSlidePublications(); }
			div = getObjectById('sliderServices');
			if (div != null) { collapseSlideServices(); }
		}
	}
	
	function fillDateField(fieldName, minYear, maxYear) {
		var dayFieldObj = document.getElementById(fieldName + "_dd");
		var monthFieldObj = document.getElementById(fieldName + "_mm");
		var yearFieldObj = document.getElementById(fieldName + "_yyyy");		
		for (i = 1; i < 10; i++) {
			option = document.createElement("option");
			option.setAttribute("value", "0" + i);
			option.appendChild(document.createTextNode("0" + i));
			dayFieldObj.appendChild(option);
		}
		for (i = 10; i <= 31; i++) {
			option = document.createElement("option");
			option.setAttribute("value", i);
			option.appendChild(document.createTextNode(i));
			dayFieldObj.appendChild(option);
		}
		for (i = 1; i < 10; i++) {
			option = document.createElement("option");
			option.setAttribute("value", "0" + i);
			option.appendChild(document.createTextNode("0" + i));
			monthFieldObj.appendChild(option);
		}
		for (i = 10; i <= 12; i++) {
			option = document.createElement("option");
			option.setAttribute("value", i);
			option.appendChild(document.createTextNode(i));
			monthFieldObj.appendChild(option);
		}
		for (i = minYear; i <= maxYear; i++) {
			option = document.createElement("option");
			option.setAttribute("value", i);
			option.appendChild(document.createTextNode(i));
			yearFieldObj.appendChild(option);
		}
	}
	
	function updateDateField(fieldName) {
		var dayFieldObj = document.getElementById(fieldName + "_dd");
		var monthFieldObj = document.getElementById(fieldName + "_mm");
		var yearFieldObj = document.getElementById(fieldName + "_yyyy");	
		
		if (monthFieldObj.value != "") {
			var daysInMonth, oldDay;
			var selMonth = parseInt(monthFieldObj.value);
			
			switch (monthFieldObj.value) {
				case '01': case '03': case '05': case '07': case '08': case '10': case '12': 
					daysInMonth = 31;
					break;
				case '04': case '06': case '09': case '11': 
					daysInMonth = 30;
					break;
				case '02': 
					daysInMonth = 
						(yearFieldObj.value != "" && (parseInt(yearFieldObj.value) % 4 == 0))? 29 : 28;
					break;
			}
			
			oldDay = dayFieldObj.value;
			dayFieldObj.options.length = 0;
			option = document.createElement("option");
			option.setAttribute("value", "");
			option.appendChild(document.createTextNode("--"));
			dayFieldObj.appendChild(option);
			
			for (i = 1; i < 10; i++) {
				option = document.createElement("option");
				option.setAttribute("value", "0" + i);
				option.appendChild(document.createTextNode("0" + i));
				dayFieldObj.appendChild(option);
			}
			for (i = 10; i <= daysInMonth; i++) {
				option = document.createElement("option");
				option.setAttribute("value", i);
				option.appendChild(document.createTextNode(i));
				dayFieldObj.appendChild(option);
			}
			if (oldDay != "" && parseInt(oldDay) <= daysInMonth) {
				dayFieldObj.value = oldDay;
			}
		}

		var dateFieldObj = document.getElementById(fieldName);
		if (dayFieldObj.value != "" && monthFieldObj.value != "" && yearFieldObj.value != "") {
			dateFieldObj.value = dayFieldObj.value + "." + monthFieldObj.value + "." + yearFieldObj.value;
		} else {
			dateFieldObj.value = "";
		}		
	}
	
	function fillTimeField(fieldName) {
		var hoursFieldObj = document.getElementById(fieldName + "_hh");
		var minutesFieldObj = document.getElementById(fieldName + "_mm");
		for (i = 0; i < 10; i++) {
			option = document.createElement("option");
			option.setAttribute("value", "0" + i);
			option.appendChild(document.createTextNode("0" + i));
			hoursFieldObj.appendChild(option);
		}
		for (i = 10; i < 24; i++) {
			option = document.createElement("option");
			option.setAttribute("value", i);
			option.appendChild(document.createTextNode(i));
			hoursFieldObj.appendChild(option);
		}
		for (i = 0; i < 10; i++) {
			option = document.createElement("option");
			option.setAttribute("value", "0" + i);
			option.appendChild(document.createTextNode("0" + i));
			minutesFieldObj.appendChild(option);
		}
		for (i = 10; i < 60; i++) {
			option = document.createElement("option");
			option.setAttribute("value", i);
			option.appendChild(document.createTextNode(i));
			minutesFieldObj.appendChild(option);
		}
	}
	
	function updateTimeField(fieldName) {
		var hoursFieldObj = document.getElementById(fieldName + "_hh");
		var minutesFieldObj = document.getElementById(fieldName + "_mm");
		
		var timeFieldObj = document.getElementById(fieldName);
		if (hoursFieldObj.value != "" && minutesFieldObj.value != "") {
			timeFieldObj.value = hoursFieldObj.value + ":" + minutesFieldObj.value;
		} else {
			timeFieldObj.value = "";
		}		
	}
	
	function toggleImportLink() {
		var block = 'block';
		var none = 'none';
		var importLinkShow = document.getElementById('importLinkShow');
		var importLinkHide = document.getElementById('importLinkHide');
		var importPromptDiv = document.getElementById('importPromptDiv');
		var display = importLinkShow.style.display;
		if (display == block) {
			importLinkShow.style.display = none;
			importLinkHide.style.display = block;
			importPromptDiv.style.display = block;
		} else {
			importLinkShow.style.display = block;
			importLinkHide.style.display = none;
			importPromptDiv.style.display = none;
		}	
	}
