
function writeEmail(val)
{
	b = val.replace(/@z/g, '@');
	b = b.replace(/\$x/g, '');
	b = b.replace(/#y/g, '');
	document.write('<a href="mailto:' + b + '">' + b + '</a>');
}

function setClass(id, val)
{
	if (el = document.getElementById(id)) el.className = val; else return false;
	return true;
}

function setDisplay(id, val)
{
	if (el = document.getElementById(id)) el.style.display = val; else return false;
	return true;
}

function setClassAll2(id, val)
{
	$i = 0;
	while (true)
	{
		$j = 0;
		while (el = document.getElementById(id + $i + '_' + $j))
		{
			el.className = val;
			$j++;
		}
		if ($j == 0) break;
		$i++;
	}
}

function setDisplayAll2(id, val)
{
	$i = 0;
	while (true)
	{
		$j = 0;
		while (el = document.getElementById(id + $i + '_' + $j))
		{
			el.style.display = val;
			$j++;
		}
		if ($j == 0) break;
		$i++;
	}
}

function getEl(id)
{
	if (el = document.getElementById(id)) return el.value;
}

function setEl(id, val)
{
	if (el = document.getElementById(id)) el.value = val;
}
	
function clearDef(el, def)
{
	if (el.value == def) el.value = '';
}

function fillDef(el, def)
{
	if (el.value == '') el.value = def;
}

function getBrowserInfo() {
	var t,v = undefined;
	if (window.opera) t = 'Opera';
	else if (document.all) {
		t = 'IE';
		var nv = navigator.appVersion;
		var s = nv.indexOf('MSIE')+5;
		v = nv.substring(s,s+1);
	}
	else if (navigator.appName) t = 'Netscape';
	return {type:t,version:v};
}
 
function bookmark(a){
	var url = window.document.location;
	var title = window.document.title;
	var b = getBrowserInfo();
	if (b.type == 'IE' && 7 > b.version && b.version >= 4) window.external.AddFavorite(url,title);
	else if (b.type == 'Opera') {
		a.href = url;
		a.rel = "sidebar";
		a.title = title;
		return true;
	}
	else if (b.type == "Netscape") window.sidebar.addPanel(title,url,"");
	else window.external.AddFavorite(url,title);
	return false;
}

function openWindow(url, width, height){
  w = screen.availWidth;
  h = screen.availHeight;
  x = (w - width)/2;
  y = (h - height)/2;
  onlineWindow= window.open(url, "_blank", "left="+x+",top="+y+",width="+width+",height="+height+",status=no,toolbar=no,menubar=no,scrollbars=yes,resizable=no");
}

function readCookie(name){
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0){ 
    offset = document.cookie.indexOf(search);
    if (offset != -1){ 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}

function writeCookie(name, value, hours){
  var expire = "";
  if(hours != null){
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}

function swap_display(id){
	if (el = document.getElementById(id)){
		if (el.style.display == 'block'){
			el.style.display = 'none';
		} else {
			el.style.display = 'block';
		}
	}	
}

function swap_display_i(id){
	if (el = document.getElementById(id)){
		if (el.style.display == 'inline'){
			el.style.display = 'none';
		} else {
			el.style.display = 'inline';
		}
	}	
}

function resForm(id, yn)
{
	if (!yn) return false;
	el = document.getElementById(id);
	el.reset();
}

function subForm(id, yn)
{
	if (!yn) return false;
	el = document.getElementById(id);
	el.submit();
}

function checkForm(formName, fields, caps){
  var flag=true;
  cnt = fields.length;
  for (i = 0; i < cnt; i++){
    if (document['forms'][formName][fields[i]].value==''){
	  flag=false; window.alert('Не заполнено поле "'+caps[i]+'"');
	  return flag;
	}
  }
  return flag;
}

$(document).ready(function() {
	$(".left-menu h4").hover(
		function() {
			$(this).children(".second-submenu").show();
		},
		function() {
			$(this).children(".second-submenu").hide();
		}
	);
	$(".second-submenu li").hover(
		function() {
			$(this).children("ul").show();
		},
		function() {
			$(this).children("ul").hide();
		}
	);
	$(".gray li").hover(
		function() {
			$(this).children("ul.third-submenu").show();
		},
		function() {
			$(this).children("ul.third-submenu").hide();
		}
	);
	
	$("#sp-button").click(function() {
		//$("#sp-block").html('http://market.yandex.ru/grade-shop.xml?shop_id=27971" target="_blank');
		//$("#sp-block").show();
		return false;
		//http://market.yandex.ru/grade-shop.xml?shop_id=27971" target="_blank
	});
});

