var marked_row = new Array;

function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
	var theCells = null;

	// 1. Pointer and mark feature are disabled or the browser can't get the
	//    row -> exits
	if ((thePointerColor == '' && theMarkColor == '') || typeof(theRow.style) == 'undefined') {
		return false;
	}

	// 2. Gets the current row and exits if the browser can't get it
	if (typeof(document.getElementsByTagName) != 'undefined') {
		theCells = theRow.getElementsByTagName('td');
	}
	else if (typeof(theRow.cells) != 'undefined') {
		theCells = theRow.cells;
	} else {
		return false;
	}

	// 3. Gets the current color...
	var rowCellsCnt  = theCells.length;
	var domDetect    = null;
	var currentColor = null;
	var newColor     = null;
	// 3.1 ... with DOM compatible browsers except Opera that does not return
	//         valid values with "getAttribute"
	if (typeof(window.opera) == 'undefined' && typeof(theCells[0].getAttribute) != 'undefined') {
		currentColor = theCells[0].getAttribute('bgcolor');
		domDetect    = true;
	}

	// 3.2 ... with other browsers
	else {
		currentColor = theCells[0].style.backgroundColor;
		domDetect    = false;
	} // end 3

	// 4. Defines the new color
	// 4.1 Current color is the default one

	if (currentColor == null || currentColor == '' || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
		if (theAction == 'over' && thePointerColor != '') {
			newColor= thePointerColor;
		} else if (theAction == 'click' && theMarkColor != '') {
			newColor= theMarkColor;
			marked_row[theRowNum] = true;
		}
	}
	// 4.1.2 Current color is the pointer one
	else if (currentColor.toLowerCase() == thePointerColor.toLowerCase() && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
		if (theAction == 'out') {
			newColor= theDefaultColor;
		} else if (theAction == 'click' && theMarkColor != '') {
			newColor= theMarkColor;
			marked_row[theRowNum] = true;
		}
	}
	// 4.1.3 Current color is the marker one
	else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
		if (theAction == 'click') {
			newColor			= (thePointerColor != '')
								? theDefaultColor
								: thePointerColor;
			marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
								? true
								: null;
		}
	} // end 4

	// 5. Sets the new color...
	if (newColor) {
		var c = null;
		// 5.1 ... with DOM compatible browsers except Opera
		if (domDetect) {
			for (c = 0; c < rowCellsCnt; c++) {
				theCells[c].setAttribute('bgcolor', newColor, 0);
			} // end for
		}
		// 5.2 ... with other browsers
		else {
			for (c = 0; c < rowCellsCnt; c++) {
				theCells[c].style.backgroundColor = newColor;
			}
		}
	} // end 5

	return true;
}

function isEmpty(s){
	if(s == null || s.length == 0){
		return true;
	}
	return !/\S/.test(s);
}

function errorMessage(node, text){
	if(document.getElementById && document.getElementById(node)){
		text_cont =document.getElementById(node);
		message = document.createTextNode(text);
		text_cont.style.color="red";
		text_cont.style.fontSize="8pt";

		if(text_cont.firstChild){
			text_cont.firstChild.data = text;
		} else {
			text_cont.appendChild(text);
		}
	} else {
		alert(text);
	}
}

var sImg = new Image();
sImg.src = "../images/loading-1.gif";
var tm;
var imageCount = 0;
var imageArrayStr = ['../images/loading-1.gif','../images/loading-2.gif', '../images/loading-3.gif', '../images/loading-4.gif', '../images/loading-5.gif', '../images/loading-6.gif', '../images/loading-7.gif', '../images/loading-8.gif', '../images/loading-9.gif', '../images/loading-10.gif', '../images/loading-11.gif', '../images/loading-12.gif', '../images/loading-13.gif'];


var imageArray = new Array();

for (i = 0; i < imageArrayStr.length; i++) {
	timg = new Image();
	timg.src = imageArrayStr[i];
	imageArray[i] = timg;
}

function ImageNext() {
	if (imageCount!=imageArray.length-1) {
		imageCount++;
	} else {
		imageCount = 0;
	}

	img = document.getElementById('SearchSplashImage');
	img.src=imageArray[imageCount].src;
}

function ShowSearchSplash(){
	tm=setInterval('ImageNext()', 2000);
}




var timeout = null;
function doLoadUp() {
	if (timeout) clearTimeout(timeout);
	timeout = setTimeout(doLoad, 1000);
}

function showItem(elem_id){
	if(document.getElementById){
		if(document.getElementById(elem_id).style.display == "none"){
			document.getElementById(elem_id).style.display="block";
		} else {
			document.getElementById(elem_id).style.display="none";
		}
	}
}

var timeout = null;
function doLoadCraneUp() {
	if (timeout) clearTimeout(timeout);
	timeout = setTimeout(doLoadCrane, 1000);
}

var egURL = [118, 119, 120, 121, 122, 124, 125, 126];

function egImageNext() {
	if (egimageCount!=egimageArray.length-1) {
		egimageCount++;
	} else {
		egimageCount= 0;
	}

	imgUrl = document.getElementById('egurl');
	img = document.getElementById('eg');
	imgtitle = document.getElementById('egtitle');

	imgUrl.href = '?p='+egURL[egimageCount];
	img.src=egimageArray[egimageCount].src;
	imgtitle.innerHTML = egTitle[egimageCount];
}

function egShow(){
	egtm=setInterval('egImageNext()', 2000);
}

function isNumber(field, event){
	var key, keyChar;

	if(window.event){
		key = window.event.keyCode;
	} else if(event){
		key = event.which;
	} else {
		return true;
	}

	if(key == null || key == 0 || key == 8 || key == 13 || key == 27 || key == 46 || key == 45 || key == 9)
		return true;

		keyChar = String.fromCharCode(key);

		if(/\d/.test(keyChar)){
			return true;
		} else {
			alert('Поле принимает только числа');
			return false;
		}
}

function addFormUrl(action){
	if(document.shopcart){
		document.shopcart.action = "?p=49&action="+action;
	}
}

function BForm(){
	var bulForm = document.getElementById('bform');
	if(bulForm.style.display == 'none'){
		bulForm.style.display = 'block';
	} else {
		bulForm.style.display = 'none';
	}
}