function changeCompetenceSelection() {
  document.location.href = document.getElementById("selectBranch").options[document.getElementById("selectBranch").selectedIndex].value;
}

//String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };

// Removes leading whitespaces
function LTrim(value) {

  var re = /\s*((\S+\s*)*)/;
  return value.replace(re, "$1");

}

// Removes ending whitespaces
function RTrim(value) {

  var re = /((\s*\S+)*)\s*/;
  return value.replace(re, "$1");

}

// Removes leading and ending whitespaces
function trim(value) {

  return LTrim(RTrim(value));

}

// clear form fields
function clearDefault(el) {
  var defaultValue = "";
  if (defaultValue == el.value) {
    el.value = "";
  }
}

function checkEnter(e, caller) //e is event object passed from function invocation
{

  var characterCode //literal character code will be stored in this variable

  if (e && e.which || e.which == 0) { //if which property of event object is supported (NN4)

    e = e;
    characterCode = e.which; //character code is contained in NN4's which property
  }
  else {
    e = event;
    characterCode = e.keyCode //character code is contained in IE's keyCode property
  }

  if (characterCode == 13)//if generated character code is equal to ascii 13 (if enter key)
  {
    if (document.all) {
      e.returnValue = false;
      e.cancel = true;
    }
    else {
      e.preventDefault();
    }
    var obj = document.getElementById(caller);
    if (obj) {

      if (obj.click) {
        obj.click();
      }
    }
    return false;
  }
  else {
    return true;
  }

}

function sendMail(e) //e is event object passed from function invocation
{
  var characterCode //literal character code will be stored in this variable

  if (e && e.which || e.which == 0) { //if which property of event object is supported (NN4)

    e = e;
    characterCode = e.which; //character code is contained in NN4's which property
  }
  else {
    e = event;
    characterCode = e.keyCode //character code is contained in IE's keyCode property
  }

  if (characterCode == 13)//if generated character code is equal to ascii 13 (if enter key)
  {
    if (document.all) {
      e.returnValue = false;
      e.cancel = true;
    }
    else {
      e.preventDefault();
    }

    //	var obj = document.getElementById(caller);
    var obj = $("input.btSubmit");
    if (obj) {

      if (obj.click) {
        obj.click();
      }
    }
    onSubmit();
    return false;
  }
  else {
    return true;
  }

}


function quickSearch(query, type) {
  var query = encodeURIComponent(query);

  //alert(query);

  if (query != '') {
    if (type == '') {
      location.href = 'Search.aspx?search=' + query;
    }
    else {
      var loc = location.href;
      var arrayloc = loc.split('/');

      /*var url = loc.substring(0,loc.length-5);*/
      var url = '';
      for (var i = 0; i < 4; i++) {
        url = url + arrayloc[i] + '/';
      }

      if (arrayloc.length > 5)
        url = url + arrayloc[4];
      else
        url = url + arrayloc[4].substring(0, arrayloc[4].length - 5);

      location.href = url + '/search.aspx?search=' + query;

    }
  }
}

function doSearch(type) {
  var q = '?search=';
  if (qBox != null) {
    q += encodeURI(qBox.value);
  }
  var urlq = '/search.aspx';

  var el = document.getElementById("advancedSearch");
  var display = el.style.display;


  var qBox = document.getElementById('searchf1Txt');
  if (qBox != null) {
    q += encodeURI(qBox.value);
  }

  if (display == "none") {
    //simple search
    urlq += q;

    var loc = location.href;
    var arrayloc = loc.split('/');

    var url = '';
    for (var i = 0; i < 4; i++) {
      url = url + arrayloc[i] + '/';
    }
    if (type == '') {
      location.href = url + urlq.substring(1, urlq.length);
    }
    else {
      if (arrayloc.length > 5)
        url = url + arrayloc[4];
      else
        url = url + arrayloc[4].substring(0, arrayloc[4].length - 5);
      location.href = url + '/ToolsMenu' + urlq;
    }

    /*document.location.href = '/ToolsMenu' + url;*/



    return;
  }
  //alert(Date.parse(document.getElementById('inputF1TextF').value));
  // alert(Date.parse(document.getElementById('inputF1TextT').value));

  //         url += q;
  //         document.location = url+"&isAdvace=true";
  return;


}

