/**
 * @author Attila Kecsmar
 */
/*
 * Password 
 */

function testPassword(passwd) {
	var intScore   = 0

	// 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+10)
	}
	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)
	}
	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)
	}
	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)
	}
	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)
	}
	if (passwd.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/))
	{
		intScore = (intScore+2)
	}
	//kiertekeles
	if (intScore < 15)
	{
	   document.getElementById('weak').innerHTML= "gyenge";
	   document.getElementById('weak').style.background = '#f96464';

	   document.getElementById('medium').innerHTML= "&nbsp;";
	   document.getElementById('medium').style.background = 'none';
	   document.getElementById('strong').innerHTML= "&nbsp;";
	   document.getElementById('strong').style.background = 'none';
	}
	else if (intScore > 14 && intScore < 27)
	{
       document.getElementById('medium').innerHTML= "k&ouml;zepes";
	   document.getElementById('medium').style.background = '#fafc67';
	   
	   document.getElementById('weak').innerHTML= "&nbsp;";
	   document.getElementById('weak').style.background = '#fafc67';
	   document.getElementById('strong').innerHTML= "&nbsp;";
	   document.getElementById('strong').style.background = 'none';	   	   
	}
	else if(intScore > 26)
	{
       document.getElementById('strong').innerHTML= "er&#337;s";
	   document.getElementById('strong').style.background = '#c4ec9c';
	   
	   document.getElementById('weak').innerHTML= "&nbsp;";
	   document.getElementById('weak').style.background = '#c4ec9c';
	   document.getElementById('medium').innerHTML= "&nbsp;";
	   document.getElementById('medium').style.background = '#c4ec9c';
	}
}
/* 
	Clean Form Validation was written from scratch by Marc Grabanski
// http://marcgrabanski.com/code/clean-form-validation
/* Under the Creative Commons Licence http://creativecommons.org/licenses/by/3.0/
	Share or Remix it but please Attribute the authors. */

var cleanValidator = {
	init: function (settings) {
		this.settings = settings;
		this.form = document.getElementById(this.settings["formId"]);
		formInputs = this.form.getElementsByTagName("input");
		
		// change color of inputs on focus
		for(i=0;i<formInputs.length;i++)
		{
			if(formInputs[i].getAttribute("type") != "submit") {
				input = formInputs[i];
				input.style.background = settings["inputColors"][0];
				input.onblur = function () {
					this.style.background = settings["inputColors"][0];
				}
				input.onfocus = function () {
					this.style.background = settings["inputColors"][1];
				}
			}
		};
		this.form.onsubmit = function () {
			error = cleanValidator.validate();
			if(error.length < 1) {
				return true;
			} else {
				cleanValidator.printError(error);
				return false;
			}
		};
	},
    validate: function () {
        error = '';
        validationTypes = new Array("isRequired", "isEmail", "isNumeric");
        for(n=0; n<validationTypes.length; n++) {
            var x = this.settings[validationTypes[n]];
            if(x != null) {
                for(i=0; i<x.length; i++) 
                {
                    inputField = document.getElementById(x[i]);
                    switch (validationTypes[n]) {
                        case "isRequired" :
                        valid = !isRequired(inputField.value);
                        form_name = inputField.title;
                        errorMsg = "kötelező mező";
                        break;
                        case "isEmail" :
                        valid = isEmail(inputField.value);
                        form_name = inputField.title;
                        errorMsg = "hibás";
                        break;
                        case "isNumeric" :
                        valid = isNumeric(inputField.value);
                        form_name = inputField.title;
                        errorMsg = "nem szám";
                        break;
                    }
                    if(!valid) {
                        error += "<div>"+errorMsg+": <span>"+form_name+"</span></div>";
                        inputField.style.background = this.settings["errorColors"][0];
                        inputField.style.border = "1px solid "+this.settings["errorColors"][1];
                    } else {
                        inputField.style.background = this.settings["inputColors"][0];
                        inputField.style.border = '1px solid ' +this.settings["inputBorder"][0];
                    }
                }
            }
        }
        return error;
    },
    printError: function (error) {
        var celElem =  document.getElementById(this.settings["formId"]+'_errorBox');
        celElem.innerHTML = error; 
    }
};

// returns true if the string is not empty
function isRequired(str){
    return (str == null) || (str.length == 0);
}
// returns true if the string is a valid email
function isEmail(str){
    if(isRequired(str)) return false;
    var re = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i
    return re.test(str);
}
// returns true if the string only contains characters 0-9 and is not null
function isNumeric(str){
    if(isRequired(str)) return false;
    var re = /[\D]/g
    if (re.test(str)) return false;
    return true;
}


function WsRadio(param) {
     document.getElementById(param).checked = true;
}
function WsAdrFunc(param,area) {
    if (!area) {
        area=false;
    } 
    if (document.getElementById('WsAdrBlock'+param).className == 'off') {
        document.getElementById("WsAdrBlock" + param).style.display = 'block';
        document.getElementById("WsAdrBlock" + param).className = 'on';
        WsRadio('WsCh1Radio' + param);
        if (area == false) {
            document.getElementById("WsAdrButton" + param).firstChild.innerHTML = 'bezar&aacute;s';
            document.getElementById("WsAdrButton" + param).firstChild.className = 'wsOpenerLink1Close';
        } else {
            document.getElementById("WsAdrButton" + param).firstChild.innerHTML = 'bezar&aacute;s';
            document.getElementById("WsAdrButton" + param).firstChild.className = 'wsOpenerLink1Close';
        }
    } else {
        document.getElementById("WsAdrBlock" + param).style.display = 'none';
        document.getElementById("WsAdrBlock" + param).className = 'off';
        WsRadio('WsCh1Radio' + param);
        if (area == false) {
            document.getElementById("WsAdrButton" + param).firstChild.innerHTML = 'lenyit&aacute;s';
            document.getElementById("WsAdrButton" + param).firstChild.className = 'wsOpenerLink1';  
        } else {
            document.getElementById("WsAdrButton" + param).firstChild.innerHTML = 'adatok megad&aacute;sa';
            document.getElementById("WsAdrButton" + param).firstChild.className = 'wsOpenerLink2';          
        }
    } 
} 


function searchFieldOnFocus(elem) {
    if (elem.title == elem.value) {
        elem.value = '';
    }
}

function searchFieldOnBlur(elem) {
    if (elem.value == '') {
        elem.value = elem.title;
    }
}

