﻿// JScript File

function check_login_form(f)
{
   if (f.txtEmailLogin.value.length<1)
    {
        alert("Mot de passe Non Valide.");
        f.txtEmailLogin.focus();
        if(document.all || document.getElementByID){
            // change the color of text field
            f.txtEmailLogin.style.background = "yellow";
        }
        // make sure the form is not submitted
        return false;    
    }
    
    if(!check_email(f.txtEmailLogin.value)){
            alert("E-mail non valide.");
            f.txtEmailLogin.focus(); 
            // if the browser is Netscape 6 or IE
            if(document.all || document.getElementByID){
            // change the color of text field
                f.txtEmailLogin.style.background = "yellow";
            }
            // make sure the form is not submitted
            return false;
        }       
        

    if (f.txtPassLogin.value.length<4)
    {
        alert("Veuillez entrez un mot de passe de plus de 3 charactères.");
        f.txtPassLogin.focus();
        if(document.all || document.getElementByID){
            // change the color of text field
            f.txtPassLogin.style.background = "yellow";
        }
        // make sure the form is not submitted
        return false;    
    }  
}

function check_reg_form(f)
{
   if (f.txtEmailReg.value.length<1)
    {
        alert("E-mail non valide.");
        f.txtEmailReg.focus();
        if(document.all || document.getElementByID){
            // change the color of text field
            f.txtEmailReg.style.background = "yellow";
        }
        // make sure the form is not submitted
        return false;    
    }
    if (f.txtConfEmailReg.value.length<1)
    {
        alert("E-mail non valide.");
        f.txtConfEmailReg.focus();
        if(document.all || document.getElementByID){
            // change the color of text field
            f.txtConfEmailReg.style.background = "yellow";
        }
        // make sure the form is not submitted
        return false;    
    }
    if(!check_email(f.txtEmailReg.value)){
            alert("E-mail non valide.");
            f.txtEmailReg.focus(); 
            // if the browser is Netscape 6 or IE
            if(document.all || document.getElementByID){
            // change the color of text field
                f.txtEmailReg.style.background = "yellow";
            }
            // make sure the form is not submitted
            return false;
        }
       
        if (f.txtEmailReg.value!=f.txtConfEmailReg.value)
        {
            alert("E-mail et E-mail confirmé ne correspond pas");
            f.txtConfEmailReg.focus();
            if(document.all || document.getElementByID){
                // change the color of text field
                f.txtConfEmailReg.style.background = "yellow";
            }
            // make sure the form is not submitted
            return false;    
        }

    if (f.txtPasswordReg.value.length<4)
    {
        alert("Veuillez entrez un mot de passe de plus que 3 charactères.");
        f.txtPasswordReg.focus();
        if(document.all || document.getElementByID){
            // change the color of text field
            f.txtPasswordReg.style.background = "yellow";
        }
        // make sure the form is not submitted
        return false;    
    }
    
    if (f.txtConfPassReg.value.length<4)
    {
        alert("Veuillez entrez un mot de passe de plus que 3 charactères.");
        f.txtConfPassReg.focus();
        if(document.all || document.getElementByID){
            // change the color of text field
            f.txtConfPassReg.style.background = "yellow";
        }
        // make sure the form is not submitted
        return false;    
    }
   
    if (f.txtConfPassReg.value!=f.txtPasswordReg.value)
    {
        alert("Mot de passe et Mot de pass confirmé ne correspond pas");
        f.txtConfPassReg.focus();
        if(document.all || document.getElementByID){
            // change the color of text field
            f.txtConfPassReg.style.background = "yellow";
        }
        // make sure the form is not submitted
        return false;    
    } 
}

function check_forgot_form(f)
{
   if (f.txtEmailForgot.value.length<1)
    {
        alert("E-mail non valide.");
        f.txtEmailForgot.focus();
        if(document.all || document.getElementByID){
            // change the color of text field
            f.txtEmailForgot.style.background = "yellow";
        }
        // make sure the form is not submitted
        return false;    
    }
    
    if(!check_email(f.txtEmailForgot.value)){
            alert("E-mail non valide.");
            f.txtEmailForgot.focus(); 
            // if the browser is Netscape 6 or IE
            if(document.all || document.getElementByID){
            // change the color of text field
                f.txtEmailForgot.style.background = "yellow";
            }
            // make sure the form is not submitted
            return false;
        }       
}

