/***********************************************
* Sticky Note script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* Visit DynamicDrive.com for hundreds of DHTML scripts
* This notice must stay intact for legal use
* Go to http://www.dynamicdrive.com/ for full source code
***********************************************/


var autohidebox=["yes", 15] 
var showonscroll="yes"

function displayfadeinbox(){
var ie=document.all && !window.opera
var dom=document.getElementById
iebody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
objref=(dom)? document.getElementById("fadeinbox") : document.all.fadeinbox
var scroll_top=(ie)? iebody.scrollTop : window.pageYOffset
var docwidth=(ie)? iebody.clientWidth : window.innerWidth
docheight=(ie)? iebody.clientHeight: window.innerHeight
var objwidth=objref.offsetWidth
objheight=objref.offsetHeight
objref.style.left=docwidth/4-objwidth/2+350+"px"
objref.style.top=scroll_top+docheight/4-objheight/2+"px"
showonscrollvar=setInterval("staticfadebox()", 50)
objref.style.visibility="visible"
if (objref.style.MozOpacity){
objref.style.MozOpacity=1
controlledhidebox()
}
else
controlledhidebox()
}

function staticfadebox(){
var ie=document.all && !window.opera
var scroll_top=(ie)? iebody.scrollTop : window.pageYOffset
objref.style.top=scroll_top+docheight/2-objheight/2+"px"
}

function hidefadebox(){
objref.style.visibility="hidden"
if (typeof showonscrollvar!="undefined")
clearInterval(showonscrollvar)
}

function controlledhidebox(){
var delayvar=autohidebox[1]*1000
setTimeout("hidefadebox()", delayvar)
}

function initfunction(){
setTimeout("displayfadeinbox()", 100)
}

function get_cookie(Name) {
var search = Name + "="
var returnvalue = ""
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;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

/*************************************************************/

function add2cart(itemid)
{
 var url = '/store/add_to_cart';
 var qty = $F('i'+itemid);
 var params = ('good_id='+ itemid +'&'+ 'amount=' + (qty));
 if (isNaN(parseInt(qty)) || parseInt(qty)==0)
 {
 alert ("Проверьте правильность ввода количества позиции!");
 }
 else
 {
 //alert(params);
 var ajax = new Ajax.Updater({success: 'icart'}, url, {method: 'post', parameters: params, onFailure: reportError} );
 }
}
function reportError(request) {
     $('icart').innerHTML = "Ошибка";
}
/*function add2cartbyEnter(e,itemid,type)
{
var res =false;
 if(navigator.appName.indexOf("Netscape")>(-1))
 {
 if (e.keyCode == 13)
 {
 add2cart(itemid,type);
 return false;
 }
 }
 if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1) || navigator.appName.indexOf("Opera")>(-1))
 {
 if (event.keyCode == 13)
 {
 add2cart(itemid,type);
 return false;
 }
 }
}*/

function validate_list(myaction)
{
 var res =false;
 for (i = 0; i < document.products.elements.length; i++)
 {
 var item = document.products.elements[i];
 if (item.name == "ch[]")
 {
 if (item.checked)
 {
 res=true;
break
 }
 }
 }
 if(res)
 {
 var ajax2 = new Ajax.Updater({success: 'icart'}, '/store/add_goods_to_cart', {asynchronous:true, evalScripts:true, parameters:Form.serialize(document.products), onFailure: reportError});
 displayfadeinbox();
 }
 else
 {
 alert ("Не выбрана ни одна позиция!");
 }
}

function checkcartqty(qty)
{
 if (isNaN(parseInt(qty))|| parseInt(qty)==0)
 {
 alert('Проверьте правильность ввода количества позиции!');
 return false;
 }
 else
 {
 return true;
 }
}

function fnc()
{
 elms = document.all.tags("input");
 for(var i=0; i<elms.length; i++)
 {
 if(elms[i].name.indexOf("quant")==0)
 {
 if(elms[i].value == "" || elms[i].value == "0")
 {
 return confirm('Товары с количеством, равным нулю, будут удалены из корзины.');
 }
 }
 }
 return true;
}

