/* Get the value of parameter from Querystring */
function Querystring(field) { 
	q_value = '';
	
	qs = location.search.substring(1, location.search.length);
	if (qs.length == 0) return q_value;

	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&');	// parse out name/value pairs separated via &
	
	// split out each name=value pair
	for (var i = 0; i < args.length; i++) {
		var pair = args[i].split('=');
		var name = decodeURIComponent(pair[0]);
		
		if(name==field){
			var q_value = (pair.length==2) ? decodeURIComponent(pair[1]) : name;		
			return q_value;
			break;
		}
	}
	return '';
}

//Function to uppercase the words ... equivalent to PHP ucwords
function fnUcwords(xx) {
	if(xx!='' && typeof(xx)!='undefined'){
		var yy = xx.split(" ");
		for (x=0; x<yy.length; x++) {
			yy[x] = yy[x].substring(0, 1).toUpperCase()+yy[x].substring(1);
		};
		xx = yy.join(" ");
		return xx;
	}
	return;
};
//End

//Function to create Page name from CategorySlug
function fnGetPageName(catslg){
	var slugvalue = '';
	slugvalue = catslg.toLowerCase();		
	
	// Find out @ and remove if found
	var at_pos = -1;
	
	at_pos = slugvalue.indexOf('@');
	
	if(at_pos >= 0)
		_slugvalue = slugvalue.substr(1);
	else 
		_slugvalue = slugvalue;
		
	//Remove "-" with space				
	_slugvalue = _slugvalue.replace(/-/g, ' ');		
	pgname = fnUcwords(_slugvalue);
	return pgname;
}

//End


function fnOmniture(customVar){
	//alert('from function---'+customVar.pgname+'==='+customVar.p1+'==='+customVar.p2+'==='+customVar.v11);

	// Create variable for Prop9
	var vprop9 = '';
	if(typeof(postid)!='undefined' && postid !='')
		vprop9 = 'bsd:'+postid;

	s_265.pfxID = "lov";
	sTitle = document.title;
	s_265.mmxgo = true;
	s_265.server = server_name;
	s_265.channel = "us.love";
	s_265.pageType = '';
	s_265.linkInternalFilters = "javascript:,aol.com, http://personals.aol.com/articles/";
	s_265.pageName = customVar.pgname;

	s_265.prop1 = customVar.p1;
	s_265.prop2 = customVar.p2;	
	s_265.prop9 = vprop9;	
	s_265.prop10 = '';
	s_265.prop12 = document.URL.split('?')[0];
	s_265.eVar11 = customVar.v11;	
	
	var s_code = s_265.t();
	if(s_code)document.write(s_code);
}
	

// Global JS Object for AOL Personals

var articles ={
	// Intialization function based on various pages
	init : function(param){
		//Initialize the array of custom omniture variables
		var customVar = {pgname:'', p1:'', p2:'', v11:''};

		switch (param)
		{
			case 'overview':					
				//Create page name
				if(cat_slg != '')
					slugvalue = cat_slg;
				else if(g_slg != '')
					slugvalue = g_slg;
				else
					slugvalue = "Articles and Advice";
				
				var strPageName = '';
				strPageName = fnGetPageName(slugvalue);
				if( typeof(strPageName)=='undefined') strPageName = '';

				sTitle= document.title;
				
				if(omniVar=="poll"){
					customVar.pgname = sTitle.split('-')[0];
					customVar.p1 = "Articles and Advice";
					customVar.p2 = "Poll";
				}else if(omniVar=="category"){
					customVar.pgname = strPageName+" Main";
					customVar.p1 = "Articles and Advice";
					customVar.p2 = strPageName;
				}else if(omniVar=="tag"){
					customVar.pgname = "Tag | "+tagVal+" Main";
					customVar.p1 = "Articles and Advice";
					customVar.p2 = "Tag";
				}else if(omniVar=="search"){
					customVar.pgname = "Article Search";
					customVar.p1 = "Articles and Advice";
					customVar.p2 = "Search";
				}else if(omniVar=="email"){
					customVar.pgname = "Email";
					customVar.p1 = "Articles and Advice";
					customVar.p2 = "Email";
				}else if(omniVar=="AllGallery"){
					customVar.pgname = "Gallery Main";
					customVar.p1 = "Gallery";
					customVar.p2 = "Main";
				}else if(g_slg!="" && g_slg!=null){
					customVar.pgname = strPageName+" Thumbnail";
					customVar.p1 = "Gallery";
					customVar.p2 = "Thumbnail";
				}else{
					customVar.pgname = strPageName+" Main";
					customVar.p1 = "Articles and Advice";
					customVar.p2 = "Main";
				}

				// Get search query
				var _srcQry = Querystring('q');
		
				if(_srcQry!=''){
					customVar.v11 = 'sTerms:f|'+_srcQry.toLowerCase();
				}

				//Call Omniture
				fnOmniture(customVar);
				break;
			case 'detail':

				var pos = -1;
				pos = pg_title.indexOf('- Personal Articles');
				
				if(pos >0)
					strPageName = pg_title.substr(0, pos);
				else
					strPageName = pg_title;			

				customVar.pgname = strPageName;
				customVar.p1 = "Articles and Advice";
				customVar.p2 = "Article";

				//Call Omniture
				fnOmniture(customVar);

				//If inject Module is called ... then injet it
				/*arrLength = arrMods.length;
				if( typeof(arrMods)!='undefined' && arrLength >0){
					for(var i=0;i<arrLength;i++){
						var _div = arrMods[i]["div"];
						var _url = arrMods[i]["url"];
						var _aid = arrMods[i]["aid"];
						var _h4 = arrMods[i]["h4"];

						fnInjectModule(_div, _url, _aid, _h4);
					}

				}*/

				break;
			case 'media':			
				//Gallery slg
				if( typeof(g_slg)=='undefined') g_slg = '';
				
				var strPageName = '';
				strPageName = fnGetPageName(g_slg);
				if( typeof(strPageName)=='undefined') strPageName = '';	

				customVar.pgname = strPageName;
				customVar.p1 = "Gallery";
				customVar.p2 = "";

				//Call Omniture
				fnOmniture(customVar);

				break;

			default:
				break;
		}
	}

}
