// Channel Script: SBC

// DOCUMENT.READY
// 	This function must be kept neat and clean, not to be crowded with assorted functions and triggers.
$(document).ready(function(){
	fox.site.channel.loadDocReadyVars(); // store global variables only available on document.ready
	fox.site.channel.genericItems(); // generic triggers
	
	story.init();
}); /* end document.ready */

// CHANNEL VARIABLES: Use this object to store global variables used in this channel only
window.channelVars = {};

// 	CHANNEL PRE-LOADER: Channel level loadEvent function
fox.site.loadEventOrig = fox.site.loadEvent||null;
fox.site.loadEvent = function(componentId) {
	if (fox.site.loadEventOrig) {
		fox.site.loadEventOrig(componentId); // existing functions
	}
	$(componentId).each(function(){
		// loadEvent listeners here
	});
};

// ----- CHANNEL SPECIFIC FUNCTIONS AND TRIGGERS -----
fox.site.channel = {}; // initialize

// DOC.READY VARIABLES: channel defined variables only available on document.ready
fox.site.channel.loadDocReadyVars = function() {
	var newVars = {
		allImgPath: pagedescriptor.getSiteMeta().static_asset_all_img,										   
		siteImgPath: pagedescriptor.getSiteMeta().static_asset_img,
		vcmid: pagedescriptor.getSiteMeta().vcmid,
		site: pagedescriptor.getSiteMeta().site,
		channel: pagedescriptor.getSiteMeta().channel
	}
	for (i in newVars) { channelVars[i] = newVars[i]; }
};

// GENERIC ITEMS - General channel specific jQuery triggered items
fox.site.channel.genericItems = function() {
	
	fox.site.channel.SBCSearchArea(true,{ method:'GET',action:'http:\/\/www.foxsmallbusinesscenter.com/search-results/search' });
	
	$(".podcast").find("li p.more-item").each(function(){ $(this).append(" &#187;"); });
	
	//openforum
	if (!siteVars.isIE6) {
		$(".generic-list.console >.bottom").each(function(){
			$(this).append('<div class="logo"><a href="http://www.openforum.com/"><img alt="Open Forum" src="'+channelVars.siteImgPath+'/logo-open.jpg"/></a></div>')
				.append('<div class="sponsor">Sponsored by<a href="http://www.fedex.com"><img alt="FedEx" src="'+channelVars.siteImgPath+'/logo-fedex.jpg"/></a></div>');
		});
	}
	
	// share print
	$(".share-print").click(function () { 
      	var printUrl = this.hash.replace('#','');
	  	window.open(printUrl, 'storyDetailsPrint','width=668,scrollbars=yes,toolbar=no,location=no,menubar=yes,resizable=no'); 
	  	return false; 
    });

}; /* end generic items */

// Search area
fox.site.channel.SBCSearchArea = function(show,prop) {
	if (show) {
		$(".searchArea .searchBox").each(function(){
			$("input[type='text']",this).attr({ name:"q",onblur:"",onfocus:"" }) // remove defaults, they're throwing js errors
				.blur(function(){
					var str = (($(this).attr("value")).length>0)?$(this).attr("value"):"Search Small Business";
					$(this).attr("value",str);
				})
				.focus(function(){
					var str = ($(this).attr("value").indexOf("Search Small Business")>-1)?"":$(this).attr("value");
					$(this).attr("value",str);
				})
			$("input[type='submit']",this).attr("name","s"); // remove submit name
			$("form",this).attr({action:prop['action'],method:prop['method'] });
			$(this).css("display","block");
		});
	}
};

// Insert header
fox.site.insertHeader = function(){
	$('.logo').html('<a id="logo-link" href="http://www.foxsmallbusinesscenter.com"><img src="/static/fb/ws/sbc/img/sbc-sm-header.jpg" alt="" /></a>');
}

// ----- CHANNEL GLOBAL SCRIPTS ------
// These are scripts that do not need to be contained in the fox namespace for their simplicity

function openWindow(url,w,h,tb,stb,l,mb,sb,rs,x,y){ 
    var t=(document.layers)? ',screenX='+x+',screenY='+y: ',left='+x+',top='+y; //A LITTLE CROSS-BROWSER CODE FOR WINDOW POSITIONING 
    tb=(tb)?'yes':'no'; stb=(stb)?'yes':'no'; l=(l)?'yes':'no'; mb=(mb)?'yes':'no'; sb=(sb)?'yes':'no'; rs=(rs)?'yes':'no'; 
    var x=window.open(url, 'newWin'+new Date().getTime(), 'scrollbars='+sb+',width='+w+',height='+h+',toolbar='+tb+',status='+stb+',menubar='+mb+',links='+l+',resizable='+rs+t); 
    x.focus(); 
} 

function doValidate(textArea) { 
    var tArray = textArea.value.split('\n'); 

    if (textArea.value.replace(/^\s+|\s+$/g,"").length == 0 || tArray.length == 0) { 
          alert('Please enter at least one tracking number.'); 
    } else if (tArray.length > 5) { 
          alert('Please limit your inquiry to 30 tracking reference FedEx Kinkos order numbers.'); 
    } else { 
          openWindow('http://www.fedex.com/Tracking?tracknumbers=' + escape(textArea.value) + '&action=track&language=english&ascend_header=1&imageField=Track', 760, 500 ,0 ,0 ,0 ,0 ,0 ,1 ,10 ,10); 
    } 
}