function profileSearch() {

  var isValue = false;

  var txtName = document.getElementById('txtName');
  var name = "";

  if (txtName != null) {
    name = encodeURIComponent(txtName.value);
    if (trim(name) != '') { isValue = true; }
  }

  var txtPosition = document.getElementById('txtPosition');
  var position = "";
  if (txtPosition != null) {
    position = encodeURIComponent(txtPosition.value);
    if (trim(position) != '') { isValue = true; }
  }

  var txtTelefon = document.getElementById('txtTelefon');
  var phone = "";
  if (txtTelefon != null) {
    phone = encodeURIComponent(txtTelefon.value);
    if (trim(phone) != '') { isValue = true; }
  }

  var txtUserName = document.getElementById('txtUserName');
  var userName = "";
  if (txtUserName != null) {
    userName = encodeURIComponent(txtUserName.value);
    if (trim(userName) != '') { isValue = true; }
  }

  var txtDepartment = document.getElementById('txtDepartment');
  var department = "";
  if (txtDepartment != null) {
    department = encodeURIComponent(txtDepartment.value);
    if (trim(department) != '') { isValue = true; }
  }

  var txtQualification = document.getElementById('txtQualification');
  var qualification = "";
  if (txtQualification != null) {
    qualification = encodeURIComponent(txtQualification.value);
    if (trim(qualification) != '') { isValue = true; }
  }

  if (isValue) {
    var query = '?name=' + name + '&position=' + position + '&telephone=' + phone + '&user=' + userName + '&department=' + department + '&qualification=' + qualification + '&page=1';
    //alert(location.href);
    location.href = '/Sitetools/ProfileSearch.aspx' + query;
  }
  else {
    location.href = '/Sitetools/ProfileSearch.aspx';
  }
}

function toggleAdvancedSearch() {
  var el = document.getElementById("advancedSearch");

  var simple = document.getElementById('h2Simple');
  var advance = document.getElementById('h2Advance');

  var display = el.style.display;

  if (i != "2") {
    el.style.display = "none";
    simple.className = "h2Active";
    advance.className = "boxTitle1";

  }
  else {
    el.style.display = "block";
    advance.className = "h2Active";
    simple.className = "boxTitle1";
  }
}

function bodyOnLoad() {

  var hiddjobsN = document.getElementById('hiddenJobsNames');
  var jobsN = "";
  if (hiddjobsN != null) {
    jobsN = hiddjobsN.value;
  }

  var hiddjobsP = document.getElementById('hiddenJobsPaths');
  var jobsP = "";
  if (hiddjobsP != null) {
    jobsP = hiddjobsP.value;
  }
  var divheightContent = 0;
  if (document.getElementById('content') != null) {
    divheightContent = document.getElementById('content').offsetHeight;
  }

  var divheightJobs = 0;
  if (document.getElementById('jobs') != null) {
    divheightJobs = document.getElementById('jobs').offsetHeight;
  }

  var i = 0, size = 0, offserFrontContent = 0;
  var firstPart, lastpart, innerText = "";
  firstPart = "<li><a href='";
  midle = "'>";
  lastPart = "</a></li>";
  var stringNames = jobsN.split("|");
  var stringPaths = jobsP.split("|");

  if (document.getElementById('rightContent') != null) {
    size = stringNames.length - 1;
    offserContent = divheightContent - 10;
    for (i = 0; i < size; i++) {
      if (document.getElementById('rightContent').offsetHeight <= offserContent) {
        if ((stringNames[i] != "") && (stringPaths[i] != "")) {
          innerText += firstPart + stringPaths[i] + midle + stringNames[i] + lastPart + " ";
          document.getElementById('lastFC').innerHTML = innerText;
        }
      } else

        break;
    }
  }
  //document.getElementById('lastFC').innerHTML=innerText;
  //   }catch(err)
  //  {}
}

