﻿var isFacebookLogin = false;
var FB_INITIALIZED = false;
var user = null;  // logged in user if it exists




/// <reference path="jquery-1.4.4-vsdoc.js" />
//$(document).ready(function () {
//    Adding event handler for main navigation menu
//    $('.MainMenu div').each(function () {
//         skipping navigation divs used for styling (borders)
//        if ($(this).hasClass('RightDesign') || $(this).hasClass('LeftDesign') || $(this).hasClass('BorderBottom'))
//            return true;
//        $(this).hover(function (event) { mainNavigationMouseOver($(this), event); }, function (event) { mainNavigationMouseOut($(this), event); });
//    });

//    /Adding event handler for main navigation menu
//});

// JavaScript Document

//function mainNavigationMouseOver(obj, event) {
//    $('#' + $(obj).attr('class') + "SubMenu").animate({ height: "41" }, 300, "easeOutSine", function () {
//        $('#' + $(obj).attr('class') + "SubMenu").hover(function () { return false; }, function (event) { mainNavigationMouseOut($(obj), event); });
//    });
//}

//function mainNavigationMouseOut(obj, event) {
//    if ($(event.target).closest($(obj)).length || $(event.target).closest('#' + $(obj).attr('class') + "SubMenu").length || $(event.target).closest('#headerBorderBottom').length) {
//   
//        $('#' + $(obj).attr('class') + "SubMenu").animate({
//            height: "0"
//        }, 300, "easeOutSine", function () { });
//    }

//    else { return; }


//}



function BgBannerSize() {

    var width = $(window).width();
    if (width <= 995) {

        $('.LeftBgBanner').css('width', 0);
        $('.RightBgBanner').css('width', 0);
    }

    else {
        var BannerWidth = (width - 1070) / 2;
        $('.LeftBgBanner').css('width', BannerWidth);
        $('.RightBgBanner').css('width', BannerWidth);
    }

}

function PositionArrows() {
    var width = $(window).width();

    if (width > 1029) {
        $('#SlideLeftT').css('left', -19);
        $('#SlideRightT').css('right', -19);
    }
    else {
        $('#SlideLeftT').css('left', 0);
        $('#SlideRightT').css('right', 0);

    }

}

function ArrowsPosition() {

    var width = $(window).width();

    if (width > 1029) {
        $('.SlideContainer .SlideLeft').css('left', -22);
        $('.SlideContainer .SlideRight').css('right', -22);
    }
    else {
        $('.SlideContainer .SlideLeft').css('left', 0);
        $('.SlideContainer .SlideRight').css('right', 0);

    }

}

function CounterPosition() {

    var width = $(window).width();

    if (width > 1029) {
        $('#picCount').css('right', -59);
      
    }
    else {
        $('#picCount').css('right', -44);

    }

}




function ChangePicture(x, nb, newa, main, pic ,count) {

    for (ImageId = 1; ImageId <= count; ImageId++) {

        if (ImageId != x) {
            document.getElementById(newa + ImageId).className = "ArticleContainer";

        }
        else {

            document.getElementById(newa + x).className = "ArticleContainer selected";

        }

    };
    document.getElementById(main).src = document.getElementById(pic).value;

}

//var SubClose = "0";
//function OpenSubmenu() {

//    if ($('.headerSlider').is(':visible')) {

//        if (SubClose == "0") {
//            SubClose = "1"
//            $('#OacityHeader').fadeIn(function () {
//                $("#SubMenuContent").animate({
//                    height: "41"
//                }, 300, "easeOutSine", function () {

//                });

//            });
//        }
//    }
//    else {
//        $("#SubMenuContent").animate({
//            height: "41"
//        }, 300, "easeOutSine", function () { });
//    }
//}

//function CloseSubmenu() {

//    if ($('.headerSlider').is(':visible')) {
//        $("#SubMenuContent").animate({
//            height: "0"
//        }, 300, "easeOutSine", function () {
//            $('#OacityHeader').fadeOut(function () { SubClose = "0" });
//        });
//    }

//    else {
//        $("#SubMenuContent").animate({
//            height: "0"
//        }, 300, "easeOutSine", function () { });

//    }
//}




