function AbrirCentro(url,nompopup,popW,popH,resizable,scroll){
	w = screen.availWidth;
	h = screen.availHeight;
	var leftPos = (w-popW)/2; topPos = (h-popH)/2;
	leftPos = leftPos - 20;
	topPos = topPos - 20;
	window.open(url,nompopup,'width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos + ',resizable=' + resizable + ',scrollbars=' + scroll );
}
function OverImg(name,source) {
	document.getElementById(name).src = source
}
function OutImg(name,source) {
	document.getElementById(name).src = source
}
function EsEmail(string) {
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {
		return true;
	} else {
		return false;
	}
}
function Montos(string) {
    var valid = "0123456789.";
    var rpta = '';
    for (var i=0; i<string.length; i++){
        val = string.substring(i, i+1);
        if (valid.indexOf(val) > -1) rpta += val;
    }
    return rpta;
}
function Enteros(string) {
    var valid = "0123456789";
    var rpta = '';
    for (var i=0; i<string.length; i++){
        val = string.substring(i, i+1);
        if (valid.indexOf(val) > -1) rpta += val;
    }
    return rpta;
}
function Caracteres(string) {
    var invalid = "!ñÑ´áéíóúÁÉÍÓÚ{}[]";
    var rpta = '';
    for (var i=0; i<string.length; i++){
        inval = string.substring(i, i+1);
        if (invalid.indexOf(inval) > -1) rpta += inval;
    }
    return rpta;
}
function Espacio(string) {
    var invalid = " ";
    var rpta = '';
    for (var i=0; i<string.length; i++){
        inval = string.substring(i, i+1);
        if (invalid.indexOf(inval) > -1) rpta += inval;
    }
    return rpta;
}
function Puntos(string) {
    var invalid = ".";
    var rpta = '';
    for (var i=0; i<string.length; i++){
        inval = string.substring(i, i+1);
        if (invalid.indexOf(inval) > -1) rpta += inval;
    }
    return rpta;
}
function Over(src,color) {
    src.bgColor=color; src.style.cursor="hand";
} 
function Out(src,color) { 
    src.bgColor=color; src.style.cursor="default"; 
}
/* Front End */
function EvaluateL(idioma) {
	tecla = (document.all) ? event.keyCode : event.which;
	if (tecla == 13) { 
		Login(idioma)
	}	
}
function Login(idioma) {
	document.tweddle.action = "validar.php"
	if (idioma == "esp") {
		if (document.tweddle.usuario_login.value == "") {
			alert("Debe de introducir su Usuario.")
			document.tweddle.usuario_login.focus()
			return
		}
		if (document.tweddle.password_login.value == "") {
			alert("Debe de introducir su Clave.")
			document.tweddle.password_login.focus()
			return
		}
		usuario_login = document.tweddle.usuario_login.value
		password_login = document.tweddle.password_login.value		
		ajaxPagina('validar.php?proceso=validacion&usuario=' + usuario_login + '&password=' + password_login)
		if (document.tweddle.error_login.value == 0) {
			alert("El usuario y/o password no concuerdan, intentalo otra vez.")
			return
		} else {
			document.tweddle.target = "_self"	
			document.tweddle.idioma.value = idioma
			document.tweddle.proceso.value = "login"
			document.tweddle.submit()			
		}
	}
	if (idioma == "ing") {
		if (document.tweddle.usuario_login.value == "") {
			alert("You must enter your Username.")
			document.tweddle.usuario_login.focus()
			return
		}
		if (document.tweddle.password_login.value == "") {
			alert("You must enter your Password.")
			document.tweddle.password_login.focus()
			return
		}
		usuario_login = document.tweddle.usuario_login.value
		password_login = document.tweddle.password_login.value		
		ajaxPagina('validar.php?proceso=validacion&usuario=' + usuario_login + '&password=' + password_login)
		if (document.tweddle.error_login.value == 0) {
			alert("The user and / or password do not match, try again.")
			return
		} else {
			document.tweddle.target = "_self"	
			document.tweddle.idioma.value = idioma
			document.tweddle.proceso.value = "login"
			document.tweddle.submit()			
		}
	}
}
function Logout(idioma) {
	document.tweddle.action = "validar.php"
	document.tweddle.target = "_self"	
	document.tweddle.proceso.value = "logout"
	document.tweddle.idioma.value = idioma
	document.tweddle.submit()
}
function EvaluateS(idioma) {
	tecla = (document.all) ? event.keyCode : event.which;
	if (tecla == 13) { 
		Search(idioma)
	}	
}
function Search(idioma) {
	if (idioma == "esp") {
		if (document.tweddle.buscador.value == "") {
			alert("Debe de introducir un valor para realizar la busqueda.")
			document.tweddle.buscador.focus()
			return
		}
		document.tweddle.action = "buscador.php?buscador=" + document.tweddle.buscador.value
	} else {
		if (document.tweddle.buscador.value == "") {
			alert("You must enter a value for the search.")
			document.tweddle.buscador.focus()
			return
		}
		document.tweddle.action = "search.php?buscador=" + document.tweddle.buscador.value
	}
	document.tweddle.target = "_self"	
	document.tweddle.proceso.value = "buscar"
	document.tweddle.submit()
}
function Notification(idioma) {
	if (idioma == "esp") {
		alert("Pronto podras registrarte y ser parte de TweddleFoto.com, escribenos")
	} else {
	}
}
function Password(idioma) {
	if (idioma == "esp") {
		url = "recordar.php"
		AbrirCentro(url,'Remember',600,230,'no','no');
	} else {
		url = "remember.php"
		AbrirCentro(url,'Remember',600,230,'no','no');
	}
}
function SubCategory(id) {
	div = document.getElementById("sc" + id);
	actual = div.style.display;
	if (actual == "") { div.style.display = "none"; } else { div.style.display = ""; }
}
function Type(id) {
	div = document.getElementById("ty" + id);
	actual = div.style.display;
	if (actual == "") { div.style.display = "none"; } else { div.style.display = ""; }
}
function SubCategories(id,idioma) {
	if (idioma == "esp") {
		document.tweddle.action = "subcategorias.php"
	} else {
		document.tweddle.action = "subcategories.php"
	}
	document.tweddle.target = "_self"	
	document.tweddle.proceso.value = "filtrar"
	document.tweddle.categoria.value = id
	document.tweddle.submit()
}
function Types(id,idioma) {
	if (idioma == "esp") {
		document.tweddle.action = "tipos.php"
	} else {
		document.tweddle.action = "types.php"
	}
	document.tweddle.target = "_self"	
	document.tweddle.proceso.value = "filtrar"
	document.tweddle.subcategoria.value = id
	document.tweddle.submit()
}
function Products(id,idioma) {
	if (idioma == "esp") {
		document.tweddle.action = "productos.php"
	} else {
		document.tweddle.action = "products.php"
	}
	document.tweddle.target = "_self"	
	document.tweddle.proceso.value = "filtrar"
	document.tweddle.tipo.value = id
	document.tweddle.submit()
}
function ProductsxS(id,idioma) {
	if (idioma == "esp") {
		document.tweddle.action = "productosxs.php"
	} else {
		document.tweddle.action = "productsxs.php"
	}
	document.tweddle.target = "_self"	
	document.tweddle.proceso.value = "filtrar"
	document.tweddle.subcategoria.value = id
	document.tweddle.submit()
}
function Details(id,idioma) {
	if (idioma == "esp") {
		document.tweddle.action = "detalles.php"
	} else {
		document.tweddle.action = "details.php"
	}
	document.tweddle.target = "_blank"	
	document.tweddle.proceso.value = "filtrar"
	document.tweddle.producto.value = id
	document.tweddle.submit()
}
function ajaxLoad() {
	var xmlHttp;
	try {
		xmlHttp=new XMLHttpRequest();
		return xmlHttp;
	} catch (e) {
	try {
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		return xmlHttp;
		} catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				return xmlHttp;
			} catch (e) {
				alert("Tu navegador no soporta AJAX!");
				return false;
			}
		}
	}
}
function CargarPagina(archivo,capa) {
	var ajax;
	ajax = ajaxLoad();
	
	ajax.open("POST",archivo, true);
	
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.onreadystatechange = function() {
		if (ajax.readyState==1){
			document.getElementById(capa).innerHTML = "<img src='images/loading.gif' align='center' valign='middle' id='loading' name='loading' />";
		}
		if (ajax.readyState == 4) {
			document.getElementById(capa).innerHTML = ajax.responseText;	
		}
	}
	ajax.send(null);
}
function ajaxPagina(archivo) {
	var ajax;
	ajax = ajaxLoad();
	
	ajax.open("POST",archivo, true);
	
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.onreadystatechange = function() {
		if (ajax.readyState == 4) {
			document.tweddle.error_login.value = ajax.responseText
		}
	}
	ajax.send(null);
}

