﻿/* General Javascript include */
/*
Images to publish:
/system_images/lt/topmenuleft_action_h.gif
/system_images/lt/topmenuleft_mobile_h.gif
/system_images/lt/topmenuleft_service_h.gif
/system_images/lt/topmenuleft_internet_h.gif
/system_images/lt/topmenuright_duk_h.gif
/system_images/lt/my_tele2_btn_h.gif
/system_images/eng/topmenuright_cs_h.gif
*/



$(document).ready(function() {


/*****************************/
/*START: Added for Footer Fix*/
/*****************************/
    var menuH = $('#sub_menu').height() + 130;
    var genericH = $('.generic').height();        // Generic templates
    var csH = $('.cs').height();                // Costumer support
    var contactH = $('.contact').height();        // Contact support
    var mobilefunH = $('.mobilefun').height();    // Mobile fun
    if (menuH > genericH) { $('.generic').css("height", menuH); $('.generic').css("min-height", menuH); }
    if (menuH > csH) { $('.cs').css("height", menuH); $('.cs').css("min-height", menuH); }
    if (menuH > contactH) { $('.contact').css("height", menuH); $('.contact').css("min-height", menuH); }
    if (menuH > mobilefunH) { $('.mobilefun').css("height", menuH); $('.mobilefun').css("min-height", menuH); }
/*****************************/
/*END: Added for Footer Fix*/
/*****************************/


    $("a.popup").click(function() { 
        window.open(this.href,this.href,'width=550,height=600,scrollbars=1,resizable=1');
        return false; 
    });
    
    $(".shop .fields .radio input").click(function() {
        $(".shop .fields .itemselected").attr("class","item");
        if($(this).is(":checked")) {
            $(this).parent().parent().attr("class","itemselected");
        }
    });
    
    
    $('#showTools').click( function() {
        $('#tools').toggle();
    });
    $('#showFaq').click( function() {
        $('#faq').toggle();
    });
    
    $(".header .main_navigation_right .closed .webmail").click(function() {
        $(".header .main_navigation_right .closed").hide();
        $(".header .main_navigation_right .open").show();
    });
    $(".header .main_navigation_right .open .webmail").click(function() {
        $(".header .main_navigation_right .open").hide();
        $(".header .main_navigation_right .closed").show();
    });
    $(".header .main_navigation_right .open .inputs .password").focus(function() {
        // Removed by SA/Addmind. Reason: IE gives error - Could not get the type property. This command is not supported.
        // $(this).attr("type","password").attr("value","");
        $(this).attr("value","");
    });
    $(".radiobox_options .select_button").click(function() {
        $(".radiobox_options .option_selected").attr("class","option");
        if($(this).is(":checked")) {
            $(this).parent().parent().attr("class","option_selected");
        }
    });
    
    $(".shop .shop_box .subscr_compare .selects input").click(function() {
        var col = $(this).attr("class");
        $(".shop .shop_box .subscr_compare table tbody .col").removeClass("active");
        $(".shop .shop_box .subscr_compare table tbody ." + col).addClass("active");
    });
    
    $(".shop .shop_box .subscr_compare .item_row").hover(function() {
        $(this).addClass("row_hover");
    }, function() {
        $(this).removeClass("row_hover");
    });
    
    $(".shop .shop_box .box_header a").click(function() {
        if($(this).is(".shop_expand")) {
            $(this).parent().parent().find(".box_contents").slideDown(200, function() {
                var set_back = $(this).parent().find(".shop_collapse").text();
                $(this).parent().find(".shop_collapse").text($(this).parent().find(".switch").text());
                $(this).parent().find(".switch").text(set_back);
            });
            $(this).attr("class","shop_collapse");
        }
        else if($(this).is(".shop_collapse")) {
            $(this).parent().parent().find(".box_contents").slideUp(200,function() {
                $(this).parent().find(".shop_collapse").attr("class","shop_expand");
                var set_back = $(this).parent().find(".shop_expand").text();
                $(this).parent().find(".shop_expand").text($(this).parent().find(".switch").text());
                $(this).parent().find(".switch").text(set_back);
            });
        }
    });
    $(".shop .shop_box_inline .box_inline_header a").click(function() {
        if($(this).is(".shop_inline_expand")) {
            $(this).parent().parent().find(".box_inline_contents .content_bottom").slideDown(200, function() {
                $(this).parent().parent().removeClass("collapsed");
                $(this).parent().parent().addClass("expanded");
            });
            $(this).attr("class","shop_inline_collapse");
        }
        else if($(this).is(".shop_inline_collapse")) {
            $(this).parent().parent().find(".box_inline_contents .content_bottom").slideUp(200, function() {
                $(this).parent().parent().removeClass("expanded");
                $(this).parent().parent().addClass("collapsed");
            });
            $(this).attr("class","shop_inline_expand");
        }
    });
    $(".tabs ul li a").click(function() {
        var view_this = $(this).attr("class");
        $(this).parent().parent().parent().parent().find(".tabs ul li").removeClass("selected");
        $(this).parent().addClass("selected");
    });
    
    $(".tab-changer ul li a").click(function() {
        var view_this = $(this).attr("class");
        $(this).parent().parent().parent().parent().find(".tab_wrapper").hide();
        $(this).parent().parent().parent().parent().find(".wrapper_" + view_this).show().addClass("active");
    });
    $(".tab-tracker ul li a").click(function() {
        var view_this = $(this).attr("class");
        $("#tab-target").attr("value", view_this);
    });
    
jQuery.fn.check = function(mode) {
   // if mode is undefined, use 'on' as default
   var mode = mode || 'on';
   
   return this.each(function() {
     switch(mode) {
       case 'on':
         this.checked = true;
         break;
       case 'off':
         this.checked = false;
         break;
       case 'toggle':
         this.checked = !this.checked;
         break;
     }
   });
 };
$(".id_form_overview_feature").click(function() {
    $(".id_form_overview_feature_all").check('off');
});
$(".id_form_overview_feature_all").click(function() {
    $(".id_form_overview_feature").check('off');
});
    $(".id_form_overview_feature_all").click(function() {
        $(".id_form_overview_feature").unCheckCheckboxes();
        $(this).check();
    });
    // Static function to change image on hover for item-icons in shopingflow.
    // Should be rebuilt to function completely  dynamic.
    $(".shop .row .item_specs img").hover(function() {
        var set_to = "system_images/icon_" + $(this).attr("class") + "_phone_hover.gif";
        $(this).attr("src",set_to);
        $(this).parent().parent().find(".item_info").text($(this).parent().find(".icon_info").html());
    }, function() {
        var set_to = "system_images/icon_" + $(this).attr("class") + "_phone.gif";
        $(this).attr("src",set_to);
        $(this).parent().parent().find(".item_info").text("");
    });
    $(".webmail_main .webmail_header .menu a:not(.active) img").hover(function() {
        var set_to = $(this).attr("src");
        set_to = set_to.substr(0,set_to.length-4) + "_hover.gif";
        $(this).attr("src",set_to);
    }, function() {
        var set_to = $(this).attr("src");
        set_to = set_to.substr(0,set_to.length-10) + ".gif";
        $(this).attr("src",set_to);
    });
    
    // OLD LINE: $(".main .main_left .header ul li a img").hover(function() {
    $(".main .main_left .header ul li a:not(.active) img").hover(function() {
        var set_to = $(this).attr("src");
        set_to = set_to.substr(0,set_to.length-4) + "_h.gif";
        $(this).attr("src",set_to);
    }, function() {
        var set_to = $(this).attr("src");
        set_to = set_to.substr(0,set_to.length-6) + ".gif";
        $(this).attr("src",set_to);
    });
    
    $(".webmail_main .webmail_header .navigation input.mail_search").focus(function() {
        $(this).attr("value","");
    });
    // Meny-hovering
    
    $("#sub_menu .item_mid").hover(function() {
        $(this).addClass("item_mid_hover");
    }, function() {
        $(this).removeClass("item_mid_hover");
    });
    
    $("#sub_menu .item_sub").hover(function() {
        $(this).addClass("item_sub_hover");
    }, function() {
        $(this).removeClass("item_sub_hover");
    });
    
    $("#sub_menu .item_first_selected").hover(function() {
        $(this).addClass("item_first_selected_hover");
    }, function() {
        $(this).removeClass("item_first_selected_hover");
    });
    
    $("#sub_menu .open").hover(function() {
        $(this).addClass("open_hover");
    }, function() {
        $(this).removeClass("open_hover");
    });
    
    $("#sub_menu .item_first").hover(function() {
        $(this).addClass("item_first_hover");
    }, function() {
        $(this).removeClass("item_first_hover");
    });
    
    $("#sub_menu .item_sub_last_selected").hover(function() {
        $(this).addClass("item_sub_last_selected_hover");
    }, function() {
        $(this).removeClass("item_sub_last_selected_hover");
    });
    
    $("#sub_menu .item_open").hover(function() {
        $(this).addClass("item_open_hover");
    }, function() {
        $(this).removeClass("item_open_hover");
    });
    $("#searchtele2form .input_text").focus(function() {
        if($(this).attr("value") == $(this).attr("id"))  {
            $(this).attr("value","");
        }
    });
    $("#searchtele2form .input_text").change(function() {
        if(!$(this).attr("value"))  {
            $(this).attr("value",$(this).attr("id"));
        }
    });
    
    $("#broadbandsearch").click(function() {
        $(this).attr("value", "");
    });
    /* $("#broadbandsearch").change(function() {
        if($(this).attr("value").length == 0 )  { 
            $(this).attr("value", "yes") 
        }
    }); */
    
    $("#clickbox .box_content").click(function() {
        document.location.href = $(this).find(".text a").attr("href");
    });
    $(".bot .photo a").click(function() {
        $("#mainproductimage").attr("src", $(this).attr("id"));
        $(".bot .photo a").removeClass("selected");
        $(this).addClass("selected");
    });
    $("#critical-alert-close").click(function(){
        $("#critical-alert").fadeOut("slow");
    });
});
 
