function limitTextArea(textarea, maxLines, maxChar){
    if(textarea.value == null || textarea.value.length == 0) {
	return;
    }

    var lines = textarea.value.split('\n');
    var i = 0;
    var newText;

    if(lines.length > maxLines){
	lines = lines.slice(0, maxLines);
    }

    while(i < lines.length) {
	
	if(lines[i].length > maxChar) {
	    lines[i] = lines[i].slice(0, maxChar);
	}

	if(lines[i].length > 0) {
	    if(newText == null) {
		if(i == lines.length - 1) {
		    newText = lines[i];
		} else {
		    newText = lines[i] + '\n';
		}
	    } else {
		if(i == lines.length - 1) {
		    newText += lines[i];
		} else {
		    newText += lines[i] + '\n';
		}
	    }
	}
	i++;
    }

    
    textarea.value = newText;
}

function limitSymbols(txtControl, maxChar) {
    
    if(txtControl.value == null || txtControl.value.length == 0) {
	return;
    }
    
    var text = txtControl.value;
    if(text.length > maxChar) {
	text = text.slice(0, maxChar);
	txtControl.value = text;
    }
}

function getKeyCode(e) {
    if (window.event) {
	return window.event.keyCode;
    } else if (e) {
	return e.which;
    } else {
	return null;
    }
}
function limitOnlyLetters(e, validchars) {
    var key='', keychar='';
    key = getKeyCode(e);
    if (key == null) {
	return true;
    }
    keychar = String.fromCharCode(key);
    keychar = keychar.toLowerCase();
    validchars = validchars.toLowerCase();
    if (validchars.indexOf(keychar) != -1) {
	return true;
    }
    if (key==null || key==0 || key==8 || key==9 || key==13 || key==27) {
	return true;
    }
    return false;
}

function removeSpaces(inputfield) {
    var text = inputfield.value;
    if(text.indexOf(' ') != -1) {
	text = text.replace(' ','');
	inputfield.value = text;
    }
}

function handleNames(textControl, maxChars) {
    removeSpaces(textControl);
    limitSymbols(textControl, maxChars);
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function changeSignupCaptcha() {
    var signupCaptcha = document.getElementById('signupCaptcha');
    signupCaptcha.src = 'signupCaptcha1';
}

function getKeyCode(e) {
    if (window.event) {
	return window.event.keyCode;
    } else if (e) {
	return e.which;
    } else {
	return null;
    }
}

function keyRestrict(text, e, validchars, maxSize) {    
    var key='', keychar='';
    key = getKeyCode(e);
    
    if (key == null) {
	return true;
    }
    if((text != null) && (text.length > (maxSize - 1))) {
	if (key==null || key==0 || key==8 || key==9 || key==13 || key==27) {
	    return true;
	}
	return false;
    }
    
    keychar = String.fromCharCode(key);
    keychar = keychar.toLowerCase();
    validchars = validchars.toLowerCase();

    if (validchars.indexOf(keychar) != -1) {
	return true;
    }
    if (key==null || key==0 || key==8 || key==9 || key==13 || key==27) {
	return true;
    }

    return false;
}

function showHideIsp() {
    var currentIspCtrl = document.getElementById("currentIsp");
    var noIspCheckBoxCtrl = document.getElementById("noIsp");

    if(noIspCheckBoxCtrl.checked) {
        currentIspCtrl.disabled = true;
        currentIspCtrl.readOnly = true;
        currentIspCtrl.value = "";
    } else {
        currentIspCtrl.disabled = false;
        currentIspCtrl.readOnly = false;
    }
}

function selectItemByValue(ddlId, value) {
    var listBox = document.getElementById(ddlId);

    //is it possible to index the dropdown array ??
    for(index1 = 0 ; index1 < listBox.options.length; index1++){
        if(listBox.options[index1].value == value) {
            listBox.options[index1].selected = true;
            break;
        }
    }
}