﻿
// jquery validation code

$(document).ready(function() {

    // now visible the alert dev after complete loading of document
    $('#alert').css('visibility', 'visible');

    //to remove right border from last div
    $('.lastitem').css('border-right-width', '0px');

    // to show dua and hadeeth boxes on home, visible after complete loading of page
    $(".dua-text").css("visibility", "visible");


    //     $(".btnLinBton").click(function(){
    //     alert('in');
    //            $('#gallery').css('visibility','visible');
    //     });

/*
    $('.video_domains a').click(function() {
        //e.preventDefault();
        animateSlider('.videoDomains');
    });

    function animateSlider(tab) {
        if (!$('.video_domains a.open').length) {
            openPopup(tab);
        } else {
            openAndClose(tab)
        }
    }
    function openPopup(tab) {
        $(tab).addClass('open');
    }
    function openAndClose(tab) {

        $('.video_domains a.open').removeClass();
        $(tab).addClass('open');
    }
*/

    // to manage programme and video tabs on home page,---------------------------------- programme and video tabs 
    // this event hides video section, and shows programme tab 
    $("#programmes_active").click(function() {
        $(".program_scrol_area").css("display", "block").css("visibility", "visible");
        $(".video_scrol_area").css("display", "none").css("visibility", "hidden");

        $("#programmes_active").css('background-image', 'url(images/tab-green-prg.jpg)');
        $("#videos").css('background-image', 'url(images/tab-white-video.jpg)');
    });

    // this event hides programme section, and shows video tab
    $("#videos").click(function() {
        $(".program_scrol_area").css("display", "none").css("visibility", "hidden");
        $(".video_scrol_area").css("display", "block").css("visibility", "visible");

        $("#videos").css('background-image', 'url(images/tab-green-video.jpg)');
        $("#programmes_active").css('background-image', 'url(images/tab-white-prg.jpg)');
    });


    //// this section is for alert--------------------------------------------------------------------------- alert
    $('#alert').innerfade({
        animationtype: 'slide',
        speed: 2050,
        timeout: 5000,
        type: 'sequence',
        containerheight: '1em'
    });

    $('#portfolio').innerfade({
        speed: 1000,
        timeout: 5000,
        type: 'sequence',
        containerheight: '220px'
    });

    $('.fade').innerfade({
        speed: 1000,
        timeout: 6000,
        type: 'random_start',
        containerheight: '1.5em'
    });

    $('.adi').innerfade({
        speed: 'slow',
        timeout: 5000,
        type: 'random',
        containerheight: '150px'
    });



    // hanlder for the top seach box when have and lost focus-------------------------------------------- search iqra home
    $('.home-search-textbox').focus(function() {
        if ($('.home-search-textbox').attr('value') == 'search all of Iqra...') {
            $('.home-search-textbox').attr('value', '');
            $('.home-search-textbox').css('color', '#878787');
        }
    });

    $('.home-search-textbox').blur(function() {
        if ($('.home-search-textbox').attr('value').length < 1) {
            $('.home-search-textbox').attr('value', 'search all of Iqra...');
            $('.home-search-textbox').css('color', '#505b5d');
        }
    });

    $('.home-search-button').click(function() {  // on search button click check validation
        if ($('.home-search-textbox').attr('value') == 'search all of Iqra...') {
            $('.home-search-textbox').focus();
            return false;
        }
    });



    $('.program_scrol_area').click(function() {
        $('.program_scrol_area').css('display', 'block');
        $('.video_scrol_area').css('display', 'none');
    });

    $('.video_scrol_area').click(function() {

        $('.program_scrol_area').css('display', 'none');
        $('.video_scrol_area').css('display', 'block');
    });


    //$('.query').blur(function(){
    $('#par').blur(function() {

        if ($('.dd-div').css('visibility') != 'visible') {
            $('#content').css('z-index', '-2');
            $('#main').css('z-index', '-1');
        }
        else {

            $('#content').css('z-index', '0');
            $('#main').css('z-index', '0');
        }
    });


    // prayer timing validation goes here------------------------------------------------------ prayer timings
    $('.btnPrayerTimings').click(function() {

        if ($('.cbocity').attr('value') == '') {
            $('#city_name').css('color', 'pink');
            return false;
        }

        if ($('.ddcountry').attr('selectedIndex') == 0) {
            $('#country_name').css('color', 'pink');
            return false;
        }

        if ($('.day').attr('value') == 'Day') {
            $('#date').css('color', 'pink');
            return false;
        }

        if ($('.month').attr('value') == 'Month') {
            $('#date').css('color', 'pink');
            return false;
        }

        if ($('.year').attr('value') == 'Year') {
            $('#date').css('color', 'pink');
            return false;
        }

        return GetValues();

        // to show the processing animation 
        $('.show_processing').css('visibility', 'visible');
    });


    function GetValues() {

        var date = $('.month').attr('value') + "/" + $('.day').attr('value') + "/" + $('.year').attr('value');
        var splitter = "/";

        return ValidateDate(date, splitter);
    }

    function ValidateDate(selecteddate, dateseparator) {
        Days = selecteddate.split(dateseparator)[1]
        Month = selecteddate.split(dateseparator)[0]
        Year = selecteddate.split(dateseparator)[2]
        var d, m;
        //alert(selecteddate);
        d = (Days);
        m = (Month);

        if ((Year % 4 == 0 && d > 29 && m == 02) || (Year % 4 != 0 && (d > 28) && (m == 02))) {
            alert("Please select a valid Date");
            return false;
        }
        if (((d > 30) && (m == 11)) || ((d > 30) && (m == 09)) || ((d > 30) && (m == 06)) || ((d > 30) && (m == 04))) {
            alert("Please select a valid Date");
            return false;
        }
        else {
            return true;
        }
    }

    // prayer timings validation ends here


    // add mosque validation goes here----------------------------------------------------------- mosque addition
    $('.save_mosque_data').click(function() {

        if ($('.ddcountry').attr('value') == 'Select Country') {
            $('#mosque_country').css('color', 'Pink');
            return false;
        }

        if ($('.ddcity').attr('value') == 'Select City' || $('.ddcity').attr('value') == 'Select Country First') {
            $('#mosque_city').css('color', 'Pink');
            return false;
        }
        else {
            $('#mosque_city').css('color', '#535355');
        }


        if ($('.mosque_name').attr('value').length < 1) {
            $('#mosque_name').css('color', 'Pink');
            return false;
        }
        else {
            $('#mosque_name').css('color', '#535355');
        }


        // send text box class name as parameter
        if (!validateEmail('.mosque_email'))
            return false;

        // to show the processing animation 
        $('.show_processing').css('visibility', 'visible');
    });




    // add event validation goes here----------------------------------------------------------- event submition
    $('.submit_event').click(function() {


        if ($('.eventname').attr('value').length < 1) {
            $('#event_name').css('color', 'Pink');
            return false;
        }
        else {
            $('#event_name').css('color', '#535355');
        }


        // send text box class name as parameter
        if (!validateEmail('.your_email'))
            return false;

        if ($('.event_start_date').attr('value').length < 1) {
            $('#event_start_date').css('color', 'Pink');
            return false;
        }
        else {
            $('#event_start_date').css('color', '#535355');
        }


        if ($('.event_vanue_name').attr('value').length < 1) {
            $('#event_vanue_name').css('color', 'Pink');
            return false;
        }
        else {
            $('#event_vanue_name').css('color', '#535355');
        }

        // to show the processing animation 
        $('.show_processing').css('visibility', 'visible');

    });


    // volunteer registration validation goes here------------------------------------------ volunteer registration
    $('.save_volunteer_data').click(function() {


        if ($('.volunteer_name').attr('value').length < 1) {
            $('#volunteer_name').css('color', 'Pink');
            $('.volunteer_name').focus();
            return false;
        }
        else {
            $('#volunteer_name').css('color', '#535355');
        }

        // send text box class name as parameter
        if (!validateEmail('.volunteer_email'))
            return false;

        if ($('.volunteer_address').attr('value').length < 1) {
            $('#volunteer_address').css('color', 'Pink');
            $('.volunteer_address').focus();
            return false;
        }
        else {
            $('#volunteer_address').css('color', '#535355');
        }

        // to show the processing animation 
        $('.show_processing').css('visibility', 'visible');

    });



    // ecard validation goes here---------------------------------------------------------------- e-card
    $('.ecard_preview').click(function() {

        if ($('.sender_name').attr('value').length < 1) {

            $('#sender_name').css('color', 'Pink');
            $('.sender_name').focus();
            return false;
        }
        else {
            $('#sender_name').css('color', '#535355');
        }

        // send text box class name as parameter
        if (!validateEmail('.your_email'))
            return false;

        if ($('.receiver_name').attr('value').length < 1) {
            $('#receiver_name').css('color', 'Pink');
            $('.receiver_name').focus();
            return false;
        }
        else {
            $('#receiver_name').css('color', '#535355');
        }

        // send text box class name as parameter
        if (!validateEmail('.receiver_email'))
            return false;

        // to show the processing animation 
        $('.show_processing').css('visibility', 'visible');

    });



    // forum registraion validation goes here---------------------------------------------------------------- forum registraion
    $('.btn_forum_registration').click(function() {


        if ($('.reg_name').attr('value').length < 1) {
            $('#reg_name').css('color', 'Pink');
            $('.reg_name').focus();
            return false;
        }
        else {
            $('#reg_name').css('color', '#535355');
        }


        if ($('.reg_login').attr('value').length < 1) {
            $('#reg_login').css('color', 'Pink');
            $('.reg_login').focus();
            return false;
        }
        else {
            $('#reg_login').css('color', '#535355');
        }


        var login = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

        var validAddress = $('.reg_login').attr('value');

        if (login.test(validAddress) == true) {
            $('#div_login').css('visibility', 'visible');
            $('#div_login').html('Email address not allowed');
            $('#div_login').slideDown('slow');
            $('.reg_login').focus();
            return false;
        }
        else {
            $('#div_login').html('');
            $('#div_login').css('visibility', 'hidden');
        }

        if ($('.reg_login').attr('value').length < 6) {
            $('#div_login').css('visibility', 'visible');
            $('#div_login').html('Login should be more than 5 chracters.');
            $('#div_login').slideDown('slow');
            $('.reg_login').focus();
            return false;
        }
        else {
            $('#div_login').html('');
            $('#div_login').css('visibility', 'hidden');
        }

        if (!checkTxtLogin())
            return false;


        if ($('.reg_password').attr('value').length < 6) {
            $('#div_password').css('visibility', 'visible');
            $('#div_password').html('Password should be more than 5 chracters.');
            $('#div_password').slideDown('slow');
            $('.reg_password').focus();
            return false;
        }
        else {
            $('#div_password').html('');
            $('#div_password').css('visibility', 'hidden');
        }

        if ($('.reg_password').attr('value') != $('.reg_confirmpass').attr('value')) {

            $('#div_confirmpass').css('visibility', 'visible');
            $('#div_confirmpass').html('Password and Confirm Password must be same.');
            $('#div_confirmpass').slideDown('slow');
            $('.reg_confirmpass').focus();

            return false;
        }
        else {
            $('#div_confirmpass').html('');
            $('#div_confirmpass').css('visibility', 'hidden');
        }


        // send text box class name as parameter
        if (!validateEmail('.reg_email'))
            return false;


        if ($('.reg_signature').attr('value').length > 500) {
            $('#div_signature').css('visibility', 'visible');
            $('#div_signature').html('Signature should be less than 500 chracters.');
            $('#div_signature').slideDown('slow');
            $('.reg_signature').focus();

            return false;
        }
        else {
            $('#div_signature').html('');
            $('#div_signature').css('visibility', 'hidden');
        }


        // to show the processing animation 
        $('.show_processing').css('visibility', 'visible');

    });

    function checkTxtLogin() {
        var _return = true;
        _return = stripCharsInBag(($('.reg_login').attr('value')));

        if (!_return) {
            $('#div_login').css('visibility', 'visible');
            $('#div_login').html("<br />Your login name contains invalid charactes. only [-_.A-Za-z0-9] characters are allowed.");
            $('.reg_login').focus();
            _return = false
        }
        return _return;
    }

    function stripCharsInBag(s) {
        var Delimiters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.";
        var i;

        var returnString = false;


        for (i = 0; i < s.length; i++) {
            var c = s.charAt(i);

            if (Delimiters.indexOf(c) > -1) {
                //alert('in if');	
                //alert(c);
                returnString = true;

            }
            else {
                //alert('dummy');
                returnString = false;
                break;
            }
        }

        return returnString;
    }



    // forum registraion validation goes here---------------------------------------------------------------- forum user profile edit
    $('.btn_forum_edituser').click(function() {

        if ($('.reg_password').attr('value').length < 6) {
            $('#div_password').css('visibility', 'visible');
            $('#div_password').html('Password should be more than 5 chracters.');
            $('#div_password').slideDown('slow');
            $('.reg_password').focus();
            return false;
        }
        else {
            $('#div_password').html('');
            $('#div_password').css('visibility', 'hidden');
        }

        if ($('.reg_password').attr('value') != $('.reg_confirmpass').attr('value')) {

            $('#div_confirmpass').css('visibility', 'visible');
            $('#div_confirmpass').html('Password and Confirm Password must be same.');
            $('#div_confirmpass').slideDown('slow');
            $('.reg_confirmpass').focus();

            return false;
        }
        else {
            $('#div_confirmpass').html('');
            $('#div_confirmpass').css('visibility', 'hidden');
        }

        if ($('.reg_signature').attr('value').length > 500) {
            $('#div_signature').css('visibility', 'visible');
            $('#div_signature').html('Signature should be less than 500 chracters.');
            $('#div_signature').slideDown('slow');
            $('.reg_signature').focus();

            return false;
        }
        else {
            $('#div_signature').html('');
            $('#div_signature').css('visibility', 'hidden');
        }


        // to show the processing animation 
        $('.show_processing').css('visibility', 'visible');

    });


    $('.new_thread').click(function() {


        if ($('.new_thread_title').attr('value').length < 1) {
            $('#new_thread_title').css("color", "Pink");
            return false;
        }
        else {
            $('#new_thread_title').css("color", "Gray");
        }


        // to show the processing animation 
        $('.show_processing').css('visibility', 'visible');


    });




    //email address validation code ---------------------------------------------------------------------- email validation
    function validateEmail(textboxCss) {

        $('.invalid_email').hide();
        $('.empty_field').hide();

        var hasError = false;
        var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

        var emailaddressVal = $(textboxCss).val();

        if (emailaddressVal == '') {
            $(textboxCss).after('<span class="empty_field">&nbsp;Please enter your email address.</span>');
            $(textboxCss).focus();
            hasError = true;
        }
        else if (!emailReg.test(emailaddressVal)) {
            $('.empty_field').hide();
            $(textboxCss).after('<span class="invalid_email">&nbsp;Enter a valid email address.</span>');
            $(textboxCss).focus();
            hasError = true;
        }
        else {
            $('.empty_field').hide();
            $('.invalid_email').hide();
        }

        if (hasError == true)
        { return false; }
        else { return true; }

    }

    // this method is used to call london prayer timings alert on home page		
    //startclock();



});

