﻿var arVersion = navigator.appVersion.split("MSIE")
var _version = parseFloat(arVersion[1])
var isIE=(navigator.appVersion.indexOf("MSIE")!=-1);
//var isIE5=document.all&&document.getElementById;
var isIE5=document.all && !window.opera;
var isIE6=(window.navigator.appVersion.indexOf("IE 6.0")!=-1);
var isNS6=document.getElementById&&!document.all;
var isIE7=(isIE&&_version==7);


function $$(el) { return (document.getElementById(el)); }
function agent(v) { return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); }
function xy(e,v) { return(v?(agent('msie')?event.clientY+document.body.scrollTop:e.pageY):(agent('msie')?event.clientX+document.body.scrollTop:e.pageX)); }


// Return element pointer
function getElById(el){
	//alert(el);
	return document.getElementById(el);
}
function getElByName(el){
	return document.getElementByName(el);
}
function getElsByName(el){
	return document.getElementsByName(el);
}

function getObject(el){
	var obj;//=null;
	if('object'==typeof(el))
		obj=el;
	else if('string'==typeof(el))
		obj = $$(el);
	if(typeof(obj)=='object'&&obj!=null)
		return obj;
	return null;
}

function showProps(obj, objName){
    var result = "";
    for (var i in obj) // обращение к свойствам объекта по индексу
        result += objName + "." + i + " = " + obj[i] + "<br />\n";
    document.write(result);
}

function delThis(){
	return !confirm("Are you sure want delete item?");
}

/* Browser object */
function yg_Browser() {
	d = document;
	this.agt = navigator.userAgent.toLowerCase();
	this.major = parseInt(navigator.appVersion);
	this.dom = (d.getElementById);
	this.ns = (d.layers);
	this.ns4up = (this.ns && this.major >= 4);
	this.ns6 = (this.dom && navigator.appName == "Netscape");
	this.op = (window.opera);
	this.ie = (d.all);
	this.ie4 = (d.all && !this.dom);
	this.ie4up = (this.ie && this.major >= 4);
	this.ie5 = (d.all && this.dom);
	this.ie6 = (d.nodeType);
	this.ff = (navigator.userAgent.indexOf("Firefox") != -1);
	this.sf = (this.agt.indexOf("safari") != -1);
	this.win = ((this.agt.indexOf("win") != -1) || (this.agt.indexOf("16bit") != -1));
	this.winme = (this.agt.indexOf("win 9x 4.90") != -1);
	this.xpsp2 = (this.agt.indexOf("sv1") != -1);
	this.mac = (this.agt.indexOf("mac") != -1);
	this.chrome = (navigator.userAgent.toLowerCase().indexOf("chrome/") != -1);
	this.konqueror = /konqueror/.test(navigator.userAgent.toLowerCase());
}
var oBw = new yg_Browser();

function getEFocus() {
	// initialize function global reference to document
	// element that currently h(as)f(ocus)
	var hf=null;
	// IE uses activeElement
	if (document.activeElement) hf = document.activeElement;
	// Firefox uses focusNode
	else if (document.focusNode) hf = document.focusNode;
	return hf;
}
/*
function setFocusHndlr() {
for (i = 0; i < form.elements.length - 1; i++) {
elem = document.elements[i];
elem.focused = false;
elem.hasFocus = function() {
return this.focused;
};
elem.onfocus = function() {
this.focused = true;
};
elem.onblur = function() {
this.focused = false;
};
}
}
{
var w;
var el;
onload = function() {
el = document.forms[0].elements;
for (var i = 0; i < el.length; i++) {
el[i].onfocus = function() {
w = (el[this.name].length > 0) ? (this.name + ' and value ' + this.value) : this.name
}
}
}
}*/

/***********			DATES			*****************************/
function diffMSec(d1,d2){
	return d1.getTime()-d2.getTime();
}
function getMonth(name){
	switch (name) {
		case 'Jan':return 1;
		case 'Feb':return 2;
		case 'Mar':return 3;
		case 'Apr':return 4;
		case 'May':return 5;
		case 'Jun':return 6;
		case 'Jul':return 7;
		case 'Aug':return 8;
		case 'Sep':return 9;
		case 'Oct':return 10;
		case 'Nov':return 11;
		case 'Dec':return 12;
	}
}

/***********			/DATES			*****************************/



/***********			POSITION			*****************************/

