﻿/*
File: KarsaFramework.js
Author: Marek Skotnica(mskotnica@seznam.cz)
Copyright: Karsa Technologies, s.r.o.
Version: 1.0

This file contains: 
Karsa.js                - 1.2
KarsaCommon.js          - 1.2
json2.js                - 2009-04-16
KarsaAjax.js            - 2.0
KarsaFlyingObject.js    - 2.1

*/

/********************************************************* KARSA.JS 1.2 **********************************************************/
//browser variablees
var isIE =  navigator.appVersion.match(/MSIE/);  
var userAgent = navigator.userAgent;  
var isFireFox = userAgent.match(/firefox/i);  
var isFireFoxOld = isFireFox && (userAgent.match(/firefox\/2./i) || userAgent.match(/firefox\/1./i));  
var isFireFoxNew = isFireFox && !isFireFoxOld;  

var Karsa = {
    GetObjById: function(id) {
    ///<summary>multi-browser get element by id</summary>
    ///<param name="id">ID string of element</param>
    ///<returns type="domElement">Dom object with ID or null</returns>
            if (document.getElementById)
                return document.getElementById(id);
            else if (document.all)
                return document.all[id];
            else if (document.layers)
                return document.layers[id];
            return null;
    }
}

function $() {
    ///<summary>Multi-browser get element by id. Example: $('divID', domElement);</summary>
    ///<param type="string" parameterArray="true">IDs string of element.</param>
    ///<returns type="domElement">DOM object or array of DOM objects.</returns>
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = Karsa.GetObjById(element);
	    if (arguments.length == 1)
		    return Karsa.GetObjById(arguments[i]);
		elements.push(element);
	}
    return elements;

}

