﻿function showhide(id) {
  if (document.getElementById(id)) {
    if (document.getElementById(id).style.display=='block') {	
      document.getElementById(id).style.display='none';
    } else {
      document.getElementById(id).style.display='block';
    }
  }	
  return false;
};

function hide(id) {
  if (document.getElementById(id)) {
      document.getElementById(id).style.display='none';
  }	
  return false;
};

function show(id) {
  if (document.getElementById(id)) {
      document.getElementById(id).style.display='block';
  }	
  return false;
};

function set(id,value) {
  if (document.getElementById(id)) {
   document.getElementById(id).innerHTML=value;
  }
  return false;
}

function get(id) {
  if (document.getElementById(id))
   return document.getElementById(id).value;
  else return '';
}

function isPrefMobileCH(str){
  return ((str=='76') || (str=='77') || (str=='78') || (str=='79'));
}

function isMobileNumber(id){
  var str=get(id);
  var isMobile=false;
  var myRegExp = new RegExp(" ","gi"); 
  str=str.replace(myRegExp, "" ); 
  if ((str.length>6) && ((str.slice(0,4)=='++41') || (str.slice(0,4)=='0041')))
    isMobile=isPrefMobileCH(str.slice(4,6));
  else if ((str.length>5) && (str.slice(0,3)=='+41'))
    isMobile=isPrefMobileCH(str.slice(3,5));	
  else if ((str.length>3) && (str.slice(0,1)=='0'))
    isMobile=isPrefMobileCH(str.slice(1,3));	
  else isMobile=isPrefMobileCH(str.slice(0,2));	
  return isMobile;
}

function checkTelNumber(id,len,mess1,mess2) {
  if (get(id).length<len) {
    alert(mess1); return false;
  } else if (isMobileNumber(id)) {
    alert(mess2); return false;
  } else return true;
}


function replaceSpecialChars(txt) {
  var myCharsA="ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÌÍÎÏìíîïÙÚÛÜùúûüÿÑñÇç";
  var myChars='AAAAAAaaaaaaOOOOOOooooooEEEEeeeeIIIIiiiiUUUUuuuuyNnCc';
  myreturn=txt;
  for (i=0;i<myCharsA.length; i=i+1) {
	var regTxt = new RegExp(myCharsA.charAt(i),'g');  
    myreturn=myreturn.replace(regTxt,myChars.charAt(i));
  }

  return myreturn;  
}

function redirectURLFromList(cbList,title,lng) {
  if (cbList) {
    var urlparams='/'+lng+'/'+cbList.value+'/';
    var myTitle=title+' '+document.getElementById('opt_'+cbList.value).innerHTML;
	myTitle=replaceSpecialChars(myTitle);
	myTitle=encodeURIComponent(myTitle.replace(/ /g, '_'));	
    window.location.href='/index.cfm'+urlparams+myTitle;
  }	
  return false;
}

//----------------------------------------------------------------------------------------
function doSubmitfrmSearch(theAction){
  document.getElementById('frmSearch').action=theAction; 
  document.frmSearch.submit();
  return false;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