function ShowVideo(whoToPlay ,VideoU) {
    $('html').animate({ scrollTop: 150 }, 'slow', function () {
     $("body").scrollTop(150);
        $('#FullOpacity').fadeIn(function () {
            $("#VideoPlay").animate({
                height: "505"
            }, 300, "easeOutSine", function () {

            });
        });

    });

    if (whoToPlay == 1) {
        JWloadMovie(VideoU, 'JWPlayerContainer', 'true');

    }

}


function CloseVideo() {
    $("#VideoPlay").animate({
        height: "0"
    }, 300, "easeOutSine", function () {
        $('#FullOpacity').fadeOut();
    });

}

function OpenTellFriend() {

    if ($("#FbPop").height() != 0) {
        $("#FbPop").animate({
            height: "0"
        });

        $("#TellFriend").animate({
            height: "395"
        }, 600, "easeOutSine", function () {

        });

    }

    else {

        $('#FixedOpacity').fadeIn(function () {
            $('#tell').fadeIn();
            $("#TellFriend").animate({
                height: "395"
            }, 600, "easeOutSine", function () {

            });
        });

    }

}

function CloseTellFriend() {

    $("#TellFriend").animate({
        height: "0"
    }, 600, "easeOutSine", function () {
        $('#tell').fadeOut();
        $('#FixedOpacity').fadeOut();
    });

}

function OpenFbPop() {

    if ($("#TellFriend").height() != 0) {
        $('#tell').fadeOut();
        $("#TellFriend").animate({
            height: "0"
        });

        $("#FbPop").animate({
            height: "228"
        }, 600, "easeOutSine", function () {

        });

    }

    else {

        $('#FixedOpacity').fadeIn(function () {
            $("#FbPop").animate({
                height: "228"
            }, 600, "easeOutSine", function () {

            });
        });

    }
}


function CloseFbPop() {

    $("#FbPop").animate({
        height: "0"
    }, 600, "easeOutSine", function () {
        $('#FixedOpacity').fadeOut();
    });

}


function manageControls(position) {

    var currentPosition = 0;
    var slideWidth = 326;
    var slides = $('.poster');
    var numberOfSlides = slides.length;

   if (position == numberOfSlides - 3 || position == numberOfSlides - 2 || position == numberOfSlides - 1) {
        $('#SlideLeft').css('background-position', 'bottom');
        $('#SlideLeft').addClass('invis');

        $('#SlideLeft').css('cursor', 'default');
    }
    else {
        $('#SlideLeft').css('background-position', 'top');
        $('#SlideLeft').removeClass('invis');
        $('#SlideLeft').css('cursor', 'pointer');
    }
    if (position == 0) {
        $('#SlideRight').css('background-position', 'bottom');
        $('#SlideRight').addClass('invis');
        $('#SlideRight').css('cursor', 'default');

    }
    else {
        $('#SlideRight').css('background-position', 'top');
        $('#SlideRight').removeClass('invis');
        $('#SlideRight').css('cursor', 'pointer');
    }

    $(".switch").removeClass('selected');
    var switchPosition;
    if (position % 3 != 0)
        switchPosition = position - (position % 3) + 3;
    else
        switchPosition = position;
    document.getElementById("switch" + switchPosition).className = "switch selected";

}


function ShowSubMenu(MenuId, DivId) {

    if ($('.headerSlider').is(':visible')) {

        $('#OacityHeader').fadeIn(function () {
            $("#" + MenuId).animate({ height: "41" }, 300, "easeOutSine", function () { });
        });

        $('.' + DivId).mouseleave(function (event) {
            hideHandler(event, MenuId);
        });
    }

    else {
        $("#" + MenuId).animate({ height: "41" }, 300, "easeOutSine", function () { });

        $('.' + DivId).mouseleave(function (event) {
            hideHandler(event, MenuId);
        });
    }
}


function hideHandler(event, MenuId) {
    var target = $(event.relatedTarget);
    if (!$(target).is("#" + MenuId) && !$(target).is(".BeautySubMenu") && !$(target).is("#headerBorderBottom")) {
        if ($('.headerSlider').is(':visible')) {
            $("#" + MenuId).animate({ height: "0" }, 300, "easeOutSine", function () { $('#OacityHeader').fadeOut(function () { }); });
        }
        else {
            $("#" + MenuId).animate({ height: "0" }, 300, "easeOutSine", function () { });
        }

    }
}


