/*general 24-May-07 || crosspromo js eliminated*/
window.onload=template_init;
function template_init(){
    channel_init();
}
var getE = document.getElementById;

function ChangeClass(menu, newClass) { 
	if (getE) { 
		getE(menu).className = newClass;
	} 
} 
function SwitchMenu(obj){
	if(getE){
		var el = getE(obj);
		var ar = getE(containerid).getElementsByTagName("DIV");
		if(el.style.display == "none"){
			for (var i=0; i<ar.length; i++){
				if (ar[i].className.substr(0,4)=="subm"){
					ar[i].style.display = "none";   
				}
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}

//URL Parser
function getParam(paramName,defaultValue) {
	var q = (location.search.replace(/\?/,"")).split("&");
	var i = q.length;
	while(i-->0) {
		var t = q[i].split("=");
		if(t[0] == paramName) return t[1];
	}
	return defaultValue;
}

// Header2.0
function p_o(o){return document.getElementById(o);}

function ai_posX(obj){
	var left=0;
	if(obj.offsetParent){
		while(obj.offsetParent){
			left+=obj.offsetLeft;
			obj=obj.offsetParent;
		}
	}else if(obj.x)left+=obj.x;
	return left;
}
function ai_posY(obj){
	var top=0;
	if(obj.offsetParent){
		while(obj.offsetParent){
			top+=obj.offsetTop;
			obj=obj.offsetParent;
		}
	} else if(obj.x)top+=obj.y;
	return top;
}

function togMore(e,state){
	var oDiv=p_o('smore');
	if(state=='show'){
		posMore(e);
		oDiv.style.zIndex=99999999;
		oDiv.style.display='block';
	} else {
		oDiv.style.display='none';
	}
	return false;
}
function posMore(e){
	var oDiv=p_o('smore');
	var oLnk=p_o('smorea');
	posY = findMousePos(e);
	oDiv.style.left=(ai_posX(oLnk)+15)+'px';
	oDiv.style.top=(posY+oLnk.offsetHeight/2)+'px';
}
// Begin : Headers 2 code
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

function srchSub(ref){
	var frm=p_o("search");
	var queryval = frm.topquery.value.trim();
	queryval = queryval.replace( /\+/, " ");
	newurl = ref.href + queryval;
	window.location = newurl;
	return false;
}

//Open POPUP Window
function popupWindow(url,width,height,features) {
	if (!isNaN(parseInt(width))){features+=",width="+width;}
	if (!isNaN(parseInt(height))){features+=",height="+height;}
	if (typeof(window.screenLeft)!="undefined"){
		features+=",left="+window.screenLeft;
		features+=",left="+Math.round(window.screenLeft+((document.body.clientWidth/2)-(width/2)));
	} else if (typeof(window.screenX)!="undefined"){
		features+=",left="+Math.round(window.screenX+((window.outerWidth/2)-(width/2)));
	}
	if (typeof(window.screenTop)!="undefined"){
		features+=",top="+window.screenTop;
		features+=",top="+Math.round(window.screenTop+150);
	} else if (typeof(window.screenY)!="undefined"){
		features+=",top="+Math.round(window.screenY+((window.outerHeight-window.innerHeight)+150));
	}
	var popupWin=window.open(url,"popupWin",features);
	//if (popupWin.focus){popupWin.focus();}
}

//Client Mssg - Show | Hide
function showClientMsg(e) {
	if (!msgObj || window != top) {alert("This area is only available within the AOL client."); return false;}
	if (document.getElementById) {var launchLink = document.getElementById("launchLink");}
	else if (document.all) {var launchLink = document.all.launchLink;}
	else {alert("This area is only available within the AOL client."); return false;}
	launchLink.href = this.href;
	e = e ? e : event;
	var cm_xPos = (e.pageX != undefined) ? e.pageX : e.clientX + (document.documentElement ? document.documentElement.scrollLeft : document.body.scrollLeft);
	var cm_yPos = (e.pageY != undefined) ? e.pageY : e.clientY + (document.documentElement ? document.documentElement.scrollTop : document.body.scrollTop);
	cm_xPos = (cm_xPos > 438) ? 438 : cm_xPos;
	msgObj.style.left = cm_xPos + "px";
	msgObj.style.top = cm_yPos + "px";
	msgObj.style.display = "block";
	if (msgObj.focus) msgObj.focus();
	return false;
}

function hideClientMsg() {
	msgObj.style.display = "none";
	return false;
}

// gets the value of the query string
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
}

// check for the valid object
function testIsValidObject(objToTest) {
    if (objToTest == null || objToTest == undefined) {
        return false;
    }
    return true;
}


// START  Function for New Footer Design ----------------------------
function bb_makefbarnew (chname) {
	var s,vC,vM,c=0,p,sub;
	//Setup footer link bar
	if(p=bb_o("n__bb_fme")){
		// To make the first letter of Channel name to Uppercase - Bala 
        var ch_fletter = chname.charAt(0).toUpperCase();
        var chname = chname.replace(/^([a-z])([a-z]+)$/i, ""+ch_fletter+"$2");
		c=0;
		bb_ll=bb_md.length;
		s_temp='<span class="n__bb_ftb">More in '+chname+': </span>';
		for(i=0;i<bb_ll;i++){
			if(bb_md[i].l==0){
				vM=bb_md[i].v.charAt(0);
				vC=bb_md[i].v.charAt(1);
				if((vC==2||vC==bb_isC)&&(vM==2||vM==bb_isM)){
					s_temp+="<a href='"+bb_md[i].u+"'";
					if(bb_md[i].n=="Y")s+=" target='_blank'";
					s_temp+=">"+bb_md[i].t+"</a> | ";
					c++;
				}
			}
		}
		s = s_temp.substring(0,eval(s_temp.length-3));
		p.innerHTML=s;
	}	

	//Setup footer plain old links
	if (typeof(bb_fm)=="undefined" || typeof(bb_fm)!="string"){
		//return;
	}else{
		if(p=bb_o("n__bb_fr")){
		s="<span class='n__bb_ftb'>"+bb_fm+"</span> ";
		c=0;
		for(i=0;i<bb_fg.length;i++){
			vM=bb_fg[i].v.charAt(0);
			vC=bb_fg[i].v.charAt(1);
			if((vC==2||vC==bb_isC)&&(vM==2||vM==bb_isM)){
				s+="<a href='"+bb_fg[i].u+"'";
				if(bb_fg[i].n=="Y")s+=" target='_blank'";
				s+=">"+bb_fg[i].t+"</a> | ";
			}
		}
		s=s.slice(0,-3);
		p.innerHTML=s;
	}
	}

	//Setup footer links
	if(p=bb_o("n__bb_frfb")){
		s="";
		c=0;
		for(i=0;i<bb_lf.length;i++){
			vM=bb_lf[i].v.charAt(0);
			vC=bb_lf[i].v.charAt(1);
			if((vC==2||vC==bb_isC)&&(vM==2||vM==bb_isM)){
				s+="<a href='"+bb_lf[i].u+"'";
				if(bb_lf[i].n=="Y")s+=" target='_blank'";
				s+=">"+bb_lf[i].t+"</a> | ";
			}
		}
		s=s.slice(0,-3);
		d=p.innerHTML;
        if (d.length > 0 && s.length > 0) {
           s+=" | " + d;
        } else {
		   s+=d;
		}
		p.innerHTML=s;
	}
}
// END  Function for New Footer Design ----------------------------

// For any module with tabs
function tabs_handleMouseOver(id,color,instance) {
	var undefined;
	if (instance !== undefined){
		if (activeTab[instance] == id) return;
		instance = '_' + instance;
		instance2 = '_' + instance + '_';
	} else {
		instance = '';
		instance2 = '';
		if(activeTab == id) return;
	}
	if (color == "ntrl"){eval('document.images.img' + instance2 + id + '.src = tabs_on_ntrl' + instance + '[' + id + ']');}
	else {eval('document.images.img' + instance2 + id + '.src = tabs_on' + instance + '[' + id + ']');}
}

function tabs_handleMouseOut(id,instance) {
	var undefined;
	if (instance !== undefined){
		if (activeTab[instance] == id) return;
		instance = '_' + instance;
		instance2 = '_' + instance + '_';
	} else {
		instance = '';
		instance2 = '';
		if(activeTab == id) return;
	}
	eval('document.images.img' + instance2 + id + '.src = tabs_off' + instance + '[' + id + ']');
}

function tabs_handleClick(id,color,instance) {
	var undefined;
	if (instance !== undefined){
		var numTabs = eval('tabs_off_'+instance+'.length');
		if(activeTab[instance] != id) {
			for (k=1; k<numTabs; k++){
				eval('document.images.img_' + instance + '_' + k + '.src=tabs_off_' + instance + '[k]');
			}
			if (color == "ntrl") {eval('document.images.img_' + instance + '_' + id + '.src=tabs_on_ntrl_' + instance + '['+id+']');}
			else {eval('document.images.img_' + instance + '_' + id + '.src=tabs_on_' + instance + '['+id+']');}
		}
		activeTab[instance] = id;
	} else {
		activeTab = id;
	}
}

// For tabbed module v2
	// Global Variables
	var ccob = new cob();
function p(j){return document.getElementById(j)}
function ob(j){return document.getElementById(j)}

function cob() {
    var cache = new Array();
	
    // methods
    this.add     = function add(key,data) {cache[key] = data}
    this.getData = function getData(key) {return cache[key]}
    this.getKeys = function getKeys() {
        var keys = new Array();
		  var ix = 0;
        for (var i in 	cache) {
            keys[ix] = i;
		    ix++;
        }
        return keys;
    }
    this.hvDat = function hvDat(key) {
	    if (cache[key] || cache[key] == 0){return 1}
 	    return 0;
    }
}

function tbmd_set(mod,t) {
    
    // get all the li tags from the parent ul 
    lis = ob('tbsid' + mod).getElementsByTagName('UL').item(0).getElementsByTagName('LI');
	  
    // if data key is in the cache object then use it to turn off tab
    key = 'curidx' + mod;
    if (ccob.hvDat(key)) {
        aObj = lis.item(ccob.getData(key)).getElementsByTagName('A').item(0);
        aObj.className = '';
	aObj.style.display = 'block';
    }
	 
    // turn on clicked tab current tab if 
    if (lis.length >= t) {
        aObj = lis.item(t).getElementsByTagName('A').item(0);
        aObj.className = 'selected';
        aObj.style.display = 'block';
        ccob.add(key,t);
    }
}
function getData(tbmid,mod,t) {
     
    // if data for tab is not it cache the get item
    key = tbmid + '_' + t;
    tbd = '';
	  
	if (ccob.hvDat(key)) {
	    tbd = ccob.getData(key);

	    tbmd_set(tbmid,t);

            // get content div object
            modObj = ob('cntd' + tbmid);

	    modObj.innerHTML = tbd;
	} else {
            // get iframe div
            tbfObj = ob('tbf' + tbmid);
            
            // store iframe src url
            tbfUrl = '/mod.adp?_miid=' + mod + '&_tbmid=' + tbmid + '&_mtb=' + t; 

            // append current query params, they may be needed by module being output via mod.adp
            tbfQry = document.location.search;
            if(tbfQry) {tbfUrl += '&' + tbfQry.substring(1)}

            // append current url and the idx of tab clicked, some modules will use this for a redir
            defTab = "_deftb" + tbmid;
            tbfTmp = location.href; 

            // rebuild params without "_deftab{instanceid}"
            if(tbfTmp.indexOf(defTab) > 1) {
                aTmp = new Array();
                aQps = tbfQry.substring(1,tbfQry.length).split('&');
                for (i=0;i < aQps.length;i++) {
                    if (aQps[i].indexOf(defTab) == -1) {
                       aTmp.push(aQps[i]);
                    } 
                }
                tbfTmp = tbfTmp.substring(0,tbfTmp.indexOf('?') + 1) + aTmp.join('&');
            }
            // append the default tab with the idx of the tab clicked
            if(tbfTmp.indexOf('?') == -1) {tbfTmp += '?'} else {tbfTmp += '&'}
            tbfUrl += '&_tbdref=' + encodeURIComponent(tbfTmp + defTab + '=' + (t + 1));
            
            // stuff iframe div then set update src
            tbfHtm = '<iframe class=\"tbf\" id=\"tbdframe\" src=\"\"></iframe>';
            tbfObj.innerHTML = tbfHtm;
            tbfObj.getElementsByTagName('iframe').item(0).src = tbfUrl;
    }
    return false;
}
function fillFromHttp(req,a) {
    // confirm data recieved successfully
	tbd = '';
    if(req) {
        key = a.key;
	tbd = req
        ccob.add(key,tbd)
    } else {
        tbd = '0';
    }
	  
    // flip tabs
    tbmd_set(a.mod,a.t);
	 
    // fillDiv 
    ob('cntd' + a.mod).innerHTML = tbd;
}

function toggleArticleDrawer(obj,id) {
	var pObj = document.getElementById(id);
	if (obj.className == "off") {
		obj.className = "on";
		if(pObj.className.match("wrap")) {
			pObj.className = "artDrawer on wrap";
		} else {
			pObj.className = "artDrawer on";
		}
	}
	else {
		obj.className = "off";
		if(pObj.className.match("wrap")) {
			pObj.className = "artDrawer off wrap";
		} else {
			pObj.className = "artDrawer off";
		}
	}
}

function toggleClassName(id,stateOne,stateTwo) {
	var obj = document.getElementById(id);
	if (obj.className == stateOne) {
		obj.className = stateTwo;
	} else {
		obj.className = stateOne;
	}
}
// END For tabbed module v2
