function isNumberKey(evt){
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
       return false;

    return true;
}

// Create a global AJAX object
if (window.XMLHttpRequest) 
{
    xmlhttp = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
   xmlhttp=false;
}

// Send an AJAX request
function sendRequest(action, callback, formData) {
    if (xmlhttp) {
	   if (formData) {
	      action += formData;
	   }
	   
	   xmlhttp.open("GET", action, true);
	   xmlhttp.onreadystatechange=callback;
 
       xmlhttp.send(null);
	}
}

function createHttpCon() {
	var httpCon;
	
	if (window.XMLHttpRequest) {
    	httpCon = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
    	httpCon = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
   		httpCon=false;
	}
	
	return httpCon;
}

function sendHttpRequest(httpCon, action, callback, formData) {
    if (httpCon) {
	   if (formData) {
	      action += formData;
	   }
	   
	   httpCon.open("GET", action, true);
	   httpCon.onreadystatechange=callback;
 
       httpCon.send(null);
	}
}

function resetWaitImage() {
    document.getElementById('pleaseWaitImage').innerHTML = '';
}

function showWaitImage(msg) {
    document.getElementById('pleaseWaitImage').innerHTML = msg + '<img src="../img/but_inProgress.gif" border="0">';
}

function resetProgressMessage(popUp) {
	popUp.close();
}

function showProgressMessage(msg) {
	var url = 'popUp.jsp?msg=' + msg;
	var popUp = window.open(url, 'popup', 'height=100,width=400');
	popUp.focus();
	return popUp;
}

