// JavaScript Document

podcast_list = new Array();

function document_print(_div) {
	_preview = window.open("/_print.shtml?"+ _div, 'document_print' , 'directories=no,fullscreen=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no,width=780,height=500,top=0,left=0', false);
	setTimeout('_preview.focus();',250);
	}

// JavaScript Document
function view_images(_id, cgi) {
      if (!(cgi)) { cgi = 'news'; }
	_view = window.open("/cgi-bin/"+cgi+".pl?Option=Gallery&Id="+ _id, 'news_view' , 'directories=no,fullscreen=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no,width=620,height=550,top=0,left=0', false);
	setTimeout('_view.focus();',250);
	}

function view_images_(_id, cgi) {
      if (!(cgi)) { cgi = 'news'; }
	//_view = window.open("/cgi-bin/"+cgi+".pl?Option=Gallery&Id="+ _id, 'news_view' , 'directories=no,fullscreen=yes,location=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no,width=620,height=660,top=0,left=0', false);
	//setTimeout('_view.focus();',250);
	window.location ="/cgi-bin/"+cgi+".pl?Option=Gallery&Id="+ _id
	}
/*
function view_images(_id) {
	_view = window.open("/cgi-bin/news.pl?Option=Gallery&Id="+ _id, 'news_view' , 'directories=no,fullscreen=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no,width=620,height=550,top=0,left=0', false);
	setTimeout('_view.focus();',250);
	}
*/
function news_multimedia_show(_id) {
	if (document.getElementById('images'))
		document.getElementById('images').style.display="none";

	if (document.getElementById('audio'))
		document.getElementById('audio').style.display="none";

	if (document.getElementById('video'))
		document.getElementById('video').style.display="none";

	if (document.getElementById('li_images'))
		document.getElementById('li_images').className="";

	if (document.getElementById('li_audio'))
		document.getElementById('li_audio').className="";

	if (document.getElementById('li_video'))
		document.getElementById('li_video').className="";

	document.getElementById(_id).style.display="block";
/*	document.getElementById('li_'+ _id).className="active"; */
	}

function news_podcasts_show(_id) {
//	alert(podcast_list.length);
	for (var n = 0; n < podcast_list.length; n++) {
		document.getElementById(podcast_list[n]).style.display="none";
		//document.getElementById('li_'+ podcast_list[n]).className="";
		}

//	alert(_id);
	if (_id) {
		document.getElementById(_id).style.display="block";
//		document.getElementById('li_'+ _id).className="active";
		}
	}

function podcast_play(_file, _title) {
	var pl3 = document.getElementById('podcast_preview');

	var _obj = {file:_file,title:_title};
	pl3.sendEvent("LOAD",_obj)
	pl3.sendEvent("PLAY","true");
	}
	
//funcionaes de estilo a formulario
function firstFocus() {
	if (document.forms.length > 0) {
		var field = document.forms[0];
		for (i = 0; i < field.length; i++) {
			if ((field.elements[i].type == "text") || (field.elements[i].type == "password") || (field.elements[i].type.toLowerCase().substring(0,6) == "select") || (field.elements[i].type.toString().charAt(0) == "s") && (field.elements[i].value == "")) {
				alert(field.elements[i].type.toLowerCase().substring(0,6));
				document.forms[0].elements[i].focus();
				break;
				}
			}
		}
	}
function defaultCSS() {
	var frm = document.compose

	for (var item = 0; item < frm.elements.length; item++) {
		if ((frm.elements[item].type == 'text') || (frm.elements[item].type == 'textarea') || (frm.elements[item].type.toLowerCase().substring(0,6) == 'select')) {
			frm.elements[item].style.cssText = frm.defaCSS.style.cssText.toLowerCase();
			}
		}
	}
function changeCSS(el) {
	var frm = document.compose
	if (el.style) {
		if (el.style.cssText.toLowerCase() == frm.overCSS.style.cssText.toLowerCase()) 
			el.style.cssText = frm.defaCSS.style.cssText.toLowerCase();
		else 
			el.style.cssText = frm.overCSS.style.cssText.toLowerCase();
		}
	}
function CheckEmail(formelem) {
	arrInvalidCharacters = new Array("?","#","$","%","^","&","*","(",")","!","~","[","]","{","}","\\","'","`",":",";","'","<",">",",","/","\\",")","+","=","|")
	var bValid = true;
	for (i = 0; i < arrInvalidCharacters.length; i++) {
		if (formelem.value.indexOf(arrInvalidCharacters[i]) != -1) {
			bValid = false;
			break;
			}
		}
	if (formelem.value == "" || formelem.value.indexOf("@") == -1 || formelem.value.indexOf(".") == -1) {
		bValid = false;
		}
	return bValid;
	}
window.onload = function() { initialize_form_ide(); show_alerts(); doOnload(); }
var _item_focused;


