function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}


/*
  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist
*/

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function imgOpen(fileName, title, w, h){
	newWindow = window.open("","imgWin","width="+w+",height="+h+",left=50,top=50,toolbar=0,directories=0,menubar=0,resizable=0,location=0,scrollbars=0,copyhistory=0,status=0");
    if (newWindow.document.images.length) {
        newWindow.close();
        newWindow = window.open("","imgWin","width="+w+",height="+h+",left=50,top=50,toolbar=0,directories=0,menubar=0,resizable=0,location=0,scrollbars=0,copyhistory=0,status=0");
    }    
    newWindow.document.write("<html><head><title>"+title+"</title></head><body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0><img src='"+fileName+"' width="+w+" height="+h+" alt='"+title+"'></body></html>");
    newWindow.focus();
    return false;
}

function AddToCart(idp, inp){
    qnt = parseInt(inp.value);
    if (qnt == 'NaN') qnt = '1';
    location = "/?page=cart&idp="+idp+"&qnt="+qnt;
    return false;
}

function QntInc(inp){
    inp.value = parseInt(inp.value) + 1;
    if (inp.value == 'NaN') inp.value = '1';
    return false;
}

function QntDec(inp){
    if (parseInt(inp.value) > 1)
        inp.value = parseInt(inp.value) - 1;
    if (inp.value == 'NaN') inp.value = '1';
    return false;
}

function winDetail(e,fileName)
{
	if (e.stopPropagation)	
		e.stopPropagation();
	else
		e.cancelBubble = true;
	
	msgWindow=window.open(fileName,"Detail","width=610,height=360,left=100,top=100,toolbar=0,directories=0,menubar=0,resizable=1,location=no,scrollbars=0,copyhistory=0");
	try {window.childWindow = msgWindow;}
	catch(e){window.childWindow = null;}
	msgWindow.focus();
	return false;
}

// Получение значение параметра из get строки
function GetParam(search, name){
name=name+"=";
var gp="";
if (search!="") {
if (search.indexOf(name, 0)!=-1){
var startpos=search.indexOf(name, 0)+name.length;
var endpos=search.indexOf("&",startpos);
if (endpos<startpos) 
{endpos=search.length;}
var gp=p.substring(startpos,endpos);
} else 
{gp=""; }
}
else {
gp="";
}
return gp;
}

function getSubCookie (str, name) {
	if (!str == 'null')
	{
		var listArray = str.split("&");
		for (i=0; i<listArray.length; i++)// each(el in listArray)
		{
			var l = listArray[i].split("=");
			if (l[0]==name)
				return l[1];
		}
	}
	return "";
} 	
