function MM_openBrWindow(theURL,winName,features) { //v2.0
  windowName = window.open(theURL,"Image","scrollbars=yes,width=1024,height=780,top=100,left=500,screenx=100,screeny=500");
  windowName.focus();
}

function AllTrim(sStr)
{ 
	while (sStr.substring(0,1) == ' ')
	{
		sStr = sStr.substring(1, sStr.length);
	}
	while (sStr.substring(sStr.length-1, sStr.length) == ' ')
	{
		sStr = sStr.substring(0,sStr.length-1);
	}
	return sStr;
}

function isString(str,msg)
{	
	if (str=="")
	{
		alert(msg)
		return false;
	}
	return true;
}

function isDate(str,msg)
{
   tstr1 = str.substring(2,3);
   tstr2 = str.substring(5,6);
   tstr3 = str.length;
   if ((tstr1=='/') && (tstr2 == '/') && (tstr3=10) )
   {
	   return true;
   }
   alert(msg);
   return false;
}

function isImage(str,msg)
{
   var z =  str;
   var z1 = z.substring(z.indexOf('.'),z.length);
   if ((z1=='.jpg') || (z1=='.JPG') || (z1=='.gif') || (z1=='.GIF') || (z1==''))
   {
      return true;
   }
   alert(msg);
   return false;
}