function fixOnMouseOut(element, event, MenuId) {
    var current_mouse_target = null;
    if (event.toElement) {
        current_mouse_target = event.toElement;
    } else if (event.relatedTarget) {
        current_mouse_target = event.relatedTarget;
    }
    if (!is_child_of(element, current_mouse_target) && element != current_mouse_target) {


        $("#" + MenuId).animate({
            height: "0"
        }, 300, "easeOutSine", function () {
            $('#OacityHeader').fadeOut(function () { });
        });


    }
}

function is_child_of(parent, child) {
    if (child != null) {
        while (child.parentNode) {
            if ((child = child.parentNode) == parent) {
                return true;
            }
        }
    }
    return false;
}





var isSlidingTab = 0;
function showTab(id) {

    if (isSlidingTab == 0) {
        
        isSlidingTab = 1;
        document.getElementById("MostCommentedButton").className = "MostCommented";
        document.getElementById("MostReadButton").className = "MostRead";
        if (id == "HomeMostRead") {
           
            document.getElementById("MostReadButton").className = "MostRead selected";


            $("#HomeMostCommented ").fadeOut(600,function () {
                $("#HomeMostRead").fadeIn(300,function () { isSlidingTab = 0; });

            })

//            $("#HomeMostCommented ").animate({ height: "0" }, 600, "easeInCirc", function () {

//                $("#HomeMostRead").animate({ height: "222" }, 600, "easeInCirc", function () { isSlidingTab = 0; });

//            });

        }


        if (id == "HomeMostCommented") {

            document.getElementById("MostCommentedButton").className = "MostCommented selected";

            
            $("#HomeMostRead ").fadeOut(600,function () {
                $("#HomeMostCommented").fadeIn(300,function () { isSlidingTab = 0; });

            })

//            $("#HomeMostRead ").animate({ height: "0" }, 600, "easeInCirc", function () {

//                $("#HomeMostCommented").animate({ height: "222" }, 600, "easeInCirc", function () { isSlidingTab = 0; });

//            });
        }
    }
}




function OpenNewReg() {

    if ($('.TopBanner').is(':visible')) {
        $('#RegOpacity .TopMenu ').css('top', 109);

    }

    else {
        $('#RegOpacity .TopMenu').css('top', 0);
    }

    if ($("#TellFriend").height() != 0) {
        $('#tell').fadeOut();
        $("#TellFriend").animate({ height: "0" });

        $('#RegOpacity').fadeIn(function () { $("#NewRegOpacity").animate({ height: "596" }, 600, "easeOutSine", function () { }); });

    }

    else
        if ($("#FbPop").height() != 0) {

            $('#tell').fadeOut();
            $("#FbPop").animate({ height: "0" });

            $('#RegOpacity').fadeIn(function () { $("#NewRegOpacity").animate({ height: "596" }, 600, "easeOutSine", function () { }); });

        }
        else
            if ($("#LoginPopUp").height() != 0) {
                $("#LoginPopUp").animate({ height: "0" });
                $("#NewRegOpacity").animate({ height: "596" });
        
        }

        else {
            $('#RegOpacity').fadeIn(function () { $("#NewRegOpacity").animate({ height: "596" }, 600, "easeOutSine", function () { }); });


        }
}


function CloseNewReg() {

    $("#NewRegOpacity").animate({ height: "0" }, 600, "easeOutSine", function () { $('#RegOpacity').fadeOut(); });
}

function OpenSiteMap() {
    if ($("#SiteMap").height() == 0) {
        $('.MapAct').css('color', '#BF1871');
        $("#SiteMap").animate({ height: "370" }, 100, "easeOutSine", function () {
            $('html, body').animate({
                scrollTop: $(document).height() - $(window).height()
            },
   2000,
   "easeOutQuint"
);

        });
    }

    else {
        $('.MapAct').css('color', '#7E7E7E');
        $("#SiteMap").animate({ height: "0" }, 2000, "easeOutQuint", function () { });
    }
}





