// возвращает cookie если есть
function getCookie(name) {
	var matches = document.cookie.match(new RegExp(
	  "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
	));
	return matches ? decodeURIComponent(matches[1]) : "";
}

// уcтанавливает cookie
function setCookie(name, value, props) {
	props = props || {};
	var exp = props.expires;
	if (typeof exp == "number" && exp) {
		var d = new Date();
		d.setTime(d.getTime() + exp*1000);
		exp = props.expires = d;
	}
	if(exp && exp.toUTCString) { props.expires = exp.toUTCString(); }

	value = encodeURIComponent(value);
	var updatedCookie = name + "=" + value + "; path=/";
	for(var propName in props){
		updatedCookie += "; " + propName;
		var propValue = props[propName];
		if(propValue !== true){ updatedCookie += "=" + propValue; }
	}
	document.cookie = updatedCookie;

}

// удаляет cookie
function deleteCookie(name) {
	setCookie(name, null, { expires: -1 });
}


function mainGetCookie(name)
{
   return getCookie(name);
}
function mainSetCookie(name,value)
{
   setCookie(name, value, {expires:14*24*60*60} );
}

function BuyRequest(id,type,price,min_price,volSize,name,weight,dfs)
{
   var newWnd = window.open("http://home-video.ru/buy-request.html?"+id+"&"+price+"&"+min_price+"&"+volSize+"&"+type+"&"+dfs+"&"+weight+"&"+escape(name)+"&"+mainGetCookie("rrr"), "hvcart", "resizable=no,toolbar=no,status=no,left=-30,top=-30,width=10,height=10");
   newWnd.blur();
}
function ToCart(id,type,price,min_price,volSize,name,weight,dfs)
{
   var newWnd = window.open("http://home-video.ru/tocart.html?"+id+"&"+price+"&"+min_price+"&"+volSize+"&"+type+"&"+dfs+"&"+weight+"&"+escape(name)+"&"+mainGetCookie("rrr"), "hvcart", "resizable=yes,left=-30,top=-30,width=10,height=10,scrollbars=yes");
   mainSetCookie("rrr","ept");
   newWnd.blur();
}
function OpenCart()
{
   ToCart(0,0,0,0,0,'',0,0);
}
function OpenDFSCart()
{
   ToCart(0,0,0,0,0,'',0,1);
}

if( document.referrer.indexOf("home-video") < 0 )
{
   mainSetCookie("rrr",document.referrer);
}

var bNavigator = (navigator.appName == "Netscape");
var bFireFox = (navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 5);
if( bNavigator && !bFireFox )
{
   window.location.href = "http://home-video.ru/netscape.html";
}
else
{
   window.name = "main";
}

function replace(s, t, u)
{
   i = s.indexOf(t);
   if (i == -1)
   {
      return s;
   }
   r = s.substring(0,i) + u;
   if( (i + t.length) < s.length)
   {
      r += s.substring(i + t.length, s.length);
   }
   return r;
}

function OnSearch(text)
{
   text = text.toLowerCase();
   if( text == null || text == "" || text.length < 3 ){alert("Пожалуйста, задайте ключевые слова для поиска.\nКлючевые слова должны быть длиной не менее 3 символов!");return;}
   text = replace(text,"\"","");text = replace(text,"\'","");text = replace(text,"\"","");text = replace(text,"\'","");if( text == "o" || text == "о" || text == "O" || text == "О" ){text = "otello";}
   if( text=="k9" || text=="k-9" || text=="k 9" || text=="к-9" || text=="к 9" || text=="к9" ){ text="ka9"; }
   if( text=="k-19" || text=="k 19" || text=="к-19" || text=="к 19" || text=="к19" ){ text="k19"; }
   if( text=="a-ha" || text=="a ha" || text=="a/ha" ){ text="aha"; }
   if( text=="ac-dc" || text=="ac dc" || text=="acdc" ){ text="ac/dc"; }
   window.location.href = "/cgi-bin/search.cgi?text="+text;
}

function OnPSearch(text)
{
   text = text.toLowerCase();
   if( text == null || text == "" || text.length < 3 ){alert("Пожалуйста, задайте ключевые слова для поиска.\nКлючевые слова должны быть длиной не менее 3 символов!");return;}
   text = replace(text,"\"","");text = replace(text,"\'","");text = replace(text,"\"","");text = replace(text,"\'","");if( text == "o" || text == "о" || text == "O" || text == "О" ){text = "otello";}
   if( text=="k9" || text=="k-9" || text=="k 9" || text=="к-9" || text=="к 9" || text=="к9" ){ text="ka9"; }
   if( text=="k-19" || text=="k 19" || text=="к-19" || text=="к 19" || text=="к19" ){ text="k19"; }
   if( text=="a-ha" || text=="a ha" || text=="a/ha" ){ text="aha"; }
   if( text=="ac-dc" || text=="ac dc" || text=="acdc" ){ text="ac/dc"; }
   window.location.href = "/cgi-bin/searchp.cgi?text="+text;
}



nereidFadeObjects = new Object();
nereidFadeTimers = new Object();
function nereidFade(object, destOp, rate, delta){
if(!document.all) return;
if(object!="[object]"){setTimeout("nereidFade("+object+","+destOp+","+rate+","+delta+")",10);return;}
clearTimeout(nereidFadeTimers[object.sourceIndex]);
diff=destOp-object.filters.alpha.opacity;
direction=1;
if(object.filters.alpha.opacity>destOp){direction=-1;}
delta=Math.min(direction*diff,delta);
object.filters.alpha.opacity+=direction*delta;
if(object.filters.alpha.opacity!=destOp){nereidFadeObjects[object.sourceIndex]=object;nereidFadeTimers[object.sourceIndex]=setTimeout("nereidFade(nereidFadeObjects["+object.sourceIndex+"],"+destOp+","+rate+","+delta+")",rate);}
}
function addToFavorites(){
if(document.all){window.external.AddFavorite( document.location.href, document.title );}
else if(navigator.appName=="Netscape" && parseInt(navigator.appVersion)>=4){alert("В Netscape, чтобы добавить в \"Избранное\", нажмите Ctrl+D");}
else{alert("К сожалению не знаю как добавить в \"Избранное\" в вашем web-browser'e  :o(\nЧтобы добавить, используйте, пожалуйста, меню или \"горячие клавиши\" вашего web-browser'a...");}
}
function setLight(id){document.all[id].style.background="#88ACDC";document.all[id].style.borderBottomStyle="ridge";}
function setDark(id){document.all[id].style.background="#E7E7E7";document.all[id].style.borderBottomStyle="groove";}
function hmnu(obj,m){ if(m=='1'){obj.style.background="#88ACDC";obj.style.borderBottomStyle="ridge";obj.style.cursor="hand";} if(m=='0'){obj.style.background="#E7E7E7";obj.style.borderBottomStyle="groove";} }

