function zNumToHex2(znum) {
	// does not work in JS 1.0, but accepts all numbers (not only until 255)
	a = znum.toString(16).toUpperCase();
	if (a.length<2) a = "0" + a;
	return a;
}


function zNumToHex(strNum) {

	for(i = 0; i < strNum.length; i++) {
		chr=strNum.substring(i, i + 1);		
		if((isNaN(chr))||(chr == ' ')) {
			alert('Can operate only with digits 0-9!');
			return false;
   		}
	}

	if(strNum > 255) {
		alert('Can operate only with numbers between 0 and 255!');
		return false;
	}
	else {
		base = strNum / 16;
		rem = strNum % 16;
		base = base - (rem / 16);
		baseS = zMakeHex(base);
		remS = zMakeHex(rem);
		return baseS + '' + remS;
	}
}


function zMakeHex(x) {

	if((x >= 0) && (x <= 9)) {
		return x; }
	else {
		switch(x) {
			case 10: return "A"; 
			case 11: return "B";  
			case 12: return "C";  
			case 13: return "D";  
			case 14: return "E";  
			case 15: return "F";  
		}
	}
}

function zHexToNum(numStr) {

	tens = zMakeNum(numStr.substring(0,1));
	if(tens == 'X') return false;

	ones = 0;
	if(numStr.length > 1) // means two characters entered
		ones = zMakeNum(numStr.substring(1,2));

	if(ones == 'X') return false;

	return (tens * 16) + (ones * 1);
}

function zMakeNum(str) {

	if((str >= 0) && (str <= 9))
	return str;

	switch(str.toUpperCase()) {
		case "A": return 10;
		case "B": return 11;
		case "C": return 12;
		case "D": return 13;
		case "E": return 14;
		case "F": return 15;
		default:  return 'X';	//alert('You must choose a number between 0 and 9 or a letter between A and F!');
	}
}


function zRgbToAbs (rgbVal) {
	// rgbVal = '128, 128, 128'

	var zAr = rgbVal.split(",");
	for (i=0; i<3; i++) {
		if (isNaN(zAr[i]) || zAr[i]>255 || zAr[i]<0) return false;
	}
	z1 = zAr[0]*1; z2 = zAr[1]*256; z3 = zAr[2]*256*256;
	return z1 + z2 + z3;
}
