var Goods = new Object();
Goods["mt5"] 				= "Цилиндр МТ5";
Goods["7x7"] 				= "Цилиндр 7х7";
Goods["3in1"] 				= "Цилиндр Светофор";
Goods["classic"] 			= "Цилиндр Classic";
Goods["inter"] 				= "Цилиндр Interactive";
Goods["roundpadlock"] 		= "Навесной замок ШАЙБА";
Goods["padlockc1"] 			= "Навесной замок C серия";
Goods["padlocktsr"] 		= "Навесной замок TSR";
Goods["padlocke1"] 			= "Навесной замок Е серия скользящий засов";
Goods["padlockc2"] 			= "Навесной замок C серия скользящий засов";
Goods["padlocke2"] 			= "Навесной замок Е серия";
Goods["padlocke3"] 			= "Навесной замок Е серия с защитой дуги";
Goods["hasplock"] 			= "Навесной замок HaspLock";
Goods["hinge"] 				= "Петли для навесного замка";
Goods["roundhinge"] 		= "Петли для круглого навесного замка";
Goods["haspprotector"] 		= "Защита навесного замка";
Goods["shackleprotector"] 	= "Защита дуги";

var Cost = new Object();
Cost["mt5"] 				= "5500";
Cost["7x7"] 				= "1800";
Cost["3in1"] 				= "3800";
Cost["classic"] 			= "3900";
Cost["inter"] 				= "4100";
Cost["roundpadlock"] 		= "3200";
Cost["padlockc1"] 			= "4500";
Cost["padlocktsr"] 			= "4000";
Cost["padlocke1"] 			= "5300";
Cost["padlockc2"] 			= "5200";
Cost["padlocke2"] 			= "5500";
Cost["padlocke3"] 			= "5800";
Cost["hasplock"] 			= "5400";
Cost["hinge"] 				= "900";
Cost["roundhinge"] 			= "1100";
Cost["haspprotector"] 		= "2500";
Cost["shackleprotector"] 	= "700";

var Img = new Object();
Img["mt5"]	 				= "images/MT5_46_40.jpg";
Img["7x7"] 					= "images/7x7_56_40.jpg";
Img["3in1"] 				= "images/3in1_68_40.jpg";
Img["classic"] 				= "images/class_55_40.jpg";
Img["inter"] 				= "images/inter_42_40.jpg";
Img["roundpadlock"] 		= "images/Round_Padlock_39_40.jpg";
Img["padlockc1"] 			= "images/C_Series_new_28_40.jpg";
Img["padlocktsr"] 			= "images/TSR_lock_29_40.jpg";
Img["padlocke1"] 			= "images/Sbe_43_40.jpg";
Img["padlockc2"] 			= "images/Sliding_Bolt_39_40.jpg";
Img["padlocke2"] 			= "images/E_Ser_23_40.jpg";
Img["padlocke3"] 			= "images/E_Ser_2_28_40.jpg";
Img["hasplock"] 			= "images/HaspLock_50_40.jpg";
Img["hinge"] 				= "images/Hasps_for_Glass_54_30.jpg";
Img["roundhinge"] 			= "images/Hasp_Hockey_Puck1_new_72_40.jpg";
Img["haspprotector"] 		= "images/Hasps_32_40.jpg";
Img["shackleprotector"] 	= "images/Shackle_protector_44_40.jpg";

if (top != this) {
	top.location = location;
}

function setCookie(c_name,c_value)
{
	var cookie = c_name +"=" + c_value + "; ";
	document.cookie = cookie;
}

function myEventHandler ()
{
	var count = 1;
	for (var val in Goods)
	{
		if (this.id == val)
		{
			if (document.cookie.length > 0)
			{
				b = document.cookie.indexOf(this.id + "=");
				if (b != -1)
				{
					b = b + (this.id + "=").length;
					e = document.cookie.indexOf(';',b);
					if (e == -1)
						e = document.cookie.length;
					if (!isNaN(document.cookie.substring(b,e)))
						count = document.cookie.substring(b,e) * 1 + 1;
						//alert(count);
				}
			}
			document.cookie = this.id + "=" + count + ";";
		}
	}
}

function onmouseoverBasket ()
{
	this.className = 'fullBasket';
}

function onmouseoutBasket ()
{
	this.className = 'emptyBasket';
}

