
//***************************************
// FOR JW FLV PLAYER
	// some variables to save
	var currentPosition;
	var currentVolume;
	var currentItem;
	var swfObjsLoaded = false;
	var tmrPrototype;

	// these functions are caught by the JavascriptView object of the player.
	function sendEvent(typ,prm) { thisMovie("mpl").sendEvent(typ,prm); };
	function getUpdate(typ,pr1,pr2,pid) {

	if(typ == "time") { currentPosition = pr1; }
		var id = document.getElementById(typ);
		id.innerHTML = typ+ ": "+Math.round(pr1);
	};

	function thisMovie(movieName) {
		if(navigator.appName.indexOf("Microsoft") != -1) {
			return window[movieName];
		} else {
			return document[movieName];
		}
	};

//***************************************

	var playaId = "";

	function writeVideoObject(id, pic, flv, width, height){
		playaId = id;
		var file = flv;
		var basePath = '/business/toughbook/';
		if(flv.startsWith('./video/')) file = basePath + flv.substring(2);
		if(flv.startsWith('video/')) file = basePath + flv;

		with(new SWFObject('./flvplayer/flvplayer.swf?preventCache=' + (new Date().valueOf()),id,width,height,'7')){
			addVariable('file',file);
			addVariable('image',pic);
			addVariable("javascriptid","_" + id);
			addVariable('height',height);
			addVariable('width',width);
			addVariable('displaywidth',width);
			addVariable('displayheight',height);
			addVariable('showvolume','true');
			//addVariable('enablejs','true'); //ENABLING THIS SEEMS TO CAUSE PROBLEMS IN IE
			addVariable('useaudio','false');
			addVariable('usecaptions','false');
			addVariable('usekeys','false');
			addVariable('autostart','true');
			addVariable("overstretch","fit");
			addParam('allowscriptaccess','always');
			addParam('allowfullscreen','true');
			addParam('wmode','transparent');

			addVariable('usefullscreen','false');
			addVariable('showdigits','false');

			//$(id).style.background= 'none';
			write(id);
		}

		// INVOKE COREMETRICS
		if(typeof(invokeCMConversionEvent)=='function') invokeCMConversionEvent(flv);
	}

	function addVideo(evt){
		var id, pic, flv, width, height;
		var srcElt = (window.event)?window.event.srcElement:Event.element(evt);
		id = srcElt.parentNode.id;
		pic = srcElt.getAttribute('img');
		flv = srcElt.getAttribute('url');
		width = srcElt.getAttribute('vidwidth');
		height = srcElt.getAttribute('vidheight');
		writeVideoObject(id, pic, flv, width, height);
	}

	function addVideos(){
		if(swfObjsLoaded) return;
		var intVideos = 0;
		var videoDivs = $$('.swfObj');
		videoDivs.each(
			function (item){
				intVideos++;
				var url = item.getAttribute('url');
				var img = item.getAttribute('img');
				var _width = item.getAttribute('vidwidth');
				var _height = item.getAttribute('vidheight');

				if(item.id=='') item.id = 'swfObj' + intVideos;

				item.style.background= 'url(/business/toughbook/img/video-loading-bg.gif) center no-repeat';
				item.innerHTML = '';

				//ADDED TO SUPPORT WRITING STATIC IMG WHEN FLASH V7 or GREATER ISN"T INSTALLED
				if (FlashDetect.versionAtLeast(8) == true){
					// CREATE PREVIEW IMAGE
					var imgPreview = document.createElement('img');
					imgPreview.setAttribute('src',img);
					imgPreview.setAttribute('width',_width);
					imgPreview.setAttribute('height',_height);
					imgPreview.setAttribute('id','swfObjImg'+intVideos);
					item.appendChild(imgPreview);
					//imgPreview = $('swfObjImg'+intVideos);
					imgPreview.style.width = _width + 'px';
					imgPreview.style.height = _height + 'px';
					imgPreview.style.cursor = 'pointer';
					imgPreview.setAttribute('img',img);
					imgPreview.setAttribute('url',url);
					imgPreview.setAttribute('vidwidth',_width);
					imgPreview.setAttribute('vidheight',_height);
					imgPreview.onclick = addVideo;
				} else {
					// CREATE MESSAGE IMAGE FOR USER TO DOWNLOAD FLASH
					var ancPreview = document.createElement('a');
					ancPreview.setAttribute('href','http://www.adobe.com/products/flashplayer/');
					ancPreview.setAttribute('target','_blank');
					//ancPreview.setAttribute('href','javascript:showRedirectBox(\'http://reviews.cnet.com/laptops/panasonic-toughbook-cf-52/4505-3121_7-32476019.html?ar=o\',null,\'getFlash\')');

					item.appendChild(ancPreview);
					var imgPreview = document.createElement('img');
					imgPreview.setAttribute('src','/business/toughbook/img/vid-no-flash-player.gif');
					imgPreview.setAttribute('width','220');
					imgPreview.setAttribute('height','164');
					imgPreview.style.border = 'solid 1px black';
					ancPreview.appendChild(imgPreview);
				};
			}
		);
	}

	function addFlashBanners(){
		var intBanners = 0;
		var bannerDivs = $$('.swfBanner');
		bannerDivs.each(
			function (item){
				intBanners++;

				if (FlashDetect.versionAtLeast(8) == true){
					var url = item.getAttribute('url');
					var width = item.getAttribute('bnrwidth');
					var height = item.getAttribute('bnrheight');
					if(item.id=='') item.id = 'swfBanner' + intBanners;
					var wmode = "";
					if (item.getAttribute('wmode')){
							wmode = item.getAttribute('wmode');
					} else {
						wmode='transparent';
					};
					writeFlashObject(item,url,width,height,wmode);
				} else {
					// CREATE MESSAGE IMAGE FOR USER TO DOWNLOAD FLASH
					var divPreview = document.createElement('div');
					divPreview.setAttribute('width',item.getAttribute('bnrwidth'));
					divPreview.setAttribute('height',item.getAttribute('bnrheight'));
					divPreview.style.border = 'solid 1px black';
					divPreview.style.backgroundColor = 'white';
					item.appendChild(divPreview);
					var ancPreview = document.createElement('a');
					ancPreview.setAttribute('href','http://www.adobe.com/products/flashplayer/');
					divPreview.appendChild(ancPreview);
					var imgPreview = document.createElement('img');
					if (parseFloat(item.getAttribute('bnrwidth')) < 151){
						imgPreview.setAttribute('src','/business/toughbook/img/vid-no-flash-player-rhp.gif');
						imgPreview.setAttribute('width','150');
						imgPreview.setAttribute('height','90');
						var topBottomMargin = (item.getAttribute('bnrheight') - 90) / 2
						imgPreview.style.marginTop = topBottomMargin;
						imgPreview.style.marginBottom = topBottomMargin;
					} else {
						imgPreview.setAttribute('src','/business/toughbook/img/vid-no-flash-player.gif');
						imgPreview.setAttribute('width','220');
						imgPreview.setAttribute('height','164');
						imgPreview.style.marginLeft = (item.getAttribute('bnrwidth') / 2) - 102;
						imgPreview.style.marginTop = item.getAttribute('bnrheight') / 2;
					}
					ancPreview.appendChild(imgPreview);
					//item.style.border = "solid 1px black";
				}
			}
		);
	}



