var xmlHttp
var frm = null;
var result = null;
var quantity = null;
//var chkSel = null;
var hasAttr = null;
var txtAttrb = null;
var fromFunc = null;
var strArry = new Array();
//var strArry1 = new Array();
//var strArryTemp = new Array();

var answerFunction;
function myConfirm(text,button1,button2,answerFunc) {
	var box = document.getElementById("confirmBox");
	box.getElementsByTagName("p")[0].firstChild.nodeValue = text;
	var button = box.getElementsByTagName("input");
	button[0].value=button1;
	button[1].value=button2;
	answerFunction = answerFunc;
	
	var prgDiv = document.getElementById("progressDiv");
	prgDiv.style.visibility="visible";
	prgDiv.style.display="block";
	
	//prgDiv.style.top = prgDiv.style.top + document.body.scrollTop;

	box.style.visibility="visible";
	box.style.display="block";
	
	//alert(document.body.scrollTop);
	placeConfirm(box,prgDiv);
	

	if (navigator.appName == "Microsoft Internet Explorer"){
		changeOpac(20,'siteLayoutPage');
	}
	else {
		opacity('siteLayoutPage', 100, 20, 200);
	}
}

function answer(response) {
	document.getElementById("confirmBox").style.visibility="hidden";
	document.getElementById("confirmBox").style.display="none";

	if (navigator.appName == "Microsoft Internet Explorer"){
		changeOpac(100,'siteLayoutPage');
	}
	else {
	     opacity('siteLayoutPage', 20, 100, 200);
	}

	answerFunction(response);
}

function callAjax(url)
{
	//alert('hai in callajax url '+url);
	xmlHttp=GetXmlHttpObject()

	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}

	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}


function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		result = xmlHttp.responseText;
		checkResult(result);		
	} 
}

