// JavaScript Document

var redirectURL;
var redirectCMName;
var redirectCMId;
var _jsonArgs;
var popupWindows = [];
var intPopupWindows = 0;
var selectElementProfiles = Array();

	function f_filterResults(n_win, n_docel, n_body) {
		var n_result = n_win ? n_win : 0;
		if (n_docel && (!n_result || (n_result > n_docel)))
			n_result = n_docel;
		return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
	}

	function f_scrollTop() {
		return f_filterResults (
			window.pageYOffset ? window.pageYOffset : 0,
			document.documentElement ? document.documentElement.scrollTop : 0,
			document.body ? document.body.scrollTop : 0
		);
	}

	function showRedirectBox(s_redirectURL,s_redirectCMName,s_redirectCMId,jsonArgs){
	
	/*
		redirectURL
		redirectCMName	(ex: "Verizon -- Tabs" in JS line below)
		redirectCMId 	(ex: "Bizco" in JS line below)
		
		cmCreatePageviewTag("Panasonic Toughbook - Bizco - You are now leaving the panasonic.com web site", "Verizon -- Tabs");
		*/

		redirectURL = s_redirectURL;
		redirectCMName = s_redirectCMName;
		redirectCMId = s_redirectCMId;
		_jsonArgs = jsonArgs;

		var dark_screen = document.getElementById('dark_screen');
		var redirectBox = document.getElementById('redirectBox');

		if(!dark_screen||!redirectBox) return void(0);

		if(document.getElementById("main")) document.getElementById("main").style.zIndex = "0";
		if(document.getElementById("site")) document.getElementById("site").style.zIndex = "0";

		// IE 6 PNG WORKAROUND
		
		var ver = getInternetExplorerVersion();
		if(ver>=7||ver==-1){
			
			if(dark_screen.style.backgroundImage.indexOf('.png')==-1) dark_screen.style.backgroundImage = "url(images/dark_screen.png)";
			
		}else{
			
			// FOR IE6 and OLDER, WE HAVE TO HIDE WINDOWED CTLS (THAT'S CONTROLS. I GUESS IT MIGHT'VE MADE MORE SENSE TO HAVE JUST SPELLED IT OUT, BUT I WAS TOO LAZY TO. Now I'm just wasting Greg's time.)
			
			// FIND SELECT ELEMENTS
			var selectElements = document.getElementsByTagName('SELECT');
			
			for(var i=0;i<selectElements.length;i++){
				
				selectElementProfiles.push(new elementProfile(selectElements[i],selectElements[i].style.display));
				
				selectElements[i].style.display = 'none';
				
			}
			
			document.getElementsByTagName('body')[0].style.overflow = 'hidden';
			
		}
	
		dark_screen.style.display = "block";
		
		resizeDarkScreen();

		if(document.getElementById('btnContinue')) document.getElementById('btnContinue').focus();

		return void(0);
	}

	function hideRedirectBox(cancel){

		var dark_screen = document.getElementById('dark_screen');
		dark_screen.style.display = "none";
		dark_screen.style.width = "100px";
		dark_screen.style.height = "100px";

		if(document.getElementById("main")) document.getElementById("main").style.zIndex = "999";
		//document.body.style.overflow = "auto";
		
		
		// IE 6 AND OLDER: SET DISPLAY BACK TO ORIGINAL STATE
		
		var ver = getInternetExplorerVersion();
		if(ver<7&&ver!=-1){
			
			for(var i=0;i<selectElementProfiles.length;i++){
				
				selectElementProfiles[i].objElement.style.display = selectElementProfiles[i].display;
				
			}
			
			document.getElementsByTagName('body')[0].style.overflow = 'auto';
			
		}
		
		//

		// CLOSE WINDOW IF POPUP WINDOW
		if(cancel&&_jsonArgs&&_jsonArgs.target=='self'){
			window.close();
		}

	}
	
	function continueRedirect(){

		try{
			cmCreatePageviewTag(redirectCMName, redirectCMId);
		}catch(err){

		}

		//if(typeof(invokeCMConversionEvent)=='function') invokeCMConversionEvent(redirectURL);

		hideRedirectBox();
		
		var params = null;
		
		// SET DEFAULT WINDOW ID
		var windowId = 'popupWindow_' + intPopupWindows;
		intPopupWindows++;

		// USE ANY ADDITIONAL ARGUMENTS PASSED		
		if(_jsonArgs){
			params = ',toolbar=0,statusbar=0,location=0,scrollbars=1,resizable=1'
			if(_jsonArgs.id) windowId = _jsonArgs.id;
			if(_jsonArgs.width) params += ',width=' + _jsonArgs.width;
			if(_jsonArgs.height) params += ',height=' + _jsonArgs.height;
			
			params = params.substr(1);
		}

		if(_jsonArgs&&_jsonArgs.target=='self'){
			// RESIZE WINDOW
			if(_jsonArgs.resize_dimensions&&_jsonArgs.resize_dimensions.length==2){
				self.resizeTo(_jsonArgs.resize_dimensions[0],_jsonArgs.resize_dimensions[1]);
			}
			window.location = redirectURL;
		}else{
		popupWindows[windowId] = (params)?window.open(redirectURL,windowId,params):window.open(redirectURL,windowId);		
		}
	}
	

	function getInternetExplorerVersion()
	// Returns the version of Internet Explorer or a -1
	// (indicating the use of another browser).
	{
	  var rv = -1; // Return value assumes failure.
	  if (navigator.appName == 'Microsoft Internet Explorer')
	  {
	    var ua = navigator.userAgent;
	    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
	    if (re.exec(ua) != null)
	      rv = parseFloat( RegExp.$1 );
	  }
	  return rv;
	}
	

	function elementProfile(objElement,display){
		
		this.objElement = objElement;
		this.display = display;		
		
	}
	
	function resizeDarkScreen(){

		var darkScreen = document.getElementById('dark_screen');
		var redirectBox = document.getElementById('redirectBox');
		var body = document.getElementsByTagName("body")[0];
		
		if(!(darkScreen&&redirectBox)) return;
		if(darkScreen.style.display!='block') return;

		with (darkScreen) {

			var visibleHeight = getInnerDimensions()[1];
			var visibleWidth = getInnerDimensions()[0];

			style.position = 'fixed';		
			style.left = "0px";
			style.top = '-50px';
			
			var isIE = (getInternetExplorerVersion() > -1);
			
			if(offsetTop>0||isIE){
				style.position = 'absolute';
				
				if(document.documentElement.scrollTop==''){
					// IE 7
					style.left = (document.body.scrollLeft) + 'px';
					style.top = (document.body.scrollTop - 50) + 'px';
				}else{
					// IE 6
					style.left = (document.documentElement.scrollLeft) + 'px';
					style.top = (document.documentElement.scrollTop - 50) + 'px';
				}
				
			}
			
			style.width = (visibleWidth) + "px";
			style.height = (visibleHeight+100) + "px";
			
		}
	
		with (redirectBox){
			style.marginLeft = (((darkScreen.clientWidth - clientWidth) / 2) - 2) + "px"
			style.marginTop = (((darkScreen.clientHeight - clientHeight) / 2) - 2) + "px"
		}
	
	}


function getInnerDimensions(){
	var x,y;
	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	
	return [x,y];
}

window.onresize = resizeDarkScreen;
window.onscroll = resizeDarkScreen;

resizeDarkScreen();

