var opera=false;
var gecko=false;
var ie=false;
var safari=false;
var browser=navigator.userAgent.toLowerCase();
var ver=parseFloat(navigator.appVersion);
if(browser.indexOf('msie')!=-1)
{
  ie=true;
  if(browser.indexOf('msie 5.5')!=-1)ver=5.5;
  else if(browser.indexOf('msie5')!=-1)ver=5;
}
if(browser.indexOf('opera')!=-1)opera=true;
if(browser.indexOf('gecko')!=-1)gecko=true;
if(browser.indexOf('safari')!=-1)safari=true;

function png(element)

{if(ie){
var src,method='scale';
var classname=element.className;
if(classname.match('png'))
{
  src=element.getAttribute('src');
  element.setAttribute('src','/img/1.gif');
}
else if(classname.match('scale')||classname.match('crop'))
{
  src=element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i)[1];
  element.style.backgroundImage='none';
if(classname.match('crop'))method='crop';
}
element.style.filter="progid:dximagetransform.microsoft.alphaimageloader(src='"+src+"',sizingmethod="+method+")";
}}


function urlEncode(com)
{
	
if (encodeURIComponent) {
    	str = encodeURIComponent(com);
} else {
    	str = escape(com);
		}		
	
	return str;
}


function myajax(url,dattt,p_callback,return_xml,met) {

   var http_request = false;

    if (window.XMLHttpRequest) { // Mozilla, Safari,...
    	
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {
            try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {}
        }
    }

    if (!http_request) {
        //alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }
    http_request.onreadystatechange = function() {
       if (http_request.readyState == 4) {
           if (http_request.status == 200 || http_request.status == 0) {
             if (return_xml) {
                   eval(p_callback + '(http_request.responseXML)');
               } else {
                   eval(p_callback + '(http_request.responseText)');
               }
           } else {
              // alert('There was a problem with the request.(Code: ' + http_request.status + ')');
           }
       }
   }
    http_request.open(met, url, true);
    http_request.send(dattt);

}

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=dc.indexOf(";", begin);if (end==-1){end=dc.length;}return unescape(dc.substring(begin+prefix.length,end));}
//function setCookie(name,value,expires,path,domain,secure){document.cookie=name+"="+escape(value)+((expires)?"; expires="+expires.toGMTString():"")+((path)?"; path="+path:"")+((domain)?";domain="+domain:"")+((secure)?"; secure":"");}



function setCookie (name, value, expires, path, domain, secure) {
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}


function DeleteCookie (name,path,domain) {
      if (GetCookie(name)) {
        document.cookie = name + "=" +
          ((path) ? "; path=" + path : "") +
          ((domain) ? "; domain=" + domain : "") +
          "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}


function add2cart(id)
{
	var cart;
	if(getCookie('icocart'))
	{
		
		cart=getCookie('icocart');
		cart+=','+id;
		setCookie('icocart',cart,true,'/','www.icojoy.com',0);
		setCookie('icocart',cart,true,'/','.icojoy.com',0);
		//alert('Item add to shopping cart');
				window.location.href='/cart/';

	} else
	{
		setCookie('icocart',','+id,true,'/','www.icojoy.com',0);
		setCookie('icocart',','+id,true,'/','.icojoy.com',0);
//		alert('Item add to shopping cart');
		window.location.href='/cart/';


	}
}
function add2cart3(id)
{
	var cart;
	if(getCookie('icocart'))
	{
		
		cart=getCookie('icocart');
		cart+=','+id;
		setCookie('icocart',cart,true,'/','www.icojoy.com',0);
		setCookie('icocart',cart,true,'/','.icojoy.com',0);
		//alert('Item add to shopping cart');
			//	window.location.href='/cart/';

	} else
	{
		setCookie('icocart',','+id,true,'/','www.icojoy.com',0);
		setCookie('icocart',','+id,true,'/','.icojoy.com',0);
//		alert('Item add to shopping cart');
	//	window.location.href='/cart/';


	}
}
function add2cart2(id)
{
	var cart;
	if(getCookie('icocart'))
	{
		
		cart=getCookie('icocart');
		cart+=','+id;
		setCookie('icocart',cart,true,'/','www.icojoy.com',0);
		setCookie('icocart',cart,true,'/','.icojoy.com',0);
		//alert('Товар добавлен в карзину');
		//window.location.href='/cart/';
		
		getcart()	

		return true;
	} else
	{
		setCookie('icocart',','+id,true,'/','www.icojoy.com',0);
		setCookie('icocart',','+id,true,'/','.icojoy.com',0);
//		alert('Товар добавлен в карзину');

		getcart()	

		return true;

	}
	
	return false;
}




function del_cart(xid)
{

	if(getCookie('icocart'))
	{
		
		newcart='';
		cart=getCookie('icocart');	
		arr=cart.split(',');
		for(i=0;i<arr.length;i++)
		{
		if(arr[i]!=xid)
		 newcart+=','+arr[i];
		}

		setCookie('icocart',newcart,true,'/','www.icojoy.com',0);
		setCookie('icocart',newcart,true,'/','.icojoy.com',0);
		window.location.reload();
	}
}


function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail")
		    return false
		 }

 		 return true					
	}
	
