function playVideo(_8){
	window.open(_8, "", "width=800,height=800,location=yes,menubar=yes,resizable=yes,scrollbars=yes,toolbar=yes,status=yes,directories=yes");
}
function getEl( id ){ return document.getElementById( id ); }
// Login Functions
function AsnsSignIn( obj, leftOffSet, topOffSet, ele ) {
	if (!leftOffSet) leftOffSet = 0;
	if (!topOffSet) topOffSet = 0;
	var pSNS = getEl(ele);
	pSNS.innerHTML = "";
	pSNS.innerHTML += _sns_var_;
	if ( document.all ) {
		var pos = findPos(obj);
		pSNS.style.position = 'absolute';
		pSNS.style.left = (pos[0] + leftOffSet - 138) + 'px';
		pSNS.style.top =  (pos[1] + topOffSet + 12)  + 'px';
} else {
		obj.appendChild(pSNS);
		pSNS.style.left = leftOffSet + 'px';
		pSNS.style.top =  topOffSet  + 'px';
		pSNS.style.position = 'relative';
		}
	var close = document.createElement("span");
	var a = document.createElement("a");
	a.href = 'javascript:AsnsClose("'+ele+'")';
	a.title = "close";
	var img = document.createElement("img")
	img.src = "http://my.screenname.aol.com/images/10x10_x.gif";
	img.style.border = "0px"
	a.appendChild(img);
	close.appendChild(a);
	spans = pSNS.getElementsByTagName("span");
	spans[1].style.cssFloat = "right";
	spans[1].style.styleFloat = "right";
	spans[1].style.margin = "1px 0px 0px 10px";
	close.style.cssFloat = "right";
	close.style.styleFloat = "right";
	close.style.margin = "2px 2px 0px 0px";
	spanPar = spans[1].parentNode;
	spanPar.insertBefore(close,spans[1]);
	pSNS.style.zIndex = 5000;
	pSNS.style.display = "block";
}
function closeSNS(ele) {
	getEl(ele).innerHTML = '';
}

function AsnsClose(ele) {
	pSNS = getEl(ele);
	pSNS.style.display = "none";
}

