﻿
// Funktion för att välja datum
function BuildTheDatePicker() {
	$(".datepicker_selector").datepicker({
		dateFormat: 'yy-mm-dd',
		firstDay: 1,
		dayNames: ['Söndag', 'Måndag', 'Tisdag', 'Onsdag', 'Torsdag', 'Fredag', 'Lördag'],
		dayNamesMin: ['Sö', 'Må', 'Ti', 'On', 'To', 'Fr', 'Lö'],
		monthNames: ['Januari', 'Februari', 'Mars', 'April', 'Maj', 'Juni', 'Juli', 'Augusti', 'September', 'Oktober', 'November', 'December'],
		monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'Maj', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec']
	});
}

// Kör genom generella funktioner när sidan är klar
$(document).ready(function () {
    try {
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
    } catch (err) { }

    function EndRequestHandler(sender, args) {
        BuildTheDatePicker();
    }

    BuildTheDatePicker();
    //highlightLastLI();
    //startJQueryFunctions();
});


if (document.addEventListener) { // DOM
	window.addEventListener("load", startJQueryFunctions, false);
} else if (window.attachEvent) { // ie specific
	window.attachEvent("onload", startJQueryFunctions);
}



//function NotImplemented() {
//    alert('Inte implementerad än');
//    return false;
//}

//// funktion för sortering av tabeller
//function SortMyTable() {
//    $(".tablesorter").tablesorter(
//                {
//                    cssAsc: "headerSortDown",
//                    cssDesc: "headerSortUp",
//                    headerSortUp: "header",
//                    widgets: ['zebra']
//                }
//            );
//}

//// Funktion för att välja datum
//function BuildTheDatePicker() {
//    $(".datepicker_selector").datepicker({
//        dateFormat: 'yy-mm-dd',
//        firstDay: 1,
//        dayNames: ['Söndag', 'Måndag', 'Tisdag', 'Onsdag', 'Torsdag', 'Fredag', 'Lördag'],
//        dayNamesMin: ['Sö', 'Må', 'Ti', 'On', 'To', 'Fr', 'Lö'],
//        monthNames: ['Januari', 'Februari', 'Mars', 'April', 'Maj', 'Juni', 'Juli', 'Augusti', 'September', 'Oktober', 'November', 'December'],
//        monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'Maj', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec']
//    });
//}


//function ArticleSearch() {
//    var data = "";
//    $.ajax({ type: "POST", url: "/Pages/Helpers/ArticleFilter.aspx/LoadData", data: "{}", contentType: "application/json; charset=utf-8",
//        dataType: "json", success: function (msg) {
//            data = msg.d.split(";"); $(".article_search_box").autocomplete(data, { matchContains: true, minChars: 1 });
//        }
//    });
//}


//// Kör genom generella funktioner när sidan är klar
//$(document).ready(function () {
//    try {
//        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
//    } catch (err) { }

//    function EndRequestHandler(sender, args) {
//        BuildTheDatePicker();
//        SortMyTable();
//        ArticleSearch();
//    }

//    BuildTheDatePicker();
//    SortMyTable();
//    ArticleSearch();

//}); 

//Snurra
//jQuery(document).ready(function () {
//    jQuery('#mycarousel').jcarousel({
//        //    btnNext: ".next",
//        //    btnPrev: ".prev",
//        visible: 4,
//        wrap: 'circular',
//            scroll: 1,
//        itemFirstInCallback: firstInCallbackFunction,
//        itemFirstOutCallback: firstOutCallbackFunction,
//        itemLastInCallback: lastInCallbackFunction,
//        itemLastOutCallback: lastOutCallbackFunction
//    });
//});


//function firstInCallbackFunction(jcarousel_object, li_object, index, state) {
//    $(li_object).removeClass('Box');
//    $(li_object).addClass('BoxFirst');
//}
//function firstOutCallbackFunction(jcarousel_object, li_object, index, state) {
//    $(li_object).removeClass('BoxFirst');
//    $(li_object).addClass('Box');
//}

//function lastInCallbackFunction(jcarousel_object, li_object, index, state) {
//    $(li_object).removeClass('Box');
//    $(li_object).addClass('BoxLast');
//}
//function lastOutCallbackFunction(jcarousel_object, li_object, index, state) {
//    $(li_object).removeClass('BoxLast');
//    $(li_object).addClass('Box');
//}


