//**************************************************//

//Funciones para cargar las localidades y provincias//

//**************************************************//

var esIE5 = (document.getElementById ? true : false);

var esIE4 = ((document.all && !esIE5) ? true : false);

var esNS4 = (document.layers ? true : false);

 

var mydate=new Date();

var dateClick;

var myValor = "";

var tiempo = 500;

 

function obtenId(id)

{

    if (esIE5) return document.getElementById(id);

    if (esIE4) return document.all[id];

    if (esNS4) return document.layers[id];

}

 function establecerCodigoLocalidad(idLocalidad, idHidden)
 {

    var objLocalidad = obtenId(idLocalidad);
    var objHidden = obtenId(idHidden);

    if (objLocalidad==null) return true;
    if (objHidden ==null) return true;
    
    objHidden.value = objLocalidad.value;
 }
 

function controlCombo(id)

{

    var obj = obtenId(id);

 

    if (obj==null) alert ('objeto no encontrado: '+id);

    

    dateClick = new Date();

    var diff = dateClick - mydate;

    

    if (diff<tiempo){

          myValor = myValor + String.fromCharCode(window.event.keyCode);

    }

    else

    {

          myValor = String.fromCharCode(window.event.keyCode);

    }

    detectaCambio(id);

    mydate = dateClick;

}

 

function detectaCambio(id)

{

    var obj = obtenId(id);

 

    if (obj==null) alert ('objeto no encontrado: '+id);

    if (dateClick == null) dateClick = mydate;

    var diff = dateClick - mydate;

    if (diff!=0 &&(diff<tiempo || myValor.length==1)){

          var encontrado = false;

          for (i=0;i<obj.options.length;i++)

          {

                if (obj.options[i].text.length==0) continue;

                if (obj.options[i].text.substring(0, myValor.length).toUpperCase()==myValor.toUpperCase())

                {

                      encontrado=true;

                      obj.selectedIndex = [i];

                      window.event.returnValue = false;

                      break;

                }

          }

          if (!encontrado)

                myValor = myValor.substring(0, myValor.length-1);

    }

      

    mydate = dateClick;

}

 
 //Deteccion Nokia S60
var deviceS60 = "series60";
var deviceSymbian = "symbian";
var engineWebKit = "webkit";
var deviceAndroid = "android";
var deviceWinMob = "windows ce";
var deviceBB = "blackberry";
var devicePalm = "palm";

//Initialize our user agent string to lower case.
var uagent = navigator.userAgent.toLowerCase(); //window.navigator.appVersion; //navigator.userAgent.toLowerCase();

function DetectMobile() {
    if (uagent.search("mobile") > -1)
        return true;
    else
        return false;
}

function DetectSafari() {
    if (DetectMobile()) {
        if (uagent.search("safari") > -1)
            return true;
        else
            return false;
    }
    else {
        return false;
    }
}
function DetectIE() {
    if (DetectMobile()) {
        if (uagent.search("msie") > -1)
            return true;
        else
            return false;
    }
    else {
        return false;
    }
}
function DetectFirefox() {
    if (DetectMobile()) {
        if (uagent.search("firefox") > -1)
            return true;
        else
            return false;
    }
    else {
        return false;
    }
}

function DetectHtc() {
    if (uagent.search("htc") > -1)
            return true;
        else
            return false;
}

function DetectAndroid() {
    if (uagent.search("android") > -1)
        return true;
    else
        return false;
}

function DetectSymbian() {
    if (uagent.search("symbianos") > -1)
        return true;
    else
        return false;
}
function DetectBlackBerry() {
    if (uagent.search("blackberry") > -1)
        return true;
    else
        return false;
}

function isPcBrowser() {
    var isMobile = false;
    if (DetectSafari()) {
        isMobile = true;
    }
    if (DetectIE()) {
        isMobile = true;
    }
    if (DetectFirefox()) {
        isMobile = true;
    }
    if (DetectHtc()) {
        isMobile = true;
    }
    if (DetectAndroid()) {
        isMobile = true;
    }
    if (DetectSymbian()) {
        isMobile = true;
    }
    if (DetectBlackBerry()) {
        isMobile = true;
    }
    if (isMobile) {
        if (confirm("Se ha detectado que est\u00E1 navegando desde un dispositivo m\u00F3vil\n\u00BFDesea ir a la p\u00E1gina espec\u00EDfica para smartphones?")) {
            window.location = "http://m.telepizza.es";
        }
    }

}

function emailValido(email)
{
                                                                                
//var filter = /[a-z0-9!#$%&'*+//=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+//=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/;
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var validationOK = document.getElementById("ok_txtmail");
var validationFail = document.getElementById("mal_txtmail");

if (filter.test(email)) {
		validationOK.style.display = "";
		validationFail.style.display = "none";
    }
    else {
	    validationOK.style.display = "none";
        validationFail.style.display = "";
    }
}

function passwordValido(password2)
{
var validationOK = document.getElementById("ok_repetirpass")
var validationFail = document.getElementById("mal_repetirpass")

var password = document.getElementById("ctl00_ContenidoBase_txtPassword").value;

if (password == password2) {
		validationOK.style.display = "";
		validationFail.style.display = "none";
    }
    else {
	    validationOK.style.display = "none";
        validationFail.style.display = "";
    }
}

function testPassword(passwd)
{
		var intScore   = 0
		var strVerdict = "weak"
		
		// PASSWORD LENGTH
		if (passwd.length<5)                         // length 4 or less
		{
			intScore = (intScore+3)
		}
		else if (passwd.length>4 && passwd.length<8) // length between 5 and 7
		{
			intScore = (intScore+6)
		}
		else if (passwd.length>7 && passwd.length<16)// length between 8 and 15
		{
			intScore = (intScore+12)
		}
		else if (passwd.length>15)                    // length 16 or more
		{
			intScore = (intScore+18)
		}
		
		
		// LETTERS
		if (passwd.match(/[a-z]/))                              // [verified] at least one lower case letter
		{
			intScore = (intScore+1)
		}
		
		if (passwd.match(/[A-Z]/))                              // [verified] at least one upper case letter
		{
			intScore = (intScore+5)
		}
		
		// NUMBERS
		if (passwd.match(/\d+/))                                 // [verified] at least one number
		{
			intScore = (intScore+5)
		}
		
		if (passwd.match(/(.*[0-9].*[0-9].*[0-9])/))             // [verified] at least three numbers
		{
			intScore = (intScore+5)
		}
		
		
		// SPECIAL CHAR
		if (passwd.match(/.[!,@,#,$,%,^,&,*,?,_,~]/))            // [verified] at least one special character
		{
			intScore = (intScore+5)
		}
		
									 // [verified] at least two special characters
		if (passwd.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/))
		{
			intScore = (intScore+5)
		}
	
		
		// COMBOS
		if (passwd.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))        // [verified] both upper and lower case
		{
			intScore = (intScore+2)
		}

		if (passwd.match(/([a-zA-Z])/) && passwd.match(/([0-9])/)) // [verified] both letters and numbers
		{
			intScore = (intScore+2)
		}
 
									// [verified] letters, numbers, and special characters
		if (passwd.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/))
		{
			intScore = (intScore+2)
		}

		if(intScore < 16)
		{
		    setPasswordStrength(1);
		}
		else if (intScore > 15 && intScore < 25)
		{
            setPasswordStrength(2);
		}
		else if (intScore > 24 && intScore < 35)
		{
            setPasswordStrength(3);
		}
		else if (intScore > 34 && intScore < 45)
		{
            setPasswordStrength(4);
		}
		else
		{
            setPasswordStrength(5);
		}
	
}