var UI_Alert = '';
var UI_Action = '';

function show_alerts() {
	if (UI_Alert != '') { alert(UI_Alert); }
	}

function doOnload() {
	if (UI_Action != '') { window.location = UI_Action; }
	}
function showRadio(){
	createCenterWindow('/cgi-bin/station.pl?Opcion=online&Ciudad=LMM&Estacion=RADIO65', 'popup', 400, 255);
}
function createCenterWindow(page, name, w, h) {
	var t = Math.round((screen.height / 2) - (h / 2))
	var l = Math.round((screen.width / 2) - (w / 2))

	nw = window.open(page, name, 'width='+w+',height='+h+',address=no,status=no,resizable=no,scrollbars=no,top='+t+',left='+l)
	setTimeout('nw.focus();',250);
	}
function initialize_form_ide() {
	var _is_not_focused = true;
	if (document.forms.length > 0) {
		//var _frm = document.forms[0];
		
		for (var j=0; j<document.forms.length; j++) {
			_frm = document.forms[j];
			for (var i=0; i < _frm.elements.length; i++) {
				if ((_frm.elements[i].type.toLowerCase() == "textarea")||(_frm.elements[i].type.toLowerCase() == "text")||(_frm.elements[i].type.toLowerCase() == "password")||(_frm.elements[i].type.toLowerCase()== "radio")||(_frm.elements[i].type.toLowerCase()== "checkbox")||(_frm.elements[i].type.toLowerCase()== "file")||(_frm.elements[i].type.toString().charAt(0) == "s") ) {
	
					changeCSS(_frm.elements[i], false);
	
					if (_is_not_focused) {
						if (((_frm.elements[i].type == 'text') || (_frm.elements[i].type == 'textarea' || _frm.elements[i].type == 'password') || (_frm.elements[i].type.toString().charAt(0) == "s")) && (_frm.elements[i].value == "")) {
					
							var _parent		= _frm.elements[i];
							var _can_focus	= true;
							while (_parent) {
								if (_parent.style) {
									if (_parent.style.display.toLowerCase() == 'none' || _parent.style.visibility.toLowerCase() == 'hidden')
										_can_focus = false;
									}
								_parent = _parent.parentNode;
								}
	
							if ( ( ! ( _frm.elements[i].disabled ) ) && _can_focus ) {
								_frm.elements[i].focus()
								_item_focused = _frm.elements[i]
								_is_not_focused = false;
								}
							}
						}
	
					if (document.addEventListener) {
						_frm.elements[i].addEventListener("focus",function(e){ changeCSS_onEvent(e); }, false);
						_frm.elements[i].addEventListener("blur",function(e){ changeCSS_onEvent(e); }, false);		
	//					_frm.elements[i].addEventListener("keydown", enter2tab, false);
						}
					else if (document.attachEvent) {
						_frm.elements[i].attachEvent("onfocus",function(){ changeCSS_onEvent(); });
						_frm.elements[i].attachEvent("onblur",function(){ changeCSS_onEvent(); });
	//				      _frm.elements[i].attachEvent("onkeydown", enter2tab);	
						}
					else {
						alert("This browser doesn't support events handdling");
						}
	
					}
				}
			}
		if(typeof(_item_focused) == 'object') {
			setTimeout("stylize_focused()", 300);
			}
		}
	}
function changeCSS_onEvent(e) {
	var ev = e ? e : window.event;
	if (!ev) { return; }
	var _field = ev.target ? ev.target : ev.srcElement;

	changeCSS(_field);
}
function stylize_focused() {
	if(typeof(_item_focused) == 'object') {
		changeCSS(_item_focused, true);
		}
	}
function changeCSS(_field, init) {
	var _frm = _field.form;
	if (_field.style) {
		if (init) {
			_field.className = "overCSS";
			}
		else {
			if ( _field.className.toLowerCase() == "defacss" ) {
				_field.className = "overCSS";
				}
			else {
				_field.className = "defaCSS";
				}
			}
		}
	}
	
function valid_form(_form) {
	for (var _obj in form_valid_object) {
		if (typeof(form_valid_object[_obj].field) != 'undefined') {
			var _input = form_valid_object[_obj];
			if (_form.elements[_input.field].value == '') {
				if ( ! ( _form.elements[_input.field].disabled ) ) {
					alert(_input.message);
	
					var _parent		= _form.elements[_input.field];
					var _can_focus	= true;
					while (_parent) {
						if (_parent.style) {
							if (_parent.style.display.toLowerCase() == 'none' || _parent.style.visibility.toLowerCase() == 'hidden')
								_can_focus = false;
							}
						_parent = _parent.parentNode;
						}
	
					if ( _can_focus ) {
						_form.elements[_input.field].focus()
						}

					return false;
					}
				}
			}
		}
	_form.submit();
	}