function rowUp (class1){
    class2 = class1.className;
    if (class2 == 'ltTableB1 ltTableBf')
    { 
        class1.className = 'ltTableB3 ltTableBfUp'
    }
    else 
        if ((class2 == 'ltTableB1 ltTableB1l')||(class2 == 'ltTableB2 ltTableB2l'))
        {
            class1.className = 'ltTableB3 ltTableBlUp'
        }
        else 
        {
            class1.className = 'ltTableB3'
        }
}
function rowBack (class1){
    class1.className = class2;
}

function miestas (visi){
    var miestai = ['visimiestai', 'alytus', 'anyksciai', 'ariogala', 'birzai', 'druskininkai', 'elektrenai', 'gargzdai', 'ignalina', 'jonava', 'joniskis', 'jurbarkas', 'kedainiai', 'kaisiadorys', 'kaunas', 'kelme', 'klaipeda', 'kretinga', 'kupiskis', 'kursenai', 'lazdijai', 'marijampole', 'mazeikiai', 'moletai', 'naujojiakmene', 'pabrade', 'pakruojis', 'palanga', 'panevezys', 'pasvalys', 'plunge', 'prienai', 'radviliskis', 'raseiniai', 'rokiskis', 'skuodas', 'taurage', 'telsiai', 'trakai', 'ukmerge', 'utena', 'varena', 'vilkaviskis', 'vilnius', 'visaginas', 'zarasai', 'sakiai', 'salcininkai', 'siauliai', 'silale', 'silute', 'sirvintos', 'svencionys'];
    var kol = miestai.length;
    for (i = 1; i < kol; i++)
    {
        if (visi.value != 'visimiestai' )
            {
                if (visi.value == miestai[i])
                    {
                        document.getElementById(miestai[i]).style.display="block";
                    }
                    else
                    {
                        document.getElementById(miestai[i]).style.display="none";
                    }
            }
            else 
            {
                document.getElementById(miestai[i]).style.display="block";
            }
        
    }
}

