/**********************************************************
*
*     Funciones Java Script comúnes a www.maxmedia.com.ar
*     © 2002 - Lucas Fonzalida
*
**********************************************************/


/**
* Oculta o desoculta campos basado en su id
*
*
*/
function swap(obj_id, mode){
    // Obtiene objeto
    obj = document.getElementById(obj_id);
    // Obtiene estado de display
    obj_display = obj.style.display;
    // Oculta o desoculta objeto
    if(mode){
        obj.style.display = "";
    }else{
        obj.style.display = "none";
    }
}

/* popup detalles.php */
function detalles(url,n){
	newwin = window.open(url,n,'screenX=10,screenY=10,width=400,height=249,menubar=no,status=no,resizable=no');
}

/* popup horarios.php */

function horarios(url,n){
	newwin = window.open(url,n,'screenX=10,screenY=10,width=620; height=400; scrollbars=yes');
}


/* Muestra dialogos de advertencia en "solicitud.php" */

function advertencia(codigo,tiempo){
	switch(codigo){
	case 1:
		if (document.solicitud.redaccion.value == 1){
			alert("Los textos a redactar requieren "+ tiempo +" horas adicionales para su producción.       ");
		}
		break;
		case 2:
		if (document.solicitud.edicion.value >= 1){
			alert("Los comerciales a editar requieren "+ tiempo +" horas adicionales para su producción.       ");
		}
	        break;	
		}
}


/* Verifica si el usuario especificó un nombre descriptivo en "solicitud.php" */


function verificar(titulo){
	if (!titulo){
		alert("Especifique un nombre descriptivo para su spot comercial.    ");
		return false;
	}
	else {
		return true;
	}

}


/* Limpia el contenido de los TextArea en "solicitud.php" */

texto = 1;
aclaraciones = 1;

function limpiar(TextArea){
	switch(TextArea){	
	case 1:
		if(texto){
			document.solicitud.texto.value='';
			texto = 0;
		}
		break;
	case 2:
		if(aclaraciones){
			document.solicitud.aclaraciones.value='';
			aclaraciones = 0;
		}
		break;
	}
}




function form_mode(campo){
		if(campo){
			if(document.solicitud.confirmacion.selectedIndex == 1){
				document.solicitud.method = "post";
				document.solicitud.action = "solicitud.php?mode=SendCopy";
				document.solicitud.submit();
			}
			if(document.solicitud.redaccion.selectedIndex == 1 && document.solicitud.confirmacion.selectedIndex == 0){
				document.solicitud.method = "post";
				document.solicitud.action = "solicitud.php?mode=NoSendCopy";
				document.solicitud.submit();
			}
		}
		else {
			if(document.solicitud.confirmacion.selectedIndex == 1){
				if(document.solicitud.redaccion.selectedIndex == 0){
					document.solicitud.method = "post";
					document.solicitud.action = "solicitud.php";
					document.solicitud.submit();
				}
			}
		}		
}


/**
* Cambia de modo el formulario "solicitud de producción"
*
*
*
*
*/
function form_mode_v2(){
    if(document.solicitud.redaccion.selectedIndex == 1){
	    document.solicitud.method = "post";
		document.solicitud.action = "solicitud.php?mode=SendCopy";
        document.solicitud.submit();
	}else{
 	    document.solicitud.method = "post";
		document.solicitud.action = "solicitud.php";
		document.solicitud.submit();
    }
}






/**
* Submit con links para todo el sitio
*
* @deprecated
*/ 
function SendFormDataTo(target){
	document.forms[0].method = "post";
	document.forms[0].action = target;
	document.forms[0].submit();
}

/* cambia de modo el formulario "Tarifas" enviando los datos al server */
/* deprecated */
function obtener_tarifas(){
	if(document.forms[0].emision.value == 0 && document.forms[0].medio.value == 0 || document.forms[0].emision.value != 0 && document.forms[0].medio.value != 0){
		document.forms[0].submit();
	}
}


/**
* Imprimie
*
* @deprecated
*/ 
function imprimir(){
    alert ('Tenga en cuenta que, para que este documento tenga validez, debe presionar "Enviar".         ');
    print();
    return true;
}


// ----  OPERACIONES NUEVAS ------------------------------------------------------



/**
* Para abrir nuevas ventanas en el navegador
* Versión flexible
*
* @access public
* @param string url Url
* @param string n   Nombre
* @param string p   Parámetros
* @see              http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/open_0.asp?frame=true
* @return void
*/
function winopen(url,n,p){
	newwin=window.open(url,n,p)
}

/**
* Submit para botones img
* 
* @access public
* @param  string  op  Valor de la variable 'op'
* @return void
*/
function post(op){
	document.forms[0].action += "?op=" + op;
	document.forms[0].method = "post";
	document.forms[0].submit();
}

/**
* Precarga imágenes
*
* @author Lucas Fonzalida
* @arg    String  path  Ruta donde se encuentran las imágenes
* @arg    String        Listado de imágenes (cantidad indefinida)
* @return Array
*/
function preloadImages(path){
    var imgs = new Array();
    var args = preloadImages.arguments;
    for(i = 1; i < args.length; i++) {
        imgs[i]     = new Image();
        imgs[i].src = path + args[i];
    }
    return imgs;
}


/**
* WC Versión Java Script
*
*
* @author Lucas Fonzalida
*/
function wc(text){
    var text = new String(text);

    // Comentarios
    var text = text.replace(/\([^\(\)]*\)/g," ");

    // Caracteres latinoamericanos
    var wa = text.match(/[\wÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ]+/g);
    if (wa != null){
        return wa.length;
    }
    return 0;
}

/**
* 
*
*
* 
*/
function id_to_value(source,id){
    for(var i = 0; i < source.length; i++){
        if(source[i][0] == id){
            return source[i][1].valueOf();
        }
    }
    return null;
}


/**
* 
*
*
*
* @author Lucas Fonzalida <contacto@lucasfonzalida.com.ar>
*/
function DBManager(dbData){

    this.dbData = dbData


}
