function AddToBookmark(userName, currentLocation,localSiteUrl, bookmarkMsgTrue, bookmarkMsgFalse) {
    $.ajax({
        type: "POST",
        url: "/_vti_bin/SyngentaFranceWebService.asmx/AddToBookmarkList",
        data: "{'userName':'" + userName + "','currentLocation':'" + currentLocation + "','localSiteUrl':'" + localSiteUrl +"'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: false,
        success: function(msg) {
            if (msg.d == true) {
                document.getElementById("blackDiv").style.display = "block";
                document.getElementById("popupDiv").style.display = "block";
                document.getElementById("tdMsg").innerHTML = bookmarkMsgTrue;
            }
            else {
                document.getElementById("blackDiv").style.display = "block";
                document.getElementById("popupDiv").style.display = "block";
                document.getElementById("tdMsg").innerHTML = bookmarkMsgFalse;
            }
        },
        error: function(msg) {
            alert(msg.d);
        }
    });
}
function hideMsgDivs() {
    document.getElementById("blackDiv").style.display = "none";
    document.getElementById("popupDiv").style.display = "none";
}



var errorProblemLodingHDImage = "";
var errorProblemLodingMSImage = "";


/* This function is responsible for providing zooming to an image */
function imageZoom(img_name, currentLocation) {
    //set the z - index of menu
    $("#header #headerBottom UL#topNav").css("z-index", 10);
    
    //To include copyright info... If avaiable with every image in future, need to fetch the same through webservice

    var _copyright = "";

    //default values
    var _width = 500;
    var _height = 500;
    var _msImagePath = '';
    var _hdImagePath = '';
    var _imageTitle = '';
    
    /* It fetches image Metadata (height and width) using web service calls */
    $.ajax({
        type: "POST",
        url: "/_vti_bin/SyngentaFranceWebService.asmx/GetImageMetadata",
        data: "{'name':'" + img_name + "','currentLocation':'" + currentLocation + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: false,
        success: function(msg) {
            msg = msg.d;
            var elem = msg.split(',');
            //alert(elem[0]);
            if (elem[0] != 0) {
                _height = elem[0];
            }
            if (elem[1] != 0) {
                _width = elem[1];
            }
            if (elem[2] != '') {
                _copyright = elem[2];
            }            

        },
        error: function(msg) {
        alert(msg.responseText + "probleme");
        }
    });

    //return;

    /* Image URLs (for Medium sized and HD images) are fetched and integrated with jqZoom */
    $.ajax({
        type: "POST",
        url: "/_vti_bin/SyngentaFranceWebService.asmx/GetMSImage",
        data: "{'name':'" + img_name + "','currentLocation':'" + currentLocation + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: false,
        success: function(msg) {
            //alert(msg.d);
             msg = msg.d;
             var elem = msg.split(';');
             if (elem[0] != '') {
                 _msImagePath = elem[0];
             }
             if (elem[1] != '') {
                 _imageTitle = elem[1];
             }            
            
        },
        error: function(msg) {        
            alert(msg.responseText + "probleme");
        }
    });

    if (_msImagePath == "") {       
      return;
    }

    $.ajax({
        type: "POST",
        url: "/_vti_bin/SyngentaFranceWebService.asmx/GetHDImage",
        data: "{'name':'" + img_name + "','currentLocation':'" + currentLocation + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: false,
        success: function(msg) {
            msg = msg.d;
            _hdImagePath = msg;

        },
        error: function(msg) {
            alert(msg.responseText + "probleme");
        }
    });

    
//    if (_hdImagePath == "") {
//        /* If zoomed image is not avaiable, only medium sized version of the image is shown */
//        get_MediumImage(img_name, _width + 50, _height + 100);
//    }
//    else {
        var insertDiv = '<div class="backScreen" style="display: none"></div>' + '<div class="div_img" style="display: none;"></div>' +
                                         '<div class="div_img_maxi" style="display: none;"></div>' + '<input type="hidden" class="input_img_maxi" style="display: none;"/>';
        $(".OuterDiv").html(insertDiv);
        //to change: magnifying image
        $(".div_img_maxi").html("<div id=\"div_img_maxi_" + img_name + "\" ><table><tr><td><img style=\"padding:3px;vertical-align:middle;\" src=\"/_LAYOUTS/InternetPlatformComponents/Images/loupe.png\"/>Pour zoomer passez votre souris sur l'image<div class=\"modalCloseImg\" onclick=\"hideMaxiZoom(\'" + img_name + "\');\"></div></td><tr><tr><td><a href=\"" + _hdImagePath + "\" class=\"jqzoom" + "" + "\"><img src=\"" + _msImagePath + "\"/></a></td></tr><tr><td style='text-align:center;'><span style=\"width:" + _width + "px;text-align:left; \">" + _imageTitle + "</span></td></tr><tr><td style='text-align:center;'><span style=\"width:" + _width + "px;text-align:center; \">" + _copyright + "</span></td></tr></table>");

            //alert($(".input_img_maxi").val());
            if ($(".input_img_maxi").val().indexOf("," + img_name + ",") == -1) {
                $(".input_img_maxi").val($(".input_img_maxi").val() + "," + img_name + ",")

                $(".div_img_maxi").css("position", "fixed");
                $(".div_img_maxi").css("margin", "0px");
                $(".div_img_maxi").css("padding", "0px");
                $(".div_img_maxi").css("z-index", "50");
                $(".div_img_maxi").css("background-color", "white");
                $(".div_img_maxi").css("margin-left", "-" + _width / 2 - 140 + "px");
                $(".div_img_maxi").css("margin-top", "-" + _height / 2 - 40 + "px");
                $(".div_img_maxi").css("left", "50%");
                $(".div_img_maxi").css("top", "50%");

                $(".div_img_maxi").show();
                $(".div_img_maxi_" + img_name).show();
                $(".backScreen").show();
                $(".OuterDiv").show();
                }
            else {
                $(".div_img_maxi").show();
                $(".div_img_maxi_" + img_name).show();
                $(".backScreen").show();
                $(".OuterDiv").show();
            }


            $(".jqzoom").jqzoom({
                zoomWidth: 300,
                zoomHeight: 450,
                xOffset: 10,
                yOffset: 0,
                position: "right",
                title: false
            });


        //}

}


