/// <reference path="jquery-1.4.4-vsdoc.js" />
var index = 0;
var disable = 0;
var child = 2;
var test = false;
var padding;
var width;
var currentslideshow = "latestnewscontent";
var testlogin = "";

$(document).ready(function () {
    showslide("latestnewscontent", $($('.rightside > .header > .item')[3]));
    $(document).keyup(function (event) {
        if (event.which == 27) {
            closeContact();
        }
    });
    //    $(document).bind('mousedown.bgpopupContact', function (e) {
    //        var clicked = $(e.target); // get the element clicked                 
    //        if (!clicked.is('#bgpopupContact')) { // outside click
    //            closeContact();
    //        }
    //    });

    if ($('#divImportantPoints').length != 0) {
        $('#divImportantPoints > .scrollheader').click(function () {
            $(this).toggleClass('shows');
            $(this).next().slideToggle();
        });
    }
    updateButtons();
    if ($('.slideshow').length != 0) {
        padding = $('.slideshow').position().left;
        padding = 31;
    }
})

function IsValidEmail(email) {
    var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
    return filter.test(email);
}

function changeLang() {
    var langId_dropy = document.getElementById("langId_dropy").value;
 //   alert(langId_dropy)
    var routeURL = document.getElementById("routeURL").value;
    var language = document.getElementById("language").value;
    var currentUrl = document.getElementById("currentUrl").value;
    var array = currentUrl.split("/");
    if (array[2] == "shift") {
        var part_number = 5;
    } else {
        var part_number = 4;
    }
    var myUrl = "";
    while (part_number < array.length) {
        myUrl = myUrl + "/" + array[part_number];
        part_number += 1;
    }
    //alert(myUrl);
    var poststr = "langId_dropy=" + encodeURI(langId_dropy);
    window.location = routeURL + langId_dropy + myUrl;
  

    
}

function resetVariables() {
    index = 0;
    disable = 0;
    padding = 31;
    width = 0;
    $('.leftnaviguation').show();
    $('.rightnaviguation').show();
    updateButtons();
}

function ScrollToElement() {
    window.scrollTo(0,$("#LoginAddJob").offset().top);  
}


function scrollWindow() {
    window.scrollTo(100, 20000);
}

function showpopup() {
    window.scroll(0, 3500);
    $('.footermenu>div').addClass('selected');
    $('.bgpopupContact').fadeIn();
}

jQuery.fn.center = function () {
    this.css("position", "absolute");
    this.css("top", ($(window).height() - this.height()) / 2 + $(window).scrollTop() + "px");
    this.css("left", ($(window).width() - this.width()) / 2 + $(window).scrollLeft() + "px");
    return this;
}

jQuery.fn.center2 = function () {
    this.css("position", "absolute");
    this.css("top", ($(window).height()) / 4 + $(window).scrollTop() + "px");
    this.css("left", ($(window).width()) / 4 + $(window).scrollLeft() + "px");
    return this;
}

function showpopupContact(elt) {
    
    $(elt).addClass('selected');
    $('.bgpopupContact').fadeIn('normal', function () {
        $('body').click(function (event) { popupHide(event) });
    });
}

function popupHide(event) {
    if ($('#bgpopupContact').length != 0 && !$(event.target).closest('#bgpopupContact').length) {
        $('#bgpopupContact').fadeOut();
        $('body').unbind('click');
        $('.footermenu > div').removeClass('selected');
    }
}

function closeContact() {
    $('.bgpopupContact').fadeOut();
    $('#footer > .footermenu > .item').removeClass('selected');
}

function showslide(id, elt) {
    $('.rightside > .content').hide();
    $("#" + id).show();
    $('.rightside > .header > .item').removeClass('selected');
    $(elt).addClass('selected');
    currentslideshow = id;
    $('.slideshow').css("left", "0px");
    resetVariables();
}
function showInfo(obj) {
    $(obj).toggleClass('shows');
    $(obj).next().slideToggle();
}

function showInfo2(obj) {
    var scrollheader = "#scrollheader" + obj;
    var scrollcontent = "#scrollcontent" + obj;
    $(scrollheader).toggleClass('shows');
    $(scrollcontent).slideToggle();
}

function openPopup(albumID) {

    var URL = document.getElementById('popupactionurl').value;
    //Ajax call
   // alert(URL)
    $.ajax({
        type: 'POST',
        data: 'relatedPictures=' + albumID,
        success: function (response) {
            if (response) {
                $("#htmlPart").empty();
                $("#htmlPart").append(response); //the response is the render partial with the ViewData

                document.getElementById('siteOverlay').style.height = $(".wrapper").attr('offsetHeight') + "px";
                //$('htmlPart').center();
                //$('.popupbg').center2();
                //$('.popupbg').show();
                $('.popupbg').center2();
                $('.popupbg').show();
                $('#siteOverlay').show();

            }
        },
        error: function (error) { },
        url: URL // controller/action
    });





}

function playVid(url, video, id) {
  //  window.scroll(0, 250);
  //  $('#sepdiv').css('z-index', '14');
    //  $('#vidloader').show();
    
    showVideo();
    $('#video_poup_ajax').load(url, function () {
        $('#vidloader').hide();
        JWloadMovie(video, 'JWPlayerContainer', 'true');
    });
}
function hideNews() {
    $('.popupbg').hide();
    $('#siteOverlay').hide();
}
function showVideo() {
    document.getElementById('siteOverlay').style.height = $(".wrapper").attr('offsetHeight') + "px";
    $('.popupbg').center();
    $('.popupbg').show();
    $('#siteOverlay').show();
}
function zoomOut() {
    var currentFontSize = $('.zoom').css('font-size');
    var currentFontSizeNum = parseInt(currentFontSize, 10);
    var newFontSize = currentFontSizeNum + 1;
    if (newFontSize < 18) {
        $('.zoom').css('font-size', newFontSize);
    }
}
function zoomIn() {
    var currentFontSize = $('.zoom').css('font-size');
    var currentFontSizeNum = parseInt(currentFontSize, 10);
    var newFontSize = currentFontSizeNum - 1;
    if (newFontSize > 9) {
        $('.zoom').css('font-size', newFontSize);
    }

}
function checkWindowSize() {
    if ($(window).width() <= 1200) {
        $('.grappes').hide();
    }
    else
        $('.grappes').show();
}

