﻿$(document).ready(function() {

    InitMainImageAnimation();

});

// Analytics funcion
function trackPageView(account, url) {
    //_gaq.push(['_setAccount', account]);
    _gaq.push(['_trackPageview', url]);

    return true;
}
// Analytics for transactions
function trackTransaction(order_id, sku_code, prod_name, cat, price_day, days, total, tax) {
    if (order_id && sku_code && prod_name && cat && price_day && days && total) {
        if (!tax)
            tax = "0";
        if (!total)
            total = "0";

        //var _gaq = _gaq || [];
        //_gaq.push(['_setAccount', 'UA-XXXXX-X']);
        _gaq.push(['_trackPageview']);
        _gaq.push(['_addTrans',
            order_id,           // order ID – required  - מספר יחודי של העסקה
            '',                 // affiliation or store name – להשאיר ריק
            total,              // total – required  - סף הכל לעסקה
            tax,                // tax – סך הכל למע"מ
            '',              // shipping – להשאיר ריק
            '',             // city – להשאיר ריק
            '',             // state or province – להשאיר ריק
            ''             // country – להשאיר ריק
          ]);

        // add item might be called for every item in the shopping cart
        // where your ecommerce engine loops through each item in the cart and
        // prints out _addItem for each
        _gaq.push(['_addItem',
            order_id,           // order ID – required – מספר יחודי של העסקה
            sku_code,           // SKU/code – required – Representative lead
            prod_name,        // product name – שם הרכב
            cat,                // category or variation – שם קטגוריית הרכבים
            price_day,          // unit price – required – מחיר ליום
            days               // quantity – required – מספר ימים להשכרה
          ]);
        _gaq.push(['_trackTrans']); //submits transaction to the Analytics servers

        //    (function () {
        //        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        //        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        //        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
        //    })();
    }
}

// JScript File
function AutoSubmit() {
    var f = document.forms[0];
    if (f) {
        var w = document.getElementById("wait");
        if (w) w.style.display = "block";

        var m = document.getElementById("msg");
        if (m) m.style.display = "none";

        f.submit();
    }
}
function onkeydownsearch(txb,e,page)
{
  if (e) {
    if (e.keyCode == 13) {
        var url = root + "search.aspx?word=" + txb.value;
        if (page != "") {
            url += "&search=" + page;
        }
        document.location = url;
        return false;
    }
  }
}

//main images animation
function InitMainImageAnimation()
{
    var item = $(".mainimg");

    item.each(function() {

        //store original width and height
        $(this).attr("W", $(this).width());
        $(this).attr("H", $(this).height());

        $(this).attr("posY", $(this).position().top);
        $(this).attr("posX", $(this).position().left);

        $(this).children("img").css("height", "auto");

        $(this).attr("active", "no");

    });

    item.mouseover(function() {
        StopAnimation($(this));
        var w = parseInt($(this).attr("W")) + 20;
        var t = parseInt($(this).attr("posY")) - 10;
        var l = parseInt($(this).attr("posX")) - 10;

        $(this).attr("active", "yes");

        $(this).children("img").animate({ width: w }, 100, null);
        $(this).animate({ left: l, top: t }, 100, null);
        //$(".mainimg[active='no']").animate({ opacity: 0.5 }, 200, null);

    }).mouseout(function() {
        StopAnimation($(this));
        var w = parseInt($(this).attr("W"));
        var t = parseInt($(this).attr("posY"));
        var l = parseInt($(this).attr("posX"));

        $(this).attr("active", "no");
        
        $(this).children("img").animate({ width: w }, 100, null);
        $(this).animate({ left: l, top: t }, 100, null);
        //$(".mainimg[active='no']").animate({ opacity: 1 }, 200, null);

    });
}

function StopAnimation(item) {
    //stop animation if any
    item.stop();
    item.children().stop();
}
//fontsize
        var schem = {

            version: '1.0',

            Init: function() {
                var style = $Cookie("schem");

                this.Activate(style);

            },

            Activate: function(title) {
                for (var i = 0; (a = document.getElementsByTagName("link")[i]); i++) {

                    if (a.getAttribute("rel").indexOf("alt") > -1 && a.getAttribute("title")) {

                        a.disabled = true;

                        if (a.getAttribute("title") == title) {

                            a.disabled = false;

                            $Cookie("schem", title, 365);

                        }

                    }

                }

                if (title == "none") $Cookie("schem", "none", 365);

            }

        };

        //set or get cookie

        function $Cookie(n, v, d) {
            if (n && v) {//set cookie

                var expires;

                if (d) {

                    var date = new Date();

                    date.setTime(date.getTime() + (d * 24 * 60 * 60 * 1000));

                    expires = "; expires=" + date.toGMTString();

                }

                else expires = "";

                document.cookie = n + "=" + v + expires + "; path=/";

            }

            else if (n) {//get cookie

                n = n + "=";

                var ca = document.cookie.split(';');

                for (var i = 0; i < ca.length; i++) {

                    var c = ca[i];

                    while (c.charAt(0) == ' ') c = c.substring(1, c.length);

                    if (c.indexOf(n) == 0)

                        return c.substring(n.length, c.length);

                }

            }

            return null;

        }

        function OnSubmit(obj, validationgroup) {

            if ((typeof (Page_ClientValidate) != "function" || Page_ClientValidate(validationgroup)) && !$(obj).hasClass("disable")) {
                $(obj).siblings(".loader").show();
                $(obj).hide();
                return true;
            }
            return false;
        }
        function ToCache() {
            document.location = "virtualstorecart.aspx";
        }
        function ToHistory() {
            document.location = "virtualstorehistory.aspx";
        }
        function ReplaceImage(obj) {
            if (obj)
                obj.style.display = "none";
        }
        function ReplaceImage2(obj) {
            if (obj)
                obj.style.display = "none";
        }