function openWindow( url, name, param ) { sitemap = window.open(url, name, param); }
 
/************** window opener ***********************************************/
function popup(url,name,width,height) {
    var features = [
        ['toolbar',    0],
        ['directories',    0],
        ['menubar',    0],
        ['status',    0],
        ['resizable',    1],
        ['location',    0],
        ['scrollbars',    0],
        ['copyhistory',    0]
        ]
    for (var nr = 4; nr < popup.arguments.length; nr++) {
        var param = popup.arguments[nr].split('=')
        for (var i = 0; i < features.length; i++)
            if (features[i][0] == param[0]) {
                features[i][1] = param[1]
                break
                }
        if (i == features.length)
            features[i] = param
        }
    var featureString = 'width=' + width + ',height=' + height
    for (var i = 0; i < features.length; i++)
        featureString += ',' + features[i][0] + '=' + features[i][1]
    window.open(url,name,featureString)
    }

function popUp(way, winW, winH){
    var url = way;
    var width = winW;
    var height = winH;
    window.open(url, "_blank","toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=1, resizable=1, copyhistory=0, top=100, left=100, width="+width+", height="+height+"");
}

function dukClick(id){
    var block = document.getElementById(id);
    if (block.style.display == 'none') block.style.display = 'block';
    else block.style.display = 'none';
}

