


/******************************************************************************
*	The main intent for this code is to hijack the Weather Channel
*	component's loading process so that we can redirect all links
*	and form submissions to a new browser window.
*
*	We use Behaviour and the CSS selector model to attach functionality
*	to elements created from the weather.com website dynamically
*
*	Sadly, we have to do some crazy reflection-style eval to create our
*	selector rules for Behaviour because the container tag ID is variable
*	and will change.....not good for associative arrays in javascript....
*******************************************************************************/






/*******************************************************/
/****** DYNAMICT HTML WRITING CODE FOR WC COMPONENT ****/
/******** ALSO ALLOWS FOR TESTING IN ALL WEBSITES ******/
/*******************************************************/


	var weatherChannelSourceLocationID = 'USFL0154';
	var weatherChannelSourceLocationName = 'Fort Myers/Southwest Florida Intl Arpt Weather Forecast, FL';
	var weatherChannelContainerName = '';
	var weatherChannelComponentConfig = '';
	var weatherChannelComponentRequest = '';
	var weatherChannelComponentHTML = '';
	
	var hn = document.location.hostname;
	switch(hn.substring(0, hn.indexOf('.'))){
		case 'swf-inhouse':
			weatherChannelContainerName = 'wx_module_2868';								
			weatherChannelComponentConfig = 'SZ=180x150*WX=FHW*LNK=SSNL*UNT=F*BGI=summer*MAP=CSC|null*DN='+hn+'*TIER=0*PID=1044603714*MD5=37d7a6fd9b091d58c650c015637e86ce';
			break;
		case 'swf-stage1':
			weatherChannelContainerName = 'wx_module_6215';
			weatherChannelComponentConfig = 'SZ=180x150*WX=FHW*LNK=SSNL*UNT=F*BGI=summer*MAP=CSC|null*DN='+hn+'*TIER=0*PID=1043610240*MD5=0d11cd32d9dd32bb6865d43fbb39b81f';
			break;
		case 'swf-stage2':
			weatherChannelContainerName = 'wx_module_396';
			weatherChannelComponentConfig = 'SZ=180x150*WX=FHW*LNK=SSNL*UNT=F*BGI=summer*MAP=CSC|null*DN='+hn+'*TIER=0*PID=1044603714*MD5=88ff0bf108ea437a9f9db24b1e4ebfbd';
			break;
		case 'swf':
			weatherChannelContainerName = 'wx_module_1906';
			weatherChannelComponentConfig = 'SZ=180x150*WX=FHW*LNK=SSNL*UNT=F*BGI=summer*MAP=CSC|null*DN='+hn+'*TIER=0*PID=1044603714*MD5=abb216858840e7c936703209de47d570';
			break;
		case 'southwestflorida':
			weatherChannelContainerName = 'wx_module_4223';
			weatherChannelComponentConfig = 'SZ=180x150*WX=FHW*LNK=SSNL*UNT=F*BGI=summer*MAP=CSC|null*DN='+hn+'*TIER=0*PID=1044603714*MD5=102a9523a7fcb7940732068ff0686ffb';
			break;
	}

	weatherChannelComponentHTML = '<div id="' + weatherChannelContainerName + '"><a href="http://www.weather.com/weather/local/';
	weatherChannelComponentHTML += weatherChannelSourceLocationID + '" target="_new">' + weatherChannelSourceLocationName + '</a></div>';
							
	weatherChannelComponentRequest = '<scr'+'ipt src="'+document.location.protocol+'//wow.weather.com/weather/wow/module/'+weatherChannelSourceLocationID;
	weatherChannelComponentRequest += '?config='+weatherChannelComponentConfig+'&proto='+document.location.protocol;
	weatherChannelComponentRequest += '&target='+weatherChannelContainerName+'"></scr'+'ipt>';

	document.write(weatherChannelComponentHTML);
	document.write(weatherChannelComponentRequest);					









/*******************************************************/
/********** BEHAVIOUR CODE FOR ATTACHING JSCRIPT *******/
/**********  TO HTML WITH SPECIAL FUNCTIONALITY	********/
/*******************************************************/
var bindingTimer = null;
var homeRules = "homeRules = {'";
homeRules += "#"+weatherChannelContainerName+"':";
homeRules += " function(container){";
homeRules += "		var anchors=container.getElementsByTagName('A');";
homeRules += "		for(var i=0;i<anchors.length;i++){anchors[i].target='_blank';}";
homeRules += "";
homeRules += "		var wcf = doSearch.toString();";
homeRules += "";
homeRules += "		var inputs=container.getElementsByTagName('INPUT');";
homeRules += "		for(var i=0;i<inputs.length;i++){";
homeRules += "			if(inputs[i].type == 'image'){";
homeRules += "				if(document.attachEvent){";
homeRules += "					wcf = wcf.substring(wcf.indexOf('http:'), wcf.indexOf('+wh;')-1);";
homeRules += "					var newButton = document.createElement('BUTTON');";
homeRules += "					inputs[i].parentNode.replaceChild(newButton, inputs[i]);";
homeRules += "					newButton.setAttribute('style', 'height:18px;width:26px;text-align:middle;');";
homeRules += "					newButton.setAttribute('value', 'GO');";
homeRules += "					newButton.attachEvent('onclick', doBetterSearch);";
homeRules += "				}else{";
homeRules += "					wcf = wcf.substring(wcf.indexOf('http:'), wcf.indexOf(' + wh;')-1);";
homeRules += "					inputs[i].setAttribute('type', 'button');";
homeRules += "					inputs[i].setAttribute('value', 'GO');";
homeRules += "					inputs[i].setAttribute('onclick', 'doBetterSearch();');";
homeRules += "				}";
homeRules += "			}";
homeRules += "		}";
homeRules += "		searchURL = wcf;";
homeRules += " }";
homeRules += "}";
homeRules = eval(homeRules);





if(document.readyState != null){
	if(document.readyState == 'interactive' || document.readyState == 'loaded'){
		window.setTimeout('Behaviour.register(homeRules);Behaviour.apply();', 2000);
	}
}else{
	Behaviour.register(homeRules);
}

	

/*******************************************************************
*****		WEATHER CHANNEL doSearch FUNCTION OVERRIDE
********************************************************************/

var searchURL = '';
function doBetterSearch(){
	var wh = document.getElementById('zipcode').value; 
	window.open(searchURL+wh);
	return false;
}
	
	
	

/*

function doSearch(){ 
	var wh = document.getElementById('zipcode').value; 
	window.location = "http://wowweb.weather.com/search/enhanced?what=Weather36HourBusinessTravelerCommand&config=SZ=180x150*WX=FHW*LNK=SSNL*UNT=F*BGI=summer*MAP=CSC|null*DN=swf-stage1.welcomeguide-map.com*TIER=0*PID=1043610240*MD5=0d11cd32d9dd32bb6865d43fbb39b81f&par=WOWs0_1043610240&site=180x150&cm_ven=WOWs0&cm_cat=180x150&code=link&promo=searchbox&cm_ite=link&cm_pla=searchbox&where="+wh; 
	return false;} 
	
function hrefURL (url){ window.location = url; }
*/