/*FLYTTA TILL EN EGEN FIL SENARE*/
/*Tänder och släcker orange inforuta när man hovrar över info-bilden*/
/*startJQueryFunctions ANVÄNDS INTE LÄNGRE*/
function startJQueryFunctions() {
    //jQuery(".infonote").css({ "background-color": "green" });

    $('.infotrigger').mouseover(function () {
        //alert($(this).attr('rel'));
        jQuery($(this).attr('name')).css({ "display": "block" });
    }).mouseout(function () {
        jQuery($(this).attr('name')).css({ "display": "none" });
    });
}



//$(".skekraft tr th img.testBild").qtip({
//    content: 'Presets, presets and more presets. Let\'s spice it up a little with our own style!',
//    style: {
//        width: 200,
//        padding: 5,
//        background: '#A2D959',
//        color: 'black',
//        textAlign: 'center',
//        border: {
//            width: 7,
//            radius: 5,
//            color: '#A2D959'
//        },
//        tip: 'bottomLeft',
//        name: 'dark' // Inherit the rest of the attributes from the preset dark style
//    }
//});


/*Orange "popup" när man hovrar över info bilder*/
/************************************************/
//Style for all the tooltips
//$.fn.qtip.styles.mystyle = { // Last part is the name of the style
//    width: 500,
//    fontSize: '12px',
//    'font-family': '"verdana", "arial", "sans-serif"',
//    padding: 5,
//    background: '#F1B434',
//    color: 'black',
//    textAlign: 'center',
//    border: {
//        width: 7,
//        radius: 5,
//        color: '#F1B434'
//    },
//    
//   tip: true,
//   name: 'dark' // Inherit the rest of the attributes from the preset dark style
//}

// A shared object containing all the values you want shared between your tooltips
var shared = {
    position: {
        corner: {
                    target: 'topRight',
                    tooltip: 'bottomLeft'
                },
                adjust: {
                    y: -15, //Orange box position i höjdled
                    x: 4 //Orange box position i sidled
                }
              },
              show: { event: 'click mouseenter' },
              style: { 
                  width: 500,
                  fontSize: '12px',
                  'font-family': '"verdana", "arial", "sans-serif"',
                  padding: 5,
                  background: '#F1B434',
                  color: 'black',
                  textAlign: 'center',
                  border: {
                      width: 7,
                      radius: 5,
                      color: '#F1B434'
                  },

                  tip: true,
                  name: 'dark' // Inherit the rest of the attributes from the preset dark style
              }
              //'mystyle'
   
             };

$(document).ready(function () {
    $('.onmouse_infoImageDescription').qtip($.extend({}, shared, {
        content: {
            text: 'Beskriver typ av kostnad - t.ex. kostnad som beror på hur mycket du förbrukar eller fasta kostnader.'
        }
        
    }));
});

$(document).ready(function () {
    $('.onmouse_infoImageCost').qtip($.extend({}, shared, {
        content: {
            text: 'Här summeras kostnaderna för nedanstående avtal som gäller just nu, uppdelat på de olika kostnadstyperna'
         }
    }));
});

$(document).ready(function () {
    $('.onmouse_infoImageAgreementId').qtip($.extend({}, shared, {
        content: {
            text: 'Skellefteå Krafts avtalsnummer på det avtal som vi fakturerar dig.'
        }
    }));
});

$(document).ready(function () {
    $('.onmouse_infoImageStatisticsType').qtip($.extend({}, shared, {
        content: {
            text: 'Filtrera sökningen på statistiktyp, Energiförbrukning eller Effekt.'
        }
    }));
});

$(document).ready(function () {
    $('.onmouse_infoImageElectricityStatisticsFilterBar').qtip($.extend({}, shared, {
        content: {
            text: 'Hämta värden för utvalda år.'
        }
    }));
});

$(document).ready(function () {
    $('.onmouse_infoImageElectricityFilterList').qtip($.extend({}, shared, {
        content: {
            text: 'Filtrera avlästa värden efter datum.'
        }
    }));
});
//$(document).ready(function () {
//    $('.onmouse_infoImage').qtip({
//        content: {
//            text: '(*) Här summeras de olika kostnaderna för nedanstående avtal som gäller nu, uppdelat' +
//        ' på förbrukningsrelaterade och fasta kostnader.'
//    //text: false
//        },
//        position: {
//        corner: {
//        target: 'topRight',
//        tooltip: 'bottomLeft'
//        },
//    adjust: {
//        screen: true // Keep the tooltip on-screen at all times
//    }
//        },
//        show: {
//            event: 'click mouseenter'
//        },
//        style: 'mystyle' // The name of the newly created custom style above
//    });
//});
/************************************************/

