var xmlHttp;
var strArray = new Array();
var mX, mY;

function getProdDet(storeProductId, storeId, e)
{ 
	/*if (navigator.appName == "Microsoft Internet Explorer"){
		mX = event.clientX+document.body.scrollLeft;
		mY = event.clientY+document.body.scrollTop;
	}
	else {
		mX = e.pageX;
		mY = e.pageY;
	}*/
	msgbox = document.getElementById("productDetails");

	/*
	if ((mY - 400) > 0) {
		msgbox.style.top = (mY - 400)+"px";
	}*/
	msgbox.style.visibility = "visible";

	JSFX_FloatDiv(msgbox.id, 10,30).floatIt();

	xmlHttp=getXmlHttpObj_forProdDetails()
	if (xmlHttp==null)
	{
	 alert ("Browser does not support HTTP Request")
	 return
	}
	
	//alert ('Product: '+storeProductId+' Store id: '+storeId);

	var url="WEB-INF/classes/GetProductDetail.php?storeProductId="+storeProductId+"&storeId="+storeId;

	xmlHttp.onreadystatechange=gotProdDetailsData;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

}

function gotProdDetailsData() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		result = xmlHttp.responseText;
		prodDetailsDisplay(result);
	} 
}

function getXmlHttpObj_forProdDetails()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}




function prodDetailsDisplay(message)
 {
  msgbox = document.getElementById("productDetails");

  strArray = message.split('::');

  prodImage = getStringValue('ProductImage');
  storeProdId = getStringValue('StoreProductId');
  storeProductVariantId = getStringValue('StoreProductVariantId');
  catId = getStringValue('ProductCategoryId');
  dispUnitName = getStringValue('ProductUnit');
  
  htmlText = "<div id=prodDetJS-1 style='width:500;align:left;'>";
  htmlText = htmlText + "<form name=frmAddToCart-1 id=frmAddToCart-1>";
  htmlText = htmlText + "<input type=hidden name=hdnStoreProductid-1 id=hdnStoreProductid-1 value='"+storeProdId+"'/>";
  htmlText = htmlText + "<input type=hidden name=hdnStoreProductVariantid-1 id=hdnStoreProductVariantid-1 value='"+storeProductVariantId+"'/>";
  htmlText = htmlText + "<input type=hidden name=hdnCategoryid-1 id=hdnCategoryid-1 value='"+catId+"'/>";
  htmlText = htmlText + "<table class=conttext border=0 cellspacing=2 cellpadding=2 align=center width=480><tr><td align=center colspan=2>";
  htmlText = htmlText + "[<a style='cursor: pointer;' onclick='closeProductDetails()'>close window</a>]";
  htmlText = htmlText + "</td></tr><tr><td colspan=2>";
  htmlText = htmlText + "<br><img border='0' src='web/img/prod/"+prodImage+"'/><br></td></tr>";

  htmlText = htmlText + "<tr><td align=left colspan=2>";
  htmlText = htmlText + getStringValue('ProductName');
  htmlText = htmlText + "</td></tr>";

  htmlText = htmlText + "<tr><td align=left colspan=2>";
  htmlText = htmlText + getStringValue('ProductVariantName');
  htmlText = htmlText + "</td></tr>";

  if (dispUnitName != '') {
	  htmlText = htmlText + "<tr><td align=left colspan=2>";
	  htmlText = htmlText + "Units: " + dispUnitName;
	  htmlText = htmlText + "</td></tr>";
  }
  
  mrp = getStringValue('ProductMRP');
  if (getStringValue('ProductHasVariants') == 1) {
  	mrp = getStringValue('ProductVariantMRP');
  }
  
  if (mrp != 0) {
	  htmlText = htmlText + "<tr><td align=left width=20% valign=top>";
	  htmlText = htmlText + "MRP: </td><td>";
	  htmlText = htmlText + "Rs."+ mrp;
	  htmlText = htmlText + "</td></tr>";
  }

  productHasAttribute = getStringValue('ProductHasAttributes');
  
  htmlText = htmlText + "<tr><td align=left width=20% valign=top>";
  htmlText = htmlText + "<span class=conttextbold>Namma Price: </span></td><td>";
  htmlText = htmlText + "Rs."+ getStringValue('ProductStoreProductPrice');
  htmlText = htmlText + "</td></tr>";
  htmlText = htmlText + "<tr><td align=left>Quantity: &nbsp;<input class=inpr type=text name=txtQuantity-1 id=txtQuantity-1 size=1 onfocus='this.select();'/></td>";
  htmlText = htmlText + "<td align=left><img style='cursor:pointer;' src='web/img/addtocart.png' border='0' title='Add to Cart' alt='Add to Cart' onclick=additnow();></td></tr>";

  if (productHasAttribute == 'Y') {
  	htmlText = htmlText + "<tr><td colspan=2 align=left valign=top>Special request: &nbsp;<input class=inprt type=text name=txtAttributes-1 id=txtAttributes-1 size=1 onfocus='this.select();'/></td></tr>";
  }
  
  moreDetailsCount = getStringValue('ProductMoreDetailsCount');
  for (j=0;j<moreDetailsCount;j++) {
	  htmlText = htmlText + "<tr><td align=left width=120 valign=top><span class=conttextbold>";
	  htmlText = htmlText + getStringValue('productDetailName'+j)+":</span></td><td>";
	  htmlText = htmlText + getStringValue('ProductDetailValue'+j);
	  htmlText = htmlText + "</td></tr>";
  }
  htmlText = htmlText + "<tr><td align=center colspan=2>";
  htmlText = htmlText + "</td></tr></table></form>";
  htmlText = htmlText + "[<a style='cursor: pointer;' onclick='closeProductDetails()'>close window</a>]</div>";
  msgbox.innerHTML = htmlText;
  quantity = document.getElementById("txtQuantity-1");
  quantity.focus();
 }
 
function closeProductDetails() {
	if (navigator.appName == "Microsoft Internet Explorer"){
		changeOpac(100,'siteLayoutPage');
	}
	else {
		opacity('siteLayoutPage', 20, 100, 200);
	}

     	msgbox = document.getElementById("productDetails");
     
	htmlText = "<div style='width:500;align:center;'>";
	htmlText = htmlText + "[<a class='conttext' style='cursor: pointer;' onclick='closeProductDetails()'>close window</a>]";
	htmlText = htmlText + "<p class='conttext' style='text-align:center'>";
	htmlText = htmlText + "<br><br><br><br>";
	htmlText = htmlText + "<img src='web/img/loading.gif'>";
	htmlText = htmlText + "<br><br><br><br>";
	htmlText = htmlText + "<p>";
	htmlText = htmlText + "[<a class='conttext' style='cursor: pointer;' onclick='closeProductDetails()'>close window</a>]";
	htmlText = htmlText + "</div>";
	
	msgbox.innerHTML = htmlText;
	msgbox.style.visibility = "hidden";
}

function getStringValue(str) {
	var retString;
	//alert(str+' ---- '+strArray.length);
	for (i=0;i<strArray.length;i++) {
		if (strArray[i] == str) {
			return strArray[i+1];
		}
	}
	
	return '';	
}

function openProductDetail() {
	if (navigator.appName == "Microsoft Internet Explorer"){
		changeOpac(20,'siteLayoutPage');
	}
	else {
		opacity('siteLayoutPage', 100, 20, 200);
	}
}

function additnow() {
	if (addtocart('frmAddToCart1',-1,'"+productHasAttribute+"','"+prodImage+"') == false)
	{
		
	}
	else
	{
		closeProductDetails();
	}
}
