﻿//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;
}

//Quiz functions

Quiz = function ()
{
	this.currentSection = 1;
}

Quiz.prototype = {

	showNextSection : function()
	{
		this.currentSection += 1;
		
		if (this.currentSection > 7)
		{
			var button = document.getElementById('yesButton');
			
			button.style.display = 'none';
			
			button = document.getElementById('noButton');
			
			button.style.display = 'none';
		}
		
		//Hide the previous section
		var el = document.getElementById('quizSection' + (this.currentSection - 1));
		
		el.style.display = 'none';
		
		//Show the next section
		el = document.getElementById('quizSection' + this.currentSection);
		
		el.style.display = '';
	}
}

//Tab functions

Tabs = function()
{
	//empty constructor
}

Tabs.setActiveTab = function(tab)
{
	//clear the current tabs
	
	var i;
	
	for (i = 1; i < 8; i++)
	{
		var el = document.getElementById('tab' + i);
		el.className = '';
	}
	
	//set the selected tab as active
	
	var el = document.getElementById('tab' + tab);
	el.className = 'active';
	
	//clear the current tab content
	
	for (i = 1; i < 8; i++)
	{
		var el = document.getElementById('tabContent' + i);
		el.style.display = 'none';
	}
	
	//set the active tab content
	
	var el = document.getElementById('tabContent' + tab);
	el.style.display = '';
	
	//Send tracking information to omniture
	
	if (tab > 1) //do not track if it's the first tab
	{
		s.pageName = 'lasik-safety_' + tab;
		s.t();
	}
}

//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.removeWatermark = function(el, text)
{
	if (el.value === text)
	{
		el.value = '';
	}
}

Utility.setWatermark = function(el, text)
{
	if (el.value === '')
	{
		el.value = text;
	}
}

Utility.toggleDetails = function(id)
{
	var el = document.getElementById('searchDetail' + id);
	
	if (el !== 'undefined')
	{
		if (el.style.display === 'none')
		{
			el.style.display = '';
		}
		
		else
		{
			el.style.display = 'none';
		}
	}	
}
Utility.getQuerystring = function (key, default_)
{
  if (default_==null) default_=""; 
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
} 