
	function SFTtoSYD(){
		//document.getElementById('syd').value=9*parseInt(document.getElementById('sft').value)
		document.getElementById('syd').value=Math.ceil(parseInt(document.getElementById('sft').value)/9);
		SFTtoBOX();
	}

	function SYDtoSFT(){
		//document.getElementById('sft').value=Math.ceil(parseInt(document.getElementById('syd').value)/9);
		document.getElementById('sft').value=9*parseInt(document.getElementById('syd').value)
		SFTtoBOX();
	}

	function SFTtoBOX(){
		if(document.getElementById('sft').value=='')
			document.getElementById('boxes').value='';
		else if(document.getElementById('floor_coverage_unit').value=='S/FT')
			document.getElementById('boxes').value=Math.ceil(parseInt(document.getElementById('sft').value)/parseInt(document.getElementById('floor_coverage').value));
		else
			document.getElementById('boxes').value=Math.ceil(parseInt(document.getElementById('syd').value)/parseInt(document.getElementById('floor_coverage').value));
		calPrice();
	}

	function BOXtoSFTorSYD(){
		if(document.getElementById('boxes').value==''){
			document.getElementById('sft').value='';
			document.getElementById('syd').value='';
		}else if(document.getElementById('floor_coverage_unit').value=='S/FT'){
			document.getElementById('sft').value=parseInt(document.getElementById('floor_coverage').value)*parseInt(document.getElementById('boxes').value);
			document.getElementById('syd').value=Math.ceil(parseInt(document.getElementById('sft').value)/9);
		}else{
			document.getElementById('syd').value=parseInt(document.getElementById('floor_coverage').value)*parseInt(document.getElementById('boxes').value);
		document.getElementById('sft').value=9*parseInt(document.getElementById('syd').value)
		}
		calPrice();
	}

	function openCal(){
		if(document.getElementById('_cal').style.display==''){
			document.getElementById('_cal').style.display='none';
			document.getElementById('_room').innerHTML='';
		}else{
			document.getElementById('_cal').style.display='';
			loadRoom();
		}
	}

	function loadRoom(){
		loadPostAjax('room.php?num_room='+document.getElementById('room').value, '_room');
	}

	function calAreaByRoom(){
		var sum=0;
		for(var i=1;i<=parseInt(document.getElementById('room').value);i++){
			sum=sum+parseInt(document.getElementById('w['+i+']').value)*parseInt(document.getElementById('l['+i+']').value);
		}
		document.getElementById('area').value=sum;
		calWaste();
	}

	function calWaste(){
		var sft=0;
		var syd=0;
		sft=parseInt(document.getElementById('area').value)+parseInt(document.getElementById('area').value)*parseInt(document.getElementById('plus').value)/100;
		document.getElementById('cal_sft').innerHTML=sft.toFixed(2);
		syd=parseFloat(sft.toFixed(2))/9;
		document.getElementById('cal_syd').innerHTML=syd.toFixed(2);
	}

	function useQuantity(){
		if(parseFloat(document.getElementById('cal_sft').innerHTML)>0){
			document.getElementById('sft').value=Math.ceil(parseFloat(document.getElementById('cal_sft').innerHTML));
			SFTtoSYD();
		}else{
			alert('Enter the area you wish to cover below to calculate quantity needed.');
		}
	}

	function calPrice(){
		var price=0;
		if(document.getElementById('boxes').value==''){
			document.getElementById('price').value='0';
			calShipping();
			return;
		}
		if(parseFloat(document.getElementById('floor_prom_price_unit').value)>0){
			price=parseFloat(document.getElementById('floor_prom_price_unit').value)*parseInt(document.getElementById('boxes').value);
		}else{
			price=parseFloat(document.getElementById('floor_price_unit').value)*parseInt(document.getElementById('boxes').value);
		}
		document.getElementById('s_total_price').innerHTML=price.toFixed(2);
		document.getElementById('price').value=price.toFixed(2);
		calShipping();
	}

	function getQuotes(){
		if((document.getElementById('sft').value=='')||(document.getElementById('price').value=='')){
			alert('You have not choose the size needed!');
		}else if(document.getElementById('color_id').value==''){
			alert('You have not select the color needed!');
		}else{
			document.forms[0].submit();
		}
	}

	function calShipping(){
		var str=new String();
		str=document.getElementById('post_code').value;
		if(str.length>=3){
			if((document.getElementById('post_code').value!='')&&(document.getElementById('boxes').value!='')&&(document.getElementById('boxes').value!='NaN')){
				var url='cal_floor.php?post_code='+document.getElementById('post_code').value+'&order_item='+document.getElementById('order_item').value+'&boxes='+document.getElementById('boxes').value;
				var result=retData(url);
				var arr=result.split('#');
				document.getElementById('total_box').innerHTML=arr[0];
				if(arr[1]=='undefined')
					arr[1]=0;
				if(document.getElementById('special_fee').value==''){
					document.getElementById('s_shipping_price').innerHTML=arr[1];
				}else{
					var shipping=parseFloat(arr[1])+parseFloat(document.getElementById('special_fee').value);
					document.getElementById('s_shipping_price').innerHTML=shipping.toFixed(2);
					//document.getElementById('s_shipping_price').innerHTML=arr[1];
				}
			}else{			
				var url='cal_floor.php?post_code='+document.getElementById('post_code').value+'&order_item='+document.getElementById('order_item').value+'&boxes=0';
				var result=retData(url);
				var arr=result.split('#');
				if(arr[0]!=''){
					document.getElementById('total_box').innerHTML=arr[0];
					if(arr[1]=='undefined')
						arr[1]=0;
					document.getElementById('s_shipping_price').innerHTML=arr[1];
				}
			}
		}
	}