function RecuperaVideo(archivo) {
	var ajax;
	ajax = ajaxLoad();
	
	ajax.open("POST",archivo, true);
	
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.onreadystatechange = function() {
		if (ajax.readyState == 4) {
			respuesta = ajax.responseText;
			valores = respuesta.split('||*||')
			titulo = valores[0];
			resumen = valores[1];
			video = valores[2];						
			var player;
			player = document.getElementById('container_video');
			player.sendEvent("LOAD", {file: "/files_servicios/videos_contenido/" + video});
			player.sendEvent("PLAY","true");
			document.getElementById('titulo_video').innerHTML = titulo
			document.getElementById('resumen_video').innerHTML = resumen
		}
	}
	ajax.send(null);
}


/* Front End */
/* Back End */
function ChequearTodos(chkbox) {
	for (var i=0;i < document.manager.elements.length;i++) {
		var elemento = document.manager.elements[i];		
		if (elemento.type == "checkbox") {
			elemento.checked = chkbox.checked
		}
	}
}
function Cancelar() {
	document.manager.proceso.value = "cancelar"
	document.manager.submit()
}
function Activar(seccion) {
	estado = 0
    for (i = 0; i < document.manager.length; i++)
		if (document.manager.elements[i].name.substring(0,3) == "chk") {
			if (document.manager.elements[i].checked == true) {
				estado = 1
			}
		}
	if (estado == 0) {
		if (seccion == "U") { alert("Debe de seleccionar un Usuario.") }
		if (seccion == "TU") { alert("Debe de seleccionar un Tipo de Usuario.") }
		if (seccion == "C") { alert("Debe de seleccionar un Cliente.") }
		if (seccion == "PV") { alert("Debe de seleccionar un Proveedor.") }
		if (seccion == "CP") { alert("Debe de seleccionar una Categoria.") }
		if (seccion == "SCP") { alert("Debe de seleccionar una SubCategoria.") }
		if (seccion == "TP") { alert("Debe de seleccionar un Tipo.") }
		if (seccion == "FP") { alert("Debe de seleccionar un Fondo.") }
		if (seccion == "T") { alert("Debe de seleccionar un Tamaño.") }
		if (seccion == "P") { alert("Debe de seleccionar un Producto.") }
		if (seccion == "D") { alert("Debe de seleccionar un Descuento.") }
		if (seccion == "PD") { alert("Debe de seleccionar un Pedido.") }
		if (seccion == "B") { alert("Debe de seleccionar un Boletin.") }		
		if (seccion == "M") { alert("Debe de seleccionar un Mailing.") }
		if (seccion == "R") { alert("Debe de seleccionar un Reporte.") }
		if (seccion == "CR") { alert("Debe de seleccionar un Cargo.") }
		if (seccion == "PS") { alert("Debe de seleccionar una Pregunta Secreta.") }
		if (seccion == "TO") { alert("Debe de seleccionar un Tipo de Organizacion.") }
		if (seccion == "RS") { alert("Debe de seleccionar una Responsabilidad.") }
		if (seccion == "BA") { alert("Debe de seleccionar un Banner.") }		
		if (seccion == "N") { alert("Debe de seleccionar un Nosotro.") }		
		if (seccion == "CO") { alert("Debe de seleccionar un Contenido.") }		
		if (seccion == "S") { alert("Debe de seleccionar un Servicio.") }		
		if (seccion == "CS") { alert("Debe de seleccionar una Categoria.") }		
		if (seccion == "ES") { alert("Debe de seleccionar un Elemento.") }		
		if (seccion == "MS") { alert("Debe de seleccionar una Muestra.") }		
		if (seccion == "COS") { alert("Debe de seleccionar una Composicion.") }		
		if (seccion == "WA") { alert("Debe de seleccionar una Web Asociada.") }		
		if (seccion == "VS") { alert("Debe de seleccionar un Video.") }		
		return
	}
	document.manager.activar.value = true
	document.manager.submit()
}
function Desactivar(seccion) {
	estado = 0
    for (i = 0; i < document.manager.length; i++)
		if (document.manager.elements[i].name.substring(0,3) == "chk") {
			if (document.manager.elements[i].checked == true) {
				estado = 1
			}
		}
	if (estado == 0) {
		if (seccion == "U") { alert("Debe de seleccionar un Usuario.") }
		if (seccion == "TU") { alert("Debe de seleccionar un Tipo de Usuario.") }
		if (seccion == "C") { alert("Debe de seleccionar un Cliente.") }
		if (seccion == "PV") { alert("Debe de seleccionar un Proveedor.") }
		if (seccion == "CP") { alert("Debe de seleccionar una Categoria.") }
		if (seccion == "SCP") { alert("Debe de seleccionar una SubCategoria.") }
		if (seccion == "TP") { alert("Debe de seleccionar un Tipo.") }
		if (seccion == "FP") { alert("Debe de seleccionar un Fondo.") }
		if (seccion == "T") { alert("Debe de seleccionar un Tamaño.") }
		if (seccion == "P") { alert("Debe de seleccionar un Producto.") }
		if (seccion == "D") { alert("Debe de seleccionar un Descuento.") }
		if (seccion == "PD") { alert("Debe de seleccionar un Pedido.") }
		if (seccion == "B") { alert("Debe de seleccionar un Boletin.") }		
		if (seccion == "M") { alert("Debe de seleccionar un Mailing.") }
		if (seccion == "R") { alert("Debe de seleccionar un Reporte.") }
		if (seccion == "CR") { alert("Debe de seleccionar un Cargo.") }
		if (seccion == "PS") { alert("Debe de seleccionar una Pregunta Secreta.") }
		if (seccion == "TO") { alert("Debe de seleccionar un Tipo de Organizacion.") }
		if (seccion == "RS") { alert("Debe de seleccionar una Responsabilidad.") }
		if (seccion == "BA") { alert("Debe de seleccionar un Banner.") }		
		if (seccion == "N") { alert("Debe de seleccionar un Nosotro.") }		
		if (seccion == "CO") { alert("Debe de seleccionar un Contenido.") }		
		if (seccion == "S") { alert("Debe de seleccionar un Servicio.") }		
		if (seccion == "CS") { alert("Debe de seleccionar una Categoria.") }		
		if (seccion == "ES") { alert("Debe de seleccionar un Elemento.") }		
		if (seccion == "MS") { alert("Debe de seleccionar una Muestra.") }		
		if (seccion == "COS") { alert("Debe de seleccionar una Composicion.") }		
		if (seccion == "WA") { alert("Debe de seleccionar una Web Asociada.") }		
		if (seccion == "VS") { alert("Debe de seleccionar un Video.") }		
		return
	}
	document.manager.desactivar.value = true
	document.manager.submit()
}
function Eliminar(seccion) {
	estado = 0
    for (i = 0; i < document.manager.length; i++)
		if (document.manager.elements[i].name.substring(0,3) == "chk") {
			if (document.manager.elements[i].checked == true) {
				estado = 1
			}
		}
	if (estado == 0) {
		if (seccion == "U") { alert("Debe de seleccionar un Usuario.") }
		if (seccion == "TU") { alert("Debe de seleccionar un Tipo de Usuario.") }
		if (seccion == "C") { alert("Debe de seleccionar un Cliente.") }
		if (seccion == "PV") { alert("Debe de seleccionar un Proveedor.") }
		if (seccion == "CP") { alert("Debe de seleccionar una Categoria.") }
		if (seccion == "SCP") { alert("Debe de seleccionar una SubCategoria.") }
		if (seccion == "TP") { alert("Debe de seleccionar un Tipo.") }
		if (seccion == "FP") { alert("Debe de seleccionar un Fondo.") }
		if (seccion == "T") { alert("Debe de seleccionar un Tamaño.") }
		if (seccion == "P") { alert("Debe de seleccionar un Producto.") }
		if (seccion == "D") { alert("Debe de seleccionar un Descuento.") }
		if (seccion == "PD") { alert("Debe de seleccionar un Pedido.") }
		if (seccion == "B") { alert("Debe de seleccionar un Boletin.") }		
		if (seccion == "M") { alert("Debe de seleccionar un Mailing.") }
		if (seccion == "R") { alert("Debe de seleccionar un Reporte.") }
		if (seccion == "CR") { alert("Debe de seleccionar un Cargo.") }
		if (seccion == "PS") { alert("Debe de seleccionar una Pregunta Secreta.") }
		if (seccion == "TO") { alert("Debe de seleccionar un Tipo de Organizacion.") }
		if (seccion == "RS") { alert("Debe de seleccionar una Responsabilidad.") }
		if (seccion == "BA") { alert("Debe de seleccionar un Banner.") }		
		if (seccion == "N") { alert("Debe de seleccionar un Nosotro.") }		
		if (seccion == "CO") { alert("Debe de seleccionar un Contenido.") }		
		if (seccion == "S") { alert("Debe de seleccionar un Servicio.") }		
		if (seccion == "CS") { alert("Debe de seleccionar una Categoria.") }		
		if (seccion == "ES") { alert("Debe de seleccionar un Elemento.") }		
		if (seccion == "MS") { alert("Debe de seleccionar una Muestra.") }		
		if (seccion == "COS") { alert("Debe de seleccionar una Composicion.") }		
		if (seccion == "WA") { alert("Debe de seleccionar una Web Asociada.") }		
		if (seccion == "VS") { alert("Debe de seleccionar un Video.") }		
		return
	}
	document.manager.eliminar.value = true
	document.manager.submit()
}
function Suscribir(seccion) {
	estado = 0
    for (i = 0; i < document.manager.length; i++)
		if (document.manager.elements[i].name.substring(0,3) == "chk") {
			if (document.manager.elements[i].checked == true) {
				estado = 1
			}
		}
	if (estado == 0) {
		if (seccion == "C") { alert("Debe de seleccionar un Cliente.") }
		if (seccion == "PV") { alert("Debe de seleccionar un Proveedor.") }
		return
	}
	document.manager.suscribir.value = true
	document.manager.submit()
}
function Desuscribir(seccion) {
	estado = 0
    for (i = 0; i < document.manager.length; i++)
		if (document.manager.elements[i].name.substring(0,3) == "chk") {
			if (document.manager.elements[i].checked == true) {
				estado = 1
			}
		}
	if (estado == 0) {
		if (seccion == "C") { alert("Debe de seleccionar un Cliente.") }
		if (seccion == "PV") { alert("Debe de seleccionar un Proveedor.") }
		return
	}
	document.manager.desuscribir.value = true
	document.manager.submit()
}
function Borrar() {
	document.manager.proceso.value = "borrar"
	document.manager.submit()
}
function Cerrar() {
	tNavegador = navigator.appName
	if (tNavegador == "Microsoft Internet Explorer") {	
		opener.window.manager.action = document.manager.destino.value
		opener.window.manager.submit()
	}
	if (tNavegador == "Netscape") {
		window.opener.document.manager.action = document.manager.destino.value
		window.opener.document.manager.submit()		
	}
	window.close()
}
/* Back End */
