﻿function mousePageX(e) {
	var x = 0;
	if (!e) e = window.event;
	if (e.pageX) {
		x = e.pageX;
	}
	else if (e.clientX) {
		x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
	}
	return x;
}

function mousePageY(e) {
	var y = 0;
	if (!e) e = window.event;
	if (e.pageY) {
		y = e.pageY;
	}
	else if (e.clientY) {
		y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
	}
	return y;
}

function showTerms(link) 
{
    
    if(typeof(link) == "undefined")
    {
	    hs.htmlExpand(document.getElementById('hrefAgree'), { objectType: 'iframe', width: '500', height: '535' });
	}
	else
    {
    	//var constLink = "/abbott_web/heb/link_popup_terms.aspx";
    	var constLink = "link_popup_terms.aspx";
        document.getElementById('hrefAgree').setAttribute('href', constLink + "?link="+link);
        hs.htmlExpand(document.getElementById('hrefAgree'), { objectType: 'iframe', width: '500', height: '400' });
    }
}
var val = true;

function CheckLink() {
	if (!val) {
		showTerms();
	}
	return val;
}

function showPopUpPassword(el) {
	hs.htmlExpand(el, { objectType: 'iframe', width: '500', height: '270' });
}

function CheckForDisabled(el) {
	if (el.options[el.selectedIndex].disabled) {
		alert('This field is disabled.');
		el.selectedIndex = 0;
	}
}

function OnMenuOver(el) {
    try
    {
	    if (el.className == "") el.className = "MenuOver";
	    if (el.nextSibling.className.indexOf("MenuSeparator") != -1) el.nextSibling.className = "MenuOver";
	    if (el.previousSibling.className.indexOf("MenuSeparator") != -1) el.previousSibling.className = "MenuOver";
	}
	catch(Error)
	{}	
}

function OnMenuOut(el) {
try
    {
	    if (el.className == "MenuOver") el.className = "";
	    if (el.nextSibling.className.indexOf("MenuOver") != -1) el.nextSibling.className = "MenuSeparator";
	    if (el.previousSibling.className.indexOf("MenuOver") != -1) el.previousSibling.className = "MenuSeparator";
	}
	catch (Error)
	{}
}

function onPopUpShow() {
    document.getElementById('divPopUp').className = 'hiddenDivVisible';
    document.getElementById('ddlCategory').className = 'DropDownList2';
    document.getElementById('ddlProduct').className = 'DropDownList2';
}

function movePopUp(event) {
	if (!event) event = window.event;
	//document.getElementById('divPopUp').style.left = event.clientX-590 + 'px';
	//document.getElementById('divPopUp').style.top = event.clientY + 'px';
	document.getElementById('divPopUp').style.left = mousePageX(event) - 720 + 'px';
	document.getElementById('divPopUp').style.top = mousePageY(event) + 'px';
	window.status = document.getElementById('divPopUp').style.left + "|" + document.getElementById('divPopUp').style.top;
}
function onPopUpHide() {
    document.getElementById('divPopUp').className = 'hiddenDiv';
    document.getElementById('ddlCategory').className = 'DropDownList';
    document.getElementById('ddlProduct').className = 'DropDownList';
}

function calculateBMI() {
	var result = 0, weight = 0, height = 0, output = '', result = 0;
	
	objWeight = document.getElementById('txtWeight');
	objHeight = document.getElementById('txtHeight');
	objOutput = document.getElementById('calculatorOutput');
	objResult = document.getElementById('calculatorResult');
	
	weight = parseFloat(objWeight.value);
	height = parseFloat(objHeight.value);

	if (!isNaN(weight) && !isNaN(height)) {
		result = (weight / Math.pow(height, 2)).toFixed(2);
		objResult.innerHTML = ': BMI = ' + result;

		if (result < 18.5) {
			output = 'תת משקל';
		}
		else if (result >= 18.5 && result < 25) {
			output = 'משקל תקין';
		}
		else if (result >= 25 && result < 30) {
			output = 'עודף משקל';
		}
		else if (result >= 30 && result < 40) {
			output = 'השמנה';
		}
		else {
			output = 'השמנה קיצונית';
		}
		objOutput.innerHTML = output;
	}
	else {
		objResult.innerHTML = '';
		objOutput.innerHTML = '';
	}

	return false;
}

