// This function displays the tree for the selected category within the corresonding div for skillSlectionBox
var links = 0;
var links0 = 0;
var links1 = 0;
function getSkills(id, label) {
	var tree_id = jQuery('#tree_id').val();
	if (tree_id == 0) {
		tree_id = id;
		jQuery('#tree_id').val(id);
	} else {
		tree_id = jQuery('#tree_id').val() + ',' + id;
		jQuery('#tree_id').val(tree_id);
	}

	dataString = 'rootCategory=' + id + '&label=' + label + '&tree_id='
			+ tree_id;

	jQuery.post('/index.php/skillSelectionBox/getTree', dataString, function(
			data) {
		jQuery('#navigationMenu').html(data.navigation);
		jQuery('#choose_competences_categories1').html(data.str);
		jQuery('#tree_id').val(data.treeid);
		/* alert(jQuery('#tree_id').val()); */
	}, "json");

	/*
	 * var j = new Ajax.Updater('',
	 * '/index.php/skillSelectionBox/getTree?rootCategory='+id+'&label='+label+'&tree_id='+tree_id,
	 * {asynchronous:true, evalScripts:false, onComplete:function(txt){var
	 * rt=txt.responseText;
	 * $('navigationMenu').innerHTML=rt.substring(0,rt.indexOf("***"));
	 * $('choose_competences_categories').innerHTML=rt.substring(rt.indexOf("***")+3,rt.indexOf("^^^"));$('tree_id').value =
	 * rt.substring(rt.indexOf("^^^")+3);} }); return false;
	 */
	jQuery('#column_quick_search_engine_text_title').hide();
	jQuery('#navigationMenu').show();

}

// filter skills with keyword
function filterSkills() {
	keyword = jQuery('#keyword').val();
	id = jQuery('#current_category_id').val();
	
	if (id != 0) {
		
		var tree_id = jQuery('#tree_id').val();
		var label = 'label';

		dataString = 'rootCategory=' + id + '&tree_id='
		+ tree_id + '&label=' + label + '&keyword=' + keyword;
		
		jQuery.post('/index.php/skillSelectionBox/getSubCategories',
				dataString, function(data) {
					//jQuery('#choose_competences_categories').html(data.str);
					//jQuery('#tree_id').val(data.treeid);
					jQuery('#select_competences').html(data.skills);

				}, "json");
	} else {
		dataString = 'keyword=' + keyword;
		jQuery.post('/index.php/skillSelectionBox/getRootData', dataString,
				function(data) {
					//jQuery('#choose_competences_categories').html(data.str);
					jQuery('#select_competences').html(data.skills);
				}, "json");
	}

	/*
	 * var j = new Ajax.Updater('',
	 * '/index.php/skillSelectionBox/getSubCategories?rootCategory='+id+'&label='+label+'&tree_id='+tree_id,
	 * {asynchronous:true, evalScripts:false, onComplete:function(txt){ var
	 * rt=txt.responseText;
	 * jQuery('#choose_competences_categories').html(rt.substring(0,rt.indexOf("***")));
	 * var rt=rt.substring(rt.indexOf("***")+3);
	 * jQuery('#tree_id').val(rt.substring(0,rt.indexOf("^^^")));
	 * jQuery('#select_add_competence').html(rt.substring(rt.indexOf("^^^")+3)); }
	 * }); return false;
	 */
}

