

window.SwitchLoginVideosUpload = function() {
	
  var uplNoLog = document.getElementById("uplVideoNoLogueado"), uplLog = document.getElementById("uplVideoLogueado");
	
	if (uplNoLog && uplLog) {
		var CMSFrontendLogin = getCookie("CMSFrontendLogin");
		if (CMSFrontendLogin) {
			var userData = CMSFrontendLogin.split("|");
			uplNoLog.style.display = "none";
		}
		else {
			uplLog.style.display = "none";
		}
	}
}

window.SwitchLoginFotosUpload = function() {
	
  var uplNoLog = document.getElementById("uplFotoNoLogueado"), uplLog = document.getElementById("uplFotoLogueado");
	
	if (uplNoLog && uplLog) {
		var CMSFrontendLogin = getCookie("CMSFrontendLogin");
		if (CMSFrontendLogin) {
			var userData = CMSFrontendLogin.split("|");
			uplNoLog.style.display = "none";
		}
		else {
			uplLog.style.display = "none";
		}
	}
}


function setCoreComboDescription(idCombo){
	if( $("comboDescription"+idCombo) && $(idCombo).selectedIndex > -1 && $(idCombo).options[$(idCombo).selectedIndex].childNodes.length ){
		$("comboDescription"+idCombo).innerHTML = $(idCombo).options[$(idCombo).selectedIndex].childNodes[0].nodeValue;
	}else{
		$("comboDescription"+idCombo).innerHTML = "";
	}
}

function clear_this(obj,val){
	if(obj.value == val) obj.value = '';
	return;
}

function fill_this(obj,val){
	if(obj.value == '') obj.value = val;
	return;
}

function popup(p,p1,p2,p3,p4){

	switch(p){
		case 'contacto':
			PopUpLogin('../contenidos/contacto.html',p);
			break;
			
		case 'login':
			PopUpLogin('../contenidos/login.html',p);
			break;
				
		case 'imprimir_nota':
			PopUpLogin('../contenidos/imprimir.html?idNota='+p1,p);
			break;
			
		case 'imprimir_certificado':
			PopUpLogin('../contenidos/imprimir_certificado.html?idCertificado='+p1,p);
			break;
			
		case 'enviar_nota':
			PopUpLogin('../contenidos/enviar_nota.html?idNota='+p1,p);
			break;
			
		case 'recuperar':
			PopUpLogin('../contenidos/recuperar.html',p);
			break;
		
		case 'punto_de_venta':
			PopUpLogin('../contenidos/punto_de_venta.html?idPuntoVenta='+p1+'&idProducto='+p2+'&idProductoMedida='+p3,p);
			break;
			
		case 'mi_auto':
			PopUpLogin('../contenidos/popup_mi_auto.html?idMiauto='+p1+'&field='+p2+'&texto='+p3+'&tipo='+p4,p);
			break;
			
		case 'terminos':
			PopUpLogin('../contenidos/terminos.html',p);
			break;
			
		case 'recomendar_miauto':
			PopUpLogin('../contenidos/mi_auto_recomendar.html');
			break;		
			
		case 'dot':
			PopUpLogin('../contenidos/dot.html');
			break;
			
		case 'checkPais':
			PopUpLogin('../contenidos/pbCountry.html?_redirect='+p1,p);
			break;
		}
}

function actualizar_neumaticos(){

	PopUpLogin('23-mi-auto_neumaticos.htm','23-mi-auto_neumaticos');
	
	}

function consulta_al_experto(){

	PopUpLogin('33-consulta-al-experto.htm','33-consulta-al-experto');
	
	}

function PopUpLogin(src,iframe_name)
{
	if(!isBackend())
	{
		block(); 

		var strFrame = (isMSIE()) ? "<iframe id='popup_iframe' name='"+iframe_name+"' frameborder='0' allowtransparency='true' scrolling='no'>" : "iframe";
		
		var objPopup = null; 
				
		objPopup = document.createElement(strFrame);
		objPopup.setAttribute("id"	,	"popup_iframe");
		objPopup.setAttribute("name"	,	iframe_name);
		objPopup.setAttribute("frameborder", "0");
		objPopup.setAttribute("scrolling", "no");
		
		objPopup.name = iframe_name;
		objPopup.src	= src;
		objPopup.style.position	= 'absolute';
		
		var width		= f_clientWidth();
		var height	= f_clientHeight() + f_scrollTop();
		
		var top 		= '0';
		var left 		= '0';
		
		objPopup.style.width	= width+'px';
		objPopup.style.height	= height+'px';
		objPopup.style.top 	= top+'px';
		objPopup.style.left = left+'px';
		
		document.documentElement.style.overflow = 'hidden';
		document.body.appendChild(objPopup);
	}
	else
	{
		window.location = src;
	}
}