function get_MediumImage(img_name, _width, _height) {

    //To include copyright info... If avaiable with every image in future, need to fetch the same through webservice
    var copyright = "";
    $.ajax({
        type: "POST",
        url: "/_vti_bin/SyngentaFranceWebService.asmx/GetMSImage",
        data: "{'name':'" + img_name + "','currentLocation':'" + currentLocation + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: false,
        success: function(msg) {
            msg = msg.d;
            $(".div_img").html("<div class=\"modalCloseImg\" onclick=\"hideZoom();\"></div><img border=\"0\" style=\"border: 3px solid #ccc;\" src=\"" + msg + "\"/><br/><div style='width:" + (_width - 50) + "px;text-align:center;'>" + copyright + "</div>");

            $(".div_img").css("position", "fixed");
            $(".div_img").css("margin", "0px");
            $(".div_img").css("padding", "0px");
            $(".div_img").css("left", "50%");
            $(".div_img").css("top", "50%");
            $(".div_img").css("z-index", "50");
            $(".div_img").css("background-color", "white");
            $(".div_img").css("margin-left", -((_width - 50) / 2) + 15);
            $(".div_img").css("margin-top", -((_height - 100) / 2));

            $(".div_img").show();
            $(".backScreen").show();

        },
        error: function(msg) {
            alert(msg.responseText + "probleme");
        }
    });

}


function hideMaxiZoom(img_name) {
    $(".div_img_maxi_" + img_name).hide();
    $(".div_img_maxi").hide();
    $(".backScreen").hide();
    $(".OuterDiv").hide();
    $("#header #headerBottom UL#topNav").css("z-index", 10008);

}

function hideZoom() {
    $(".div_img").hide();
    $(".backScreen").hide();
}