// This function displays the tree of sub categories and skills for the selected
// category within the corresonding div for advanced skillSlectionBox
function getAllSkills(id, label) {
		
	if (!jQuery('#' + id).hasClass('selectedtreenode')) {
		var tree_id = jQuery('#tree_id').val();
		if (tree_id == 0) {
			tree_id = id;
			jQuery('#tree_id').val(id);
		} else {
			tree_id = jQuery('#tree_id').val() + ',' + id;
			jQuery('#tree_id').val(tree_id);
		}

		dataString = 'rootCategory=' + id + '&label=' + label + '&tree_id='
				+ tree_id;
		
		jQuery.post('/index.php/skillSelectionBox/getSubCategories',
				dataString, function(data) {
					jQuery('#choose_competences_categories').html(data.str);
					jQuery('#tree_id').val(data.treeid);
					jQuery('#current_category_id').val(id);
					jQuery('#select_competences').html(data.skills);

				}, "json");
	} else {
		jQuery('#current_category_id').val(0);
		dataString = '';
		jQuery.post('/index.php/skillSelectionBox/getRootData', dataString,
				function(data) {
					jQuery('#choose_competences_categories').html(data.str);
					jQuery('#select_competences').html(data.skills);
				}, "json");
	}

	/*
	 * var j = new Ajax.Updater('',
	 * '/index.php/skillSelectionBox/getSubCategories?rootCategory='+id+'&label='+label+'&tree_id='+tree_id,
	 * {asynchronous:true, evalScripts:false, onComplete:function(txt){ var
	 * rt=txt.responseText;
	 * jQuery('#choose_competences_categories').html(rt.substring(0,rt.indexOf("***")));
	 * var rt=rt.substring(rt.indexOf("***")+3);
	 * jQuery('#tree_id').val(rt.substring(0,rt.indexOf("^^^")));
	 * jQuery('#select_add_competence').html(rt.substring(rt.indexOf("^^^")+3)); }
	 * }); return false;
	 */
}

// This function displays only the root categories within corresonding div for
// skillSlectionBox
function getRootCategories() {
	dataString = '';
	jQuery.post('/index.php/skillSelectionBox/getRootCategories', dataString,
			function(data) {
				jQuery('#choose_competences_categories1').html(data.str);
				jQuery('#navigationMenu').html(data.navigation);
			}, "json");

	jQuery('#column_quick_search_engine_text_title').show();

	jQuery('#navigationMenu').hide();
	// var j = new Ajax.Updater('',
	// '/index.php/skillSelectionBox/getRootCategories', {asynchronous:true,
	// evalScripts:false, onComplete:function(txt){var
	// rt=txt.responseText;$('choose_competences_categories').innerHTML=rt;

	// });
	// return false;
}

// This function adds the category drop down.
function addList(parentDiv, optionStr) {
	var optionArry = optionStr.split(',');
	var totalOptions = optionArry.length;
	var allOptions = '';

	document.getElementById('divCount').value++;
	var totalCnt = document.getElementById('divCount').value;
	var content = '';
	for (addCnt = 0; addCnt < totalCnt; addCnt++) {
		content = content + "<div id='category_" + addCnt + "'>";
		content = content + "<select name='category_id[]' id='category_id[]'>";
		for (optionCnt = 0; optionCnt < totalOptions; optionCnt++) {
			myOption = optionArry[optionCnt].split('_');
			allOptions = allOptions + "<option value='" + myOption[0] + "'>"
					+ myOption[1] + "</option>";
		}
		content = content + allOptions;
		content = content + "</select>";
		content = content
				+ "<img src='/images/minus_icon.gif' onClick='javascript:removeList(\"parentDiv\",\""
				+ optionStr + "\");'></div>";
		allOptions = '';
	}
	document.getElementById(parentDiv).innerHTML = content;
}

// This function removes the category drop down.
function removeList(parentDiv, optionStr) {
	var optionArry = optionStr.split(',');
	var totalOptions = optionArry.length;
	var allOptions = '';

	document.getElementById('divCount').value--;
	var totalCnt = document.getElementById('divCount').value;
	var content = '';
	for (addCnt = 0; addCnt < totalCnt; addCnt++) {
		content = content + "<div id='category_" + addCnt + "'>";
		content = content + "<select name='category_id[]' id='category_id[]'>";
		for (optionCnt = 0; optionCnt < totalOptions; optionCnt++) {
			myOption = optionArry[optionCnt].split('_');
			allOptions = allOptions + "<option value='" + myOption[0] + "'>"
					+ myOption[1] + "</option>";
		}
		content = content + allOptions;
		content = content + "</select>";
		content = content
				+ "<img src='/images/minus_icon.gif' onClick='javascript:removeList(\"parentDiv\",\""
				+ optionStr + "\");'></div>";
	}
	document.getElementById(parentDiv).innerHTML = content;

}

// This function removes the category drop down while editing a sub category or
// a skill.
function removeParent(parentDiv) {
	document.getElementById(parentDiv).innerHTML = '';

}

