
var position = 0;
//var color = "#ffffff";
var timer;


function startPolling(){timer=setInterval("poll()",1000)}
function stopPolling(){
clearTimeout(timer);	
}
function poll(){
/*if (navigator.appName == "Microsoft Internet Explorer"){position = document.body.scrollTop;}
else {position = window.pageYOffset;}*/
var scrOfX = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    position = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    position = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    position = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  //alert(position);
document.getElementById('image_content').style.top=position+'px';
}

function zoomPicture(obj,prd){
	showImage();
	var viewportwidth;
 	var viewportheight;
 
 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 if (typeof window.innerWidth != 'undefined')
 {
      viewportwidth = window.innerWidth,
      viewportheight = window.innerHeight
 }
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
 else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
 {
       viewportwidth = document.documentElement.clientWidth,
       viewportheight = document.documentElement.clientHeight
 } 
 // older versions of IE
 else
 {
       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
       viewportheight = document.getElementsByTagName('body')[0].clientHeight
 }
if (prd == '') {
	viewportwidth -= 100;
	viewportheight -= 100;
}else{
	viewportwidth -= 200;
	viewportheight -= 200;
}
	if(xhtml.readyState==4 || xhtml.readyState==0){
		xhtml.open('GET','include/view_image.php?url='+obj.href+'&prd='+prd+'&mxw='+viewportwidth+'&mxh='+viewportheight,true);
		xhtml.onreadystatechange=function(){
			if(xhtml.readyState==4 && xhtml.status==200){
			document.getElementById('image_content').innerHTML=xhtml.responseText;
			startPolling();
			}
		}
		xhtml.send(null);
	}
}

function showImage(){
	//document.getElementById('prd_qty').value='';
var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }

var viewportwidth;
 var viewportheight;
 
 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 
 if (typeof window.innerWidth != 'undefined')
 {
      viewportwidth = window.innerWidth,
      viewportheight = window.innerHeight
 }
 
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

 else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
 {
       viewportwidth = document.documentElement.clientWidth,
       viewportheight = document.documentElement.clientHeight
 }
 
 // older versions of IE
 
 else
 {
       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
       viewportheight = document.getElementsByTagName('body')[0].clientHeight
 }


var winl=(viewportwidth-300)/2;
var wint=(viewportheight-400)/2+scrOfY;


//document.getElementById('numeric_pad').style.left=winl+'px';
//document.getElementById('numeric_pad').style.top=wint+'px';
//document.getElementById('numeric_pad').style.display='block';
ph=new Array();
ph=getPageSizeWithScroll();
if(ph[1]<viewportheight) ph[1]=viewportheight;
document.getElementById('imagex').style.height=ph[1]+'px';
document.getElementById('imagex').style.width=(ph[0]-20)+'px';
document.getElementById('imagex1').style.height=ph[1]+'px';
document.getElementById('imagex1').style.width=(ph[0]-20)+'px';
document.getElementById('imagex').style.display='block';
document.getElementById('image_content').style.position='absolute';
document.getElementById('image_content').style.width='100%';
document.getElementById('image_content').style.left='0px';
document.getElementById('image_content').style.top=scrOfY+'px';
document.getElementById('slide').style.display='none';
}

function closeImage(){
document.getElementById('imagex').style.display='none';
document.getElementById('image_content').innerHTML='<div style="width:250px; height:250px; padding:20px; background:#333333; border:1px solid #000000; position:relative; z-index:4;">'+
	        '<div style="background:#eeeeee; height:240px; padding:5px; width:240px; overflow:auto;">'+
	          '<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">'+
  '<tr>'+
    '<td height="240" align="center" valign="middle" bgcolor="#FFFFFF"><img src="images/loading_img.gif" alt="Loading" width="40" height="40" /></td>'+
  '</tr>'+
'</table>'+

	       ' </div>'+
	      '/div>';
document.getElementById('slide').style.display='block';	      
}

function addCartx2(kode,prd){
		qty=document.getElementById('prd_qty'+kode).value;
		title_prd=document.getElementById('title_product').value;	
		if (qty > 0) {
			var md = qty % document.getElementById('hide_prd_qty' + kode).value;
			if (md != 0) {
				if (parseInt(qty) < parseInt(document.getElementById('hide_prd_qty'+kode).value)) {
					qty1 = document.getElementById('hide_prd_qty'+kode).value;
				}
				else {
					var xx = document.getElementById('hide_prd_qty'+kode).value - md;
					qtyx = parseInt(qty) + parseInt(xx);
					var xx1=document.getElementById('prd_qty'+kode).value%document.getElementById('hide_prd_qty'+kode).value;
					var qty2=document.getElementById('prd_qty'+kode).value-xx1;
					var xxx = document.getElementById('hide_prd_qty'+kode).value / 2;
					if(parseInt(xx)>xxx) qty1=qty2; else qty1=qtyx;
				
				}
				var yes='qty = '+qty1+';'+
					'document.getElementById(\'prd_qty'+kode+'\').value = qty;';
				
				yes+='yesAddCartx2(\''+kode+'\',\''+qty1+'\',\''+prd+'\',\''+title_prd+'\')';
				var no='document.getElementById(\'prd_qty'+kode+'\').value=\'\'';
				confirmMsg('Vous ne pouvez pas commander ' + qty + ' pcs. Ce produit est vendu par ' + document.getElementById('hide_prd_qty' + kode).value + ' pcs.<br>Vous devez choisir un multiple de ' + document.getElementById('hide_prd_qty' + kode).value + '<br><br>Voulez-vous commanderr ' + qty1 + ' pcs?',yes,no,'');
			}else{
				yesAddCartx2(kode,qty,prd,title_prd);
			}
		}else{
			alertMsg('SVP saisissez la  quantit&eacute; que vous souhaitez!','');
		}
}

function yesAddCartx2(kode,qty,prd,title){
				if(sendReq.readyState==4 || sendReq.readyState==0){
				document.getElementById('contentx').innerHTML='<div style="background:#ffffff;"><img src="images/loading_img.gif" alt="loading" width="32" height="32"></div>';
				sendReq.open("POST", 'include/sc_additem.php', true);
				sendReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
				sendReq.onreadystatechange = function(){
				if(sendReq.readyState==4 && sendReq.status==200){
					window.location.reload();
					}
				}
				var param='proses=add';
				param+='&proid='+prd;
				param+='&jumlahproduk='+qty/document.getElementById('hide_prd_qty'+kode).value;
				param+='&titleproduct='+title;
				param+='&qty=';
				param+='&code='+document.getElementById('code');
				sendReq.send(param);
								
				}				
}

function getTotalCart(){
	//doRequest("get","include/get_total.php",'text','cart_total');
	if(sendReq.readyState==4 || sendReq.readyState==0){
		sendReq.open('GET','include/get_total.php',true);
		sendReq.onreadystatechange=function(){
			if(sendReq.status==200 && sendReq.readyState==4){
				document.getElementById('cart_total').innerHTML=sendReq.responseText;
				closeImage();
			}
		}
		sendReq.send(null);
	}
}
