﻿function checkLoginForm()
{
    if (document.LogInForm.txtUsername.value == "")
    {
        alert("Please, enter your username.");
        document.LogInForm.txtUsername.focus();
        return false;
    }
    
    if (document.LogInForm.txtPassword.value == "")
    {
        alert("Please, enter your password.");
        document.LogInForm.txtPassword.value.focus();
        return false;
    }
    
    return true;
}

function checkRegFormStep1()
{
    var emailValidator = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
    
    if (document.SignUpForm.txtUserName.value == "")
    {
        alert("Please, enter username.");
        document.SignUpForm.txtUserName.focus();
        return false;
    }
    
    if (document.SignUpForm.txtUserName.value.length < 3)
    {
        alert("Your username is too short. Your username should be more than 3 characters.");
        document.SignUpForm.txtUserName.focus();
        return false;
    }    
    
    if (document.SignUpForm.txtUserName.value.length > 20)
    {
        alert("Your username is too long. Your username should be less than 20 characters.");
        document.SignUpForm.txtUserName.focus();
        return false;
    }      
    
    if (document.SignUpForm.txtPassword.value == "")
    {
        alert("Please, enter password.");
        document.SignUpForm.txtPassword.focus();
        return false;
    }
    
    if (document.SignUpForm.txtPassword.value.length < 8)
    {
        alert("Your password is too short. Your password should be more than 8 characters.");
        document.SignUpForm.txtPassword.focus();
        return false;
    }    
    
    if (document.SignUpForm.txtConfirmPassword.value == "")
    {
        alert("Please, enter confirm password.");
        document.SignUpForm.txtConfirmPassword.focus();
        return false;
    }
    
    if (document.SignUpForm.txtPassword.value != document.SignUpForm.txtConfirmPassword.value)
    {
        alert("Your password and confirm password must be the same.");
        document.SignUpForm.txtConfirmPassword.value = "";
        document.SignUpForm.txtConfirmPassword.focus();
        return false;
    }

    if (document.SignUpForm.txtEmail.value == "")
    {
        alert("Please, enter your contact e-mail address.");
        document.SignUpForm.txtEmail.focus();
        return false;
    }
    
    if (document.SignUpForm.txtEmail.value.length > 50)
    {
        alert("Your e-mail address is too long. Your e-mail address should be less than 50 characters.");
        document.SignUpForm.txtEmail.focus();
        return false;
    }    
    
    if (emailValidator.test(document.SignUpForm.txtEmail.value) == false) 
    {
	    alert("Please, enter valid e-mail address.");
	    document.SignUpForm.txtEmail.focus();
	    return false;
    }

    return true;
}

function checkRegFormStep2()
{
     var zipCodeValidator = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
     var phoneValidator = /((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}/;
     
    if (document.SignUpForm.txtCompName.value == "")
    {
        alert("Please, enter company name.");
        document.SignUpForm.txtCompName.focus();
        return false;
    }
    
    if (document.SignUpForm.txtCompName.value.length > 50)
    {
        alert("Your company name is too long. Your company name should be less than 50 characters.");
        document.SignUpForm.txtCompName.focus();
        return false;
    }    
    
    if (document.SignUpForm.lstCategory.value == "0")
    {
        alert("Please, select a category.");
        document.SignUpForm.lstCategory.focus();
        return false;
    }
    
    if (document.SignUpForm.txtAddr.value == "")
    {
        alert("Please, enter street address.");
        document.SignUpForm.txtAddr.focus();
        return false;
    }
    
    if (document.SignUpForm.txtAddr.value.length > 100)
    {
        alert("Your street address is too long. Your street address should be less than 100 characters.");
        document.SignUpForm.txtAddr.focus();
        return false;
    }      
    
    if (document.SignUpForm.txtCity.value == "")
    {
        alert("Please, enter city name.");
        document.SignUpForm.txtCity.focus();
        return false;
    }
    
    if (document.SignUpForm.txtCity.value.length > 50)
    {
        alert("Your city name is too long. Your city name should be less than 50 characters.");
        document.SignUpForm.txtCity.focus();
        return false;
    }       
    
    if (document.SignUpForm.txtZip.value == "")
    {
        alert("Please, enter zip code.");
        document.SignUpForm.txtZip.focus();
        return false;
    }        
    
    if (zipCodeValidator.test(document.SignUpForm.txtZip.value) == false) 
    {
	    alert("Please, enter valid zip code.");
	    document.SignUpForm.txtZip.focus();
	    return false;
    }        
    
    if (document.SignUpForm.txtPhoneNum.value == "")
    {
        alert("Please, enter phone number.");
        document.SignUpForm.txtPhoneNum.focus();
        return false;
    }
    
    if (phoneValidator.test(document.SignUpForm.txtPhoneNum.value) == false) 
    {
	    alert("Please, enter valid phone number.\n\ne.g) 323-456-7890 or (323)456-7890");
	    document.SignUpForm.txtPhoneNum.focus();
	    return false;
    }    
    
    if (document.SignUpForm.txtDescription.value == "")
    {
        alert("Please, enter brief description.");
        document.SignUpForm.txtDescription.focus();
        return false;
    }
    
    if (document.SignUpForm.txtDescription.value.length > 500)
    {
        alert("Your description is too long. Your description should be less than 500 characters.");
        document.SignUpForm.txtDescription.focus();
        return false;
    }
    
    return true;
}

function createWindow(cUrl,cName,cFeatures)	{
	var xWin = window.open(cUrl,cName,cFeatures)
}