/*
 * this is Jquery bind functions starts here please add your code at the end of
 * this funtion
 */
jQuery(document)
		.ready( function() {
			// if selection var is set then only
				if (jQuery('#selectionVar').val() == 1) {
					jQuery('.hiddencls').each( function(index) {
						jQuery(this).val('');
					});
					// function set all cells unavailable.
					/*
					 * jQuery('.cell').each(function(index){
					 * if(!(jQuery(this).hasClass("unavailable")))
					 * jQuery(this).addClass("unavailable"); });
					 */

					// bind function execute when a single cell is clicked.
					jQuery('.cell').bind("click", function() {
						if (jQuery(this).hasClass("unavailable"))
							jQuery(this).removeClass("unavailable");
						else
							jQuery(this).addClass("unavailable");
					});

					// binds function execute when a row header gets clicked.
					jQuery('.hour')
							.bind(
									"click",
									function() {
										var flag = 0;
										var parent = jQuery(this).parent();
										jQuery(parent)
												.children()
												.each( function(index) {// selects
																		// all
																		// cells
																		// which
																		// are
																		// under
																		// the
																		// current
																		// row,
																		// following
																		// code
																		// checks
																		// for
																		// all
																		// cells
																		// are
																		// same
																		// status
															if (jQuery(this)
																	.hasClass(
																			"unavailable")
																	&& jQuery(
																			this)
																			.hasClass(
																					"cell"))
																flag = 1;
														});

										if (flag == 0) {
											jQuery(parent)
													.children()
													.each( function(index) {// selects
																			// all
																			// cells
																			// which
																			// are
																			// under
																			// the
																			// current
																			// row
																if (!(jQuery(this)
																		.hasClass("unavailable")))
																	jQuery(this)
																			.addClass(
																					"unavailable");
															});
										} else {
											jQuery(parent)
													.children()
													.each( function(index) {// selects
																			// all
																			// cells
																			// which
																			// are
																			// under
																			// the
																			// current
																			// row
																jQuery(this)
																		.removeClass(
																				"unavailable");
															});
										}

									});

					// binds function execute when a column header gets clicked.
					jQuery('#timetable th')
							.bind(
									'click',
									function() {
										var childNumber;
										var flag = 0;

										switch (jQuery(this).html())// selects
																	// current
																	// column
																	// number
										{
										case 'Lun':
											childNumber = 1;
											break;
										case 'Mar':
											childNumber = 2;
											break;
										case 'Mer':
											childNumber = 3;
											break;
										case 'Jeu':
											childNumber = 4;
											break;
										case 'Ven':
											childNumber = 5;
											break;
										case 'Sam':
											childNumber = 6;
											break;
										case 'Dim':
											childNumber = 7;
											break;
										}
										jQuery('#timetable table tr')
												.each( function(index) { // selects
																			// all
																			// rows
																			// from
																			// timetable
																			// div
															if (index)// gets
																		// executed
																		// when
																		// a row
																		// is
																		// not a
																		// header
																		// row
															{
																jQuery(this)
																		.children()
																		.each(
																				function(
																						ii) {// gets
																								// all
																								// childrens
																								// of
																								// current
																								// row
																								// i.e.(children[index])
																					if (jQuery(
																							this)
																							.hasClass(
																									"unavailable")
																							&& jQuery(
																									this)
																									.hasClass(
																											"cell")
																							&& ii == childNumber)// checks
																													// for
																													// all
																													// td
																													// of
																													// current
																													// column
																													// are
																													// having
																													// same
																													// status
																													// or
																													// not.
																						flag = 1;
																				});
															}
														});

										jQuery('#timetable table tr')
												.each(
														function(index) {
															if (index) {
																jQuery(this)
																		.children()
																		.each(
																				function(
																						index) {
																					if (flag == 0) {
																						if (!(jQuery(this)
																								.hasClass("unavailable"))
																								&& index == childNumber)
																							jQuery(
																									this)
																									.addClass(
																											"unavailable");
																					} else {
																						if (index == childNumber)
																							jQuery(
																									this)
																									.removeClass(
																											"unavailable");
																					}
																				});
															}
														});
									});

					// gets executed when submit button is clicked
					jQuery('#update_button')
							.bind(
									'click',
									function() {

										jQuery('.hiddencls').each(
												function(index) {
													jQuery(this).val('');
												});

										var hourstr;
										var txtval;
										jQuery('#timetable table tr')
												.each(
														function(index) {
															jQuery(this)
																	.children()
																	.each(
																			function(
																					ii) {// gets
																							// all
																							// childrens
																							// of
																							// current
																							// row
																							// i.e.(children[index])
																				if (index) {
																					if (!ii) {
																						hourstr = jQuery(
																								this)
																								.html();
																						hourstr = hourstr
																								.replace(
																										"h",
																										"");
																						hourstr = hourstr
																								.replace(
																										" ",
																										"");
																					}
																					if (!(jQuery(this)
																							.hasClass('unavailable'))
																							&& ii) {
																						switch (ii) {
																						case 1:
																							txtval = 'txtLun';
																							break;
																						case 2:
																							txtval = 'txtMar';
																							break;
																						case 3:
																							txtval = 'txtMer';
																							break;
																						case 4:
																							txtval = 'txtJeu';
																							break;
																						case 5:
																							txtval = 'txtVen';
																							break;
																						case 6:
																							txtval = 'txtSam';
																							break;
																						case 7:
																							txtval = 'txtDim';
																							break;
																						}
																						jQuery(
																								'#' + txtval)
																								.val(
																										jQuery(
																												'#' + txtval)
																												.val()
																												+ ";"
																												+ hourstr);

																					}
																				}

																			});
														});

										jQuery('#formtimetable').submit();
									});

				}// if selection var is set then only
			});