function isEmail(str,msg)
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)

	if (str.indexOf(at)==-1)
	{
	   alert(msg)
	   return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
	{
	   alert(msg)
	   return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
	{
	    alert(msg)
	    return false;
	}

	if (str.indexOf(at,(lat+1))!=-1)
	{
	   alert(msg)
	   return false;
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
	{
	   alert(msg)
	   return false;
	}

	if (str.indexOf(dot,(lat+2))==-1)
	{
	   alert(msg)
	   return false;
	}
		
	if (str.indexOf(" ")!=-1)
	{
	   alert(msg)
	   return false;
	}

	return true;
}

function calcamt(row)
{
   if (itemform["select"+row].checked == true)
   {
      if (itemform["purchase_qty"+row].value != 0)
      {
         itemform["purchase_qty"+row].value = Math.ceil(itemform["purchase_qty"+row].value / itemform["qty"+row].value) * itemform["qty"+row].value;
         itemform["purchase_amt"+row].value = Math.round(itemform["purchase_qty"+row].value * itemform["price"+row].value * 100) / 100;
      }
      else
      {
         itemform["purchase_amt"+row].value = 0;
         itemform["select"+row].checked = false;
         itemform["select"+row].refresh;         
         alert('Please enter Purchase Qty.!.....');
      }
   }
   else
   {
      itemform["purchase_qty"+row].value = 0;
      itemform["purchase_amt"+row].value = 0;
   }
   itemform["purchase_qty"+row].refresh;
   itemform["purchase_amt"+row].refresh;
}


function checkzeroqty(row)
{
   if (itemform["purchase_qty"+row].value == 0)
   {
      itemform["purchase_weight"+row].value = 0;
      itemform["purchase_amt"+row].value = 0;
      itemform["select"+row].checked = false;
      itemform["select"+row].refresh; 
      itemform["purchase_amt"+row].refresh;        
      itemform["purchase_weight"+row].refresh;        
   }

}

function storeoldqty(row)
{
   cartform["purchase_qty_old"+row].value = cartform["purchase_qty"+row].value;
   cartform["purchase_qty_weight"+row].value = cartform["purchase_weight"+row].value;
}


function cartcalcamt(row)
{
   if (cartform["purchase_qty"+row].value != 0)
   {
      var told_value = cartform["purchase_amt"+row].value;
      var told_qty = cartform["purchase_qty_old"+row].value;
      var told_weight = cartform["purchase_weight_old"+row].value;
      cartform["purchase_qty"+row].value = Math.ceil(cartform["purchase_qty"+row].value / cartform["qty"+row].value) * cartform["qty"+row].value;
      cartform["purchase_weight"+row].value = Math.round(cartform["weight"+row].value * cartform["purchase_qty"+row].value * 10000)/10000;
      cartform["purchase_amt"+row].value = Math.round(cartform["purchase_qty"+row].value * cartform["price"+row].value * 100) / 100;
      cartform.total_amt.value = (Math.round(cartform.total_amt.value*100)/100) - (Math.round(told_value*100)/100) + (Math.round(cartform["purchase_amt"+row].value*100)/100);
      cartform.total_amt.value = Math.round(cartform.total_amt.value*100)/100;
      cartform.total_qty.value = (Math.round(cartform.total_qty.value*100)/100) - (Math.round(told_qty*100)/100) + (Math.round(cartform["purchase_qty"+row].value*100)/100);
      cartform.total_qty.value = Math.round(cartform.total_qty.value*100)/100;
      cartform.total_weight.value = (Math.round(cartform.total_weight.value*10000)/10000) - (Math.round(told_weight*10000)/10000) + (Math.round(cartform["purchase_weight"+row].value*10000)/10000);
      cartform.total_weight.value = Math.round(cartform.total_weight.value*10000)/10000;
      cartform["remove"+row].checked = false;
   }
   else
   {
      cartform.total_amt.value = (Math.round(cartform.total_amt.value*100)/100) - (Math.round(cartform["purchase_amt"+row].value*100)/100);
      cartform.total_amt.value = Math.round(cartform.total_amt.value*100)/100;
      cartform["purchase_amt"+row].value = 0;
      cartform.total_qty.value = (Math.round(cartform.total_qty.value*100)/100) - (Math.round(cartform["purchase_qty_old"+row].value*100)/100);
      cartform.total_qty.value = Math.round(cartform.total_qty.value*100)/100;
      cartform["purchase_qty"+row].value = 0;

      cartform.total_weight.value = (Math.round(cartform.total_weight.value*10000)/10000) - (Math.round(cartform["purchase_weight_old"+row].value*10000)/10000);
      cartform.total_weight.value = Math.round(cartform.total_weight.value*10000)/10000;
      cartform["purchase_weight"+row].value = 0;

      cartform["remove"+row].checked = true;
      alert('Item is removed from cart!.....');
   }
   cartform.total_amt.refresh;
   cartform.total_qty.refresh;
   cartform.total_weight.refresh;
   cartform["remove"+row].refresh;         
   cartform["purchase_qty"+row].refresh;
   cartform["purchase_weight"+row].refresh;
   cartform["purchase_amt"+row].refresh;
   
   document.location.href='refresh_cart_item.php?row='+row+'&qty='+cartform["purchase_qty"+row].value+'&weight='+cartform["purchase_weight"+row].value+'&amt='+cartform["purchase_amt"+row].value+'&total_amt='+cartform.total_amt.value+'&total_qty='+cartform.total_qty.value+'&total_weight='+cartform.total_weight.value+'&cust_item_id='+cartform["cust_item_id"+row].value;
}

function cartremoveitem(row)
{
   if (cartform["remove"+row].checked == true)
   {
      cartform.total_amt.value = (Math.round(cartform.total_amt.value*100)/100) - (Math.round(cartform["purchase_amt"+row].value*100)/100);
      cartform.total_amt.value = Math.round(cartform.total_amt.value*100)/100;
      cartform.total_qty.value = (Math.round(cartform.total_qty.value*100)/100) - (Math.round(cartform["purchase_qty"+row].value*100)/100);
      cartform.total_qty.value = Math.round(cartform.total_qty.value*100)/100;
      cartform.total_weight.value = cartform.total_weight.value - cartform["purchase_weight"+row].value;
      cartform.total_weight.value = cartform.total_weight.value;
	  
      cartform["purchase_qty"+row].value = 0;
      cartform["purchase_weight"+row].value = 0;
      cartform["purchase_amt"+row].value = 0;
   }
   cartform.total_amt.refresh;
   cartform.total_qty.refresh;
   cartform.total_weight.refresh;
   cartform["purchase_qty"+row].refresh;
   cartform["purchase_weight"+row].refresh;
   alert('Item is removed from cart!.....');
   cartform["purchase_amt"+row].refresh;
   document.location.href='refresh_cart_item.php?row='+row+'&qty='+cartform["purchase_qty"+row].value+'&weight='+cartform["purchase_weight"+row].value+'&amt='+cartform["purchase_amt"+row].value+'&total_amt='+cartform.total_amt.value+'&total_qty='+cartform.total_qty.value+'&total_weight='+cartform.total_weight.value+'&cust_item_id='+cartform["cust_item_id"+row].value;
}

function rfqstoreoldqty(row)
{
   rfqform["required_qty_old"+row].value = rfqform["required_qty"+row].value;
}


function rfqcalcqty(row)
{
   if (rfqform["required_qty"+row].value != 0)
   {
      var told_qty = rfqform["required_qty_old"+row].value;
      rfqform["required_qty"+row].value = Math.ceil(rfqform["required_qty"+row].value / rfqform["qty"+row].value) * rfqform["qty"+row].value;
      rfqform.total_qty.value = (Math.round(rfqform.total_qty.value*100)/100) - (Math.round(told_qty*100)/100) + (Math.round(rfqform["required_qty"+row].value*100)/100);
      rfqform.total_qty.value = Math.round(rfqform.total_qty.value*100)/100;
      rfqform["remove"+row].checked = false;
   }
   else
   {
      rfqform.total_qty.value = (Math.round(rfqform.total_qty.value*100)/100) - (Math.round(rfqform["required_qty_old"+row].value*100)/100);
      rfqform.total_qty.value = Math.round(rfqform.total_qty.value*100)/100;
      rfqform["required_qty"+row].value = 0;
      rfqform["remove"+row].checked = true;
      alert('Item is removed from cart!.....');
   }
   rfqform.total_qty.refresh;
   rfqform["remove"+row].refresh;         
   rfqform["required_qty"+row].refresh;
   document.location.href='refresh_rfq_item.php?row='+row+'&qty='+rfqform["required_qty"+row].value+'&total_qty='+rfqform.total_qty.value;
}

function rfqremoveitem(row)
{
   if (rfqform["remove"+row].checked == true)
   {
      rfqform.total_qty.value = (Math.round(rfqform.total_qty.value*100)/100) - (Math.round(rfqform["required_qty"+row].value*100)/100);
      rfqform.total_qty.value = Math.round(rfqform.total_qty.value*100)/100;
      rfqform["required_qty"+row].value = 0;
   }
   rfqform.total_qty.refresh;
   rfqform["required_qty"+row].refresh;
   alert('Item is removed from cart!.....');
   document.location.href='refresh_rfq_item.php?row='+row+'&qty='+rfqform["required_qty"+row].value+'&total_qty='+rfqform.total_qty.value;
}
