CompareUrlDataBas = '/add_to_backet.php';
CompareWarez = '/add_to_compare.phtm';


// массив с флагами "открыт/закрыт" пунктов меню
var inelem = [];

var timerOver = [];
var timerOut = [];

function loadSource(url) {
		document.getElementById('HiddenFrame').src = url;
}

function AddToCart(warez_id, name)
{

id_tov="";
kol_tov="0";

if (name =="") 
{
	id_tov=warez_id;
	kol_tov="1";
}
else 
{
	if (name.elements.length > 0)
	{
		for (var i=0; i<(name.elements.length); i++)
		{
			if ((name.elements[i].type == "text") && (name.elements[i].value > 0) || (name.elements[i].type == "hidden"))
			{
				id_tov = warez_id;
				kol_tov = name.elements[i].value;
			}
		}
	}

}


if ((id_tov != "")&&(kol_tov != ""))
{
	loadSource(CompareUrlDataBas + "?ware_id=" + id_tov + "&count=" + kol_tov);
	//alert(CompareUrlDataBas + "?ware_id=" + id_tov + "&count=" + kol_tov);
	id_tov="";
	kol_tov="0";
}
}



startList = function() {
	if (document.getElementById) {
		// получаем список с пунктами меню
		navRoot = document.getElementById("nav");
		//location="about:blank";
		// для всех дочерних нод списка с меню
		for (i=0; i<navRoot.childNodes.length; i++) {
			// текущая дочерняя нода
			node = navRoot.childNodes[i];

			// если текущая нода LI и она не является активным пунктом меню (он всегда открыт) и не является разделительной линией
			if ((node.nodeName=="LI") && (node.className.indexOf("cur") == -1) && (node.className.indexOf("line")==-1)) {

				// инициализируем флаг "открыт/закрыт"
				inelem[i] = false;
				
				var h3 = node.getElementsByTagName("h3");
				h3 = h3[0];
				

				// назначаем событие на нажатие мышки
				h3.onmousedown = function(ii) {
					return function() {
						inelem[ii] = true;

          						// сбрасываем все флаги кроме текущего, текущий наоборот взводим
          					for(k = 0; k < inelem.length; k++) {
          						inelem[k] = k == ii;
          						}

								// навсякий случай пробегаем по остальным пунктам меню и закрываем их
								for (k = 0; k < navRoot.childNodes.length; k++) {
									siblingNode = this.parentNode.parentNode.childNodes[k];
									if ((siblingNode.nodeName=="LI") && (siblingNode.className.indexOf("cur") == -1) && (siblingNode.className.indexOf("line")==-1)) {
										if(inelem[k])
											showLI(siblingNode, k);
										else
								 			hideLI(siblingNode, k);
									}
								}
	
        						// показываем текущий пункт меню
        						showLI(this.parentNode, ii);
        				}

				}(i);


			}
		}
	}
}


function showitem(id, height, maxheight) {
	var navRoot = document.getElementById("nav");
	var li = navRoot.childNodes[id];

	var lists = li.getElementsByTagName("ul");
	if (lists.length > 0) {
		var list = lists[0];

       	
       	height += Math.round((maxheight - height) / 1.2);
			
       	if (height >= maxheight){
       		list.style.height="auto";
//       		list.style.height=maxheight;
       	} else {
      		if (li.className.indexOf("active") == -1) {
      			li.className+=" active";
      		}
       		list.style.height = height+'px';
       		timerOver[id] = setTimeout('showitem('+id+', '+height+', '+maxheight+')', 1);
			}
 	}
}


showLI = function(li, id) {
     	var lists = li.getElementsByTagName("ul");
		if (lists.length > 0) {
	     	var list = lists[0];
       	if (li.className.indexOf("active") != -1) {
       		inelem[id] = false;
			list.style.height = "auto";
       		hideLI(li, id);
       		return;
       	}

       	list.style.top = '-10000px';
       	list.style.left = '-10000px';
       	list.style.position = "absolute";
       	list.style.width = '184px';
       	list.style.height = "auto";
       	list.style.display = "block";
       	var maxHeight =  Math.round(list.offsetHeight);
		//alert(maxHeight);
       	list.style.display = "";
       	list.style.position = "";
       	list.style.left = '';
       	list.style.width = '';

       	list.style.height="0px";

       	listheight = parseInt(list.style.height);
			
       	timerOver[id] = setTimeout('showitem('+id+', '+listheight+', '+maxHeight+')', 1);
		}
}

function hideitem(id, height) {
	var navRoot = document.getElementById("nav");
	var li = navRoot.childNodes[id];

	var lists = li.getElementsByTagName("ul");
	var list = lists[0];

       	height -= Math.round(height / 2);
       	if (height <= 0) {
       		list.style.height = '0px';
       		li.className=li.className.replace("active", "");
       	} else {
       		list.style.height = height+'px';
       		timerOut[id] = setTimeout('hideitem('+id+', '+height+')', 1);
       	}
}


