

ordval=Math.floor (Math.random()*1000000);

function GetDomain () {
var url = ""+window.location+"";
if (url.indexOf("terra.com.pr",0) != -1)
        pcountry = "pr";
else
        pcountry = "us";
}
GetDomain();

ppubli = pcountry + ".terra.deportes/home";
ppublicidad = pcountry + ".terra.deportes/home";
pextrapubli = ";niv=0;ga=us_depo";
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function mm(url,pref) {
	terratv = window.open("http://php.terra.com/terratv/video.php?video="+url, "terratv");
}

function mm_old(url,pref) {
        options = "scrollbars=no,height=600 width=720";
        if (pref == null) pref = 0;
        newWindow = window.open("http://php.terra.com/videos/mm_choice.html?video="+url+"&pref="+pref+"&dart=us.terra.autos/vids",'mmedia',options);
}

// banners
ordval=Math.floor (Math.random()*1000000);

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}



function bbcradio(radio) {
        window.open("http://php.terra.com/radio/bbcradio/bbc.html?af="+radio,"bbcradio","width=626,height=440,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no");
}

function MM_findObj(n, d) {
        var p,i,x;
        if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
                d=parent.frames[n.substring(p+1)].document;
                n=n.substring(0,p);
        }
        if(!(x=d[n])&&d.all) x=d.all[n];
        for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
        for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
        if(!x && d.getElementById) x=d.getElementById(n);
        return x;
}

function MM_showHideLayers() {
        var i,p,v,obj,args=MM_showHideLayers.arguments;
        for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) {
                v=args[i+2];
                if (obj.style) {
                        obj=obj.style;
                        v=(v=='show')?'visible':(v=='hide')?'hidden':v;
                }
                obj.visibility=v;
        }
}


function defineAction() {
if (document.frmAllLogin2.page[1].checked)
        document.frmAllLogin2.action = "http://www.autobytel.com/content/Buy/used/index.cfm?id=22690;TERRA&dontStoreVehicle=True";
else
        document.frmAllLogin2.action = "http://www.autobytel.com/content/buy/LM/new/index.cfm?id=22690;TERRA";
return true;
}


function redirectURL() {
	if (document.frm.url_analisis.options[document.frm.url_analisis.selectedIndex].value != "") {
		document.location.href = document.frm.url_analisis.options[document.frm.url_analisis.selectedIndex].value;
	}
}

if(Browser == undefined){
	var Browser = {
		isIE: function(){ return (window.ActiveXObject && document.all && navigator.userAgent.toLowerCase().indexOf("msie") > -1  && navigator.userAgent.toLowerCase().indexOf("opera") == -1) ? true : false; }
	}
}