function see() {
    var name = 'Father\'s name';
    if (document.getElementById('fathername1').value == name) {
        document.getElementById('fathername1').value = '';

    }
}
function see1(fname) {
    //alert(fname);
    var name = fname;
    if (document.getElementById('fathername2').value == name) {
        document.getElementById('fathername2').value = '';

    }
}

function showNextSlide() {
    slideSwitch();
}

function showPreviousSlide() {
    slideBack();
}

function add() {
    index = index + 1;
    disable = 0;
    end_next();
    reset_previous();
}

function sub_index() {
    index = index - 1;
    disable = 0;
    reset_next();
    end_previous();
}
function end_next() {
    if (index == x.length - 1) {
        $('.rightnaviguation').hide();
    }
}
function reset_next() {
    if (index != x.length - 1)
        $('.rightnaviguation').show();
}
function end_previous() {
    if (index == 0)
        $('.leftnaviguation').hide()
}
function reset_previous() {
    if (index != 0)
        $('.leftnaviguation').show();
}


function updateButtons() {
    if (index == 0)
        $('.leftnaviguation').hide();
    //if (index != 0)
    //  $('.leftnaviguation').show();
    //  if (index != x.length - 1) 
    //  $('.rightnaviguation').show();
    //  if (index == x.length - 1) 
    //   $('.rightnaviguation').hide();


}







    function startSlide() {
                   
    var rotation = 1;
    var $next;
    var $active = $('.image_reel .active');
    if ($active.length == 0) $active = $('.image_reel .reelimg:last');
    $next = $active.next().length ? $active.next() : $('.image_reel .reelimg:first');

    slideSwitch = function () {
        $active = $('.image_reel .active');

        if ($active.length == 0) $active = $('.image_reel .reelimg:last');

        $next = $active.next('.reelimg').length ? $active.next('.reelimg') : $('.image_reel .reelimg:first');

        $active.animate({ opacity: 0.0 }, 1000);
        $next.css('display', 'block');



        $next.css({ opacity: 0.0 })
                    .addClass('active')
                    .animate({ opacity: 1.0 }, 1000, function () {
                        //$('.image_reel').css("height", "200px");

                        $active.removeClass('active last-active');
                        $active.css('display', 'none');
                        //$active.css("height", "235px");
                    });

    };


    slideBack = function () {
        $active = $('.image_reel .active');

        if ($active.length == 0) $active = $('.image_reel .reelimg:last');

        $next = $active.prev('.reelimg').length ? $active.prev('.reelimg') : $('.image_reel .reelimg:last');
        $active.animate({ opacity: 0.0 }, 1000);


        $next.css({ opacity: 0.0 })
                    .addClass('active')
                    .animate({ opacity: 1.0 }, 1000, function () {
                        $active.removeClass('active last-active');
                    });
    };


    rotateSwitch = function () {
        play = setInterval("slideSwitch()", 7000);
    };

    //On Click
    $(".gallery .pause").click(function () {
        if (rotation == 1) {
            clearInterval(play);
            rotation = 0;
            $('.gallery .options .pause').css('background-image', 'url("/epicentertainment/content/images/rctrl.png")');
        }
        else {
            rotateSwitch();
            rotation = 1;
            $('.gallery .options .pause').css('background-image', 'url("/epicentertainment/content/images/pausectrl.png")');
        }
    });
    $(".gallery .rctrl").click(function () {
        if (!$next.is(':animated'))
            slideSwitch();
    });
    $(".gallery .lctrl").click(function () {
        if (!$next.is(':animated'))
            slideBack();
    });

    rotateSwitch(); //Run function on launch
}

function sentContact() {
    
    var failure = "";
    var poststr = "";
    var firstName = document.getElementById("firstName").value;
    var fathersName = document.getElementById("fathersName").value;
    var lastName = document.getElementById("lastName").value;
    var Email = document.getElementById("contactemail").value;
    var address = document.getElementById("address").value;
    var comment = document.getElementById("comment").value;
    var language = document.getElementById("language").value;
    
    var AtPos = Email.indexOf("@");
    var StopPos = Email.lastIndexOf(".");



    var firstNameValue = document.getElementById("firstNameValue").value;
    var fathersNameValue = document.getElementById("fathersNameValue").value;
    var lastNameValue = document.getElementById("lastNameValue").value;
    var EmailValue = document.getElementById("emailValue").value;
    var commentValue = document.getElementById("commentValue").value;
    var addressValue = document.getElementById("addressValue").value;


    /*document.getElementById("fullnameId").className = "row";
    document.getElementById("addressId").className = "row";
    document.getElementById("phoneId").className = "row";
    document.getElementById("emailId").className = "row";*/

    if (AtPos == -1 || StopPos == -1 || Email == "" || Email == "EmailValue") {
      
        failure = "1";
        document.getElementById("contactemail").className = "missing";
    }

    if (firstName == "" || firstName == firstNameValue) {
       
        failure = "1";
        document.getElementById("firstName").className = "missing";

    } else {
        document.getElementById("firstName").className = "";
    }

    if (fathersName == "" || fathersName == fathersNameValue) {
       
        failure = "1";
        document.getElementById("fathersName").className = "missing";
    } else {
        document.getElementById("fathersName").className = "";
    }

    if (lastName == "" || lastName == lastNameValue) {
        
        failure = "1";
        document.getElementById("lastName").className = "missing";
    } else {
        document.getElementById("lastName").className = "";
    }

    if (comment == "" || comment == commentValue) {
      
        failure = "1";
        document.getElementById("comment").className = "missing";
    } else {
        document.getElementById("comment").className = "";
    }

    if (address == "" || address == addressValue) {
    
        failure = "1";
        document.getElementById("address").className = "missing";
    } else {
        document.getElementById("address").className = "";
    }
  

    if (failure == "") {
    
        document.getElementById('contactloader').style.display = "block";
        var poststr = "firstName=" + firstName + "&fathersName=" + fathersName + "&lastName=" + lastName + "&Email=" + Email + "&address=" + address + "&comment=" + comment;
        var routeURL = document.getElementById("routeURL").value;
        /*$(':input', '#formContactMailId').not(':button, :submit, :reset, :hidden').val('').removeAttr('checked').removeAttr('selected');
        $('#formContactMailId').hide();
        $('#contenuSendingContactId').show();*/


        $.ajax({
            url: routeURL + language + '/Home/SendMail',
            type: 'POST',
            data: '' + poststr,
            success: function (data) {
            
                document.getElementById('contactloader').style.display = "none";
                document.getElementById('contactmessage').style.display = "block";

                document.getElementById("firstName").value = firstNameValue;
                document.getElementById("fathersName").value = fathersNameValue;
                document.getElementById("lastName").value = lastNameValue;
                document.getElementById("contactemail").value = EmailValue;
                document.getElementById("address").value = addressValue;
                document.getElementById("comment").value = commentValue;


                setTimeout("closeContact()", 5000);


                /* $('.alertmsg').show();

                setTimeout("hideContactUs()", 5000);
                location.href = $("#urlContactUs").val();*/
            }
        });
    }

}

