function AmbVendedor(modo, idprovincia_fijo)
{                        
    var formulario = document.getElementById("panelderecho");        
    var ajaxformulario = nuevoajax();                    
    if((modo == "N") || (modo == "M"))
    {
        var NombreLocal = document.getElementById("NombreLocal").value;
        var Domicilio = document.getElementById("Domicilio_Vendedor").value;
        var CPostal = document.getElementById("CPostal").value;
        var Telefono = document.getElementById("Telefono").value;
        var Email = document.getElementById("Email").value;        
        var SitioWeb = document.getElementById("SitioWeb").value;
        var Movil = document.getElementById("Movil").value;
        var Texto = document.getElementById("Texto").value;
        var Tag = document.getElementById("Tag").value;
        var SubDominio = document.getElementById("SubDominio").value;
        var Saldo = document.getElementById("Saldo").value;
        var IdIdioma = document.getElementById("IdIdioma").value;
        var idprovincia = document.getElementById("idprovincia").value;
        var b_inactivar = document.getElementById("b_inactivar").checked;        
    }                
    switch(modo)
    {
        case "N":
            ajaxformulario.open("GET", "webapp_ambvendedor.php?modo="+modo+"&idprovincia_fijo="+idprovincia_fijo+"&NombreLocal="+NombreLocal+"&Domicilio="+Domicilio+"&CPostal="+CPostal+"&Telefono="+Telefono+"&Email="+Email+"&SitioWeb="+SitioWeb+"&Movil="+Movil+"&Texto="+Texto+"&Tag="+Tag+"&SubDominio="+SubDominio+"&Saldo="+Saldo+"&IdIdioma="+IdIdioma+"&idprovincia="+idprovincia+"&b_inactivar="+b_inactivar, true);                
            break;
        case "M":
            ajaxformulario.open("GET", "webapp_ambvendedor.php?modo="+modo+"&idprovincia_fijo="+idprovincia_fijo+"&NombreLocal="+NombreLocal+"&Domicilio="+Domicilio+"&CPostal="+CPostal+"&Telefono="+Telefono+"&Email="+Email+"&SitioWeb="+SitioWeb+"&Movil="+Movil+"&Texto="+Texto+"&Tag="+Tag+"&SubDominio="+SubDominio+"&Saldo="+Saldo+"&IdIdioma="+IdIdioma+"&idprovincia="+idprovincia+"&b_inactivar="+b_inactivar, true);                
            break;
        case "E":
            ajaxformulario.open("GET", "webapp_ambvendedor.php?modo="+modo, true);                
            break;
        case "P":
            var Email = document.getElementById("Email").value;        
            ajaxformulario.open("GET", "webapp_ambvendedor.php?Email="+Email+"&modo="+modo, true);                
            break;
    }
    ajaxformulario.onreadystatechange=function()
    {
        if (ajaxformulario.readyState==4 && ajaxformulario.status == 200)                
        {
            pageTracker._trackPageview("/webapp_ambvendedor.php");
            var respuesta = ajaxformulario.responseText;                                                    
            if((modo == "N") || (modo == "M"))
            {
                ActualizarNombreLocal();
                LogoVendedor();
                EstadoInactivo();
                CerrarPanelDerecho();                        
            }
            else
            {
                MostrarMensaje(respuesta);
                FormLogin()
            }
        }
    }
    ajaxformulario.send(null);
}

function stopUploadLogo(success, archivodestino, idpersona, mensaje)
    {        
        if (success == 1)
        {
            if(mensaje == "")
            {
                if (archivodestino != "")
                {
                    var ajaxformulario = nuevoajax();                
                    ajaxformulario.open("GET", "webapp_aux_logo_converter.php?archivodestino="+archivodestino+"&idpersona="+idpersona, true);                
                    ajaxformulario.onreadystatechange=function()
                    {
                        if (ajaxformulario.readyState==4 && ajaxformulario.status == 200)
                        {
                            pageTracker._trackPageview("/webapp_aux_logo_converter.php");
                            CerrarPanelDerecho();
                            LogoVendedor();
                            MostrarMensaje(mensaje);
                            EstadoInactivo();
                            LoginPersona(idpersona);
                        }
                    }
                    ajaxformulario.send(null);
                }
                else
                {
                    CerrarPanelDerecho();
                    LogoVendedor();
                    MostrarMensaje(mensaje);
                    EstadoInactivo();
                    LoginPersona(idpersona);
                }
            }
            else
            {
                document.getElementById('f1_upload_process').style.visibility = 'hidden';
                alert(mensaje);
            }
        }
        else
            var result = '<span class="emsg">There was an error during file upload!<\/span><br/><br/>';
        return true;   
    }

    