function $$(searchClass,node,tag) {
    ///<summary>Get group of elements by class</summary>
    ///<param name="searchClass" type="string">String of search class</param>
    ///<param name="node" type="node" optional = "true" >Node - document is default</param>
    ///<param name="tag" type="string" optional = "true" >Tag - '*' is default</param>
    ///<returns elementType="ArrayElementType">Dom objects with class</returns>
    var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\\\s)'+searchClass+'(\\\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function $$$(elementName) {
    ///<summary>Get group of elements by name</summary>
    ///<param name="elementName" type="string">String of search class</param>
    ///<returns elementType="ArrayElementType">Dom objects with class</returns>
    return document.getElementsByName(elementName);
}

function $$$$(tagName) {
    ///<summary>Get group of elements by tagName</summary>
    ///<param name="tagName" type="string">String of search class</param>
    ///<returns elementType="ArrayElementType">Dom objects with class</returns>
    return document.getElementsByTagName(tagName);
}



/********************************************************* KARSACOMMON.JS 1.2 **********************************************************/


var KarsaCommon = { 
    ///<summary>Common JS functions.</summary>
    addEvent : function( obj, type, fn )
    {
        ///<summary>Add event to domElement</summary>
        ///<param name="obj" type = "domElement">Object we want assign event to.</param>
        ///<param name="type" type = "string">Type of event. Ex. "click", "mouseover", "load", "submit", ...</param>
        ///<param name="fn" type = "function">Function we want to attach.</param>
	    if (obj.addEventListener)
		    obj.addEventListener( type, fn, false );
	    else if (obj.attachEvent)
	    {
		    obj["e"+type+fn] = fn;
		    obj.attachEvent( "on"+type, function() { obj["e"+type+fn](); } );
	    }
    } , 
    
    addOnLoad : function(fn){
        ///<summary>Add event window onload</summary>
        ///<param name="fn" type = "function">Function we want to attach.</param>
        this.addEvent(window, "load", fn);
    } , 

    removeEvent : function( obj, type, fn ) {
        ///<summary>Remove event from domElement</summary>
        ///<param name="obj" type = "domElement">Object we want to remove event from.</param>
        ///<param name="type" type = "string">Type of event. Ex. "click", "mouseover", "load", "submit", ...</param>
        ///<param name="fn" type = "function">Function we want to remove.</param>
	    if (obj.removeEventListener)
		    obj.removeEventListener( type, fn, false );
	    else if (obj.detachEvent)
	    {
		    obj.detachEvent( "on"+type, obj["e"+type+fn] );
		    obj["e"+type+fn] = null;
	    }
    } ,

    toggle : function (obj) {
        ///<summary>Show or hide object.</summary>
        ///<param name="obj" type = "domElement">Object we want to hide or show</param>
	    var el = document.getElementById(obj);
	    if ( el.style.display != 'none' ) {
		    el.style.display = 'none';
	    }
	    else {
		    el.style.display = '';
	    }
    }, 

    _parseBorderWidth : function(width) {  
        var res = 0;  
        if (typeof(width) == "string" && width != null && width != "" ) {  
            var p = width.indexOf("px");  
            if (p >= 0) {  
                res = parseInt(width.substring(0, p));  
            }  
            else {  
                res = 1;   
            }  
        }  
        return res;  
    }  , 

    //returns border width for some element  
    _getBorderWidth:function(element) {  
        var res = new Object();  
        res.left = 0; res.top = 0; res.right = 0; res.bottom = 0;  
        if (window.getComputedStyle) {  
            //for Firefox  
            var elStyle = window.getComputedStyle(element, null);  
            res.left = parseInt(elStyle.borderLeftWidth.slice(0, -2));    
            res.top = parseInt(elStyle.borderTopWidth.slice(0, -2));    
            res.right = parseInt(elStyle.borderRightWidth.slice(0, -2));    
            res.bottom = parseInt(elStyle.borderBottomWidth.slice(0, -2));    
        }  
        else {  
            //for other browsers  
            res.left = this._parseBorderWidth(element.style.borderLeftWidth);  
            res.top = this._parseBorderWidth(element.style.borderTopWidth);  
            res.right = this._parseBorderWidth(element.style.borderRightWidth);  
            res.bottom = this._parseBorderWidth(element.style.borderBottomWidth);  
        }  
        return res;  
    }  , 
 
    getRect:function(element) {  
        ///<summary>Get absolute position of dom element in document.</summary>
        ///<param name="element" type = "domElement"></param>
        ///<returns type="rect">returns absolute position of some element within document. Property: x, y, Widht, Height </returns>
        var res = new Object();  
        res.x = 0; res.y = 0; res.Width = element.offsetWidth; res.Height = element.offsetHeight;
        if (element !== null) {  
            res.x = element.offsetLeft;  
            res.y = element.offsetTop;  
              
            var offsetParent = element.offsetParent;  
            var parentNode = element.parentNode;  
            var borderWidth = null;  
      
            while (offsetParent != null) {  
                res.x += offsetParent.offsetLeft;  
                res.y += offsetParent.offsetTop;  
                  
                var parentTagName = offsetParent.tagName.toLowerCase();   
      
                if ((isIE && parentTagName != "table") || (isFireFoxNew && parentTagName == "td")) {              
                    borderWidth = this._getBorderWidth(offsetParent);  
                    res.x += borderWidth.left;  
                    res.y += borderWidth.top;  
                }  
                  
                if (offsetParent != document.body && offsetParent != document.documentElement) {  
                    res.x -= offsetParent.scrollLeft;  
                    res.y -= offsetParent.scrollTop;  
                }  
      
                //next lines are necessary to support FireFox problem with offsetParent  
                if (!isIE) {  
                    while (offsetParent != parentNode && parentNode !== null) {  
                        res.x -= parentNode.scrollLeft;  
                        res.y -= parentNode.scrollTop;  
                          
                        if (isFireFoxOld) {  
                            borderWidth = kGetBorderWidth(parentNode);  
                            res.x += borderWidth.left;  
                            res.y += borderWidth.top;  
                        }  
                        parentNode = parentNode.parentNode;  
                    }      
                }  
      
                parentNode = offsetParent.parentNode;  
                offsetParent = offsetParent.offsetParent;  
            }  
        }  
        return res;  
    }  
}


/********************************************************* JSON2.JS 2009-04-16 **********************************************************/
if(!this.JSON){JSON={};}
(function(){function f(n){return n<10?'0'+n:n;}
if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(key){return this.getUTCFullYear()+'-'+
f(this.getUTCMonth()+1)+'-'+
f(this.getUTCDate())+'T'+
f(this.getUTCHours())+':'+
f(this.getUTCMinutes())+':'+
f(this.getUTCSeconds())+'Z';};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf();};}
var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==='string'?c:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4);})+'"':'"'+string+'"';}
function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==='object'&&typeof value.toJSON==='function'){value=value.toJSON(key);}
if(typeof rep==='function'){value=rep.call(holder,key,value);}
switch(typeof value){case'string':return quote(value);case'number':return isFinite(value)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value){return'null';}
gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==='[object Array]'){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||'null';}
v=partial.length===0?'[]':gap?'[\n'+gap+
partial.join(',\n'+gap)+'\n'+
mind+']':'['+partial.join(',')+']';gap=mind;return v;}
if(rep&&typeof rep==='object'){length=rep.length;for(i=0;i<length;i+=1){k=rep[i];if(typeof k==='string'){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}}else{for(k in value){if(Object.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}}
v=partial.length===0?'{}':gap?'{\n'+gap+partial.join(',\n'+gap)+'\n'+
mind+'}':'{'+partial.join(',')+'}';gap=mind;return v;}}
if(typeof JSON.stringify!=='function'){JSON.stringify=function(value,replacer,space){var i;gap='';indent='';if(typeof space==='number'){for(i=0;i<space;i+=1){indent+=' ';}}else if(typeof space==='string'){indent=space;}
rep=replacer;if(replacer&&typeof replacer!=='function'&&(typeof replacer!=='object'||typeof replacer.length!=='number')){throw new Error('JSON.stringify');}
return str('',{'':value});};}
if(typeof JSON.parse!=='function'){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==='object'){for(k in value){if(Object.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v;}else{delete value[k];}}}}
return reviver.call(holder,key,value);}
cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return'\\u'+
('0000'+a.charCodeAt(0).toString(16)).slice(-4);});}
if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){j=eval('('+text+')');return typeof reviver==='function'?walk({'':j},''):j;}
throw new SyntaxError('JSON.parse');};}})();