function OpenLoginPop() {

    if ($('.TopBanner').is(':visible')) {
        $('#RegOpacity .TopMenu ').css('top', 109);

    }

    else {
        $('#RegOpacity .TopMenu').css('top', 0);
    }

    if ($('#NewRegOpacity').height() != 0) {
        $("#NewRegOpacity").animate({ height: "0" }); 
            $("#LoginPopUp").animate({ height: "354" });    
    }

    else {
        $('#RegOpacity').fadeIn(function () { $("#LoginPopUp").animate({ height: "354" }, 600, "easeOutSine", function () { }); });

    }

    if ($("#TellFriend").height() != 0) {
        $('#tell').fadeOut();
        $("#TellFriend").animate({ height: "0" });

        $('#RegOpacity').fadeIn(function () { $("#LoginPopUp").animate({ height: "354" }, 600, "easeOutSine", function () { }); });

    }

    else
        if ($("#FbPop").height() != 0) {

            $('#tell').fadeOut();
            $("#FbPop").animate({ height: "0" });

            $('#RegOpacity').fadeIn(function () { $("#LoginPopUp").animate({ height: "354" }, 600, "easeOutSine", function () { }); });

        }
        else
            if ($("#LoginPopUp").height() != 0) {
                $("#LoginPopUp").animate({ height: "0" });
                $("#LoginPopUp").animate({ height: "354" });

            }

            else {
                $('#RegOpacity').fadeIn(function () { $("#LoginPopUp").animate({ height: "354" }, 600, "easeOutSine", function () { }); });


            }
}

function CloseLoginPop() {

    $("#LoginPopUp").animate({ height: "0" }, 600, "easeOutSine", function () { $('#RegOpacity').fadeOut(); });
}

function OpenForgotPassword() {

    $("#LoginPopUp").animate({ height: "0" }, 600, "easeOutSine", function () { $('#RegOpacity .TopMenu ').hide(); });
    $("#ForgotPassword").animate({ height: "181" });

}

function CloseForgotPassword() {

    $("#ForgotPassword").animate({ height: "0" }, 600, "easeOutSine", function () {

        $('#RegOpacity').fadeOut(function () {

            $('#RegOpacity .TopMenu ').show();
         });
    });
}


//var ISFadin = 0;
//function ChangeMainDiv(id, MainId) {
//    var xy = 0;
//    var cou = 0;
//    if (ISFadin == 0) {
//        ISFadin = 1;
//        if (xy==0){
//            for (var x = 1; x <= 4; x++) {
//                xy = 1;
//                cou++;
//                $('#MainFashion' + x).css('display', 'none');
//                if (cou == 4) {
//                    xy = 0;
//                }
//            }
//       }

//        $('#' + MainId).fadeOut(function () {

//            $('#' + id).fadeIn(function () {
//                ISFadin = 0;
//            });
//        });

//    }
//}

//function ResetMainDiv(main, event) {

//    $("#bodyFa").mouseleave(function (event) { 
//    for (var x = 1; x <= 4; x++) {
//           $('#MainFashion' + x).css('display', 'none');
//      }

//     $('#' + main).fadeIn(function () {

//           $('#' + main).css('display', 'block');
//            ISFadin = 0;
//      });
//    
//    });

var check = 0;
function ChangeMainDiv(id, MainId) {
    $('.MainFashion').css('height', '0');
    $('.MainFashion').css('padding-bottom', '0');
    $('#' + id).stop().animate({ height: 139, paddingBottom: 14 }, 0);
}
function ChangeMainDiv1(id, MainId) {

    $('#' + id).stop().animate({ height: 0, paddingBottom: 0 }, 0);
    $('#' + MainId).css('height', '139px');
    $('#' + MainId).css('padding-bottom', '14px');
}




function SlideThumbnails() {


    var currentPosition = 0;
    var slideWidth = 127;
    var slides = $('.OtherPicCadre');
    var numberOfSlides = slides.length;

    slides
        .wrapAll('<div id="slideInner"></div>')
        .css({
            'float': 'right',
            'width': 111
        });

    $('#slideInner').css('width', slideWidth * numberOfSlides);

    $('.SlideContainer')

    manageControlsT(currentPosition, numberOfSlides);

    $('.control').bind('click', function () {
        if ($(this).attr('id') == 'SlideLeftT') {
            if (currentPosition + 12 > numberOfSlides) {
                currentPosition = currentPosition + (numberOfSlides % 6);
            }
            else
                currentPosition = currentPosition + 6;

        }
        else
            if ($(this).attr('id') == 'SlideRightT') {
                if (currentPosition - 6 < 0) {
                    currentPosition = currentPosition - (numberOfSlides % 6);
                }
                else
                    currentPosition = currentPosition - 6;
            }
        manageControlsT(currentPosition, numberOfSlides);
        $('#slideInner').animate({ 'marginRight': slideWidth * (-currentPosition) });
    });


}