function writeFlashObject(srcElement,url,width,height,wmode){
	var div = srcElement.parentNode;
	if(typeof(srcElement)=='string') srcElement = $(srcElement);
	var ret = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\""+width+"\" height=\""+height+"\"><param name=\"movie\" value=\""+url+"\"><param name=\"quality\" value=\"high\"><param name=\"wmode\" value=\""+wmode+"\"><embed src=\""+url+"\" width=\""+width+"\" height=\""+height+"\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" wmode=\""+wmode+"\" type=\"application/x-shockwave-flash\"></embed></object>";
	srcElement.innerHTML = ret;
}


// NEW PRODUCTS SECTION FUNCTIONS

function writeProductVideo(elt, id, pic, flv, width, height, vidDownloadPath, vidDownloadTypeAndSize){
	var download_link = $('vidSubLinks');

	writeVideoObject(id, pic, flv, width, height);

	$$(".vidInList").each(function(elmt){elmt.removeClassName('vidSelected');});
	Element.up(elt,'div').addClassName('vidSelected');

	// KICK OUT COREMETRICS PAGEVIEWS
	if(typeof toughbook_model=='string'){
		var pageId, categoryId
		categoryId = 'Toughbook Products Sub'; //cmCategoryId
		pageId = 'Toughbook Videos '+toughbook_model;
		var video_title_span = Element.down(elt,'span.vidListName');
		var video_title;
		if(video_title_span){
			video_title = (video_title_span.textContent||video_title_span.innerText);
			if(video_title.indexOf('[')>-1) video_title = video_title.substr(0,video_title.indexOf('[')).strip();
			if(pageId&&categoryId) cmCreatePageviewTag(cm_sanitize(pageId + ' ' + video_title),categoryId);
		}
	}

	if (vidDownloadPath == '' || vidDownloadTypeAndSize == ''){
		if(download_link) download_link.style.display = 'none';
	} else {
		if(download_link) download_link.style.display = 'block';
		if ($('vidDownloadLinkHref')) $('vidDownloadLinkHref').href = vidDownloadPath;
		if ($('vidDownloadLinkSize')) $('vidDownloadLinkSize').innerHTML = vidDownloadTypeAndSize;
	}
}

