function userConfirm(prodid,curUrl){

     qtyinpt=document.productlist.elements['order_product['+prodid+']'].value;
   if (qtyinpt!="")
   {
  	 if(confirm("The product has already been added to the cart. Do you want to add the product again?"))
    {
     qty=document.productlist.elements['order_product['+prodid+']'].value;
    window.location.href="http://www.regentproducts.com/index.php?action=buy_now&products_id="+prodid+"&buyqty="+qty+"&curUrl="+curUrl+"";
    }
    
	}
     
}


function checkNotZero(objName)
{
	var numberfield = parseInt (objName.value);
	if (numberfield==0)
	{
		alert("Customer Number cannot be 0");
		return false;
	}
	else
	{
		return true;
	}
}



function userConfirm2(prodid,curUrl,sid){

  
   qtyinpt=document.forms['productlist'+sid].elements['order_product['+prodid+']'].value;
   if (qtyinpt!="")
   {
	if(confirm("The product has already been added to the cart. Do you want to add the product again?"))
    {
     qty=document.forms['productlist'+sid].elements['order_product['+prodid+']'].value;
    window.location.href="http://www.regentproducts.com/index.php?action=buy_now&products_id="+prodid+"&buyqty="+qty+"&curUrl="+curUrl+"";
    }
   	}
     
}

function productQty(prodid,curUrl){

   qtyinpt=document.productlist.elements['order_product['+prodid+']'].value;
   if (qtyinpt!="")
   { 
      qty=document.productlist.elements['order_product['+prodid+']'].value;

      window.location.href="http://www.regentproducts.com/index.php?action=buy_now&products_id="+prodid+"&buyqty="+qty+"&curUrl="+curUrl+"";
    }
}
function productQty2(prodid,curUrl,sid){
   qtyinpt=document.forms['productlist'+sid].elements['order_product['+prodid+']'].value;
   if (qtyinpt!="")
   { 
  
     qty=document.forms['productlist'+sid].elements['order_product['+prodid+']'].value;

       window.location.href="http://www.regentproducts.com/index.php?action=buy_now&products_id="+prodid+"&buyqty="+qty+"&curUrl="+curUrl+"";
	
    
    }
}


/*function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

	*/
	
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}


function checkCasepacks(obj)
{
 var qtyreqd=obj.title;
  var qtyinpt=obj.value;
  /* if (trim(qtyinpt)=='' || qtyinpt==null || !qtyinpt)
   { 
    alert('Invalid Product Quantity');
	
   }*/
   if (qtyinpt!="")
   { 
   if(qtyinpt%qtyreqd!=0)
   {
   alert('This is not a valid quantity, your quantity has been adjusted to its nearest acceptable value');
	obj.value=Math.round((qtyinpt/qtyreqd)+.5)*qtyreqd;
    } 
   }
}

function extractNumber(obj, decimalPlaces, allowNegative)
{
	var temp = obj.value;
	
	// avoid changing things if already formatted correctly
	var reg0Str = '[0-9]*';
	if (decimalPlaces > 0) {
		reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
	} else if (decimalPlaces < 0) {
		reg0Str += '\\.?[0-9]*';
	}
	reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
	reg0Str = reg0Str + '$';
	var reg0 = new RegExp(reg0Str);
	if (reg0.test(temp)) return true;

	// first replace all non numbers
	var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
	var reg1 = new RegExp(reg1Str, 'g');
	temp = temp.replace(reg1, '');

	if (allowNegative) {
		// replace extra negative
		var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
		var reg2 = /-/g;
		temp = temp.replace(reg2, '');
		if (hasNegative) temp = '-' + temp;
	}
	
	if (decimalPlaces != 0) {
		var reg3 = /\./g;
		var reg3Array = reg3.exec(temp);
		if (reg3Array != null) {
			// keep only first occurrence of .
			//  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
			var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
			reg3Right = reg3Right.replace(reg3, '');
			reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
			temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;
		}
	}
	
	obj.value = temp;
}

function checkkey(v) {
if (/\W/.test(v.value)) {
return false;
}
return true;
}

function alphaNumeric(e)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// alphas and numbers
else if ((("abcdefghijklmnopqrstuvwxyz0123456789-").indexOf(keychar) > -1))
   return true;
else
   return false;

}

function blockNonNumbers(obj, e, allowDecimal, allowNegative)
{
	var key;
	var isCtrl = false;
	var keychar;
	var reg;
		
	if(window.event) {
		key = e.keyCode;
		isCtrl = window.event.ctrlKey
	}
	else if(e.which) {
		key = e.which;
		isCtrl = e.ctrlKey;
	}
	
	if (isNaN(key)) return true;
	
	keychar = String.fromCharCode(key);
	
	// check for backspace or delete, or if Ctrl was pressed
	if (key == 8 || isCtrl)
	{
		return true;
	}

	reg = /\d/;
	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
	
	return isFirstN || isFirstD || reg.test(keychar);
}


function UpdateCartQuantity()
{
  document.cart_quantity.submit();
}

function changeQuantity(obj, i,qty)
{ checkCasepacks(obj);
	
  document.cart_quantity['qty_'+i].value = Number(document.cart_quantity['qty_'+i].value)+Number(qty);
  

    UpdateCartQuantity(); 
 
}
function changeQuantity2(i,qty)
{ 
	
  document.cart_quantity['qty_'+i].value = Number(document.cart_quantity['qty_'+i].value)+Number(qty);
  
 
    UpdateCartQuantity(); 
  
}

var counter = 1;

function add_product() {
    counter++;
// I find it easier to start the incrementing of the counter here.
    var newFields = document.getElementById('add_product_field').cloneNode(true);
    newFields.id = '';
    newFields.style.display = 'block';
    var newField = newFields.childNodes;
    for (var i=0;i<newField.length;i++) {
        var theName = newField[i].name
        if (theName)
                newField[i].name = theName + counter+']';
				newField[i].id = theName + counter+']';
// This will change the 'name' field by adding an auto incrementing number at the end. This is important.
        }
        var insertHere = document.getElementById('add_product_field');
// Inside the getElementById brackets is the name of the div class you will use.
        insertHere.parentNode.insertBefore(newFields,insertHere);
}


function toggleLayer( whichLayer , toggle)
{

  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
 if(toggle==1)
  vis.display ='block';
 if(toggle==0)
  vis.display ='none';

}

function toggleLayer( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

/* getElementByClass
/**********************/

var allHTMLTags = new Array();



function changeAlpha()
{
var shipper=document.invoiceshipform.invoiceship.value;

var ship_fl=shipper.charAt(0)+'shipselect';
ship_fl=ship_fl.toLowerCase();

document.getElementById(ship_fl).click();
}

function closeGreybox() {
    parent.parent.GB_hide();
	setTimeout('window.top.location.reload()', 500);
	
}

function redirectHome()
{
	window.location = "http://www.regentproducts.com/"

}

function closeGreyboxHome() {
    parent.parent.GB_hide();
	setTimeout('redirectHome', 500);
	
}
