function echeck(str) {

    var at = "@"
    var dot = "."
    var lat = str.indexOf(at)
    var lstr = str.length
    var ldot = str.indexOf(dot)
    if (str.indexOf(at) == -1) {
        alert("Invalid E-mail ID")
        return false
    }

    if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
        alert("Invalid E-mail ID")
        return false
    }

    if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
        alert("Invalid E-mail ID")
        return false
    }

    if (str.indexOf(at, (lat + 1)) != -1) {
        alert("Invalid E-mail ID")
        return false
    }

    if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
        alert("Invalid E-mail ID")
        return false
    }

    if (str.indexOf(dot, (lat + 2)) == -1) {
        alert("Invalid E-mail ID")
        return false
    }

    if (str.indexOf(" ") != -1) {
        alert("Invalid E-mail ID")
        return false
    }

    return true
}

function ValidateForm() {
    var emailID = document.contact.email
    var firstName = document.contact.firstname
    var lastName = document.contact.lastname
    var companyName = document.contact.company
    var titleField = document.contact.title
    var phoneNumber = document.contact.phone
    var stateField = document.contact.state

    var w = document.contact.state.selectedIndex;
    var selected_text = document.contact.state.options[w].text;

    if ((firstName.value == null) || (firstName.value == "")) {
        alert("Please Enter First Name")
        firstName.focus()
        return false
    }

    if ((lastName.value == null) || (lastName.value == "")) {
        alert("Please Enter Last Name")
        lastName.focus()
        return false
    }

    if ((companyName.value == null) || (companyName.value == "")) {
        alert("Please Enter Company")
        companyName.focus()
        return false
    }

    if ((titleField.value == null) || (titleField.value == "")) {
        alert("Please Enter Title")
        titleField.focus()
        return false
    }

    if ((phoneNumber.value == null) || (phoneNumber.value == "")) {
        alert("Please Enter Phone")
        phoneNumber.focus()
        return false
    }
    
    if ((selected_text == null) || (selected_text == "Select One"))
    {
        alert("Please select State")
        stateField.focus()
        return false
    }
    
    if ((emailID.value == null) || (emailID.value == "")) {
        alert("Please Enter your Email ID")
        emailID.focus()
        return false
    }

    if (echeck(emailID.value) == false) {
        emailID.value = ""
        emailID.focus()
        return false
    }

    contact.submit();
    return true
}


/* 
For Testimonials Pages
*/
function ValidateTestimonialsForm() {
    var emailID = document.testimonials.email

    if ((emailID.value == null) || (emailID.value == "")) {
        alert("Please Enter your Email ID")
        emailID.focus()
        return false
    }

    if (echeck(emailID.value) == false) {
        emailID.value = ""
        emailID.focus()
        return false
    }

    testimonials.submit();
    return true
}

function ValidateAccessCodeForTestimonials() {
    var accessCode = document.testimonials.password

    if (accessCode.value == null || accessCode.value == "") {
        alert("Please enter Access Code")
        accessCode.focus()
        return false
    }

    if (accessCode.value == "GlobalLitigation") {
        window.open('Testionomial.pdf')
    }
    else {
        alert("Access Code you have entered is not valid.\nPlese check it and try again.")
        return false
    }
}

/* 
For Case Study Pages
*/

function ValidateCaseStudiesForm() {
    var emailID = document.casestudies.email

    if ((emailID.value == null) || (emailID.value == "")) {
        alert("Please Enter your Email ID")
        emailID.focus()
        return false
    }

    if (echeck(emailID.value) == false) {
        emailID.value = ""
        emailID.focus()
        return false
    }

    casestudies.submit();
    return true

}

function ValidateAccessCodeForCaseStudies() {
    var accessCode = document.casestudies.password

    if (accessCode.value == null || accessCode.value == "") {
        alert("Please enter Access Code")
        accessCode.focus()
        return false
    }

    if (accessCode.value == "GlobalLitigation") {
        window.open('CaseStudies.pdf')
    }
    else {
        alert("Access Code you have entered is not valid.\nPlese check it and try again.")
        return false
    }
}

/* 
For Global-Box Video Pages
*/

function ValidateGlobalBoxVideoForm() {
    var emailID = document.globalboxvideo.email

    if ((emailID.value == null) || (emailID.value == "")) {
        alert("Please Enter your Email ID")
        emailID.focus()
        return false
    }

    if (echeck(emailID.value) == false) {
        emailID.value = ""
        emailID.focus()
        return false
    }

    casestudies.submit();
    return true

}

function ValidateAccessCodeForGlobalBoxVideo() {
    var accessCode = document.globalboxvideo.password

    if (accessCode.value == null || accessCode.value == "") {
        alert("Please enter Access Code")
        accessCode.focus()
        return false
    }

    if (accessCode.value == "GlobalLitigation") {
        window.open('GlobalBoxVideo.html')
    }
    else {
        alert("Access Code you have entered is not valid.\nPlese check it and try again.")
        return false
    }
}