
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 submitForm(formName){
    if (isFirstTimeSubmitted()) {
        document.forms[typeof(formName) != 'undefined' ? formName : 0].submit();
    }
}

function submitTheForm(formName){
    if (isFirstTimeSubmitted()) {
        document.forms[typeof(formName) != 'undefined' ? formName : 0].submit();
    }
}   
// convert all characters to lowercase to simplify testing
    var agt=navigator.userAgent.toLowerCase();

    // *** BROWSER VERSION ***
    // Note: On IE5, these return 4, so use is.ie5up to detect IE5.
    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_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 = 800;
	var	h = 600;
	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("The filling of field '"+fieldName+"' is obligatory!\n Please enter value in that field!");
        field.focus();
		field.select();
		return true;
}
function invValue(field,fieldName){
        alert("The field '"+fieldName+"' contain invalid value!\n Please enter correct value in that field!");
        field.focus();
		field.select();
		return true;
}
function isValidDate(fieldName){

    dateField=eval("document.forms[0]."+fieldName);
	d=dateField.value;
	enteredDate=d.substr(d.lastIndexOf(".")+1)+d.substr(d.indexOf(".")+1,2)+d.substring(0,d.indexOf("."));
    re = /[0123]\d[.][01]\d[.][12]\d\d\d/;
	if (d.search(re)==-1){
	    alert("The date is not correct. Correct date format is dd.mm.yyyy.\nPlease fill correct date!");
	    dateField.focus();
	    dateField.select();
	    return ;
	}
	else {
		return true;
	}


 }

function isFirstDateBeforeSecond(fD,sD){
  	firstDate=fD.substr(fD.lastIndexOf(".")+1)+fD.substr(fD.indexOf(".")+1,2)+fD.substring(0,fD.indexOf("."));
  	secondDate=sD.substr(sD.lastIndexOf(".")+1)+sD.substr(sD.indexOf(".")+1,2)+sD.substring(0,sD.indexOf("."));
    if (firstDate>secondDate){
        return false;
    }
    else{
         return true;
    }
}

function getRadioValue(radio){
	for (i=0;i<radio.length;i++){
	    if (radio[i].checked){
	        return radio[i].value;	
	    }
	}
}

function PrintContents(){
	window.print();
}