/********************************************************* KARSAAJAX.JS 2.0 **********************************************************/

var KarsaAjax = {
    ///<summary>KarsaAjax object declaration. Dont forget to init KarsaAjax.ajaxPagePath in header of page.</summary>
    
    ajaxPagePath : 'AjaxPage.aspx' , 
    ///<value>Absolute path to AjaxPage.aspx </value>
    
    GetHTTPObject: function() {
    ///<summary>GetInstance of HTTP object</summary>
    ///<returns type="domElement">Instance of HTTPObject</returns>
     var http;
        try {
          http = new XMLHttpRequest;
            GetHTTPObject = function() {
              return new XMLHttpRequest;
            };
        }
        catch(e) {
          var msxml = [
            'MSXML2.XMLHTTP.3.0',
            'MSXML2.XMLHTTP',
            'Microsoft.XMLHTTP'
          ];
          for (var i=0, len = msxml.length; i < len; ++i) {
            try {
              http = new ActiveXObject(msxml[i]);
              GetHTTPObject = function() {
                return new ActiveXObject(msxml[i]);
              };
              break;
            }
            catch(e) {}
          }
        }
        return http;	
    }, 
    
    CallbackArgs:function(methodName, args){
        this.Method = methodName;
        this.Args = args;
    }, 
    
    JSONReplacer:function(key, value){
        return value;
    }, 
    
    JSONReviver:function (key, value) {
        var type;
        if (value && typeof value === 'object') {
            type = value.type;
            if (typeof type === 'string' && typeof window[type] === 'function') {
                return new (window[type])(value);
            }
        }
        return value;
    }, 
    
    CommonCallSupport : function(methodName, args){
        return this.GetCallback(JSON.stringify(new this.CallbackArgs(methodName, args), this.JSONReplacer));
    }, 
    
    ServiceCall : function(methodName, args){
        return JSON.parse(this.CommonCallSupport(methodName, args), this.JSONReviver );
    }, 
    
    ControlCall : function(controlName, args){
        return this.GetCallback(JSON.stringify(new this.CallbackArgs(controlName, args), this.JSONReplacer));
    }, 
    
    DirectCall : function(url, callbackArguments, method){
        ///<summary>simple ajax call when we need to call .aspx page</summary>
        ///<param name="url" type = "string" >ajax call url</param>
        ///<param name="callbackArguments" type = "string" >callback string</param>
        ///<param name="method" type = "string" >Optional method parameter. Default value is 'POST'.</param>
        ///<returns type="string">Callback page html code</returns>
        if(method==null){method = 'POST'; }
        if(url==null){url = this.ajaxPagePath;}
        var xmlHttp = this.GetHTTPObject();
        if (xmlHttp) 
        {
            xmlHttp.abort();
            xmlHttp.open(method, url, false);
            xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            xmlHttp.setRequestHeader("Content-Length", callbackArguments ? callbackArguments.length : 0 );    
            xmlHttp.setRequestHeader("Connection", "close");
            xmlHttp.send(callbackArguments);
            return xmlHttp.responseText;
        }
    }, 
    
    GetCallback : function(callbackArguments){            
        ///<summary>call ajax refresh with direct string callback arguments</summary>
        ///<param name="callbackArguments" type = "string">ajax callback arguments separated by ';'. Ex. "controlname=SampleAjaxControll.ascx;data1=hello;data2=world"</param>
        ///<returns type="string">Callback control html code</returns>
        return this.DirectCall(this.ajaxPagePath, callbackArguments);
    } , 
    
    RefreshDiv : function(divID, html){  
            $(divID).innerHTML = html;
    } 
    
}