function manageControlsT(position, numberOfSlides) {

    // Hide left arrow if position is first slide
    if (position == 0) {
        $('#SlideRightT').hide()
        
      }
    else {
        $('#SlideRightT').show()
        
    }
    // Hide right arrow if position is last slide
    if (position == numberOfSlides - 6 || numberOfSlides<6) {
        $('#SlideLeftT').hide() 
     }
    else {
        $('#SlideLeftT').show()
     }
}



function submitContact(ContactType) {

    var Mainroute = document.getElementById("Mainroute").value;
    var url = Mainroute + "Home/SendMail";
    var ContactType = ContactType;
    var email = $("#EmailInput").val();
    var FullName = $("#NameInput").val();
    var PhoneNmbr = $("#PhoneInput").val();
    var Country = $("#CountryInput").val();
    var Message = $("#NoteInput").val();

    var AtPos = email.indexOf("@");
    var StopPos = email.lastIndexOf(".");

    document.getElementById("EmailAdvetise").className = "inputArea";
    document.getElementById("NameAdvetise").className = "inputArea";
    document.getElementById("PhoneAdvertise").className = "inputArea";
    document.getElementById("CountryAdvertise").className = "inputArea";
    document.getElementById("NoteAdvertise").className = "inputArea";

    var failure = "";
    if ((AtPos == -1 || StopPos == -1)) {
        document.getElementById("EmailAdvetise").className = "inputArea Required";
        failure = "1";

    }
    if (FullName == "") {
        document.getElementById("NameAdvetise").className = "inputArea Required";
        failure = "1";
    }
    if (PhoneNmbr == "") {

        document.getElementById("PhoneAdvertise").className = "inputArea Required";
        failure = "1";
    }
    if (Country == "") {
        document.getElementById("CountryAdvertise").className = "inputArea Required";
        failure = "1";
    }

    if (Message == "") {
        document.getElementById("NoteAdvertise").className = "inputArea Required";
        failure = "1";
    }

    if (failure == "") {
        var emailTo = "rfakhry@koein.com";
        $("#AjaxL").show()
        $.ajax({
            url: url,
            type: 'POST',
            data: 'email=' + email + "&FullName=" + FullName + "&PhoneNmbr=" + PhoneNmbr + "&Country=" + Country + "&Message=" + Message + "&emailTo=" + emailTo + "&ContactType=" + ContactType,
            success: function (data) {
                $("#AjaxL").hide()
                //$("#mailNote").show();
                 $("#MailMsg").show();
                setTimeout(function () {
                     $("#MailMsg").hide();
                }, 4000);

                //                  window.setTimeout("hideNotec()", 4000);

                $(".AdvertiseForm")[0].reset();
                //                  document.SendFormMsg.reset();

            }
        });
    }
}

function resetForm(className) {
    $("." + className)[0].reset();
}


function bookmark(art) {

    title = document.title;
    url = window.location.href;
    if (window.sidebar) {
        // Mozilla
        window.sidebar.addPanel(art, url, "");
    } else if (window.external) {
        // IE Favorite
        window.external.AddFavorite(url, art);
    }
    else if (window.opera && window.print) {
        // Opera
        return true;
    }

}


function SendToMail (){
        OpenTellFriend();
}