//function highlightLastLI() {
//    var liList, ulTag, liTag;
//    var ulList = document.getElementsByTagName("ul");
//    for (var i = 0; i < ulList.length; i++) {
//        ulTag = ulList[i];
//        liList = ulTag.getElementsByTagName("li");
//        liTag = liList[liList.length - 1];
//        liTag.className = "myPagesDropdownLastchildImage";
//    }
//}

/*Lägger till en bild med rundade hörn längst ner i dropdownmenyn.*/
//function highlightLastLI() {
//    var liList, ulTag, liTag, addLiElementLast;
//    var ulList = $("ul.myPagesDropdownLI");
//    for (var i = 0; i < ulList.length; i++) {
//        ulTag = ulList[i];
//        addLiElementLast = document.createElement("li");
//        ulTag.appendChild(addLiElementLast);
//        liList = ulTag.getElementsByTagName("li");
//        liTag = liList[liList.length - 1];
//        liTag.className = "myPagesDropdownLastchildImage";
//    }
//}



//    if (navigator.userAgent.toLowerCase().match('chrome'))
//        document.write('<link rel="stylesheet" type="text/css" href="/Administration/Egna Stylesheet/CSSFiles/otherBrowsers.css">');
    


//////    function startJQueryFunctions() {
//////	//jQuery(".infonote").css({ "background-color": "green" });

//////    $(".infotrigger").mouseover(function () {
//////        //alert($(this).attr('rel'));
//////       jQuery($(this).attr('rel')).css({ "display": "block" });
//////    }).mouseout(function () {
//////       jQuery($(this).attr('rel')).css({ "display": "none" });
//////    }); 



	// js classes with different functions
	//jQuery(".js_vanish").css({ "display": "none" });
	
	//var btGo = document.getElementById('top1_Select_region___dropdown1_btGo');
	//btGo.style.display = 'none';

	//    window.countpopups = 0;
	//    jQuery(".js_popupwin").click(function () {
	//        var url = this.href;
	//        var winname = '';
	//        window.countpopups++;
	//        var winname = "win" + window.countpopups;
	//        var w = url.replace(/.*w=(\d+).*?$/, "$1") * 1;
	//        var h = url.replace(/.*h=(\d+).*?$/, "$1") * 1;
	//        if (url.match(/http:\/\/[\S]+?\.jpg/g) != null) {
	//            var img = new Image();
	//            img.src = url;
	//            w = img.width + 42;
	//            h = img.height + 32;
	//        }
	//        w = (typeof w == "number" && !isNaN(w)) ? w : 500;
	//        h = (typeof h == "number" && !isNaN(h)) ? h : 500;
	//        var popupWin = window.open(url, winname, 'menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,dependent=no,width=' + w + ',height=' + h + '');
	//        return false;
	//    });
	//    jQuery(".js_winx").click(function () {
	//        self.close();
	//    });
//jQuery(".js_selectbox").selectbox();




	/////jQuery(".myPagesDropdown").selectbox();
