function money_format(num) {
	num = num.toString();
	has_dot = false;
	dot_pos = 0;

	if(is_numeric(num)) {
		for(i = 0; i < num.length; i++) {
			ch = num.charAt(i);
			if(ch == ".") {
				has_dot = true;
				dot_pos = i;
				break;
			}
		}
		
		if(has_dot) {
			if((dot_pos + 1) == num.length-1) {
				return (num.substr(0, dot_pos + 2) + "0");
			}
			else if(dot_pos == num.length-1) {
				return (num + "00");
			}
			else {
				return num.substr(0, dot_pos + 3);
			}
		}
		else {
			return num + ".00";
		}
	}
	return false;
}

function is_numeric(string, positive_only) {
	pos_valid_chars = "1234567890.";
	all_valid_chars = "1234567890.-";
	
	dots = 0;

	if(string.length == 0) 
		return false;

	for(i = 0; i < string.length && (dots <= 1); i++) {
		ch = string.charAt(i);

		if(ch == ".")
			dots++;
				
		// jeigu pirmas taskas iseinam
		if((i == 0) && (ch == '.')) 
			return false;

		// jeigu daugiau kaip 1 taskas, iseinam
		if(dots > 1)
			return false;
				
		if(positive_only) {
			if(pos_valid_chars.indexOf(ch) == -1) {
				return false;
			}
		}
		else {
			// ziurim pirma skaiciu, nes tik jis gali buti "-"
			if(i == 0) {
				if(all_valid_chars.indexOf(ch) == -1) {
					return false;
				}
			}
			else {
				if(pos_valid_chars.indexOf(ch) == -1) {
					return false;
				}
			}
		}
	}
	
	return true;
}

function count_price() {
	d = document;
	
	priceas		= document.getElementById("price").value;
	percentas	= d.getElementById("main_contrib").value;
	monthsas	= d.getElementById("months").value;
	monthlyas	= d.getElementById("monthly");
	f_contribas	= d.getElementById("first_contrib");

	if(is_numeric(priceas, true) && is_numeric(monthsas, true) && is_numeric(percentas, true)) {
		first_sum = priceas * percentas / 100;
		f_contribas.value = money_format(first_sum);
		monthlyas.value = money_format((priceas - first_sum) / monthsas);
	}
}

function openPopup( url, width, height ) {
		xposition=20; yposition=20;
		if ((parseInt(navigator.appVersion) >= 4 )){
			xposition = (screen.width - width) / 2;
			yposition = (screen.height - height) / 2;
		} 
		args = "width=" + width + "," 
			    + "height=" + height + "," 
				+ "location=0," 
				+ "menubar=0,"
				+ "resizable=0,"
				+ "scrollbars=yes,"
				+ "status=0," 
				+ "titlebar=0,"
				+ "toolbar=0,"
				+ "hotkeys=0,"
				+ "screenx=" + xposition + ","  //NN Only
				+ "screeny=" + yposition + ","  //NN Only
				+ "left=" + xposition + ","     //IE Only
				+ "top=" + yposition;           //IE Only 
		ww = window.open(url,'devlabc', args);
	}