function delRow()
{
	//alert(this.id.substring(1));
	var row = document.getElementById(this.id.substring(1));
	var s = 0;
	if (row)
	{
		row.parentNode.removeChild(row);
		b = document.cookie.indexOf(this.id.substring(1) + "=");
		if (b != -1)
			document.cookie = this.id.substring(1) + "=" + 
                "; expires=Thu, 01-Jan-70 00:00:01 GMT";

	}
	for (var val in Goods)
	{
		if (document.cookie.length > 0)
		{
			b = document.cookie.indexOf(val + "=");
			if (b != -1)
			{
				e = document.cookie.indexOf(';',b);
				if (e == -1)
					e = document.cookie.length;
					b = document.cookie.indexOf('=',b) + 1;
					
					for (var v in Cost)
					{
						if (v == val)
						{
							if (!isNaN(Cost[v]) && !isNaN(document.cookie.substring(b,e)))
							{
								s = s + Cost[v]*document.cookie.substring(b,e);
							}
						}
					}
			}
		}
	}
	var newCell4TFoot = document.getElementById('newCell4TFoot');
	if (newCell4TFoot)
	{
		newCell4TFoot.firstChild.nodeValue = s;
	}
}

function empty(){}

function preSaleTable ()
{
	var div = document.getElementById('preSale');
	var table = document.getElementById('table');
	var s = 0;
	if (!table)
	{
		var table = document.createElement("TABLE");
		table.id = 'table';
		table.className = 'tTable';
		div.appendChild(table);
			if(!table.tHead)
			{
				var tHead = document.createElement("THEAD");
				table.appendChild(tHead);
				newRow = table.tHead.insertRow(0);
				newCell1 = newRow.insertCell(0);
				newCell1.className = 'tBodyCellC';
				newCell1.width = '380';
				var text1 = document.createTextNode('Наименование товара');
				newCell1.appendChild(text1);
				newCell2 = newRow.insertCell(1);
				newCell2.className = 'tBodyCellC';
				newCell2.width = '100';
				var text2 = document.createTextNode('Количество');
				newCell2.appendChild(text2);
				newCell3 = newRow.insertCell(2);
				newCell3.className = 'tBodyCellC';
				newCell3.width = '100';
				var text3 = document.createTextNode('Цена за шт');
				newCell3.appendChild(text3);
				newCell4 = newRow.insertCell(3);
				newCell4.className = 'tBodyCellC';
				newCell4.width = '100';
				var text4 = document.createTextNode('Сумма');
				newCell4.appendChild(text4);
				newCell5 = newRow.insertCell(4);
				newCell5.className = 'tBodyCellC';
				newCell5.width = '100';
				var text5 = document.createTextNode('Удалить');
				newCell5.appendChild(text5);
				table.tHead.className = 'tHead';
			}
	}
	for (var val in Goods)
	{
		if (document.cookie.length > 0)
		{
			b = document.cookie.indexOf(val + "=");
			if (b != -1)
			{
				e = document.cookie.indexOf(';',b);
				if (e == -1)
					e = document.cookie.length;
					var tBody = document.getElementById('tbody');
					if (!tBody)
					{
						var tBody = document.createElement('TBODY');
						tBody.id = 'tbody';
						tBody.className = 'tBody';
						table.appendChild(tBody);
					}
					b = document.cookie.indexOf('=',b) + 1;

					newRow = table.tBodies[0].insertRow(table.tBodies[0].rows.length);
					newRow.id = val;
					newRow.className = 'tBodyRow';
					
					newCell1 = newRow.insertCell(newRow.cells.length);
					for (var im in Img)
					{
						if (im == val)
						{
							newImg = document.createElement('IMG');
							newImg.src = Img[im];
							div = document.createElement('DIV');
							newCell1.appendChild(div);
							div.className = 'divSmallImage';
							div.appendChild(newImg);
							//alert(Img[im]);
						}
					}
					var text1 = document.createTextNode(Goods[val]);
					newCell1.className = 'tBodyCellL';
					p = document.createElement('P');
					newCell1.appendChild(p);
					p.appendChild(text1);
					newCell2 = newRow.insertCell(newRow.cells.length);
					var text2 = document.createTextNode(document.cookie.substring(b,e));
					newCell2.className = 'tBodyCellC';
					newCell2.appendChild(text2);
					for (var v in Cost)
					{
						if (v == val)
						{
							var text3 = document.createTextNode(Cost[v]);
							if (!isNaN(Cost[v]) && !isNaN(document.cookie.substring(b,e)))
							{
								var text4 = document.createTextNode(Cost[v]*document.cookie.substring(b,e));
								s = s + Cost[v]*document.cookie.substring(b,e);
								//alert(s);
							}
						}
					}
					newCell3 = newRow.insertCell(newRow.cells.length);
					newCell3.className = 'tBodyCellR';
					newCell3.appendChild(text3);
//					if (!isNaN(text3*document.cookie.substring(b,e)))
	//				{
		//			}
					newCell4 = newRow.insertCell(newRow.cells.length);
					newCell4.className = 'tBodyCellR';
					newCell4.appendChild(text4);
					newCell5 = newRow.insertCell(newRow.cells.length);
					var a = document.createElement("A");
					a.href = 'javascript:empty()';
					var div = document.createElement("DIV");
					div.height = '32';
					var img = document.createElement("IMG");
					img.src = 'images/remove32.png';
					img.title = 'Удалить';
					img.alt = 'Удалить';
					img.border = '0';
					img.id = 'a' + val;
					img.onclick = delRow;
					newCell5.className = 'tBodyCellC';
					newCell5.appendChild(div);
					div.appendChild(a);
					a.appendChild(img);
					
				//if (!isNaN(document.cookie.substring(b,e)))
					//count = document.cookie.substring(b,e) * 1 + 1;
			}
		}
	}
		if(!table.tFoot)
		{
			var tFoot = document.createElement("TFOOT");
			table.appendChild(tFoot);
			tFoot.className = 'tFoot';
			newRow = table.tFoot.insertRow(0);
			newCell1 = newRow.insertCell(0);
			//var text1 = document.createTextNode('Итого :');
			//newCell1.appendChild(text1);
			newCell2 = newRow.insertCell(1);
			//var text2 = document.createTextNode('Итого :');
			//newCell2.appendChild(text2);
			newCell3 = newRow.insertCell(2);
			var text3 = document.createTextNode('Итого: ');
			newCell3.appendChild(text3);
			newCell3.className = 'tBodyCellRNoFrame';
			newCell4 = newRow.insertCell(3);
			//newCell4.id = 'newCell4';
			//newCell4.className = 'tFoot';
			var text4 = document.createTextNode(s);
			newCell4.appendChild(text4);
			newCell4.id = 'newCell4TFoot';
			newCell4.className = 'tBodyCellR';
			newCell5 = newRow.insertCell(4);
			//var text5 = document.createTextNode('Итого :');
			//newCell5.appendChild(text5);
			//table.tFoot.className = 'tFoot';
		}
			//else
			//{
			//	var newCell4 = document.getElementById('newCell4');
			//	var text4 = document.createTextNode(s);
			//	newCell4.appendChild(text4);
			//}
}