function hide_add2cat(idd)
{
	

	document.getElementById(idd).innerHTML='';		

}	
	
//function show_add2cat(idd)
//{
//	document.getElementById(idd).innerHTML='<div class="" style="position:absolute;z-index:100;margin-left:78px;margin-top:-27px;"><div style="width:9px;float:left;"><img src="/img/ll_l.gif"></div><div style="background:#333333;float:left;height:23px;color:white;padding-top:6px;overflow:hidden;padding-left:12px;padding-right:12px;">added to cart</div><div style="width:4px;float:left;"><img src="/img/ll_r.gif"></div></div>	';		
	
//	setTimeout('hide_add2cat(\''+idd+'\')',2000);

//}

function setOpacity(domId, val) {

obj = document.getElementById(domId);
obj.style.MozOpacity = val;
obj.style.opacity = val/10;
obj.style.filter = 'Alpha(Opacity="' + (val * 10) + '")';

};

function fade(domId){
obj = document.getElementById(domId); //Get the Element

 if(obj.style.display == "none") return false; //Return false if the element is already hidden

 var alpha = 10; //Set the initial value of alpha to 10 (Opaque)
 function f(){ //Internal function

  alpha--; //Decrement the alpha value

  setOpacity(domId, alpha); //Set the opacity of our element to the specified alpha

  if(alpha > -1){ //If alpha is still bigger than -1 then..
   setTimeout(f, 80); //..then call the function again after 100 milliseconds

  }else{ //otherwise..
  // obj.style.display = 'none'; //..otherwise now that we cant see the element anyways, hide it
		hide_add2cat(domId);
		setOpacity(domId,10);
  }
}
setTimeout(f, 80); //This is where we call the f() function for the first time

};
function show_add2cat(idd)
{
	document.getElementById(idd).innerHTML='<div class="" style="position:absolute;z-index:100;margin-left:78px;margin-top:-27px;"><div style="width:9px;float:left;"><img src="/img/ll_l.gif"></div><div style="background:#333333;float:left;height:23px;color:white;padding-top:6px;overflow:hidden;padding-left:12px;padding-right:12px;">added to cart</div><div style="width:4px;float:left;"><img src="/img/ll_r.gif"></div></div>	';		
	setTimeout(function(){fade(idd);},500);

	var yoid=idd.replace("iconsq", "");
	add2cart2(yoid);
	
	//setTimeout('',10);


	//setTimeout('',2000);

}	
	
function show_add2cat_all(idd,idd2)
{
	
	document.getElementById(idd).innerHTML='<div class="" style="position:absolute;z-index:100;margin-left:78px;margin-top:-27px;"><div style="width:9px;float:left;"><img src="/img/ll_l.gif"></div><div style="background:#333333;float:left;height:23px;color:white;padding-top:6px;overflow:hidden;padding-left:12px;padding-right:12px;">added to cart</div><div style="width:4px;float:left;"><img src="/img/ll_r.gif"></div></div>	';		
	setTimeout(function(){fade(idd);},500);

	var arr=idd2.split(',');
	
	for(var i=0;i<arr.length;i++)
	add2cart3(arr[i]);
	getcart();
	
	//setTimeout('',10);


	//setTimeout('',2000);

}	
	


function getcart()
{
	myajax('/service/getcart.php?rand='+(Math.random()*10000)+'&icocart='+getCookie('icocart')+'&lang='+getCookie('language'),'','getcart_cb',false,'GET');	
}

function getcart_cb(txt)
{

	if(txt)
	document.getElementById('getcart').innerHTML=txt;		
}


window.onload=function(){
	getcart()	
}