var zipsearch = false;//this is for checking if local rearch was already clicked 
function MyLocation() {
  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)("whatwherezip").className = 'whatwhereZipClass';
	if(!zipsearch){
	  _proxy_jslib_assign('', document.whatwhere.where, 'value', '=', ( ''));
	 zipsearch = true;
  	} 
}

function MyLocationClose(dn) {
	 _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(dn+"zip").className = 'whatwhereZipClassHidden';
}


//Recent Search Example
//USGA0028:1:Atlanta, GA^12345:4:Schenectady,NY(12345)

//MyPrefs Example
//12345^4^Schenectady,+NY+(12345)^|*|*|*
var getMyPrefs = GetCookie("MyPrefs");
var getRecentLocations = getUserPreferences("27");

//Remove invalid elements, if you have an invalid zip, you will have element like 12000:*:*
var splitUpSearches = getRecentLocations.split("^");
for (var i=0;i<splitUpSearches.length;i++){
	var search =  _proxy_jslib_handle(splitUpSearches, (i), 0, 0).split(":");
	if ( _proxy_jslib_handle(null, 'search', search, 0, 0)[1]=="*" &&  _proxy_jslib_handle(null, 'search', search, 0, 0)[2]=="*")
	{
		//remove that element so we can update the userpreferences cookie finally
		splitUpSearches.splice(i,1);			
	}
				
}
if (splitUpSearches.length>0){
	splitUpSearches=splitUpSearches.join("^");
	setUserPreferences('27',splitUpSearches);
}else{
	setUserPreferences('27','');
}
getRecentLocations = getUserPreferences("27");

var getMyCityFromPrefs = "";
var getMyWatchListFromPrefs = "";
var watchListName = "";
var myWatchlist ="";
var myCity="";
var hasMyCity = false;
var hasMyWatchlist = false;
var hasRecentSearches = false;


if(getRecentLocations.length > 1){
hasRecentSearches = true;
var splitUpRecent = getRecentLocations.split("^");
}

if(getMyPrefs.length > 1){
hasMyCity =  true;
getMyCityFromPrefs = getMyPrefs.split("|").splice(0,1);
myCity = unEscJava(getMyCityFromPrefs[0]);
getMyWatchListFromPrefs = getMyPrefs.split("|").splice(3,4);
myWatchlist = unEscJava(getMyWatchListFromPrefs[0]);
}



//Watchlist Example
//12345:USFL0481:*:*:*:testing+this+thing:busch+gardens:*:*:*:Schenectady,+NY(12345):Tampa,+FL:*:*:*
if(myWatchlist != '' && myWatchlist != '*'){
	watchListCk = myWatchlist.split(":");
	hasMyWatchlist = true;		
}