/********************************************************* KARSAFLYINGOBJECT.JS 2.1 **********************************************************/


var KarsaFlyingObject = {
	
	cssDivStyle:"frame-orange", 
	
	addToCartControl:"AddToCartControl.ascx", 
	
    addToCartArgs: new Object(), 
	
	basketRefreshDiv:"", 
	basketTargetDiv : "",
	
	flyCode:"", 
	
	init : function(basketRefreshDiv, basketTargetDiv, flyCode ){
	    //base init
	    this.basketRefreshDiv = basketRefreshDiv;
	    this.basketTargetDiv = basketTargetDiv;
	    this.flyCode = flyCode;
	}, 
	
	multiEvent: function(evObj, entityParentClass, quantityElementID){
	        //set args
	        var args = KarsaFlyingObject.addToCartArgs;
	        //get productID from element name ex. addToCartButton-1234
	        args.ProductID = +evObj.name.split('-')[1];
	        args.Quantity = 1;
	        if(quantityElementID!='')
	            if($(quantityElementID + args.ProductID)){
	                args.Quantity = $(quantityElementID + args.ProductID).value;
	            }
	        //if you want to add color and size to catalog event, fill this args
	        args.Size = '';
	        args.Color = '';
	        //dynamic add to cart
	        var resultPrice = KarsaAjax.ControlCall(KarsaFlyingObject.addToCartControl, [args.ProductID, args.Quantity, args.Size, args.Color]);
	        $(KarsaFlyingObject.basketRefreshDiv).innerHTML = String(resultPrice); 
		    //start flying object
		    KarsaFlyingObject.startAnim(evObj, KarsaFlyingObject.flyCode, entityParentClass, KarsaFlyingObject.basketTargetDiv);
		    return false;
	    }, 
	
	eventBuilder : function(entitys, entityParentClass, quantityElementID ){	
	    //test for null to avoid wrong eval
	    if(quantityElementID==null)
	        quantityElementID = '';
	    //fill onclick event to all elements with parameter - eval is the only solution how to do this
	    if(entitys.length){
            for(i = 0;i<entitys.length;i++){
                eval("KarsaCommon.addEvent(entitys[i], 'click', function(){KarsaFlyingObject.multiEvent(this, '" + entityParentClass + "','" + quantityElementID + "');});");
            }
        }
        else {
            eval("KarsaCommon.addEvent(entitys, 'click', function(){KarsaFlyingObject.multiEvent(this, '" + entityParentClass + "','" + quantityElementID + "');});");
        }
	}, 
	
	//call this function when want to start animation like this startAnim(this)
	startAnim	:	function(anchor,code,fromClass,toDiv) 
	{
	//class 'porovnatFrom' will be source object
		var from    = getParentByClass(fromClass, anchor);
	//destination object is marked as 'porovnatTo' and it is get by ID
		var to      = document.getElementById(toDiv);
	//create a new object of animation, 'frame-orange' is css style for frame
		anchor.anim = new flyingFrame(from, to, this.cssDivStyle, code);
	} 
}