function ValidaVendedor(modo)
{  
    if(document.getElementById("NombreLocal").value == "")
    {  
        alert("The field Store name can not be left blank.")  
        document.getElementById("NombreLocal").focus();
        return false;
    }
    if (document.getElementById("Logo").value)
    {
        var archivo = document.getElementById("Logo").value;
        var extensiones_permitidas = new Array(".gif", ".jpg", ".png");      
        extension = (archivo.substring(archivo.lastIndexOf("."))).toLowerCase();
        permitida = false;
        for (var i = 0; i < extensiones_permitidas.length; i++)
            if (extensiones_permitidas[i] == extension)
                permitida = true;
        if(!permitida)
        {
            alert("Is not a valid file extension. The extension must be gif, jpg or png.");
            document.getElementById("Logo").focus();
            return false;
        }
    }
    
    if(document.getElementById("Domicilio_Vendedor").value == "")
    {  
        alert("The field Address can not be left blank.")  
        document.getElementById("Domicilio_Vendedor").focus();
        return false;
    }
    if(document.getElementById("Domicilio_Vendedor").value.length > 45)
    {  
        alert("The field Address have exceeded the maximum size allowed (45 characters).")  
        document.getElementById("Domicilio_Vendedor").focus();
        return false;
    }
    if(document.getElementById("Telefono").value == "")
    {  
        alert("The field Phone can not be left blank.")  
        document.getElementById("Telefono").focus();
        return false;
    }
    if(document.getElementById("Email").value == "")
    {  
        alert("The field Email can not be left blank.");
        document.getElementById("Email").focus();
        return false;
    }
    if(modo == "N")
    {
        if(document.getElementById("Email2").value == "")
        {  
            alert("The field Confirm email can not be left blank.");
            document.getElementById("Email2").focus();
            return false;
        }
        if(document.getElementById("Email").value != document.getElementById("Email2").value)
        {  
            alert("The field Email and Confirm email can not be different.");
            document.getElementById("Email2").focus();
            return false;
        }
    }
    if(document.getElementById("SitioWeb").value != "")
    {  
        if(!ValidarUrl(document.getElementById("SitioWeb").value))
        {  
            alert("Is not a valid Website.");
            document.getElementById("SitioWeb").select();
            return false;
        }
    }
    if(document.getElementById("SubDominio").value == "")
    {  
        alert("The field SubDomain can not be left blank.");
        document.getElementById("SubDominio").focus();
        return false;
    }
    if(ValidarDomininio(document.getElementById("SubDominio").value))
    {  
        alert("Is not a valid SubDomain.");
        document.getElementById("SubDominio").select();
        return false;
    }
    if(document.getElementById("SubDominio").value.length > 30)
    {  
        alert("The field SubDomain have exceeded the maximum size allowed (30 characters).")  
        document.getElementById("SubDominio").focus();
        return false;
    }
	 if(document.getElementById("Texto").value =='')
    {  
        alert("The field text can not be left blank.")  
        document.getElementById("Texto").focus();
        return false;
    }
    if(document.getElementById("Texto").value.length > 200)
    {  
        alert("The field text have exceeded the maximum size allowed (200 characters).")  
        document.getElementById("Texto").focus();
        return false;
    }
    /*if(document.getElementById("IdIdioma").value == 0)
    {
        alert("The field Language can not be left blank.");
        document.getElementById("IdIdioma").focus();
        return false;
    }*/
    if(document.getElementById("idpais_Vendedor").value == 0)
    {
        alert("The field Country can not be left blank.");
        document.getElementById("idpais_Vendedor").focus();
        return false;
    }
    if(document.getElementById("idprovincia_Vendedor").value == 0)
    {
        alert("The field City can not be left blank.");
        document.getElementById("idprovincia_Vendedor").focus();
        return false;
    }
	
	
	if (document.getElementById("formmovil").style.display!='none')
	{
		if (document.getElementById("Movil").value!='')
		{
			if(!ValidarUrl(document.getElementById("Movil").value))
			{  
				alert("Is not a valid youtube url.");
				document.getElementById("Movil").select();
				return false;
			}
        }
	}
	if (document.getElementById("formfacebook").style.display!='none')
	{
		if (document.getElementById("FacebookPage").value!='')
		{
			if(!ValidarUrl(document.getElementById("FacebookPage").value))
			{  
				alert("Is not a valid facebook page.");
				document.getElementById("FacebookPage").select();
				return false;
			}
        }
	}
	if (document.getElementById("formblog").style.display!='none')
	{
		if (document.getElementById("BlogPage").value!='')
		{
			if(!ValidarUrl(document.getElementById("BlogPage").value))
			{  
				alert("Is not a valid blog url.");
				document.getElementById("BlogPage").select();
				return false;
			}
        }
	}
	if (document.getElementById("formfoto").style.display!='none')
	{
		if (document.getElementById("Foto").value!='')
		{
			if(!ValidarUrl(document.getElementById("Foto").value))
			{  
				alert("Is not a valid album url.");
				document.getElementById("Foto").select();
				return false;
			}
        }
	}
	if(document.getElementById("formmovil").style.display!='none' && !(ValidarUrlDiferentes(document.getElementById("Movil"))))
		return false;
	if(document.getElementById("formfacebook").style.display!='none' && !(ValidarUrlDiferentes(document.getElementById("FacebookPage"))))
		return false;
	if(document.getElementById("formblog").style.display!='none' && !(ValidarUrlDiferentes(document.getElementById("BlogPage"))))
		return false;
	if(document.getElementById("formfoto").style.display!='none' && !(ValidarUrlDiferentes(document.getElementById("Foto"))))
		return false;
	startUpload();
	return true;

}

