/*===================================================================================================
Create: 	Minh Dao (IBM)
VA Team:	Web Solutions Services
Created on: 10/20/2011
Description:This script will detect all links on the page and generate disclaimer box on the page. 
			If the link does not have '.va.gov', it will call disclaimer box or xbox automatically.
====================================================================================================*/

	var timer;  		// Variable for timer
	var iSeconds = 30; 	// Number of seconds before redirecting 

	// exit box begin
	var isIE5 = false;	
	if ( $.browser.msie ) {
		if ($.browser.version < 6){isIE5 = true;}
	}
	
		var urlarray = new Array();
		var linkUrl;	
		jQuery(document).ready(function() {
		$("a").each(function() {
			var $a = jQuery(this);   
			if (!isIE5){
				if (this.href != null && !$a.is(".exempt")) {					
					if (getLinkType(this.href) != 1){	// Not .va.gov					
						$a.click(function() {
							$("#exitBoxDiv").modal({
													opacity:80,
													overlayCss: {backgroundColor:"#000"},											
													onOpen: function (dialog) {
														dialog.overlay.fadeIn('fast', function () {
															dialog.data.hide();
															dialog.container.fadeIn('fast', function () {
																dialog.data.slideDown('fast');
															});
														});
													},											
													onClose: function (dialog) {
														dialog.data.fadeOut('fast', function () {
															dialog.container.hide('fast', function () {
																dialog.overlay.slideUp('fast', function () {
																	$.modal.close();
																	linkUrl = null;
																});
															});
														});
													} // end onClose
											}); // end modal							
							
							linkUrl = this.href;
								
							var linkMsg;
							if (getLinkType(linkUrl)==2){	// gov
								linkMsg = '&nbsp;';
							}
							else if (getLinkType(linkUrl)==3){	// iris							
								linkMsg = 'This is a secure site contracted to VA. If you use bookmarks and favorites for these website urls, please make sure you update them when you get to the destination.';
							}
							else if (getLinkType(linkUrl)==4){	// non-gov 
								linkMsg = 'VA does not endorse and is not responsible for the content of the linked Web site.';
							}
							
							var linkMsg2;
							linkMsg2 = 'You can access <a href="'+ linkUrl +'" title="Link to external site">'+linkUrl+'</a>';
							linkMsg2 += ' or in 30 seconds you will be redirected to the external Web site.';
						
							// show message on disclaimer box
							document.getElementById('leaveMsg').innerHTML = linkMsg;																			
							document.getElementById('spanUrlInfo').innerHTML = linkMsg2;																			
							timer = setTimeout("AutoRedirect()", iSeconds*1000); 
							// disable link
							return false;						
						});
					}		            
				}
			} // not IE5
		});		
}); // jQuery(document)

function getLinkType(url)
{
	if (url.toLowerCase().indexOf('.va.gov') != -1)
		return 1; // va 
	else if (url.toLowerCase().indexOf('.gov') != -1)
		return 2; // gov  
	else if (url.toLowerCase().indexOf('https://iris.custhelp.com') != -1)
		return 3; // iris 
	else
		return 4;	// non gov
}

function AutoRedirect(){   
	if (linkUrl != null)
		location.href = linkUrl;
}	

// initiate disclaimer box or xbox
var xboxStr = '';
xboxStr += '<div id="exitBoxDiv" style="padding:1.5em; text-align:left; font-family:Arial; font-size:12px; display:none; background-color:#FFFFFF; width:550px; height:220px; border:5px solid #FF9900;">';
xboxStr += '	<br><b>You are now leaving the Department of Veterans Affairs Web site.</b>';
xboxStr += '	<br><br><div id="leaveMsg"></div><br><br>';
xboxStr += '		<div style="padding:0.5em; background:#EEEEEE; border-top:1px solid #666666; border-bottom:1px solid #666666;">';
xboxStr += '			<span id="spanUrlInfo"></span>';																					
xboxStr += '		</div>';
xboxStr += '	<br><br><br><br><b>We hope your visit was informative.</b>';						
xboxStr += '</div>';
document.write(xboxStr);
// end exit box