/*function responsible for showing zoomed image in carousel; it also provides scrolling facility*/
function carousel_zoom(id_carrousel, img_name, current_index, currentLocation) {
    $("#header #headerBottom UL#topNav").css("z-index", 10);
    var insertDiv = '<div class="backScreen" style="display: none"></div>' + '<div class="div_img" style="display: none;"></div>' +
                                         '<div class="div_img_maxi" style="display: none;"></div>' + '<input type="hidden" class="input_img_maxi" style="display: none;"/>';
    $(".OuterDiv").html(insertDiv);
   
    $(".input_img_maxi").val('');
    $(".div_img_maxi").html('');
        
    var _width = 0;
    var _height = 0;    
    var _current_max_index = 0;
    var _previousImgName = "";
    var _nextImgName = "";
    var _msImagePath = '';
    var _hdImagePath = '';
    var prev_index = 0;
    var next_index = 0;
    var _imageTitle = '';
    

    //To include copyright info... If avaiable with every image in future, need to fetch the same through webservice

    var _copyright = "";
    _copyright = document.getElementById('hdnCopyright').value;

    //Setting Global error variable
    errorProblemLodingHDImage = document.getElementById('hdnErrorHDImage').value;
    errorProblemLodingMSImage = document.getElementById('hdnErrorMSImage').value;
    
    //Fetching metadata related to selected image and image carousel
    $.ajax({
        type: "POST",
        url: "/_vti_bin/SyngentaFranceWebService.asmx/getMaxiCarrousel", //to be replaced with original names
        data: "{'carouselId':'" + id_carrousel + "','sequenceNo':'" + current_index + "','currentLocation':'" + currentLocation + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: false,
        success: function(msg) {
            msg = msg.d;           
            var elem = msg.split(';');
            _height = elem[0];
            _width = elem[1];            
            _current_max_index = elem[2];
            _previousImgName = elem[3];
            _nextImgName = elem[4];         
            prev_index = current_index - 1;
            next_index = current_index + 1;          
            
        },
        error: function(msg) {
            alert(msg.responseText + "probleme");
        }

    });
    
   
    /* Image URLs (for Medium sized and HD images) are fetched and integrated with jqZoom */
    $.ajax({
        type: "POST",
        url: "/_vti_bin/SyngentaFranceWebService.asmx/GetMSImage",
        data: "{'name':'" + img_name + "','currentLocation':'" + currentLocation + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: false,
        success: function(msg) {
            //alert(msg.d);
            msg = msg.d;
            var elem = msg.split(';');
            if (elem[0] != '') {
                _msImagePath = elem[0];
            }
            if (elem[1] != '') {
                _imageTitle = elem[1];
            }
        },
        error: function(msg) {
            alert('b');
            alert(msg.responseText + "probleme");
        }
    });


    $.ajax({
        type: "POST",
        url: "/_vti_bin/SyngentaFranceWebService.asmx/GetHDImage",
        data: "{'name':'" + img_name + "','currentLocation':'" + currentLocation + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: false,
        success: function(msg) {
            msg = msg.d;
            _hdImagePath = msg;

        },
        error: function(msg) {

            alert(msg.responseText + "probleme");
        }
    });
    
    
                    if ($(".input_img_maxi").val().indexOf("," + img_name + ",") == -1) {

                        $(".input_img_maxi").val($(".input_img_maxi").val() + "," + img_name + ",");

                        //to change: image location
                        var left_arrow = "<img border='0' onclick=\"carousel_zoom('" + id_carrousel + "','" + _previousImgName + "'," + prev_index + ",'" + currentLocation + "');\" src='/_LAYOUTS/InternetPlatformComponents/Images/carrou_left.png' style='cursor:pointer;padding-right:3px;'>";

                        if (current_index == 1) {
                            left_arrow = "";
                        }

                        var carrou_index = current_index + "/" + _current_max_index;

                        var right_arrow = "<img border='0' onclick=\"carousel_zoom('" + id_carrousel + "','" + _nextImgName + "'," + next_index + ",'" + currentLocation + "');\" src='/_LAYOUTS/InternetPlatformComponents/Images/carrou_right.png' style='cursor:pointer;padding-left:3px;'>";

                        if (current_index == _current_max_index) {
                            right_arrow = "";
                        }


                        var _html = "";


                        _html = _html + "<div id=\"div_img_maxi_" + img_name + "\">"
                        _html = _html + "<table><tr><td>";
                        _html = _html + "<table width='" + _width + "' cellpadding='0' cellspacing='0' border='0'><tr><td>";

                        if (_hdImagePath != "") {
                            _html = _html + "<img style='padding:3px;vertical-align:middle;' src='/_LAYOUTS/InternetPlatformComponents/Images/loupe.png'/>Pour zoomer passez votre souris sur l'image";
                        }
                        else {
                            _html = _html + "<img style='padding:3px;vertical-align:middle;' src='/_LAYOUTS/InternetPlatformComponents/Images/loupe.png'/>";
                        }

                        _html = _html + "</td><td style='vertical-align:bottom;text-align:right;'>";
                        _html = _html + "<span style='padding-right:20px;'><b>" + left_arrow + carrou_index + right_arrow + "</b></span>";
                        _html = _html + "</td></tr></table>";
                        _html = _html + "</td></tr><tr><td>";
                        _html = _html + "<div class=\"modalCloseImg\" onclick=\"hideMaxiZoom('" + img_name + "');\"></div>";


                        _html = _html + "<a href=\"" + _hdImagePath + "\" class=\"jqzoom\"><img src='" + _msImagePath + "' border='0' /></a>";

                        _html = _html + "</td></tr><tr><td>";
                        _html = _html + "<table width='" + _width + "'  cellpadding='0' cellspacing='0' border='0'><tr><td style='padding-left:3px;padding-top:8px;'>" + left_arrow + "</td>";
                        _html = _html + "<td style='text-align:center; width:100%;padding-top:4px; padding-bottom:4px;'>" + "<b>" + carrou_index + " - </b>" + _imageTitle + "&nbsp;</td>";
                        _html = _html + "<td style='padding-right:3px;padding-top:8px;'>" + right_arrow + "</td></tr>";
                        _html = _html + "<tr><td colspan='4' style='text-align:center;'><span style=\"width:" + _width + "px;text-align:center; \">" + _copyright + "</span></td></tr></table>";
                        _html = _html + "</td></tr></table>";
                        _html = _html + "</div>";
                        $(".div_img_maxi").html(_html);

                        $(".div_img_maxi").css("position", "fixed");
                        $(".div_img_maxi").css("margin", "0px");
                        $(".div_img_maxi").css("padding", "0px");
                        $(".div_img_maxi").css("z-index", "50");
                        $(".div_img_maxi").css("background-color", "white");
                        $(".div_img_maxi").css("margin-left", "-" + _width / 2 - 140 + "px");
                        $(".div_img_maxi").css("margin-top", "-" + _height / 2 - 40 + "px");
                        $(".div_img_maxi").css("left", "50%");
                        $(".div_img_maxi").css("top", "50%");



                        $(".div_img_maxi").show();
                        $(".div_img_maxi_" + img_name).show();
                        $(".backScreen").show();
                        $(".OuterDiv").show();

                        $(".jqzoom").jqzoom({
                            zoomWidth: 300,
                            zoomHeight: 450,
                            xOffset: 10,
                            yOffset: 0,
                            position: "right",
                            title: false
                        });

                    }
                    else {                        
                        $(".div_img_maxi").show();
                        $(".div_img_maxi_" + id_img).show();
                        $(".backScreen").show();
                        $(".OuterDiv").show();
                    }

               if (_msImagePath == "") {
                   alert(errorProblemLodingMSImage);

               }
               else if (_hdImagePath == "") {
                   alert(errorProblemLodingHDImage);
               }                 
                    
               
}


