/* Release 5.1 */

/* 
 * ua.partner.js
 * 
 * Created: Nov 2010
  
 * Author: Rob O'Brien
 * Release: 5.1
 * 
 * Dependencies:
 * ua.js
 * ua.vsTracking.js
 * 
 * Partner Kit functionality
 * 
 */

ua.partner = new function(){
	var vs = ua.vsTracking;
	
	/* @PRIVATE */
	this.setDefaults = function(){
		/* Make sure the Partner has defined their basic identifiers defined */
		
		/* TEMPORARY - only necessary until ua.js gets the default value of clientName removed */
		if (vs.getClientName() === 'United') { vs.setClientName(''); }
		
		/* 
		 * If ua.vsTracking.getClientName() is empty, we'll try to use the 
		 * legacy window.sPartnerName, finally falling back to document.domain
		 */
		if (vs.getClientName().length === 0) {
			if (typeof window.sPartnerName === 'string') {
				vs.setClientName(window.sPartnerName);
			}
			else {
				/* Otherwise, let's grab the document.domain  */
				vs.setClientName(document.domain);
			}
		}
		
		if (vs.getPageTitle().length === 0) {
			if (typeof window.sPartnerPageTitle === 'string') {
				vs.setPageTitle(window.sPartnerPageTitle);
			}
			else {
				/* Otherwise, let's grab the document.title */
				vs.setPageTitle(document.title);
			}
		}
		
		/* With all of our new data, we'll set the final Page Title */
		vs.setPageTitle('United_Partner-' + vs.getClientName() + '-' + vs.getPageTitle());
	};
};

ua.partner.utils  = new function(){

}();


/* 
 * Before the page unloads, make sure we have the defaults (like page title) set.
 * 
 * The tagScope (unload) should not be set explicitly, but must be done so 
 * temporarily until the addFunction() method is fixed in ua.vsTracking.js to 
 * allow for a the default scope.
 */
ua.vsTracking.addFunction(ua.partner.setDefaults,null,'unload');


/* 
 * 
 * 
 * From original vsForPartners.js 
 * 
 * 
 * 
 */

function chkBrs(sInp) {
	var sUA=navigator.userAgent.toLowerCase();
	var bFound=sUA.indexOf(sInp) +1;
	return bFound;
}

//added 9-3-2010 SHD
/* Obtain the value of a URL parameter. */
var qs = document.location.search.substr(1);
function gup(parameter) {
	parameter = parameter.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+parameter+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( qs );
	if( results == null ) return null;
	else return results[1];
	}