function findPos(obj) {
	var curleft = curtop = 0;
	curleft = getX(obj);
	curtop = getY(obj);
	return [curleft,curtop];
}
function getY( oElement )
{
	var iReturnValue = 0;
	while( oElement != null ) {
		iReturnValue += oElement.offsetTop;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}

function getX( oElement )
{
	var iReturnValue = 0;
	while( oElement != null ) {
		iReturnValue += oElement.offsetLeft;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}
/* Header functions*/
// Tog More for Search
function togMore(sShow){
	if (sShow == "hide"){
		getEl("srchMoreId").style.display = "none";
	}
	else{
		getEl("srchMoreId").style.display = "block";
	}
	return false;
}

// Begin : Headers 2 code
function p_o(o){return getEl(o);}

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( /\+/, " ");
	if(ref == 'a'){
		var newurl = frm.action + queryval;
		if (frm.target == '_blank') {
			window.open(newurl, '_blank', '');
		} else {
			window.location = newurl;
			}
	}else{
		var newurl = ref.href + queryval;
		window.location = newurl;
	}
	return false;
}

function searchTarget(url, newWindow, newTarget) {
	// Set the target for the form
	document.bb_topform.action = url;
	if (newWindow) {
		document.bb_topform.target = '_blank';
	} else {
		document.bb_topform.target = '';
	}

	// Update the tabs classes to allow highlighting of the selected
	var tabList = ["searchTabNews","searchTabWeb","searchTabImages","searchTabVideo","searchTabLocal"]
	for(var i=0;i<tabList.length;i++){
	getEl(tabList[i]).className = '';
	}
	getEl(newTarget).className = 'srchCatBg';

	return false;
}

function eventIsEnterKey(event) {
	if (event && event.which == 13 || window.event && window.event.keyCode == 13 || event && event.which == 3 || window.event && window.event.keyCode == 3) {
		return true;
	}
	return false;
}

function submitHeaderSearch(event) {
	if (event == "onclick" || eventIsEnterKey(event)) {
		return srchSub("a");        
	} else {
	return true;
	}
}

//Prevent IE flickr
try {
	document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

function hideHeaderMore(e) {
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;

	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;

	if(targ.id != 'srchMoreAnc') {
    	var oDiv=p_o('srchMoreId');

		if(oDiv.style.display.toLowerCase() == "block") 
			oDiv.style.display='none';
	}
}

document.onclick = hideHeaderMore;
/*end header functions*/

// Tag Cloud/List (Blog Chatter)
function showTags(){
	if (iTagType == 1) // Show as Cloud
		{
			caption = "List";
			iTagType = 2;
			getEl("tagCloud").style.display = "block";
			getEl("newsTagList").style.display = "none";
		} 
		else // Show as List
		{
			caption = "Cloud";
			iTagType = 1;
			getEl("tagCloud").style.display = "none";
			getEl("newsTagList").style.display = "block";
		}
			getEl("newsTagTypeAnc").innerHTML = caption;
}
// End: Tag Cloud/List (Blog Chatter)
function showToolTip(oCaller, ttID){getEl(ttID).style.display = "block";}
function hideToolTip(oCaller, ttID){getEl(ttID).style.display = "none";}

function changeSort(sort){
	setPref("sort", sort);
	document.frmHubSrt.submit();
	return false;
}

function changeTimePeriod(){
	var i = document.frmHubSrt.timePeriodSelect.selectedIndex;
	setPref("timePeriod", document.frmHubSrt.timePeriodSelect[i].value);
	document.frmHubSrt.submit();  
}

function changeSource(url){
	var i = document.frmHubSrt.sourceSelect.selectedIndex;
	var value = document.frmHubSrt.sourceSelect[i].value;
	var url = url+value+"/results";
	setPref("source",value);
	document.frmHubSrt.action = url;
	document.frmHubSrt.submit();
}

function goToHub() {
	var txt = getEl("searchText").value;
	if(txt == "" || txt == "Search News Videos"){
		return false;
	}
	else{
		setPref("sort", 'mostRecent');
		document.qksearch.submit();
	}
	return false;
}

function searchTxt(event){
			if (event == "onclick" || evntIsEnerKy(event)) {
				return	goToHub();    
			}
			else{
				return true;
			}
}
function evntIsEnerKy(event) {
	if (event && event.which == 13 || window.event && window.event.keyCode == 13 || event && event.which == 3 || window.event && window.event.keyCode == 3) {
	    return true;
		}
	return false;
}

function textAppear(id,obj,img,size){
var ul=getEl("sortimg");
if(ul.childNodes != null){
	for (var i=1;i<=size;i++) {
		getEl("vid"+i).style.display="";
		getEl("vid1"+i).style.display="none";
	}
	var imagePlace = getEl(id);
	imagePlace.style.display="block";
	obj.style.display="none";
	imagePlace.style.background='url('+img+')';
}
}

function textHide(size){
	for (var i=1;i<=size;i++) {
		getEl("vid"+i).style.display="";
		getEl("vid1"+i).style.display="none";
	}
}

function changeVw(bkgrnd,vw){
	if(vw == "grid"){
					getEl("gridImg").src="/videos/images/grid_selected.gif";
					bkgrnd.parentNode.className ="viewHoverDiv";
					getEl("detImg").src="/videos/images/detail.gif";
					getEl("listImg").src="/videos/images/list.gif";
					getEl("detailBk").parentNode.className="viewDivDet";
					getEl("listBk").parentNode.className="viewDiv";
	}

	else if(vw == "detail"){
					getEl("detImg").src="/videos/images/detail_selected.gif";
					bkgrnd.parentNode.className ="viewHoverDetail";
					getEl("gridImg").src="/videos/images/grid.gif";
					getEl("listImg").src="/videos/images/list.gif";
					getEl("gridBk").parentNode.className="viewDiv";
					getEl("listBk").parentNode.className="viewDiv";
	}
	else{
					getEl("listImg").src="/videos/images/list_selected.gif";
					bkgrnd.parentNode.className ="viewHoverDiv";
					getEl("detImg").src="/videos/images/detail.gif";
					getEl("gridImg").src="/videos/images/grid.gif";
					getEl("detailBk").parentNode.className="viewDivDet";
					getEl("gridBk").parentNode.className="viewDiv";
	}
	var con = getEl("hubContainerviewsnav");
	var content = getEl("hubContainerresnav");
	if(con){
		con.className = vw;
	}
	if(content){
		content.className = vw;
	}
	setPref("view", vw);
	return true;
}

/*user ratings starts */
function rtngOver(element, starOverURL){
	element.style.cursor = 'pointer';
	var baseId = element.id;
	var myEl = getEl(baseId);
	myEl.src = starOverURL;
}

function submitRating(rating,vidId,url,subCategory){
	var request = getHTTPObject();
	if(request){
		request.onreadystatechange = function(){
		displayRatingResponse(request, rating);
	};
	request.open("POST", url, true);
	request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	request.send("id="+vidId+"&rating="+rating+"&subCategory="+subCategory);
}}

function displayRatingResponse(request, rating){
	if(request.readyState == 4){
    if(request.status == 200){
      var element = getEl("videoDetailContainer");
		  element.innerHTML = request.responseText;
		  getEl("beforeRating").style.display = "none";
		  getEl("afterRating").style.display = "block";
		  for(var cnt=1;cnt<=rating;cnt++){
			  var myEl = getEl("usrRtngStr1" + cnt);
			  myEl.src = "http://www.aolcdn.com/news_vce/220208-1/images/redstar.gif";
		  }
    }
	}
}

/*user ratings ends */

function changeCnt(cnt){
	setPref("resultsNbr", document.navcountgen.resultsNbr.value);
	setPref("resultsIndex", "0");
	document.navcountgen.submit();
	return true;
}

function clearText(obj){
	var headerQuery = obj.value;
	obj.value = '';
	obj.className="nobg";
}

function replaceText(obj){
	headerQuery = ""
	var target = obj.value.trim();
	obj.value = (target == "") ?  headerQuery : target;
	if (obj.value == "") {
		obj.className="";
	}
}

var type_error = "error";
var type_debug = "debug";
var isdebug = false;

function log( type, msgs ){
	var result = "";
	for (var i = 0; i < arguments.length; i++){
		result += " " + arguments[i];
	}
	if (type == type_debug && isdebug ) alert(result);
}

var logger = new function(){
	this.error = function(msgs){ log(type_error,msgs); };
	this.debug = function(msgs){ log(type_debug,msgs); };
}

if (typeof console == "undefined" || !console.error) {
	var console = {};
	console= logger;
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function setPref(param, value){
	var prefCookieName = "VCE-PREFS";
	var prefCookieString = "";
	var prefDelim = "&";
	var keyvalDelim = ":";
	var prefArray;
	var prefCookie = getCookie(prefCookieName);
	if ( prefCookie ) {
		prefArray = prefCookie.split(prefDelim);
	} else {
		prefArray = new Array();
	}

	var re = "^" + param + keyvalDelim;
	for (var i=0;i<prefArray.length;i++){
		if ( prefArray[i].search(re) <  0 ){
			if (prefCookieString != "" ){
				prefCookieString += prefDelim;
			}
			prefCookieString += prefArray[i];
		}
	}
	if (prefCookieString != "" )
		prefCookieString += prefDelim;

	prefCookieString += (param + keyvalDelim + value);
	setCookie(prefCookieName,prefCookieString,null);
	}

function getHTTPObject(){
	var xhr = null;
	if (window.XMLHttpRequest){
		xhr = new XMLHttpRequest();
	} else {
		if (window.ActiveXObject){
			try {
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					xhr = new ActiveXObject("Microsoft.XMLHTTP");
					}
				catch (e) {
					xhr = null;
				}
			}
		}
	}
return xhr;
}

//adds a video id to the VCE-QUICKLIST cookie
function addToQuicklist(videoId, url){
	var vceCookieVal = getCookie("VCE-QUICKLIST");
	if(vceCookieVal){
		if(vceCookieVal.indexOf(videoId) == -1){
		var vIdArray = vceCookieVal.split(",");
		setCookie("VCE-QUICKLIST", addToArray(vIdArray, videoId), 30);
		var now = new Date();
		setCookie("VCE-LASTUPDATED", now.getTime(), 30);
		}
		else{
			alert("This Video has already been added to Quicklist");
		}
	}
	else setCookie("VCE-QUICKLIST", videoId, 30);
	var request = getHTTPObject();
	if(request){
	request.onreadystatechange = function(){
	displayResponse(request, "quickListContainer");
	};
	request.open("POST", url, true);
	request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	request.send("videoId="+videoId);
	}
}

//removes a video id from the VCE-QUICKLIST cookie
function removeFromQuicklist(videoId, url){
	var vceCookieVal = getCookie("VCE-QUICKLIST");
	if(vceCookieVal != null && vceCookieVal != ""){
	var vIdArray = vceCookieVal.split(",");
	vIdArray = removeFromArray(vIdArray, videoId);
	setCookie("VCE-QUICKLIST", vIdArray, 30); 
	var now = new Date();
	setCookie("VCE-LASTUPDATED", now.getTime(), 30);
	}
	var request = getHTTPObject();
	if(request){
	request.onreadystatechange = function(){
	displayResponse(request, "quickListViewContainer");
	};
	if(vIdArray.length>0){
	request.open("POST", url, true);
	request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	request.send("videoId="+videoId);
	}
	else{getEl("quickListView").innerHTML="No Videos in list";}
	}
}

function updatePlaybackQuicklistNav(vId, url){
	var request = getHTTPObject();
	if(request){
	request.onreadystatechange = function(){
	displayResponse(request, "playbackQuicklistNavContainer");
	};
	request.open("POST", url, true);
	request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	request.send("id="+vId);
	}
}

function update(vId, url){
	var request = getHTTPObject();
	if(request){
	request.onreadystatechange = function(){
	displayResponse(request, "quickcentCont");
	};
	request.open("POST", url, true);
	request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	request.send("id="+vId);
	}

}

function addComment(vId,subCategory,url){
	var comment="";
	var comnt = getEl("newComment").value;
	getEl("newComment").value = "type your comment here";
	var txt="type your comment here";
	if(comnt == txt || comnt == "" || comnt == "null" || comnt.replace(/\s{2,}/gi," ") == " "){getEl("newComment").value="type your comment here";}
	else{
    comnt = comnt.replace(/\s{2,}/gi," ").replace(/\n/gi," <br/>");
	var str= comnt.split(" ");
	for(var i=0;i<str.length;i++){
		comment+=cutString(str[i],50)+" ";
		}
	var request = getHTTPObject();
	if(request){
	request.onreadystatechange = function(){
	displayResponse(request, "commentsContainer");
	};
	request.open("POST", url, true);
	request.setRequestHeader("Content-type","application/x-www-form-urlencoded;charset=UTF-8");
	request.send("id="+vId+"&subCategory="+subCategory+"&newComment="+comment);
	}
	}
}

function cutString (str, maxchars) {
		if(str&&str.length<maxchars) return str;
		else if(str) return (str.substring(0,maxchars).lastIndexOf(" ")>0)?str.substring(0,str.substring(0,maxchars).lastIndexOf(" ")):str.substring(0,maxchars);
		else return "";
	}

function updateMoreVideos(sort,url){
	var request = getHTTPObject();
	if(request){
	request.onreadystatechange = function(){
	displayResponse(request, "moreVideosContainer");
	};
	request.open("POST", url, true);
	request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	request.send("sort="+sort);
}
}

//ajax callback function
function displayResponse(request, elementId){
	if(request.readyState == 4){
    if(request.status == 200){ 
	    var element = getEl(elementId);
      element.innerHTML = request.responseText;
	  if(element.id == "quickListContainer"){
		  if(getEl("quickVid")){
				var quick = getEl("quickVid");
				 if(quick.offsetHeight>230){
					quick.style.height = "230px";
					quick.style.overflow = "auto";
				}
			}
			else if(!getEl("quickVid")){
				var quick = getEl("vidsRelated");
				 if(quick.offsetHeight>350){
					quick.style.height = "350px";
					quick.style.overflow = "auto";
				}
			}
		}
    }
	} 
}

function updateCommentPagination(vId,resultsIndex,resultsNbr,url){
	var query="id="+vId+"&resultsIndex="+resultsIndex+"&resultsNbr="+resultsNbr;
	var request = getHTTPObject();
	if(request){
	request.onreadystatechange = function(){
	displayResponse(request, "commentsContainer");
	};
	request.open("POST", url, true);
	request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	request.send(query);
	}
}

function processKey(e){
	if (null == e)
	e = window.event;
	var browserName=navigator.appName;
	if (e.keyCode == 13 && browserName=="Microsoft Internet Explorer"){
	document.commentForm.submit();
	}	
}

//sets a cookie with the specified
//name, value and expiration date
function setCookie(name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+";path=/";
}

//returns the value of the
//specified cookie
function getCookie(cookieName){
	if (document.cookie.length>0){
	var start=document.cookie.indexOf(cookieName + "=");
	if (start!=-1){ 
	start=start + cookieName.length+1; 
	var end=document.cookie.indexOf(";",start);
	if (end==-1){
	end=document.cookie.length;
	}
	return unescape(document.cookie.substring(start,end));
	}
	}
	return null;
}

//removes the specified element from the
//current array
function removeFromArray(array, element){
	var newArray = new Array(array.length - 1);
	var ni = 0;
	var i = 0;
	for(; i < array.length;){
		if(array[i].indexOf(element) == -1){
		newArray[ni] = array[i];
		ni=ni+1; 
		}
		i=i+1;
	}
	return newArray;
}

//adds the specified element to the
//current array
function addToArray(array, element){
	var newArray = new Array(array.length);
	var l = array.length;
	var i = 0;
	if(array.length==20){
		for(; i < 20; ){
				newArray[i] = array[i];
				i=i+1;
		}
		alert("Quick List can only store 20 videos");
		return newArray;
	}
	else{
		    newArray = new Array(array.length+1);
			for(; i < array.length; ){
				newArray[i] = array[i];
				i=i+1;
			}
			newArray[i] = element;
			return newArray;
	}
}

function shareOperation(iOperation,strTitle){
	var staf_obj = new staf_SE();
	staf_obj.setLang("en-US");
	var strUrl=location.href;
	if (strUrl != ""){
	staf_obj.setURL(strUrl);
	}
	if (strTitle != ""){
	staf_obj.setTitle(strTitle);
	}
	if (iOperation == 1){
	staf_obj.sendIM();
	}
	else{
	staf_obj.sendEmail();
	}
}

/* start of staf_init.js */

function staf_SE(){
	var omniture_tracking;
	// Email This variables
	var width, height;        // Width and Height of Email Popup
	var im_width, im_height;  // Width and Height of Email Popup
	var lang = "";            // Language parameter
	// IM Variables
	var message = "";        // IM Message
	var linkURL = "";        // Default URL is the current page.
	var pageTitle = "";      // Page Title
	var confirm = false;     // Confirmation pop-up window for non-AOL browsers
	// Launch IM
	var sendIM = function(){
		winl = (screen.width - im_width) / 2;
		wint = (screen.height - im_height) / 2;
		if (winl < 0) winl = 0;
		if (wint < 0) wint = 0;
		window.open("http://sendtoafriend.aol.com/im.adp?url=" + linkURL + "&title=" + pageTitle + "&lang=" + lang, "IM_Window", "height=" + im_height + ",width=" + im_width + ",top=" + wint + ",left=" + winl + ",statusbar=0,toolbar=0,menubar=0,location=0,resizable=0");
	}
	// Launch Email
	var sendEmail = function (){
		winl = (screen.width - width) / 2;
		wint = (screen.height - height) / 2;
		if (winl < 0) winl = 0;
		if (wint < 0) wint = 0;
		window.open("http://sendtoafriend.aol.com/?url=" + linkURL + "&title=" + pageTitle + "&lang=" + lang, "Email_Window", "height=" + height + ",width=" + width + ",top=" + wint + ",left=" + winl + ",statusbar=0,toolbar=0,menubar=0,location=0,resizable=0");
	}
	// Default Values
	var setDefault = function (){
		message = "Your friend wants you to check this out:";
		linkURL = escape(document.location);
		pageTitle = escape(document.title);
		confirm = false;
		width = 292;
		height = 500;
		im_width = 292;
		im_height = 150;
		lang = "en-US";
	}

	// Set default values.
	setDefault();
	return {
		sendIM: function(){
			if(omniture_tracking){
				setOmniStaf("IM");
			}
			sendIM();
		},
		sendEmail: function(){
			if(omniture_tracking){
				setOmniStaf("Email");
			}
			sendEmail();
		},
		setMessage: function(custom_message){
			if (typeof(custom_message) == "string"){
				message = custom_message;
			}
		},
		setWidth: function(custom_width){
			if (typeof(custom_width) == "number") {
				width = custom_width;
			}
		},
		setHeight: function(custom_height){
			if (typeof(custom_height) == "number"){
				height = custom_height;
			}
		},
		setIMWidth: function (custom_width) {
			if (typeof(custom_width) == "number") {
				im_width = custom_width;
			}
		},
		setIMHeight: function(custom_height){
			if (typeof(custom_height) == "number") {
				im_height = custom_height;
			}
		},
		setLang: function(custom_lang){
			if(typeof(custom_lang) == "string"){
				lang = custom_lang;
			}
		},
		setTitle: function(custom_title){
			if(typeof(custom_title) =="string"){
				pageTitle = escape(custom_title);
			}
		},
		setURL: function(custom_url){
			if (typeof(custom_url) =="string"){
				linkURL = escape(custom_url);
			}
		}
	};

}

/*end of staf_init.js*/

function loginCheck() {
    var sitedomain1 = 'sitedomain='+sitedomain;
	var url="siteState="+encodeURIComponent("OrigUrl="+encodeURIComponent(window.location));
	if(_sns_isLoggedIn) {
		getEl("userspan").innerHTML="Logged In: "+_sns_current_user;
		getEl("loginlink").href="https://my.screenname.aol.com/_cqr/logout/mcLogout.psp?"+sitedomain1+"&"+url;
		getEl("loginlink").title="Sign Out";  
		getEl("loginlink").innerHTML="Sign Out";
	} else {
		getEl("loginlink").href="https://my.screenname.aol.com/_cqr/login/login.psp?"+sitedomain1+"&"+url;
		getEl("loginlink").title="Sign In";        	
		getEl("loginlink").innerHTML="Sign In";
	 }
}