function carousel_right(id) {
    //get the width of the items 
    var item_width = $("#" + id + " li").outerWidth() + 10;

    //calculae the new left indent of the unordered list
    var left_indent = parseInt($("#" + id).css('left')) - item_width;

    //make the sliding effect using jquery's anumate function '
    $("#" + id + ":not(:animated)").animate({ 'left': left_indent }, 500, function() {

        //get the first list item and put it after the last list item (that's how the infinite effects is made) '
        $("#" + id + " li:last").after($("#" + id + " li:first"));

        //and get the left indent to the default -210px
        //        $("#" + id).css({ 'left': '-135px' });
        $("#" + id).css({ 'left': '-105px' });
    });
}

function carousel_left(id) {
    var item_width = $("#" + id + " li").outerWidth() + 10;

    /* same as for sliding right except that it's current left indent + the item width (for the sliding right it's - item_width) */
    var left_indent = parseInt($("#" + id).css('left')) + item_width;

    $("#" + id + ":not(:animated)").animate({ 'left': left_indent }, 500, function() {

        /* when sliding to left we are moving the last item before the first list item */
        $("#" + id + " li:first").before($("#" + id + " li:last"));

        /* and again, when we make that change we are setting the left indent of our unordered list to the default -210px */
        //$("#" + id).css({ 'left': '-135px' });
        $("#" + id).css({ 'left': '-105px' });
    });
}


//var addthis_config =
//{
//    data_ga_property: "UA-10673794-1",
//    data_track_clickback: true,
//    ui_click: true
//};

function validatorWP(obj1, obj2, msg1, msg2) {    
    var val1 = document.getElementById(obj1).value;
    var val2 = document.getElementById(obj2).value;

    if (val1 == "") {
        alert(msg1);
        return false;
    }
    if (val2 == "") {
        alert(msg2);
        return false;
    }
}