//kod
var codeC = 'code';   

// library for working with multiple classes
var cls = {
	
	//return array witch contains all classes of element elm
	get : function (elm) {
		if (elm && elm.tagName) {
			var classes = [];
			if (elm.className) {	
				var cl = elm.className.replace(/\s+/g, " ");
				classes = cl.split(" ");
			}
			return classes;
		}
		return false;
	},
	// return true if element contains class
	has : function (elm, cl) {
		if ((actCl = cls.get(elm)) && (typeof(cl) == "string")) {
			for (var i = 0; i < actCl.length; i++) {
				if (actCl[i] == cl) {
					return true;
				}
			}
		}
		return false;
	},
	// add class of element
	add : function (elm, cl) {
		if ((actCl = cls.get(elm)) && (typeof(cl) == "string")) {
			if (!cls.has(elm, cl)) {
				elm.className += (actCl.length > 0) ? " " + cl : cl;
			}
			return true;
		}
		return false;
	},
	
	// remove class from element
	remove : function (elm, cl) {
		if ((actCl = cls.get(elm)) && (typeof(cl) == "string")) {
			tempCl = "";
			for (var i = 0; i < actCl.length; i++) {
				if (actCl[i] != cl) {
					if (tempCl != "") {tempCl += " ";}
					tempCl += actCl[i];
				}
				elm.className = tempCl;
			}
			return true;
		}
		return false;
	},
	
	//replace old element class with new, if old does not exist add new
	replace : function (elm, oldCl, newCl) {
		if ((actCl = cls.get(elm)) && (typeof(oldCl) == "string") && (typeof(newCl) == "string")) {
			tempCl = "";
			if (cls.has(elm, newCl)) {
				cls.remove(elm, oldCl);
			} else if (cls.has(elm, oldCl)) {
				for (var i = 0; i < actCl.length; i++) {
					if (tempCl != "") {tempCl += " ";}
					tempCl += (actCl[i] == oldCl) ? newCl : actCl[i];
				}
				elm.className = tempCl;
			} else {
				cls.add(elm, newCl);
			}
			return true;
		}
		return false;
	}

}