function fGetLeft(obj){
   return(obj.offsetParent==null ? obj.offsetLeft : obj.offsetLeft+fGetLeft(obj.offsetParent));
}

function fGetTop(obj){
   return(obj.offsetParent==null ? obj.offsetTop : obj.offsetTop+fGetTop(obj.offsetParent));
}

function getOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

function GetXPosition(item){
	var position = 0;
	if (item.offsetWidth != null){
		while (item != document.body && item != null){
			position += item.offsetLeft;
			item = item.offsetParent;
		}
	}
	return position;
}

function GetYPosition(item){
	var position = 0;
	if (item.offsetWidth != null){
		while (item != document.body && item != null){
			position += item.offsetTop;
			item = item.offsetParent;
        }
    }
	return position;
}

function getBounds(element) {
  var left = element.offsetLeft;
  var top = element.offsetTop;
  for (var parent = element.offsetParent; parent; parent = parent.offsetParent) {
    left += parent.offsetLeft;
    top += parent.offsetTop;
  }
  return {left: left, top: top, width: element.offsetWidth, height: element.offsetHeight};
}

function getPageSize() {
	var q, r;
	var p, u;
	var m = document;
	if (self.innerHeight && self.scrollMaxY) { q = m.body.scrollWidth; r = self.innerHeight + self.scrollMaxY }
	else {
		if (m.body.scrollHeight > m.body.offsetHeight) { q = m.body.scrollWidth; r = m.body.scrollHeight }
		else { q = m.body.offsetWidth; r = m.body.offsetHeight } 
	}
	if (self.innerHeight) { p = self.innerWidth; u = self.innerHeight }
	else {
		if (m.documentElement && m.documentElement.clientHeight) { p = m.documentElement.clientWidth; u = m.documentElement.clientHeight }
		else {
			if (m.body) { p = m.body.clientWidth; u = m.body.clientHeight }
		}
	}
	var t = Math.max(q, p);
	var s = Math.max(r, u);
	return [t, s, p, u]

} 
/***********			/POSITION			*****************************/



/***********			WINDOW			*****************************/
//set window status
function setStatus(msg){
    status = msg;
    return true;
}
function clearStatus(msg){
    window.status='';
    return true;
}
function setTitle(strTitle){
	window.document.title=strTitle;
}
function goBack(){
	history.back();
}

function setWindow(left,top,width,height)
{
	self.moveTo(left,top);
	self.resizeTo(width,height);
	self.scrollTo(0,0);
}

function openWindow(url) {
	popupWin = window.open(url,'new_page','width=400,height=400');
	
}
function lochref(url){
	location.href=url;
}

function wourl(url){
	window.open(url);
}
function openWindowCenter(url,name,width,height){
	var left = (screen.width - width) / 2;
	var top = (screen.height - height) / 2;
	var popupWin = window.open(url,name,'width='+width+',height='+height+',top='+top+',left='+left);
	return popupWin;
}
/***********			/WINDOW			*****************************/



/***********			DISPLAY			*****************************/
function hideobj(objname){
	if ($$(objname))
		$$(objname).style.visibility = 'hidden';
}
function setZindex(obj,index){
	obg.zIndex=index;
}
/***********			/DISPLAY		*****************************/

/***********			STRING		*****************************/
if ('undefined' == typeof String.prototype.ltrim) {
  String.prototype.ltrim = function() {
    return this.replace(/^\s+/, '');
  }
}

if ('undefined' == typeof String.prototype.rtrim) {
  String.prototype.rtrim = function() {
    return this.replace(/\s+$/, '');
  }
}

if ('undefined' == typeof String.prototype.trim) {
  String.prototype.trim = function() {
    return this.replace(/^\s+/, '').replace(/\s+$/, '');
  }
}

String.nl2br=function(pString){return pString.replace(/\n/g,'<br />\n');}

//escape UTF8
String.escape_utf8=function(pD){
	if(pD==''||pD==null)return '';pD=pD.toString();var bfr='';
	for(var i=0;i<pD.length;i++){
		var c=pD.charCodeAt(i),bs = new Array();
		if (c>0x10000){//4 bytes
			bs[0]=0xF0|((c&0x1C0000)>>>18);
			bs[1]=0x80|((c&0x3F000)>>>12);
			bs[2]=0x80|((c&0xFC0)>>>6);
			bs[3]=0x80|(c&0x3F);
		}else if(c > 0x800){//3 bytes
			bs[0]=0xE0|((c&0xF000)>>>12);
			bs[1]=0x80|((c&0xFC0)>>>6);
			bs[2]=0x80|(c&0x3F);
		}else if(c>0x80){//2 bytes
			bs[0]=0xC0|((c&0x7C0)>>>6);
			bs[1]=0x80|(c&0x3F);
		}else{//1 byte
            bs[0]=c;
        }
		for(var j=0;j<bs.length;j++) {
            var b=bs[j]; 
            var hex=nibble_to_hex((b&0xF0)>>>4)+nibble_to_hex(b & 0x0F); 
            bfr+='%'+hex;
        }
	}
	return bfr;
}