function writeProductVideoYoutube(elt,video_elt,url,width,height){
	writeFlashObject(video_elt,url,width,height,'opaque');
	var download_link = $('vidSubLinks');
	if(download_link) download_link.style.display = 'none';

	$$(".vidInList").each(function(elmt){elmt.removeClassName('vidSelected');});
	Element.up(elt,'div').addClassName('vidSelected');

}
function cm_sanitize(value){
	value = value.replaceAll('/',' ');
	value = value.replaceAll('-','');
	value = value.replaceAll(',',' ');
	value = value.replaceAll('  ',' ');
	value = value.replaceAll('\\(',' ');
	value = value.replaceAll('\\)',' ');
	value = value.replaceAll('  ',' ');
	return value;
}

Event.observe(window,'load',function(){
	addVideos();
	addFlashBanners();

	// FOR ANY PAGE WITH A FILTER DROPDOWN, PERFORM RE-FILTER
	filter();
},false);

document.observe('dom:loaded',function(){
	unfocusLinks();

	// CLEAR SOLUTION FLOATING
	var solutions = $$('.solution');
	if(solutions){
		solutions.each(function(solution){
			var div = new Element('div');
			div.style.clear = 'both';
			div.style.height = div.style.width = '0px';
			solution.appendChild(div);
		});
	}
},false);


var last_sol;
function filter(){ //NOT SURE IF THIS FUNCTION IS USED ANY MORE IN LIEU OF filterSelection() in expandCollapse.js
	if(!$('dd')) return;
	var sol = $('dd').value;
	if(sol==last_sol){
		return;
	}else{
		last_sol = sol;
	}
	var solutions = $$(".solution");
	var closers = $$(".closer")
	var first_index = -1;
	var num_shown = 0;
	var first_sol;
	solutions.each(function(solution,index){
		solution.removeClassName('first');
		solution.style.display = 'block';
		if(sol=='all'){
		    //var h2Sol = solution.down('h2');
		    //if(h2Sol){if(!h2Sol.hasClassName('catHeader')) alert(h2Sol.innerHTML); h2Sol.addClassName('catHeader');}

			if(first_index==-1){
				first_index = 0;
				first_sol = solution;
				closers.each(function(item){item.style.display = 'block';})
				first_sol.style.borderTop='none';
			} else {
				solution.style.borderTop='solid 1px';
			}
			num_shown++;
		}else if(solution.hasClassName(sol)){
			if(first_index==-1){
				first_index = index;
				first_sol = solution;
				closers.each(function(item){item.style.display = 'block';})
				//first_sol.removeClassName('catHeader');
				first_sol.style.borderTop='none';
			} else {
				solution.style.borderTop='solid 1px';
			}
			num_shown++;
		}else{
			solution.style.display = 'none';
		}
	});
	//if (num_shown > 1) {
		//alert(first_index);
		if(solutions[first_index]) solutions[first_index].addClassName('firstly');
	//}

	var collapse_buttons = $$('.collapseBtn');
	collapse_buttons.each(
		function(item){
			item.style.display = (num_shown<=1)?'none':'block';
		}
	);

	if(first_sol){
		var collapse_btn = first_sol.down('.collapseBtn');
		var collapse = first_sol.down('.collapse');
		if(typeof toggleElement == 'function') if(collapse){toggleElement(collapse.getAttribute('id'),collapse_btn.getAttribute('btn_index'))};
	}

	if(num_shown>1) {
		if(typeof collapseAllElements == 'function') collapseAllElements(-1);
	}
}

