dom = (document.getElementById)? true : false;
nn4 = (document.layers)? true : false;
ie = (document.all)? true : false;
ie4 = (!dom && ie)? true : false;
moz = (dom && (navigator.appName=="Netscape")) ? true : false;

var itemRef="null", styleSwitch="null";

if (nn4) {
    itemRef = "document";
    styleSwitch = "";
} else if (ie4 || dom) {
    itemRef = "document.all";
    styleSwitch = ".style";
}
if (moz) {
    itemRef = "document.getElementById";
    styleSwitch = ".style";
}

var imgFolder ="/img/";

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		kol = newImage(imgFolder+"bgr_kol-" + clr + ".gif");
		auto = newImage(imgFolder+"bgr_auto-" + clr + ".gif");
		mebel = newImage(imgFolder+"bgr_mebel-" + clr + ".gif");
		uhod = newImage(imgFolder+"bgr_uhod-" + clr + ".gif");
		korm = newImage(imgFolder+"bgr_korm-" + clr + ".gif");
		safety = newImage(imgFolder+"bgr_safety-" + clr + ".gif");

		preloadFlag = true;
	}
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeTip() {
	if (document.images && (preloadTipsFlag == true)) {
		for (var i=0; i<changeTip.arguments.length; i+=2) {
			document[changeTip.arguments[i]].src = changeTip.arguments[i+1];
		}
	}
}


function resetBgr(item) {
    if (!moz) {
        eval(itemRef + '["' + item + '"]' + styleSwitch + '.background="url(' + imgFolder + 'bgr_' + currCat + '-' + clr + '.gif) no-repeat"');
    }
    else {
        eval(itemRef + '("' + item + '")' + styleSwitch + '.background="url(' + imgFolder + 'bgr_' + currCat + '-' + clr + '.gif) no-repeat"');
    } 
}

function changeBgr(item, cat) {
    if (!moz) {
        eval(itemRef + '["' + item + '"]' + styleSwitch + '.background="url(' + imgFolder + 'bgr_' + cat + '-' + clr + '.gif) no-repeat"');
    }
    else {
        eval(itemRef + '("' + item + '")' + styleSwitch + '.background="url(' + imgFolder + 'bgr_' + cat + '-' + clr + '.gif) no-repeat"');
    }
}

//Передача параметров между страницами
function getParam(sParamName){
    var Params = location.search.substring(1).split("&"); // отсекаем «?» и вносим переменные и их значения в массив
    var variable = "";
    for (var i = 0; i < Params.length; i++){ // пробегаем весь массив
        if (Params[i].split("=")[0] == sParamName){ // если это искомая переменная — бинго!
            if (Params[i].split("=").length > 1) variable = Params[i].split("=")[1]; // если значение параметра задано, то возвращаем его
            return variable;
        }
    }
    return "";
}

// Расцветки и всплывающие картинки в Автокреслах

function changeColor(color) {
		currcolor = color;
		//eval(itemRef+'("model")'+styleSwitch+'.background="url('+imgFolder+'bgr_zagruzka.gif) no-repeat"');
		var bgrFile = imgFolder+modelName+'_'+color+'.jpg';
		eval(itemRef+'("model")'+styleSwitch+'.background="url('+bgrFile+') no-repeat"');
		var bigimageFile = imgFolder+modelName+"_"+color+"_big.jpg";
		eval(itemRef+'("zoom").href="'+bigimageFile+'"');
	}


	function hidehint() {
		eval(itemRef+'("hint")'+styleSwitch+'.display="none"');
	}

	function showhint(hintname) {
		eval('document["hintimg"].src="'+imgFolder+'hint_load.gif"');
		var hintFile = imgFolder+modelName+'_'+hintname+'.jpg';
		hintimage = newImage(hintFile);
		document["hintimg"].src=hintimage.src;
		eval(itemRef+'("hint")'+styleSwitch+'.display="block"');
	}

	function bigimageWin () {
		var img = imgFolder+modelName+"_"+currcolor+"_big.jpg";
		var location = "/bigimage.html?img="+img;
		popupWin = window.open(location, 'bigimg', 'resizable=yes,scrollbars=yes,width=610,height=610,top=0'); popupWin.focus();
	}