//trim whitespaces on the edges of the string
//String.trim=function(s){while(s.substring(0,1)==' ')s=s.substring(1,s.length);while(s.substring(s.length-1,s.length)==' ')s=s.substring(0,s.length-1);return s;}

//find and replace
//String.replace=function(find,replace){return this.split(find).join(replace);}

//escape for xml file
String.escapeForXML=function(){return this.replace('&','&amp;').replace('"','&quot;').replace('<','&lt;').replace('>','&gt;');}

//escape xml to non destructive html
String.escapeForDisplay=function(){return this.replace('<','&lt;');}

function hexnib(d) { if(d<10) return d; else return String.fromCharCode(65+d-10); }

function hexbyte(d) { return "%"+hexnib((d&240)>>4)+""+hexnib(d&15);}

function hexcode(url) {
	var result="";
	var hex="";
	for(var i=0;i<url.length; i++) {
		var cc=url.charCodeAt(i);
		if (cc<128) {
			result+=hexbyte(cc);
		} else if((cc>127) && (cc<2048)) {
			result+=  hexbyte((cc>>6)|192)
				+ hexbyte((cc&63)|128);
		} else {
			result+=  hexbyte((cc>>12)|224)
				+ hexbyte(((cc>>6)&63)|128)
				+ hexbyte((cc&63)|128);
		}
	}
	return result;
}
/***********			/STRING		*****************************/


/***********			INPUTS		*****************************/
//return code of preesed key
function enterPressed(e){
    var keynum;
	if(window.event)//ie
		keynum=window.event.keyCode
	else if (e.which)//Netscape/Firefox/Opera
		keynum=e.which;

	return (keynum==13);
	//keychar = String.fromCharCode(keynum)
	//numcheck = /\d/
	//return !numcheck.test(keychar)

	//if (window.event.keyCode == 13 && window.event.srcElement.tagName!='TEXTAREA')
}
function textCounter(field, countfield, maxlimit) {
	try{
		if (field.value.length > maxlimit) 
			field.value = field.value.substring(0, maxlimit-1);
		else 
			countfield.value = maxlimit - field.value.length;
	}
	catch(err){;}
}

function my_trim(s)
{
	while (s.substring(0, 1) == ' '){
		s = s.substring(1, s.length);
	}
	while (s.substring(s.length-1, s.length) == ' '){
		s = s.substring(0, s.length-1);
	}
	return s;
}

function xreplace(text,toberep,repwith){
	var temp = text;
	var i = temp.indexOf(toberep);
	while(i > -1){
		temp = temp.replace(toberep, repwith);
		i = temp.indexOf(toberep, i + repwith.length + 1);
	}
	return temp;
}

function isDigit(num) {
	if (num.length>1){return false;}
	var string="1234567890";
	if (string.indexOf(num)!=-1){return true;}
	return false;
}

function regReplace(text,patern,replacement){
	var re = new RegExp(patern, "g");
	return text.replace(re,replacement);
}

/***********			/INPUTS		*****************************/

/***********			ARRAYS			*****************************/
function searcharr(arr,what) {
	if(arr){
		var i;
		for(i=0;i<arr.length;i++)
			if(arr[i]==what)
				return i;
	}
	return -1;
}
function removeBad(arr){
	if(arr){
		var arrlength=arr.length;
		for(var index=0;index < arrlength;index++)
			if (!$$(arr[index])) {
				arr.splice(index,1);
				index--;
				arrlength--;
			}
	}
	return arr;
}
function removeDuplicates(arr){
	if(arr){
		var newArr=new Array();
		var hash = new Object();
		for (var i=0; i<arr.length; i++){
			if (hash[arr[i]] != 1){
				newArr = newArr.concat(arr[i]);
				hash[arr[i]] = 1;
			}
		}
	}
	return newArr;
}
/***********			/ARRAYS			*****************************/