function calcMust() {
    var objBMI, objWeight, objdisease, result;
    var objWeight3,objBMI2;
    var chk=0;
    var i;
    objBMI2 = document.getElementById('BMI');
    if (objBMI2.value.length < 1) {
        alert('שלב 1 לא בוצע');
        return;
    }
    if (objBMI2.value > 20)
        objBMI = 0;
    else if (objBMI2.value <= 20 && objBMI2.value >= 18.5)
        objBMI = 1;
    else if (objBMI2.value < 18.5)
        objBMI = 2;
    objWeight3 = document.getElementsByName('weight');
    
    for (i = 0; i < objWeight3.length; i++) {
        //alert(objWeight3[i].checked);
        if (objWeight3[i].checked)
        {
            objWeight = objWeight3[i].value;
            chk=1;
        }
    }   
    if (chk==0)
    {
        alert('שלב 2 לא בוצע');  
        return;
    }
    chk = 0;
    objWeight3 = document.getElementsByName('disease');
    for (i = 0; i < objWeight3.length; i++) {
        if (objWeight3[i].checked)
        {
            objdisease = objWeight3[i].value;
            chk=1;
        }
    }   
    if (chk==0)
    {
        alert('שלב 3 לא בוצע');  
        return;
    }
    objBMI = parseInt(objBMI);
    objWeight = parseInt(objWeight);
    objdisease = parseInt(objdisease);
    result = parseInt(objBMI + objWeight + objdisease);
    if (result == 0) {
        document.getElementById('result2').style.display = 'none';
        document.getElementById('result22').style.display = 'none';
        document.getElementById('result3').style.display = 'none';
        document.getElementById('result33').style.display = 'none';
        document.getElementById('bapen').style.display = 'none';
        document.getElementById('result1').style.display = 'block';
        document.getElementById('result11').style.display = 'block';
    }
    else if (result == 1) {
        document.getElementById('result1').style.display = 'none';
        document.getElementById('result11').style.display = 'none';
        document.getElementById('result3').style.display = 'none';
        document.getElementById('result33').style.display = 'none';
        document.getElementById('bapen').style.display = 'none';
        document.getElementById('result2').style.display = 'block';
        document.getElementById('result22').style.display = 'block';
    }
    else if (result >= 2) {
        document.getElementById('result1').style.display = 'none';
        document.getElementById('result11').style.display = 'none';
        document.getElementById('result2').style.display = 'none';
        document.getElementById('result22').style.display = 'none';
        document.getElementById('bapen').style.display = 'none';
        document.getElementById('result3').style.display = 'block';
        document.getElementById('result33').style.display = 'block';
    }
}
function calculateBMR(sex) {
	var result = 0, weight = 0, height = 0, age = 0, factor = 1, output = '', result = 0;

	objWeight = document.getElementById('txtWeight' + sex);
	objHeight = document.getElementById('txtHeight' + sex);
	objAge = document.getElementById('ddlAge' + sex);
	objFactor = document.getElementById('ddlFactor' + sex);
	objOutput = document.getElementById('calculatorOutput' + sex);

	weight = parseFloat(objWeight.value);
	height = parseFloat(objHeight.value);
	age = parseFloat(objAge.value);
	factor = parseFloat(objFactor.value);

	if (!isNaN(weight) && !isNaN(height) && age > 0) {
		if (sex == 'M')	{
			result = (66.47 + 13.75 * weight + 5 * height - 6.75 * age) * factor;
			
		}
		else {
			result = (655.09 + 9.56 * weight + 1.85 * height - 4.67 * age) * factor;
		}

		output = result.toFixed(0) + ' קלוריות ליום';
		
		objOutput.innerHTML = output;
	}
	else {
		objOutput.innerHTML = '';
	}
	
	return false;
}


function check(field) {
	if ((window.event.keyCode >= 48 && window.event.keyCode <= 57) || (window.event.keyCode == 46)) {
		if (window.event.keyCode != 46) {
			return true;
		}
		else {
			if (field.value.search(/\./) == -1 && field.value.length > 0)
				return true;
			else
				return false;
		}
	}
	else {
		return false;
	}
}

function openPrintWindow(mode, id, ref) 
{
	var features, w = 500, h = 500;
	var top = (screen.height - h) / 2, left = (screen.width - w) / 2;
	if (top < 0) top = 0;
	if (left < 0) left = 0;
	//toolbar=no,location=no,directories=no,status=no,scrollbar=yes,resizable=yes, width=" + w + ",heigth=" + h + "
	newWindow = window.open("Print.aspx?ref=" + ref + "&mode=" + mode + "&id=" + id, "printWin");
}


function openCustomerPrintWindow(mode, id, ref) {
    var features, w = 500, h = 500;
    var top = (screen.height - h) / 2, left = (screen.width - w) / 2;
    if (top < 0) top = 0;
    if (left < 0) left = 0;
    //toolbar=no,location=no,directories=no,status=no,scrollbar=yes,resizable=yes, width=" + w + ",heigth=" + h + "
    newWindow = window.open("../Print.aspx?ref=" + ref + "&mode=" + mode + "&id=" + id, "printWin");
}


function ClickFAQ(prmThis) {

    if (prmThis.nextSibling.style!=undefined && prmThis.nextSibling.style.display == "none") {
        if (document.selectedMenu) {
            document.selectedMenu.className = "menuRightLong";
            document.selectedMenu.nextSibling.style.display = "none";
        }

        prmThis.className = "menuRightLongSelect";
        if (prmThis.nextSibling.style!=undefined && prmThis.nextSibling.style.display != undefined) {

            prmThis.nextSibling.style.display = "";
        }
        document.selectedMenu = this;
    }
    else {
        this.className = "menuRightLong";
        if (prmThis.nextSibling != undefined && prmThis.nextSibling.style!=undefined) {
            prmThis.nextSibling.style.display = "none";
        }
    };
}

function funcshowfaq(id) {
    document.getElementById('open_' + id).style.display = 'block';
    document.getElementById('close_' + id).style.display = 'none';
    //document.getElementById('details_' + id).style.display = 'block';
    $('#details_' + id).slideDown('slow');
}
function funchidefaq(id) {
    document.getElementById('open_' + id).style.display = 'none';
    document.getElementById('close_' + id).style.display = 'block';
    //document.getElementById('details_' + id).style.display = 'none';
    $('#details_' + id).slideUp('slow');
}