function dukClickOnce(id){
    var block = document.getElementById(id);
    block.style.display = 'block';
}
    
function dukShowHideAll(block_list, action){
    var count = block_list.length;
    var show = 'none';

    if (action == 1) show = 'block';
    if (action == 0) show = 'none';
        
    for(i = 0; i < count; i++){
        document.getElementById(block_list[i]).style.display = show;
    }
}

function dukShowHideArray(block_list){
    var count = block_list.length;
    var show = 'none';
    var block = document.getElementById(block_list[0]);
    
    if (block.style.display == 'none') show = 'block';
    if (block.style.display == 'block') show = 'none';

    for(i = 0; i < count; i++){
        document.getElementById(block_list[i]).style.display = show;
    }
}

function dukClickHref(array){
    if (array != ''){
        document.cookie = 'duk_block_active=' + array;
    }
}

function dukCheck(){
    duk_block_active = null;
    var cookie_pair = new Array();
    var cookie_list = document.cookie.split(';');
    var cookie_count = cookie_list.length;
        
    for (var i = 0; i < cookie_count; i++){
        cookie_pair = cookie_list[i].split('=');
        cookie_pair[0] = cookie_pair[0].replace(/\s+/i, '');
        if (cookie_pair[0] == 'duk_block_active'){
            duk_block_active = cookie_pair[1];
            break;
        }
    }
    
    if (duk_block_active){
        var dukOpenBlock = new Array();
        dukOpenBlock = duk_block_active.split(':');
        if (dukOpenBlock != 0){
            dukShowHideAll(dukOpenBlock, 1);
            document.cookie = 'duk_block_active='+0;
        }
    }
}

function getURLParam(strParamName){
    var strReturn = "";
    var strHref = window.location.href;
    if ( strHref.indexOf("?") > -1 ){
        var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
        var aQueryString = strQueryString.split("&");
        for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
            if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
                var aParam = aQueryString[iParam].split("=");
                strReturn = aParam[1];
                break;
            }
        }
    }
    return unescape(strReturn);
}

function select_filter(select, array_list){
    var kol = array_list.length;
    for (i = 1; i < kol; i++){
        if (select.value != 'all' ){
            if (select.value == array_list[i]){
                document.getElementById(array_list[i]).style.display="block";
            }else{
                document.getElementById(array_list[i]).style.display="none";
            }
        }else{
            document.getElementById(array_list[i]).style.display="block";
        }
    }
}

