function showLength_init(answar) {
var result=answar.split("==");
//alert("=="+result[1]+"==");
var arrVal=result[1];

	if(arrVal==1)
	{
		showQTY(result[0],result[2]);
		//alert(result[0]);
	}
	else
	{
		var vDiv="lengthDiv["+result[0]+"]";
		document.getElementById(vDiv).innerHTML = result[1];
		//alert("B");
	}

}

function showLength(id,row)
{
	var colorVal = document.frm1.colorSelection[row].value;

	//alert(colorVal);

    var result=colorVal.split(",");
	//color Id result[0]
	//Price result[1]

	var vDiv="subTotalDiv["+row+"]";
	document.getElementById(vDiv).innerHTML = "<font color=#FF0000><i>Waiting .....</i></font>";
    document.getElementById(vDiv).innerHTML = '0';

	//alert(id+"-"+result[0]+"-"+result[1]+"-"+result[2]+"-"+row);
	ajax_showLength(id,result[0],result[1],result[2],row,result[3],showLength_init);
}

//---------------------------------------------------------------//

function showValue(row,price)
{
	//alert(row);
	//alert(price);
	var lengthSelName = "lengthSelection" + row;
	//alert(lengthSelName);
	var length = document.frm1.elements[lengthSelName].value;
	//alert(length);
	
	var qtySelName ="qtySelection"+row;
	//alert(qtySelName);
	var qty = document.frm1.elements[qtySelName].value;
	//alert(qty);
	
	//var itemPriceName="itemPrice"+row;
	//var price = document.frm1.elements[itemPriceName].value;
	//alert(price);
	//alert(length);
    if(length==0)
	{
	length=1;
	var subTotal = qty*price*length;
	}
	else
	{
	var subTotal = qty*price*length;
	}
	
	var vDiv="subTotalDiv["+row+"]";
	document.getElementById(vDiv).innerHTML = "<font color=#FF0000><i>Waiting .....</i></font>";
    document.getElementById(vDiv).innerHTML = subTotal.toFixed(2);
	
	var subValName="subTotalVal"+row;
	document.frm1.elements[subValName].value=subTotal.toFixed(2);
	//ajax_showValue(row,showValue_init);
	
	var totalItems =document.getElementById("totalItems").value; 
    //alert(totalItems);
	
	var i=0;
    var totalVal=0;
	var sTotal=0;
	var totalLength=0;
	length=0;
	var subQty=0;
	
	for(i=0;i<totalItems;i++)
	{
		var sValName="subTotalVal"+i;

		sTotal=document.frm1.elements[sValName].value;
		//alert(sTotal);
		totalVal = totalVal + parseFloat(sTotal); 
		//alert(totalVal);
		//alert(document.frm1.subTotalVal[i].value);
		
	   //subQty = document.frm1.elements[colorSelection[i]].value;
		
	   qtySelName ="qtySelection"+i;
	   subQty = document.frm1.elements[qtySelName].value;
		
	   lengthSelName = "lengthSelection" + i;
	   length =document.frm1.elements[lengthSelName].value;
	   totalLength = totalLength + (parseFloat(length)*subQty);
	   
	  
	   
	}
	//document.getElementById("orderTotal").innerHTML = totalVal.toFixed(2);
	var freight=0;
	
	if(totalLength>100)
	freight = 28;
	else
	freight = 22;
	
	//document.getElementById("freightTotal").innerHTML = freight.toFixed(2);
	var grandTotal=	freight+totalVal;
	//document.getElementById("grandTotal").innerHTML = grandTotal.toFixed(2);
	//document.frm1.amount.value=grandTotal;
	
	//document.frm1.elements["grandTot"].value=grandTotal;
	//document.frm1.elements["freightTot"].value=freight;
	showSummery();
}

function showQTY_init(answar)
{
var result=answar.split("==");
var vDiv="qtyDiv["+result[0]+"]";
document.getElementById(vDiv).innerHTML = "<font color=#FF0000><i>Waiting .....</i></font>";
document.getElementById(vDiv).innerHTML = result[1];
showValue(result[0],result[2]);
}

function showQTY(row,price)
{
	//alert(price);
	ajax_showQTY(row,price,showQTY_init);
}

