﻿function chk_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=chk_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function doUpdate(lbasketlineid)
{
	var ctrl=chk_findObj('qty_'+lbasketlineid)	
	var lqty=ctrl.value;

	if(isPositiveInteger(lqty)==false) {
		ctrl.focus();
		alert("Please enter a valid quantity!");
		return false;
	}
	else{
		window.location.href="basket.aspx?act=upd&lineid="+lbasketlineid+"&qty=" + lqty;
	}
}

//Check for a positive Integer
//(empty values must be chacked for bedfore calling)
function isPositiveInteger(str)
{
    return (isSignedInteger(str) && parseInt(str)>0);
}

function isSignedInteger(str)
{   

    var startPos = 0;
    
    // skip leading + or -
    if ( (str.charAt(0) == "-") || (str.charAt(0) == "+") ) startPos = 1;
    return (isInteger(str.substring(startPos, str.length)))    
}

function isInteger (str)
{  
	var i;
	for (i = 0; i < str.length; i++){
	   // Check that current character is number.
	   var c = str.charAt(i);
	   if (!isDigit(c)) return false;
	}
	// All characters are numbers.
	return true;
}

// Returns true if character c is a digit (0 .. 9).
function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}
function gotoBasketLine(lBasketLineID)
{
	//goto the bookmark
	window.document.location.href="#" + lBasketLineID;
}