preloadI(


);
function returnObjById( id ){   if (document.getElementById) var returnVar = document.getElementById(id); else if (document.all) var returnVar = document.all[id];   else if (document.layers)  var returnVar = document.layers[id];  return returnVar; }	

function SignInClick() {
	newDisplay = ($('#login-div').css('display') == 'none') ? 'block' : 'none';
	$('#login-div').css('display',newDisplay ).ready(function(){
		$('#mod_login_username','#login-div').focus();
	});
}

function do_nothing(){
}

function preloadI() {
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadI.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

function overMn(e)
{
	e.style.backgroundImage = 'url("/images/arrow_over.png")';
}

function outMn(e)
{
	e.style.backgroundImage = 'url("/images/arrow.png")';
}

$(document).ready(function() {
	$("#categories .r").hover(
		function() { overMn2(document.getElementById($(this).attr("id")), $(this).attr("id")); },
		function() { outMn2(document.getElementById($(this).attr("id"))); }
	);
	$("#categories .r_on").hover(
			function() { overMn2(document.getElementById($(this).attr("id")), $(this).attr("id")); },
			function() { outMn2(document.getElementById($(this).attr("id"))); }
	);
});

var head_img;
var class_r_s;
function overMn2(e, img)
{
	if (document.getElementById("head_img")) {
		head_img = document.getElementById("head_img").style.backgroundImage;
		document.getElementById("head_img").style.backgroundImage = 'url(' + img + ')';
	}
	else if (document.getElementById("head_img_sm")) {
		head_img = document.getElementById("head_img_sm").style.backgroundImage;
		document.getElementById("head_img_sm").style.backgroundImage = 'url(' + img+ ')';
	}
	class_r_s = e.className;
	e.className = 'r_over';
	e = e.firstChild;
	if (e.firstChild.childNodes[0]) {
		if (e.firstChild.childNodes[0].className == "s") {
			e.firstChild.childNodes[0].style.display = 'block';
		}
	}
	if (e.firstChild.childNodes[1]) {
		if (e.firstChild.childNodes[1].className == "s") {
			e.firstChild.childNodes[1].style.display = 'block';
		}
	}
}

function outMn2(e)
{
	if (document.getElementById("head_img")) {
		document.getElementById("head_img").style.backgroundImage = head_img;
	}
	else if (document.getElementById("head_img_sm")) {
		document.getElementById("head_img_sm").style.backgroundImage = head_img;
	}
	e.className = class_r_s;
	e = e.firstChild;
	if (e.firstChild.childNodes[0]) {
		if (e.firstChild.childNodes[0].className == "s") {
			e.firstChild.childNodes[0].style.display = 'none';
		}
	}
	if (e.firstChild.childNodes[1]) {
		if (e.firstChild.childNodes[1].className == "s") {
			e.firstChild.childNodes[1].style.display = 'none';
		}
	}
}

function outMn3(e)
{
	e.style.backgroundImage = 'url("/images/menu/arrow.png")';
	e.style.backgroundPosition = '6px 8px';
	e.firstChild.style.backgroundImage = 'none';
	e.firstChild.firstChild.style.backgroundImage = 'none';
}

function overBtn(e)
{
	e.style.backgroundImage = 'url("/images/button_over.png")';
}
function outBtn(e)
{
	e.style.backgroundImage = 'url("/images/button.png")';
}

function overBtn2(id)
{
	if ((document.getElementById('product-'+id).style.backgroundImage) != 'url(/images/wait.gif)') {
		$('#product-' + id + '').css({
			"background-image" : "url(/images/button_right_over.png)"
		});
	}
}
function outBtn2(id)
{
	if ((document.getElementById('product-'+id).style.backgroundImage) != 'url(/images/wait.gif)') {
		$('#product-' + id + '').css({
			"background-image" : "url(/images/button_right.png)"
		});
	}
}

function overBtn3(e)
{
	e.firstChild.style.backgroundImage = 'url("/images/button2_left_over.png")';
}
function outBtn3(e)
{
	e.firstChild.style.backgroundImage = 'url("/images/button2_left.png")';
}

function overBtn4(id)
{
	$('#product-' + id + '').css({
		"background-image" : "url(/images/in-cart.png)"
	});	
}
function outBtn4(id)
{
	$('#product-' + id + '').css({
		"background-image" : "url(/images/in-cart_over.png)"
	});	
}


function show_hidden(id) {
	var faq = document.getElementById("faq" + id);
	var title = document.getElementById("title" + id);
	if (faq.style.display == "block") {
		faq.style.display = "none";
		title.childNodes[0].src = "/images/arrow.png";
		title.childNodes[2].style.fontWeight = "normal";
		title.childNodes[2].style.textDecoration = "underline";
	}
	else {
		faq.style.display = "block";
		title.childNodes[0].src = "/images/arrow_over.png";
		title.childNodes[2].style.fontWeight = "bolder";
		title.childNodes[2].style.textDecoration = "none";
	}
}

function imgZoom(url_img){
	document.getElementById("product_img").src = url_img;
}

function is_number(e)
{
	var key = e.keyCode;
	if (!key) {
		key = e.charCode;
	}
    if (key > 31)
        if (key < 37 || key > 40)
            if (key < 48 || key > 57)
                return false;
}

function sms_subscribe()
{
	var phone = document.getElementById("sms_phone").value;
	if (phone == "") {
		alert("Phone is empty");
		return false;
	}
	JsHttpRequest.query(
			'/sms_subscribe.php', // backend
			{
				'phone': phone
            },
            // Function is called when an answer arrives. 
            function(result, errors) {
            	document.getElementById("sms_subscribe").innerHTML = result;
            },
            false  // do not disable caching
    );
    return false;
}


var mnTimeoutConst = 1000;     // время задержки перед открытием и закрытием менюшки

var timeoutIdClose = new Array();
var timeoutIdOpen = new Array();

function preloadI() {
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadI.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

function mnO(idNum)
{
    if ((typeof(is_IE) != "undefined") && (window.location.pathname=="/smartclip/SmartClip_Update_Zone.php")) {
        return;
    }
    if ((typeof idNum == 'object') && (idNum.constructor == Array)) {
        for (var i = 0; i < idNum.length; i++) {
            if (timeoutIdClose[idNum[i]]) {
                clearTimeout(timeoutIdClose[idNum[i]]);
                timeoutIdClose[idNum[i]] = 0;
            }
            if (document.getElementById("mn" + idNum[i])) {
//                if (document.getElementById("mna" + idNum[i])) {
////                    document.getElementById("mna" + idNum[i]).style.backgroundColor = "#ff6600"; //"#848484";
////                    document.getElementById("mna" + idNum[i]).style.color = "#ffffff"; //"#848484";
//                }
                timeoutIdOpen[idNum[i]] = setTimeout('mnOpen('+ idNum[i] + ')', mnTimeoutConst);
            }
        }
        for (var j=1; j < 1000; j++) {
            for (var k = 0; k < idNum.length; k++) {
                if (j != idNum[k]) {
                    if (timeoutIdClose[j]) {
                        clearTimeout(timeoutIdOpen[j]);
                        timeoutIdOpen[j] = 0;
                    }
                }
            }
        }
    } else {
        if (timeoutIdClose[idNum]) {
            clearTimeout(timeoutIdClose[idNum]);
            timeoutIdClose[idNum] = 0;
        }
        for (var j=1; j < 10000; j++) {
            if (j != idNum) {
                if (timeoutIdClose[j]) {
                    clearTimeout(timeoutIdOpen[j]);
                    timeoutIdOpen[j] = 0;
                }
            }
        }
        if (document.getElementById("mn" + idNum)) {
//            if (document.getElementById("mna" + idNum)) {
////                document.getElementById("mna" + idNum).style.backgroundColor = "#ff6600";//"#848484";
////                document.getElementById("mna" + idNum).style.color = "#ffffff";//"#848484";
//            }
            timeoutIdOpen[idNum] = setTimeout('mnOpen('+ idNum + ')', mnTimeoutConst);
        }
    }
}
function mnOpen(idNum)
{
    document.getElementById("mn" + idNum).style.display = "block"; 
	document.getElementById("mn" + idNum).style.border = "1px solid black";
    if (typeof(is_IE) != "undefined") {
        var aElement = document.getElementById("mn" + idNum);
        var aClientX = 0;
        var aClientY = 0;

        while (aElement){

            if (aElement.style) {
                if (aElement.style.position == "relative") {
                    break;
                }
            }

            aClientX = aClientX + aElement.offsetLeft;
            aClientY = aClientY + aElement.offsetTop;
            aElement = aElement.offsetParent;
        }

        var mnFrame = document.getElementById("mnFrame");
        var iframe = document.createElement('iframe');
        iframe.frameborder = "1px solid black";
        iframe.id = "mnFrame" + idNum;
        mnFrame.appendChild(iframe);

        document.getElementById("mnFrame" + idNum).style.left = aClientX+2;
        document.getElementById("mnFrame" + idNum).style.top = aClientY+2;

        document.getElementById("mnFrame" + idNum).style.width = document.getElementById("mn" + idNum).clientWidth+1+"px";
        document.getElementById("mnFrame" + idNum).style.height = document.getElementById("mn" + idNum).clientHeight+1+"px";
        document.getElementById("mnFrame" + idNum).style.display = "block";
    } 
}

function mnC(idNum)
{
    if ((typeof(is_IE) != "undefined") && (window.location.pathname=="/smartclip/SmartClip_Update_Zone.php")) {
        return;
    }
    if ((typeof idNum == 'object') && (idNum.constructor == Array)) {
        idNum = idNum.sort(function (a,b) { return b-a; });
        for (var i = 0; i < idNum.length; i++) {
            if (document.getElementById("mn" + idNum[i])) {
               if (document.getElementById("mna" + idNum[i])) {
//                    if (document.getElementById("mna" + idNum[i]).className == "rootl") {
////                        document.getElementById("mna" + idNum[i]).style.backgroundColor = "#F4F4F4";
////                        document.getElementById("mna" + idNum[i]).style.color = "#333333";
//                    }
//                    else {
//            	   			document.getElementById("mn" + idNum[i]).style.border = "1px solid black";
////                        document.getElementById("mna" + idNum[i]).style.color = "#333333";
//                    }
               }
                timeoutIdClose[idNum[i]] = setTimeout('mnClose('+ idNum[i] + ')', mnTimeoutConst);
            }
        }
    }
    else {
        if (document.getElementById("mn" + idNum)) {
//            if (document.getElementById("mna" + idNum)) {
////                if (document.getElementById("mna" + idNum).className == "rootl") {
//////                    document.getElementById("mna" + idNum).style.backgroundColor = "#F4F4F4";
//////                    document.getElementById("mna" + idNum).style.color = "#333333";
////                }
////                else {
//////                    document.getElementById("mna" + idNum).style.backgroundColor = "#F4F4F4";
//////                    document.getElementById("mna" + idNum).style.color = "#333333";
////                }
//            }
            timeoutIdClose[idNum] = setTimeout('mnClose('+ idNum + ')', mnTimeoutConst);
        }
    }
}

function mnClose(idNum)
{
    document.getElementById("mn" + idNum).style.display = "none";
    if (typeof(is_IE) != "undefined") {
        if (document.getElementById("mnFrame" + idNum)) {
            document.getElementById("mnFrame").removeChild(document.getElementById("mnFrame" + idNum));
        }
    }
}

function fixArrowMargin()
{
    for (var i = 0; i < 1000; i++) {
        var el = document.getElementById("mna" + i);
        if (el) {
            if ((el.className == "root") || (el.className == "rootl")) {
                if (el.parentNode.clientHeight == 38) {
                    if (el.firstChild.tagName == "IMG") {
                        el.firstChild.style.marginTop = "20px";
                    }
                }
                
            }
        }
    }
}

function DeleteFile(button, path)
{
	if (confirm("Уверены, что хотите удалить файл: path?")) {
		post = 'path=' + path ;   
		url = typeof(language)  == 'undefined' ? "/admin/deletefile" : language + "/admin/deletefile";
		$.post(url, post, function(){
		    $(button).parent().remove();
		});
		}
}

function sendMail()
{
	url = typeof(language)  == 'undefined' ? "/preorder/ordersummary" : language + "/preorder/ordersummary";
}

function sortForBrand(brand)
{
	$("#brand option:selected").each(function () {
		id = $(this).attr('id');
		document.selectForm.action = id;
	});
}
function SaveComment(id) {
	post = 'id=' + id + '&comment=' + $("#comment-" + id ).attr('value') ;
	url = typeof(language)  == 'undefined' ? "/cart/savecomment" : language + "/cart/savecomment";
	$.post(url, post, function(){

	});
}
function SaveCommentGeneral() {
	post = 'comment=' + $("#comment").attr('value') ;
	url = typeof(language)  == 'undefined' ? "/cart/savecommentgeneral" : language + "/cart/savecommentgeneral";
	$.post(url, post, function(){

	});
}

$(document).ready(function(){
	$(document).click(function(event) {
		if ($(event.target).closest('.login-div').length == 0) $("#login-div").hide();
	});
});
