function maskKeyPress(objEvent) 
{
    var iKeyCode;   
	if (objEvent.keyCode) { 
	iKeyCode = objEvent.keyCode; 
	} 
	else { 
	iKeyCode = objEvent.which; 
	}; 
    if((iKeyCode>=48 && iKeyCode<=57)||(iKeyCode==8)||(iKeyCode==46)) return true;
    return false;
}
function popup(url,winname,opt)
{
	var win = window.open(url,winname,opt);
}

function limit(objEvent,elem,maxchars,typ) 
{
	var iKeyCode;   
	if (objEvent.keyCode) { 
	iKeyCode = objEvent.keyCode; 
	} 
	else { 
	iKeyCode = objEvent.which; 
	};
    var strlen = elem.value.length;
	switch(typ) {
		case 'alphanum':
			if((strlen<maxchars && ((iKeyCode>=65 && iKeyCode<=90)||(iKeyCode>=97 && iKeyCode<=122)||(iKeyCode>=48 && iKeyCode<=57))||(iKeyCode==8)||(iKeyCode==46)||(iKeyCode>=37 && iKeyCode<=40))){return true;}	
			break;
		case 'num':
			if((strlen<maxchars && ((iKeyCode>=48 && iKeyCode<=57))||(iKeyCode==8)||(iKeyCode==46)||(iKeyCode>=37 && iKeyCode<=40))){return true;}
			break;

		case 'date':
			if((strlen<maxchars && ((iKeyCode>=47 && iKeyCode<=57)))||(iKeyCode==8)||(iKeyCode==46)||(iKeyCode>=37 && iKeyCode<=40)){return true;}
			break;
	}
	return false;
}

function toggleCnt(container)
{
	var img = document.getElementById('dn' + container);
	if(img.src.indexOf('plus.gif') > 0)
	{
		//is closed
		img.src='/images/minus.gif';
		//alert(img.src);
		document.getElementById('cnt' + container).className='show';
		//img.src='/images/minus.gif';
	}else{
		//is open
		img.src='/images/plus.gif';
		//alert(img.src);
		document.getElementById('cnt' + container).className='hide';
		//img.src='/images/plus.gif';
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function mustSelect(onForm)
{
	if (onForm.size.selectedIndex == 0)
	{
		alert('You must select a size..');
		return false;
	}
	if (onForm.colour.value == 'Please choose...')
	{
		alert('You must select a colour..');
		return false;
	}	
	return true;
}

function buildColours(comeFromOnload){
	var tempColArray = new Array();
	var tempColArrayTwo = new Array();
	if ( document.frmAdd.size.options.selectedIndex == -1 ) 
		{ 
			var origin = "XXX"; 
		}else{
			var colid = document.frmAdd.size;
			var origin = colid.options[colid.selectedIndex].value;
		}
	if (origin != 'XXX') {
		var previousCol = document.frmAdd.colour.selectedIndex;
		ColList = document.frmAdd.colour.options;
		ColList.length = 1;
		var n = 0;
		for (var loop=0; loop < validCol.length; loop++) {
			var index = validCol[loop].indexOf(origin);
			var splitpos = validCol[loop].indexOf(':');
			//alert(index + ' - ' + splitpos + '=' + origin.length);
			if ((index == 0)&&(splitpos==origin.length)) {
				var col = validCol[loop].substring(splitpos+1,validCol[loop].length);
				//alert(mod);
				tempColArray[n] = col;
				n++;
			} else if (index == splitpos + 1) {
				var col = validCol[loop].substring(0,splitpos);
				//alert(mod);
				tempColArray[n] = col;
				n++;
			}
		}
		count = 0;
		n = 0;
		for (count=0;count<tempColArray.length;count++){
			colID = tempColArray[count];
			tempColArrayTwo[count] = colID;
		}
		//tempModArrayTwo.sort(doCompareTxt);
		count = 0;
		for (count=0;count<tempColArrayTwo.length;count++){
			//alert('boo');
			//ColList[count] = new Option(tempColArray[count]);
			ColList[count] = new Option(validColStr[count+1]);
			ColList[count].value = tempColArrayTwo[count];
		}

		if (ColList.length > -1) {
			ColList.selectedIndex = 0;
		}
		else {
			ColList.selectedIndex = -1;
		}
		if ( (previousCol != -1) && (comeFromOnload == 1) ) {
			ColList.selectedIndex = previousCol;
		}
	}
}

function doCompare(a, b){
	return a - b;
}

function doCompareTxt(a, b){
	var inda = a.indexOf(" ");
	var aval = a.substring(0,inda);
	var indb = b.indexOf(" ");
	var bval = b.substring(0,indb);
	var result = parseInt(aval - bval);
	return result;
}
