﻿$(document).ready(function() {

    $(".toggle_container").hide();

    $("h2.trigger").toggle(function() {
        $(this).addClass("active");
    }, function() {
        $(this).removeClass("active");
    });

    $("h2.trigger").click(function() {
        $(this).next(".toggle_container").slideToggle("slow,");
    });

});

function ValidateUser(name, sirname, emailid, pass, cpass, address, city, country, pin, mobile) {
    if (document.getElementById(name).value == '') {
        alert("Name can not be blank ");
        document.getElementById(name).focus();
        return false;
    }
    if (document.getElementById(sirname).value == '') {
        alert("Sir name can not be blank ");
        document.getElementById(sirname).focus();
        return false;
    }
    if (document.getElementById(emailid).value == '') {
        alert("Email id can not be blank ");
        document.getElementById(emailid).focus();
        return false;
    }
    if (!emailCheck(document.getElementById(emailid).value)) {
        document.getElementById(emailid).value = '';
        document.getElementById(emailid).focus();
        return false;
    }
    if (document.getElementById(pass).value == '') {
        alert("Password can not be blank ");
        document.getElementById(pass).focus();
        return false;
    }
    if (document.getElementById(cpass).value == '') {
        alert("ConfirmPassword can not be blank ");
        document.getElementById(cpass).focus();
        return false;
    }
    if (document.getElementById(pass).value != document.getElementById(cpass).value) {
        alert("ConfirmPassword  and  Password must be same ");
        document.getElementById(cpass).value = '';
        document.getElementById(cpass).focus();
        return false;
    }
    if (document.getElementById(address).value == '') {
        alert("Address can not be blank ");
        document.getElementById(address).focus();
        return false;
    }
    if (document.getElementById(city).value == '') {
        alert("City can not be blank ");
        document.getElementById(city).focus();
        return false;
    }
    if (document.getElementById(country).value == '') {
        alert("Country can not be blank ");
        document.getElementById(country).focus();
        return false;
    }
    if (document.getElementById(pin).value == '') {
        alert("Pin can not be blank ");
        document.getElementById(pin).focus();
        return false;
    }
    if (document.getElementById(pin).value != '') {
        if (isNaN(document.getElementById(pin).value)) {
            alert("Pin must be digit");
            document.getElementById(pin).value = '';
            document.getElementById(pin).focus();
            return false;
        }
    }
    if (document.getElementById(mobile).value == '') {
        alert("Mobile can not be blank ");
        document.getElementById(mobile).focus();
        return false;
    }
    if (document.getElementById(mobile).value != '') {
        if (isNaN(document.getElementById(mobile).value)) {
            alert("MobileNumber must be digit");
            document.getElementById(mobile).value = '';
            document.getElementById(mobile).focus();
            return false;
        }
    }
}  

function ValidateLogin(username, pass) {
    if (document.getElementById(username).value == '') {
        alert("User name can not be blank");
        document.getElementById(username).focus();
        return false;
    }
    if (document.getElementById(pass).value == '') {
        alert("Password can not be blank");
        document.getElementById(pass).focus();
        return false;
    }
}

function ValidateLogin1(username, pass) {
    if (document.getElementById(username).value == '') {
        alert("User id can not be blank");
        document.getElementById(username).focus();
        return false;
    }
    if (document.getElementById(username).value != '') {
        if (isNaN(document.getElementById(username).value)) {
            alert("User id must be Digit ");
            document.getElementById(username).value = '';
            document.getElementById(username).focus();
            return false;
        }
    }
    if (document.getElementById(pass).value == '') {
        alert("Password can not be blank");
        document.getElementById(pass).focus();
        return false;
    }
}

function CheckValidEmailId(emailid)
{ if (document.getElementById(emailid).value == '') {
        alert("Email id can not be blank ");
        document.getElementById(emailid).focus();
        return false;
    }
    if (!emailCheck(document.getElementById(emailid).value)) {
        document.getElementById(emailid).value = '';
        document.getElementById(emailid).focus();
        return false;
    }
}