function getInnerText(elt) {
	return (elt.textContent||elt.innerText);
}

function filterVids() {
	var sol = $('dd').value;
	var vids = $$(".vidInList");
	vids.each(function(vid){
		if(sol=='all'){
			vid.style.display = 'block';
		} else if(vid.hasClassName(sol)){
			vid.style.display = 'block';
		} else {
			vid.style.display = 'none';
		}
	});
}

function subcontentShow(whatToShow, whichAnchor){

	$$(".visib").each(function(elmt){
		elmt.removeClassName('visib');
	});
	$(whatToShow).addClassName('visib');

	$$('a.activ').each(function(elt){
		elt.removeClassName('activ');
	});
	Element.addClassName(whichAnchor,'activ');

	if ($('subContentFAQs')) hideFaqsDiv();

	// KICK OUT COREMETRICS PAGEVIEWS
	var pageId, categoryId;
	categoryId = 'Toughbook Products Sub'; //cmCategoryId
	if(typeof toughbook_model=='string'){
		switch(whatToShow){
			case 'subContentProductImages':
				pageId = 'Toughbook Prod Img '+toughbook_model;
			break;
			case 'subContentApplicationImages':
				pageId = 'Toughbook App Img '+toughbook_model;
			break;
			case 'subContentNewsReviews':
				pageId = 'Toughbook News Reviews '+toughbook_model;
			break;
			case 'subContentReviews':
				pageId = 'Toughbook Reviews '+toughbook_model;
			break;
			case 'subContentNews':
				pageId = 'Toughbook News '+toughbook_model;
			break;
			case 'subContentSpec':
				pageId = 'Toughbook Specs '+toughbook_model;
			break;
			case 'subContentIntel':
				pageId = 'Toughbook Intel '+toughbook_model;
			break;
			case 'subContentGobi':
				pageId = 'Toughbook Gobi '+toughbook_model;
			break;
			case 'subContentROI':
				pageId = 'Toughbook ROI '+toughbook_model;
			break;
			case 'subContentAwards':
				pageId = 'Toughbook Awards '+toughbook_model;
			break;
		}
		if(pageId&&categoryId) cmCreatePageviewTag(cm_sanitize(pageId),categoryId);
	}
}

function showFaqsDiv(){
	var elemental = $('subContentFAQs');
	if (elemental){
		elemental.style.position = 'relative';
		elemental.style.visibility = 'visible';
	}
};

function hideFaqsDiv(){
	var elemental = $('subContentFAQs');
	if (elemental){
		elemental.style.position = 'absolute';
		elemental.style.visibility = 'hidden';
	}
};

// Make all doc links target new windows
function unfocusLinks(){
	for(var i=0;i<document.links.length;i++){
		var lnk = document.links[i];
		lnk.onfocus = function(){this.blur();};
	}
}


/**
*
*  Javascript trim, ltrim, rtrim
*  http://www.webtoolkit.info/
*
**/


function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


/**
*
*  FROM http://www.quirksmode.org/js/cookies.html
*
**/

function createCookie(name,value,minutes) {
	if (minutes) {
		var date = new Date();
		date.setTime(date.getTime()+(minutes*60*1000)); //when was days was (days*24*60*60*1000)
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1000);
}