/*validate email*/

function IsValidEmail(email) {
    var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
    return filter.test(email);
}

/*validate number*/
function IsValidNumber(number) {
    var filter = /[0-9]+/;
    return filter.test(number);
}

/*registration validation*/
function submituser(formid) {
    var recaptcha = document.getElementById('recaptcha_response_field').value;
    $('#notificationmessage2').css('display', 'none');
    test = false;

    var city = $('#cityvalue').val();
    var state = $('#statevalue').val();

    $(formid).find('input,textarea,select').each(function () {
        var isError = false;
        //var test = false;

        var elem;
        if (($(this).attr('required') == '1' && $(this).attr('value').length == 0) || ($(this).attr('email') == '1' && !IsValidEmail($(this).attr('value'))) || ($(this).attr('email') == '1' && !IsValidEmail($(this).attr('value'))) || ($(this).attr('required') == '1' && $(this).attr('value') == city) || ($(this).attr('required') == '1' && $(this).attr('value') == state)) {
            $(this).addClass('required');
            isError = true;
            test = true;
            if (!elem) elem = $(this);
        } else {
            $(this).removeClass('required');

        }
    })
    //alert(test);
    if (test == false && document.getElementById('checkemail').style.display == "none" && document.getElementById('passwordvalidation').style.display == "none") {
        $('#notificationmessage').css('display', 'none');
        if (recaptcha == "") {
            $('#notificationmessage2').css('display', 'block');
            $('#recaptcha_response_field').css('border-color', '#03B6D4');
        } else {
            document.forms["registrationform"].submit();
        }
    } else {
    $('#notificationmessage').css('display', 'block');
    }
}

/*edit validation*/
function edituser(formid) {
    var recaptcha = document.getElementById('recaptcha_response_field').value;
    $('#notificationmessage2').css('display', 'none');
    test = false;

    var city = $('#cityvalue').val();
    var state = $('#statevalue').val();

    $(formid).find('input,textarea,select').each(function () {
        var isError = false;
        //var test = false;

        var elem;
        if (($(this).attr('required') == '1' && $(this).attr('value').length == 0) || ($(this).attr('email') == '1' && !IsValidEmail($(this).attr('value'))) || ($(this).attr('email') == '1' && !IsValidEmail($(this).attr('value'))) || ($(this).attr('required') == '1' && $(this).attr('value') == city) || ($(this).attr('required') == '1' && $(this).attr('value') == state)) {
            $(this).addClass('required');
            isError = true;
            test = true;
            if (!elem) elem = $(this);
        } else {
            $(this).removeClass('required');

        }
    })
    //alert(test);
    if (test == false && document.getElementById('checkemail').style.display == "none" && document.getElementById('passwordvalidation').style.display == "none" && document.getElementById('checkoldpassword').style.display == "none") {
        if (recaptcha == "") {
            $('#notificationmessage2').css('display', 'block');
            $('#recaptcha_response_field').css('border-color', '#03B6D4');
        } else {
            document.forms["registrationform"].submit();
        }
        
    }
}


function onblurregister(formid) {

    formid = formid;

    $(formid).find('input,textarea,select').blur(function () {
        var isError = false;
        var elem;
        if (($(this).attr('required') == '1' && $(this).attr('value').length == 0) || ($(this).attr('email') == '1' && !IsValidEmail($(this).attr('value'))) || (($(this).attr('required') == '1' && $(this).attr('value') == 'City') || ($(this).attr('required') == '1' && $(this).attr('value') == 'area code') || ($(this).attr('required') == '1' && $(this).attr('value') == 'State') || ($(this).attr('required') == '1' && $(this).attr('value') == 'number') || $(this).attr('value') == 'address') || ($(this).attr('email') == '1' && !IsValidEmail($(this).attr('value')))) {
            $(this).addClass('required');
            isError = true;
            if (!elem) elem = $(this);
        } else {
            $(this).removeClass('required');
        }
    })

}

/**/
function sendnewfamily() {
    
    var fullname = document.getElementById("fullname").value;
    var family = document.getElementById("family").value;
    var phone = document.getElementById("phone").value;
    var email = document.getElementById("email").value;
    var location = document.getElementById("location").value;
    var address = document.getElementById("address").value;
    var routeURL = document.getElementById("routeURL").value;
    var language = document.getElementById("language").value;
    
    loginmessage2('#newfamily');
    if (test == false) {
        document.getElementById('annloader').style.display = "block";


        var poststr = "fullname=" + encodeURI(fullname) + "&family=" + encodeURI(family) + "&phone=" + encodeURI(phone) + "&email=" + encodeURI(email) + "&location=" + encodeURI(location) + "&address=" + encodeURI(address);
        $.ajax({
            url: routeURL + language + '/Families/sendNewFamily',
            type: 'POST',
            data: '' + poststr,

            success: function (data) {
                if (data == "success") {

                    $("#fullname").val('');
                    $("#family").val('');
                    $("#phone").val('');
                    $("#email").val('');
                    $("#location").val('');
                    $("#address").val('');
                    document.getElementById('newfamilyvalidation').style.display = "block";
                    document.getElementById('annloader').style.display = "none";
                    
                }
            }
        });

    }
}
/**/

