﻿// JScript File
// debugger

function GetOwnURL() {
    var scriptSrc = /(^|[\/\\])OnlineAdvertisment\/i\.js(\?|$)/;
    var scripts = document.getElementsByTagName("script");
    for (var i = 0; i < scripts.length; i++) {
        var src;
        if (src = scripts[i].getAttribute("src")) {
            if (src.match(scriptSrc)) {
                return src;
            }
        }
    }
}

function GetDocumentRootPath(url) {    
    var lastSlash = url.lastIndexOf("/");
    var root = url.substring(0, lastSlash);
    return root + "/";
}

var serverPath = GetDocumentRootPath(GetOwnURL());

var style = hy_width + ',' + hy_height; //+ hy_padding+ ',' + hy_border_style+ ',' + hy_border_width+ ',' +hy_border_color+ ',' + hy_background_color;
var hylnk=false;
var hy_GetString = "<script src='" + GetImpURL() + "' type='text/javascript'> </script>";
document.writeln(hy_GetString);

function GetImpURL()
{
	return serverPath + "Imp.ashx?AuthKey=" + AuthKey + "&Type=" + Type + "&Style=" + style + "&hylnk=" + getInBoundKey()
		              + "&Ref=" + escape(document.referrer) + "&clientSize=" + screen.width + "," + screen.height;
}

function getTextContents(element)
{
	if (element.innerText)
		return element.innerText;
	return element.textContent;
}

function validateHyLink(hylnk)
{
	return ('http://www.healthyes.com/' == hylnk.href) && ('Health Yes! Preventative Screening' == getTextContents(hylnk));
}

function getInBoundKey()
{
	var hyMain = document.getElementById("hyMain" + AuthKey);
	var hylnk = false;
	
	if (hyMain != null)
	{		
		for (var i = 0; i < hyMain.childNodes.length; i++)
		{
			if ("hylnk" + AuthKey == hyMain.childNodes[i].id)
			{
				hylnk = hyMain.getElementsByTagName("a")[0];				
				break;
			}
		}
	}

	var inbound = ((hylnk != null) && validateHyLink(hylnk));
	return inbound;
}
