var len, wid, hgt, area_mt, j

function isNumber(form) {
	for(j=0; j<3; j++) {
		var inputStr = form.elements[j].value
		var inputVal = parseInt(inputStr)
			for(var i=0; i<inputStr.length; i++) {
				var isChar = inputStr.substring(i, i+1)
					if(inputStr == " " || inputVal <= 0 || isChar > "9") {
						alert("Please enter a number in " + form.elements[j].name + " field.")
						return false
	 				}
			}
	}
	return true
}			

function check(form) 
{
	
		len = parseFloat(form.length.value)
		wid = parseFloat(form.width.value)
		hgt = parseFloat(form.height.value)
		
		if ( form.w1.value.split(" ").join("") == "" ) { form.w1.value = "0"; }
		if ( form.h1.value.split(" ").join("") == "" ) { form.h1.value = "0"; }
		if ( form.w2.value.split(" ").join("") == "" ) { form.w2.value = "0"; }
		if ( form.h2.value.split(" ").join("") == "" ) { form.h2.value = "0"; }
		doorw1 = parseFloat(form.w1.value);
		doorh1 = parseFloat(form.h1.value);
		winw2 = parseFloat(form.w2.value);
		winh2 = parseFloat(form.h2.value);
		chk = false;
		for(x=0; x<16; x++) {
			if ( form.tileSize[x].checked == true ) { chk = form.tileSize[x].checked; }
			}
		if ( chk == false ) {
			alert("Please select Size");
			}
		else {
			calculate_area(form)
			$find('ModalPopupResult').show();
			return false;
			}
	
}
/*
function calculate_area(form) {

	var no_tile, no_box, no_box_p, val
		
	if(len < wid) {
		var temp = len
		len = wid
		wid = temp
	}
	var area_ft = (((2 * (len + wid)) * hgt)) * 1.05
	var str_ft = (" " + area_ft)
	form.AreaFt.value = parseFloat(str_ft.substring(0, 5))		
	area_mt = area_ft / 10.76
  	
	if(hgt <= 5) { 
		area_mt = (area_mt - 0.75)
		var str_mt = (" " + area_mt)
		area_mt = parseFloat(str_mt.substring(0, 5))
		form.AreaMt.value = area_mt
	}
	else {
		area_mt = (area_mt - 1.5)
		var str_mt = (" " + area_mt)
		area_mt = parseFloat(str_mt.substring(0, 5))
		form.AreaMt.value = area_mt
	}

	for(var i=0; i<form.tileSize.length; i++) {
		if(form.tileSize[i].checked) {
			val = form.tileSize[i].value
			break
		}
	}
	if(val == "one") 
	{
		alert(area_mt);
		alert(no_tile);
		no_tile = parseInt(area_mt / 0.04)
		no_box = parseInt(no_tile / 30)
		no_box_p = no_tile % 30
	}
	else if(val == "two") {
		no_tile = parseInt(area_mt / 0.06)
		no_box =  parseInt(no_tile / 25)
		no_box_p = no_tile % 25
	}
	else if(val == "three") {
		no_tile = parseInt(area_mt / 0.09)
		no_box =  parseInt(no_tile / 20)
		no_box_p = no_tile % 20
	}
	else if(val == "four") {
		no_tile = parseInt(area_mt / 0.13)
		no_box =  parseInt(no_tile / 15)
		no_box_p = no_tile % 15
	}
	else if(val == "five") {
		no_tile = parseInt(area_mt / 0.18)
		no_box =  parseInt(no_tile / 10)
		no_box_p = no_tile % 10
	}
	
		
	form.NumTile.value = no_tile
	form.NumBox.value = no_box_p
	form.NumP.value = no_box
}
*/
function calculate_area(form) {

	var no_tile, no_box, no_box_p, val
		
	/*if(len < wid) {
		var temp = len
		len = wid
		wid = temp
	}*/
	for(var i=0; i<form.tileSize.length; i++) {
		if(form.tileSize[i].checked) {
			val = form.tileSize[i].value
			break
		}
	}
	if ( val.substring(0, 1) == "x" ) {
		var area_ft1 = 0;
		var area_ft2 = 0;
		var area_ft = len * wid;
		var area_mt = (area_ft/(3.28*3.28))
		//area_mt = area_ft * 10.76
		//area_mm=area_mt*1000
		form.AreaMt.value = area_mt
		form.AreaFt.value = area_ft
		}
	else {
		var area_ft1 = 2 *(len * hgt) + 2 *(wid * hgt)
		var area_ft2 = (doorw1 * doorh1) + (winw2 * winh2)
		var area_ft = (area_ft1 - area_ft2)
		var area_mt = (area_ft/10.7584)
		//area_mt = area_ft * 10.76
		//area_mm=area_mt*1000
		form.AreaMt.value = area_mt
		form.AreaFt.value = area_ft
		}
	
	if(val == "one") 
	{
		//no_tile = parseInt(area_mt / 40)	
		//no_box = parseInt(no_tile / 24)
		//no_box_p = no_box * 24

		var no_tile = parseInt((area_mt*24)/0.96);
		var no_box = parseInt(no_tile/24);
		var nobox = no_tile/24;
		var mary = nobox.toString().split(".");
		if ( parseInt(mary[1]) > 0 ) { no_box++; }
		no_box_p = no_box * 24;
	}
	else if(val == "two") {
		no_tile = parseInt((area_mt*15)/0.90)
		no_box = parseInt(no_tile/15)
		var nobox = no_tile/15;
		var mary = nobox.toString().split(".");
		if ( parseInt(mary[1]) > 0 ) { no_box++; }
		no_box_p = no_box * 15
		
	}
	else if(val == "three") {
		no_tile = parseInt((area_mt*10)/0.90)
		no_box = parseInt(no_tile/10)
		var nobox = no_tile/10;
		var mary = nobox.toString().split(".");
		if ( parseInt(mary[1]) > 0 ) { no_box++; }
		no_box_p = no_box * 10
	}
	else if(val == "four") {
		no_tile = parseInt((area_mt*11)/0.90)
		no_box = parseInt(no_tile/11)
		var nobox = no_tile/11;
		var mary = nobox.toString().split(".");
		if ( parseInt(mary[1]) > 0 ) { no_box++; }
		no_box_p = no_box * 11
	}
	else if(val == "five") {
		no_tile = parseInt((area_mt*9)/0.95)
		no_box = parseInt(no_tile/9)
		var nobox = no_tile/9;
		var mary = nobox.toString().split(".");
		if ( parseInt(mary[1]) > 0 ) { no_box++; }
		no_box_p = no_box * 9
	}
	else if(val == "six") {
		no_tile = parseInt((area_mt*9)/0.90)
		no_box = parseInt(no_tile/9)
		var nobox = no_tile/9;
		var mary = nobox.toString().split(".");
		if ( parseInt(mary[1]) > 0 ) { no_box++; }
		no_box_p = no_box * 9
	}
	else if(val == "seven") {
		no_tile = parseInt((area_mt*8)/0.96)
		no_box = parseInt(no_tile/8)
		var nobox = no_tile/8;
		var mary = nobox.toString().split(".");
		if ( parseInt(mary[1]) > 0 ) { no_box++; }
		no_box_p = no_box * 8
	}
	else if(val == "eight") {
		no_tile = parseInt((area_mt*7)/0.95)
		no_box = parseInt(no_tile/7)
		var nobox = no_tile/7;
		var mary = nobox.toString().split(".");
		if ( parseInt(mary[1]) > 0 ) { no_box++; }
		no_box_p = no_box * 7
	}
	else if(val == "xone") {
		no_box = parseInt(area_mt/0.96);
		var nobox = area_mt/0.96;
		var mary = nobox.toString().split(".");
		if ( parseInt(mary[1]) > 0 ) { no_box++; }
		no_tile = (area_mt*24)/0.96
		var tile_rnd = no_tile.toString().split(".");
		if ( parseInt(tile_rnd[1]) > 0 ) { no_tile++ }
		no_tile = parseInt(no_tile)
		//no_tile = parseInt(no_box*24)
		no_box_p = no_box * 24
	}
	else if(val == "xtwo") {
		no_box = parseInt(area_mt/0.90);
		var nobox = area_mt/0.90;
		var mary = nobox.toString().split(".");
		if ( parseInt(mary[1]) > 0 ) { no_box++; }
		no_tile = (area_mt*15)/0.90
		var tile_rnd = no_tile.toString().split(".");
		if ( parseInt(tile_rnd[1]) > 0 ) { no_tile++ }
		no_tile = parseInt(no_tile)
		no_box_p = no_box * 15
	}
	else if(val == "xthree") {
		no_box = parseInt(area_mt/0.90);
		var nobox = area_mt/0.90;
		var mary = nobox.toString().split(".");
		if ( parseInt(mary[1]) > 0 ) { no_box++; }
		no_tile = (area_mt*11)/0.90
		var tile_rnd = no_tile.toString().split(".");
		if ( parseInt(tile_rnd[1]) > 0 ) { no_tile++ }
		no_tile = parseInt(no_tile)
		no_box_p = no_box * 11

	}
	else if(val == "xfour") {
		no_box = parseInt(area_mt/0.95);
		var nobox = area_mt/0.95;
		var mary = nobox.toString().split(".");
		if ( parseInt(mary[1]) > 0 ) { no_box++; }
		no_tile = (area_mt*9)/0.95
		var tile_rnd = no_tile.toString().split(".");
		if ( parseInt(tile_rnd[1]) > 0 ) { no_tile++ }
		no_tile = parseInt(no_tile)
		no_box_p = no_box * 9
	}
	else if(val == "xfive") {
		no_box = parseInt(area_mt/0.90);
		var nobox = area_mt/0.90;
		var mary = nobox.toString().split(".");
		if ( parseInt(mary[1]) > 0 ) { no_box++; }
		no_tile = (area_mt*9)/0.90
		var tile_rnd = no_tile.toString().split(".");
		if ( parseInt(tile_rnd[1]) > 0 ) { no_tile++ }
		no_tile = parseInt(no_tile)
		no_box_p = no_box * 9
	}
	else if(val == "xsix") {
		no_box = parseInt(area_mt/0.90);
		var nobox = area_mt/0.90;
		var mary = nobox.toString().split(".");
		if ( parseInt(mary[1]) > 0 ) { no_box++; }
		no_tile = (area_mt*10)/0.90
		var tile_rnd = no_tile.toString().split(".");
		if ( parseInt(tile_rnd[1]) > 0 ) { no_tile++ }
		no_tile = parseInt(no_tile)
		no_box_p = no_box * 10	}
	else if(val == "xseven") {
		no_box = parseInt(area_mt/0.96);
		var nobox = area_mt/0.96;
		var mary = nobox.toString().split(".");
		if ( parseInt(mary[1]) > 0 ) { no_box++; }
		no_tile = (area_mt*8)/0.96
		var tile_rnd = no_tile.toString().split(".");
		if ( parseInt(tile_rnd[1]) > 0 ) { no_tile++ }
		no_tile = parseInt(no_tile)
		no_box_p = no_box * 8	}
	else if(val == "xeight") {
		no_box = parseInt(area_mt/0.95);
		var nobox = area_mt/0.95;
		var mary = nobox.toString().split(".");
		if ( parseInt(mary[1]) > 0 ) { no_box++; }
		no_tile = (area_mt*7)/0.95
		var tile_rnd = no_tile.toString().split(".");
		if ( parseInt(tile_rnd[1]) > 0 ) { no_tile++ }
		no_tile = parseInt(no_tile)
		no_box_p = no_box * 7	}

	form.NumTile.value = no_tile
	form.NumBox.value = no_box
//	form.NumP.value = no_box_p
}
