/*
** Sitewide Functions
** Last Edited: 9.9.2010
*/

/* Document Ready */
$j(document).ready(function(){
	layerMaker_info.init(); 
	initUtilitiesArea();	  
});

/*
** Configurable Directives
*/
var scripts = new Array('layerMaker_info','textSizer_info','builder','utilities_info','effects');

/*
** Script Auto-loader, takes array of filenames
*/
var pathToRoot;
function dynLoadScript(scriptArr) {
    // Find the relative path to our javascript includes
    handler = document.getElementsByTagName("head")[0].getElementsByTagName("script");
    for (var x = 0; x < handler.length; x++) {
        if (handler[x].getAttribute("src")!=undefined && handler[x].getAttribute("src").match(/functions_info.js/)) {
            scriptPrefix = handler[x].getAttribute("src").replace(/functions_info.js/, "");
            pathToRoot = scriptPrefix.replace(/javascript/, "").replace(/\/\//, "/");
            if (pathToRoot == "/") {
                pathToRoot = "";
            }
        }
    }
    var a = new Array();
    for (var x = 0; x < scriptArr.length; x++) {
        // safari fails on dynamic loading, brute force
        document.write('<script type="text/javascript" src="' + scriptPrefix + scriptArr[x] + '.js"></script>');
    }
    return false;
}
dynLoadScript(scripts);


function initUtilitiesArea() {
    if (document.getElementById('site-tools')) {
        $j('a.email').click(function() { layerMaker_info.activate('Email This Page', this); return false; });
		$j('a.rheumatology').click(function() { layerMaker_info.activate('Find a Rheumatologist', this); return false;  });
        $j('a.print').click(function() { printThisPage(); return false; });
        $j('a.increase-text-size').click(function() { textSizer_info('incr', '.dm-textcontent'); return false; });
        $j('a.reduce-text-size').click(function() { textSizer_info('decr', '.dm-textcontent'); return false; });
    }	
	
	$j('a.sound-sjogrens').click(function(){
		$j('embed').remove();
		$j('body').append('<embed src="/audio/VO_002.mp3" autostart="true" hidden="true" loop="false">');
		return false;
	});
	
	$j('a.sound-evoxac').click(function(){
		$j('embed').remove();
		$j('body').append('<embed src="/audio/VO_001.wav" autostart="true" hidden="true" loop="false">');
		return false;
	});
	
	
    return false;
}


/*
** universal print function
*/
function printThisPage() {
 // WebTrends Track page emailed - 01-05-2010 - SP - START BLOCK
 dcsMultiTrack("WT.pi", "Print This Page", "WT.z_print", "1");
 // WebTrends Track page emailed - 01-05-2010 - SP - END BLOCK
 window.open("/info/utilities/print_template.html", "mywindow","location=0,status=0,scrollbars=1, width=655,height=800");
 return false;
} 


function printDiscussionGuide() {
	$j('input').each(function(i,e){
		var inputVal = $j(this).val();
		var inputId = $j(this).attr("id");
		if (inputId.indexOf(inputVal)) {
			$j(this).attr("alt",$j(this).val());
		}
		else
			$j(this).attr("alt","");
		
	});	
	
	$j('#textquestions').attr("alt", $j('#questions').val());
		        
	window.open("/info/printable-discussion-guide.html", "discussionwindow","location=0,status=0,scrollbars=1, width=900,height=800");
 return false;
}

/*
** Basic site-wide and site-specific functionality

function initSite() {
    // Loading external file functions first
    initUtilitiesArea();
    validateForm.prep();
    layerMaker_info.init();
    //didYouKnow.init();
    initExpander();
    initRedirLink();
    setTimeout("", 2000);
    if (getCookie('sentThisPage') == "yes") {
        layerMaker_info.activate('Email This Page Confirmation', '');
        document.cookie = "sentThisPage=no";
    }
    if (getCookie('isHCP') == "yes") {
        layerSets['HCP Disclaimer']['isActive'] == false;
    }
}*/

function initRedirLink() {
    if (document.getElementById('dykGoBack')) {
        url = getCookie('dykOrigUrl');
        document.getElementById('dykGoBack').href = url;
        document.getElementById('dykGoBack').onclick = "";
    }
}


function hcpDisclaimerConfirmed() {
    document.cookie = "isHCP=yes";
}

function initHCPDisclaimer() {
    sandbox = document.getElementsByTagName("a");
    for (var x = 0; x < sandbox.length; x++) {
        if (sandbox[x].href.match(/hcp/) && !window.location.href.match(/hcp/)) {
            sandbox[x].onclick = function() { layerMaker_info.activate('HCP Disclaimer', this); return false; };
        }
    }
    return false;
}

function submitEmailThisPage() {
    document.getElementById('emailThisPageSuccess').value = window.location.href;
    if (validateForm.initEmail(document.forms[document.forms.length - 1])) {
        // WebTrends Track page emailed - SAP 12-22-2009 -  START BLOCK
        dcsMultiTrack("WT.pi", "Email This Page Sent", "WT.z_email", "1");
        // WebTrends Track page emailed - SAP 12-22-2009 -  END BLOCK
        document.forms[document.forms.length - 1].submit();
		/*layerMaker_info.deactivate();*/
		$j("#emailThisPageLayer").hide();
		layerMaker_info.activate('Email Confirmation', this);
		return false;
    } else {
        return false;
    }
}


function addFriendInput() {
    // Find relative path depth to determine location of images folder
    pathDepth = 0;
    hcpSide = false;
    var strHref = window.location.href;
    var handler = strHref.split('/');
    for (var i = 0; i < handler.length; i++) {
        if (handler[i] == "info") {
            pathDepth = 1;
        }
        if (handler[i] == "about_evoxac" || handler[i] == "managing_hypertension" || handler[i] == "patient_resources" || handler[i] == "utilities_info" || handler[i] == "professional_resources") {
            pathDepth = 2;
        }
        if (handler[i] == "hcp") {
            hcpSide = true;
        }
    }
    if (hcpSide == true) {
        pathDepth++;
    }

    // Determine how many friend inputs currently exist
    counter = 1;
    for (var x = 0; x < counter; x++) {
        if (document.getElementById('recipient' + counter)) {
            counter++;
        }
    }

    // If friend inputs number less than our limit AND first friend email is not blank, construct new input field
    if (counter <= 5) {
        if (counter == 5) {
            document.getElementById('addMoreFriendLink').style.display = "none";
        }
        document.getElementById('recipient1').innerHTML = "* Recipient's e-mail address 1";
        myDiv = document.getElementById('extraEmailInputs');

        var objFormListArea = document.createElement("div");
        myDiv.appendChild(objFormListArea);

        var objInputLabel = document.createElement("span");
        objInputLabel.setAttribute('id', 'recipient' + counter);
        objInputLabel.innerHTML = "&nbsp;&nbsp;Recipient's e-mail address " + counter;
        objFormListArea.appendChild(objInputLabel);

        var objInputArea = document.createElement("input");
        objInputArea.setAttribute('type', 'test');
        objInputArea.setAttribute('id', 'toAddress' + counter);
        objInputArea.setAttribute('name', 'toAddress');
        objFormListArea.appendChild(objInputArea);

        document.getElementById("extraEmailInputs").style.display = "block";
        var clearBothDiv = document.createElement("div");
        clearBothDiv.style.clear = "both";
        myDiv.appendChild(clearBothDiv);
    }
}

function initYearHelper() {
    if (document.getElementById('yearHelperInfo')) {
        workingObj = document.getElementById('yearHelperInfo');
        workingObj.href = "javascript:void(0);";
        workingObj.onclick = function() { layerMaker_info.activate('Why year of birth tooltip', this) };
    }
    return false;
}

function initLeaveSite() {
 //  sandbox = document.getElementsByTagName("a");
 	sandbox = $j("a").not(".rheumatology").toArray();
    for (var x = 0; x < sandbox.length; x++) {
        currentLinkIsExt = 0;
        currentHref = sandbox[x].href;
        if (currentHref.match(/http:\/\//) || currentHref.match(/https:\/\//)) {
            if (leavingSiteExcludeSites) {
                for (var i = 0; i < leavingSiteExcludeSites.length; i++) {
                    if (currentHref.search(leavingSiteExcludeSites[i]) > -1) {
                        currentLinkIsExt += 1;
                    }
                }
            }
            if (currentHref.match("\\b" + currentUrl.domainName() + "\\b")) {
                currentLinkIsExt += 1;
            }
            if (currentLinkIsExt == 0) {
                sandbox[x].onclick = function() { layerMaker_info.activate('Leaving the Site', this); return false; };
            }
        }
    }
    return false;
}
initLeaveSite();
function initLeaveToDSI() {
    sandbox = document.getElementsByTagName("a");
    for (var x = 0; x < sandbox.length; x++) {
        if (sandbox[x].href.match(/sankyopharma.com/) || sandbox[x].href.match(/www.dsi.com/)) {
            sandbox[x].onclick = function() { layerMaker_info.activate('External DSI Disclaimer', this); return false; };
        }
    }
    return false;
}
/*
function initLeaveToRheumatologist() {
    sandbox = document.getElementsByTagName("a");
    for (var x = 0; x < sandbox.length; x++) {
        if (sandbox[x].href.match(/www.rheumatology.org/)) {
            sandbox[x].onclick = function() { layerMaker_info.activate('Find a Rheumatologist', this); return false; };
        }
    }
    return false;
}
*/
/*// Mozilla and Opera
if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", initSite, false);
} else {
    if (window.onload) {
        oldOnloader = window.onload;
        window.onload = function() { oldOnloader(); window.onload; return false; };
    } else {
        window.onload = function() { initSite(); return false; };
    }
}*/