/***********			DOM			*****************************/
function addEvent(object, event, handler)
{
  if (typeof object.addEventListener != 'undefined')
    object.addEventListener(event, handler, false);
  else if (typeof object.attachEvent != 'undefined')
    object.attachEvent('on' + event, handler);
  else
    throw "Incompatible browser";
}

function removeEvent(object, event, handler)
{
  if (typeof object.removeEventListener != 'undefined')
    object.removeEventListener(event, handler, false);
  else if (typeof object.detachEvent != 'undefined')
    object.detachEvent('on' + event, handler);
  else
    throw "Incompatible browser";
}

function addEvent_(name,evf){

	try{
		if (window.addEventListener){
			if(eval("window.addEventListener(name, evf, false);"))
				window.addEventListener(name, evf, false);
			else if(document.getElementById)
				eval("window."+name+"="+evf);
		}
		else if (window.attachEvent){
			window.attachEvent(name, evf);
		}
		else if (document.getElementById){
			eval("window."+name+"="+evf);
		}
	}catch(err){;}
}
/*function addEvent(obj,evType,fn,useCapture){
var ret=false;
if(obj!=null){
if(obj.addEventListener){
obj.addEventListener(evType,fn,useCapture);
ret=true;
}
else if(obj.attachEvent){
obj.attachEvent(”on”+evType,fn);ret=true;
}
}
return ret;
}*/

function setGlobalOnLoad(f) {
   var root = window.addEventListener || window.attachEvent ? window : document.addEventListener ? document : null
   if (root){
      if(root.addEventListener) root.addEventListener("load", f, false)
      else if(root.attachEvent) root.attachEvent("onload", f)
   } else {
      if(typeof window.onload == 'function') {
         var existing = window.onload
         window.onload = function() {
            existing()
            f()
         }
      } else {
         window.onload = f
      }
   }
}

function cr_el(name, attrs, style, text) {
    var e = document.createElement(name);
    if (attrs) {
        for (key in attrs) {
            if (key == 'class') {
                e.className = attrs[key];
            } else if (key == 'id') {
                e.id = attrs[key];
            } else {
                e.setAttribute(key, attrs[key]);
            }
        }
    }
    if (style) {
        for (key in style) {
            e.style[key] = style[key];
        }
    }
    if (text) {
        e.appendChild(document.createTextNode(text));
    }
    return e;
}

function cleanNode(dest)
{
  while (dest.firstChild)
    dest.removeChild(dest.firstChild);
}

function getElemText(node){
    return node.text || node.textContent || (function(node){
        var _result = "";
        if (node == null) {
            return _result;
        }
        var childrens = node.childNodes;
        var i = 0;
        while (i < childrens.length) {
            var child = childrens.item(i);
            switch (child.nodeType) {
                case 1: // ELEMENT_NODE
                case 5: // ENTITY_REFERENCE_NODE
                    _result += arguments.callee(child);
                    break;
                case 3: // TEXT_NODE
                case 2: // ATTRIBUTE_NODE
                case 4: // CDATA_SECTION_NODE
                    _result += child.nodeValue;
                    break;
                case 6: // ENTITY_NODE
                case 7: // PROCESSING_INSTRUCTION_NODE
                case 8: // COMMENT_NODE
                case 9: // DOCUMENT_NODE
                case 10: // DOCUMENT_TYPE_NODE
                case 11: // DOCUMENT_FRAGMENT_NODE
                case 12: // NOTATION_NODE
                // skip
                break;
            }
            i++;
        }
        return _result;
    }(node));
}

function element2element(obj,elName) {
   var el = document.createElement(elName);
   while (obj.firstChild) el.appendChild(obj.firstChild);
   obj.parentNode.replaceChild(el, obj);
}

function setOuterHTML(el, txt) 
{ 
	//работает для IE, но не работает для Firefox.
	if (el.outerHTML) 
		el.outerHTML = txt; 
	//работает для Firefox, но не работает для IE.
	else { 
		var range = document.createRange(); 
		range.setStartBefore(el); 
		var docFrag = range.createContextualFragment(txt); 
		el.parentNode.replaceChild(docFrag, el); 
	} 
}