function showSummery()
{
	var allItem ="";	 
	var a=0;
	for (var i=0; i < document.frm1.colorSelection.length; i++)
   {
   var qty = "qtySelection"+i;
   var itemTotal = "subTotalVal"+i;
   var itemLength = "lengthSelection"+i;
    
   if (document.frm1.colorSelection[i].value!=0 && document.frm1.elements[qty].value!=0)
      {
	/*	*/    
	   if(a==0)
	  allItem = allItem + "Prduct Type:"+ document.frm1.productType[i].value;	  
	   else
	  allItem = allItem + "/Prduct Type:"+ document.frm1.productType[i].value;	  
	 
      allItem = allItem +"-Option:" + document.frm1.colorSelection[i].options[document.frm1.colorSelection[i].selectedIndex].text;
	  allItem = allItem +"-Length\Letres:"+ document.frm1.elements[itemLength].options[document.frm1.elements[itemLength].selectedIndex].text;
	  allItem = allItem +"-Quantity:"+ document.frm1.elements[qty].options[document.frm1.elements[qty].selectedIndex].text;
	  allItem = allItem +"-Amount:"+ document.frm1.elements[itemTotal].value;
	  allItem = allItem +"\n";
	  a++;	  
      }
   }
   //document.frm1.elements["item_name"].value=allItem;
  //alert(allItem); 
}
//----------------------------------------------------------------------------------------//

function submitOrder_init(answar)
{
	alert(answar);
	document.cartFrm.submit();
}

function submitOrder(p1,p2,p3)
{
 if(document.cartFrm.elements["cusName"].value=="")
 {
	 alert("Please Fill Name");
 }
 else if(document.cartFrm.elements["cusAddress"].value=="")
 {
	 alert("Please Fill Address");
 }
 else if(document.cartFrm.elements["cusEmail"].value=="")
 {
	 alert("Please Fill Email");
 }
 else if(document.cartFrm.elements["cusTelephone"].value=="")
 {
	  alert("Please Fill Telephone Number");
 }
 else
 {
	//alert("A");
	var allItem ="";	 
	var a=0;
	for (var i=0; i < document.frm1.colorSelection.length; i++)
   {
   var qty = "qtySelection"+i;
   var itemTotal = "subTotalVal"+i;
   var itemLength = "lengthSelection"+i;
    
  if (document.frm1.colorSelection[i].value!=0 && document.frm1.elements[qty].value!=0)
      {
	/*	*/    
	   if(a==0)
	  allItem = allItem + "Prduct Type:"+ document.frm1.productType[i].value;	  
	   else
	  allItem = allItem + "/Prduct Type:"+ document.frm1.productType[i].value;	  
	 
      allItem = allItem +"-Option:" + document.frm1.colorSelection[i].options[document.frm1.colorSelection[i].selectedIndex].text;
	  allItem = allItem +"-Length\Letres:"+ document.frm1.elements[itemLength].options[document.frm1.elements[itemLength].selectedIndex].text;
	  allItem = allItem +"-Quantity:"+ document.frm1.elements[qty].options[document.frm1.elements[qty].selectedIndex].text;
	  allItem = allItem +"-Amount:"+ document.frm1.elements[itemTotal].value;
	  //allItem = allItem +"\n";
	  a++;	  
      }
   }
   //document.frm1.elements["item_name"].value=allItem;
   //alert(allItem); 
   
   var cusDetails="Name:"+ document.cartFrm.elements["cusName"].value;
   cusDetails = cusDetails +"=Address:"+ document.cartFrm.elements["cusAddress"].value;
   cusDetails = cusDetails +"=Email:"+ document.cartFrm.elements["cusEmail"].value;
   cusDetails = cusDetails +"=Telephone:"+ document.cartFrm.elements["cusTelephone"].value;
   
   var grandTot=document.cartFrm.elements["amount"].value;
   var freightTot=document.cartFrm.elements["freightTot"].value;
   
  //alert(allItem);
 // alert(grandTot);
  //alert(freightTot);
   ajax_submitOrder(allItem,grandTot,freightTot,cusDetails,submitOrder_init);	
 }
}


function addToCart_init(answar)
{
	
	viewCart();
}


function addToCart(rowId)
{
	var itemLength = "lengthSelection"+rowId;
	var qty = "qtySelection"+rowId;
	var itemTotal = "subTotalVal"+rowId;
	var lengthSelName = "lengthSelection" + rowId;
	var lengthVal =document.frm1.elements[lengthSelName].value;
	
	var product = document.frm1.productType[rowId].value;
	var text = document.frm1.colorSelection[rowId].options[document.frm1.colorSelection[rowId].selectedIndex].text;
	var length = document.frm1.elements[itemLength].options[document.frm1.elements[itemLength].selectedIndex].text;
	var qtyVal = document.frm1.elements[qty].options[document.frm1.elements[qty].selectedIndex].text;
	var subTotal = document.frm1.elements[itemTotal].value;
	//alert(product+"-"+text+"-"+length+"-"+qtyVal+"-"+subTotal);
	
	ajax_addToCart(product,text,length,qtyVal,subTotal,lengthVal,addToCart_init);	
}