function onfocussearchField ()
{
	if (!this.value.length)
		this.className = 'search-fieldFocus';
}

function onblursearchField ()
{
	if (!this.value.length)
		this.className = 'search-field';
}

function onfocussearchFieldY ()
{
	if (!this.value.length)
		this.className = 'search-fieldFocus';
}

function onblursearchFieldY ()
{
	if (!this.value.length)
		this.className = 'search-field-Y';
}

window.onload = function ()
{
	var allA = document.getElementsByTagName('A');
	for(var i=0; i < allA.length; i++)
		if (allA[i].title == 'Купить')
		{
			allA[i].onclick = myEventHandler;
		}
	var bascet = document.getElementById('d');
	if (bascet)
	{
		bascet.onmouseover = onmouseoverBasket;
		bascet.onmouseout = onmouseoutBasket;
	}
	var searchField = document.getElementById('searchField');
	if (searchField)
	{
		searchField.onfocus = onfocussearchField;
		searchField.onblur = onblursearchField;
	}
	var searchFieldY = document.getElementById('searchFieldY');
	if (searchFieldY)
	{
		searchFieldY.onfocus = onfocussearchFieldY;
		searchFieldY.onblur = onblursearchFieldY;
	}
	var div = document.getElementById('preSale');
	if (div) preSaleTable();

	for (var val in Cost)
	{
		var H2 = document.getElementById('cost' + val);
		if (H2)
			if (H2.firstChild)
				H2.firstChild.nodeValue = Cost[val] + ' руб';
			else
			{
				var t = document.createTextNode(Cost[val] + ' руб');
				H2.appendChild(t);
			}
	}
	/*
	var allH2 = document.getElementsByTagName('H2');
	for(var i=0; i < allH2.length; i++)
	{
		if (allH2[i].parentNode.nextSibling.nodeType == 3)
			goodId = allH2[i].parentNode.nextSibling.nextSibling.firstChild.nextSibling.id;
		else
			goodId = allH2[i].parentNode.nextSibling.firstChild.id;
		if (goodId)
		{
			for (var val in Cost)
			{
				if (goodId == val)
					allH2[i].firstChild.nodeValue = Cost[val] + ' руб';
					//alert(Cost[val]);
			}
		}
	}
	*/
}