function block()
{
	window.onmousewheel = document.onmousewheel = wheel;
	document.documentElement.style.overflow = 'hidden';
	
	var objBlock = null;
	if( objBlock == null )
	{
		
		var width		= f_clientWidth();
		var height		= f_clientHeight() + f_scrollTop();
		var top 		= 0;
		var left 		= 0;
		
		var strFrame = (isMSIE()) ? "<iframe id='block_iframe' name='block_iframe' frameborder='0' allowtransparency='true' scrolling='no'>" : "iframe";
		
		objBlock = document.createElement(strFrame);
				
		objBlock.src				= '../interior/block.html';
		objBlock.style.position 	= 'absolute';
		
		objBlock.setAttribute("id"	,	"block_iframe");
		objBlock.setAttribute("name"	,	"block_iframe");
		objBlock.setAttribute("frameborder"	,	"0");
		objBlock.setAttribute("scrolling"		,	"no");
		objBlock.name = 'block_iframe';
		objBlock.style.width	= width+'px';
		objBlock.style.height	= height+'px';
		objBlock.style.top 	= top+'px';
		objBlock.style.left = left+'px';
		
		if(isMSIE()){
			objBlock.style.filter = 'alpha(opacity=80)';
		}else{
			objBlock.style.opacity = 0.8;
		}
		
		document.body.appendChild(objBlock);
		
	}
}




function soyPopup(obj){
	
	if(isBackend()) return false;
	
	obj.body.style.height = '100%';
	
	var div_height 		= 0;
	var div_width 		= 0;
	var div_offsetY 	= f_scrollTopParent();
	var clientHeight 	= f_clientHeight() - div_offsetY;
	var clientWidth  	= f_clientWidth();
	
	// Busco la altura del div exterior
	for(i=0;i<obj.body.childNodes.length;i++)
	{
		if(obj.body.childNodes[i].tagName == 'DIV'){
			div = obj.body.childNodes[i];
			
			div_height = div.offsetHeight;
			div_width = div.offsetWidth;
			break;
		}
	}
	
	
	if(div_height > clientHeight){
		
		div_height = clientHeight - 100;

		div.style.height = div_height+'px';
		div.style.width	 = parseInt(div.offsetWidth + 20)+'px';
		div.style.overflow = 'auto';		
	}
		
	if( window.frameElement )
	{
		var top 	 = div_offsetY + ((clientHeight - div_height - 40)/2);
		var left 	 = (clientWidth - div_width)/2;
		var height = clientHeight; // - vtop;
		
		div.style.position = 'absolute';
		div.style.top  = top+'px';
		div.style.left  = left+'px';
		//div.style.top  = vtop+'px';
	}
	
	
	
	
	
}

function unblock()
{
	objBlock = window.parent.objBlock;
	
	if( objBlock != null ){
		window.parent.document.documentElement.style.overflow = 'auto';
		objBlock.parentNode.removeChild(objBlock);
		delete(objBlock);
		objBlock = null;
	}
}

function closePopUp() {
	
	if(!isBackend()) {
		
		parent.document.documentElement.style.overflow = 'auto';
		
		var objBlock = parent.document.getElementById('block_iframe');
		var objPopup = parent.document.getElementById('popup_iframe');
		
		objBlock.parentNode.removeChild(objBlock);
		objPopup.parentNode.removeChild(objPopup);

	}
	else
	{
		history.back();
	}
	
}

function close(){
	
	parent.window.closePopUp();	
}

function isMSIE(){
	return (navigator.appName == "Microsoft Internet Explorer");
}

function f_clientWidth() {
	
	return document.documentElement.clientWidth;

}
function f_clientHeight() {
	
	return document.documentElement.clientHeight;

}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}

function f_scrollTopParent() {
	return f_filterResults (
		window.parent.window.pageYOffset ? window.parent.window.pageYOffset : 0,
		window.parent.document.documentElement ? window.parent.document.documentElement.scrollTop : 0,
		window.parent.document.body ? window.parent.document.body.scrollTop : 0
	);
}

function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function wheel(event){ 
	//if (event.preventDefault) event.preventDefault();
	//event.returnValue = false;
	return true; 
	}
	

tamanio0=11;
tamanio1=14;

tamanioL0=13;
tamanioL1=16;

