﻿$(document).ready(function(){
    pageNum = window.location.pathname.substring(window.location.pathname.lastIndexOf('/') + 1, window.location.pathname.indexOf('-'));
    if(pageNum.length == 4)
    {
        id = "img#nav" + pageNum;
        
        if ($(id).length != 0)
        {
            $(id).attr("src", $(id).attr("src").replace("Off","On"));
            $(id).removeAttr("onmouseover");
            $(id).removeAttr("onmouseout");
        }
        
        
        
        id = "a#nav" + pageNum;
        
        if ($(id).length != 0)
        {
            $(id).addClass("active");
        }
        
       
    }
    else
    {
    
    }
});
//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];
} 


function trackLink()
{
    if (arguments.length < 3)
    {
        alert("Error: Not enough arguments to TrackLink()");
        return;
    }

    var linkTest = arguments[0];

    var link;

    if (linkTest.href == undefined)
    {
        link = document.createElement('a');
        link.href = linkTest;
        document.body.appendChild(link);
    }

    else
    {
        link = linkTest;
    }

    var name = arguments[1];

    var linkType = arguments[2];

    var options;

    if (arguments.length > 3)
    {
        options = arguments[3];
    }

    var linkTrackVars = 'channel'; //override to always track the channel
    var linkTrackEvents = '';

    var suppressTracking = false;

    if (options != undefined)
    {
        if (options.prop != undefined)
        {
            if (linkTrackVars.length > 0)
            {
                linkTrackVars += ",";
            }

            linkTrackVars += options.prop;

            s[options.prop] = options.prop;
        }

        if (options.event != undefined)
        {
            if (linkTrackVars.length > 0)
            {
                linkTrackVars += ",";
            }

            linkTrackVars += "events";

            linkTrackEvents += options.event;

            s.events = options.event;
        }
        
        if (options.evars != undefined)
        {
            for(var i in options.evars)
            {
                var evar = options.evars[i];
                
                if (linkTrackVars.length > 0)
                {
                    linkTrackVars += ",";
                }
                
                linkTrackVars += evar.name;
                
                s[evar.name] = evar.value;
            }
        }

        if (options.supress != undefined)
        {
            suppressTracking = options.supress;
        }
    }

    s.linkTrackVars = linkTrackVars;
    s.linkTrackEvents = linkTrackEvents;

    if (!suppressTracking)
    {
        s.tl(link, linkType, name);
    }
}

function trackPage()
{
    if (arguments.length < 1)
    {
        alert("Error: Not enough arguments to trackPage()");
        return;
    }

    s.pageName = arguments[0];

    var options;
    
    if (arguments.length > 1)
    {
        options = arguments[1];
    }

    var linkTrackVars = 'channel'; //override to always track the channel
    var linkTrackEvents = '';

    var suppressTracking = false;

    if (options != undefined)
    {
        if (options.prop != undefined)
        {
            if (linkTrackVars.length > 0)
            {
                linkTrackVars += ",";
            }

            linkTrackVars += options.prop;

            s[options.prop] = options.prop;
        }

        if (options.event != undefined)
        {
            if (linkTrackVars.length > 0)
            {
                linkTrackVars += ",";
            }

            linkTrackVars += "events";

            linkTrackEvents += options.event;

            s.events = options.event;
        }
        
        if (options.evar != undefined)
        {
            if (linkTrackVars.length > 0)
            {
                linkTrackVars += ",";
            }
            
            linkTrackVars += options.evar.name;
            
            s[options.evar.name] = options.evar.value;
        }

        if (options.supress != undefined)
        {
            suppressTracking = options.supress;
        }
    }

    s.linkTrackVars = linkTrackVars;
    s.linkTrackEvents = linkTrackEvents;

    if (!suppressTracking)
    {
        s.t();
    }
}