function GetXmlHttpObject()
{
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 showCart()
{

	fromFunc = 2;
	var url="WEB-INF/classes/ShowCart.php";
	callAjax(url);

}

function addtocart(thisfrm,id,hasAttrb,prodImage)
{ 
	fromFunc = 1;
	frm = document.getElementById(thisfrm);

	var stPrId = document.getElementById('hdnStoreProductid'+id).value;
	var prVarId = document.getElementById('hdnStoreProductVariantid'+id).value;
	var catId = document.getElementById('hdnCategoryid'+id).value;
	var wantToLogin = '';

	hasAttr = hasAttrb;

	if(prVarId == null || prVarId == '')
	{
		prVarId = 0;
	}
	
	quantity = document.getElementById('txtQuantity'+id)
	var quantityval = trim(quantity.value);
	quantity.value = quantityval;

	if(quantityval == null || quantityval =='' )
	{
		selQuantity = 1;
		alert('Please enter the quantity for the selected product');
		quantity.focus();
		quantity.select();
		return false;
	}
	else {
		if(isNaN(quantityval) || quantityval == 0) {
			alert('Please enter a numeric value greater then Zero');
			quantity.focus();					
			return false;
		}
		if(!IsInteger(quantityval))
		{
			alert(' Quantity cannot be a fractional value');
			quantity.focus();
			return false;
		}
		if (quantityval > 99)
		{
			alert(' Quantity cannot be greater than 99');
			quantity.focus();
			return false;
		}
	}
	txtAttrb = null;
	if(hasAttr == 'Y')
	{
		txtAttrb = document.getElementById('txtAttributes'+id);
		txtAttrb.value = trim(txtAttrb.value);
		if(txtAttrb.value != '' || txtAttrb.value == null)
		{
			if(!regAlpNum.test(txtAttrb.value))
			{
				alert('Please enter valid Special request');
				txtAttrb.focus();
				txtAttrb.select();
				return false;
			}
		}
	}

	var url="WEB-INF/classes/AddToCart.php"
	url=url+"?SPID="+ stPrId
	url=url+"&PVID="+ prVarId;
	url=url+"&CATID="+ catId;
	url=url+"&quantity="+ quantityval;

	if(hasAttr == 'Y')
	{
		url=url+"&attribute="+ trim(txtAttrb.value);	
	}
	else
	{
		url=url+"&attribute= ";
	}

	var loggedIn = document.getElementById('userLoggedIn').value;
	var custCartId = document.getElementById('custCartId').value;
	if (loggedIn != 1 && custCartId == 0) {
		confirmLogin (url);
	}
	else {
		showFlying(id,prodImage);
		callAjax(url);
	}

}

function confirmLogin (url) {
	myConfirm("Dear customer,","Yes","No",function (answer) {
									if (answer) {
										url = url + "&signinrequired=yes";
										callAjax(url);
									}
									else {
										callAjax(url);
									}
								}
		);

}

function getSubCat(thisfrm,parentCatID)
{

	fromFunc = 3;
	if(parentCatID == 0)
	{
		parentCatID = -1;
	}
	if(thisfrm.name == 'frmEditProduct')
	{
		thisfrm.selProdId.options.length = 1;
		clear_ProdData(thisfrm);	
	}
	else if(thisfrm.name == 'frmAddStoreProduct' || thisfrm.name == 'frmAddOrderItem')
	{
		thisfrm.selSubCat.options.length = 1
		clear_StoreData(thisfrm);	
	}
	var url="WEB-INF/classes/GetSubCategory.php?parentCategoryId="+parentCatID;
	callAjax(url);	
}


function getCatProduct(thisfrm,categoryId)
{
	//alert(' categoryId '+categoryId);
	fromFunc = 4;
	
	//clear all the previous data of variant part
	
	if(categoryId == 0)
	{
		categoryId = -1;
	}
	
	if(thisfrm.name == 'frmEditProduct')
	{
		thisfrm.selProdId.options.length = 1;
		clear_ProdData(thisfrm);	
	}
	else if(thisfrm.name == 'frmAddStoreProduct' || thisfrm.name == 'frmAddOrderItem')
	{
		//thsfrm.selSubCat.options.length = 1
		clear_StoreData(thisfrm);	
	}
	var str = '';
	if(thisfrm.name == 'frmEditProdVariant'){
		str ='&variant=1';
	}
	
	var url="WEB-INF/classes/GetCategoryProducts.php?categoryId="+categoryId+str;
	
	callAjax(url);
}


function getSubCategory(thisfrm,parentCatID)
{
	fromFunc = 5;
	if(parentCatID == 0)
	{
		parentCatID = -1;
	}
	var url="WEB-INF/classes/GetSubCategory.php?parentCategoryId="+parentCatID;
	callAjax(url);
}

function getProduct(thisfrm,productId)
{
	fromFunc = 6;
	
	//clear all the previous data of variant part
	
	if(productId == 0)
	{
		productId = -1;
	}
	
	if(thisfrm.name == 'frmEditProduct')
	{
		//thisfrm.selProdId.options.length = 1;
		clear_ProdData(thisfrm);	
	}
	var url="WEB-INF/classes/GetProduct.php?productId="+productId;	
	callAjax(url);

}

function getVariant(thisfrm,variantId)
{
	//alert('hai');
	fromFunc = 7;
	//alert(' variantId '+variantId+' this frm '+thisfrm)
	//clear all the previous data of variant part
	
	if(variantId == 0)
	{
		variantId = -1;
	}
	var url="WEB-INF/classes/GetVariant.php?variantId="+variantId;	
	callAjax(url);

}

function getProductVariant(thisfrm,productId)
{
	fromFunc = 8;
	if(productId == 0)
	{
		productId = -1;
	}
	if(thisfrm.name == 'frmAddStoreProduct')
	{
		//thsfrm.selSubCat.options.length = 1
		clear_StoreData(thisfrm);	
	}
	var url="WEB-INF/classes/GetProdVariant.php?productId="+productId;	
	callAjax(url);
}

function getStoreProduct(thisfrm,storeId)
{
	fromFunc = 9;
	if(storeId == 0)
	{
		storeId = -1;
	}
	productId = thisfrm.selProdId.value;
	if(productId == 0)
	{
		productId = -1;
	}
	variantId = thisfrm.selProdVarId.value;
	/*if(variantId == 0)
	{
		variantId = -1;
	}*/
	var url="WEB-INF/classes/GetStoreProduct.php?storeId="+storeId+"&productId="+productId+"&variantId="+variantId;	
	//alert(url);
	callAjax(url);
}


function getStoreCategory(thisfrm,storeId)
{
	fromFunc = 10;
	if(storeId == 0)
	{
		storeId = -1;
	}
	var url="WEB-INF/classes/GetStoreCategory.php?storeId="+storeId+"&parentId=0";
	clear_OrderData(thisfrm);
	callAjax(url);
}

function getStoreSubCategory(thisfrm,parentId)
{
	fromFunc = 11;
	
	storeId = thisfrm.selStoreId.options[thisfrm.selStoreId.selectedIndex].value
	if(storeId == '')
	{
		storeId = -1;
	}
	if(parentId == '')
	{
		parentId = -2;
	}
	clear_OrderData(thisfrm);
	var url="WEB-INF/classes/GetStoreCategory.php?storeId="+storeId+"&parentId="+parentId;
	callAjax(url);
}

function getCategoryDetails(thisfrm,categoryId)
{
	fromFunc = 12;
	
	if(categoryId == '')
	{
		categoryId = -1;
	}
	clearCategoryData(thisfrm);
	var url="WEB-INF/classes/GetCategoryDetails.php?categoryId="+categoryId;
	callAjax(url);
}

function getStoreCatProduct(thisfrm,categoryId)
{
	fromFunc = 13;
	
	//clear all the previous data of variant part
	storeId = thisfrm.selStoreId.options[thisfrm.selStoreId.selectedIndex].value
	if(storeId == '')
	{
		storeId = -1;
	}
	
	if(categoryId == 0)
	{
		categoryId = -1;
	}	
	
		//thsfrm.selSubCat.options.length = 1
	//clear_OrderData(thisfrm);
	
	var url="WEB-INF/classes/GetStoreCategoryProducts.php?storeId="+storeId+"&categoryId="+categoryId;	
	callAjax(url);
}
function getStoreProductVariant(thisfrm,productId)
{
	
	fromFunc = 14;
	
	//clear all the previous data of variant part
	storeId = thisfrm.selStoreId.options[thisfrm.selStoreId.selectedIndex].value
	if(storeId == '')
	{
		storeId = -1;
	}
	
	if(productId == 0)
	{
		productId = -1;
	}	
	
	//thsfrm.selSubCat.options.length = 1
		
	var url="WEB-INF/classes/GetStoreProdVariant.php?storeId="+storeId+"&productId="+productId;	
	//alert(url);
	callAjax(url);
}



function checkResult(result)
{
	if(fromFunc == 1)
	{
		var res = null;
		res = result.split(":");

		if(res[0] == "CALL")
		{
			//sbmtButton = document.getElementById("btnAdd2Cart");
			//sbmtButton.click();
			window.location = "index.php?do=Signin&signInText=Sign in";
		}
		else if(res[0] == "MSG")
		{			
			quantity.value = '';
			//chkSel.checked = false;;
			if(hasAttr == 'Y')
			{
				txtAttrb.value = '';
			}
		}
		if (res[2] == "CID") {
			document.getElementById('custCartId').value = res[3];
		}
		showCart();
	}
	else if(fromFunc == 2)
	{		
		var res = null;
		res = result.split("~");

		if(res[0] == "DISP")
		{
			var shCart = document.getElementById("showCart");
			shCart.innerHTML = res[1];
			unhidetab('viewCart');
			unhide('divViewCart');
		}
		else if(res[0] == "MSG")
		{
			alert(res[1]);
			hide('divViewCart');
			//hide('viewCart');
		}
		else {
			hide('divViewCart');
		}
		
	}
	else if(fromFunc == 3)
	{
		var strArry = new Array();
		strArry = result.split('::');
		var selSubCat = document.getElementById("selSubCat");		
		
		if(strArry[0] == "MSG")
		{
			alert(strArry[1]);			
		}
		if(selSubCat.length > 1) {		
			selSubCat.length = 1;			
		}
		if(parseInt(strArry.length/10)<=0)
		{
			selSubCat.disabled = true;
			var selCatgy = document.getElementById("selCat");
			categoryId = selCatgy.options[selCatgy.selectedIndex].value;
			getCatProduct(selCatgy.form,categoryId);
			//getSubCategory(selCatgy.form,categoryId);
		}
		else
		{
			selSubCat.disabled = false;
		}
		
		for(i=0;i<parseInt(strArry.length/10);i++)
		{
			text = getStringVal('CategoryName'+i,strArry);
			value = getStringVal('CategoryId'+i,strArry);
			//alert('text->'+text+' value '+value)
			//AddItem(text,value,i+1);
			var opt = document.createElement("option");
						
			// Assign text and value to Option object
			opt.text = text;
			opt.value = value;
			selSubCat.options[i+1] = opt;			
		}
		
	}
	else if(fromFunc == 4)
	{
		//alert(result);
		var strArry = new Array();
		strArry = result.split('::');
		var selProd = document.getElementById("selProdId");
		//alert(' strArry '+strArry);
		if(strArry[0] == "MSG")
		{
			alert(strArry[1]);			
		}
		if(selProd.length > 1) {		
			selProd.length = 1;			
		}

		for(i=0;i<parseInt(strArry.length/4);i++)
		{
			//alert(' i -> '+i);
			
			text = getStringVal('ProductName'+i,strArry);
			value = getStringVal('ProductId'+i,strArry);
			
			//alert('text->'+text+' value '+value)
			//AddItem(text,value,i+1);
			
			var opt = document.createElement("option");
			
			//alert(' hrer '+getStringVal('ProductId0',strArry));
			
			// Assign text and value to Option object
			opt.text = text;
			opt.value = value;
			selProd.options[i+1] = opt;
		}
	}
	else if(fromFunc == 5)
	{
		var strArry = new Array();
		strArry = result.split('::');
		var selSubCate = document.getElementById("selectSubCat");
		
		//alert(strArry)
		
		if(strArry[0] == "MSG")
		{
			alert(strArry[1]);
		}
		if(selSubCate.length > 1) {		
			selSubCate.length = 1;			
		}
		if(parseInt(strArry.length/10)<=0)
		{
			selSubCate.disabled = true;
		}
		else
		{
			selSubCate.disabled = false;
		}
		
		for(i=0;i<parseInt(strArry.length/10);i++)
		{
			text = getStringVal('CategoryName'+i,strArry);
			value = getStringVal('CategoryId'+i,strArry);
			//alert('text->'+text+' value '+value)
			//AddItem(text,value,i+1);
			var opt = document.createElement("option");
						
			// Assign text and value to Option object
			opt.text = text;
			opt.value = value;
			selSubCate.options[i+1] = opt;
		}
	}	
	else if(fromFunc == 6)
	{
		var strArry = new Array();
		//strArryTemp = result.split('~');
		strArry = result.split('::');
		//strArry1 = strArryTemp[1].split('::');
		
		//alert('strArryTemp product '+strArry);
		//alert('strArryTemp variants '+strArryTemp[1]);
		

		if(strArry[0] == "MSG")
		{
			alert(strArry[1]);			
		}
		
		displayProduct(strArry);		
	}
	else if(fromFunc == 7)
	{
		//strArryTemp = result.split('~');
		//strArry = result.split('::');
		strArry1 = result.split('::');
		//alert(' st ret '+result);
		if(strArry1[0] == "MSG")
		{
			alert(strArry1[1]);			
		}
		
		displayVariant(strArry1);		
	}
	else if(fromFunc == 8)
	{
		//alert(result);
		var strArry = new Array();
		strArry = result.split('::');
		var selProdVar = document.getElementById("selProdVarId");
		
		if(strArry[0] == "MSG")
		{
			alert(strArry[1]);			
		}
		if(selProdVar.length > 1) {		
			selProdVar.length = 1;			
		}
		if(parseInt(strArry.length/4)<=0)
		{
			selProdVar.disabled = true;
		}
		else
		{
			selProdVar.disabled = false;
			//getStoreProduct(thisfrm,storeId);
		}
		
		for(i=0;i<parseInt(strArry.length/4);i++)
		{
			text = getStringVal('VariantName'+i,strArry);
			value = getStringVal('VariantId'+i,strArry);
			//alert('text->'+text+' value '+value)
			//AddItem(text,value,i+1);
			var opt = document.createElement("option");
			
			// Assign text and value to Option object
			opt.text = text;
			opt.value = value;
			selProdVar.options[i+1] = opt;
		}
	}
	else if(fromFunc == 9)
	{
		var strArry = new Array();
		//strArryTemp = result.split('~');
		strArry = result.split('::');
		//strArry1 = strArryTemp[1].split('::');
		
		//alert('strArryTemp product '+strArry);
		//alert('strArryTemp variants '+strArryTemp[1]);
		

		if(strArry[0] == "MSG")
		{
			alert(strArry[1]);			
		}
		
		displayStoreProduct(strArry);	
	}
	else if(fromFunc == 10)
	{
		var strArry = new Array();
		strArry = result.split('::');
		var selCate = document.getElementById("selCat");

		//alert(strArry)

		if(strArry[0] == "MSG")
		{
			alert(strArry[1]);			
		}
		if(selCate.length > 1) {		
			selCate.length = 1;			
		}
		if(parseInt(strArry.length/10)<=0)
		{
			selCate.disabled = true;
		}
		else
		{
			selCate.disabled = false;
		}

		for(i=0;i<parseInt(strArry.length/10);i++)
		{
			text = getStringVal('CategoryName'+i,strArry);
			value = getStringVal('CategoryId'+i,strArry);
			//alert('text->'+text+' value '+value)
			//AddItem(text,value,i+1);
			var opt = document.createElement("option");

			// Assign text and value to Option object
			opt.text = text;
			opt.value = value;
			selCate.options[i+1] = opt;
		}
	}
	else if(fromFunc == 11)
	{
		var strArry = new Array();
		strArry = result.split('::');
		var selSubCate = document.getElementById("selSubCat");

		//alert(strArry)

		if(strArry[0] == "MSG")
		{
			alert(strArry[1]);			
		}
		if(selSubCate.length > 1) {		
			selSubCate.length = 1;			
		}
		if(parseInt(strArry.length/10)<=0)
		{
			selSubCate.disabled = true;
			var selCatgy = document.getElementById("selCat");
			categoryId = selCatgy.options[selCatgy.selectedIndex].value;
			getStoreCatProduct(selSubCate.form,categoryId)
		}
		else
		{
			selSubCate.disabled = false;
		}

		for(i=0;i<parseInt(strArry.length/10);i++)
		{
			text = getStringVal('CategoryName'+i,strArry);
			value = getStringVal('CategoryId'+i,strArry);
			//alert('text->'+text+' value '+value)
			//AddItem(text,value,i+1);
			var opt = document.createElement("option");

			// Assign text and value to Option object
			opt.text = text;
			opt.value = value;
			selSubCate.options[i+1] = opt;
		}
	}
	else if(fromFunc == 12)
	{
		var strArry = new Array();
		strArry = result.split('::');
		
		if(strArry[0] == "MSG")
		{
			alert(strArry[1]);			
		}
		
		displayCategory(strArry);		
	}
	else if(fromFunc == 13)
	{
		//alert(result);
		var strArry = new Array();
		strArry = result.split('::');
		var selProd = document.getElementById("selProdId");
		
		if(strArry[0] == "MSG")
		{
			alert(strArry[1]);			
		}
		if(selProd.length > 1) {		
			selProd.length = 1;			
		}
		/*if(parseInt(strArry.length/10)<=0)
		{
			selProd.disabled = true;
		}
		else
		{
			selProd.disabled = false;
		}*/
		
		for(i=0;i<parseInt(strArry.length/8);i++)
		{
			value = getStringVal('ProductId'+i,strArry);
			text = getStringVal('ProductName'+i,strArry);
			//alert('text->'+text+' value '+value)
			//AddItem(text,value,i+1);
			var opt = document.createElement("option");
			//alert(' hrer '+getStringVal('ProductId0',strArry));
			// Assign text and value to Option object
			opt.text = text;
			opt.value = value;
			selProd.options[i+1] = opt;
		}
	}
	else if(fromFunc == 14)
	{
		//alert(result);
		var strArry = new Array();
		strArry = result.split('::');
		var selProdVar = document.getElementById("selProdVarId");

		if(strArry[0] == "MSG")
		{
			alert(strArry[1]);			
		}
		if(selProdVar.length > 1) {		
			selProdVar.length = 1;			
		}
		if(parseInt(strArry.length/4)<=0)
		{
			selProdVar.disabled = true;
		}
		else
		{
			selProdVar.disabled = false;
			//getStoreProduct(thisfrm,storeId);
		}

		for(i=0;i<parseInt(strArry.length/6);i++)
		{
			text = getStringVal('VariantName'+i,strArry);
			value = getStringVal('VariantId'+i,strArry);
			//alert('text->'+text+' value '+value)
			//AddItem(text,value,i+1);
			var opt = document.createElement("option");

			// Assign text and value to Option object
			opt.text = text;
			opt.value = value;
			selProdVar.options[i+1] = opt;
		}
	}
}



function AddItem(Text,Value,pos)
{
// Create an Option object        

var opt = document.createElement("option");

// Assign text and value to Option object
opt.text = Text;
opt.value = Value;

// Add an Option object to Drop Down/List Box
//document.getElementById("selectSubCat").options[pos] = opt;
return opt;
}

function getStringVal(str,strArry) {
	var retString;
	for (j=0;j<=strArry.length;j++) {
	
		/*if(j == 0){
			alert(' str->'+str+' --> '+strArry[j]);
		}*/
		
		if (strArry[j] == str) {
			//alert(' str->'+str+' --> '+strArry[j+1]);
			return strArry[j+1];
		}
	}

	return 'xx';	
}

function getStringValVar(str,strArry1) {
	var retString;
	for (v=0;v<strArry1.length;v++) {
		if (strArry1[v] == str) {
			return strArry1[v+1];
		}
	}

	return '';	
}

function displayProduct(strArry)
{
	var thsfrm = document.getElementById('frmEditProduct');
	selPrd = thsfrm.selProdId;
	prodId = getStringVal('ProductId',strArry);
	prodName = getStringVal('ProductName',strArry);
	
	if((selPrd.selectedIndex) == 0 && (selPrd.options.length ==1))
	{
		text = prodName;
		value = prodId;
		//alert('text->'+text+' value '+value)
		//AddItem(text,value,i+1);
		var opt = document.createElement("option");

		// Assign text and value to Option object
		opt.text = text;
		opt.value = value;
		selPrd.options[0] = opt;
		//selPrd.selectedIndex = selPrd.options.length;		
	}
	
	thsfrm.txtProdName.value = prodName;
	thsfrm.txtaProdDes.value = getStringVal('ProductDesc',strArry);
	var brandId = getStringVal('ProductBrandId',strArry);
	thsfrm.selectBrand.selectedIndex = getIndexByValue(thsfrm.selectBrand,brandId);
	
	var parcatId = getStringVal('ParentCategoryId',strArry);
	var prdcatId = getStringVal('ProductCategoryId',strArry);
	//alert(' parcatId '+parcatId+' prdcatId '+prdcatId)
	if(parcatId == 0)
	{
		thsfrm.selectCat.selectedIndex = getIndexByValue(thsfrm.selectCat,prdcatId);
		thsfrm.selectSubCat.disabled = true;
		//alert(' parcatId -> here '+parcatId);
	}
	else
	{
		thsfrm.selectCat.selectedIndex = getIndexByValue(thsfrm.selectCat,parcatId);
		thsfrm.selectSubCat.disabled = false;
		getSubCategory(thsfrm,parcatId);
		
		var subCatIndx =0;
		alert('click here to avoid delay');
		if(!(thsfrm.selectSubCat.disabled))
		{
			subCatIndx = getIndexByValue(thsfrm.selectSubCat,prdcatId);
			//while(subCatIndx == 0)
			//{
			//	subCatIndx = getIndexByValue(thsfrm.selectSubCat,prdcatId);
			//}
			
		}
		
		thsfrm.selectSubCat.selectedIndex = subCatIndx;
	}
	
	thsfrm.txtMRP.value = getStringVal('ProductMRP',strArry);
	prodTaxId = getStringVal('ProductTaxId',strArry);
	//alert(' prodTaxId '+prodTaxId)
	thsfrm.selectTax.selectedIndex = getIndexByValue(thsfrm.selectTax,prodTaxId);
	
	//alert(' has var '+getStringVal('ProductHasVariants',strArry));
	
	if(getStringVal('ProductHasVariants',strArry) == 1)
	{
		thsfrm.chkProdHasVariant.checked = true;
	}
	else
	{
		thsfrm.chkProdHasVariant.checked = false;
	}
	//thsfrm.filImage.value = getStringVal('productImage',strArry);
	
	prodHasAttrb = getStringVal('ProductHasAttributes',strArry);
	
	if( prodHasAttrb == 'Y')
	{
		thsfrm.chkProdHasAttrb.checked = true;
		//displayProductVariant(thsfrm);
	}
	else
	{
		thsfrm.chkProdHasAttrb.checked = false;
	}
	
	if(getStringVal('IsProductAvailable',strArry) == 'Y')
	{
		thsfrm.chkProdAvlb.checked = true;
	}
	else
	{
		thsfrm.chkProdAvlb.checked = false;
	}
	thsfrm.txtCostPrice.value = getStringVal('ProductCostPrice',strArry);
	//thsfrm.txtQntAvlb.value = getStringVal('ProductQuantityAvailable',strArry);
	thsfrm.txtUpdatedDate.value = getStringVal('ProductUpdatedDate',strArry);
	
	measureUnitsid = getStringVal('MeasureUnitsId',strArry);
	//alert(' prodTaxId '+prodTaxId)
	thsfrm.selectMeasureUnits.selectedIndex = getIndexByValue(thsfrm.selectMeasureUnits,measureUnitsid);

	thsfrm.txtDispOrder.value = getStringVal('ProductDisplayOrder',strArry);;
}

function displayVariant(strArry)
{
	var thisfrm = document.getElementById('frmEditProdVariant');
	
	varId = getStringValVar('ProductVariantId',strArry);
	varProdId = getStringValVar('ProductId',strArry);
	varName = getStringValVar('ProductVariantName',strArry);
	varDesc = getStringValVar('ProductVariantDesc',strArry);
	varMrp = getStringValVar('ProductVariantMRP',strArry);
	varHasAttrb = getStringValVar('ProductVariantHasAttrb',strArry);
	varImage = getStringValVar('ProductVariantImage',strArry);
	varTaxId = getStringValVar('ProductVariantTaxId',strArry);
	varProdAvlb = getStringValVar('IsProductVariantAvailable',strArry);
	varProdCostPrice = getStringValVar('ProductVariantCostPrice',strArry);
	//varProdQntAvlb = getStringValVar('ProductVariantQuantityAvailable',strArry);
	varProdUpdDate = getStringValVar('ProductVariantUpdatedDate',strArry);
	varMeasureUnitsId = getStringValVar('MeasureUnitsId',strArry);
	
	selProdVar = thisfrm.selProdVarId;
	if((selProdVar.selectedIndex) == 0 && (selProdVar.options.length ==1))
	{
		text = varName;
		value = varId;
		//alert('text->'+text+' value '+value)
		//AddItem(text,value,i+1);
		var opt = document.createElement("option");

		// Assign text and value to Option object
		opt.text = text;
		opt.value = value;
		selProdVar.options[0] = opt;
		//selPrd.selectedIndex = selPrd.options.length;		
	}
	selPrd = thisfrm.selProdId;
	if((selPrd.selectedIndex) == 0 && (selPrd.options.length ==1))
	{
		text = varName;
		value = varProdId;
		//alert('text->'+text+' value '+value)
		//AddItem(text,value,i+1);
		var opt = document.createElement("option");

		// Assign text and value to Option object
		opt.text = text;
		opt.value = value;
		selPrd.options[0] = opt;
		//selPrd.selectedIndex = selPrd.options.length;		
	}
		
	thisfrm.selProdId.selectedIndex = getIndexByValue(thisfrm.selProdId,varProdId);
	thisfrm.txtProdVarName.value = varName;
	thisfrm.txtaProdVarDes.value = varDesc;
	thisfrm.txtVarMRP.value = varMrp;
	thisfrm.selectVarTax.selectedIndex = getIndexByValue(thisfrm.selectVarTax,varTaxId);
	
	
	if(varHasAttrb == 'Y')
	{
		thisfrm.chkProdHasAttrb.checked = true;
	}
	else
	{
		thisfrm.chkProdHasAttrb.checked = false;
	}
	if(varProdAvlb == 'Y')
	{
		thisfrm.chkProdVarAvlb.checked = true;
	}
	else
	{
		thisfrm.chkProdVarAvlb.checked = false;
	}
	thisfrm.txtVarCostPrice.value = varProdCostPrice;
	//thisfrm.txtVarQntAvlb.value = varProdQntAvlb;
	thisfrm.txtVarLastUpd.value = varProdUpdDate;
	thisfrm.selectMeasureUnits.selectedIndex = getIndexByValue(thisfrm.selectMeasureUnits,varMeasureUnitsId);
	
}

function displayStoreProduct(strArry)
{
	var thsfrm = document.getElementById('frmAddStoreProduct');
	
	strPrdId = getStringValVar('StoreProductId',strArry);
	strId = getStringValVar('StoreId',strArry);
	productId = getStringValVar('ProductId',strArry);
	prodVarID = getStringValVar('ProductVariantId',strArry);
	strProdPrice = getStringValVar('StoreProductPrice',strArry);
	strProdSKU = getStringValVar('StoreProductSku',strArry);
	strProdDiscount = getStringValVar('StoreProductDiscount',strArry);
	strFeaProd = getStringValVar('FeaturedProduct',strArry);
	strProdOffrPrice = getStringValVar('StoreProductOfferPrice',strArry);
	strProdQntyAvlb = getStringValVar('StoreProductQuantityAvailable',strArry);
	
	
	//alert(thsfrm.name);	
	//thsfrm.selectCat.selectedIndex = 0;
	//thsfrm.selSubCat.options.length = 1;

	//thsfrm.selProdId.options.length = 1;
	//thsfrm.selProdVarId.options.length = 1;

	thsfrm.selStoreId.selectedIndex = getIndexByValue(thsfrm.selStoreId,strId);
	if(strFeaProd == 'Y')
	{
		thsfrm.chkStoreFeaProd.checked = true;
	}
	else
	{
		thsfrm.chkStoreFeaProd.checked = false;
	}
	
	thsfrm.txtaStoreProdSKU.value = strProdSKU;	

	thsfrm.txtStoreProdPrice.value = strProdPrice;
	thsfrm.txtStoreProdDiscount.value = strProdDiscount;
	thsfrm.txtStoreProdOffrPrice.value = strProdOffrPrice;
	thsfrm.txtStrProdQntAvlb.value = strProdQntyAvlb;
}

function displayCategory(strArry)
{
	var thsfrm = document.getElementById('frmEditCategory');
	
	catId = getStringValVar('CategoryId',strArry);
	catParId = getStringValVar('ParentCategoryId',strArry);
	catName = getStringValVar('CategoryName',strArry);
	catDesc = getStringValVar('CategoryDesc',strArry);
	catImg = getStringValVar('CategoryImage',strArry);
	catDispOrd = getStringValVar('CategoryDispOrder',strArry);	
	
	thsfrm.selParCatId.selectedIndex = getIndexByValue(thsfrm.selParCatId,catParId);
	thsfrm.txtCatName.value = catName;
	thsfrm.txtaCatDes.value = catDesc;
	//thsfrm.filCatImage.value = catImg;
	thsfrm.txtCatDispOrder.value = catDispOrd;
}


function displayProductVariant(strArry)
{
	var thsfrm = document.getElementById('frmProductUpdate');
	var pos = 0;
	var str = '';
	
	//alert(' var array lenb '+strArry1.length);
	
	for(i=0;i<parseInt(strArry1.length/(7*2));i++)
	{
		pos = thsfrm.hdnNofVariants.value;
		varId = getStringValVar('ProductVariantId'+i,strArry);
		varName = getStringValVar('ProductVariantName'+i,strArry);
		varDesc = getStringValVar('ProductVariantDesc'+i,strArry);
		varMrp = getStringValVar('ProductVariantMRP'+i,strArry);
		varTaxId = getStringValVar('ProductVariantTaxId'+i,strArry);
		varProdAvlb = getStringValVar('IsProductVariantAvailable'+i,strArry);
		
		str = varId+'|'+varName+'|'+varDesc+'|'+varMrp+'|'+varTaxId+'|'+varProdAvlb;
		
		addVarToTab(thsfrm,str,pos,"DBvar")
	}	
}




function removeChildNodes(ctrl)
{
  while (ctrl.childNodes[0])
  {
    ctrl.removeChild(ctrl.childNodes[0]);
  }
}


function clear_ProdData(thsfrm)
{	
		
	//alert(thsfrm);	
	thsfrm.txtProdName.value = '';
	thsfrm.txtaProdDes.value = '';
	thsfrm.selectBrand.selectedIndex = 0;
	
	thsfrm.selectCat.selectedIndex = 0;
	thsfrm.selectSubCat.options.length = 1;

	thsfrm.txtMRP.value = '';
	thsfrm.selectTax.selectedIndex = 0;
	thsfrm.chkProdHasVariant.checked = false;		
	thsfrm.filImage.value = '';	
	thsfrm.chkProdHasAttrb.checked = false;
	thsfrm.chkProdAvlb.checked = false;
	thsfrm.txtCostPrice.value = '';
	//thsfrm.txtQntAvlb.value = '';
}

function clear_StoreData(thsfrm)
{	
		
	//alert(thsfrm);	
	//thsfrm.selectCat.selectedIndex = 0;
	//thsfrm.selSubCat.options.length = 1;
	
	if(fromFunc !=8) {
		thsfrm.selProdId.options.length = 1;
	}	
	thsfrm.selProdVarId.options.length = 1;
	
	thsfrm.selStoreId.selectedIndex = 0;
	thsfrm.chkStoreFeaProd.checked = false;		
	thsfrm.txtaStoreProdSKU.value = '';	
	
	thsfrm.txtStoreProdPrice.value = '';
	thsfrm.txtStoreProdDiscount.value = '';
	thsfrm.txtStoreProdOffrPrice.value = '';	
}

function clear_OrderData(thsfrm)
{	
		
	//alert(thsfrm);	
	//thsfrm.selectCat.selectedIndex = 0;
	thsfrm.selSubCat.options.length = 1;
	
	thsfrm.selProdId.options.length = 1;
		
	thsfrm.selProdVarId.options.length = 1;
	
	thsfrm.txtQuantity.value = '';		
	thsfrm.txtProdAttribute.value = '';
}

function clearCategoryData(thsfrm)
{
	thsfrm.selParCatId.selectedIndex = 0;
	thsfrm.txtCatName.value = '';
	thsfrm.txtaCatDes.value = '';
	thsfrm.filCatImage.value = '';
}
function getIndexByValue(selObj,val) {
var indexi = 0;
	
	for (var i = 0; i < selObj.options.length; i++) {
		if (selObj.options[i].value == val) {
			//alert(' opt value '+selObj.options[i].value+' val '+val+' obj '+selObj.name);
			indexi = i;
			break;
		}
	}	
	return indexi;	
}


function editProduct(thisfrm,productId)
{
	if(productId == 0)
	{
		productId = -1;
	}

	thisfrm.selCat.disabled = true;
	thisfrm.selSubCat.disabled = true;
		
	getProduct(thisfrm,productId);

}

function editVariant(thisfrm,variantId)
{
	if(variantId == 0)
	{
		variantId = -1;
	}
	
	thisfrm.selCat.disabled = true;
	thisfrm.selSubCat.disabled = true;
	
	getVariant(thisfrm,variantId);

}



function unhidetab(tabID) {
  var item = document.getElementById(tabID);
   if(item) {
  	item.style.visibility = 'visible';
  	//item.style.display = 'table-cell';
  }
}


function placeConfirm(ele,prgDiv)
{	
	
	JSFX_FloatDiv(ele.id, 10,30).floatIt();
	prgDiv.style.visibility="hidden";
	prgDiv.style.display="none";
}

/************************************************************************************************************
(C) www.dhtmlgoodies.com, March 2006

This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	

Terms of use:
You are free to use this script as long as the copyright message is kept intact. However, you may not
redistribute, sell or repost it without our permission.

Version:
	1.0	Released	March. 3rd 2006

Thank you!

www.dhtmlgoodies.com
Alf Magne Kalleland

************************************************************************************************************/
var flyingSpeed = 20;
var url_addProductToBasket = 'addProduct.php';
var url_removeProductFromBasket = 'removeProduct.php';
var txt_totalPrice = 'Total: ';


var shopping_cart_div = false;
var flyingDiv = false;
var currentProductDiv = false;

var shopping_cart_x = false;
var shopping_cart_y = false;

var slide_xFactor = false;
var slide_yFactor = false;

var diffX = false;
var diffY = false;

var currentXPos = false;
var currentYPos = false;

var ajaxObjects = new Array();

function shoppingCart_getTopPos(inputObj)
{		
  var returnValue = inputObj.offsetTop;
  while((inputObj = inputObj.offsetParent) != null){
  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetTop;
  }
  return returnValue;
}

function shoppingCart_getLeftPos(inputObj)
{
  var returnValue = inputObj.offsetLeft;
  while((inputObj = inputObj.offsetParent) != null){
  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetLeft;
  }
  return returnValue;
}

function showFlying(productId,prodImage)
{
	if (prodImage == 'product_default_30x20.jpg' || prodImage == 'product_default_50x50.jpg')
	{
		prodImage = 'groceries.gif';
	}
	if(!shopping_cart_div)shopping_cart_div = document.getElementById('showCart');
	if(!flyingDiv){
		flyingDiv = document.createElement('DIV');
		flyingDiv.style.position = 'absolute';
		document.body.appendChild(flyingDiv);
	}
	
	shopping_cart_x = shoppingCart_getLeftPos(shopping_cart_div) + 50;
	shopping_cart_y = shoppingCart_getTopPos(shopping_cart_div) + 20;

	currentProductDiv = document.getElementById('prodDetJS' + productId);
	
	currentXPos = shoppingCart_getLeftPos(currentProductDiv);
	currentYPos = shoppingCart_getTopPos(currentProductDiv);
	
	diffX = shopping_cart_x - currentXPos;
	diffY = shopping_cart_y - currentYPos;
	
	var shoppingContentCopy = currentProductDiv.cloneNode(true);
	shoppingContentCopy.id='';
	flyingDiv.innerHTML = '';
	flyingDiv.style.left = currentXPos + 'px';
	flyingDiv.style.top = currentYPos + 'px';
	flyingDiv.appendChild(shoppingContentCopy);
	flyingDiv.style.display='block';
	//flyingDiv.style.width = currentProductDiv.offsetWidth + 'px';
	flyingDiv.innerHTML = '<img src="web/img/' + prodImage + '">';
	flyToBasket(productId);
	
}


function flyToBasket(productId)
{
	var maxDiff = Math.max(Math.abs(diffX),Math.abs(diffY));
	var moveX = (diffX / maxDiff) * flyingSpeed;;
	var moveY = (diffY / maxDiff) * flyingSpeed;	
	
	currentXPos = currentXPos + moveX;
	currentYPos = currentYPos + moveY;
	
	flyingDiv.style.left = Math.round(currentXPos) + 'px';
	flyingDiv.style.top = Math.round(currentYPos) + 'px';	
	
	
	if(moveX>0 && currentXPos > shopping_cart_x){
		flyingDiv.style.display='none';		
	}
	if(moveX<0 && currentXPos < shopping_cart_x){
		flyingDiv.style.display='none';		
	}
		
	if(flyingDiv.style.display=='block')setTimeout('flyToBasket("' + productId + '")',10); /*else ajaxAddProduct(thisfrm,productId,hasAttrb);*/
}