function setTamFuente(nodo,tamanio,tamanioL)
{
	// nodo actual
	if(nodo && nodo.style)
	{ nodo.style.fontSize = tamanio+'px'; nodo.style.lineHeight = tamanioL+'px'; }

	// tiene hijos?
	if(nodo.childNodes.length)
	{
		nodo = nodo.firstChild;

		// primer hijo
		if(nodo.style) { nodo.style.fontSize = tamanio+'px'; nodo.style.lineHeight = tamanioL+'px'; }
		setTamFuente(nodo,tamanio,tamanioL);

		// resto de los hijos
		while(nodo = nodo.nextSibling)
		{
			if(nodo.style) { nodo.style.fontSize = tamanio+'px'; nodo.style.lineHeight = tamanioL+'px'; }
			setTamFuente(nodo,tamanio,tamanioL);
		}
	}
}

function tamFuente(operacion)
{
	
  if (operacion == 0)
  {
    if (tamanio0 > 8) { tamanio0--; tamanioL0--; }
    if (tamanio1 > 8) { tamanio1--; tamanioL1--; }

  }
  else if(operacion == 1)
  {
    if (tamanio0 < 20) { tamanio0++; tamanioL0++; }
    if (tamanio1 < 20) { tamanio1++; tamanioL1++; }
  }
  else if(operacion == 2)
  {
  	tamanio0=11;
		tamanio1=14;
		
		tamanioL0=13;
		tamanioL1=16;
  }

	setTamFuente(document.getElementById('copete'),tamanio1,tamanioL1);
	setTamFuente(document.getElementById('cuerpo'),tamanio0,tamanioL0);

}

function isBackend(){
	
	if(typeof(window.parent.document.body) != 'undefined' && window.parent.document.body.id == 'mainBody'){
		//alert('back');
		return true;
	}
	else
	{
		//alert('front');
		return false;
	}
		
}


function isValidEmail(mail){
  if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail))){
  	return false;
  } else {
    return true;
  }
}

function trim(valor) {
	var re = /^\s+|\s+$/;
	var str = (valor? valor: this);
	return str.replace(re, "");
}
String.prototype.trim = trim;

function _post(url)
{
	var _objPost = document.createElement("iframe");
			_objPost.style.display 	= "none";
			_objPost.style.width   	= "100%";
			_objPost.style.height  	= "200";
			_objPost.src 						= url;
	document.body.appendChild(_objPost);
}

var img = "../_templates/images/rate",
		estado = new Array("02", "01"),
		ext = ".jpg";
		

function swapImage(idModulo,idContenido,obj) {
    for (var i = 1; i <= obj; ++i) {
		document.getElementById("S_" + idModulo +'_'+ idContenido + '_' + i).src = img + estado[1] + ext;
    }
}

function starVotar(puntaje) {
	var frm = document.getElementById("frmPrincipal");
	frm.votar.value = puntaje;
	frm.submit();
}

function swapOut(idModulo,idContenido) {
	for (var i = 1; i <= 5; ++i)
		document.getElementById("S_" + idModulo +'_'+ idContenido + '_' + i).src = img + estado[0] + ext;
}

function consultarGalleta(nombre){

	var buscamos = nombre + "=";
	if (document.cookie.length > 0){
		i = document.cookie.indexOf(buscamos);
		if (i != -1) {
			i += buscamos.length;
			j = document.cookie.indexOf(";", i);
			if (j == -1)
				j = document.cookie.length;
			return unescape(document.cookie.substring(i,j));
		}
	}
}

function $()
{
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++)
	{
		var element = arguments[i];
	  if (typeof element == 'string') element = document.getElementById(element);
	  if (arguments.length == 1) return element;
	  elements.push(element);
	}
	return elements;
}

function show(id){ 
	if($(id)) {
			$(id).style.display = 'block';
	}
}
function hide(id){
	if($(id)) {
			$(id).style.display = 'none'; 
	}
}
function submit(id){
	if($(id)) {
		$(id).submit(); 
	}
}
function setValue(id,val){ 
	if($(id)) {
		$(id).value = val;
	}
}

function getCookie(name)
{
  var dc 			= document.cookie;
  var prefix 	= name + "=";
  var begin 	= dc.indexOf("; " + prefix);
  var end = -1;

  if (begin == -1)
  {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
    end = dc.indexOf(';');
  }
  else
  {
  	begin += 2;
  	var end = document.cookie.indexOf(";", begin);
  	if (end == -1)
  	{
    	end = dc.length;
    }
  }
  return unescape(dc.substring(begin + prefix.length, end));
}