/* Jquery bind functions ends here */

// This function validates the add user skill form.
function validateAddSkill(frm) {
	var innerTxt = '';

	if ($('skill_id').value == 0 && $('yourSkill').value == '') {
		$('skill_id').value = 0
		error2 = $('error_skill').value;
		innerTxt = innerTxt + error2 + '<br>';
	}
	if ($('skill_id').value == 0 && $('yourSkill').value != '') {
		if ($('yourSkill').value.length < 3) {
			error3 = $('error_skill_label').value;
			innerTxt = innerTxt + error3 + '<br>';

		}
	}
	if ($('skillLevels').value == 0) {
		error4 = $('error_skill_level').value;
		innerTxt = innerTxt + error4 + '<br>';
	}
	if (frm == 'addOwnedSkill') {
		if ($('textarea_comp_desc_2').value.length < 10) {
			error5 = $('error_ownedSkill_edit').value;
			innerTxt = innerTxt + error5 + '<br>';
		}

	}
	if ($('yourSkill').value.length > 20) {
		error6 = $('error_yourSkill').value;
		innerTxt = innerTxt + error6 + '<br>';
	}
	if (innerTxt != '') {
		// alert(innerTxt);
		$('skillPosition').innerHTML = innerTxt;
		$('add_competence_scoller').focus();
		return false;
	} else {
		$(frm).submit();
		return false;
	}
}

// This function displays the pop up for a skill after clicking over 'X'.
function displayPopUp(skill_id, skill_name, skill_flag) {
	var compName = skill_name;

	document.getElementById('popup_1_' + skill_id).style.display = 'block';

	if (skill_name.length > 14) {
		compName = skill_name.substr(0, 14) + '...';
	}
	document.getElementById('skillNameDiv_' + skill_id).innerHTML = compName + '?';

	document.getElementById('deleteSkillId').value = skill_id;
	document.getElementById('deleteSkillFlag').value = skill_flag;
}

// This function displays the pop up for a skill after clicking over 'X'.
function displayPopUp1(skill_id, skill_name, skill_flag) {
	var compName = skill_name;

	document.getElementById('popup1_1_' + skill_id).style.display = 'block';

	if (skill_name.length > 14) {
		compName = skill_name.substr(0, 14) + '...';
	}
	document.getElementById('skillNameDiv1_' + skill_id).innerHTML = compName + '?';

	document.getElementById('deleteSkillId').value = skill_id;
	document.getElementById('deleteSkillFlag').value = skill_flag;
}

