function openpage(pagenumber) {
  //отправляет постом номер выводимой страницы
  document.getElementById("startelement").value = pagenumber;
  a=document.getElementById("ProdPage");
  a.submit();
}

function getDims(winWidth, winHeight) {
	var dims = new Object();
	if (winWidth) {
		dims.width = winWidth;
		dims.scrollbars = false;
		if (screen.width < dims.width + 70) {
			dims.width = screen.width - 70;
			dims.scrollbars = true;
		}
	}

	if (winHeight) {
		dims.height = winHeight;
		if (screen.height < dims.height + 100) {
			dims.height = screen.height - 100;
			dims.scrollbars = true;
		}
	}
	dims.heightStr = (winHeight)? ',height=' + dims.height : '';
	dims.scrollbarsStr = (dims.scrollbars)? ',scrollbars=yes' : ',scrollbars=no';
	dims.width=(dims.scrollbars)? dims.width+17 : dims.width;
	dims.widthStr = (winWidth)? ',width=' + dims.width : '';
	dims.posX = Math.round((screen.width - dims.width) / 2);
	dims.posY = Math.round((screen.height - winHeight) / 2);
	dims.posCode = (document.all)? ',left=' + dims.posX + ',top=' + dims.posY : ',screenX=' + dims.posX + ',screenY=' + dims.posY;
	return dims;
}
function popupImg(imgSrc, winName, imgWidth, imgHeight, winTitle) {

	winWidth = (imgWidth)? imgWidth +0 : null;
	winHeight = (imgHeight)? imgHeight + 0 : null;
	var dims = getDims(winWidth, winHeight);
	var popupWin = window.open('', winName, 'menubar=no,toolbar=no,resizable=yes,status=yes' + dims.scrollbarsStr + dims.widthStr + dims.heightStr + dims.posCode);
	if (popupWin) {
		popupWin.document.open();
		popupWin.document.write('<html><head><title>' + winTitle + '</title></head><body bgcolor="white" style="margin: 0px 0px; padding: 0px;">')
		popupWin.document.write('<img src="' + imgSrc + '" width="' + imgWidth + '" height="' + imgHeight + '" />')
		popupWin.document.write('</body></html>')
		popupWin.document.close();
	}
	return false;
}function popupImage(href, width, height, title)
{

var popupWin = window.open('', 'Image', 'menubar=no,toolbar=no,resizable=no,status=no,scrollbars=no, width='+width+',height='+height);
	if (popupWin) {
		popupWin.document.open();
		popupWin.document.write('<html><head><title>'+title+'</title></head><body bgcolor="white" style="margin: 0px; padding: 0px;">')
		popupWin.document.write('<img src="' + href + '" width="' + width + 'px" height="' + height + 'px" alt="'+title+'"/>')
		popupWin.document.write('</body></html>')
		popupWin.document.close();
	}
	return true;

}
function addCart(product_id)
{
	var url	= add_url+'?productID='+product_id;
	window.open(url,'addCart','width=300, height=200, left=300, top=250');
}
function displayPlayLinks(allow_play)
{
	var played_cookie	= getCookie('played');
	if (!played_cookie && allow_play) return true;  //Can play

	//Cannt play
	document.styleSheets[0].addRule(".winIt", "display:none");
	return false;
}


function playNow(product_id)
{
    var _isIE7_8 = ((navigator.userAgent.indexOf('MSIE 7')>0) || (navigator.userAgent.indexOf('MSIE 8')>0));
    
    if (!confirm("У вас есть шанс выиграть этот товар прямо сейчас (получить право на разовое приобретение выигранного товара за 1 гривну на протяжении 7 дней с момента выигрыша). \r\n Участвовать в игре можно не чаще одного раза в неделю.\r\n Вероятность выигрыша выше для товаров, имеющих меньшую стоимость. \r\n Получить выигрыш может только лицо, данные которого указаны при регистрации в конкурсе при наличии документов, удостоверяющих личность. \r\n Попытка использования методов обмана системы приведет к исключению из конкурса и лишению прав на получение выигрыша. \r\n\r\n Принимаете условия?")) return;    
    
    if (_isIE7_8) {
        var product_id = product_id;
        IEprompt('Введите имя и фамилию (кирилица)', '', 'Окно ввода', product_id);
        
    } else {
        var name    = prompt("Ваше имя (кириллица)", 'Имя');
        if (!name) return false;
        var famname    = prompt("Ваша фамилия (кириллица)", 'Фамилия');
        if (!famname) return false;
        var url        = PLAY_url+'?product='+product_id+'&name='+name+'&famname='+famname;
        document.location.href=url;
        return false;    
    }
}