/**/
function sendAdvertise() {

    var firstname = document.getElementById("firstname").value;
    var lastname = document.getElementById("lastname").value;
    var company = document.getElementById("company").value;
    var phone = document.getElementById("phone").value;
    var email = document.getElementById("email").value;
    var comment = document.getElementById("comment").value;
    var chkMedia = document.getElementById("chkMedia").checked;
    var comment = document.getElementById("comment").value;
    var routeURL = document.getElementById("routeURL").value;
    var language = document.getElementById("language").value;
    

    if (chkMedia == true) {
    var resultchk = "individual";
    }else{
    var resultchk = "mediaagency";
    }
    var language = document.getElementById("language").value;

    loginmessage2('#AdvertiseForm');

    

    if (test == false) {
        document.getElementById('annloader').style.display = "block";


        var poststr = "firstname=" + encodeURI(firstname) + "&lastname=" + encodeURI(lastname) + "&company=" + encodeURI(company) + "&phone=" + encodeURI(phone) + "&email=" + encodeURI(email) + "&comment=" + encodeURI(comment) + "&resultchk=" + encodeURI(resultchk) ;
        $.ajax({
            url: routeURL + language + '/Advertise/sendNewAdvertise',
            type: 'POST',
            data: '' + poststr,

            success: function (data) {
                if (data == "success") {

                    $("#firstname").val('');
                    $("#lastname").val('');
                    $("#company").val('');
                    $("#phone").val('');
                    $("#email").val('');
                    $("#comment").val('');
                    document.getElementById('newadvertisevalidation').style.display = "block";
                    document.getElementById('annloader').style.display = "none";

                }
            }
        });

    }
}
/**/

/**/



function DiscussionSubmit() {
    document.getElementById('LoginAddJob').style.display = "none";
    var routeURL = document.getElementById("routeURL").value;
    var language = document.getElementById("language").value;
    var topictextarea = document.getElementById("topictextarea").value;
    var descriptiontextarea = document.getElementById("descriptiontextarea").value;
    if (testlogin == "") {
        testlogin = document.getElementById("showloginform").value;
    }


   
    loginmessage('#DiscussionForum');
   
    if (test == false) {
        document.getElementById('topicloader').style.display = "block";

        var poststr = "topictextarea=" + encodeURI(topictextarea) + "&descriptiontextarea=" + encodeURI(descriptiontextarea);
        $.ajax({
            url: routeURL + language + '/DiscussionForum/DiscussionSubmit',
            type: 'POST',
            data: '' + poststr,

            success: function (data) {
                if (data == "success") {

                    $("#topictextarea").val('');

                    $("#descriptiontextarea").val('');
                    // $('#topicContainer').append(data);
                    document.getElementById('topicloader').style.display = "none";
                    //document.getElementById('forgotpassword').style.display = "none";
                    document.getElementById('discussionmessage').style.display = "block";

                } else {
                   
                    document.getElementById('LoginAddJob').style.display = "block";
                    window.scrollTo(0, $("#LoginAddJob").offset().top);
                }
            }
        });
    }
}


function NewsletterSubmit() {
    var routeURL = document.getElementById("routeURL").value;
    var language = document.getElementById("language").value;
    var fullname = document.getElementById("fullname").value;
    var phone = document.getElementById("phone").value;
    var mobile = document.getElementById("mobile").value;
    var email = document.getElementById("email").value;
    var message = document.getElementById("message").value;
    var country = document.getElementById("newslettercountry").value;
    
    loginmessage2('#NewsletterForm');

    if (test == false) {
        document.getElementById('annloader').style.display = "block";
        var poststr = "fullname=" + encodeURI(fullname) + "&country=" + encodeURI(country) + "&phone=" + encodeURI(phone) + "&mobile=" + encodeURI(mobile) + "&email=" + encodeURI(email) + "&message=" + encodeURI(message);


        $.ajax({
            url: routeURL + language + '/Newsletter/NewsletterSubmit',
            type: 'POST',
            data: '' + poststr,

            success: function (data) {
                if (data == "success") {

                    document.getElementById('annloader').style.display = "none";
                    document.getElementById('annmessage').style.display = "block";

                    $("#fullname").val('');
                    $("#phone").val('');
                    $("#mobile").val('');
                    $("#email").val('');
                    $("#message").val('');

                } else {
                    alert("failed");

                }

            }
        });
    }
}


function CommentSubmit() {
    document.getElementById('LoginAddJob').style.display = "none";
    var routeURL = document.getElementById("routeURL").value;
    var language = document.getElementById("language").value;
    var commenttextarea = document.getElementById("commenttextarea").value;
    var selecteddiscussionid = document.getElementById("selecteddiscussionid").value;
    if (testlogin == "") {
        testlogin = document.getElementById("showloginform").value;
    }

    loginmessage('#DiscussionForumComments');
    if (test == false) {
        document.getElementById('commentsloader').style.display = "block";

        var poststr = "commenttextarea=" + encodeURI(commenttextarea) + "&selecteddiscussionid=" + encodeURI(selecteddiscussionid);
        $.ajax({
            url: routeURL + language + '/DiscussionForum/CommentSubmit',
            type: 'POST',
            data: '' + poststr,

            success: function (data) {
                if (data == "success") {
                   
                    //var newComment = '<div class="paragraph comment"><div class="picture"><img src="/LabakiFamily/Content/images/profilpicture.png" width="44" height="55"> </div><div class="news zoom">$comment$</div><div class="info">$time$</div><div class="info none" style="right: 0px;"> by <span>$user$</span></div></div>';
                    $("#commenttextarea").val('');
                    //newComment = newComment.replace('$comment$', commenttextarea);
                    // $('#commentContainer').append(data);
                    document.getElementById('commentsloader').style.display = "none";
                    document.getElementById('commentsmessage').style.display = "block";
                } else {
                    
                    document.getElementById('LoginAddJob').style.display = "block";
                    window.scrollTo(0, $("#LoginAddJob").offset().top);
                }

            }
        });
    }
}

