﻿//$(document).ready(function () {
function ConfigureCMS() {
    //alert("inside cms.js");

    var cookieName = "language";
    var lang = $.cookie(cookieName);

    //Call ajax routine to change session var or simply set a cookie?
    //Requires jquery.cookie.js!
    $("a.lang_en").click(function () {
        if (lang != null && lang != "en") {
            $.cookie('language', null); //clear cookie
            $.cookie(cookieName, "en", { path: "/" });
            window.location.reload(true);
        }
    });

    $("a.lang_zh").click(function () {
        if (lang != "zh") {
            $.cookie('language', null);
            // @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
            $.cookie(cookieName, "zh", { path: "/" });
            window.location.reload(true);
        }
    });

    ConfigureContentRenderers();
    //alert("finished cms.js");
//});
}

//Configures content blocks - adds styles, click-thru link to CMS admin, etc.
function ConfigureContentRenderers() {
	var contents = $('.content');
	$('.content').each(function () {
		var ele = $(this);
		var editrights = (ele.attr('editrights') == 'True');
		if (editrights) {
			ele.addClass("contentEditable");
			ele.hover(
				function () { //.hover handlerIn
					//Add edit button
					var editButton = ele.find('.contentEdit').show();
					editButton.addClass("hand");
					editButton.unbind('click');
					editButton.click(function () {
						var url = ele.attr("url");
						window.open(url, null, "");
					});
					//Edit vs Preview mode styling
					var preview = ele.attr('preview') == 'True';
					if (preview)
						ele.addClass("previewContent");
					else
						ele.addClass("approvedContent");
				}, //end handlerIn
				function () { //.hover handlerOut
					var editButton = ele.find('.contentEdit').hide();
					ele.removeClass("approvedContent").removeClass("previewContent");
				}); //end handlerOut
		} //if editrights
	});
}

//NO LONGER USED?
//Configures content elements - adds styles, edit page link, etc.
//Parameters:
// - clientID: used for uniqueness across different .net WebControls in different partials/UserControls.
// - previewMode - boolean flag set by server-side UserControl
// - userName - admin login
function ContentManage(clientID, previewMode, hasAccess) {
	//alert(clientID + "," + previewMode + "," + hasAccess);
	if (!hasAccess) return;
	
	var content = $("#" + clientID); //outer content element(s)
	
	if (content) {
		content.addClass("hand");
		if (previewMode)
			content.addClass("previewContent");
		else {
			content.addClass("approvedContent");
			//alert("show approved only!");
		}

		content.each(function() {
			$(this).click(function() {
				var url = $(this).attr("url");
				window.location = url;
			});
		});
	}
}