function SendToFriend(ContactType) {

    var Mainroute = document.getElementById("Mainroute").value;
    var url = Mainroute + "Home/SendMailFriend";
    var ContactType = ContactType;
    var Message = $("#Message").val();
    var YourName = $("#YourName").val();
    var YourMail = $("#YourMail").val();
    var FriendName = $("#FriendName").val();
    var FriendMail = $("#FriendMail").val();
    var Link = window.location.href;



    var AtPos = YourMail.indexOf("@");
    var StopPos = YourMail.lastIndexOf(".");

    var AtPosFrnd = FriendMail.indexOf("@");
    var StopPosFrnd = FriendMail.lastIndexOf(".");

    document.getElementById("textNote").className = "InputField";
    document.getElementById("NameFd").className = "InputField ";
    document.getElementById("mailFd").className = "InputField noMarginleft ";
    document.getElementById("FriendN").className = "InputField";
    document.getElementById("FriendM").className = "InputField noMarginleft";

    var failure = "";
    if ((AtPos == -1 || StopPos == -1)) {
        document.getElementById("mailFd").className = "InputField noMarginleft Required";
        failure = "1";

    }
    if ((AtPosFrnd == -1 || StopPosFrnd == -1)) {
        document.getElementById("FriendM").className = "InputField noMarginleft Required";
        failure = "1";

    }
    if (Message == "") {
        document.getElementById("textNote").className = "InputField Required";
        failure = "1";
    }
    if (YourName == "") {

        document.getElementById("NameFd").className = "InputField Required";
        failure = "1";
    }
    if (FriendName == "") {
        document.getElementById("FriendN").className = "InputField Required";
        failure = "1";
    }


    if (failure == "") {
            $("#AjaxTell").show()
            $.ajax({
                url: url,
                type: 'POST',
                data: 'Message=' + Message + "&YourName=" + YourName + "&YourMail=" + YourMail + "&FriendName=" + FriendName + "&FriendMail=" + FriendMail + "&Link=" + Link + "&ContactType=" + ContactType,
                success: function (data) {
                    $("#AjaxTell").hide()

                    $("#SuccessNote").show();
                    setTimeout(function () {
                        $("#SuccessNote").hide();
                    }, 4000);

                    $(".tellForm")[0].reset();
                    CloseTellFriend();
                }
            });
    }
}



function ShowMoreArticles() {

    var CatId = $('#CatId').val();
    var CatTemplateId = $('#CatTemplateId').val();
    var pageId = $('#currentPageArticle').val();

    pageId = parseInt(pageId) + 1;
    if (parseInt(pageId) == parseInt(document.getElementById("NbPageArticles").value - 1))
        $('.MoreToList').hide();
    if (parseInt(pageId) <= parseInt(document.getElementById("NbPageArticles").value - 1)) {
        document.getElementById("currentPageArticle").value = pageId;
          $('.LoaderList').show();
        var Mainroute = document.getElementById("Mainroute").value;
        var Controller = document.getElementById("Controller").value;

        var url = Mainroute + 'Home/getArticles?pageId=' + pageId + "&CatId=" + CatId + "&CatTemplateId=" + CatTemplateId;
       var controller= document.getElementById("Controller").value;
        $.ajax({
            url: url,
            type: 'POST',
            data: 'controller=' + controller,
            success: function (data) {
                if (CatTemplateId == 1) {
                    $('#FirstToList').append(data);
                }
                else
                    if (CatTemplateId == 2) {
                        $('#SecondToList').append(data);
                    }


                    $('.LoaderList').hide();
            }
        });

    }
    else {
        $('.MoreToList').hide();
    }

}


