//***************************************************************************************
// newsUtil.js
// Version: 1.0.1		Date: 20-10-2011
// Author: GDV
//***************************************************************************************

function hideDirectos() {  	
	var devicesTve = document.getElementById('allowedTveDevices').value.split(',');
	var devicesRne = document.getElementById('allowedRneDevices').value.split(',');
	//alert(devicesTve);
	var agent = navigator.userAgent.toLowerCase();
	//alert(agent);
	var i; 

	for(i=0; i<devicesTve.length; i++){
		if(agent.indexOf(devicesTve[i])!=-1){            
            //Replace url
            $(".directoTV a").attr("href",$(".directoTV a").attr("href") + "/" + devicesTve[i].replace(' ', '')); //to do
            //Show Buttons
            $(".directoTV").attr("style","");
            //break;
		}
	}	
	for(i=0; i<devicesRne.length; i++){
		if(agent.indexOf(devicesRne[i])!=-1){
            //Replace url
            $(".directoRadio a").attr("href",$(".directoRadio a").attr("href") + "/" + devicesTve[i].replace(' ', '')); //to do
            //Show Buttons
            $(".directoRadio").attr("style","");
            //break;
		}
	}
    
    //enable rescale content in android devices
    if(agent.indexOf("android")!=-1 || agent.indexOf("firefox")!=-1 )
        document.getElementById("viewport").setAttribute("content", "width=device-width; initial-scale=1.0;");
}

function visitarPagina() {
    var pagina  = document.getElementById("irA").value;
	document.form.action = 'http://www.rtve.es/' + pagina;  
	document.form.submit();
}

function gfxSocialNetwork() {
	RTVE.general.loadFacebook();
	jQuery.getScript("http://platform.twitter.com/widgets.js"); 
}

function pageScroll() {			// in order to see the visited links' background's color (just for the url without parameters)	
    if(location.href.indexOf("#ActiveSection") == -1) {     //searh the url for the string '#ActiveSection'
        window.location.assign("#ActiveSection"); 
        window.location.assign("#PageInit"); 
    }
	//window.scrollBy(0,50); 	// horizontal and vertical scroll increments
}

function getUrlParams() {
    var Url = location.href;
    Url = Url.replace(/.*\?(.*?)/,"$1");
    Variables = Url.split ("&");
    for (i = 0; i < Variables.length; i++) {
       Separ = Variables[i].split("=");
       eval ('var '+Separ[0]+'="'+Separ[1]+'"');  //ex: Separ[0]=asc   Separ[1]=Deportes
    }
    //alert(asc);
}

function getMoreTagItems(sTitle, sRssFile) {
    if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else {xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");} // code for IE6, IE5
        
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4 && xmlhttp.status==200) {                       
            nItem = document.getElementById("nextItem");
            //$("#nextItem").offsetParent().append(xmlhttp.responseText);
            nItem.innerHTML = xmlhttp.responseText;
            nItem.setAttribute("id", "");            
            nItem.setAttribute("style", "");  
            iNextItem = nItem.getAttribute("next_it");
            /*newFuction = document.getElementById("refNextTags").getAttribute("onclick").replace(',6);', ',' + iNextItem + ');');
            document.getElementById("refNextTags").setAttribute("onclick", newFuction);*/
            document.getElementById("loadingMoreTags").setAttribute("style", "display:none;");
            if(xmlhttp.responseText.search('id="NoMoreItems"')!=-1) {
                document.getElementById("multimediacontenttable").setAttribute("style", "display:none;");
            }
			redirectInternalLinksToMobileWebSite();
        }
    }
    iNextItem = document.getElementById("nextItem").getAttribute("next_it");
    document.getElementById("loadingMoreTags").removeAttribute("style");
    xmlhttp.open("GET","getMoreTags.php?t="+sTitle+"&rs="+sRssFile+"&ni="+iNextItem, true);
    xmlhttp.send();
}

/* function inicializarToolTipsSocialBookMarksMobile() {
	$("div.social_block div.view_social_networks div.labelSocial").live('click',function(){RTVE.general.toolTipsSocialBookMarksClickMobile($(this).parent());return false;});
	$("div.social_block div.view_social_networks").live('mouseleave',function(){RTVE.general.toolTipsSocialBookMarksLeaveMobile($(this));return false;});
}*/

/*
* Funcion para menu deplegable de los social bookmarks.
* Muestra el menu deplegable de los socialbookmarks de las pfs de noticia, encuesta, fotos y tag, cuando se hace click sobre la capa de Enviar
*/
/*function toolTipsSocialBookMarksClickMobile(divSocial) {
    var divSocialNets = divSocial.find(".social_networks");
    if (divSocialNets.hasClass("topMenuSocial")) {
        divSocialNets.find(".arrowTop").css({'display':'block'});
    }
    if (divSocialNets.hasClass("bottomMenuSocial")) {
        divSocialNets.find(".arrowBottom").css({'display':'block'});
    }
    if (divSocialNets.hasClass("leftMenuSocial")) {
        divSocialNets.find(".arrowLeft").css({'display':'block'});
    }
    divSocialNets.show();
    RTVE.general.hideMenuSocialBookMarks = false;
}*/
/*
* Funcion para menu deplegable de los social bookmarks.
* Oculta el menu deplegable de los socialbookmarks de las pfs de noticia, encuesta, fotos y tag, cuando se retira el raton de la capa de Enviar
*/
/*function toolTipsSocialBookMarksLeaveMobile(divSocial) {
    var divSocialNets = divSocial.find(".social_networks");
    if (RTVE.general.hideMenuSocialBookMarks == false) {
        divSocialNets.find(".arrowTop").css({'display':'none'});
        divSocialNets.find(".arrowBottom").css({'display':'none'});
        divSocialNets.find(".arrowLeft").css({'display':'none'});
        divSocialNets.hide();
    }
    RTVE.general.hideMenuSocialBookMarks = true;
} */
 