Event.observe(window,'load',function(){
	// /* SOLUTIONS */ HIDE HORIZONTAL RULE UNDER LAST ARTICLE
	var selector = '.articleBlock hr.clearboth';
	var filter_section = window.details.queryString()['filter_section'];
	if(filter_section) selector = '.articleBlock.'+filter_section+' hr.clearboth';
	var HRs = $$(selector);
	if(HRs.length) HRs[HRs.length-1].style.visibility = 'hidden';

	// HIDE HORIZONTAL RULE UNDER LAST ARTICLE - PRODUCT SECTIONS
	if(typeof _filter_section=='string'&&_filter_section){
		$$('.subContent').each(function(div){
			var HRs = div.select('.articleBlock.'+_filter_section+' hr.clearboth');
			if(HRs.length) HRs[HRs.length-1].style.visibility = 'hidden';
		});
	}

	// RHC NEW PRODUCTS PROMO
	var rhp_featured_products = $('rhp_featured_products');
	if(rhp_featured_products){
		if (sRightNavVersion=='WirelessSprintHome') {

			//rhp_featured_products.update('<a href="/business/toughbook/sprint-broadband-offers.asp" tpg_cm_sp="Toughbook Site Promotions-_-Right Hand Promo-_-Sprint Special Offers Promo"><img src="/business/toughbook/img/rc-feature-sprint.gif" alt=""/></a>')

			writeFlashObject(rhp_featured_products,'/business/toughbook/flash/rc-feature-Sprint.swf','150','95','transparent');

		/*
		} else if ((sRightNavVersion=='WirelessVerizon')||(sRightNavVersion=='WirelessVerizonHome')) {
			rhp_featured_products.update('<a href="/business/toughbook//verizon-wireless-laptop-offers.asp"><img src="./img/rc-feature-verizon.gif" alt=""/></a>')
		*/

		} else {

			/* //JPL CONCISE CODE FOR USE WHEN ONLY 2 CASES ARE NEEDED, FOR MORE, USE THE BELOW MORE VERBOSE SCRIPT
			var path = '/business/toughbook/flash/'+((sRightNavVersion=='Federal')?'rc-feature-fed.swf':'rc-feature-main.swf');
			writeFlashObject(rhp_featured_products,path,'150','95','transparent');
			*/


			var path;
			if (sRightNavVersion=='Federal'){
				path = '/business/toughbook/flash/rc-feature-fed_30.swf';
			} else if ((sRightNavVersion!='SupportUnauthenticated') && (sRightNavVersion.substr(0,7) == 'Support')){
				path = '/business/toughbook/flash/rc-feature-support.swf';
			} else {
				path = '/business/toughbook/flash/rc-feature-main.swf';
			}
			writeFlashObject(rhp_featured_products,path,'150','95','transparent');
		}
		// MONITOR ANY NEW LINKS CREATED BY THIS FEATURED PROMO BLOCK
		monitorCMLinks();
	}
});

function SprintPromo() {
window.open('http://digital.virtualmarketingpartners.com/vmp/panasonic/PCSC-sprint/index.php?cm_sp=Toughbook Site Promotions-_-Right Hand Promo-_-Flash RHP Promo Sprint Brochure','0','resizable=1,scrollbars=0,width=800,height=700')
}


function invokeClickManageConversionEvent(event_id){

/*
	Example:
	    Description: Wireless Contact
	    Tag Format : <img width='1' height='1' style='visibility:hidden' src='[ Protocol (http|https) ]://www.clickmanage.com/events/conversionevent.aspx?ca=10623&ci=12284&cv=[ Optional conversion value ]'>
	    Known URLs :
*/
	var img = new Image();
	img.src = window.location.protocol + '//www.clickmanage.com/events/conversionevent.aspx?ca=10623&ci=' + event_id;
	img.style.visibility = 'hidden';
	img.style.position = 'absolute';
	document.body.appendChild(img);

	if(event_id=='12288'){
		// INVOKE CONVERSION EVENT TAG
		cmCreateManualLinkClickTag(window.location.href+((window.location.href.indexOf('?')>-1)?'&':'?')+'cm_sp=Toughbook%20Site%20Promotions-_-Right%20Hand%20Promo-_-Pre-Sales%20Live%20Chat');
	}


	//alert('ClickManage ' + event_id);
}