﻿function trim(str) {
	var whitespace = new String(" \t\n\r");
	var s = new String(" " + str + " ");
	if (whitespace.indexOf(s.charAt(0)) != -1) {
		var j=0, i = s.length;
            while (j < i && whitespace.indexOf(s.charAt(j)) != -1) {
			j++;
		}
            s = s.substring(j, i);
	}

	if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
		var i = s.length - 1;       
            while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) {
			i--;
		}
            s = s.substring(0, i+1);
	}
	return s;
}

function Textbox_Maxlenth(textbox, max) {
    var maxlength = new Number(max);
    if (textbox.value.length > maxlength) {
        textbox.value = textbox.value.substring(0, maxlength);
        alert('You have entered too many characters! ' + max + ' character limit');
    }
}

function win(URL, w, h) { 
	swidth = (screen.width-w)/2;
	sheight = (screen.availHeight-h)/2
	var win = window.open(URL,'win','width='+w+',height='+h+',top=' + sheight + ',left=' + swidth + ',resizable=yes,scrollbars=yes,menubar=yes');
	win.focus();
}
function winpic(URL, w, h) { 
	swidth = (screen.width-w)/2;
	sheight = (screen.availHeight-h)/2
	var winpic = window.open(URL,'winpic','width='+w+',height='+h+',top=' + sheight + ',left=' + swidth + ',resizable=yes,scrollbars=yes,menubar=yes');
	winpic.focus();
}