
function strint_ValidateForm(frm) {
    var listaLabela = frm.getElementsByTagName("label");
    var strError = "";
    var countError = 0;
    for (i = 0; i < listaLabela.length; i++) {
        if (listaLabela[i].htmlFor != "") {
            if (listaLabela[i].innerHTML.charAt(0) == "*") {
                var selElement = document.getElementById(listaLabela[i].htmlFor);
                if (selElement.type == "select-one") {
                    if ((selElement.selectedIndex == -1) || (selElement.options[selElement.selectedIndex].text == "----------")) {
                        strError += "Opcija '" + listaLabela[i].innerHTML.substring(1) + "' nije izabrana! \n";
                        countError++;
                    }
                }
                else if (selElement.type == "select-multiple") {
                    if (selElement.selectedIndex == -1 || selElement.selectedIndex == null) {
                        strError += "Opcija '" + listaLabela[i].innerHTML.substring(1) + "' nije izabrana! \n";
                        countError++;
                    }
                }
                else {
                    if (selElement.value == "") {
                        strError += "Polje '" + listaLabela[i].innerHTML.substring(1) + "' je prazno! \n";
                        countError++;
                    }
                }
            }
            var rg_Element = document.getElementById(listaLabela[i].htmlFor);
            var rg_DataType = rg_Element.getAttribute("rgvalidate");
            var rg_Value = rg_Element.value;

            switch (rg_DataType) {
            case "email":
                var filter = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i;
                if (!filter.test(rg_Value)) {
                    strError += "Polje '" + listaLabela[i].innerHTML.substring(0) + "' nije ispravna email adresa! \n";
                    countError++;
                }
                break;
            case "url":
                var filter = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
                if (!filter.test(rg_Value)) {
                    strError += "Polje '" + listaLabela[i].innerHTML.substring(0) + "' mora sadrzati ispravnu adresu! \n";
                    countError++;
                }
                break;
            case "numeric":
                var filter = /^\d+$/
                if (!filter.test(rg_Value)) {
                    strError += "Polje '" + listaLabela[i].innerHTML.substring(0) + "' mora imati numericku vrednost! \n";
                    countError++;
                }
                break;
            case "passwordagain":
				var listaPass = frm.getElementsByTagName("input");
				for (e = 0; e < listaPass.length; e++) {
					if(listaPass[e].getAttribute("rgvalidate")=="password"){
						var origPass = listaPass[e];	
					};	
				}
				if(origPass){
						if(rg_Element.value != origPass.value){
							strError += "Polje lozinka i ponovo lozinka se ne poklapaju! \n";
							countError++;
						}
				}
                break;
            case "phone":
                //execute code block 2
                break;
            case "pib":
                var filter = /\w\w\_^\d+$/
                if (!filter.test(rg_Value)) {
                    strError += "Polje '" + listaLabela[i].innerHTML.substring(0) + "' nema validnu vrednost! \n";
                    countError++;
                }
                break;
            case "JMBG":
                var filter = /\b(0[1-9]|[12]\d|3[01])(0[1-9]|1[0-2])(9\d{2}|0[01]\d)\d{6}\b/;
                if (!filter.test(rg_Value)) {
                    strError += "Polje '" + listaLabela[i].innerHTML.substring(0) + "' nema validnu vrednost! \n";
                    countError++;
                }
                break;
            default:
            }
        }
    }
    if (countError > 0) {
        alert(strError);
        return false;
    }
    return true;
}