// JavaScript Document
function depurar(texto){ 
    if(texto.lastIndexOf("@")>=0){
		return texto.substr(0, texto.length-1);
	}
    if(texto.lastIndexOf("ñ")>=0){
		return texto.substr(0, texto.length-1);
	}
    if(texto.lastIndexOf(" ")>=0){
		return texto.substr(0, texto.length-1);
	}
    if(texto.lastIndexOf(",")>=0){
		return texto.substr(0, texto.length-1);
	}
    if(texto.lastIndexOf(".")>=0){
		return texto.substr(0, texto.length-1);
	}
    if(texto.lastIndexOf(";")>=0){
		return texto.substr(0, texto.length-1);
	}
    if(texto.lastIndexOf("'")>=0){
		return texto.substr(0, texto.length-1);
	}
    if(texto.lastIndexOf("´´")>=0){
		return texto.substr(0, texto.length-2);
	}
    if(texto.lastIndexOf("´")>=0){
		return texto.substr(0, texto.length-1);
	}
    if(texto.lastIndexOf("{")>=0){
		return texto.substr(0, texto.length-1);
	}
    if(texto.lastIndexOf("}")>=0){
		return texto.substr(0, texto.length-1);
	}
    if(texto.lastIndexOf("?")>=0){
		return texto.substr(0, texto.length-1);
	}
    if(texto.lastIndexOf("¿")>=0){
		return texto.substr(0, texto.length-1);
	}
    if(texto.lastIndexOf("[")>=0){
		return texto.substr(0, texto.length-1);
	}
    if(texto.lastIndexOf("]")>=0){
		return texto.substr(0, texto.length-1);
	}
	return texto;
}
function OpenBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) { //v3.0
	if(window.screen)if(isCenter)if(isCenter=="true"){
		var myLeft = (screen.width-myWidth)/2;
		var myTop = (screen.height-myHeight)/2;
		features+=(features!='')?',':'';
		features+=',left='+myLeft+',top='+myTop;
	}
	window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight+', scrollbars=0, resizable=0');
}
function valida_pago()
{
	if(!document.form_pago.pago.value)
	{
		alert('Es necesario ingresar la forma de pago');
		document.form_pago.pago.focus;
		return;
	}
	if(!document.form_pago.first_name.value)
	{
		alert('Es necesario ingresar su nombre');
		document.form_pago.first_name.focus;
		return;
	}
	if(!document.form_pago.empresa.value)
	{
		alert('Es necesario ingresar su empresa');
		document.form_pago.empresa.focus;
		return;
	}
	if(!document.form_pago.country.value)
	{
		alert('Es necesario ingresar su país');
		document.form_pago.country.focus;
		return;
	}
	if(!document.form_pago.state.value)
	{
		alert('Es necesario ingresar su estado');
		document.form_pago.state.focus;
		return;
	}
	if(!document.form_pago.city.value)
	{
		alert('Es necesario ingresar su ciudad');
		document.form_pago.city.focus;
		return;
	}
	if(!document.form_pago.address1.value)
	{
		alert('Es necesario ingresar su dirección');
		document.form_pago.address1.focus;
		return;
	}
	if(!document.form_pago.numero.value)
	{
		alert('Es necesario ingresar su número de casa');
		document.form_pago.numero.focus;
		return;
	}
	if(!document.form_pago.zip.value)
	{
		alert('Es necesario ingresar su código postal');
		document.form_pago.zip.focus;
		return;
	}
	if(!document.form_pago.email.value)
	{
		alert('Es necesario ingresar su email');
		document.form_pago.email.focus;
		return;
	}
	else if(!mail(document.form_pago.email.value))
	{
		alert('Su email no es valido');
		document.form_pago.email.focus;
		return;
	}
	if(!document.form_pago.telefono.value)
	{
		alert('Es necesario ingresar su teléfono');
		document.form_pago.telefono.focus;
		return;
	}
	if(document.form_pago.pago.value=='1')
	{
		document.form_pago.action='forma-pago-deposito.php';
		document.form_pago.submit();	
		return
	}
	else
	{
		document.form_pago.action='https://www.paypal.com/cgi-bin/webscr';
		document.form_pago.submit();	
		return
	}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function guarda_datos()
{
    compilar('ajx_paypal.php', '&last_name='+document.form_pago.last_name.value+'&first_name='+document.form_pago.first_name.value+'&zip='+document.form_pago.zip.value+'&address1='+document.form_pago.address1.value+'&empresa='+document.form_pago.empresa.value+'&city='+document.form_pago.city.value+'&state='+document.form_pago.state.value+'&country='+document.form_pago.country.value+'&email='+document.form_pago.email.value+'&numero='+document.form_pago.numero.value+'&telefono='+document.form_pago.telefono.value, 'sub_verificador', 'get', '0', 'carga', '');
}
function sub_verificador(texto)
{
    document.getElementById('carga').innerHTML = '';
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function mail(texto){ 
    var mailres = true;             
    var cadena = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890@._-"; 
     
    var arroba = texto.indexOf("@",0); 
    if ((texto.lastIndexOf("@")) != arroba) arroba = -1; 
     
    var punto = texto.lastIndexOf("."); 
                 
     for (var contador = 0 ; contador < texto.length ; contador++){ 
        if (cadena.indexOf(texto.substr(contador, 1),0) == -1){ 
            mailres = false; 
            break; 
     } 
    } 

    if ((arroba > 1) && (arroba + 1 < punto) && (punto + 2 < (texto.length)) && (mailres == true) && (texto.indexOf("..",0) == -1)) 
    return mailres = true; 
    else 
    return mailres = false; 
}