function openPopup( url, name ){
    var popupwindow = '';
    
    if( !popupwindow.closed && popupwindow.location ){
        popupwindow.location.href = url;
    }else{
        popupwindow = window.open( url, name, 'width=250,height=485,left=740,top=200,menubar=no,toolbar=no,location=no,scrollbars=no,alwaysRaised=yes,resizable=no');
        if( !popupwindow.opener )
            popupwindow.opener = self;
    }
        
    if( window.focus )
        popupwindow.focus();

    return false;
}

// --- functions to add a new plan to shoping cart --- /

function getPageSize(){
    
    var xScroll, yScroll;
    
    if (window.innerHeight && window.scrollMaxY) {    
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
    
    var windowWidth, windowHeight;
    if (self.innerHeight) {    // all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }    
    
    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight){
        pageHeight = windowHeight;
    } else { 
        pageHeight = yScroll;
    }
    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth){    
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }

    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
    return arrayPageSize;
}

/* To add plan to cart [old version] */

function addPlanToCart(plan, type, gcode)
{
    var width = 328;
    var height = 196;
    
    var newdiv = document.createElement('div');
    newdiv.setAttribute('id', 'PlanToCartDiv');
    newdiv.setAttribute('class', 'PlanToCartDiv');
    newdiv.className = 'PlanToCartDiv';
   
    newdiv.style.width = width;
    newdiv.style.height = height;
    
    // position ---
    
    WinSize = getPageSize();
    
    newdiv.style.left = (WinSize[2]/2) - (width/2)+'px';
    newdiv.style.top = (WinSize[3]/2) - (height/2)+'px';
    
    scroll(0,0);
    
    // ----
    
    var text = "Jūsų pasirinkta prekė sėkmingai įdėta į krepšelį.";
    var plan = plan;
    
    // ----
    
    var client_type = type;
    var to_cart = 'http://mob.tele2.lt/lt/krepselis_privatiems?step1';
    
    if (type == 2) to_cart = 'http://mob.tele2.lt/lt/krepselis_verslui?step1';
    
    // ----
    
    var url = 'http://mob.tele2.lt/lt/sim?add_cart_id=1&phone=Neįsigyjamas&plan='+plan+'&period=Neterminuota&price=-&group_id='+client_type+'&gcode='+gcode+'&subcost=0';
    newdiv.innerHTML = '<a href="javascript:PlanToCartDivHide();"><img align="right" class="PlanToCartClose" src="/images/PlanToCartDiv_close.gif" border="0" alt="Close" /></a><div class="PlanToCartClose_center"><br /><br /><img src="/images/PlanToCartDiv_center_img.gif" border="0" alt="" /><br /><br />'+text+'<br /><br /><a href="'+to_cart+'"><img src="/images/PlanToCartDiv_goto.gif" border="0" alt="" /></a></div><iframe height="0" width="0" src="'+url+'" frameborder="0"></iframe>';
    document.body.appendChild(newdiv);
    
    delete text;
    delete type;
    delete url;
    delete plan;
}

/* To add mobile internet product to cart */

function addPlanToCart_MI(prod_id, type)
{
    var width = 328;
    var height = 196;
    
    var newdiv = document.createElement('div');
    newdiv.setAttribute('id', 'PlanToCartDiv');
    newdiv.setAttribute('class', 'PlanToCartDiv');
    newdiv.className = 'PlanToCartDiv';
   
    newdiv.style.width = width;
    newdiv.style.height = height;
    
    // position ---
    
    WinSize = getPageSize();
    
    newdiv.style.left = (WinSize[2]/2) - (width/2)+'px';
    newdiv.style.top = (WinSize[3]/2) - (height/2)+'px';
    
    scroll(0,0);
    
    // ----
    
    var text = "Jūsų pasirinkta prekė sėkmingai įdėta į krepšelį.";
    var prod = prod_id;
    
    // ----
    
    var client_type = type;
    var to_cart = 'http://mob.tele2.lt/lt/mobinter_krepselis_privatiems?step1';
    
    if (client_type == 2) to_cart = 'http://mob.tele2.lt/lt/mobinter_krepselis_verslui?step1';
    
    // ----
    
    var url = 'http://mob.tele2.lt/scripts/add_to_cart.php?product_id='+prod+'&group_id='+client_type;
    
    newdiv.innerHTML = '<a href="javascript:PlanToCartDivHide();"><img align="right" class="PlanToCartClose" src="/images/PlanToCartDiv_close.gif" border="0" alt="Close" /></a><div class="PlanToCartClose_center"><br /><br /><img src="/images/PlanToCartDiv_center_img.gif" border="0" alt="" /><br /><br />'+text+'<br /><br /><a href="'+to_cart+'"><img src="/images/PlanToCartDiv_goto.gif" border="0" alt="" /></a></div><iframe height="0" width="0" src="'+url+'" frameborder="0"></iframe>';
    
    document.body.appendChild(newdiv);
    
    delete text;
    delete type;
    delete url;
    delete prod;
}

