// Event.observe(window, 'load', slayerinit, false);

function togglebiomenue(subid){
        var win = window;
	var actel = document.getElementById(subid).style.display;
        var idToShow = document.getElementById(subid);
	if (actel == "none") {
                var countLi = idToShow.getElementsByTagName('li').length;
                newHeight = 24 * countLi ;
                oldHeight = 0;
                slideTime = countLi * 4 * 24;
                idToShow.style.display = "block";
				jQuery(idToShow).animate({opacity:1, height: newHeight + 'px'}, slideTime, function() {
                        document.getElementById('navlink-' + subid).style.backgroundImage = "url(/skin/frontend/default/biomaris_theme/images/meta/navigation/oben.png)";
                    }
                );
	} else {
                oldHeight = win.$_(idToShow).offsetHeight;
                newHeight = 0;
                slideTime = (oldHeight ) * 4 ;
                jQuery(idToShow).animate({opacity:1, height: newHeight + 'px'}, slideTime, function() {
                        document.getElementById(subid).style.display = "none";
                        document.getElementById('navlink-' + subid).style.backgroundImage = "url(/skin/frontend/default/biomaris_theme/images/meta/navigation/unten.png)";
                    }
                );
		//
	}	
}

function togglelayer(subid, top, left){
			
	        var actel = document.getElementById(subid).style.display;
	        if (actel == "none") {
	                document.getElementById(subid).style.display = "block";
					if (typeof(top) != "undefined") {
						document.getElementById(subid).style.left = left + "px";
						document.getElementById(subid).style.top = top + "px";
					}
	        } else {
	                document.getElementById(subid).style.display = "none";
	        }
	}

Varien.DOBExtented = Class.create();
Varien.DOBExtented.prototype = {
    initialize: function(selector, required, format) {
        var el        = $$(selector)[0];
        this.day      = Element.select($(el), '.dob-day input')[0];
        this.month    = Element.select($(el), '.dob-month input')[0];
        this.year     = Element.select($(el), '.dob-year input')[0];
        this.dob      = Element.select($(el), '.dob-full input')[0];
        this.advice   = Element.select($(el), '.validation-advice')[0];
        this.required = required;
        this.format   = format;

        this.day.validate = this.validate.bind(this);
        this.month.validate = this.validate.bind(this);
        this.year.validate = this.validate.bind(this);

        this.advice.hide();
    },

    validate: function() {
		
        var error = false;

        if (this.day.value=='' && this.month.value=='' && this.year.value=='' || (this.day.value=='TT' && this.month.value=='MM' && this.year.value=='JJJJ')) {
            if (this.required) {
                error = 'This date is a required value.';
            } else {
                this.day.value = '';
                this.month.value = '';
                this.year.value = '';
                this.dob.value = '';
            }
        } else if (this.day.value=='' || this.month.value=='' || this.year.value=='' || (this.day.value=='TT' && this.month.value=='MM' && this.year.value=='JJJJ')) {
            error = 'Please enter a valid full date.';
        } else {
            var date = new Date();
            if (!this.is_int(this.day.value) || this.day.value<1 || this.day.value>31) {
                error = 'Please enter a valid day (1-31).';
            } else if (!this.is_int(this.month.value) || this.month.value<1 || this.month.value>12) {
                error = 'Please enter a valid month (1-12).';
            } else if (!this.is_int(this.year.value) || this.year.value<1900 || this.year.value>date.getFullYear()) {
                error = 'Please enter a valid year (1900-'+date.getFullYear()+').';
            } else {
                this.dob.value = this.format.replace(/(%m|%b)/i, this.month.value).replace(/(%d|%e)/i, this.day.value).replace(/%y/i
, this.year.value);
                var testDOB = this.month.value + '/' + this.day.value + '/'+ this.year.value;
                var test = new Date(testDOB);
                if (isNaN(test)) {
                    error = 'Please enter a valid date.';
                }
            }
        }

        if (error !== false) {
            try {
                this.advice.innerHTML = Translator.translate(error);
            }
            catch (e) {
                this.advice.innerHTML = error;
            }
            this.advice.show();
            return false;
        }

        this.advice.hide();
        return true;
    },

    is_int: function(value) {
        if((parseFloat(value) == parseInt(value, 10)) && !isNaN(value)){
            return true;
        } else {
            return false;
        }
    }
}

Varien.DOBCheckout = Class.create();
Varien.DOBCheckout.prototype = {
    initialize: function() {
        
        this.day      = Element.select('birthdate','input')[0];
        this.month    = Element.select('birthdate', 'input')[1];
        this.year     = Element.select('birthdate', 'input')[2];
        this.dob      = Element.select('birthdate', 'input')[3];
        this.advice   = Element.select('loginBillingRight','.validation-advice')[0];
        
        this.format   = '%d.&m.%y';

        this.day.validate = this.validate.bind(this);
        this.month.validate = this.validate.bind(this);
        this.year.validate = this.validate.bind(this);
        this.advice.innerHTML = '';
        this.advice.hide();
        //alert(this.day.value + '/' + this.month.value + '/' + this.year.value);
    },

    validate: function() {
        var error = false;
        if (this.day.value=='' && this.month.value=='' && this.year.value=='' || (this.day.value=='TT' && this.month.value=='MM' && this.year.value=='JJJJ')) {
            this.advice.hide();
            return true;
        } else if (this.day.value=='' || this.month.value=='' || this.year.value=='' || (this.day.value=='TT' && this.month.value=='MM' && this.year.value=='JJJJ')) {
            error = 'Please enter a valid full date.';
        } else {
            var date = new Date();
            if (!this.is_int(this.day.value) || this.day.value<1 || this.day.value>31) {
                error = 'Please enter a valid day (1-31).';
            } else if (!this.is_int(this.month.value) || this.month.value<1 || this.month.value>12) {
                error = 'Please enter a valid month (1-12).';
            } else if (!this.is_int(this.year.value) || this.year.value<1900 || this.year.value>date.getFullYear()) {
                error = 'Please enter a valid year (1900-'+date.getFullYear()+').';
            } else {
                this.dob.value = this.format.replace(/(%m|%b)/i, this.month.value).replace(/(%d|%e)/i, this.day.value).replace(/%y/i, this.year.value);
                var testDOB = this.month.value + '/' + this.day.value + '/'+ this.year.value;
                var test = new Date(testDOB);
                if (isNaN(test)) {
                    error = 'Please enter a valid date.';
                }
            }
        }

        if (error !== false) {
            try {
                this.advice.innerHTML = Translator.translate(error);
            }
            catch (e) {
                this.advice.innerHTML = error;
            }
            this.advice.show();
            return false;
        }
        this.advice.hide();
        return true;
    },

    is_int: function(value) {
        if((parseFloat(value) == parseInt(value, 10)) && !isNaN(value)){
            return true;
        } else {
            return false;
        }
    }
}

var browser = navigator.appName
var ver = navigator.appVersion
var thestart = parseFloat(ver.indexOf("MSIE"))+1
var brow_ver = parseFloat(ver.substring(thestart+4,thestart+7))
var req_url = document.URL

if ((browser=="Microsoft Internet Explorer") && (brow_ver < 7) && (req_url.search("/home-static") == -1)  ) {
    window.location="http://www.biomaris.com/home-static";
} //else alert("url: " + req_url.search("/home-static") + " Browser: " +  browser + " ver: " + brow_ver);