function sendData() {
  //alert("bu");
  var hiddResponsable = document.getElementById('responsible');
  var responsible = "";
  if (hiddResponsable != null) {
    responsible = hiddResponsable.value;
  }

  var hiddBackToThePage = document.getElementById('back');
  var back = "";
  if (hiddBackToThePage != null) {
    back = hiddBackToThePage.value;
  }
  alert(responsible);
  alert(back);
  Session("responsible") = responsible;
  Session("linkBack") = back;

}

function wopen(url, w, h) {
  // Fudge factors for window decoration space.
  // In my tests these work well on all platforms & browsers.
  w += 50;
  h += 96;
  //alert(w +" "+h);
  var win = window.open(url, 'Flash Install', 'width=' + w + ', height=' + h + ', ' + 'location=no, menubar=no, ' + 'status=no, toolbar=no, scrollbars=yes, resizable=no');
  win.resizeTo(w, h);
  win.focus();
}
/*
function getKey(evt) {
if (evt && ns6)
typedKey=evt.which;
else
typedKey=event.keyCode;
if (typedKey == 13) {
if(document.all) {
window.event.cancelBubble='true';
window.event.returnValue = false;
} else {
evt.stopPropagation();
evt.preventDefault();
}

document.getElementById("searchbutton").click();
}
}
*/

function getUrlForPrint() {
  var printLink = document.getElementById('printLink');

  if (printLink != null) {
    hreflink = printLink.value;
    var oldurl = location.href + "?";
    var stringHref = oldurl.split("?");
    var url;
    if (stringHref[1] != "") {
      url = location.href + "&p=1";
    }
    else {
      url = location.href + "?p=1";
    }
    printLink.href = url;
  }
}

function redirectUrl(qs) {

  var qsNV = qs.split("=");
  var oldurl = location.href;
  //var addAnchor="";

  if (oldurl.search('sc_lang') >= 0) {
    var paramIndex = oldurl.search('sc_lang');
    var sc_lang_Val = oldurl.substring(paramIndex);
    var myHref = oldurl.substring(0, paramIndex);
    if (sc_lang_Val.search('&') >= 0) {
      var params = sc_lang_Val.split('&');
      var sc_lang = "";
      var otherParams = "";
      for (var i = 0; i < params.length; i++) {
        if (params[i].split('=')[0] == 'sc_lang')
          sc_lang = params[i];
        else
          otherParams += params[i] + '&';
      }
      location.href = myHref + otherParams + sc_lang.replace(sc_lang.split('=')[1], qsNV[1]);
    }
    else {
      location.href = myHref + sc_lang_Val.replace(sc_lang_Val.split('=')[1], qsNV[1]);
      return;
    }
  }
  else {
    if (oldurl.search('=') >= 0)//I can't search for '?' to see if there are other query string parameters so I used '=' instead. '?' throws a invalid qualifier errro.
      location.href = oldurl + '&' + qs;
    else
      location.href = oldurl + '?' + qs;
  }

  /* Changed by LDU 2010-05-03

  if (oldurl.search('#')>=0){
  // if exist anchor prepare url
  var ank = oldurl.split('#');
  addAnchor = oldurl.substr(oldurl.search('#'),ank[1].length+1);
  oldurl = oldurl.substr(0, oldurl.length-(ank[1].length+1));
  }
	
  var stringHref = oldurl.split("?");
  if (stringHref[1] != null){
  // if exist query prepare url
  if (stringHref[1].search(qsNV[0])>=0){
  // if parameter exist in query just change the value
  var findString ="";
  if (stringHref[1].search('&')>=0){ 
  var qss = stringHref[1].split('&');
  for(var i=0;i<qss.length;i++)
  findString=(qss[i].split('='))[1];
  }
  else
  findString = (stringHref[1].split('='))[1];			
  url = oldurl.replace('=' + findString, '=' + qsNV[1]);
  }		
  else
  //add parameter in query
  url=oldurl + "&" + qs;
  }
  else
  url = stringHref[0] + "?" + qs;
		
  url = url + addAnchor; // if anchor exist
  location.href=url;

  */
}
