var oldrub;
function swap_field(num_rub){
    if (oldrub && num_rub != oldrub){
        document.getElementById("opt"+oldrub).style.display ="none";
    }
    if (oldrub != num_rub){
        document.getElementById("opt"+num_rub).style.display ="block";
        oldrub = num_rub;
    } 
}


function svd(nom_div){
    var div = document.getElementById(nom_div);
    div.style.display = "block";
}

function sivd(nom_div){
    var div = document.getElementById(nom_div);
    div.style.display = "none";
}

/* liens avec question */
function dolink(url,rem,target) {
	if (confirm(rem)) {
        if (!target)
		    document.location.href = url;
        else
            document.getElementById(target).src = url;
	}
}

function open_url(url,titre,width,height){
  eval("window.open('"+url+"&titre="+titre+"&width="+width+"&height="+height+"','pop_img','width="+width+",height="+height+",scrollbars=no,resizable=no,toolbar=no,status=no,location=no,left=0,top=0');");
}


function show_props(obj, objName) {
    if (!objName)
        objName = obj;
    var result = "";
    for (var i in obj) {
        result += "<p>"+ objName + "." + i + " = " + obj[i] + "</p>\n";
    }
    return result;
} 

function form_validation() {
    var checkEmail = "@.";
    var EmailValid = false;
    var EmailAt = false;
    var EmailPeriod = false;
    var err = false;
    var checkStr = document.getElementById('email_ct').value;
    var TabChecks = document.getElementsByName('motif_cnt');

    i=0;
    while(i<TabChecks.length){
        if (TabChecks[i].type == "radio" && TabChecks[i].checked == true){
            motif = TabChecks[i].value;
        }
        i++;
    }
    
    if (document.getElementById('nom_ct').value == ''){
        alert('Veuillez saisir votre Nom');
        document.getElementById('nom_ct').focus();
        err = true;
    }
    if (document.getElementById('email_ct').value == '' && !err){
        alert('Veuillez saisir votre E-mail');
        document.getElementById('email_ct').focus();
        err = true;
    }
    if (motif == 12 && !err){
        if (document.getElementById('cv_cnt').value == '' && !err){
            alert('Veuillez fournir un CV');
            document.getElementById('cv_cnt').focus();
            err = true;
        }
        if (document.getElementById('motiv_cnt').value == '' && !err){
            alert('Veuillez fournir une lettre de motivation');
            document.getElementById('motiv_cnt').focus();
            err = true;
        }
    
    }
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkEmail.length;  j++)
    {
      if (ch == checkEmail.charAt(j) && ch == "@")
        EmailAt = true;
      if (ch == checkEmail.charAt(j) && ch == ".")
        EmailPeriod = true;
	  if (EmailAt && EmailPeriod)
		break;
	  if (j == checkEmail.length)
		break;
	}
	// if both the @ and . were in the string
    if (EmailAt && EmailPeriod)
    {
		EmailValid = true
		break;
	}
  }
  if (!EmailValid && !err)
  {
    alert("L'adresse électronique rentrée est invalide !");
    document.getElementById('email_c').focus();
    err = true;
  }
  if (err == false)
      return true;
  else
      return false;

}