// This function opens the Login form
var loginopened = 0;
function openLogin() {
    if (loginopened == 0) {
        document.getElementById('sentpass').style.display = "none";
        $('.container .input_text').css('display', 'block');
        $('.container .input_text_desc').css('display', 'block');
        $('.container .divlogin').css('display', 'block');
        $('.container .more').css('display', 'block');
        $('.forgotpass').css('display', 'none');
    }
    if (loginopened == 1) {
        $("#opened").removeClass('openedclose');
        $("#popuplogin").removeClass('popuploginclose');
    }
        document.getElementById("opened").style.display = "block";
        document.getElementById("popuplogin").style.display = "block";
        loginopened = 1;

}

function closLogin() {

    loginopened = 0;
    $('#opened').addClass('openedclose');
    $('#popuplogin').addClass('popuploginclose');
}

function logout() {
    var routeURL = document.getElementById("routeURL").value;
    var language = document.getElementById("language").value;

    $.ajax({
        url: routeURL + language + '/User/SignOut',
        success: function () {
            window.location = routeURL + language;
        }
    });


}

function showMsg() {

    $("#showforgotpass").css('display', 'none');
    $("#showlogin").fadeIn(1000);

    /*$('#loginform2').css('display', 'block');
    $('#forgotpass2').css('display', 'none');
    $('#sendbtn').css('display', 'none');
    $('#loginbtn').css('display', 'block');
    $('#forgotpass').css('display', 'block');*/


}

function sentPass2() {
    var usernameemail = document.getElementById("usernameforgot2").value;
    var routeURL = document.getElementById("routeURL").value;
    var language = document.getElementById("language").value;

    var poststr = "usernameemail=" + encodeURI(usernameemail);

    
    document.getElementById('jobsloader2').style.display = "block";

    $.ajax({
        url: routeURL + language + '/User/GetPassword',
        type: 'POST',
        data: '' + poststr,
        success: function (data) {

            if (data == "True") {
                document.getElementById('jobsloader2').style.display = "none";
                document.getElementById("usernameforgot2").value = "";


                $('#invalidemail2').css('display', 'none');
                $('#emailsent2').css('display', 'block');

                setTimeout("showMsg()", 5000);


            }
            else {
              
                $('#jobsloader2').css('display', 'none');
                $('#invalidemail2').css('display', 'block');

            }
        }
    });
}


function sentPass() {
    var usernameemail = document.getElementById("usernameforgot").value;
    var routeURL = document.getElementById("routeURL").value;
    var language = document.getElementById("language").value;

    var poststr = "usernameemail=" + encodeURI(usernameemail);

    document.getElementById("usernameforgot").value = "";
    document.getElementById('sending').style.display = "block";
    document.getElementById('forgotpass').style.display = "none";

    $.ajax({
        url: routeURL + language + '/User/GetPassword',
        type: 'POST',
        data: '' + poststr,
        success: function (data) {

            if (data == "True") {
                document.getElementById('sending').style.display = "none";
                document.getElementById('invalidlogin').style.display = "none";
                document.getElementById('sentpass').style.display = "block";
                document.getElementById('invalidemail').style.display = "none";
                //setTimeout("closLogin()", 5000);
                loginopened = 0;
                setTimeout("openLogin()", 5000);
                
                //alert(routeURL + language);
                
            }
            else {
                document.getElementById('sending').style.display = "none";
                document.getElementById('forgotpass').style.display = "block";
                document.getElementById('invalidlogin').style.display = "none";
                document.getElementById('sentpass').style.display = "none";
                document.getElementById('invalidemail').style.display = "block";
            }
        }
    });
}

function submitLogin() {


    var usernameLogIn = document.getElementById("usernameLogIn").value;
    var passwordLogIn = document.getElementById("passwordLogIn").value;
    var routeURL = document.getElementById("routeURL").value;
    var language = document.getElementById("language").value;



    var poststr = "usernameLogIn=" + encodeURI(usernameLogIn) + "&passwordLogIn=" + encodeURI(passwordLogIn);

    $.ajax({
        url: routeURL + language + '/User/AjaxWebLogOn',
        type: 'POST',
        data: '' + poststr,
        success: function (data) {

            if (data == "True") {

                testlogin = "logedin";

                $('.container .input_text').css('display', 'none');
                $('.container .input_text_desc').css('display', 'none');
                $('.container .divlogin').css('display', 'none');
                $('.container .more').css('display', 'none');
                $('.container .closelogin').css('display', 'none');

                document.getElementById("usernameLogIn").value = "";
                document.getElementById("passwordLogIn").value = "";
                document.getElementById('loading').style.display = "block";
                setTimeout("closLogin()", 5000);
                //alert(routeURL + language);
                window.location = routeURL + language;
                document.getElementById('logintxt').style.display = "none";
                document.getElementById('welcometxt').style.display = "block";
            } else {
                document.getElementById('invalidlogin').style.display = "block";
            }
            /* $('.alertmsg').show();

            setTimeout("hideContactUs()", 5000);
            location.href = $("#urlContactUs").val();*/
        }
    });

}

function openForgotPass() {
    loginopened = 2;
    $('.container .input_text').css('display', 'none');
    $('.container .input_text_desc').css('display', 'none');
    $('.container .divlogin').css('display', 'none');
    $('.container .more').css('display', 'none');
    $('.forgotpass').css('display', 'block');
}

function openForgotPass2() {
    window.scrollTo(0, $("#LoginAddJob").offset().top);
    loginopened = 2;
    $("#showlogin").css('display', 'none');
    $("#showforgotpass").fadeIn(1000);
    //$("#showlogin").fadeOut("slow");
    
    

    /*$('#loginform2').css('display', 'none');
    $('#forgotpass2').css('display', 'block');
    $('#sendbtn').css('display', 'block');
    $('#loginbtn').css('display', 'none');
    $('#forgotpass').css('display', 'none');*/
}