function viewCart_init(answar)
{
	//alert(answar);
	showPopup('700','400','7');
	document.getElementById("popupSubContaint").innerHTML = answar;
}

function viewCart()
{
	ajax_viewCart(viewCart_init);
}


function removeItems_init(answar)
{
	//alert(answar);
	viewCart();
}

function removeItems()
{
	var a=0;
	var removeArray="";
	var remove="";
	//alert("A");
        if(undefined != document.cartFrm.remove.length)
		{
		
				for (var i=0; i < document.cartFrm.remove.length; i++)
				{
				  remove=document.cartFrm.remove[i].checked;
				  //alert(remove);
				   if(remove==true)
				   {
					  
						  if(a==0)
						  {
						  removeArray=document.cartFrm.remove[i].value;
						  }
						  else
						  {
						  removeArray = removeArray +","+ document.cartFrm.remove[i].value;
						  }
					  
					 //alert("removeArray"+removeArray);
					 a=1;
				   }
				}
				
				
		}
		else
		{
			//alert("Not Array");
			if(document.cartFrm.remove.checked)
			{
				removeArray =document.cartFrm.remove.value;
			}
		}

   //alert("removeArray-2"+removeArray);
   
  ajax_removeItems(removeArray,removeItems_init);
}
//------------------------------------------------------------------------------------------------------------------//

function submitOrder2_init(answar)
{
	alert("Your Request Email Sent Successfully");
	//document.cartFrm.submit();
}

function submitOrder2()
{
 if(document.cartFrm.elements["cusName"].value=="")
 {
	 alert("Please Fill Name");
 }
 else if(document.cartFrm.elements["cusAddress"].value=="")
 {
	 alert("Please Fill Address");
 }
 else if(document.cartFrm.elements["cusEmail"].value=="")
 {
	 alert("Please Fill Email");
 }
 else if(document.cartFrm.elements["cusTelephone"].value=="")
 {
	  alert("Please Fill Telephone Number");
 }
 else
 {
	//alert("A");
	var allItem ="";	 
	var a=0;
	for (var i=0; i < document.frm1.colorSelection.length; i++)
   {
   var qty = "qtySelection"+i;
   var itemTotal = "subTotalVal"+i;
   var itemLength = "lengthSelection"+i;
    
  if (document.frm1.colorSelection[i].value!=0 && document.frm1.elements[qty].value!=0)
      {
	/*	*/    
	   if(a==0)
	  allItem = allItem + "Prduct Type:"+ document.frm1.productType[i].value;	  
	   else
	  allItem = allItem + "/Prduct Type:"+ document.frm1.productType[i].value;	  
	 
      allItem = allItem +"-Option:" + document.frm1.colorSelection[i].options[document.frm1.colorSelection[i].selectedIndex].text;
	  allItem = allItem +"-Length\Letres:"+ document.frm1.elements[itemLength].options[document.frm1.elements[itemLength].selectedIndex].text;
	  allItem = allItem +"-Quantity:"+ document.frm1.elements[qty].options[document.frm1.elements[qty].selectedIndex].text;
	  allItem = allItem +"-Amount:"+ document.frm1.elements[itemTotal].value;
	  //allItem = allItem +"\n";
	  a++;	  
      }
   }
   //document.frm1.elements["item_name"].value=allItem;
   //alert(allItem); 
   
   var cusDetails="Name:"+ document.cartFrm.elements["cusName"].value;
   cusDetails = cusDetails +"=Address:"+ document.cartFrm.elements["cusAddress"].value;
   cusDetails = cusDetails +"=Email:"+ document.cartFrm.elements["cusEmail"].value;
   cusDetails = cusDetails +"=Telephone:"+ document.cartFrm.elements["cusTelephone"].value;
   
   var grandTot=document.cartFrm.elements["amount"].value;
   var freightTot=document.cartFrm.elements["freightTot"].value;
   
  //alert(allItem);
 // alert(grandTot);
  //alert(freightTot);
   ajax_submitOrder2(allItem,grandTot,freightTot,cusDetails,submitOrder2_init);	
 }
}
