// JScript File

function check_login_form(f)
{
   if (f.txtEmailLogin.value.length<1)
    {
        alert("Invalid email detected.");
        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("Invalid email detected.");
            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("Please enter a password with more than 3 characters");
        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("Invalid email detected.");
        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("Invalid email detected.");
        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("Invalid email detected.");
            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("Email and Confirm Email don't match");
            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("Please enter a password with more than 3 characters.");
        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("Please enter a password with more than 3 characters.");
        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("Password and Confirm Password don't match");
        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("Invalid email detected.");
        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("Invalid email detected.");
            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 of File"></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%';
  }

  function DisplayConfirmMessage(msg, width, height)
	{
		// Set default dialogbox width if null
		if (width == null)
			divWidth = 180;
		else
			divWidth = width;

		// Set default dialogBox height if null
		if (height == null)
			divHeight = 90;
		else
			divHeight = height;


		// Ge the dialogbox object
		var divLayer = document.getElementById('divConfMessage');
		// Set dialogbox height and width
		SetHeightWidth(divLayer);
		// Set dialogbox top and left
		SetTopLeft(divLayer);

		// Show the div layer
		divLayer.style.display = 'block';
		// Change the location and reset the width and height if window is resized
		window.onresize = function()
			{
				if (divLayer.style.display == 'block')
				{
					//SetTopLeft(divLayer);
					//SetHeightWidth(divLayer);
				}
			}
		// Set the dialogbox display message
		document.getElementById('confirmText').innerText = msg;
	}

	function SetTopLeft(divLayer)
	{
	  // Get the dialogbox height
	  var divHeightPer = divLayer.style.height.split('px')[0];

	  // Set the top variable
	  var top = (parseInt(document.body.offsetHeight) / 2) - (divHeightPer / 2);
	  // Get the dialog box width
	  var divWidthPix = divLayer.style.width.split('px')[0];

	  // Get the left variable
	  var left = (parseInt(document.body.offsetWidth) / 2) - (parseInt(divWidthPix) / 2);
	  // set the dialogbox position to abosulute
	  divLayer.style.position = 'absolute';

	  // Set the div top to the height
	  divLayer.style.top = top;

	  // Set the div Left to the height
	  divLayer.style.left = left;
	}

	function SetHeightWidth(divLayer)
	{
	  // Set the dialogbox width
	  divLayer.style.width = divWidth + 'px';
	  // Set the dialogbox Height
	  divLayer.style.height = divHeight + 'px';
	}

	function SetText(txtButton1, txtButton2)
	{
	  // Set display text for the two buttons
	  if (txtButton1 == null)
	    document.getElementById('btnConfYes').innerText = txtFirstButton;
	  else
	    document.getElementById('btnConfYes').innerText = txtButton1;

	  // Set display text for the two buttons
	  if (txtButton2 == null)
	    document.getElementById('btnConfNo').innerText = txtSecondButton;
	  else
	    document.getElementById('btnConfNo').innerText = txtButton2;
	}

	function SetDefaultButton(defaultButton)
	{
	  // Set the focus on the Cancel button
	  document.getElementById(defaultButton).focus();
	}

	function ShowMessage(msgText, width, height)
	{
	  SetText('Yes', 'No');
	  DisplayConfirmMessage(msgText, width, height);

	  SetDefaultButton('btnConfNo');

	  return false;
	}

	/**
	 *
	 * @access public
	 * @return void
	 **/
	function HideConfirmationMessage(){
		var divLayer = document.getElementById('divConfMessage');

		// Show the div layer
		divLayer.style.display = 'none';
	}

	function Donothing()
	{
	}

	/**
	 *
	 * @access public
	 * @return void
	 **/
	function AskForConfirmation(firstName, lastName, Id, role, email){
		var msg = "Are you sure you want to delete " + role + " named " + firstName + " " + lastName + "?";
		var answer = confirm(msg);

		if(answer)
		{
			window.location.href = "delete_redirection.php?Id=" + Id + "&role=" + role + "&email=" + email;
		}
	}