function submitLogin2() {


    var usernameLogIn2 = document.getElementById("usernameLogIn2").value;
    var passwordLogIn2 = document.getElementById("passwordLogIn2").value;
    var routeURL = document.getElementById("routeURL").value;
    var language = document.getElementById("language").value;
    var pagename = document.getElementById("pagename").value;



    var poststr = "usernameLogIn2=" + encodeURI(usernameLogIn2) + "&passwordLogIn2=" + encodeURI(passwordLogIn2);

    $.ajax({
        url: routeURL + language + '/User/AjaxWebLogOn2',
        type: 'POST',
        data: '' + poststr,
        success: function (data) {

            if (data == "True") {

                testlogin = "logedin";


                document.getElementById("usernameLogIn2").value = "";
                document.getElementById("passwordLogIn2").value = "";
                document.getElementById('LoginAddJob').style.display = "none";

                document.getElementById('loading').style.display = "block";

                $('#hidemenucontainer').load(routeURL + language + '/User/showhidemenu');
                if (pagename == "RecrutmentCenter") {
                    submitjob();
                }

                if (pagename == "PhotoOfTheDay") {
                    submitphoto();
                }

                if (pagename == "AddAnnouncements") {
                    submitann();
                }

               
                if (pagename == "DiscussionForum") {
                    DiscussionSubmit();
                }

                if (pagename == "DiscussionForumComments") {
                    CommentSubmit();
                }


            } else {
                document.getElementById('invalidlogin2').style.display = "block";
            }

        }
    });

}

function onblur(formid) {

    formid = formid;
    
    $(formid).find('input,textarea').blur(function () {
        var isError = false;
        var elem;
        if (($(this).attr('required') == '1' && $(this).attr('value').length == 0) || ($(this).attr('email') == '1' && !IsValidEmail($(this).attr('value'))))     
                 {
                     $(this).addClass('required');
                     isError = true;
                     if (!elem) elem = $(this);
        } else {
            $(this).removeClass('required');
        }
    })

}


function loginmessage(formid) {
    var pagename = document.getElementById("pagename").value;
  
    test = false;

    $(formid).find('input,textarea').each(function () {
        var isError = false;
        //var test = false;
        var elem;
        if (($(this).attr('required') == '1' && $(this).attr('value').length == 0) || ($(this).attr('email') == '1' && !IsValidEmail($(this).attr('value')))) {
            $(this).addClass('required');
            isError = true;
            test = true;
            if (!elem) elem = $(this);
        } else {
            $(this).removeClass('required');
      
        }
    })
   
    if (test == false && formid != "#applyjob") {
        /*test login to test if i'm logged in sections activity ann discussion...*/
        
        //var testlogin = document.getElementById('showloginform').value;
        //alert(testlogin);
     
        if (testlogin == "logedin") {
            document.getElementById('LoginAddJob').style.display = "none";
        } else {
       
        document.getElementById('LoginAddJob').style.display = "block";
        testlogin == "logedin";
        }

        }



}

function loginmessage2(formid) {
    var pagename = document.getElementById("pagename").value;

    test = false;

    $(formid).find('input,textarea').each(function () {
        var isError = false;
        //var test = false;
        var elem;
        if (($(this).attr('required') == '1' && $(this).attr('value').length == 0) || ($(this).attr('email') == '1' && !IsValidEmail($(this).attr('value')))) {
            $(this).addClass('required');
            isError = true;
            test = true;
            if (!elem) elem = $(this);
        } else {
            $(this).removeClass('required');

        }
    })

}

function submitapplication() {
   
        var poststr = "";
        var name = document.getElementById("name").value;
        var phonenumber = document.getElementById("phonenumber").value;
        var Email = document.getElementById("email").value;
        var language = document.getElementById("language").value;
        var routeURL = document.getElementById("routeURL").value;
        var applicationname = document.getElementById("img_src").value;
   
       loginmessage('#applyjob');
       if (test == false) {
           
           document.getElementById('applicationloader').style.display = "block";
           var poststr = "name=" + name + "&phonenumber=" + phonenumber + "&Email=" + Email +"&applicationname=" + applicationname;

           $.ajax({
               url: routeURL + language + '/RecrutmentCenter/SendMail',
               type: 'POST',
               data: '' + poststr,
               success: function (data) {
                   document.getElementById('applicationloader').style.display = "none";
                   document.getElementById('applicationmessage').style.display = "block";
                   document.getElementById("name").value = "";
                   document.getElementById("phonenumber").value = "";
                   document.getElementById("email").value = "";
                   setTimeout("applicationmessage()", 4000); 
                   
                   
               }
           });

       }



   }

   function applicationmessage() {
       document.getElementById('applicationmessage').style.display = "none";
       $('#applybtn').parent().parent().find(".content").find(".paragraph").find(".scrollcontent").animate({ height: '113px' }, 2000);
   }

   


function submitjob() {
    document.getElementById('LoginAddJob').style.display = "none";
    var routeURL = document.getElementById("routeURL").value;
    var language = document.getElementById("language").value;
    var jobtitletextarea = document.getElementById("jobtitletextarea").value;

    var jobemailtextarea = document.getElementById("jobemailtextarea").value;
    var descriptiontextarea = document.getElementById("descriptiontextarea").value;
    
//    var AtPos = jobemailtextarea.indexOf("@");
//    var StopPos = jobemailtextarea.lastIndexOf(".");

//    var descriptiontextarea = document.getElementById("descriptiontextarea").value;
//    if (jobtitletextarea == "" && descriptiontextarea == "") {
//        $('#jobtitletextarea').addClass('required');
//        $('#descriptiontextarea').addClass('required');
//    }
//    else if (jobtitletextarea == "") {
//        $('#jobtitletextarea').addClass('required');
//    }
//    else if (jobemailtextarea == "" || AtPos == -1 || StopPos == -1) {
//        $('#jobemailtextarea').addClass('required');
//    }
//    
//    else if (descriptiontextarea == "") {
//        $('#descriptiontextarea').addClass('required');
//    } else {
    loginmessage('#ApplyJobForm')
if(test == false){
        document.getElementById('jobsloader').style.display = "block";

        var poststr = "jobtitletextarea=" + encodeURI(jobtitletextarea) + "&jobemailtextarea=" + encodeURI(jobemailtextarea) + "&descriptiontextarea=" + encodeURI(descriptiontextarea) + "&language=" + encodeURI(language);
        $.ajax({
            url: routeURL + language + '/RecrutmentCenter/JobSubmit',
            type: 'POST',
            data: '' + poststr,

            success: function (data) {
                if (data == "success") {
                    $("#jobtitletextarea").val('');
                    $("#descriptiontextarea").val('');
                    $("#jobemailtextarea").val('');

                    //$('#jobscontainer').append(data);
                    document.getElementById('jobsloader').style.display = "none";
                    document.getElementById('jobmessage').style.display = "block";

                } else {
                    
                    document.getElementById('LoginAddJob').style.display = "block";
                    window.scrollTo(0, $("#LoginAddJob").offset().top);
                }
            }

        });

    }

}