function ValidationForProject(projectname, description) {
    if (document.getElementById(projectname).value == '') {
        alert("Project name can not be Blank");
        document.getElementById(projectname).focus();
        return false;
    }
    if (document.getElementById(description).value == '') {
        alert("Discription can not be Blank");
        document.getElementById(description).focus();
        return false;
    }
}
function CheckValidEmail(emailid,resume) {
    if (document.getElementById(emailid).value == '') {
        alert("Email id can not be blank ");
        document.getElementById(emailid).focus();
        return false;
    }
    if (!emailCheck(document.getElementById(emailid).value)) {
        document.getElementById(emailid).value = '';
        document.getElementById(emailid).focus();
        return false;
    }
    if (document.getElementById(resume).value == '') {
        alert("Please upload your Resume ");
        document.getElementById(resume).focus();
        return false;
    }
}

function CheckValidTestimonial(name,emailid, contactno,testimonial) {
    if (document.getElementById(name).value == '') {
        alert("Name can not be Blank ");
        document.getElementById(name).focus();
        return false;
    }
    
    if (document.getElementById(emailid).value == '') {
        alert("Email id can not be blank ");
        document.getElementById(emailid).focus();
        return false;
    }
    if (!emailCheck(document.getElementById(emailid).value)) {
        document.getElementById(emailid).value = '';
        document.getElementById(emailid).focus();
        return false;
    }
    if (document.getElementById(contactno).value == '') {
        alert("Contact no can not be Blank ");
        document.getElementById(contactno).focus();
        return false;
    }
    if (document.getElementById(contactno).value != '') {
        if (isNaN(document.getElementById(contactno).value)) {
            alert("Contact no must be Digit ");
            document.getElementById(contactno).value = '';
            document.getElementById(contactno).focus();
            return false;
        }
    }
    if (document.getElementById(testimonial).value == '') {
        alert("Testimonial can not be Blank ");
        document.getElementById(testimonial).focus();
        return false;
    }
}

function CheckValidAppointmentForm(fname,lname,age,emailid,doa,contactno,time,address) {
    if (document.getElementById(fname).value == '') {
        alert("First Name can not be Blank ");
        document.getElementById(fname).focus();
        return false;
    }
    if (document.getElementById(lname).value == '') {
        alert("Last Name can not be Blank ");
        document.getElementById(lname).focus();
        return false;
    }
    if (document.getElementById(age).value == '') {
        alert("Age can not be Blank ");
        document.getElementById(age).focus();
        return false;
    }
    if (document.getElementById(age).value != '') {
        if (isNaN(document.getElementById(age).value)) {
            alert("Age must be Digit ");
            document.getElementById(age).value = '';
            document.getElementById(age).focus();
            return false;
        }
    }
    if (document.getElementById(emailid).value == '') {
        alert("Email id can not be blank ");
        document.getElementById(emailid).focus();
        return false;
    }
    if (!emailCheck(document.getElementById(emailid).value)) {
        document.getElementById(emailid).value = '';
        document.getElementById(emailid).focus();
        return false;
    }
    if (document.getElementById(doa).value == '') {
        alert("Provisional Date of Appointment can not be Blank ");
        document.getElementById(doa).focus();
        return false;
    }
    if (document.getElementById(contactno).value == '') {
        alert("Phone can not be Blank ");
        document.getElementById(contactno).focus();
        return false;
    }

    if (document.getElementById(time).value == '') {
        alert("Provisional Time of Appointment can not be Blank ");
        document.getElementById(time).focus();
        return false;
    }
    if (document.getElementById(address).value == '') {
        alert("Address can not be Blank ");
        document.getElementById(address).focus();
        return false;
    }
}

function emailCheck(str) {
    var at = "@"
    var dot = "."
    var lat = str.indexOf(at)
    var lstr = str.length
    var ldot = str.indexOf(dot)

    // check if '@' is at the first position or  at last position or absent in given email 
    if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
        alert("Invalid E-mail ID")
        return false
    }
    // check if '.' is at the first position or at last 
    //   position or absent in given email
    if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
        alert("Invalid E-mail ID")
        return false
    }
    // check if '@' is used more than one times in given email
    if (str.indexOf(at, (lat + 1)) != -1) {
        alert("Invalid E-mail ID")
        return false
    }

    // check for the position of '.'
    if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
        alert("Invalid E-mail ID")
        return false
    }
    // check if '.' is present after two characters 
    //  from location of '@'
    if (str.indexOf(dot, (lat + 2)) == -1) {
        alert("Invalid E-mail ID")
        return false
    }

    // check for blank spaces in given email
    if (str.indexOf(" ") != -1) {
        alert("Invalid E-mail ID")
        return false
    }
    return true
}