function insertTag(id, text) {
	if ((document.selection && $$(id) == '[object]')) {
		$$(id).focus();
		$$(id).document.selection.createRange().text = text;
	} else $$(id).value += text;
};
function insertBBTag(id, text1, text2) {
	if ((document.selection && $$(id) == '[object]')) {
		$$(id).focus();
		$$(id).document.selection.createRange().text = text1 + $$(id).document.selection.createRange().text + text2;
		$$(id).focus();
	} else $$(id).value += text1 + text2;
};
/***********			/DOM		*****************************/



/***********			COOKIE		*****************************/
function setCookie(name, value,days){
	var cswitch = getCookie("cswitch");
	if (!cswitch){
		var today = new Date();d = new Date(today.getTime() + days*24*60*60*1000); 
		var newCookie1 = name + "=" + escape(value) + ";expires=" + d.toGMTString() + ";path=/ ;";
		document.cookie = newCookie1;
		//var newCookie2 = name + "=" + escape(value) + ";expires=" + d.toGMTString() + ";path=/ ;domain=labirint-shop.ru;";
		//document.cookie = newCookie2;
		//var newCookie3 = name + "=" + escape(value) + ";expires=" + d.toGMTString() + ";path=/ ;domain=192.168.2.252;";
		//document.cookie = newCookie3;
	}
}
function getCookie(name){
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}
function readCookie(name){
	var nameEQ = name + "=";
	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(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name){
	createCookie(name,"",-1);
}
/***********			/COOKIE		*****************************/



/***********			FLASH		*****************************/
function setFlashVar(flashName,varName, value){
	var internetExplorer = navigator.appName.indexOf("Microsoft") != -1;
	var myFlashObj = internetExplorer ? $$(flashName) : eval('window.document.'+flashName);
	//alert(varName+" "+value);
	if(internetExplorer)
		$$(flashName).SetVariable(varName, value);
	else
		myFlashObj.SetVariable(varName,value);
}


//getFlash('laptop_button', 122, 81);
function getFlash(id, fileName, width, height){            
	document.write('<object id='+id+' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+width+'" height="'+height+'">');
	document.write('<param name="movie" value="'+fileName+'">');
	document.write('<param name="quality" value="high">');
	document.write('<PARAM NAME="WMode" VALUE="Transparent">');
	document.write('<embed id='+id+' src="'+fileName+'" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'"></embed>');
	document.write('</object>');
}
/***********			/FLASH		*****************************/





/** Use this to add an event to an object unobtrusively
 *  @param - obj: Object to add event to (i.e. window)
 *  @param - evType: Event type (i.e. 'load')
 *  @param - fn:Function to be called when event occurs
 */
var KS_Util=function(){
		this.prototype = function(){
			addEvent=function (obj, evType, fn){ 
			if (obj.addEventListener){ 
				obj.addEventListener(evType, fn, false); 
				return true; 
			} 
			else if (obj.attachEvent){ 
				var r = obj.attachEvent("on"+evType, fn); 
				return r; 
			} 
			else { 
				return false; 
			} 
			fadeElement=function(pEle,pFadeVisible,pMsg) {
				var ele = $$(pEle);
				 if (null!=pMsg && ""!=pMsg) ele.innerHTML = pMsg;
				 var oAnim=null;
				 if (pFadeVisible) {
   	 				oAnim = new YAHOO.util.Anim(pEle, { opacity: { to: 1, from : 0 } }, 1.9, YAHOO.util.Easing.easeNone);
				 }
				 else { //hidden
   	 				oAnim = new YAHOO.util.Anim(pEle, { opacity: { to: 0, from : 1 } }, 1.9, YAHOO.util.Easing.easeNone);
				 }
				 // YAHOO.util.Event.on(document, 'click', oAnim.animate, anim, true);
			   
				 //if (pFadeVisible) oAnim.onStart = function() { 
				 ele.style.visibility = 'visible';
				 oAnim.animate();
				 return false;
			}
		}
	}
}


var blank = new Image();
blank.src = '/null.gif';

$(document).ready(function() {
   var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
   if (badBrowser) {
     // get all pngs on page
     $('img[src$=.png]').each(function() {
       if (!this.complete) {
         this.onload = function() { fixPng(this) };
       } else {
         fixPng(this);
       }
     });
   }
 });
 
 function fixPng(png) {
   // get src
   var src = png.src;
   // set width and height
   if (!png.style.width) { png.style.width = $(png).width(); }
   if (!png.style.height) { png.style.height = $(png).height(); }
   // replace by blank image
   png.onload = function() { };
   png.src = blank.src;
   // set filter (display original image)
   png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
 }