var Flash = function(movie, id, width, height, initParams){

	this.html = "";
	this.attributes = this.params = this.variables = null;
	
	this.variables = new Array();
	this.attributes = {
		"classid": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",
		"codebase": "http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab#version=8,0,22,0",
		"type": "application/x-shockwave-flash"
	}
	this.params = { "pluginurl": "http://www.macromedia.com/go/getflashplayer_br" };
	
	if(movie) {
		this.addAttribute("data", movie);
		this.addParameter("movie", movie);
	}
	
	if(id && id != null) this.addAttribute("id", id);
	if(width) this.addAttribute("width", width);
	if(height) this.addAttribute("height", height);
	
	if(initParams != undefined){
		for(var i in initParams){
			this.addParameter(i.toString(), initParams[i]);
		}
	}
	
}
Flash.version = "1.2b";
Flash.getObjectByExceptions = function(obj, excep){
	var tempObj = {};
	for(var i in obj){
		var inclui = true;
		for(var j=0; j<excep.length; j++)
			if(excep[j] == i.toString()) { inclui = false; break; };
		if(inclui) tempObj[i] = obj[i];
	}
	return tempObj;
}
Flash.prototype.addAttribute = function(prop, val){ this.attributes[prop] = val; }
Flash.prototype.addParameter = function(prop, val){ this.params[prop] = val; }
Flash.prototype.addVariable = function(prop, val){ this.variables.push([prop, val]); }
Flash.prototype.getFlashVars = function(){
	var tempString = new Array();
	
	for(var i=0; i<this.variables.length; i++)
		tempString.push(this.variables[i].join("="));
		
	return tempString.join("&");
}
Flash.prototype.toString = function(){
	
	this.params.flashVars = this.getFlashVars();
	if(Browser.isIE()){
		//IE
		this.html = "<ob" + "ject";
		var attr = Flash.getObjectByExceptions(this.attributes, ["type", "data"]);
		for(var i in attr) if(i.toString() != "extend") this.html += " " + i.toString() + " = \"" + attr[i] + "\"";
		this.html += "> ";
		var params = Flash.getObjectByExceptions(this.params, ["pluginurl", "extend"]);
		for(var i in params) if(i.toString() != "extend") this.html += "<param name=\"" + i.toString() + "\" value=\"" + params[i] + "\" /> ";
		this.html += " </obj" + "ect>";
	} else {
		//non-IE
		this.html = "<!--[if !IE]> <--> <obj" + "ect";
		var attr = Flash.getObjectByExceptions(this.attributes, ["classid", "codebase"]);
		for(var i in attr) if(i.toString() != "extend") this.html += " " + i.toString() + " = \"" + attr[i] + "\"";
		this.html += "> ";
		var params = Flash.getObjectByExceptions(this.params, ["extend"]);
		for(var i in params) if(i.toString() != "extend") this.html += "<param name=\"" + i.toString() + "\" value=\"" + params[i] + "\" /> ";
		this.html += " </obj" + "ect> <!--> <![endif]-->";
	}

	return this.html;
	
}
Flash.prototype.write = Flash.prototype.outIn = Flash.prototype.writeIn = function(w){
	if(typeof w == "string" && document.getElementById) var w = document.getElementById(w);
	if( w != undefined && w ) w.innerHTML = this.toString();
	else document.write( this.toString() );
}


function encode_utf8(txt) {
    txt = txt.replace(/\r\n/g,"\n");
    var utf = "";
    for(var n=0; n<txt.length; n++) {
        var c=txt.charCodeAt(n);
        if (c<128)
            utf += String.fromCharCode(c);
        else if((c>127) && (c<2048)) {
            utf += String.fromCharCode((c>>6)|192);
            utf += String.fromCharCode((c&63)|128);
        } else {
            utf += String.fromCharCode((c>>12)|224);
            utf += String.fromCharCode(((c>>6)&63)|128);
            utf += String.fromCharCode((c&63)|128);
        }
    }
    return utf;
}


function StartLayer(){

MM_showHideLayers('oldcar','','show','newcar','','hide');
document.frmSearchBox.tracktype[1].checked = true;
}

function ChangeLayer(car){

switch (car) {
case "oldcar": MM_showHideLayers('oldcar','','show','newcar','','hide');
	break;
case "newcar": MM_showHideLayers('oldcar','','hide','newcar','','show');
	break;
}

}


function checkFAutosHeader(){
 if (document.getElementById("query").value == ""){
	alert("Ingresa la palabra que deseas buscar.");
 } else{
	document.FHeader.action = "http://autos.terra.com/buscador/"+document.getElementById("query").value+"/";
	document.FHeader.submit(); 
 }
}


function checkFAutosFooter(){
 if (document.getElementById("query2").value == ""){
	alert("Ingresa la palabra que deseas buscar.");
 } else{
	document.FFooter.action = "http://autos.terra.com/buscador/"+document.getElementById("query2").value+"/";
	document.FFooter.submit(); 
 }
}


function checkSearchAutos(){
 if (document.getElementById("marca").value == "0") { 
	alert("Seleccione una marca."); 
 } else{
//	document.FSearch.action = "http://autos.terra.com/listado_autos.php";
	document.FSearch.action = "http://autos.terra.com/autos/"+document.getElementById("marca").value+"/";
	document.FSearch.submit(); 
 }
}

/* Redirect para o novo formato de busca de vídeos do terra.
Antes, o form ia para http://terratv.terra.com/templates/searchResult.aspx. Agora vai para http://terratv.terra.com/busca/<busca do usuário>
Trocar o 'palavra' pelo id correto do campo de busca. De preferência, deixar todos os forms com o mesmo id, pois esta função está localizada em mais de um local no portal Terra.
*/
function redirectBusca(objeto)
{
	redirect = objeto.palavra.value;
	window.open('http://terratv.terra.com/busca/' +  redirect + '.htm', '_blank');
}
