﻿function validateText(controls)
{    
    for (i = 0; i <= controls.length - 1; i++)
    {
        if (checkRegex($(controls[i][0]).val(), controls[i][1]) == true)
        {
        
            for (k=0; k<=controls.length-1; k++)            
            {
                $(controls[k][0]).css("border-color","#8ab8d6").parent().children(".warningM").remove().css("color","#133e5a");
            }        
        }
        else
        {            
            for (a=0; a<=controls.length-1; a++)            
            {
                $(controls[a][0]).css("border-color","#8ab8d6").parent().children(".warningM").remove().css("color","#133e5a");
            }

            $(controls[i][0]).css("color","#133e5a").focus();
            
            if ($(controls[i][0]).parent().children(".warning").length == 0)
            {
                $(controls[i][0]).css("border-color","#ea943e").parent().append("<img class=\"warningM\" style=\"padding:0; margin:0; position:absolute; background-color:transparent; left:"+ ($(controls[i][0]).position().left + $(controls[i][0]).innerWidth() + 5) +"; top:"+ ($(controls[i][0]).position().top) +"; \" alt=\"boş geçilemez...\" onclick = \"$(this).prev().focus()\" title=\""+ checkRegex($(controls[i][0]).val(), controls[i][1]) +"\" src=\"Images/warning.png\" />")
            }
            return false;
        }
    }
    return true;
}

function checkRegex(_val, _stringFormat)
{
    var valider = new Object();
    valider.Currency = /^\d{1,6}(,\d{3})*\,\d{2}$/;
    valider.figure = /d/;
    valider.number = /^\d+$/;
    valider.emailAddress = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
    valider.phoneNumber = /^\(?\d{3}\)?\s|-\d{3}-\d{4}$/;
    valider.Date = /^([0-9]){2}(\/|-){1}([0-9]){2}(\/|-){1}([0-9]){4}$/;                    
    valider.telephone = /\d{3}\s\d{3}\s\d{2}\s\d{2}$/;
    valider.webAddress = /^((https?\:\/\/)?([\w\d\-]+\.){2,}([\w\d]{2,})((\/[\w\d\-\.]+)*(\/[\w\d\-]+\.[\w\d]{3,4}(\?.*)?)?)?)$/;
    
    if (_stringFormat == 'empty')
    {
        if (_val == '')
            return "Boş Geçilemez";
        else
            return true;
    }
    else if (_stringFormat == 'c')
    {
        if (valider.Currency.exec(_val))
            return true;
        else
            return "Geçersiz Format...";
    }
    else if (_stringFormat == 'f')
    {
        if (valider.figure.exec(_val) || _val == "0")
            return "Geçersiz Bir Değer...";
        else
            return true
    }    
    else if (_stringFormat == 'n')
    {
        if (valider.number.exec(_val))
            return true;
        else
            return "Sadece sayı yazılabilir...";
    }
    else if (_stringFormat == 'e')
    {
        if (valider.emailAddress.exec(_val))
            return true;
        else
            return "Geçersiz E-Mail Adresi Girdiniz...";
    }      
    else if (_stringFormat == 'h')
    {
        if (valider.webAddress.exec(_val))
            return true;
        else
            return "Geçersiz Web Adresi Girdiniz...";
    }     
    else if (_stringFormat == 'd')
    {
        if (valider.Date.exec(_val))
            return true;
        else
            return  "Geçersiz Format...";
    }      
    else if (_stringFormat == 't')
    {
        if (valider.telephone.exec(_val))
            return true;
        else
            return  "Geçersiz Format...";
    }      
}