function registerWebUser() {

    var Mainroute = document.getElementById("Mainroute").value;
    var url = Mainroute + "Home/NewRegister";
    var NewMail = $("#NewMail").val();
    var NewPassword = $("#NewPassword").val();
    var NewName = $("#NewName").val();
    var NewNickName = $("#NewNickName").val();
    var NewPhone = $("#NewPhone").val();
    var NewCountry = parseInt($("#NewCountry").val());
  // var NewAddress = $("#NewAddress").val();
    

    var AtPos = NewMail.indexOf("@");
    var StopPos = NewMail.lastIndexOf(".");

    document.getElementById("NewMailDiv").className = "inputArea";
    document.getElementById("NewPasswordDiv").className = "inputArea ";
    document.getElementById("NewNameDiv").className = "inputArea ";
    document.getElementById("NewNickDiv").className = "inputArea";
    document.getElementById("NewPhoneDiv").className = "inputArea";
    document.getElementById("NewCountryDiv").className = "inputArea";
   // document.getElementById("NoteAdvertise").className = "inputArea";

    var failure = "";
    if ((AtPos == -1 || StopPos == -1)) {
        document.getElementById("NewMailDiv").className = "inputArea  Required";
        failure = "1";

    }

    if (NewPassword == "") {
        document.getElementById("NewPasswordDiv").className = "inputArea Required";
        failure = "1";
    }
    if (NewName == "") {

        document.getElementById("NewNameDiv").className = "inputArea Required";
        failure = "1";
    }
    if (NewCountry == 0) {
        document.getElementById("NewCountryDiv").className = "inputArea Required";
        failure = "1";
    }


    if (failure == "") {
          $("#LoaderNew").show()
          $.ajax({
              url: url,
              type: 'POST',
              data: 'NewMail=' + NewMail + "&NewPassword=" + NewPassword + "&NewName=" + NewName + "&NewNickName=" + NewNickName + "&NewPhone=" + NewPhone + "&NewCountry=" + NewCountry, // + "&NewAddress=" + NewAddress,
              success: function (data) {

                  if (data == "3") {
                      $('#UserExist ').show();
                      setTimeout(function () {
                          $('#UserExist ').hide();
                      }, 3000);
                      $("#LoaderNew").hide()
                  }
                  else {
                      $("#LoaderNew").hide()

                      CloseNewReg();
                      updateLogArea(NewName);
                      setTimeout(function () {

                      }, 4000);
                      window.location = Mainroute + "/Home";
                      $(".RegisterForm")[0].reset();
                  }
              }
          });
    }

}




function loginWebUser() {
    $('#loginErrorMessage').hide();
    $('#loginErrorMessage').html('');
    if (isWebUserLoginValid() == 1) {
        $('#loginErrorMessage').hide();
        $('loginErrorMessage').html('');

            $('#loginloader').show();
            var Mainroute = document.getElementById("Mainroute").value;
            var url = Mainroute + "Home/loginWebUser";
            var data = collectLoginData();
            $.ajax({
                type: 'POST',
                data: data,
                url: url,
                success: function (response) {
                    $('#loginloader').hide();
                    $(".LoginForm")[0].reset();
                    if (response.indexOf('Error') < 0) {
                        user = jQuery.parseJSON(response).Ounousa.user[0];
                        $('#WebUser_SessionId').val(user.SessionId);
                        CloseLoginPop();

                        window.location = Mainroute +"/Home"
                    
                   //     updateUIAfterLogin();
                    } else {
                        var error = jQuery.parseJSON(response).Error;
                        $('#loginErrorMessage').html(error);
                        $('#loginErrorMessage').show();
                    }

                    
                }
            });
        
    }
}



function isWebUserLoginValid() {
    var returnVal = 1;
    var Password = $("#PasswordLog").val()
    var email = $("#NameLog").val()
    var AtPos = email.indexOf("@");
    var StopPos = email.lastIndexOf(".");

    if ($("#PasswordLog").val() == "") {
        document.getElementById("UserPasswordLog").className = "inputArea Required";
        returnVal = 0;
    } else {
        document.getElementById("UserPasswordLog").className = "inputArea ";
    }

    if ((AtPos == -1 || StopPos == -1)) {
        document.getElementById("UserNameLog").className = "inputArea Required";
        returnVal = 0;
    } else {
        document.getElementById("UserNameLog").className = "inputArea";
    }



    return returnVal;
}


function collectLoginData() {
    var email = $("#NameLog").val();
    var password = $("#PasswordLog").val();

    return 'email=' + email
        + '&password=' + password
        + '&rnd=' + getRandom();
}


function getRandom() {
    return Math.random();
}


function updateLogArea(Name) {

    $("#LoginDiv").hide();
    $("#NewuserDiv").hide();

    $("#WelcomeName").html("");
    $("#WelcomeName").html(" أهلاً " + Name);
    $("#welcomeDiv").show();

}


function logoutWebUser() {
        var Mainroute = document.getElementById("Mainroute").value;
        var url = Mainroute + "home/logoutWebUser";
     //   $('#header .loader').show();
        $.ajax({
            url: url,
            success: function (response) {
                user = null;
                //   $('#header .loader').hide();
                updateUIAfterLogout();
                window.location = Mainroute + "/Home";
            }
        });
    
}