// callback function for IEpromt()
function promptCallback(val) {
    var pie = val.split(';',3);

    product_id  = pie[2];
    name        = pie[0];
    famname     = pie[1];
    
    var url        = PLAY_url+'?product='+product_id+'&name='+name+'&famname='+famname;
    document.location.href=url;    
}


//-------------------------------------
// Sets cookie. Expere in days
function setCookie(name, value, expire)
{
	var expire_date		= new Date();
    var cookie_expire	= expire_date.getTime() + Math.round(expire*24*60*60*1000);
    expire_date.setTime(cookie_expire);
    document.cookie		= name + "="+value+"; path=/; expires="+expire_date.toGMTString()+";";

	return true;
}

//-------------------------------------
// Sets cookie. Expere in days
function removeCookie(name)
{
	setCookie(name, false, -1);
	return true;
}



//-------------------------------------
// Gets cookie.
function getCookie(name)
{
//	if (document.cookie.length <= 0) return null;	//No cookies found
	var cookie_expr		= new RegExp (name+'=([^;]*)', 'i');
	var cookie_parsed	= document.cookie.match(cookie_expr);
	var cookie_value	= (cookie_parsed)? unescape(cookie_parsed[1]) : null;

	return cookie_value;
}

///////////////////////////////////////////////////////////
// Usage IEprompt("dialog descriptive text", "default starting value");
// 
// IEprompt will call promptCallback(val)
// Where val is the user's input or null if the dialog was canceled.
///////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////
// This source code has been released into the public domain
// January 14th, 2007.
// You may use it and modify it freely without compensation
// and without the need to tell everyone where you got it.
///////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////
// You must create a promptCallback(val) function to handle
// the user input.  If you don't this script will fail and
// Bunnies will die.
///////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////
// These are global scope variables, they should remain global.
///////////////////////////////////////////////////////////
var _dialogPromptID=null;
var _blackoutPromptID=null;
///////////////////////////////////////////////////////////

function IEprompt(innertxt, def, window_title, product_id) {

   that=this;
   
   if ((window_title == '') || (window_title == undefined)) {
        window_title = 'Input Required';
   }
   
   // Check to see if this is MSIE 7.   This isn't a great general purpose
   // detection system but it works well enough just to find MSIE 7.
   var _isIE7 = ((navigator.userAgent.indexOf('MSIE 7')>0) || (navigator.userAgent.indexOf('MSIE 8')>0));

   this.wrapupPrompt = function (cancled) {
      // wrapupPrompt is called when the user enters or cancels the box.
      // It's called only by the IE7 dialog box, not the non IE prompt box
      if (_isIE7) {
         // Make sure we're in IE7 mode and get the text box value
         val_name = document.getElementById('user_name').value;
         val_famname = document.getElementById('user_famname').value;
         // clear out the dialog box
         _dialogPromptID.style.display='none';
         // clear out the screen
         _blackoutPromptID.style.display='none';
         // clear out the text field
         document.getElementById('user_name').value = '';
         document.getElementById('user_famname').value = '';
         // if the cancel button was pushed, force value to null.
         if (cancled) { 
            val = '';             
         } else {
            val = val_name + ';' + val_famname + ';' + product_id;
         }
         // call the user's function
         promptCallback(val);
      }
      return false;
   }

   //if def wasn't actually passed, initialize it to null
   if (def==undefined) { def=''; }

   if (_isIE7) {
      // If this is MSIE 7.0 then...
      if (_dialogPromptID==null) {
         // Check to see if we've created the dialog divisions.
         // This block sets up the divisons
         // Get the body tag in the dom
         var tbody = document.getElementsByTagName("body")[0];
         // create a new division
         tnode = document.createElement('div');
         // name it
         tnode.id='IEPromptBox';
         // attach the new division to the body tag
         tbody.appendChild(tnode);
         // and save the element reference in a global variable
         _dialogPromptID=document.getElementById('IEPromptBox');
         // Create a new division (blackout)
         tnode = document.createElement('div');
         // name it.
         tnode.id='promptBlackout';
         // attach it to body.
         tbody.appendChild(tnode);
         // And get the element reference
         _blackoutPromptID=document.getElementById('promptBlackout');
         // assign the styles to the blackout division.
         _blackoutPromptID.style.opacity='.9';
         _blackoutPromptID.style.position='absolute';
         _blackoutPromptID.style.top='0px';
         _blackoutPromptID.style.left='0px';
         _blackoutPromptID.style.backgroundColor='#555555';
         _blackoutPromptID.style.filter='alpha(opacity=90)';
         _blackoutPromptID.style.height=(document.body.offsetHeight<screen.height) ? screen.height+'px' : document.body.offsetHeight+20+'px'; 
         _blackoutPromptID.style.display='block';
         _blackoutPromptID.style.zIndex='50';
         // assign the styles to the dialog box
         _dialogPromptID.style.border='2px solid blue';
         _dialogPromptID.style.backgroundColor='#DDDDDD';
         _dialogPromptID.style.position='absolute';
         _dialogPromptID.style.width='330px';
         _dialogPromptID.style.zIndex='100';
      }
      // This is the HTML which makes up the dialog box, it will be inserted into
      // innerHTML later. We insert into a temporary variable because
      // it's very, very slow doing multiple innerHTML injections, it's much
      // more efficient to use a variable and then do one LARGE injection.
      var tmp = '<div style="width: 100%; background-color: blue; color: white; font-family: verdana; font-size: 10pt; font-weight: bold; height: 20px">'+window_title+'</div>';
      tmp += '<div style="padding: 10px">'+innertxt + '<BR><BR>';
      tmp += '<form action="" onsubmit="return that.wrapupPrompt()">';
      tmp += 'Имя:' + '<br/>';
      tmp += '<input id="user_name" name="user_name" type=text size=46 value="'+def+'">';
      tmp += '<br/>';
      tmp += 'Фамилия:' + '<br/>';
      tmp += '<input id="user_famname" name="user_famname" type=text size=46 value="'+def+'">';
      tmp += '<br><br><center>';
      tmp += '<input type="submit" value="&nbsp;&nbsp;&nbsp;OK&nbsp;&nbsp;&nbsp;">';
      tmp += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
      tmp += '<input type="button" onclick="that.wrapupPrompt(true)" value="&nbsp;Cancel&nbsp;">';
      tmp += '</form></div>';
      // Stretch the blackout division to fill the entire document
      // and make it visible.  Because it has a high z-index it should
      // make all other elements on the page unclickable.
      _blackoutPromptID.style.height=(document.body.offsetHeight<screen.height) ? screen.height+'px' : document.body.offsetHeight+20+'px'; 
      _blackoutPromptID.style.width='100%';
      _blackoutPromptID.style.display='block';
      // Insert the tmp HTML string into the dialog box.
      // Then position the dialog box on the screen and make it visible.
      _dialogPromptID.innerHTML=tmp;
      _dialogPromptID.style.top=parseInt(document.documentElement.scrollTop+(screen.height/3))+'px';
      _dialogPromptID.style.left=parseInt((document.body.offsetWidth-315)/2)+'px';
      _dialogPromptID.style.display='block';
      // Give the dialog box's input field the focus.
      document.getElementById('user_name').focus();
   } else {
      // we are not using IE7 so do things "normally"
      promptCallback(prompt(innertxt,def));
   }
}

