
var formName = "";
var isFormSubmitted  = false;

function clearSubmit(){
    formName = "";
    isFormSubmitted = false;
}

function isFirstTimeSubmitted(){
    var result = false;
    if (!isFormSubmitted) {
        isFormSubmitted = true;
        setTimeout("clearSubmit()", 30000);
        result = true;
    } else {
        alertDoubleSubmit();
    }
    return result;
}

function submitTheForm(formName){
    if (isFirstTimeSubmitted()) {
        document.forms[typeof(formName) != 'undefined' ? formName : 0].submit();
    }
}
function alertDoubleSubmit(){
    alert('Заявката Ви вече е изпратена!');
}
   
 var agt=navigator.userAgent.toLowerCase();
    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);
    var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1));
    var is_nav2 = (is_nav && (is_major == 2));
    var is_nav3 = (is_nav && (is_major == 3));
    var is_nav4 = (is_nav && (is_major == 4));
    var is_nav4up = (is_nav && (is_major >= 4));
    var is_nav45up = (is_nav && (is_minor >= 4.5));
    var is_navonly = (is_nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );
    var is_nav5 = (is_nav && (is_major == 5));
    var is_nav5up = (is_nav && (is_major >= 5));
    var is_nav7down = false;
    var is_nav7 = false;
    var is_nav6 = false;
    var is_nav6_0 = false;
    var is_mozilla = false;
    var netscapeVerRegex = new RegExp();
    if(is_nav4up)
    {
        is_nav7down = true;
        netscapeVerRegex.compile("([.])*netscape([^/])*/", "gi");
        var info = netscapeVerRegex.exec(agt);
        if(info != null)
        {
            var nav_major = parseInt(agt.substr(netscapeVerRegex.lastIndex));
            var nav_minor = parseFloat(agt.substr(netscapeVerRegex.lastIndex));
            is_nav7down = nav_major < 7;
            is_nav7 = nav_major == 7;
            is_nav6 = nav_major == 6;
            is_nav6_0 = nav_minor == 6.0;
        }
        else if(is_nav5up)
        {
            is_mozilla = true;
            is_nav7down = false;
        }
    }

    var is_ie   = (agt.indexOf("msie") != -1);
    var is_ie3  = (is_ie && (is_major < 4));
    var is_ie4  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")==-1) );
    var is_ie4up  = (is_ie  && (is_major >= 4));
    var is_ie5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    var is_ie5up  = (is_ie  && !is_ie3 && !is_ie4);
    var is_ie6 = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.0")!=-1) );

    var is_aol   = (agt.indexOf("aol") != -1);
    var is_aol3  = (is_aol && is_ie3);
    var is_aol4  = (is_aol && is_ie4);

    var is_opera = (agt.indexOf("opera") != -1);
    var is_webtv = (agt.indexOf("webtv") != -1);

   



var isNetscape=((navigator.userAgent.toLowerCase().indexOf('mozilla')!=-1)&&
         (navigator.userAgent.toLowerCase().indexOf('spoofer')==-1)&&
         (navigator.userAgent.toLowerCase().indexOf('compatible')==-1));


function showElement(element_id) {
   if (document.layers){
     eval("document."+element_id).visibility="visible";
   }
   if (document.all){
       eval("document.all."+element_id).style.visibility="visible";
   }
   if (isNetscape && document.getElementById &&
         document.getElementById(element_id) &&
         document.getElementById(element_id).style){
         
             document.getElementById(element_id).style.visibility="visible";
   }
}

function hideElement(element_id) {

   if (document.layers){
     eval("document."+element_id).visibility="hidden";
   }
   if (document.all){
       eval("document.all."+element_id).style.visibility="hidden";
   }
   if (isNetscape && document.getElementById &&
         document.getElementById(element_id) &&
         document.getElementById(element_id).style){
         
              document.getElementById(element_id).style.visibility="hidden";
   }
}


function showHelpWindow(page){
    var wnd=null;
    var w = 600;
    var h = 700;
    wnd=window.open('','Help',
    'scrollbars=1,toolbar=0,location=0,menubar=0,dirctories=0,status=0,resizable=1'+
    ',top=50,left=50'+
    ',width=' + w +
    ',height=' + h +
    ''
    );
    wnd.location.href = page;
    wnd.focus(1);
}

var digits="0123456789";
var phone="+ 0123456789-/()";
var letters="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
+"абвгдежзийклмнопрстуфхцчшщъьщюяАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЬЮЯЭыЫэ'";
var punctuation="!?()-/,.\"\';:";
var other="@#&*%$";
function isInvalidValue(value,pattern){
    ferror=false;
    for (i=0;i<value.length;i++){
        if (pattern.indexOf(value.charAt(i))==-1){
             ferror=true;
             break;
        }
    }

    return ferror;
}

function isInt(value){
    return !isInvalidValue(value,digits);
}

function isPhone(value){
    return !isInvalidValue(value,phone);
}

function isName(value){
    return !isInvalidValue(value,letters+" .");
}
function isString(value){
    return !isInvalidValue(value,letters+" "+digits+punctuation+other);
}
function empty(field,fieldName){
        alert("Попълването на полето '"+fieldName+"' е задължително!\n Моля попълнете това поле!");
        field.focus();
        field.select();
        return true;
}
function invValue(field,fieldName){
        alert("Полето '"+fieldName+"' съдържа невалидна стойност!\n Моля коригирайте стойността в това поле!");
        field.focus();
        field.select();
        return true;
}

function getRadioValue(radio){
    for (i=0;i<radio.length;i++){
        if (radio[i].checked){
            return radio[i].value;  
        }
    }
}