/* To add plan to cart [new version] */

function planToCart(product_code, type)
{
    var width = 328;
    var height = 196;
    var randomnumber = Math.floor(Math.random()*100000000);
    
    // lets create popup ---
    
    var newdiv = document.createElement('div');
    newdiv.setAttribute('id', 'PlanToCartDiv');
    newdiv.setAttribute('class', 'PlanToCartDiv');
    newdiv.className = 'PlanToCartDiv';
   
    newdiv.style.width = width;
    newdiv.style.height = height;
    
    // position ---
    
    WinSize = getPageSize();
    
    newdiv.style.left = (WinSize[2]/2) - (width/2)+'px';
    newdiv.style.top = (WinSize[3]/2) - (height/2)+'px';
    
    scroll(0,0);
    
    // ----
    
    var text = "Jūsų pasirinkta prekė sėkmingai įdėta į krepšelį.";
    var product_code = product_code;
    
    // ----
    
    var client_type = type;
    var to_cart = 'http://mob.tele2.lt/lt/krepselis_privatiems?step1';    
    if (type == 2) to_cart = 'http://mob.tele2.lt/lt/krepselis_verslui?step1';
    
    // ----    
        
    var url = 'http://mob.tele2.lt/scripts/add_to_cart2.php?product_code='+product_code+'&group_id='+type+'&rand='+randomnumber;
    
    newdiv.innerHTML = '<a href="javascript:PlanToCartDivHide();"><img align="right" class="PlanToCartClose" src="/images/PlanToCartDiv_close.gif" border="0" alt="Close" /></a><div class="PlanToCartClose_center"><br /><br /><img src="/images/PlanToCartDiv_center_img.gif" border="0" alt="" /><br /><br />'+text+'<br /><br /><a href="'+to_cart+'"><img src="/images/PlanToCartDiv_goto.gif" border="0" alt="Eiti į krepšelį" /></a></div><iframe height="0" width="0" src="'+url+'" frameborder="0"></iframe>';
    document.body.appendChild(newdiv);
    
    delete text;
    delete type;
    delete url;
    delete product_code;
}

/* Close cart popup */

function PlanToCartDivHide()
{
    var elem = document.getElementById('PlanToCartDiv');
    if (elem) document.body.removeChild(elem);
    return;
}

/*google search*/

var searchAsYouTypeConfiguration = {
    resourcesPath: "http://www.tele2.se/search1/",
    ajaxResponderUrl: "http://www.tele2.se/search1/Suggest.ashx",
    extendedArgs: "&x=lt",
    helpPageUrl: "",
    maxFullResults: 10,
    keystrokeDelay: 5,
    showResultsDelay: 10,
    bottomPageMargin: 10
};
$(document).ready(function () {
    if (typeof searchAsYouType != "undefined") {
        if ($('#searchfield2').length) {
            searchAsYouType.initialize($('#searchfield2').get(0), false);
        }
        else if ($('#searchfield').length) {
            searchAsYouType.initialize($('#searchfield').get(0), false);
        }
    }
});


// --- /