// This function deletes the user searched skill'.
function deleteUserSkill(module) {
	if (module == '') {
		document.getElementById('deleteSkill').action = '/index.php/profile/deleteUserSkill';
	} else {
		document.getElementById('deleteSkill').action = '/index.php/profile/deleteUserSkill?user=1';
	}
	document.getElementById('deleteSkill').submit();
}

// This function deletes the user owned skill'.
function deleteUserOwnedSkill(module) {
	if (module == '') {
		document.getElementById('deleteOwnedSkill').action = '/index.php/profile/deleteUserOwnedSkill';
	} else {
		document.getElementById('deleteOwnedSkill').action = '/index.php/profile/deleteUserOwnedSkill?user=1';
	}
	// document.getElementById('deleteOwnedSkill').action =
	// '/index.php/profile/deleteUserOwnedSkill';
	document.getElementById('deleteOwnedSkill').submit();
}

/**
 * display a generic popup div by id
 * 
 * @param idpopup
 * @return
 */
function displayPopup(idpopup) {
	document.getElementById(idpopup).style.display = 'block';
	return false;
}

/**
 * display a confirm dialog popup div by id with a parameter to display
 * 
 * @param idpopup
 * @param idparam
 * @param valeur
 *            'inner' : use innerHTML to retrieve data 'value' (default): use
 *            value to retrieve data 'selected' value selected index of a select
 * @return
 */
function displayPopupConfirm(idpopup, idparam, valeur) {
	displayPopup(idpopup);
	switch (valeur) {
	case 'selected':
		document.getElementById(idpopup + '_var_1').innerHTML = document
				.getElementById(idparam).options[document
				.getElementById(idparam).selectedIndex].value;
		break;
	case 'inner':
		document.getElementById(idpopup + '_var_1').innerHTML = document
				.getElementById(idparam).innerHTML;
		break;
	default:
		document.getElementById(idpopup + '_var_1').innerHTML = document
				.getElementById(idparam).value;
		break;
	}
	return false;
}

/**
 * hide a generic popup div by id
 * 
 * @param idpopup
 * @return
 */
function closePopup(idpopup) {
	document.getElementById(idpopup).style.display = 'none';
	return false;
}

/**
 * hide a confirm dialog popup div by id and submit the form identified by its
 * id
 * 
 * @param idpopup
 * @param idform
 * @param submit
 * @return
 */
function closePopupConfirm(idpopup, idform) {
	closePopup(idpopup);
	document.getElementById(idform).submit();
	return false;
}