function remove_recent_items(rsv,mcv,mwv) {
//rsv = Recent Search Value; mcv = My City Value; mwv = My Watchlist Value
counter = 10;
	if(hasMyCity){
	//Begin mycity information	
	var myCityItem = mcv.split("^");
	var myCityId = myCityItem[0];	
	var myCityPresName = myCityItem[2];	
	 if (myCityPresName.indexOf(":")!=-1){
	 	hasMyCity=false;
	 	hasMyWatchlist=false;
	 	
	 }
	}


	if(hasRecentSearches && hasMyCity && !hasMyWatchlist){ 
		//This is the recent search check
		
		for (var i=0;i<rsv.length;i++){
				 var rsItem =  _proxy_jslib_handle(rsv, (i), 0, 0).split(":");
				 var rsId = rsItem[0];
				 if(rsId == myCityId){
				 rsv.splice(i,1);
				 }
			}
			if(rsv.length >= 5){
			//remove the last one
			rsv.splice(5,1);
			}
	}
	
	if(hasRecentSearches && hasMyWatchlist){
	var mwItem = mwv.split(":");
	wListCounter = 0;
	tempValue = "";
	//This is the watchlist check
	 for (var m=0;m<5;m++){
	  if( _proxy_jslib_handle(mwItem, (m), 0, 0) != '*'){
		 watchListPresName =  _proxy_jslib_handle(mwItem, (m+counter), 0, 0);
		  if(typeof(watchListPresName)!='undefined' && watchListPresName != '*'){wListCounter++;}
		 }
	}//end watchlist loop
	
	//This is the recent search check
	
	for (var j=0;j<rsv.length;j++){
	var rsItem =  _proxy_jslib_handle(rsv, (j), 0, 0).split(":");
	//compare rsv with mycity
	 var rsId = rsItem[0];
	  	 if(rsId == myCityId){
		    rsv.splice(j,1);
		 }
	 }
	 
	//compare watchlist  with rsv
	for (var j=0;j<rsv.length;j++){
	var rsItem =  _proxy_jslib_handle(rsv, (j), 0, 0).split(":");	
	var rsPresName = rsItem[2];
		for (var k=0;k<5;k++){
			if( _proxy_jslib_handle(mwItem, (k), 0, 0) != '*'){
				watchListPresName =  _proxy_jslib_handle(mwItem, (k+counter), 0, 0);
				
				if((typeof(watchListPresName)!='undefined' &&  _proxy_jslib_handle(watchListPresName, 'replace', '', 1, 0)("--",",") == rsPresName) || 
				(typeof( _proxy_jslib_handle(mwItem, (k), 0, 0))!='undefined' &&  _proxy_jslib_handle(mwItem, (k), 0, 0) == rsItem[0])){ //city check is for international
					rsv.splice(j,1); 
				}				
			}
		tempValue = watchListPresName;
		}//end watchlist loop
	}//end recent search loop
	
	
	
		//Let's check the sizes on both objects to ensure it will display correctly
	//	if(rsv.length >= 5 && wListCounter == 1){
	//	rsv.splice(4,2);
	//	}else if(rsv.length >= 5 && wListCounter == 2){
	//	rsv.splice(3,3);
		//}else if(rsv.length >= 5 && wListCounter == 3){
		//rsv.splice(2,4);
		//}else if(rsv.length >= 5 && wListCounter == 4){
		//rsv.splice(1,5);
		//}else if(rsv.length >= 5 && wListCounter == 5){
		//rsv.splice(0,6);
		//}
	
	}//ending the if
}//ends remove_items function