function submitann() {
    document.getElementById('LoginAddJob').style.display = "none";
    var routeURL = document.getElementById("routeURL").value;
    var language = document.getElementById("language").value;
    var annoucementtextarea = document.getElementById("annoucementtextarea").value;
    var anndesctextarea = document.getElementById("anndesctextarea").value;
    var anncategory = document.getElementById("anncategory").value;
    
    


    loginmessage('#AddAnnouncement');
    if (test == false) {
        document.getElementById('annloader').style.display = "block";
        var poststr = "annoucementtextarea=" + encodeURI(annoucementtextarea) + "&anndesctextarea=" + encodeURI(anndesctextarea) + "&anncategory=" + encodeURI(anncategory) + "&language=" + encodeURI(language);
        //alert(poststr);
        $.ajax({
            url: routeURL + language + '/Announcements/AnnSubmit',
            type: 'POST',
            data: '' + poststr,

            success: function (data) {
                if (data == "success") {
                    $("#annoucementtextarea").val('');
                    $("#anndesctextarea").val('');

                    document.getElementById('annloader').style.display = "none";
                    document.getElementById('annmessage').style.display = "block";
                } else {
                    
                    document.getElementById('LoginAddJob').style.display = "block";
                    window.scrollTo(0, $("#LoginAddJob").offset().top);
                }

            }

        });
    }

}

function checkpassword() {
    var password = document.getElementById("password").value;
    var confirmpass = document.getElementById("confirmpass").value;
    if (password != confirmpass) {
        document.getElementById('passwordvalidation').style.display = "block";
        
    } else {
        document.getElementById('passwordvalidation').style.display = "none";
    }
}

function checkemail() {
    var routeURL = document.getElementById("routeURL").value;
    var language = document.getElementById("language").value;
    var email = document.getElementById("email").value;
    var poststr = "email=" + encodeURI(email);
    $.ajax({
        url: routeURL + language + '/Register/CheckEmail',
        type: 'POST',
        data: '' + poststr,

        success: function (data) {
            
            if (data == "success") {
                document.getElementById('checkemail').style.display = "none";
            } else {
                document.getElementById('checkemail').style.display = "block";
                $('#email').addClass('required');

            }

        }

    });
}


function submitphoto() {
    document.getElementById('LoginAddJob').style.display = "none";
    var routeURL = document.getElementById("routeURL").value;
    var language = document.getElementById("language").value;
    var photocategorytextarea = document.getElementById("photocategorytextarea").value;
    var photodescriptiontextarea = document.getElementById("photodescriptiontextarea").value;
    var photoname = document.getElementById("img_src").value;

    if (photocategorytextarea == "" && photodescriptiontextarea == "") {
        $('#photocategorytextarea').addClass('required');
        $('#photodescriptiontextarea').addClass('required');
    }
    else if (photocategorytextarea == "") {
        $('#photocategorytextarea').addClass('required');
    }
    else if (photodescriptiontextarea == "") {
        $('#photodescriptiontextarea').addClass('required');
    } else {

        document.getElementById('photoloader').style.display = "block";


        var poststr = "photocategorytextarea=" + encodeURI(photocategorytextarea) + "&photodescriptiontextarea=" + encodeURI(photodescriptiontextarea) + "&photoname=" + encodeURI(photoname) + "&language=" + encodeURI(language);
        //alert(poststr);
        if (photocategorytextarea != "" && photodescriptiontextarea != "" && photoname != "") {
            $.ajax({

                url: routeURL + language + '/Gallery/PhotoSubmit',
                type: 'POST',
                data: '' + poststr,

                success: function (data) {
                    if (data == "success") {
                        $("#photodescriptiontextarea").val('');

                        //$('#jobscontainer').append(data);
                        document.getElementById('photoloader').style.display = "none";
                        document.getElementById('photomessage').style.display = "block";
                    }
                    else {
                       
                        document.getElementById('LoginAddJob').style.display = "block";
                        window.scrollTo(0, $("#LoginAddJob").offset().top);
                    }

                }

            });
        } else {

            $("#photodescriptiontextarea").val('');

            //$('#jobscontainer').append(data);
            document.getElementById('photoloader').style.display = "none";
            document.getElementById('photoerrormessage').style.display = "block";
        }
    }

}

/*rita*/

function showNextPicture() {
    x = $('#' + currentslideshow).find(".slide");
    width = x.width();
    if (disable == 0) {
        disable = 1;
        //left = $('.slideshow').position().left;
        left = $('#' + currentslideshow + ' > .div_padd > .slideshow').position().left;
        if (index == 0) {
            $('#' + currentslideshow + ' > .div_padd > .slideshow').animate({
                left: left - (width + padding) + "px"
            }, 1000, 'easeInOutCubic', add);
        }
        else {

            if (index == x.length - 1) {
                disable = 0;
            }

            else {
                $('#' + currentslideshow + ' > .div_padd > .slideshow').animate({
                    left: left - (width + padding) + "px"
                }, 1000, 'easeInOutCubic', add);
            }
        }
    }
}

function showPreviousPicture() {
    x = $('#' + currentslideshow).find(".slide");
    width = x.width();
    if (disable == 0) {
        disable = 1;
        //left = $('.slideshow').position().left;
        left = $('#' + currentslideshow + ' > .div_padd > .slideshow').position().left;
        if (index == 0) {
            disable = 0;

        }
        else {
            $('#' + currentslideshow + ' > .div_padd > .slideshow').animate({
                left: left + (width + padding) + "px"
            }, 1000, 'easeInOutCubic', sub_index);
        }
    }
}

