/*****************************
**   Common cookie methods
******************************/

// Functions from Netscape's JavaScript Guide
// http://developer.netscape.com/docs/manuals/js/client/jsguide/

function setCookie(name, value, expire, path) {
	document.cookie = name + '=' + escape(value)
		+ ((expire == null)? '' : ('; expires=' + expire.toUTCString()))
		+ ((path == null)? '' : ('; path=' + path));
}

function getCookie(Name) {
	var search = Name + '='
	if (document.cookie.length > 0) { // if there are any cookies
		offset = document.cookie.indexOf(search) 
		if (offset != -1) { // if cookie exists 
			offset += search.length 
			// set index of beginning of value
			end = document.cookie.indexOf(';', offset) 
			// set index of end of cookie value
			if (end == -1) 
				end = document.cookie.length
			

return unescape(document.cookie.substring(offset, end))

//return decodeURIComponent(document.cookie.substring(offset, end))

}	}
	return '';
}

//Определение координат мыши
var mouseX; var mouseY;

function imouse(e)
{
  var x = 0, y = 0;
  if (!e) e = window.event;

  if (e.pageX || e.pageY){
    x = e.pageX;
    y = e.pageY;
  } else if (e.clientX || e.clientY) {
    x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
    y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
  }

  mouseX=x; mouseY=y;
}

document.onmousemove=imouse;


function bc(name,namesrc)
{
	var a = document.getElementById(name);
	a.src=namesrc;
}


function show_hide(id)
{
	var win = document.getElementById(id);
	if(win.style.display=='block')
	{
		win.style.display='none';
	}
	else
	{
		win.style.display='block';
	}
}


//open window
var Opened = false;
function ow(PageSrc,Width,Height, Params)
{
	if(!Params) Params="toolbar=no,menubar=no,location=no,directories=no,scrollbars=auto,resizable=yes";
	Features="top=118,left=255,width="+Width+",height="+Height+","+Params;
	if ((!Opened) || (NewWin.closed))
	{
		Opened = true;
		NewWin = window.open(PageSrc,null,Features);
		NewWin.focus();
		var w = (window.document.body.offsetWidth)?window.document.body.offsetWidth - 4:window.document.innerWidth;
		var h = (window.document.body.offsetHeight)?window.document.body.offsetHeight - 4:window.document.innerHeight;
		if ((w != Width) || (h != Height)) {NewWin.resizeTo(Width + 10, Height + 29);}
	}
	else
	{
		if ((Opened) || (!NewWin.closed))
		{
			NewWin.location=PageSrc;
			NewWin.focus();
		}
	}
}

function hideMsg(div)
{
document.getElementById(div).style.display='none';
}

function showMsg(div)
{
document.getElementById(div).style.display='block';
var timeout_id;
timeout_id = setTimeout("hideMsg('"+div+"');",2000);
}

function showVid(vid){
	Dialog.info("<div id='video_wrap'></div>", {width:400, className: "alphacube", closable: "true", onShow: function(){
		flowplayer("video_wrap", "/js/flowplayer/flowplayer-3.2.5-0.swf", {key: '#e2a9ae9185a859ca473', clip: vid});
	}, onClose: function(){
		$('video_wrap').remove();
	}});
}


function getClientWidth()
{
 return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight()
{
 return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}


function toggleMenu(m){
	f=document.getElementById('feer_menu');
	fb=document.getElementById('feer_btn');
	k=document.getElementById('karn_menu');
	kb=document.getElementById('karn_btn');

	if(m=='feer'){
		f.style.cssText='display: block;';
		fb.className='bcm1a';
	}else{
		f.style.cssText='display: none;';
		fb.className='';
	}
	if(m=='karn'){
		k.style.cssText='display: block;';
		kb.className='bcm1a';
	}else{
		k.style.cssText='display: none;';
		kb.className='';
	}
}


function toggleCmm(s){
	var cmm=document.getElementById('cmm');
	var vid=document.getElementById('vid');

	if(s){
		cmm.style.cssText='display: block;';
		if(vid){
			vid_html=vid.innerHTML;
			vid.innerHTML='';
			vid.style.cssText='display: none;';
		}
	}else{
		cmm.style.cssText='display: none;';
		if(vid){
			vid.innerHTML=vid_html;
			vid.style.cssText='display: block;';
		}
	}
}

function checkCmmForm(){
	f=document.getElementById('cmm_form');

	if(!f.cmm_name.value || !f.cmm_text.value){
		alert('Обязательно введите имя и текст отзыва!');
	}else{
		f.submit();
	}
}



function showPrdPopup(id){
	b=document.getElementById('prd_popup');
	b.innerHTML='<iframe src="/product_popup/'+id+'/" width=100%% height=100%% scrolling="no" frameborder="no"></iframe>';
	b.style.display='block';
	b.style.top=mouseY-30;
	b.style.left=mouseX-300;
}

function hidePrdPopup(){
	b=document.getElementById('prd_popup');
	b.innerHTML='';
	b.style.display='none';
}

function showCallback() {
	Dialog.info($("callback_form").innerHTML, {width:370, className: "alphacube", closable: "true"});
}

function showAnother(id) {
	$('atrigger_'+id).style.display = 'none';
	$('another_'+id).style.display = 'block';
}