function loginFBCallback(response) {
    FB_INITIALIZED = true;
    user = jQuery.parseJSON(response).Facebook.user[0];
    //   $('#WebUser_SessionId').val(user.SessionId);
    //    alert('Welcome ' + user.Email);
    //   $('#facebook_login .loader').hide();
    CloseLoginPop();

    //updateUI
    updateUIAfterLogin();
}


function logoutFBCallback(response) {
    user = null;
    //updateUI
    FB_INITIALIZED = false;
    updateUIAfterLogout();
}




function updateUIAfterLogin() {
    $("#LoginDiv").hide();
    $("#NewuserDiv").hide();

    $("#WelcomeName").html("");
    $("#WelcomeName").html(" أهلاً " + user.FirstName);
    $("#welcomeDiv").show();

}


function updateUIAfterLogout() {

    $("#LoginDiv").show();
    $("#NewuserDiv").show();

    $("#WelcomeName").html("");
    $("#welcomeDiv").hide();


}

function FtrRemove() {

    var width = $(window).width();
    if (width <= 995) {
        $('#RemoveB').hide();
    }

    else {
        $('#RemoveB').show();
    }

}


function RemoveFooterBAnner() {

    $("#FooterBanner").hide();

}

function runScript(e) {
    if (e.keyCode == 13) {
        document.SearchForm.submit();
        return false;
    }
}


function RunSerach() {

    document.SearchForm.submit();
}

function SetVotes(object , RateId , ArticleId) {

    $(object).prevAll().andSelf().addClass('selected');
    $(object).nextAll().removeClass('selected');
    var userId = $("#WebUser_UserId").val();
    var url = Mainroute + "home/Rating";

//    $.ajax({
//        url: url,
//        type: 'POST',
//        data: 'RateId=' + RateId + "&ArticleId=" + ArticleId + "&userId=" + userId,
//        success: function (data) {


//        }
//    });
}


function SetFbCount() {
    var ArticleId = $("#ArtId").val();
    var CommmentCount = $("#CommentCout").val();

    var Mainroute = document.getElementById("Mainroute").value;
    var url = Mainroute + "home/SetComment";

    $.ajax({
        url: url,
        type: 'POST',
        data: 'ArticleId=' + ArticleId + "&CommmentCount=" + CommmentCount,
        success: function (data) {

            return '1';
        }
    });

}

function toScroll() {
    setTimeout(function () {
        var CalWidth = $('#GivenWidth').val();
        var jspDragW = $('.jspDrag').width();
        var LeftJspane = 677 - CalWidth;
        var LeftJspDrag = 677 - jspDragW;

        $('.jspPane').css('left', LeftJspane + "px");
        $('.jspDrag').css('left', LeftJspDrag +"px");

    }, 2000);

}

function AnimateFooter() {

    if ($('.FixedFooter').height() == 45) {
        $('#animate_footer').animate({ height: "0" }, 1000, "easeOutQuint", function () {
            $('#animate_footer').css('background-position', '16px 16px');
            $('.FixedFooter').animate({ height: "2px" }, 1000, "easeOutQuint", function () {
                $('#animate_footer').animate({ height: "16px" }, 1000, "easeOutQuint");
                $('.FooterLinks').hide();
                $('.FooterMail').hide();
                $('.FooterChat').hide();
                $('.FooterRss').hide();

            });
        });

    }
    else {
        $('#animate_footer').animate({ height: "0" }, 1000, "easeOutQuint", function () {
            $('#animate_footer').css('background-position', '16px 0');
            $('.FooterLinks').show();
            $('.FooterMail').show();
            $('.FooterChat').show();
            $('.FooterRss').show();
            $('.FixedFooter').animate({ height: "45px" }, 1000, "easeOutQuint", function () {
                $('#animate_footer').animate({ height: "16px" }, 1000, "easeOutQuint");

            });
        });
    
    }

}

function ResizeLink() {
    if ($('#ResizeBanner').css('position') == "fixed") {
        if ($(window).scrollTop() != 0) {
            $('.TopResizeBanner').hide();
        }
        else {
            $('.TopResizeBanner').show();
        }

    }

    if ($('#BgBanner').css('position') == "fixed") {
        if ($(window).scrollTop() != 0) {
            $('.TopBigBanner').hide();
        }
        else {
            $('.TopBigBanner').show();
        }

    }


};
