function retrieveStatus() {
    var email = document.getElementById('email').value;
    var orderId = document.getElementById('orderid').value;
    var result = document.getElementById('result');

    xmlHttp = getXmlHttpObj();
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
		var message = xmlHttp.responseText;
		result.innerHTML = message;
		document.getElementById('showMessage').style.display='none';
        }
    }
    var url = "retrieve_status.php?email="+email+"&orderid="+orderId;
    xmlHttp.open("GET",url,true);
    document.getElementById('showMessage').style.display='block';
    xmlHttp.send(null);
}


function dollartoeuro(prodSize) {
    iddollar = document.getElementById('dollar');
    ideuro = document.getElementById('euro');
    document.getElementById('currency').value = 'euro';

    var savevals = new Array();
    var pricevals = new Array();
    //prodSize = 3;

    for (i = 1; i <= prodSize; i++) {
        var ele = eval('document.form1.save' + i);
        if (ele) {
            savevals[i] = ele.value;
            pricevals[i] = eval('document.form1.price' + i).value;
        }
    }

    iddollar.checked = false;

    xmlHttp = getXmlHttpObj();
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            document.getElementById('showMessage').style.display='none';
            var oneeurodollarrate = xmlHttp.responseText;
            onedollareuro = 1/oneeurodollarrate;

            for (i =1; i <= prodSize; i++) {
                if (savevals[i]) {
                    saveVal = eval(savevals[i]*onedollareuro).toFixed(2);
                    priveVal = eval(pricevals[i]*onedollareuro).toFixed(2);
    
                    savingDiv = eval('document.getElementById("saving'+i+'id")');
                    priceDiv = eval('document.getElementById("price'+i+'id")');
    
                    saveVal = custom_round(saveVal.toString());
                    priveVal = custom_round(priveVal.toString());
    
		    savingDiv.innerHTML = '&euro;'+ saveVal;
                    priceDiv.innerHTML = '&euro;'+ priveVal;
                }
            }
        }
    }
    xmlHttp.open("GET","http://www.vitopharma.com/exchange.php",true);
    document.getElementById('showMessage').style.display='block';
    xmlHttp.send(null);
}


function getCheckedValue(radioObj) {
    if(!radioObj)
        return "";
    var radioLength = radioObj.length;
    if(radioLength == undefined)
        if(radioObj.checked)
            return radioObj.value;
        else
            return "";
    for(var i = 0; i < radioLength; i++) {
        if(radioObj[i].checked) {
            return radioObj[i].value;
        }
    }
    return "";
}

function getCheckedIndex(radioObj) {
    if(!radioObj)
        return "";
    var radioLength = radioObj.length;
    if(radioLength == undefined)
        if(radioObj.checked)
            return radioObj.value;
        else
            return "";
    for(var i = 0; i < radioLength; i++) {
        if(radioObj[i].checked) {
            return i;
        }
    }
    return "";
}

function eurotodollar(prodSize) {
    ideuro = document.getElementById('euro');
    var savevals = new Array();
    var pricevals = new Array();

    document.getElementById('currency').value = 'dollar';


    ideuro.checked = false;

    for (i = 1; i <= prodSize; i++) {
        savingDiv = eval('document.getElementById("saving'+i+'id")');
        if (savingDiv) {
            priceDiv = eval('document.getElementById("price'+i+'id")');
    
	    savingDiv.innerHTML = "$" + eval('document.form1.save' + i).value;
            priceDiv.innerHTML = "$" + eval('document.form1.price' + i).value;
        }
    }

    xmlHttp = getXmlHttpObj();
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
		document.getElementById('showMessage').style.display='none';
        }
    }
    xmlHttp.open("GET","http://www.vitopharma.com/exchange.php?dollar",true);
    document.getElementById('showMessage').style.display='block';
    xmlHttp.send(null);
}


function callfn(id) {
    iddollar = document.getElementById('dollar');
    ideuro = document.getElementById('euro');
    document.getElementById("eurodisplay").innerHTML = ''
    dollarvalue = iddollar.value;
    eurovalue = ideuro.value;
    if (id.value == dollarvalue) {
        iddollar.checked = true;
        ideuro.checked = false;
    }
    if (id.value == eurovalue) {
        ideuro.checked = true;
        iddollar.checked = false;
    }
}

function getXmlHttpObj() {
    try {
        xmlHttp = new XMLHttpRequest();
    } catch (e) {
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                alert("Your browser does not support AJAX!");
                return false;
            }
        }
    }
    return xmlHttp;
}

function addItem() {
	document.form1.additem.value = getCheckedValue(document.form1.itemcheck);
	document.form1.submit();
	return false;
}

function custom_round(price) {
    var add, pad;
    var tmp = price.split('.');
    var dec = tmp[1];

    if (dec < 25) {
        add = 0.00;
        pad = ".00";
    } else if (dec < 75) {
        add = 0.50;
        pad = "0";
    } else {
        add = 1.00;
        pad = ".00";
    }
    result = parseFloat(tmp[0]) + parseFloat(add);;
    result += pad;
    return result;
}
function checkFree(qty) {
        var node = document.getElementById('freebottle');

        qty = parseInt(qty);
	document.getElementById('quantity').value = qty;
        if (qty == 6 ) {
                node.innerHTML = 'BONUS : 2 FREE Additional Bottles!!';
        } else if (qty>=7 && qty<13 ) {
                node.innerHTML = 'BONUS : 3 FREE Additional Bottles!!';
        } else {
                node.innerHTML = '&nbsp;';
        }
        return true;
}

function checkFreeNew(qty) {
        var node = document.getElementById('freebottle');

        qty = parseInt(qty);
        document.getElementById('quantity').value = qty;
        if (qty == 4 ) {
                node.innerHTML = 'BONUS : 1 FREE Additional Bottle!!';
        } else if (qty == 6 ) {
                node.innerHTML = 'BONUS : 1 FREE Additional Bottle!!';
        } else {
                node.innerHTML = '&nbsp;';
        }
        return true;
}

function highlightRow(row) {
	var childs = row.getElementsByTagName('td');
	//row.style.cursor='hand';
	for(i = 0; i < childs.length; i++) {
		//childs[i].setAttribute("class", "row_hover");
		childs[i].className = childs[i].className + " row_hover";
	}
}

function fadeRow(row, key) {
	
	var childs = row.getElementsByTagName('td');
	var check = eval('document.getElementById("check"+key)');
	//if (check.checked == false) {
		for(i = 0; i < childs.length; i++) {
			//childs[i].setAttribute("class", "row_normal");
			childs[i].className = childs[i].className.replace(/row_hover/, "row_normal");
		}
	//}
}


function checkThis(key,indx) {
	var checks = document.form1.itemcheck;
	var rows = document.getElementsByName('rows');
	checks[indx].checked = true;

	/*for (i = 0; i < rows.length; i++) {
		if (indx != i) {
			var childs = rows[i].getElementsByTagName('td');
			for(j = 0; j < childs.length; j++) {
				childs[j].setAttribute("class", "row_normal");
			}
		}
	}*/
	
	
	checkFree(key);
}