function ValidarDomininio(nombre_dominio)
{
    if(nombre_dominio == "www")
        return true;
    for(var j=0; j<nombre_dominio.length; j++)
    {
        var dh = nombre_dominio.charAt(j);
        var hh = dh.charCodeAt(0);
        if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || hh==45 || hh==95)
        {
            if((j==0 || j==nombre_dominio.length-1) && (hh == 45 || hh==95)) //Tu nombre de dominio no puede contener el simbolo guion '-' al principio ni al final
                return true;
        }
        else
            return true; //El dominio no puede contener caracteres especiales
    }    
    return false;
}

function ValidarUrlDiferentes(CampoOrigen)
{
	if(CampoOrigen.value!='')
	{
		if(document.getElementById("formmovil").style.display!='none')
		{
			if((document.getElementById("Movil").value==CampoOrigen.value) && (CampoOrigen.id!=document.getElementById("Movil").id))
			{
				alert("The Websites can not be the same.");
				document.getElementById("Movil").select();
				return false;
			}
		}
		if(document.getElementById("formfacebook").style.display!='none')
		{
			if((document.getElementById("FacebookPage").value==CampoOrigen.value) && (CampoOrigen.id!=document.getElementById("FacebookPage").id))
			{
				alert("The Websites can not be the same.");
				document.getElementById("FacebookPage").select();
				return false;
			}
		}
		if(document.getElementById("formblog").style.display!='none')
		{
			if((document.getElementById("BlogPage").value==CampoOrigen.value) && (CampoOrigen.id!=document.getElementById("BlogPage").id))
			{
				alert("The Websites can not be the same.");
				document.getElementById("BlogPage").select();
				return false;
			}
		}
		if(document.getElementById("formfoto").style.display!='none')
		{
			if((document.getElementById("Foto").value==CampoOrigen.value) && (CampoOrigen.id!=document.getElementById("Foto").id))
			{
				alert("The Websites can not be the same.");
				document.getElementById("Foto").select();
				return false;
			}
		}
	}
	return true;
}

function MostrarAviso()
{
	IdMoneda = document.getElementById("MonedaPrecio").value;
	var ajaxformulario = nuevoajax();
	Aleat = Date();
	ajaxformulario.open("GET", "webapp_aux_valida_vendedor.php?IdMoneda="+IdMoneda+"&Aleat="+Aleat, true);                
    ajaxformulario.onreadystatechange=function()
    {          
        if (ajaxformulario.readyState==4 && ajaxformulario.status == 200)                
        {
            pageTracker._trackPageview("/webapp_aux_valida_vendedor.php");
            if(ajaxformulario.responseText != "OK")
                document.getElementById('Aviso').style.display='block';
            else
				document.getElementById('Aviso').style.display='none';
        }
    }
    ajaxformulario.send(null);	
}