// This function validates the edit skill form'.
function validateEditSkill(frm, actionUrl, module) {
	var innerTxt = '';
	var divWithError = '';
	var divWithoutError = '';
	var divWithError1 = '';
	var divWithoutError1 = '';
	var levelError = $('error_skill_level').value;
	temp1 = $('validatedIds').value.split(',');
	for (i = 0; i < temp1.length; i++) {
		var val = temp1[i];
		skillLabel = $('skillLabelsHid[' + val + ']').value;
		if ($('skillLevels_' + val).value == 0) {
			innerTxt = innerTxt + '<br>Compétence \'' + skillLabel + '\' : '
					+ levelError + '<br>';
			if (divWithError == '')
				divWithError = divWithError + val;
			else
				divWithError = divWithError + ',' + val;

		} else {
			if (divWithoutError == '')
				divWithoutError = divWithoutError + val;
			else
				divWithoutError = divWithoutError + ',' + val;
		}
		if (frm == 'editUserOwnedSkill') {
			var detailsError = $('error_ownedSkill_edit').value;
			if ($('textarea_comp_desc_0_' + val).value.length < 10) {
				innerTxt = innerTxt + '<br>Compétence \'' + skillLabel
						+ '\' : ' + detailsError + '<br>';
			}
		}

	}

	if ($('unvalidatedIds').value != '') {
		temp2 = $('unvalidatedIds').value.split(',');
		for (i = 0; i < temp2.length; i++) {
			var val = temp2[i];
			skillLabel1 = $('skillLabelsHid1[' + val + ']').value;
			if ($('skillLevels1_' + val).value == 0) {
				innerTxt = innerTxt + '<br>Compétence \'' + skillLabel1
						+ '\' : ' + levelError + '<br>';
				if (divWithError1 == '')
					divWithError1 = divWithError1 + val;
				else
					divWithError1 = divWithError1 + ',' + val;

			} else {
				if (divWithoutError1 == '')
					divWithoutError1 = divWithoutError1 + val;
				else
					divWithoutError1 = divWithoutError1 + ',' + val;
			}
			if (frm == 'editUserOwnedSkill') {
				var detailsError = $('error_ownedSkill_edit').value;
				if ($('textarea_comp_desc_1_' + val).value == '') {
					innerTxt = innerTxt + '<br>Compétence \'' + skillLabel1
							+ '\' : ' + detailsError + '<br>';
				}
			}
		}
	}
	if (innerTxt != '') {
		$('errorDiv').innerHTML = innerTxt;
		document.location = '#errorDiv';
		if (divWithError != '') {
			divIds = divWithError.split(',');
			for (i = 0; i < divIds.length; i++) {
				var tempId = divIds[i];
				$('validated_competence_' + tempId).style.display = 'inline';
			}
		}
		if (divWithoutError != '') {
			divIds2 = divWithoutError.split(',');
			for (i = 0; i < divIds2.length; i++) {
				var tempId = divIds2[i];
				$('validated_competence_' + tempId).style.display = 'none';
				$('validated_competence_scoller_' + tempId).className = 'scroller plus';
			}
		}

		if (divWithError1 != '') {
			divIds1 = divWithError1.split(',');
			for (i = 0; i < divIds1.length; i++) {
				var tempId = divIds1[i];
				$('waiting_competence_' + tempId).style.display = 'inline';
			}
		}
		if (divWithoutError1 != '') {
			divIds3 = divWithoutError1.split(',');
			for (i = 0; i < divIds3.length; i++) {
				var tempId = divIds3[i];
				$('waiting_competence_' + tempId).style.display = 'none';
				$('waiting_competence_scoller_' + tempId).className = 'scroller plus';
			}
		}
		return false;
	} else {
		if (module == '')
			$(frm).action = '/index.php/profile/' + actionUrl;
		else
			$(frm).action = '/index.php/profile/' + actionUrl + '?user=1';
		$(frm).submit();
		return false;
	}
}

// This function sets the hidden field value to the selected skill in
// skillSelectionBox.
function setSkillId(skillId) {
	// jQuery('#skill_id').val(skillId);
	jQuery(document).ready( function() {
		jQuery('#select_add_competence1').each( function(index) {
			jQuery(this).children().each( function(ii) {// gets all childrens of
														// current row
														// i.e.(children[index])
						jQuery(this).css( {
							backgroundColor :"#FFFFFF"
						});

					});
		});
	});

	jQuery('#skill_id').val(skillId);
	jQuery('#category_id').val(0);
	jQuery('#li_' + skillId).css( {
		backgroundColor :'#CCCCCC'
	});
	jQuery('#select_add_competence1').css( {
		height :'140px',
		backgroundColor :"#FFFFFF"
	});
}

//This function sets the hidden field value to the selected category in
//skillSelectionBox.
function setCategoryId(categoryId) {
	
	jQuery('li.li_cat').css( {
		backgroundColor :"#FFFFFF"
	});

	jQuery('#category_id').val(categoryId);
	jQuery('#skill_id').val(0);
	jQuery('#li_cat_' + categoryId).css( {
		backgroundColor :'#CCCCCC'
	});
	jQuery('#select_add_competence1').css( {
		height :'140px',
		backgroundColor :"#FFFFFF"
	});
}

// This function sets the hidden field value to the selected skill in advanced
// skill selection box.
function setAdvancedSkillId(skillId) {
	jQuery(document).ready( function() {
		jQuery('#select_add_competence').each( function(index) {
			jQuery(this).children().each( function(ii) {// gets all childrens of
														// current row
														// i.e.(children[index])
						jQuery(this).css( {
							backgroundColor :"#FFFFFF"
						});

					});
		});
	});
	
	jQuery('li.li_cat').css( {
		backgroundColor :"#FFFFFF"
	});
	
	jQuery('li.li_s').css( {
		backgroundColor :"#FFFFFF"
	});

	jQuery('#skill_id').val(skillId);
	jQuery('#category_id').val(0);
	$('li_' + skillId).style.backgroundColor = '#CCCCCC';
}