function check_email(e) {
    ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

    for(i=0; i < e.length ;i++){
        if(ok.indexOf(e.charAt(i))<0){ 
            return (false);
        }   
    } 

    if (document.images) {
        re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
        re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
        if (!e.match(re) && e.match(re_two)) {
            return (-1);        
        } 
    }
}

  function limitText(limitField, limitCount, limitNum) {
    if (limitField.value.length > limitNum) {
      limitField.value = limitField.value.substring(0, limitNum);
    } else {
      limitCount.value = limitNum - limitField.value.length;
    }
  }


  function addUpload() {
    //Increment the value of total
    var jtotal = document.getElementById('totalUploads');
    jtotal.value++;

    //add element 
    var ni = document.getElementById('uploadsDiv');
    var numi = document.getElementById('theValueUploads');
    var num = (document.getElementById('theValueUploads').value -1)+ 2;
    numi.value = num;
    var divIdName = 'my'+num+'UploadDiv';
    var newdiv = document.createElement('div');     
    newdiv.setAttribute('id',divIdName);
   
    newdiv.innerHTML = 'Document '+num+': <input type="file" size="40" name="file'+num+'" /> - Description: <input type="text" name="desc'+num+'" size="50"><br />';

    ni.appendChild(newdiv);
  }

  function deleteLastUpload(){
      var numi = document.getElementById('theValueUploads');
      removeElementUpload('my'+numi.value+'UploadDiv');
      numi.value--;
  }

  function removeElementUpload(divNum) {
    var d = document.getElementById('uploadsDiv');
    var olddiv = document.getElementById(divNum);
    d.removeChild(olddiv);
    
    //Decrement the value of total
    var jtotal = document.getElementById('totalUploads');
    jtotal.value--;     
  }

  function add_extra_doc(){
    //Increment the value of total
    var jtotal = document.getElementById('totalUploads');
    jtotal.value++;

    //add element 
    var ni = document.getElementById('uploadsDiv');
    var numi = document.getElementById('theValueUploads');
    var num = (document.getElementById('theValueUploads').value -1)+ 2;
    numi.value = num;
    var divIdName = 'my'+num+'UploadDiv';
    var newdiv = document.createElement('div');     
    newdiv.setAttribute('id',divIdName);
   
    newdiv.innerHTML = '<table border="1"><tr><td><input type="file" size="30" name="file'+num+'"></td><td><input type="text" size="40" name="desc'+num+'"></td><td width="300"><input type="checkbox" name="AE_AH_AA'+num+'"></td><td width="300"><input type="checkbox" name="leadership'+num+'"></td><td width="300"><input type="checkbox" name="arts'+num+'"></td><td width="300"><input type="checkbox" name="science'+num+'"></td><td width="300"><input type="checkbox" name="sports'+num+'"></td></tr></table>';

    ni.appendChild(newdiv);
  }

  function deleteLastExtraDoc(){
      var numi = document.getElementById('theValueUploads');
      removeElementExtraDoc('my'+numi.value+'UploadDiv');
      numi.value--;
  }

  function removeElementExtraDoc(divNum) {
    var d = document.getElementById('uploadsDiv');
    var olddiv = document.getElementById(divNum);
    d.removeChild(olddiv);
    
    //Decrement the value of total
    var jtotal = document.getElementById('totalUploads');
    jtotal.value--;     
  }
  
    function add_referee_doc(){
    //Increment the value of total
    var jtotal = document.getElementById('totalUploads');
    jtotal.value++;

    //add element 
    var ni = document.getElementById('uploadsDiv');
    var numi = document.getElementById('theValueUploads');
    var num = (document.getElementById('theValueUploads').value -1)+ 2;
    numi.value = num;
    var divIdName = 'my'+num+'UploadDiv';
    var newdiv = document.createElement('div');     
    newdiv.setAttribute('id',divIdName);
   
    newdiv.innerHTML = '<table align="center"><tr><td><input type="file" size="30" name="file'+num+'"></td><td><input type="text" size="40" name="desc'+num+'" value="Description du Fichier"></td></tr></table>';
    ni.appendChild(newdiv);
  }  
  
  function showUploadMessage(){
	getElementById('boxTwo').style.visibility='visible';
	getElementById('boxTwo').style.width='500px';
	getElementById('boxTwo').style.height='80%';
	getElementById('container').style.width='50%';
	getElementById('container').style.height='50%';
  }
