// JavaScript Document
//document.top_pg..value
function calc_floor_area()
{
	var err=0;
	var cnt = document.top_pg.radiobutton.length;
	if(document.top_pg.length_sqft.value=="")
	{
		alert("Please Enter Length of room");
		err=1;		
		document.top_pg.length_sqft.focus();
		return false;
	}
	if(document.top_pg.length_sqft.value.match(/[ A-Za-z`~!#$%^*()_:;"'|<>?]+/))
	{
		alert("Please Enter Only numeric value for Length of room");
		err=1;		
		document.top_pg.length_sqft.value="";
		document.top_pg.length_sqft.focus();
		return false;
	}	
	if(document.top_pg.width_sqft.value=="")
	{
		alert("Please Enter Width of room");
		err=1;		
		document.top_pg.width_sqft.focus();
		return false;
	}
	if(document.top_pg.width_sqft.value.match(/[ A-Za-z`~!#$%^*()_:;"'|<>?]+/))
	{
		alert("Please Enter Only numeric value for Width of room");
		err=1;
		document.top_pg.width_sqft.value="";
		document.top_pg.width_sqft.focus();
		return false;
	}
	if(cnt==0)
	{
		alert("Still no product Added..");
	}
	else if(cnt > 1)
	{
		var chk=0
		for(var x=0; x<cnt; x++)
		{
			if(document.top_pg.radiobutton[x].checked==true)
			{
				document.top_pg.tilesize.value = document.top_pg.radiobutton[x].value;
				chk=1;
			}
		}
		if(chk==0)
		{
			alert("Please select one of the tiles size");
			err=1;
			document.top_pg.radiobutton[0].focus();
			return false;
		}
	}
	else
	{
		if(document.top_pg.radiobutton.checked==false)
		{
			alert("Please select one of the tiles size");
			err=1;
			document.top_pg.radiobutton.focus();
			return false;			
		}
		else
		{
			document.top_pg.tilesize.value = document.top_pg.radiobutton.value;
		}
	}
	if(err == 0)
	{
		var area_sq_feet = document.top_pg.length_sqft.value * document.top_pg.width_sqft.value;
		var total_tiles_before_waste, total_tiles
		document.top_pg.AreaSqFt.value=area_sq_feet;
		if(area_sq_feet < 0)
		{
			alert("Eithers of input is wrong!!");
			document.top_pg.width_sqft.focus();
			return false;			
		}
		// geting size of tiles in sqft
		var splt_size = document.top_pg.tilesize.value.split("~");
		if(splt_size[0] < 0 || splt_size[1] < 0)
		{
			alert("Some error has occurd.. Sorry for incovinance..");
			return false;
		}
		else
		{
			var tile_sqft_widht = splt_size[0] * 0.0032808399
			var tile_sqft_height = splt_size[1] * 0.0032808399
			var tile_sqft = tile_sqft_widht * tile_sqft_height;
		}
		// # end of geting tiles size
		
		// calculate total number of tiles needed
		total_tiles_before_waste=area_sq_feet / tile_sqft;
		total_waste_add = total_tiles_before_waste * 0.10;
		total_tiles = Math.ceil(total_tiles_before_waste + total_waste_add);
//		alert(" total_tiles_before_waste " + total_tiles_before_waste + " , total_tiles " +total_tiles+ " , total_waste_add " +total_waste_add);
		document.top_pg.NumTile.value=total_tiles;
		var total_number_box = Math.ceil(total_tiles / document.top_pg.p_package.value);
		var em_tab_txt='<table width="450" border="0" cellpadding="0" cellspacing="0"><tr align="center" valign="top" bgcolor="#FFFFFF"><td height="25" colspan="2" valign="middle"><span class="paratext_head"><font size="2">Floor Tiles Calculator</font></span></td></tr><tr valign="top"><td width="228" height="25" align="left" valign="middle" bgcolor="#FFFFFF" class="paratext"><b>&nbsp;&nbsp;From [Name]:</b></td><td height="25" align="left" valign="middle" class="newstxt"><input name="from_name" type="text" class="form_textfield" id="from_name"></td></tr><tr valign="middle" bgcolor="#FFFFFF"><td height="25" align="left" class="paratext"><b>&nbsp;&nbsp;From [Email]:</b></td><td height="25" align="left"><input name="from_email" type="text" class="form_textfield" id="from_email"></td></tr><tr valign="middle" bgcolor="#FFFFFF"><td height="25" align="left" class="paratext"><b>&nbsp;&nbsp;Architect [Email]:</b></td><td height="25" align="left"><input name="architect_email" type="text" class="form_textfield" id="architect_email"></td></tr><tr valign="top" bgcolor="#FFFFFF"><td height="25" align="left" valign="middle" class="paratext"><b>&nbsp;&nbsp;Other [Email]:</b></td><td height="25" align="left" valign="middle"><input name="other_email" type="text" class="form_textfield" id="other_email"></td></tr><tr align="center" valign="top" bgcolor="#FFFFFF"><td></td><td height="50" align="left" valign="middle" class="paratext"><input type="submit" name="Submit" value="Submit" class="form_btn1"></td></tr></table>';
		document.getElementById("em_tbl").innerHTML = em_tab_txt;
	}
}
function sub_frm(catid)
{
	if(catid ==2)
	{
		window.location.href="calculator_wall.php";
	}
}
function chk_frm()
{
	var cnt_email=0;
	if(document.top_pg.from_name.value=="")
	{
		alert("Pleaes enter your name");
		document.top_pg.from_name.focus();
		return false;
	}
	if(document.top_pg.from_email.value=="")
	{
		alert("Pleaes enter your Email Address");
		document.top_pg.from_email.focus();
		return false;
	}
	if(document.top_pg.from_email.value!="")
	{
		
		if(echeck(document.top_pg.from_email.value)==false)
		{
			document.top_pg.from_email.value="";
			document.top_pg.from_email.focus();
			return false;
		}
	}
	
	if(document.top_pg.architect_email.value!="")
	{
		
		if(echeck(document.top_pg.architect_email.value)==false)
		{
			document.top_pg.architect_email.value="";
			document.top_pg.architect_email.focus();
			return false;
		}
		else
		{
			cnt_email=1;
		}
	}
	if(document.top_pg.other_email.value!="")
	{
		if(echeck(document.top_pg.other_email.value)==false)
		{
			document.top_pg.other_email.value="";
			document.top_pg.other_email.focus();
			return false;
		}
		else
		{
			cnt_email=2;
		}
	}
	if(cnt_email==0)
	{
		alert("Please enter atleast one address.");
		document.top_pg.architect_email.focus();
		return false;
	}
}
function echeck(str)
{
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){
	   alert("Please enter valid email id");
	   return false;
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Please enter valid email id");
	   return false;
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Please enter valid email id");
		return false;
	}
	 if (str.indexOf(at,(lat+1))!=-1){
		alert("Please enter valid email id");
		return false;
	 }
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Please enter valid email id");
		return false;
	 }
	 if (str.indexOf(dot,(lat+2))==-1){
		alert("Please enter valid email id");
		return false;
	 }

	 if (str.indexOf(" ")!=-1){
		alert("Please enter valid email id");
		return false;
	 }
	  return true;
}
