
var browserType;

if (document.layers) {browserType = "nn4"}
if (document.all) {browserType = "ie"}
if (window.navigator.userAgent.toLowerCase().match("gecko")) {
   browserType= "gecko"
}


function addItem2Cart(p_id, sessionid, lid)
{
	if (lid==1)
	{
		msg1 = "Ο browser σας δεν υποστηρίζει AJAX!";
		msg2 = "λάθος";
	}
	else
	{
		msg1 = "Your browser does not support AJAX!";
		msg2 = "error";
	} 
	
	var img_old;
	show(lid);
//	img_old = document.getElementById('cartindicator').src;
//	width_old = document.getElementById('cartindicator').width;
//	height_old = document.getElementById('cartindicator').height;
//	document.getElementById('cartindicator').width = 16;
//	document.getElementById('cartindicator').height = 16;
//	document.getElementById('cartindicator').src = 'files/indicator.gif';
	var xmlHttp;
	try { 	// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();	} catch (e) {	// Internet Explorer
		try {	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 	} catch (e) {
			try {	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");	} catch (e) {	alert(msg1);	
			return false;	}
			}
		}
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
				{
				//                                    alert(xmlHttp.responseText);
					if (xmlHttp.responseText==1)
					{
						updateCartItems(lid);
					}    //end if - email added
					else 
					{
						alert(msg2);
					} //end else if - email already exists
//					document.getElementById('cartindicator').width = width_old;
//					document.getElementById('cartindicator').height = height_old;
//					document.getElementById('cartindicator').src = img_old;
					hide();
				}
		}
	xmlHttp.open("GET","wmt_additem2cart.php?sessionid="+sessionid+"&product_id="+p_id+"&quantity=1", true);
	xmlHttp.send(null);

} //end function addItem2Cart

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
} //end function gup

function updateCartItems(lid, ignore)
{
	if (typeof ignore == "undefined") {
    ignore = "1";
	}
	if (gup('pid')=='14' && ignore==1) 
	{		
		document.location.href=document.location.href;		
		return false;
	}
	if (lid==1)
	{
		msg1 = "Ο browser σας δεν υποστηρίζει AJAX!";
		msg2 = "προϊόντα";
	}
	else
	{
		msg1 = "Your browser does not support AJAX!";
		msg2 = "products";
	} 
	document.getElementById('cartitems').innerHTML = '(...) '+msg2;
	var xmlHttp;
	try { 	// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();	} catch (e) {	// Internet Explorer
		try {	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 	} catch (e) {
			try {	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");	} catch (e) {	alert(msg1);	
			return false;	}
			}
		}
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
				{
				                       //        alert(xmlHttp.responseText);
					if (xmlHttp.responseText!=-1)
					{
						document.getElementById('cartitems').innerHTML = '(' + xmlHttp.responseText + ') ' + msg2;
					}    //end if - email added
					else 
					{
						document.getElementById('cartitems').innerHTML = '???';
					} //end else - referrer not recognised
				}
		}
	xmlHttp.open("GET","http://www.solidshop.gr/wmt/webpages/wmt_countcartitems.php", true);
	xmlHttp.send(null);

} //end function updateCartItems

function quantityChanged(session_id, cid, quantity, lid, pid)
{
	show(lid);
	location.href='wmt_changequantity.php?sessionid='+session_id+'&cid='+cid+'&quantity='+quantity+'&lid='+lid+'&pid='+pid;
	hide();
} //end function quantityChanged

function deleteitem(session_id, cid, lid ,pid)
{
	location.href='wmt_deleteitemfromcart.php?sessionid='+session_id+'&cid='+cid+'&lid='+lid+'&pid='+pid;
} //end function deleteitem

function hide() {
  document.getElementById('generalindicator').innerHTML = "";
  if (browserType == "gecko" )
     document.poppedLayer = 
         eval('document.getElementById("generalindicator")');
  else if (browserType == "ie")
     document.poppedLayer = 
        eval('document.getElementById("generalindicator")');
  else
     document.poppedLayer =   
        eval('document.layers["generalindicator"]');
  document.poppedLayer.style.visibility = "hidden";
}

function show(lid) {
	if (lid==1)
	{
		msg1 = " Φορτώνει, παρακαλώ περιμένετε . . .";
	}
	else
	{
		msg1 = " Loading; please wait . . .";
	} 
  document.getElementById('generalindicator').innerHTML = "<br/><br/><br/><img src='files/indicator.gif' border='0' />"+msg1;
  if (browserType == "gecko" )
     document.poppedLayer = 
         eval('document.getElementById("generalindicator")');
  else if (browserType == "ie")
     document.poppedLayer = 
        eval('document.getElementById("generalindicator")');
  else
     document.poppedLayer = 
         eval('document.layers["generalindicator"]');
  document.poppedLayer.style.visibility = "visible";
}