function displayPlayLinks(allow_play)
{
	var played_cookie	= getCookie('played');
	if (!played_cookie && allow_play) return true;  //Can play

	//Cannt play
	document.styleSheets[0].addRule(".winIt", "display:none");
	return false;
}


function playNow(product_id)
{
	if (!confirm("У вас есть шанс выиграть этот товар прямо сейчас (получить право на разовое приобретение выигранного товара за 1 гривну на протяжении 7 дней с момента выигрыша). \r\n Участвовать в игре можно не чаще одного раза в неделю.\r\n Вероятность выигрыша выше для товаров, имеющих меньшую стоимость. \r\n Получить выигрыш может только лицо, данные которого указаны при регистрации в конкурсе при наличии документов, удостоверяющих личность. \r\n Попытка использования методов обмана системы приведет к исключению из конкурса и лишению прав на получение выигрыша. \r\n\r\n Принимаете условия?")) return;
	var name	= prompt("Ваше имя (кириллица)", 'Имя');
	if (!name) return false;
	var famname	= prompt("Ваша фамилия (кириллица)", 'Фамилия');
	if (!famname) return false;
	var url		= PLAY_url+'?product='+product_id+'&name='+name+'&famname='+famname;
	document.location.href=url;

	return false;
}




//-------------------------------------
// Sets cookie. Expere in days
function setCookie(name, value, expire)
{
	var expire_date		= new Date();
    var cookie_expire	= expire_date.getTime() + Math.round(expire*24*60*60*1000);
    expire_date.setTime(cookie_expire);
    document.cookie		= name + "="+value+"; path=/; expires="+expire_date.toGMTString()+";";

	return true;
}

//-------------------------------------
// Sets cookie. Expere in days
function removeCookie(name)
{
	setCookie(name, false, -1);
	return true;
}



//-------------------------------------
// Gets cookie.
function getCookie(name)
{
//	if (document.cookie.length <= 0) return null;	//No cookies found
	var cookie_expr		= new RegExp (name+'=([^;]*)', 'i');
	var cookie_parsed	= document.cookie.match(cookie_expr);
	var cookie_value	= (cookie_parsed)? unescape(cookie_parsed[1]) : null;

	return cookie_value;
}

