// Fonctions pour afficher ou cacher des div


function display(divId, status){
  if (document.getElementById && document.getElementById(divId) != null){
  	if (status == 'show'){
    document.getElementById(divId).style.visibility='visible';
    document.getElementById(divId).style.display='block';
	}
	if (status == 'hide'){
    document.getElementById(divId).style.visibility='hidden';
    document.getElementById(divId).style.display='none';
	}
  }
}
  
function switchdisplay(divId){
	if (document.getElementById(divId).style.visibility =='hidden'){display(divId, 'show')} else {display(divId, 'hide')}
	}

function hide(divId){
display(divId, 'hide')}

function show(divId){
display(divId, 'show')}

//Fonction pour affecter un comportement à un objet

function addEvent(obj, type, fn, par){
 
  if(document.getElementById(obj).addEventListener){
 
    document.getElementById(obj).addEventListener(type, function(event){        
 
      return fn.call(obj, event, par);
 
    }, false );
 
  }else if(document.getElementById(obj).attachEvent){
 
    document.getElementById(obj).attachEvent("on"+type, function(e){
 
      if (!e) var e = window.event;   
 
      return fn.call(document.getElementById(obj), e, par);
 
    });
 
  }
 }


//Fonction pour changer la classe css d'un élement

function changeClass(element, className){
//window.alert(element);
//window.alert(className);
document.getElementById(element).className=className;
}

//Fonctions pour tester un contenu

function checkIfSelection(controlId){
if (document.getElementById(controlId).options[0].selected){
		recordError(controlId);
	}
}

function checkIfFilled(controlId){
		if (document.getElementById(controlId).value == ""){
		recordError(controlId);
	}
}

function checkIfAlpha(controlId){
	var mask =  /^[-a-zA-Z\s]+$/;
	if (!document.getElementById(controlId).value.match(mask)){
	recordError(controlId);
		}
}

function checkIfNumeric(controlId){
	reg = /^\d+$/
	if (reg.exec(document.getElementById(controlId).value) == null && document.getElementById(controlId).value!=""){recordError(controlId)};
	//if (document.getElementById(controlId).value == '59'){recordError(controlId);}
}

function checkIfAlphanumeric(controlId){
	var mask = /^[-0-9a-zA-Z\s]+$/;
	if (!document.getElementById(controlId).value.match(mask)){
	recordError(controlId);
}
}

function checkIfPhone(controlId){
	var mask = /^[-0-9 \+\().\-]+$/;
	if (!document.getElementById(controlId).value.match(mask) && document.getElementById(controlId).value != ""){
	recordError(controlId);
}
}


function checkIfSize(controlId, min, max){
	//window.alert(controlId);
	if (document.getElementById(controlId).value.length > max || document.getElementById(controlId).value.length < min){
	recordError(controlId);
}
}

function checkIfValidDate(controlIdMonth, controlIdYear){
month = document.getElementById(controlIdMonth).selectedIndex+1;
year = document.getElementById(controlIdYear).options[document.getElementById(controlIdYear).selectedIndex].value;
selectedDate = new Date(year, month, 1);
currentDate = new Date();
if (selectedDate < currentDate) {
recordError(controlIdMonth);
recordError(controlIdYear);
}
}


function checkIfSame(controlId1, controlId2){
		if (document.getElementById(controlId1).value != document.getElementById(controlId2).value){
		recordError(controlId1);
		recordError(controlId2);
	}
}


function checkIfMail(controlId){
	indexAroba = document.getElementById(controlId).value.indexOf('@');
	indexPoint = document.getElementById(controlId).value.lastIndexOf('.');
	if (document.getElementById(controlId).value.length < 5 || indexAroba < 1 || indexPoint < indexAroba){
	recordError(controlId);
	}
	}

function checkIfChecked(controlId){
	//window.alert("I check");
	if (document.getElementById(controlId).checked==false){
	recordError(controlId);
	}
}


function checkIfCreditCardNr(controlId){
stringNumCB = document.getElementById(controlId).value;
intNumCB = parseInt(stringNumCB);
intResultLuhn = 0;
	if(stringNumCB.length == 16 && !isNaN(intNumCB)){
      for(i=0;i<16;i+=2){
      	intRang1 = parseInt(stringNumCB.charAt(i)) * 2;
      	if(intRang1>9){
        	intRang1 = intRang1 - 9;
        };
        intResultLuhn = intResultLuhn + intRang1;
      }
      for(i=1;i<16;i+=2){
      	intRang2 = parseInt(stringNumCB.charAt(i));
      	intResultLuhn = intResultLuhn + intRang2;
	  };
	}
if(intResultLuhn%10 != 0 || intResultLuhn == 0){
      recordError(controlId);
}
}

function checkIfZipCode(ControlId){
	checkIfNumeric(ControlId);
}

function checkIfWeekEndTourTicket(controlId){
	checkIfNumeric(controlId);
}

//fonction pour se positionner sur un élement
function focus(t_input)
{
document.getElementById(t_input).focus();
}


//anciennes fonctions

function redirect(page){
document.F1.H_REDIRECT.value = page;
document.F1.submit()}





