function showW2L()
{
    // Formatting
    document.getElementById("headerFooter0").disabled = !document.forms["formConv"].isText.checked;
    document.getElementById("headerFooter1").disabled = !document.forms["formConv"].isText.checked;
    document.getElementById("headerFooter2").disabled = !document.forms["formConv"].isText.checked;
    document.forms["formConv"].isSection.disabled = !document.forms["formConv"].isText.checked;
    document.forms["formConv"].isHeading.disabled = !document.forms["formConv"].isText.checked;
    document.forms["formConv"].isParFormat.disabled = !document.forms["formConv"].isText.checked;
    document.forms["formConv"].isSymbolFormat.disabled = !document.forms["formConv"].isText.checked;
    
    // Equations
    document.getElementById("isEqTexStyle0").disabled = !document.forms["formConv"].isEq.checked;
    document.getElementById("isEqTexStyle1").disabled = !document.forms["formConv"].isEq.checked;
    document.forms["formConv"].isContourInt.disabled = !document.forms["formConv"].isEq.checked;
    document.forms["formConv"].isResetNudging.disabled = !document.forms["formConv"].isEq.checked;
    document.forms["formConv"].isEqBadPict.disabled = !document.forms["formConv"].isEq.checked;
    
    // References
    document.getElementById("labelRef0").disabled = !document.forms["formConv"].isLabelRef.checked;
    document.getElementById("labelRef1").disabled = !document.forms["formConv"].isLabelRef.checked;
    document.getElementById("labelRef2").disabled = !document.forms["formConv"].isLabelRef.checked;
    
    // Tables
    document.getElementById("tableRatio0").disabled = !document.forms["formConv"].isTable.checked;
    document.getElementById("tableRatio1").disabled = !document.forms["formConv"].isTable.checked;
    document.getElementById("tableRatio2").disabled = !document.forms["formConv"].isTable.checked;
    document.forms["formConv"].isTableBorder.disabled = !document.forms["formConv"].isTable.checked;
    
    // Images
    document.forms["formConv"].pictNumber.disabled = !document.forms["formConv"].isPict.checked;
    document.getElementById("isPictPs0").disabled = !document.forms["formConv"].isPict.checked;
    document.getElementById("isPictPs1").disabled = !document.forms["formConv"].isPict.checked;
}

function showN()
{
    document.forms["formConv"].scale.disabled = !document.forms["formConv"].isScale.checked;
}

function showMCoperator()
{
    document.forms["formConv"].newPrice.disabled = !document.forms["formConv"].isNewPrice.checked;
}

function add_more_upload() 
{
    var old_total = Math.round(document.formConv.TOTAL_FILE.value++);
    var new_total = old_total + 1;
    
    document.getElementById('attach_' + old_total).innerHTML = 
        "<input type='checkbox' CHECKED name='isFile[" + old_total + "]'> " + 
        "<input type='file' size='40' name='theFile[" + old_total + "]'><br>" + 
        "<span id='attach_" + new_total + "'></span>";
}

function clear_upload() 
{
    document.formConv.TOTAL_FILE.value = 1;
    document.getElementById('attach').innerHTML = 
        "<span id='attach_0'><input type='checkbox' CHECKED name='isFile[0]'> " + 
        "<input type='file' size='40' name='theFile[0]'><br>" + 
        "<span id='attach_1'></span></span>";
}


// form submiting

function formCreateAccountSubmit()
{
    if (document.formCreateAccount.FName.value == "")
    {
        alert("Please specify First Name.");
        document.formCreateAccount.FName.focus();
        return false;
    }
    
    if (document.formCreateAccount.LName.value == "")
    {
        alert("Please specify Last Name.");
        document.formCreateAccount.LName.focus();
        return false;
    }
    
    if (document.formCreateAccount.Email.value == "")
    {
        alert("Please specify e-mail address.");
        document.formCreateAccount.Email.focus();
        return false;
    }
    
    if (!ValidateEmail(document.formCreateAccount.Email.value))
    {
        alert("The e-mail address you have entered does not seem to be valid.");
        document.formCreateAccount.Email.focus();
        return false;
    }
    
    if (document.formCreateAccount.Username.value == "")
    {
        alert("Please specify a Username.");
        document.formCreateAccount.Username.focus();
        return false;
    }
    
    if (document.formCreateAccount.Password.value == "")
    {
        alert("Please specify a Password.");
        document.formCreateAccount.Password.focus();
        return false;
    }
    
    if (document.formCreateAccount.Password.value != document.formCreateAccount.ConfPassword.value)
    {
        alert("Password mismatch.");
        document.formCreateAccount.Password.focus();
        return false;
    }
    
    if (!document.formCreateAccount.License.checked)
    {
        alert("You must agree to the terms and conditions of the GrindEQ License Agreement.");
        document.formCreateAccount.License.focus();
        return false;
    }
    
    document.formCreateAccount.submit();
    
    return true;
}

function formAccountSettingsSubmit()
{
    //if (!ValidateNewUserForm()) return false;
    document.formAccountSettings.submit();
    return true;
}

function formChangePasswordSubmit()
{
    var oldPass = document.getElementById('OldPassword');
    
    if(oldPass.value == "")
    {
        alert("Password could not be empty.");
        return false;
    }
    
    //if(!ValidatePassword())
    //    return false;
    
    return true;
}

function formConv_OnSubmit() 
{    
    if (!ValidateEmail(document.formConv.customMail)) 
    {        
        return false;
    }    

    formConvSubmit();
    
    return true;
}

function formConvSubmit()
{
    document.formConv.submit();
}


// mnemonic analizer of email address
//   return: true - email correct, false - incorrect

function ValidateEmail(email) 
{
    var str = email;
    
    // cleaning spaces
    while (str.length && str.charAt(0) == " ") str = str.substring(1);
    while (str.length && str.charAt(str.length - 1) == " ") str = str.substring(0, str.length - 1);
    
    var len = str.length;
    var at = str.indexOf("@");
    var dot = str.indexOf(".");
    
    if (len == 0) return false;  // empty address
    
    if (str.indexOf(" ") != -1) return false;  // incorrect spaces
    
    if (at == -1 || at == 0 || str.lastIndexOf("@") == len - 1) return false;  // incorrect '@'
    
    if (str.indexOf("@", at + 1) != -1) return false;  // double '@'
    
    if (dot == -1 || dot == 0 ||  str.lastIndexOf(".") == len - 1) return false;  // incorrect '.'
    
    if (str.charAt(at - 1) == "." || str.charAt(at + 1) == ".") return false;  // ".@" or "@."
    
    if (str.indexOf(".", at) == -1) return false;  //  '.' must be after '@'
    
    return true; 
}