//This function sets the hidden field value to the selected category in
//advancedSkillSelectionBox.
function setAdvancedCategoryId(categoryId) {
	
	jQuery('li.li_cat').css( {
		backgroundColor :"#FFFFFF"
	});
	
	jQuery('li.li_s').css( {
		backgroundColor :"#FFFFFF"
	});

	jQuery('#category_id').val(categoryId);
	jQuery('#skill_id').val(0);
	jQuery('#li_cat_' + categoryId).css( {
		backgroundColor :'#CCCCCC'
	});
	jQuery('#select_add_competence1').css( {
		height :'140px',
		backgroundColor :"#FFFFFF"
	});
}

// This function sets the class = scroller_minus for the div
function setDivMinus(divId) {
	if (document.getElementById(divId).style.display == 'none') {

		document.getElementById(divId).style.display = 'inline';
		document.getElementById('add_competence_scoller').className = 'scroller minus';
	}
}

// This function adds the link entered in the link textbox to the div which
// shows the added links for a skill.
function addLink() {
	var linkUrl = $('linkUrl').value;

	if (linkUrl != '') {
		if (linkUrl.length > 100) {
			$('error_link').innerHTML = "100 caractères max espaces compris";
			return false;
		} else if (links == 10) {
			$('error_link').innerHTML = "Vous ne pouvez avoir plus de 10 liens";
			return false;
		} else {
			$('addedLinks').style.display = 'inline';
			if (linkUrl.length > 50) {
				linkPart1 = linkUrl.substring(0, 50);
				linkPart2 = ' ' + linkUrl.substring(50, linkUrl.length);
			} else {
				linkPart1 = linkUrl;
				linkPart2 = '';
			}
			$('addedLinks').innerHTML = $('addedLinks').innerHTML
					+ '<div id="my_'
					+ links
					+ '" class="font_size_11"><input type="hidden" name="links[]" id="links[]" value="'
					+ linkUrl
					+ '">'
					+ linkPart1
					+ linkPart2
					+ '&nbsp;<a href="#" title="" class="cross_link" onclick="javascript:return removeLink(\'my_\',\''
					+ links + '\');">X</a></div>';
			$('linkUrl').value = '';
			links++;

			return false;
		}

	} else {
		return false;
	}
}

// This function adds the link entered in the link textbox to the div which
// shows the added links for a skill while editing the validated skills.
function addLinks_0(skillId) {
	var linkUrl = $('linkUrl_0_' + skillId).value;
	if (linkUrl != '') {
		if (linkUrl.length > 100) {
			$('error_link0').innerHTML = "100 caractères max espaces compris";
			return false;
		} else if (links0 == 10) {
			$('error_link0').innerHTML = "Vous ne pouvez avoir plus de 10 liens";
			return false;
		} else {
			if (linkUrl.length > 50) {
				linkPart1 = linkUrl.substring(0, 50);
				linkPart2 = ' ' + linkUrl.substring(50, linkUrl.length);
			} else {
				linkPart1 = linkUrl;
				linkPart2 = '';
			}

			$('addedLinks_0_' + skillId).innerHTML = $('addedLinks_0_' + skillId).innerHTML
					+ '<div id="my_0_'
					+ links0
					+ '" class="font_size_11"><input type="hidden" name="links0['
					+ skillId
					+ '][]" id="links0['
					+ skillId
					+ '][]" value="'
					+ linkUrl
					+ '">'
					+ linkPart1
					+ linkPart2
					+ '&nbsp;<a href="#" title="" class="cross_link" onclick="javascript:return removeLink(\'my_0_\',\''
					+ links0 + '\');">X</a></div>';
			$('linkUrl_0_' + skillId).value = '';
			links0++;
			return false;
		}

	} else {
		return false;
	}
}