function addChild() {

    var firstname = $('#childfirstname').val();
    var middlename = $('#childmiddlename').val();
    var lastname = $('#childlastname').val();

    var newRow = $($('.childrencontainer')[0]).clone();

    var childcounter = 1;
    $(newRow).find('input').each(function (index, value) {
        $(this).val('');
        if (childcounter == 1) {
            $(this).attr('name', 'child_firstname_' + eval($('.childrencontainer').length + index + 1));
            $(this).val(firstname);
        }
        if (childcounter == 2) {
            $(this).attr('name', 'child_middlename_' + eval($('.childrencontainer').length + index));
            $(this).val(middlename);
        }
        if (childcounter == 3) {
            $(this).attr('name', 'child_lastname_' + eval($('.childrencontainer').length + index - 1));
            $(this).val(lastname);
        }

        $(this).removeAttr('required', '1');
       
        ++childcounter;
    });

    $(newRow).find('select').each(function (index, value) {
       $(this).attr('name', 'child_Gender_' + eval($('.childrencontainer').length + 1));
   });

    /**/
    $($('.childrencontainer')[$('.childrencontainer').length - 1]).find('input').each(function(index, value){
    $(this).attr('required','1');
});
/**/

$(newRow).insertAfter($($('.childrencontainer')[$('.childrencontainer').length - 1]));

var rowNumber = $('.childrencontainer').length;
if (rowNumber <= 1) {
    document.getElementById('removechild').style.display = "none";
} else {
    document.getElementById('removechild').style.display = "block";
}

}

function deleteChild() {

    var rowNumber = $('.childrencontainer').length;
    if (rowNumber != 1) {
        $($('.childrencontainer')[$('.childrencontainer').length - 1]).remove();
        $($('.childrencontainer')[$('.childrencontainer').length - 1]).find('input').each(function (index, value) {
            $(this).removeAttr('required', '1');
            $(this).removeClass('missing');
        });
    }

    var rowNumber = $('.childrencontainer').length;
    if (rowNumber <= 1) {
        document.getElementById('removechild').style.display = "none";
    } else {
        document.getElementById('removechild').style.display = "block";
    }

}


function getfathers() {
    var routeURL = document.getElementById("routeURL").value;
    var language = document.getElementById("language").value;
    var familyid = document.getElementById("familyId").value;
    var poststr = "familyid=" + encodeURI(familyid);
    var url = routeURL + language + '/Register/GetFathers';

    $('#fathersdropdown').load(url, { familyid: familyid });

}

function editProfile() {
    var routeURL = document.getElementById("routeURL").value;
    var language = document.getElementById("language").value;
    var url = routeURL + language + '/Register';

    window.location = url;
}

function viewProfile(dataId) {
    //document.getElementById('loaderprofile').style.display = "block";
    
    var URL = document.getElementById('popupactionurl').value;
    showpopup2();
    $.ajax({
        type: 'POST',
        data: 'relatedData=' + dataId,
        success: function (response) {
           
            if (response) {

                $("#htmlPart").empty();
                $("#htmlPart").append(response); //the response is the render partial with the ViewData


                // document.getElementById('siteOverlay').style.height = $(".wrapper").attr('offsetHeight') + "px";
                //$('.popupbg').center();
                $('#popupbg').css({ display: 'block' });

                $('#loaderprofile').css({ display: 'none' });

            }
        },
        error: function (error) { },
        url: URL // controller/action
    });
}


function showpopup2() {

    $('#siteOverlay').css({ height: $(".wrapper").attr('offsetHeight') + "px" });
    $('#siteOverlay').css({ display: 'block' });
    $('#loaderprofile').css({ display: 'block' });

}

function enterclick(event){

    if (event.keyCode == 13) {
        submitLogin();
    }

}

function changepassword() {
    $('#changepassword').css({ display: 'block' });
    $('#changepasswordlabel').css({ display: 'none' });
    $('#oldpassword').attr('required', '1');
}

function checkoldpassword() {
    var routeURL = document.getElementById("routeURL").value;
    var language = document.getElementById("language").value;
    var oldpassword = document.getElementById("oldpassword").value;
    var emailedit = document.getElementById("emailedit").value;
    var poststr = "emailedit=" + encodeURI(emailedit) + "&oldpassword=" + encodeURI(oldpassword);
    //alert(poststr);
    $.ajax({
        url: routeURL + language + '/Register/CheckOldPassword',
        type: 'POST',
        data: '' + poststr,

        success: function (data) {
            if (data == "success") {
                document.getElementById('checkoldpassword').style.display = "none";
            } else {
                document.getElementById('checkoldpassword').style.display = "block";
                $('#oldpassword').addClass('required');

            }

        }

    });

}

function emptyonclick(elt) {
    elt.value = "";
}


function changestyleonclick(elt) {
    elt.value = "";
    $(elt).css('font-style', 'normal');
    $(elt).css('font-weight', 'bold');
}

function changestyleonblur(elt) {
    $(elt).css('font-style', 'italic');
    $(elt).css('font-weight', 'normal');

}


function GetMembers() {
    var routeURL = document.getElementById("routeURL").value;
    var language = document.getElementById("language").value;
    var familyRoot = document.getElementById("selectlistfamilyroot").value;
    var poststr = "familyRoot=" + encodeURI(familyRoot);
   
    $.ajax({
        url: routeURL + language + '/Families/GetMembers',
        type: 'POST',
        data: '' + poststr,

        success: function (data) {
            $('#familyMembers').html(data);
        }

    });

}

function addSpouseGender() {
    var gender = document.getElementById("genderId").value;
    if (gender == "2") {
        document.getElementById("spouseGender").value = "Female";
    } else {
        document.getElementById("spouseGender").value = "Male";
    }
}


function checkRecaptcha() {
    alert("in");
    var routeURL = document.getElementById("routeURL").value;
    var language = document.getElementById("language").value;
    var poststr = "";
    $.ajax({
        url: routeURL + language + '/Account/testCaptcha',
        type: 'POST',
        data: '' + poststr,

        success: function (data) {
            alert("success");
        }

    });
}

/*function checkemail() {
    var routeURL = document.getElementById("routeURL").value;
    var language = document.getElementById("language").value;
    var email = document.getElementById("email").value;
    var poststr = "email=" + encodeURI(email);
    $.ajax({
        url: routeURL + language + '/Register/CheckEmail',
        type: 'POST',
        data: '' + poststr,

        success: function (data) {

            if (data == "success") {
                document.getElementById('checkemail').style.display = "none";
            } else {
                document.getElementById('checkemail').style.display = "block";
                $('#email').addClass('required');

            }

        }

    });
}*/








       