/* funcion par activar texto */
function activText(_obj){
	if (_obj.value == _obj.length-1){
		document.forms['compose'].elements['other_'+_obj.name].disabled = false;
		document.forms['compose'].elements['other_'+_obj.name].focus();
	}else{
		document.forms['compose'].elements['other_'+_obj.name].value = '';
		document.forms['compose'].elements['other_'+_obj.name].disabled = true;
	}
}
/* funcion de validación de formularo */
function sendForm(){
	frm = document.compose;
	if ((frm.company.value == "")&& (frm.contact.value == "")) {
		alert('Debe indicar una compañia o un contacto por lo menos');
		frm.company.focus();
		return false;
	}
	if ((!(frm.lmm.checked))&&(!(frm.gve.checked))&&(!(frm.gml.checked))) {
		alert('Debe seleccionar una ciudad por lo menos');
		frm.lmm.focus();
		return false;
	}
	if (!CheckEmail(frm.email)) {
		alert('Debe capturar un correo electronico valido\n\nEjemplo: info@promored.com.mx');
		frm.email.focus()
		return false;
		}
	if ((frm.phone.value == "")&& (frm.cel.value == "")) {
		alert('Debe indicar un telefono o celular por lo menos');
		frm.phone.focus();
		return false;
	}
	if ((frm.results.value == 5)&& (frm.other_results.value == "")) {
		alert('Debe indicar cual otro resultado busca');
		frm.other_results.focus();
		return false;
	}
	if ((frm.market.value == 7)&& (frm.other_market.value == "")) {
		alert('Debe indicar a cual otro mercado va dirigido');
		frm.other_market.focus();
		return false;
	}
	if ((frm.means.value == 6)&& (frm.other_means.value == "")) {
		alert('Debe indicar en cual otro medio se anuncia');
		frm.other_means.focus();
		return false;
	}				
	frm.submit();			
}
/* funcion de validación de formularo de radioescucha*/
function sendForm_(){
      frm = document.forms[0];
	if (frm.name.value == "") {
		alert('Debe capturar su nombre');
		frm.name.focus();
		return false;
	}
	if (frm.phone.value == "") {
		alert('Debe capturar su teléfono');
		frm.phone.focus();
		return false;
	}
	if (!CheckEmail(frm.mail)) {
		alert('Debe capturar un correo electronico valido\n\nEjemplo: info@promored.com.mx');
		frm.mail.focus()
		return false;
		}
	if (frm.header.value == "") {
		alert('Debe capturar un titulo de su queja o sugerencia');
		frm.title.focus();
		return false;
	}
	if (frm.fullnote.value == "") {
		alert('Debe capturar un titulo de su queja o sugerencia');
		frm.title.focus();
		return false;
	}
	frm.submit();
      alert('Su información ya es analizada por el equipo de promored. Gracias por su confianza');
      window.close();			
}
function CheckEmail(formelem) {
	arrInvalidCharacters = new Array("?","#","$","%","^","&","*","(",")","!","~","[","]","{","}","\\","'","`",":",";","'","<",">",",","/","\\",")","+","=","|")
	var bValid = true;
	for (i = 0; i < arrInvalidCharacters.length; i++) {
		if (formelem.value.indexOf(arrInvalidCharacters[i]) != -1) {
			bValid = false;
			break;
			}
		}
	if (formelem.value == "" || formelem.value.indexOf("@") == -1 || formelem.value.indexOf(".") == -1) {
		bValid = false;
		}
	return bValid;
	}

function newCenterWindow(page, name, w, h) {
	var t = Math.round((screen.height / 2) - (h / 2));
	var l = Math.round((screen.width / 2) - (w / 2));

	nw = window.open(page, name, 'width='+w+',height='+h+',status=no,resizable=no,scrollbars=yes,top='+t+',left='+l);
	setTimeout('nw.focus();',250);
	}

//HUGO-ALTAVOZ

function show_list(opc, obj) {
      if (opc) {
            $("#"+obj).slideDown("slow");
            $("#podcasts-container").slideUp("slow");
            }
      else {
            $("#"+obj).slideUp("slow");
            $("#podcasts-container").slideDown("slow");
            }
      }
//funcion para ocultar divs desde FLASh
function showSwf(_n){
	if (_n == 1){
		document.getElementById("div_lista").style.zIndex = 10000;
		document.getElementById("div_data").style.zIndex = 10001;
	}else{
		document.getElementById("div_lista").style.zIndex = 10001;
		document.getElementById("div_data").style.zIndex = 10000;		
	}
}
//funcion para ocultar divs desde flash
function showChat(_m){
	if (_m == 1){
		document.getElementById("promos").style.zIndex = 1;
		document.getElementById("messages").style.zIndex = 2;
	}else{
		document.getElementById("promos").style.zIndex = 2;
		document.getElementById("messages").style.zIndex = 1;		
	}
}