	var FOOT_UNIT = 30.48
	var INCH_UNIT = 2.54;
	
	
	/*
	=================================
	 convertWeight [???? ]
	 -  @unitDiv  0: lb -> kg  1: kg -> lb
	 -  @weightNum
	=================================
	*/
	function convertWeightKG(weightNum) {
		return (parseFloat(weightNum) / 2.2);
	}

	/*
	=================================
	 convertWeight [???? ]
	 -  @unitDiv  0: lb -> kg  1: kg -> lb
	 -  @weightNum
	=================================
	*/
	function convertWeightLB(weightNum) {
		return (parseFloat(weightNum) * 2.2);
	}
	
	/*
	=================================
	 convertHeight 
	 	[?? :foot/inch -> cm ?? ]
	 -  @footInt  
	 -  @inchInt
	=================================
	*/
	function convertHeight( footInt , inchInt) {
		return footInt*FOOT_UNIT+inchInt*INCH_UNIT;			
	}
	
	/*
	=================================
	 convertInchHeight 
	 	[?? :foot/inch -> inch ?? ]
	 -  @footInt  
	 -  @inchInt
	=================================
	*/
	function convertInchHeight( footInt) {
		return footInt*12;
	}
	
	function convertFootInchHeight( footInt , inchInt) {
		return parseInt(footInt)+parseInt(inchInt);
	}
	
	function convertFood( heightcm ) {
		return heightcm/FOOT_UNIT;  
	}
	
	function convertInch( heightcm , feet ) {	
				
		return (heightcm -(feet*FOOT_UNIT))/INCH_UNIT;
	}
	/*
	 =================================
	 setBMI
	 	[BMI Formula]
	 - @weightNum (kg)
	 - @heightNum (cm)
	 =================================
	*/
	function setBMI( weightNum , heightNum ) {
		return (weightNum/(heightNum *heightNum))*10000;
	}
	
	/*
	 =================================
	 setWHR
	 	[WHR Formula : ??? ??? ?.. (??? ?? )]
	 - @waistNum
	 - @hipNum
	 =================================
	*/
	function setWHR( waistNum , hipNum ) {
		return waistNum/hipNum;
	}
	
	/*
	 =================================
	 setIBW
	   [Healthy Body Weight Formula]
	 - @sexStr    ( 1: men  , 0: women )
	 - @heightNum (inch)
	 - @frameSize ( 0.9:S , 0:M , 1.1:L)
	 =================================
	*/
	function setIBW( sexStr , heightNum, frameSize ) {
	
		var ibwNum;			
	
		if ( sexStr == "0"){
			// women
			ibwNum = 100 + 5 * (heightNum - 60);
			
		} else {
			//men
			ibwNum = 106 + 5 * (heightNum - 60);
		}
		if(frameSize =="0"){//S
			ibwNum = ibwNum *0.9 ;
		}
		if(frameSize =="2"){//L
			ibwNum = ibwNum *1.1 ;
		}
		return ibwNum;			
	}
	
	/*
	 =================================
	 setDailyCalorieBudget
	 	[???  ??? ??? ]
	 - @sexStr     (1: men  , 0: women)
	 - @ageInt    
	 - @weightNum (Kg)
	 - @heightNum (cm)
	 - @activityLvl 
	 =================================
	*/
	function setDailyCalorieBudget( sexStr ,ageInt , weightNum , heightNum , activityLvl ) {
	
		var totDailyNum;		// Daily Calorie Budget
		var bmrlvlNum;		// factor considering activity level
		var bmrNum;			// BMR 
	
		// BMR ?? [????? ?? ??]
		if ( sexStr == "0" ){
			// women
			bmrNum = 655 + ( 9.56 * weightNum ) + ( 1.85 * heightNum) - ( 4.68 * ageInt );
		} else {
			//men
			bmrNum = 66 + ( 13.75 * weightNum ) + ( 5 * heightNum) - ( 6.76 * ageInt );
		}
		
		// Daily calorie needs = BMR * activity level value 
		bmrlvlNum = bmrNum * activityLvl;

		// Dail Calorie Needs = BMR + (BMR * activity level)
		totDailyNum = bmrlvlNum

		return totDailyNum;			
	}
	
	/*
	 =================================
	 setDailyCalorieNeed
	   [??? ?? ?? ??? ]
	 - @lossWeightInt  goal weight loss
	 - @totDailyNum    daily calorie bugdget  	[lbl]	
	 =================================
	*/
	function setObjectDailyCalorieNeed( totDailyNum , lossWeightInt  ) {	
		
		var needCalorieNum = totDailyNum - (lossWeightInt * 117);		// Daily Calorie Budget
		return needCalorieNum/100 ;			
	}		
	
	/*
	 =================================
	 setTargetHeartRate  KG
	   [??? ?? ?? ??? ]
	 - @sexStr     (1: men  , 0: women)
	 - @ageInt
	 =================================
	*/
	function setTargetHeartRate( sexStr,ageInt){	
		var heartCnt;
		
		// ??? ??? ?
		if ( sexStr == "0" ){
			// women
			heartCnt = 226-ageInt;
		} else {
			//men
			heartCnt = 220-ageInt;
		}
		
		return heartCnt;
	}		
	
	/*
	 =================================
	 bmiLang
	   [BMI ??  ]
	 - @target  daily calorie bugdget  		
	 =================================
	*/
	function bmiLang(target) {
    	var bmiRange = "(Under weight)";
    	
    	if( target > 18.5 && target < 25){
    		bmiRange = "(Normal weight)";
    	} else if( target >= 25 && target < 30){
    		bmiRange = "(Over weight)";
    	} else if( target >= 30){
    		bmiRange = "(Obese)";
    	}
    	
    	return bmiRange;    	
    }
	
	 /**
     *  Unit Convert
     *  cm -> inch
     * 
     * @param weight	 
     * @return
     */
    function convertUnitInch(target){ 	
    	return parseFloat(target) * 0.39;
    }
    
    /**
     *  Unit Convert
     * 
     *  [ inch -> cm ] 
     * @param weight	 
     * @return
     */
     function convertUnitCM(target){ 	
    	return target * 2.54;
    }

    /**
     *  period
     * 
     *  [ period ] 
     * @param year
     * @param month
     * @param day
     * @param cycle
     * @return
     */
     function getPeriod(year, month, day, cycle){ 	
    	//return toDate(year, month, day)+ nextDate(cycle);
    }
    //number & float
    function handlerNum(frm, num){
    	var forms;
    	if(num == 0){ forms = frm.bmi_lbs; }	//bmi_lbs
    	if(num == 1){ forms = frm.cm_1; }		//cm_1
    	if(num == 2){ forms = frm.whr_inch1; }	//whr_inch1
    	if(num == 3){ forms = frm.whr_inch2; }	//whr_inch2
    	if(num == 4){ forms = frm.health_lbs; }	//health_lbs
    	if(num == 5){ forms = frm.cm_2; }		//cm_2
    	if(num == 6){ forms = frm.caloric_lbs; }//caloric_lbs
    	if(num == 7){ forms = frm.cm_3; }		//cm_3
    	if(num == 8){ forms = frm.caloric_age; }//caloric_age
    	if(num == 9){ forms = frm.target_age; }	//target_age
    	if(num == 10){ forms = frm.women_cycle; }	//women_cycle
    	
    	e = window.event; 
        if(e.keyCode >= 48 && e.keyCode <= 57 || e.keyCode == 9 || e.keyCode >= 96 && e.keyCode <= 105 || e.keyCode == 8 || e.keyCode == 46 || e.keyCode == 110 || e.keyCode == 190){
            if(e.keyCode == 48 || e.keyCode == 96 || e.keyCode == 110 ||  e.keyCode == 190){
                if(forms.value == "" ) // not num + 0
                    e.returnValue=false; //not input
                else //num + 0
                    return; //input
            }
            else // not 0 and num
                return; //input
        }
        else //not num
            e.returnValue=false;
    }
	// number
    function handlerNum1(frm, num){
    	var forms;
    	if(num == 0){ forms = frm.bmi_lbs; }	//bmi_lbs
    	if(num == 1){ forms = frm.cm_1; }		//cm_1
    	if(num == 2){ forms = frm.whr_inch1; }	//whr_inch1
    	if(num == 3){ forms = frm.whr_inch2; }	//whr_inch2
    	if(num == 4){ forms = frm.health_lbs; }	//health_lbs
    	if(num == 5){ forms = frm.cm_2; }		//cm_2
    	if(num == 6){ forms = frm.caloric_lbs; }//caloric_lbs
    	if(num == 7){ forms = frm.cm_3; }		//cm_3
    	if(num == 8){ forms = frm.caloric_age; }//caloric_age
    	if(num == 9){ forms = frm.target_age; }	//target_age
    	if(num == 10){ forms = frm.women_cycle; }	//women_cycle
    	
    	e = window.event; 
        if(e.keyCode >= 48 && e.keyCode <= 57 || e.keyCode >= 96 && e.keyCode <= 105 || e.keyCode == 8 || e.keyCode == 46 ){
            if(e.keyCode == 48 || e.keyCode == 96 ){
                if(forms.value == "" ) // not num + 0
                    e.returnValue=false; //not input
                else //num + 0
                    return; //input
            }
            else // not 0 and num
                return; //input
        }
        else //not num
            e.returnValue=false;
    }

	 /**
	 * ex) fncRoundPrecision(300.12345678,3) <p>
	 * Result ) 300.123
	 * @param {Number} val 
	 * @param {Number} precision
	 * @return 
	 * @type Number
	 */
	function fncRoundPrecision(val, precision){
	  var p = Math.pow(10, precision);
	 return Math.round(val * p) / p;
	}

	function setPreviewBox(){ 
	  preview.style.posLeft = event.x + 30 + document.body.scrollLeft; 
	  preview.style.posTop = event.y - 30 + document.body.scrollTop;
	} 

	function hidePreview(){ 
	  preview.innerHTML=''; 
	  preview.style.visibility='hidden'; 
	}	
	
	function showPreview(){ 
	    var text; 
	    text = '<table cellpadding="0" cellspacing="0"  style="width:460px;background:#FFFFFF;border:1px solid #B8C7D5;padding:13px 12px 8px 2px;">';
	    text += '<tr>'; 
	    text += '<td valign="top">'; 
	    text +='<table width="100%" cellpadding="0" cellspacing="0">'; 
	    text += '<tr>'; 
		text += '<ul >';
		text += '<li style="margin:0 0 5px 0;">';
		text += '<strong>- Sedentary</strong> : bed-ridden / sitting most of the time / little or no exercise';
		text += '</li>';	
		text += '<li style="margin:0 0 5px 0;">';
		text += '<strong>- Light Activity</strong> : doing mostly desk jobs / less than 1 hour of exercise a day';	
		text += '</li>';	
		text += '<li style="margin:0 0 5px 0;">';	
		text += '<strong>- Moderate Activity</strong> : housework / shopping / 1 hour of exercise most days of the week';	
		text += '</li>';	
		text += '<li style="margin:0 0 5px 0;">';
		text += '<strong>- Very Active</strong> : jobs requiring constant moving all day / 2 hours of exercise most days of the week';
		text += '</li>';
		text += '<li style="margin:0 0 5px 0;">';
		text += '<strong>- Extremely Active</strong> : Athletes / Farmers/ Construction work /at least 2 hours of daily hard work';
		text += '</li>';
		text += '</ul>';
		text += '</td>';
		text += '</tr>';	
		text += '</table>';	
		text += '</td>';
		text += '</tr>';	
		text += '</table>';	
    	preview.innerHTML=text; 
	    preview.style.visibility='visible'; 
	}
    //A, B, C, unit (lbs : kg)
	function ibw_advice2(result_a, result_b, result_c, unit){ 
	    var text; 
	    text = 'You weigh  <span class="cFF0808">'+result_a+'</span>';
	    if(unit == "01"){
	    	text += ' lbs.'; 
	    }else{
	    	text += ' kg.'; 
	    }
	    text += ' above the upper limit of your healthy body weight range. ';
	    text += 'It is recommended that you start a healthy diet program to begin losing weight slowly and safely. '; 
	    text += 'You can start by trying to lose about 10% of your current weight, or <span class="cFF0808">'+result_b+'</span>';
	    if(unit == "01"){
	    	text += ' lbs.'; 
	    }else{
	    	text += ' kg.'; 
	    }
	    text +=' over <span class="cFF0808">'+result_c+'</span> months at the rate of '; 
	    if(unit == "01"){
	    	text += '~ 1 lb.'; 
	    }else{
	    	text += '~ 0.5 kg.'; 
	    }
		text += '</tr>';	
		text += 'per week for a slow and healthy weight loss.';	
		return text;
	}
    