﻿//Image rollover
//image filenames must be in the format 'filename.ext' and 'filename-on.ext'

Rollover = function()
{
	//empty constructor	
}

//Static function turns on the rollover image
Rollover.turnOn = function(element)
{
	var img = element;
	
	//Get the filename portion minus the extension
	var filename = img.src.substr(0, img.src.lastIndexOf('.'));
	
	//Get the extension portion
	var extension = img.src.substr(img.src.length - 4, 4);
	
	//insert '-on' between the filename and extension and set it as the new src
	img.src = filename + '-on' + extension;
}
	
//Static function turns off the rollover image
Rollover.turnOff = function(element)
{
	var img = element;
	
	//Get the filename portion minus the extension, also removed the '-on'
	var filename = img.src.substr(0, img.src.lastIndexOf('.') - 3);
	
	//Get the extension portion
	var extension = img.src.substr(img.src.length - 4, 4);
	
	//Set the combined name as the new img src
	img.src = filename + extension;
}

//Static function to change the image, use when image filenames can not be in the "-on" format
Rollover.setImage = function(element, href)
{
	var img = element;
	
	img.src = href;
}

//Utility Functions

Utility = function()
{
	//empty constructor
}

Utility.showCalculator = function()
{
	var amount = document.getElementById('txtAmount').value;
	
	if (amount)
	{
		var popup = window.open('http://www.carecredit.com/payment_calculator/template.html?amount=' + amount + '&ss=http://www.ilasik.com/common/calc-template.css', 'calcPopup', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=550,height=550');
	}
	
	else
	{
		alert('Error: No amount entered');
	}
}

Utility.submitOnEnter = function(e, btn)
{
    if (!e)
        var e = window.event;
    
    var key = e.keyCode || e.which;
    
    if (key == 13) //enter key pressed
    {
        Utility.showCalculator();
         
        //Prevent form from submitting
        if (e.preventDefault)
            e.preventDefault();
            
        e.returnValue = false;
    }
}

Utility.getRadioValue = function(radio)
{
    var value = -1;

    for (var i = 0; i < radio.length; i++)
    {
        if (radio[i].checked)
        {
            value = radio[i].value;
        }
    }
    
    return value;
}

Utility.onEstimate = function()
{
    var age = document.getElementById('age').value;
    var contactType = Utility.getRadioValue(document.forms['estimate'].elements['contact-type']);

    if (age == -1 || contactType == -1)
    {
        return;
    }

    var url = "http://www.ilasik.com/ilasik-vs-contacts.aspx?age=" + age + "&contact=" + contactType;

    window.open(url, "estimate");
}