//////	jQuery(".myPagesDropdown").addClass("selectbox").css("opacity", "0");

	// plugins and functions for effects/animations enhancement	

	// plugin: show/hide , note: method findobj overrides property area
	/* html example: 
	<div class="js_shownext"><a href="#"></a></div>
	<div class="js_showhidearea"></div>
	(  class="open" is added to "a" tag if not overridden )
	js:
	jQuery(".js_shownext").showHide(); 
	*/
	//    jQuery.fn.showHide = function (opt) {
	//        opt = jQuery.extend({
	//            area: ".js_showhidearea",
	//            openselector: "a",
	//            openclass: "open",
	//            eventtype: "click",
	//            effect: "slide",
	//            defaultstate: { "display": "none" }, // css values
	//            findobj: function (obj) {
	//                return jQuery(obj).next(opt.area);
	//            }
	//        }, opt);
	//        opt.findobj(this).css(opt.defaultstate);
	//        return this.bind(opt.eventtype, function (e) {
	//            if (opt.effect == "slide") opt.findobj(this).slideToggle(300);
	//            else if (opt.effect == "none") opt.findobj(this).toggle();
	//            jQuery(this).children(opt.openselector).toggleClass(opt.openclass);
	//            jQuery(this).children("tr").children("td.first").children(opt.openselector).toggleClass(opt.openclass);
	//            // komatsu special:
	//            if ((jQuery(".js_showhideall").hasClass("buttoncollapsed") && jQuery(opt.area + ":hidden").size() == 0) ||
	//				(jQuery(".js_showhideall").hasClass("buttonopened") && jQuery(opt.area + ":visible").size() == 0))
	//                switchStateCollapse();
	//            return false;
	//        });
	//    };

	//    jQuery(".js_shownext").showHide();
	//    jQuery(".js_shownexttbody").showHide({
	//        "effect": "none",
	//        "findobj": function (obj) {
	//            return jQuery(obj).next("tbody.js_showhidearea");
	//        }
	//    });
	//    jQuery(".js_showhideall").click(function () {
	//        switchStateCollapse();
	//        return false;
	//    });
	//    var switchStateCollapse = function () {
	//        if (jQuery(".js_showhideall").hasClass("buttonopened")) {
	//            jQuery(".js_showhideall").removeClass("buttonopened").addClass("buttoncollapsed");
	//            jQuery(".js_showhidearea").hide();
	//            jQuery(".js_shownext a").removeClass("open");
	//            jQuery(".js_shownexttbody td.first a").removeClass("open");
	//        } else {
	//            jQuery(".js_showhideall").removeClass("buttoncollapsed").addClass("buttonopened");
	//            jQuery(".js_showhidearea").show();
	//            jQuery(".js_shownext a").addClass("open");
	//            jQuery(".js_shownexttbody td.first a").addClass("open");
	//        }
	//    }

	//    jQuery.fn.plugin = function (opt) {
	//        opt = jQuery.extend({
	//            forcealert: false,
	//            checknode: false
	//        }, opt);
	//        return this.each(function () {
	//            var info = jQuery.log.tagInfo(this, opt);
	//            if (opt.forcealert) {
	//                alert(info);
	//            } else {
	//                jQuery.echo(info);
	//            }
	//            if (opt.checknode) {
	//                jQuery(this).children("*").debug(opt); // jQuery.extend(opt,{ pad : " - "})
	//            }
	//        });
	//    };

	/*
	* jQuery selectbox plugin
	*
	* (c) 2008 Elin Tjerngren, artopod.se 
	* Licensed under the GPL license and MIT:
	*   http://www.opensource.org/licenses/GPL-license.php
	*   http://www.opensource.org/licenses/mit-license.php
	*
	* The code is inspired from Selectbox plugin by Sadri Sahraoui (http://brainfault.com)
	*
	*/
//////	jQuery.fn.extend({
//////		selectbox: function (options) {
//////			if (!(
//////			(jQuery.browser.opera && jQuery.browser.version < 9.25) ||
//////			(jQuery.browser.msie && jQuery.browser.version < 7)
//////			)) { // edit by elin: filter out old operas
//////				return this.each(function () {
//////					new jQuery.SelectBox(this, options);
//////				});
//////			}
//////		}
//////	});

//////	jQuery.SelectBox = function (selectobj, options) {
//////		var $ = jQuery;  // local fix by elin

//////		var opt = options || {};
//////		opt.selClass = opt.selClass || "selectbox";
//////		opt.selStartClass = opt.selStartClass || "selectbox-start";
//////		opt.containerClass = opt.containerClass || "selectbox-wrapper";

//////		var elm_id = selectobj.id;
//////		var active = -1;
//////		var inFocus = false;
//////		var hasfocus = 0;
//////		//jquery object for select element
//////		var $select = $(selectobj);
//////		var $styledSelect = setupStyledSelect();
//////		updateSelectValue();
//////		$select.change(updateSelectValue);

//////		function setupContainer(options) {
//////			var container = document.createElement("div");
//////			$container = $(container);
//////			//$container.attr('id', elm_id+'_container');
//////			$container.addClass(options.containerClass);

//////			return $container;
//////		}

//////		function setupStyledSelect() {
//////			var el = document.createElement("div");
//////			var $styledSelect = $(el);
//////			$styledSelect.addClass(opt.selClass);
//////			$styledSelect.width(selectobj.offsetWidth); // width of the actual selectbox 
//////			$select.wrap('<div class="' + opt.containerClass + '"></div>').before($styledSelect);
//////			$styledSelect.wrap('<div class="' + opt.selStartClass + '"></div>');
//////			return $styledSelect;
//////		}

//////		function updateSelectValue() {
//////			$styledSelect.html($select.children("option:selected").html());
//////		}
//////	};
//////}

	
	   
	