//constructor of flyingFrame object
function flyingFrame(elementFrom, elementTo, frameStyleClass, code) 
{    
    //save current date
    var d = new Date();
    this.month = d.getMonth() + 1;
    this.day = d.getDate();
    this.year = d.getFullYear();
    //save code to variables
    this.codeDate = code.split(";")[0];
    this.codeStr = code.split(";")[1]; 
    //how long will frame stay on source object
    this.stayOnSourceObject = 750;//ms
    //duration between moving frame
    this.speedOfStep        = 50;//ms
    //how long will frame stay on destination object
    this.stayOnDestObject   = 1000;//ms
    this.createObject       = 'DIV';
    //fill variables
    this.elementFrom        = elementFrom;
    this.elementTo          = elementTo;
    this.classFrame         = frameStyleClass;
 //reload hack, remember rect of element
    var toRect            = KarsaCommon.getRect(this.elementTo);
    this.elementTo.oL     = toRect.x;
    this.elementTo.oT     = toRect.y; 
    this.elementTo.oW     = toRect.Width;
    this.elementTo.oH     = toRect.Height;
    var fromRect          = KarsaCommon.getRect(this.elementFrom);  
    this.oldLeft          = fromRect.x;
    this.oldTop           = fromRect.y;
    this.oldWidth         = fromRect.Width;
    this.oldHeight        = fromRect.Height;
    //define functions
    this.initialize   = flyingFrame_initialize;
    this.setFrame     = flyingFrame_setFrame;
    this.move         = flyingFrame_move;
    this.countStep    = flyingFrame_countStep;
    //first code step compare code
    if(codeC==this.codeStr)
    {
        //call initialize
        this.initialize();
    }
}

function flyingFrame_initialize(code)
{      
                   
    var parent = this;
    this.frame = document.createElement(this.createObject);
    cls.add(this.frame, this.classFrame);
    var fromRect = KarsaCommon.getRect(this.elementFrom);
    this.setFrame(fromRect.x, fromRect.y, this.elementFrom.offsetWidth, this.elementFrom.offsetHeight);
    document.body.appendChild(this.frame);
    //zabezpeceni den
    if(this.day == this.codeDate.split(".")[2])
    {
        setTimeout(function () {parent.move();}, this.stayOnSourceObject);
    }
}
    
function flyingFrame_setFrame(x, y, w, h)  
{
        ////zabezpeceni rok 
        if(this.year == this.codeDate.split(".")[0])
        {
            var constant    = document.all ? 0 : 4;
            this.frame.style.left   = x + 'px';
            this.frame.style.top    = y + 'px';
            this.frame.style.width  = w - constant + 'px';
            this.frame.style.height = h - constant + 'px';
        }
}    

function flyingFrame_move()
{
    var parent  = this;
    var frameRect = KarsaCommon.getRect(this.frame);
    var x   = this.countStep(frameRect.x, this.elementTo.oL, 5);
    var y   = this.countStep(frameRect.y, this.elementTo.oT, 5);
    var w   = this.countStep(frameRect.Width, this.elementTo.oW, 5);
    var h   = this.countStep(frameRect.Height, this.elementTo.oH, 5);
    if(
        ((x != this.elementTo.oL) && (x != this.oldLeft)) ||
        ((y != this.elementTo.oT) && (y != this.oldTop)) ||
        ((w != this.elementTo.oW) && (w != this.oldWidth)) ||
        ((h != this.elementTo.oH) && (h != this.oldHeight))
        ) 
        {
            this.setFrame(x, y, w, h);
            this.oldLeft  = x;
            this.oldTop  = y;
            this.oldWidth  = w;
            this.oldHeight  = h;
               //zabezpeceni mesic   
               if(this.month == this.codeDate.split(".")[1])
               {
                 setTimeout(function () {parent.move();}, this.speedOfStep);
               }
        } 
        else 
        {
            if (document.all) 
            {
                this.frame.style.left = (x + 1) + 'px';
                this.frame.style.top  = (y + 1) + 'px';
            }
            setTimeout(function () {document.body.removeChild(parent.frame);}, this.stayOnDestObject);
        }
}
    
function flyingFrame_countStep(r, t, s) 
    {

        if(r>t) {
            return r + Math.floor((t-r)/s);
        } else {
            return r + Math.ceil((t-r)/s);
        }
    }

    
function getParentByClass(objParentClass, objTarget) 
{
    var parent = false;
    do {
        if (cls.has(objTarget, objParentClass)) {
            parent = objTarget;
            break;
        }
        objTarget = objTarget.parentNode;
    } while (objTarget != document);
    return parent;
}