function convertErrorCode2Message(errorCode) {
	if (errorCode == 1)
		return "USER_ALREADY_EXISTS";
	else if (errorCode == 2)
		return "DB_UNAVAIL";
	else if (errorCode == 3)
		return "DB_ERROR";
	else if (errorCode == 4)
		return "EXCEEDED_MAX_SERVICES";
	else if (errorCode == 5)
		return "ILLEGAL_SERVICE";
	else if (errorCode == 6)
		return "NOT_AVAILABLE";
	else if (errorCode == 7)
		return "USER_NOT_FOUND";
	else if (errorCode == 8)
		return "DEVICE_NOT_FOUND";
	else if (errorCode == 9)
		return "SERVICE_NOT_FOUND";
	else if (errorCode == 10)
		return "EXCEEDED_MAX_DEVICES";
	else if (errorCode == 11)
		return "SNAC_PROBLEM";
	else if (errorCode == 12)
		return "DEVICE_ALREADY_EXISTS";
	else if (errorCode == 13)
		return "INVALID_COMPNAME";
	else if (errorCode == 14)
		return "INVALID_BID";
	else if (errorCode == 15)
		return "INVALID_PREFERENCE_FLAGS";
	else if (errorCode == 16)
		return "INVALID_DEVICE_ID";
	else if (errorCode == 17)
		return "INVALID_DEVICENAME";
	else if (errorCode == 18)
		return "INVALID_LANG";
	else if (errorCode == 19)
		return "INVALID_SERVICE_TYPE";
	else if (errorCode == 20)
		return "INVALID_SERVICE_ID";
	else if (errorCode == 21)
		return "SERVICES_NOT_SPECIFIED";
	else if (errorCode == 22)
		return "INVALID_CLIENT_TYPE";
	else if (errorCode == 23)
		return "TOO_MANY_SERVICES_IN_REQ";
	else if (errorCode == 24)
		return "UNKNOWN_SNAC_REQUEST";
	else if (errorCode == 25)
		return "DB_TIMEOUT";
	else if (errorCode == 26)
		return "INVALID_CREATE_DATE";
	else if (errorCode == 27)
		return "INVALID_UPDATE_DATE";
	else if (errorCode == 28)
		return "INVALID_VIEWED_DATE";
	else if (errorCode == 29)
		return "INVALID_MIGRATION_ID";
	else if (errorCode == 30)
		return "RECORD_IS_OLD";
	else if (errorCode == 31)
		return "INVALID_PIN_CODE";
	else if (errorCode == 32)
		return "INVALID_CONFIRM_CODE";
	else if (errorCode == 33)
		return "INVALID_DEVICE_NUMBER";
	else if (errorCode == 34)
		return "INVALID_CARRIER_ID";
	else if (errorCode == 35)
		return "INVALID_DEVICE_MODEL";
	else if (errorCode == 36)
		return "INVALID_DEVICE_FLAGS";
	else if (errorCode == 37)
		return "INVALID_CONFIRM_COUNT";
	else if (errorCode == 38)
		return "INVALID_CONFIRM_EXPIRY";
	else if (errorCode == 39)
		return "INVALID_DEVICE_TYPE";
	else if (errorCode == 40)
		return "INVALID_DELIVERY_METHOD";
	else if (errorCode == 41)
		return "BACKEND_NOT_AVAILABLE";
	else if (errorCode == 42)
		return "NULL_CLIENT_ID";
	else if (errorCode == 43)
		return "INVALID_CLIENT_ID";
	else if (errorCode == 44)
		return "INVALID_MPRIVACY";
	else if (errorCode == 100)
		return "DOPEBALLS_ERROR";
	else if (errorCode == 101)
		return "COMPNAME_TOO_LONG";
	else if (errorCode == 102)
		return "NULL_COMPNAME";
	else if (errorCode == 103)
		return "ALL_BLANKS_COMPNAME";
	else if (errorCode == 104)
		return "DEVICENAME_TOO_LONG";
	else if (errorCode == 105)
		return "NULL_DEVICENAME";
	else if (errorCode == 106)
		return "ALL_BLANKS_DEVICENAME";
	else if (errorCode == 107)
		return "NAME_LANG_TOO_LONG";
	else if (errorCode == 108)
		return "NULL_DEVICENAME_LANG";
	else if (errorCode == 109)
		return "ALL_BLANKS_NAME_LANG";
	else if (errorCode == 110)
		return "DEVICE_PIN_TOO_LONG";
	else if (errorCode == 111)
		return "NULL_DEVICE_PIN";
	else if (errorCode == 112)
		return "ALL_BLANKS_DEVICE_PIN";
	else if (errorCode == 113)
		return "INVALID_DEVICE_PIN";
	else if (errorCode == 114)
		return "CONFIRM_CODE_TOO_LONG";
	else if (errorCode == 115)
		return "NULL_CONFIRM_CODE";
	else if (errorCode == 116)
		return "ALL_BLANKS_CONFIRM_CODE";
	else if (errorCode == 117)
		return "DEVICE_NUMBER_TOO_LONG";
	else if (errorCode == 118)
		return "NULL_DEVICE_NUMBER";
	else if (errorCode == 119)
		return "ALL_BLANKS_DEVICE_NUM";
	else if (errorCode == 120)
		return "INVALID_SERVICE_FLAGS";
	else if (errorCode == 121)
		return "INVALID_NUM_SERVICE_IDS";
	else if (errorCode == 122)
		return "INVALID_SERVICE_IDS";
	else if (errorCode == 123)
		return "INVALID_NUM_SERVICES";
	else if (errorCode == 124)
		return "NOT_ALL_DEVICES_DELETED";
	else if (errorCode == 125)
		return "DEVICES_DELETED_WITH_ERRORS";
	else if (errorCode == 126)
		return "SERVICES_NOT_NOTIFIED";
	else if (errorCode == 127)
		return "NULL_ATTRIBUTES";
	else if (errorCode == 128)
		return "DELETE_REQUEST_NOT_PROCESSED";
	else if (errorCode == 130)
		return "DEVICE_ALREADY_ACTIVATED";
	else if (errorCode == 131)
		return "INVALID_CONF_CODE";
	else if (errorCode == 132)
		return "INCORRECT_CONF_CODE";
	else if (errorCode == 133)
		return "NULL_BODY";
	else if (errorCode == 134)
		return "INVALID_TO";
	else if (errorCode == 135)
		return "INVALID_FROM";
	else if (errorCode == 136)
		return "INVALID_SUBJ";
	else if (errorCode == 201)
		return "NOT_SIGNED_IN";
	else if (errorCode == 202)
		return "REGISTRATION_PARAMETERS_MISSING";
	else if (errorCode == 203)
		return "PARAMETER_PH1_MISSING";
	else if (errorCode == 204)
		return "PARAMETER_PH2_MISSING";
	else if (errorCode == 205)
		return "PARAMETER_PH3_MISSING";
	else if (errorCode == 206)
		return "PARAMETER_PHONE_NUMBER_MISSING";
	else if (errorCode == 207)
		return "PARAMETER_DEVICE_NUMBER_MISSING";
	else if (errorCode == 208)
		return "PARAMETER_SHORT_CODE_MISSING";
	else if (errorCode == 209)
		return "PARAMETER_DEVICE_ID_MISSING";
	else if (errorCode == 210)
		return "PARAMETER_SERVICE_MISSING";
	else if (errorCode == 211)
		return "PARAMETER_CARRIER_MISSING";
	else if (errorCode == 212)
		return "PARAMETER_MAKE_MISSING";
	else return "Unknown error: " + errorCode;
}