// This function adds the link entered in the link textbox to the div which
// shows the added links for a skill while editing the unvalidated skills.
function addLinks_1(skillId) {
	var linkUrl = $('linkUrl_1_' + skillId).value;
	if (linkUrl != '') {
		if (linkUrl.length > 100) {
			$('error_link1').innerHTML = "100 caractères max espaces compris";
			return false;
		} else if (links1 == 10) {
			$('error_link1').innerHTML = "Vous ne pouvez avoir plus de 10 liens";
			return false;
		} else {
			if (linkUrl.length > 50) {
				linkPart1 = linkUrl.substring(0, 50);
				linkPart2 = ' ' + linkUrl.substring(50, linkUrl.length);
			} else {
				linkPart1 = linkUrl;
				linkPart2 = '';
			}

			$('addedLinks_1_' + skillId).innerHTML = $('addedLinks_1_' + skillId).innerHTML
					+ '<div id="my_1_'
					+ links1
					+ '" class="font_size_11"><input type="hidden" name="links1['
					+ skillId
					+ '][]" id="links1['
					+ skillId
					+ ']" value="'
					+ linkUrl
					+ '">'
					+ linkPart1
					+ linkPart2
					+ '&nbsp;<a href="#" title="" class="cross_link" onclick="javascript:return removeLink(\'my_1_\',\''
					+ links1 + '\');">X</a></div>';
			$('linkUrl_1_' + skillId).value = '';
			links1++;

			return false;
		}
	} else {
		return false;
	}
}

// This function removes the link added.
function removeLink(prefix, linkUrl) {

	$(prefix + linkUrl).innerHTML = '';
	if (prefix == 'my_') {
		links--;
	} else if (prefix == 'my_0_') {
		links0--;
	} else if (prefix == 'my_1_') {
		links1--;
	}
	return false;
}

// This function validates the send message form.
function validateMessage(frm) {
	var innerTxt = '';

	if (trimAll($('subject').value) == '') {
		innerTxt = innerTxt + $('subjectEmpty').value + '<br>';
	}
	if (trimAll($('message_content').value) == '') {
		innerTxt = innerTxt + $('bodyEmpty').value;
	}
	if (innerTxt != '') {
		$('fieldErrors').innerHTML = innerTxt;
		$('fieldErrors').style.display = 'inline';
		return false;
	} else {
		$(frm).submit()
		return false;
	}
}

/*
 * DESCRIPTION: Removes leading and trailing spaces.
 * 
 * PARAMETERS: Source string from which spaces will be removed;
 * 
 * RETURNS: Source string with whitespaces removed.
 */
function trimAll(strValue) {

	var objRegExp = /^(\s*)$/;

	// check for all spaces
	if (objRegExp.test(strValue)) {
		strValue = strValue.replace(objRegExp, '');
		if (strValue.length == 0)
			return strValue;
	}

	// check for leading & trailing spaces
	objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
	if (objRegExp.test(strValue)) {
		// remove leading and trailing whitespace characters
		strValue = strValue.replace(objRegExp, '$2');
	}
	return strValue;
}

// This function makes all check boxes checked.
function checkAll(frm, checkboxControl) {
	var chkboxLength = document.inboxFrm.receivedChk.length;
	if (chkboxLength) {
		for (i = 0; i < chkboxLength; i++) {
			document.inboxFrm.receivedChk[i].checked = true;
		}
	} else {
		document.inboxFrm.receivedChk.checked = true;
	}
}

// This function makes all check boxes unchecked.
function uncheckAll(frm, checkboxControl) {
	var chkboxLength = document.inboxFrm.receivedChk.length;
	if (chkboxLength) {
		for (i = 0; i < chkboxLength; i++) {
			document.inboxFrm.receivedChk[i].checked = false;
		}
	} else {
		document.inboxFrm.receivedChk.checked = false;
	}
}

// This function sets all selected items ids to one hidden field and submits the
// form of delete items.
function deleteSelectedItems(frm, checkboxControl) {
	var chkboxLength = document.inboxFrm.receivedChk.length;
	var selectedIds = '';
	if (chkboxLength) {
		for (i = 0; i < chkboxLength; i++) {
			if (document.inboxFrm.receivedChk[i].checked == true) {
				if (selectedIds == '')
					selectedIds = selectedIds
							+ document.inboxFrm.receivedChk[i].value;
				else
					selectedIds = selectedIds + ','
							+ document.inboxFrm.receivedChk[i].value;
			}
		}
	} else {
		selectedIds = document.inboxFrm.receivedChk.value;
	}
	$('selectedIds').value = selectedIds;
	$('deleteSelected').submit();
	return false;
}