remove_recent_items(splitUpRecent,myCity,myWatchlist);
//alert(hasRecentSearches + "," + hasMyCity + ","  + hasMyWatchlist);
if(hasRecentSearches && !hasMyCity && !hasMyWatchlist){

//This user only has Recent Searches....
 _proxy_jslib_handle(document, 'write', '', 1, 0)('<DIV class="yui-ac-hd" id="recentSearches" style="display:block;">Recent Searches<!--<SPAN style="padding: 0px 0px 0px 50px;"><IMG src="http://i.imwx.com/web/common/icons/sm_close_box.gif" border="0" onMouseDown="MyLocationClose(\'whatwhere\')"></SPAN>--></DIV>');
 _proxy_jslib_handle(document, 'write', '', 1, 0)('<div class="yui-ac-bd"><ul class="link" style="padding:0px;margin-top:0px;margin-left:4px;*margin-left:4px;">');
	for (var i=0;i<splitUpRecent.length;i++){
	var splitEachSearch =  _proxy_jslib_handle(splitUpRecent, (i), 0, 0).split(":");
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('<li style="list-style:none;"><a href ="http://www.weather.com/weather/local/'+splitEachSearch[0]+'" onmousedown="setClick();" onMouseUp="this.href=intelliTrak({\'href\':this.href,\'from\':\'recentsearch\'});" class="linkVerdanaText10">');
	var presentationName = splitEachSearch[2];
	if(presentationName.length > 28) {
	        presentationName = presentationName.substring(0,25);
	        presentationName += "...";
	    }

	 _proxy_jslib_handle(document, 'write', '', 1, 0)(presentationName);
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('</a></li>');
	//THIS <BR> only needs to be done on the last item
	//document.write('<BR>');
	}
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('</ul></div>');
}else if (hasRecentSearches && hasMyCity && !hasMyWatchlist){
//This user has Recent Searches and My City....
if (splitUpRecent.length > 0){
 _proxy_jslib_handle(document, 'write', '', 1, 0)('<DIV class="yui-ac-hd" id="recentSearches" style="display:block;">Recent Searches<!--<SPAN style="padding: 0px 0px 0px 50px;"><IMG src="http://i.imwx.com/web/common/icons/sm_close_box.gif" border="0" onMouseDown="MyLocationClose(\'whatwhere\')"></SPAN>--></DIV>');
 _proxy_jslib_handle(document, 'write', '', 1, 0)('<div class="yui-ac-bd"><ul class="link" style="padding:0px;list-style:none;margin-top:0px;margin-left:4px;*margin-left:4px;">');
	for (var i=0;i<splitUpRecent.length ;i++){
	var splitEachSearch =  _proxy_jslib_handle(splitUpRecent, (i), 0, 0).split(":");
	var presentationName = splitEachSearch[2];
	
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('<li style="list-style:none;"><a href ="http://www.weather.com/weather/local/'+splitEachSearch[0]+'" onmousedown="setClick();" onMouseUp="this.href=intelliTrak({\'href\':this.href,\'from\':\'recentsearch\'});" class="linkVerdanaText10">');
	if(presentationName.length > 28) {
	        presentationName = presentationName.substring(0,25);
	        presentationName += "...";
	}

	 _proxy_jslib_handle(document, 'write', '', 1, 0)(presentationName);
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('</a></li>');
	//THIS <BR> only needs to be done on the last item
	//document.write('<BR>');
	
	}
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('</ul></div>');
	}
	//Begin mycity information
	var splitCityInfo = myCity.split("^");
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('<DIV class="myFavorites">My Favorites</DIV>');
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('<TABLE border="0" cellpadding="0" cellspacing="0"><TR><TD>');
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('<a href ="http://www.weather.com/weather/local/'+splitCityInfo[0]+'" onmousedown="setClick();" onMouseUp="this.href=intelliTrak({\'href\':this.href,\'from\':\'recentsearch\'});" class="linkVerdanaText10">');
	var presentationName =  _proxy_jslib_handle(splitCityInfo[2], 'replace', '', 1, 0)("--",",");
	if(presentationName.length > 28) {
	        presentationName = presentationName.substring(0,25);
	        presentationName += "...";
	    }
	 _proxy_jslib_handle(document, 'write', '', 1, 0)(presentationName);
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('</a>');
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('</TD></TR></TABLE>');
	
}else if (!hasRecentSearches && hasMyCity && hasMyWatchlist){
//This user has My City and My Watchlist....
	var splitCityInfo = myCity.split("^");
		
	//Begin mycity information
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('<DIV class="myFavorites">My Favorites<SPAN style="padding: 0px 0px 0px 43px;"><IMG src="http://i.imwx.com/web/common/icons/sm_close_box.gif" border="0" onMouseDown="MyLocationClose(\'whatwhere\')"></SPAN></DIV>');
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('<TABLE border="0" cellpadding="0" cellspacing="0"><TR><TD>');
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('<a href ="http://www.weather.com/weather/local/'+splitCityInfo[0]+'" onmousedown="setClick();" onMouseUp="this.href=intelliTrak({\'href\':this.href,\'from\':\'recentsearch\'});" class="linkVerdanaText10">');
	var presentationName =  _proxy_jslib_handle(splitCityInfo[2], 'replace', '', 1, 0)("--",",");

	if(presentationName.length > 28) {
	        presentationName = presentationName.substring(0,25);
	        presentationName += "...";
	    }
	 _proxy_jslib_handle(document, 'write', '', 1, 0)(presentationName);
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('</a>');
	
	//Begin the watchlist information
	var splitWatchlistInfo = myWatchlist.split(":");
	counter = 10;
	for (var i=0;i<5;i++){
		if( _proxy_jslib_handle(splitWatchlistInfo, (i), 0, 0) != splitCityInfo[0] &&  _proxy_jslib_handle(splitWatchlistInfo, (i), 0, 0) != '*' && typeof( _proxy_jslib_handle(splitWatchlistInfo, (i), 0, 0))!='undefined' &&  typeof( _proxy_jslib_handle(splitWatchlistInfo, (i+counter), 0, 0))!='undefined'){
		 _proxy_jslib_handle(document, 'write', '', 1, 0)('<BR><a href ="http://www.weather.com/weather/local/'+ _proxy_jslib_handle(splitWatchlistInfo, (i), 0, 0)+'" onmousedown="setClick();" onMouseUp="this.href=intelliTrak({\'href\':this.href,\'from\':\'recentsearch\'});" class="linkVerdanaText10">');
		watchListName =  _proxy_jslib_handle( _proxy_jslib_handle(splitWatchlistInfo, (i+counter), 0, 0), 'replace', '', 1, 0)("--",",");
		if(watchListName != '' && watchListName.length > 23) {
	        watchListName = watchListName.substring(0,20);
	        watchListName += "...";
	    }
	 _proxy_jslib_handle(document, 'write', '', 1, 0)(watchListName);
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('</a>');
		}
	}
	
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('</TD></TR></TABLE>');
	
	
}else if(hasRecentSearches && hasMyCity && hasMyWatchlist){
//This user has Recent Searches, My City and My Watchlist...
var splitCityInfo = myCity.split("^");
	var watchList=myWatchlist.split(":");
		var myCounter=0;
		for (var i=0;i<5;i++){
			if( _proxy_jslib_handle(watchList, (i), 0, 0) != '*' &&  _proxy_jslib_handle(watchList, (i), 0, 0)!='' && typeof( _proxy_jslib_handle(watchList, (i), 0, 0))!='undefined' &&  _proxy_jslib_handle(watchList, (i), 0, 0)!=splitCityInfo[0]){
			 myCounter ++;	
			}
		}
		//add 1 to myCounter for mycity
		myCounter ++;
	
	
	if(splitUpRecent.length > 0 && myCounter < 6){
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('<DIV class="yui-ac-hd" id="recentSearches" style="display:block;">Recent Searches<!--<SPAN style="padding: 0px 0px 0px 50px;"><IMG src="http://i.imwx.com/web/common/icons/sm_close_box.gif" border="0" onMouseDown="MyLocationClose(\'whatwhere\')"></SPAN>--></DIV>');
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('<div class="yui-ac-bd"><ul class="link" style="padding:0px;list-style:none;margin-top:0px;margin-left:4px;">');
		var cntr = 6 - myCounter;
		
		for (var i=0;i< cntr && typeof( _proxy_jslib_handle(splitUpRecent, (i), 0, 0))!='undefined';i++){
		var splitEachSearch =  _proxy_jslib_handle(splitUpRecent, (i), 0, 0).split(":");
		var presentationName =  _proxy_jslib_handle(splitEachSearch[2], 'replace', '', 1, 0)("--",",");
		 _proxy_jslib_handle(document, 'write', '', 1, 0)('<li style="list-style:none;"><a href ="http://www.weather.com/weather/local/'+splitEachSearch[0]+'" onmousedown="setClick();" onMouseUp="this.href=intelliTrak({\'href\':this.href,\'from\':\'recentsearch\'});" class="linkVerdanaText10">');
		if(presentationName.length > 28) {
		        presentationName = presentationName.substring(0,25);
		        presentationName += "...";
		    }
	
		 _proxy_jslib_handle(document, 'write', '', 1, 0)(presentationName);
		 _proxy_jslib_handle(document, 'write', '', 1, 0)('</a></li>');
		//THIS <BR> only needs to be done on the last item
		//document.write('<BR>');
		
		}
		
		 _proxy_jslib_handle(document, 'write', '', 1, 0)('</ul></div>');
	}
	//Begin mycity information
	if(splitUpRecent.length == 0){
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('<DIV class="myFavorites">My Favorites<SPAN style="padding: 0px 0px 0px 43px;"><IMG src="http://i.imwx.com/web/common/icons/sm_close_box.gif" border="0" onMouseDown="MyLocationClose(\'whatwhere\')"></SPAN></DIV>');
	}else{
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('<DIV class="myFavorites">My Favorites</DIV>');
	}
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('<TABLE border="0" cellpadding="0" cellspacing="0"><TR><TD>');
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('<a href ="http://www.weather.com/weather/local/'+splitCityInfo[0]+'" onmousedown="setClick();" onMouseUp="this.href=intelliTrak({\'href\':this.href,\'from\':\'recentsearch\'});" class="linkVerdanaText10">');
	var presentationName =  _proxy_jslib_handle(splitCityInfo[2], 'replace', '', 1, 0)("--",",");
		
	if(presentationName.length > 23) {
	        presentationName = presentationName.substring(0,20);
	        presentationName += "...";
	    }
	 _proxy_jslib_handle(document, 'write', '', 1, 0)(presentationName);
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('</a>');
	
	//Begin the watchlist information
	var splitWatchlistInfo = myWatchlist.split(":");
	counter = 10;
	for (var i=0;i<5;i++){
		if( _proxy_jslib_handle(splitWatchlistInfo, (i), 0, 0) != splitCityInfo[0] &&  _proxy_jslib_handle(splitWatchlistInfo, (i), 0, 0) != '*' &&  _proxy_jslib_handle(splitWatchlistInfo, (i), 0, 0) !='' && typeof( _proxy_jslib_handle(splitWatchlistInfo, (i), 0, 0))!='undefined' && typeof( _proxy_jslib_handle(splitWatchlistInfo, (i+counter), 0, 0))!='undefined'){
		 _proxy_jslib_handle(document, 'write', '', 1, 0)('<BR><a href ="http://www.weather.com/weather/local/'+ _proxy_jslib_handle(splitWatchlistInfo, (i), 0, 0)+'" onmousedown="setClick();" onMouseUp="this.href=intelliTrak({\'href\':this.href,\'from\':\'recentsearch\'});" class="linkVerdanaText10">');
	watchListName =  _proxy_jslib_handle( _proxy_jslib_handle(splitWatchlistInfo, (i+counter), 0, 0), 'replace', '', 1, 0)("--",",");
	if(typeof(watchListName)!='undefined' && watchListName != '' && watchListName.length > 23) {
	        watchListName = watchListName.substring(0,20);
	        watchListName += "...";
	    }
	 _proxy_jslib_handle(document, 'write', '', 1, 0)(watchListName);
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('</a>');
		}
	}
	
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('</TD></TR></TABLE>');
	
}else if(!hasRecentSearches && hasMyCity && !hasMyWatchlist){

//This user has only has My City.....
	var splitCityInfo = myCity.split("^");
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('<DIV class="myFavorites">My Favorites<SPAN style="padding: 0px 0px 0px 43px;"><IMG src="http://i.imwx.com/web/common/icons/sm_close_box.gif" border="0" onMouseDown="MyLocationClose(\'whatwhere\')"></SPAN></DIV>');
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('<TABLE border="0" cellpadding="0" cellspacing="0"><TR><TD>');
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('<a href ="http://www.weather.com/weather/local/'+splitCityInfo[0]+'" onmousedown="setClick();" onMouseUp="this.href=intelliTrak({\'href\':this.href,\'from\':\'recentsearch\'});" class="linkVerdanaText10">');
	var presentationName =  _proxy_jslib_handle(splitCityInfo[2], 'replace', '', 1, 0)("--",",");
	if(presentationName.length > 23) {
	        presentationName = presentationName.substring(0,20);
	        presentationName += "...";
	    }
	 _proxy_jslib_handle(document, 'write', '', 1, 0)(presentationName);
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('</a>');
	 _proxy_jslib_handle(document, 'write', '', 1, 0)('</TD></TR></TABLE>');
}
 ;
_proxy_jslib_flush_write_buffers() ;