hideLI = function(li, id) {
	if(inelem[id]) return;

       	var lists = li.getElementsByTagName("ul");
			if (lists.length > 0) {
       	var list = lists[0];
			

			if (list.style.height == 'auto' && list.offsetHeight > 0) {
				list.style.height = (list.offsetHeight) + "px";
			} else {
		//		alert(list.style.height);
				list.style.height = "0px";
			}
		
			listheight = parseInt(list.style.height);
		       	timerOut[id] = setTimeout('hideitem('+id+', '+listheight+');', 1);
			}
}


window.onload=startList;



function doFeedbackRu(form) {
	if (!(form.elements[0].value == '' || form.elements[3].value == '' || form.elements[4].value == '' || form.elements[5].value == '' || form.elements[9].value == '' || form.elements[18].value == '')) {
		if (!isEmail(form.elements[9].value)) {
			alert('Некорректный e-mail адрес!');
			return false;
		}
	} else {
		alert('Не все обязательные поля заполнены!');
		return false;
	}
}


function doFeedbackDe(form) {
	if (!(form.elements[0].value == '' || form.elements[3].value == '' || form.elements[4].value == '' || form.elements[5].value == '' || form.elements[9].value == '' || form.elements[18].value == '')) {
		if (!isEmail(form.elements[9].value)) {
			alert('E-mail is not correct!');
			return false;
		}
	} else {
		alert('Some of imperative fields are not filled in!');
		return false;
	}
}



function doFeedbackEn(form) {
	if (!(form.elements[0].value == '' || form.elements[3].value == '' || form.elements[4].value == '' || form.elements[5].value == '' || form.elements[9].value == '' || form.elements[18].value == '')) {
		if (!isEmail(form.elements[9].value)) {
			alert('E-mail is not correct!');
			return false;
		}
	} else {
		alert('Some of imperative fields are not filled in!');
		return false;
	}
}



function doFeedbackFr(form) {
	if (!(form.elements[0].value == '' || form.elements[3].value == '' || form.elements[4].value == '' || form.elements[5].value == '' || form.elements[9].value == '' || form.elements[18].value == '')) {
		if (!isEmail(form.elements[9].value)) {
			alert('E-mail is not correct!');
			return false;
		}
	} else {
		alert('Some of imperative fields are not filled in!');
		return false;
	}
}


function doContactRu(form) {
	if (!(form.elements[0].value == '' || form.elements[2].value == '' || form.elements[5].value == '')) {
		if (!isEmail(form.elements[2].value)) {
			alert('Некорректный e-mail адрес!');
			return false;
		}
	} else {
		alert('Не все обязательные поля заполнены!');
		return false;
	}
}


function doContactDe(form) {
	if (!(form.elements[0].value == '' || form.elements[2].value == '' || form.elements[5].value == '')) {
		if (!isEmail(form.elements[2].value)) {
			alert('E-mail is not correct!');
			return false;
		}
	} else {
		alert('Some of imperative fields are not filled in!');
		return false;
	}
}



function doContactEn(form) {
	if (!(form.elements[0].value == '' || form.elements[2].value == '' || form.elements[5].value == '')) {
		if (!isEmail(form.elements[2].value)) {
			alert('E-mail is not correct!');
			return false;
		}
	} else {
		alert('Some of imperative fields are not filled in!');
		return false;
	}
}



function doContactFr(form) {
	if (!(form.elements[0].value == '' || form.elements[2].value == '' || form.elements[5].value == '')) {
		if (!isEmail(form.elements[2].value)) {
			alert('E-mail is not correct!');
			return false;
		}
	} else {
		alert('Some of imperative fields are not filled in!');
		return false;
	}
}

function doRegistrationRu(form) {
	if (!(form.elements[4].value == '' || form.elements[5].value == '')) {
		if (!isEmail(form.elements[5].value)) {
			alert('Некорректный e-mail адрес!');
			return false;
		}
	} else {
		alert('Не все обязательные поля заполнены!');
		return false;
	}
}


function doRegistrationDe(form) {
	if (!(form.elements[4].value == '' || form.elements[5].value == '')) {
		if (!isEmail(form.elements[5].value)) {
			alert('E-mail is not correct!');
			return false;
		}
	} else {
		alert('Some of imperative fields are not filled in!');
		return false;
	}
}



function doRegistrationEn(form) {
	if (!(form.elements[4].value == '' || form.elements[5].value == '')) {
		if (!isEmail(form.elements[5].value)) {
			alert('E-mail is not correct!');
			return false;
		}
	} else {
		alert('Some of imperative fields are not filled in!');
		return false;
	}
}



function doRegistrationFr(form) {
	if (!(form.elements[4].value == '' || form.elements[5].value == '')) {
		if (!isEmail(form.elements[5].value)) {
			alert('E-mail is not correct!');
			return false;
		}
	} else {
		alert('Some of imperative fields are not filled in!');
		return false;
	}
}




function isEmail(string) {	
	return string.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
}


function correct (data) {
		eval("var str = document.forms[1]."+data+".value;");
		ws = /\s+/;
		comma = /,/;
		str = str.replace(ws, "");
		str = str.replace(comma, "\.");
		eval("document.forms[1]."+data+".value = str;");
}
