// general variables
    var lang="PL";
	var errorInPreviouslyFilledField = "False";
	var generalErrorMessage="<b>Pola oznaczone na czerwono zostały wypełnione niepoprawnie.</b>";
	var generalErrorMessageEN="<b>Fields marked red have been incorrectly completed.</b>";
	var placowki = new Array();
	var miasta = new Array();
	var i=0;
	var j=0;
// general arrays

	var fieldNames = new Array ();
	fieldNames[0]='name';
	fieldNames[1]='surname';
	fieldNames[2]='company';
	fieldNames[3]='regon';
	fieldNames[4]='city';
	fieldNames[5]='zipCode11';
	fieldNames[6]='zipCode12';
	fieldNames[7]='email';
	fieldNames[8]='mobileTelephone';
	fieldNames[9]='homeTelephoneSmall';
	fieldNames[10]='homeTelephone';
	fieldNames[11]='notice';
	fieldNames[12]='agreement1';
	fieldNames[13]='agreement2';
	fieldNames[14]='dropDown';
	fieldNames[15]='chkbox1';
	fieldNames[16]='chkbox2';
	fieldNames[17]='chkbox3';
	fieldNames[18]='chkbox4';
	fieldNames[19]='checkBoxNotice';
	fieldNames[20]='nip';
	fieldNames[21]='branchCity';
	fieldNames[22]='branchAddress';		
	fieldNames[23]='function';		
	
	var fieldRequirement = new Array();
	fieldRequirement[0]=1;
	fieldRequirement[1]=1;
	fieldRequirement[2]=1;
	fieldRequirement[3]=0;
	fieldRequirement[4]=1;
	fieldRequirement[5]=1;
	fieldRequirement[6]=1;
	fieldRequirement[7]=0;
	fieldRequirement[8]=0;
	fieldRequirement[9]=0;
	fieldRequirement[10]=0;
	fieldRequirement[11]=0;
	fieldRequirement[12]=0;
	fieldRequirement[13]=0;
	fieldRequirement[14]=0;
	fieldRequirement[15]=0;
	fieldRequirement[16]=0;
	fieldRequirement[17]=0;
	fieldRequirement[18]=0;
	fieldRequirement[19]=0;
	fieldRequirement[20]=0;
	fieldRequirement[21]=0;
	fieldRequirement[22]=0;
	fieldRequirement[23]=0;
	
	var fieldHints = new Array ();
	fieldHints[0]=" ";
	fieldHints[1]="W przypadku nazwisk wieloczłonowych prosimy o wstawienie znaku \"-\" między poszczególnymi członami. ";
	fieldHints[2]="";
	fieldHints[3]=" ";
	fieldHints[4]="Wpisz nazwę miejscowości / miasta, w krórym obecnie mieszkasz.";
	fieldHints[5]="";
	fieldHints[6]="";
	fieldHints[7]="";
	fieldHints[8]="Wpisz numer telefonu bez spacji, np. 111222333";
	fieldHints[9]="Wpisz numer kierunkowy bez spacji, np. 22 dla Warszawy";
	fieldHints[10]="Wpisz numer telefonu bez spacji, np. 7771122";
	fieldHints[11]="Wpisz swoje uwagi lub pytania, które chciałbyś zadać naszemu doradcy.";
	fieldHints[12]="";
	fieldHints[13]=""
	fieldHints[14]=""
	fieldHints[15]=""
	fieldHints[16]=""
	fieldHints[17]=""
	fieldHints[18]=""
	fieldHints[19]=""
	fieldHints[20]=""
	fieldHints[21]="Wybierz miasto, w którym znajduje się oddział, z którego w razie potrzeby będzie Ci najwygodniej skorzystać.";
	fieldHints[22]="Wybierz oddział, z którego w razie potrzeby będzie Ci najwygodniej skorzystać.";
	fieldHints[23]="";
	
	var fieldHintsEN = new Array ();
	fieldHintsEN[0]=" ";
	fieldHintsEN[1]="In case of compound surnames please put \"-\" between parts. ";
	fieldHintsEN[2]="";
	fieldHintsEN[3]=" ";
	fieldHintsEN[4]="Enter name of the city.";
	fieldHintsEN[5]="";
	fieldHintsEN[6]="";
	fieldHintsEN[7]="";
	fieldHintsEN[8]="Enter phone number numer without spaces, e.g. 111222333";
	fieldHintsEN[9]="Enter area code, e.g. 22 for Warsaw";
	fieldHintsEN[10]="Enter phone number numer without spaces, e.g. 7771122";
	fieldHintsEN[11]="Enter your comments or questions here, which you would like to ask our advisor.";
	fieldHintsEN[12]="";
	fieldHintsEN[13]=""
	fieldHintsEN[14]=""
	fieldHintsEN[15]=""
	fieldHintsEN[16]=""
	fieldHintsEN[17]=""
	fieldHintsEN[18]=""
	fieldHintsEN[19]=""
	fieldHintsEN[20]=""
	fieldHintsEN[21]="Select town/city where the most convinient branch for you to use is located.";
	fieldHintsEN[22]="Please select a branch most convenient for you to use if necessary.";
	fieldHintsEN[23]="";

	var fieldErrorMessagesEN = new Array ();
	fieldErrorMessagesEN[0]="Field above contains errors";//general error message
	fieldErrorMessagesEN[1]="Illegal characters used in the field \"Name\".";
	fieldErrorMessagesEN[2]="Field \"Name\" must contain at least 2 characters.";
	fieldErrorMessagesEN[3]="Field \"Name\" must not contain repeated identical letters.";
	fieldErrorMessagesEN[4]="Illegal characters used in the field \"Surname\".";
	fieldErrorMessagesEN[5]="Field \"Surname\" must contain at least 2 characters.";
	fieldErrorMessagesEN[6]="Field \"Surname\" must not contain repeated identical letters.";
	fieldErrorMessagesEN[7]="Illegal characters used in the field \"City\".";
	fieldErrorMessagesEN[8]="Field \"City\" must contain at least 2 characters.";
	fieldErrorMessagesEN[9]="Field \"City\" must not contain repeated identical letters.";
	fieldErrorMessagesEN[10]="Invalid data format in field \"Email\".<br />Enter valid email address, e.g. twojanazwa@twojapoczta.pl ";
	fieldErrorMessagesEN[11]="Field \"Email\" must contain at least 2 characters.";
	fieldErrorMessagesEN[12]="Field \"Email\" must not contain repeated identical letters.";
	fieldErrorMessagesEN[13]="The \"Mobile phone\" should contain 9 digits.";
	fieldErrorMessagesEN[14]="The \"Mobile phone\" should contain 9 digits.";
	fieldErrorMessagesEN[15]="Field \"Mobile phone\" must not contain repeated identical numbers.";
	fieldErrorMessagesEN[16]="Field \"Prefix\" should contain 2 digits.";
	fieldErrorMessagesEN[17]="Field \"Home phone\" should contain 7 digits.";
	fieldErrorMessagesEN[18]="Field \"Home phone\" must not contain repeated identical numbers.";
	fieldErrorMessagesEN[19]="Field \"Prefix\" should contain 2 digits.";
	fieldErrorMessagesEN[20]="Field \"Office phone\" should contain 7 digits.";
	fieldErrorMessagesEN[21]="Field \"Office phone\" must not contain repeated identical numbers.";
	fieldErrorMessagesEN[22]="";
	fieldErrorMessagesEN[23]="You must choose one option.";
	fieldErrorMessagesEN[24]="Provide at least one phone number.";
	fieldErrorMessagesEN[25]="The first postal code field should contain 2 digits.";
	fieldErrorMessagesEN[26]="The second postal code field should contain 3 digits.";
	fieldErrorMessagesEN[27]="Illegal characters used in the field \"Company name\".";
	fieldErrorMessagesEN[28]="Field \"Company name\" must contain at least 2 characters.";
	fieldErrorMessagesEN[29]="Field \"Company name\" must not contain repeated identical letters.";
	fieldErrorMessagesEN[30]="Select product you are interested in.";
	fieldErrorMessagesEN[31]="Field \"Function\" must not contain repeated identical letters.";
	fieldErrorMessagesEN[32]="Please fill this field in and specify what type of product are you interested in.";
	fieldErrorMessagesEN[33]="This field is required.";
	fieldErrorMessagesEN[34]="Field \"Function\" must contain at least 2 characters.";
	fieldErrorMessagesEN[35]="Illegal characters used in the field \"Function\".";
	fieldErrorMessagesEN[36]="NIP number does not contain enought digits.";
	fieldErrorMessagesEN[37]="Check digit in provided NIP number is not valid.";
	fieldErrorMessagesEN[38]="REGON number does not contain enought digits.";
	fieldErrorMessagesEN[39]="Check digit in provided REGON number is not valid.";
	fieldErrorMessagesEN[40]="Branch selection is required.";
	
	var fieldErrorMessages = new Array ();
	fieldErrorMessages[0]="W powyższym polu znajdują się błędy.";//general error message
	fieldErrorMessages[1]="W polu\"Imię\" zastosowano niedozwolone znaki.";
	fieldErrorMessages[2]="Pole \"Imię\" musi zawierać minimum 2 znaki.";
	fieldErrorMessages[3]="Pole \"Imię\" nie może zawierać powtarzających się identycznych liter.";
	fieldErrorMessages[4]="W polu\"Nazwisko\" zastosowano niedozwolone znaki.";
	fieldErrorMessages[5]="Pole \"Nazwisko\" musi zawierać minimum 2 znaki.";
	fieldErrorMessages[6]="Pole \"Nazwisko\" nie może zawierać powtarzających się identycznych liter.";
	fieldErrorMessages[7]="W polu\"Miasto\" zastosowano niedozwolone znaki.";
	fieldErrorMessages[8]="Pole \"Miasto\" musi zawierać minimum 2 znaki.";
	fieldErrorMessages[9]="Pole \"Miasto\" nie może zawierać powtarzających się identycznych liter.";
	fieldErrorMessages[10]="Pole \"Email\" ma nieprawidłowy format. <br />Podaj prawidłowy adres e-mail, np. twojanazwa@twojapoczta.pl ";
	fieldErrorMessages[11]="Pole \"Email\" musi zawierać minimum 2 znaki.";
	fieldErrorMessages[12]="Pole \"Email\" nie może zawierać powtarzających się identycznych liter.";
	fieldErrorMessages[13]="Pole \"Telefon komórkowy\" powinno zawierać 9 cyfr";
	fieldErrorMessages[14]="Pole \"Telefon komórkowy\" powinno zawierać 9 cyfr";
	fieldErrorMessages[15]="Pole \"Telefon komórkowy\" nie może zawierać powtarzających się identycznych cyfr.";
	fieldErrorMessages[16]="Pole \"Prefiks\" powinno zawierać 2 cyfry.";
	fieldErrorMessages[17]="Pole \"Telefon domowy\" powinno zawierać 7 cyfr.";
	fieldErrorMessages[18]="Pole \"Telefon domowy\" nie może zawierać powtarzających się identycznych cyfr.";
	fieldErrorMessages[19]="Pole \"Prefiks\" powinno zawierać 2 cyfry.";
	fieldErrorMessages[20]="Pole \"Telefon służbowy\" powinno zawierać 7 cyfr.";
	fieldErrorMessages[21]="Pole \"Telefon służbowy\" nie może zawierać powtarzających się identycznych cyfr.";
	fieldErrorMessages[22]="";
	fieldErrorMessages[23]="Musisz wybrać jedną z opcji.";
	fieldErrorMessages[24]="Wymagane jest podanie przynajmniej jednego numeru telefonu.";
	fieldErrorMessages[25]="Pole pierwsze kodu pocztowego powinno składać się z 2 cyfr. ";
	fieldErrorMessages[26]="Pole drugie kodu pocztowego powinno składać się z 3 cyfr. ";
	fieldErrorMessages[27]="W polu\"Nazwa firmy\" zastosowano niedozwolone znaki.";
	fieldErrorMessages[28]="Pole \"Nazwa firmy\" musi zawierać minimum 2 znaki.";
	fieldErrorMessages[29]="Pole \"Nazwa firmy\" nie może zawierać powtarzających się identycznych liter.";
	fieldErrorMessages[30]="Musisz zaznaczyć co najmniej jedno pole.";
	fieldErrorMessages[31]="Pole \"Funkcja\" nie może zawierać powtarzających się identycznych liter.";
	fieldErrorMessages[32]="Proszę uzupełnić pole i określić jakiego typu produkt Cię interesuje.";
	fieldErrorMessages[33]="To pole jest wymagane.";
	fieldErrorMessages[34]="Pole \"Funkcja\" musi zawierać minimum 2 znaki.";
	fieldErrorMessages[35]="W polu\"Funkcja\" zastosowano niedozwolone znaki.";
	fieldErrorMessages[36]="NIP zawiera nieprawidłową ilość cyfr.";
	fieldErrorMessages[37]="W numerze NIP nie zgadza się cyfra kontrolna. Proszę sprawdź wprowadzony numer.";
	fieldErrorMessages[38]="REGON zawiera nieprawidłową ilość cyfr.";
	fieldErrorMessages[39]="W numerze REGON nie zgadza się cyfra kontrolna. Proszę sprawdź wprowadzony numer.";	
	fieldErrorMessages[40]="Wybor oddziału jest wymagany.";	
// functions

		function prepareBranches(){
		placowki[i]=new Array(3);		
		placowki[i][0]="";
		placowki[i][1]="--";
		placowki[i][2]="";
	}
	
	function fillBranchesAndCities(elementColumn0,elementColumn1,elementColumn2){
		i++;
		placowki[i]=new Array(3);
		placowki[i][0]=elementColumn1;
		placowki[i][1]=elementColumn2;
		placowki[i][2]=elementColumn0;
	
		miasta[j]=new Array(2);						
		miasta[j][0]=elementColumn0;
		miasta[j][1]=elementColumn1;
		j++;
		
	}

	//function to clear select
	function clearBranchSelect(select){
		for( i=select.length-1; i >= 0; i-- ){
			select.options[i] = null;
		}
	}

	//function to clear error in branch combobox
	function clearBranchError(){
		var branchCity=document.getElementById('branchAddress');
		if (branchCity.value!=''){
			branchCity.style.backgroundColor='#FFFFFF';
			showHideBoth('branchCity','hide');
			showHideBoth('branchAddress','hide');
		}
	}
	
	
	// function to fill select	
	function fillSelect(id, select,id_miasta){
	  clearBranchSelect(select);
	var n = true;
	var i=0;
		for (var m=0; m<placowki.length; m++) {
			if((placowki[m][0])==(id)){
				var opt = document.createElement("OPTION");
				opt.text=placowki[m][1];
				if (m > 0){
					opt.value=placowki[m][2] + '---' + placowki[m][1];
				}
				else{
					opt.value='---';
 				}
				select.options.add(opt);
				if(i==0){
					document.getElementById(id_miasta).value=placowki[m][2];					
				}
				i++;			
			}
		} 
	}
	
	
	
	
	// function to set proper hint in assistant box
	function setHint(fieldName) {
		
		//  check which field was passed
		for (counter in fieldNames) {
			if (fieldNames[counter]==fieldName) {
			fieldNumber=counter;
			}
		}
		
		// if telephone hide general error message
		if (fieldName.indexOf('Telephone')!=-1) showHideError('generalTelephone', 'hide');
		
		//  input hint
		if (errorInPreviouslyFilledField == "False") { // check if there were error message
			if(lang=='PL'){
				document.getElementById('assistant-text').innerHTML=fieldHints[fieldNumber];
			}else{
				document.getElementById('assistant-text').innerHTML=fieldHintsEN[fieldNumber];
			}
		}
		else{
			if(lang=='PL'){
				document.getElementById('assistant-text').innerHTML=generalErrorMessage+"<br /><p> </p><br />"+fieldHints[fieldNumber];
			}else{
				document.getElementById('assistant-text').innerHTML=generalErrorMessageEN+"<br /><p> </p><br />"+fieldHintsEN[fieldNumber];
			}
			errorInPreviouslyFilledField="False";
		}
		fieldCheck= SetFieldCheck(fieldName);
		
		if (document.getElementById (fieldCheck+'Exclamation')){
			if (document.getElementById (fieldCheck+'Exclamation').style.display!='block') {
				if((fieldName.indexOf('zipCode11')!=-1)){
					document.getElementById (fieldName).style.backgroundColor='#E4EDFC'; // set color if there were en error, you can't  set it in the style
					document.getElementById ('zipCode12').style.backgroundColor='#E4EDFC';
				}else{
					document.getElementById (fieldName).style.backgroundColor='#E4EDFC'; // set color if there were en error, you can't  set it in the style
				}
			}
		}
	}
	
	// function to set proper id value for error and exclamation - problem occurs for telephone fields with extention number (1 error field - 2 telephone fields)
	function SetFieldCheck(whichField){

		if ((whichField.indexOf('homeTelephoneSmall')!=-1) || (whichField.indexOf('officeTelephoneSmall')!=-1)) { // check if this was short field 
			returnValue = whichField.substring (0,whichField.length-5);
		}else {
			returnValue=whichField;
		}
		return returnValue
	}
	
	//clear spaces from passed text
	function Trim(str, chars) {
		return Ltrim(Rtrim(str, chars), chars);
	}
	
	// clear spaces from left side
	function Ltrim(str, chars) {
		chars = chars || "\\s";
		return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
	}
	
	// clear spaces from right side
	function Rtrim(str, chars) {
		chars = chars || "\\s";
		return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
	}
	
	//function to block values which are not allowed
	function checkIfProperKeyValueWasPassed(e,whichPatternIsAllowed){
		// set event according to the browser 
		if(!e) e=window.event;
		// set proper object according to the browser
		if (!e.target) e.target=e.srcElement; 
		
		

		
		// set proper pattern to compare
		switch(whichPatternIsAllowed){
			case 1:
				patternString=/[^0-9]+/;
				break
			case 2:
				patternString=/[^a-zA-ZąĄżŻźŹńŃłŁśŚęĘóÓćĆ]+/;
				break
			case 3:
				patternString=/[^a-zA-ZąĄżŻźŹńŃłŁśŚęĘóÓćĆ\- ]+/;
				break
			case 4:
				patternString=/[^0-9a-zA-Z-_@.]+/;
				break
			case 5:
				patternString=/[^a-zA-ZąĄżŻźŹńŃłŁśŚęĘóÓćĆ\-\./ ]+$/;
				break
			case 6:
				patternString=/[^0-9a-zA-ZąĄżŻźŹńŃłŁśŚęĘóÓćĆ\-\./ ]+$/;
				break
		}
		if (!((e.keyCode==37) || (e.keyCode==39) || (e.keyCode==8))){
			var fieldRefferingTo = document.getElementById (e.target.id);
			var fieldValue = Ltrim(fieldRefferingTo.value);
			var clearedString=fieldValue.replace(patternString,"");
			  if (clearedString!=fieldValue){ 
	                fieldRefferingTo.value=clearedString; 
	        } 

		}
		
	}
	
	//function to check if field is empty
	function checkIfEmpty (fieldValue){
		return fieldValue.length
	}
	
	// check if pattern is proper according to regular expressions
	function checkValidationPattern (patternToUse, fieldValueUsed) {
		var validationPatternStatus=1;
		if (patternToUse.test(fieldValueUsed)==true) validationPatternStatus=0
		return validationPatternStatus
	}
	
	//check if field length is not to short
	function checkLength (fieldValueUsed,minimumValue){
		if(!minimumValue) minimumValue=1;
		if (fieldValueUsed.length<=minimumValue){
			return 1
		}
		else{
			return 0
		}	
	}
	
	//check if field contains the same letters
	function checkIfLettersOfTheSameType(fieldValueUsed){
		letterToMatch=fieldValueUsed.substring(0,1)
		patternLength=fieldValueUsed.length;
		pattern="^["+letterToMatch+"]{"+patternLength+"}$";
		patternToMatch= new RegExp(pattern);
		var status=checkValidationPattern (patternToMatch,fieldValueUsed);
		if (status!=0){
			return  0
		}
		else{
			return 1
		}
	}
	
	// function check all neccessary options for specific field and return errorcode
	function checkAllNecessaryValidations (fieldValue, fieldType){
		var errorCodeReturned=-1;
		// make necessary checks according to the field type
		switch (fieldType){
		  
		  case "branchAddress":
				if (checkIfEmpty(fieldValue) ==0 || fieldValue == '---' ){
				    errorCodeReturned=40;
				}
				break	
		    case "regon":
				patternString1=/^[0-9]{9}$/;
				patternString2=/^[0-9]{14}$/;
				if (checkIfEmpty(fieldValue)>0){
					if (checkValidationPattern(patternString1,fieldValue) ==0 || checkValidationPattern(patternString2,fieldValue)==0){
						if (checkRegon(fieldValue)>0){
						    errorCodeReturned=39;
						}
					}
					else{
					    errorCodeReturned=38;
					}
				}
				break			  
		  
			case "nip":
				patternString=/^[0-9]{10}$/;
				if (checkIfEmpty(fieldValue)>0){
					if (checkValidationPattern(patternString,fieldValue)!=0){
						errorCodeReturned=36;
					}
					else{
						if (checkNIP(fieldValue)>0){
							errorCodeReturned=37;
						}
					}
				}
				break			  
			case "name":
				patternString=/^[a-zA-ZąĄżŻźŹńŃłŁśŚęĘóÓćĆ]+((( |\-){1}[a-zA-ZąĄżŻźŹńŃłŁśŚęĘóÓćĆ]+)+)?$/;
				if (checkIfEmpty(fieldValue)>0){
					if (checkValidationPattern(patternString,fieldValue)!=0){
						errorCodeReturned=1;
					}
					else{
						if (checkLength(fieldValue)>0){
							errorCodeReturned=2;
						}
						else{
							if (checkIfLettersOfTheSameType(fieldValue)>0) errorCodeReturned=3;
						}
					}
				}
				break
			case "surname":
				patternString=/^[a-zA-ZąĄżŻźŹńŃłŁśŚęĘóÓćĆ]+((( |\-){1}[a-zA-ZąĄżŻźŹńŃłŁśŚęĘóÓćĆ]+)+)?$/;
				if (checkIfEmpty(fieldValue)>0){
					if (checkValidationPattern(patternString,fieldValue)!=0){
						errorCodeReturned=4;
					}
					else{
						if (checkLength(fieldValue)>0){
							errorCodeReturned=5;
						}
						else{
							if (checkIfLettersOfTheSameType(fieldValue)>0) errorCodeReturned=6;
						}
					}
				}
				break
			case "city":
				patternString=/^[a-zA-ZąĄżŻźŹńŃłŁśŚęĘóÓćĆ\./]+((([-][a-zA-ZąĄżŻźŹńŃłŁśŚęĘóÓćĆ\./]+)+)|(([ ][a-zA-ZąĄżŻźŹńŃłŁśŚęĘóÓćĆ\./]+)+))?$/;
				if (checkIfEmpty(fieldValue)>0){
					if (checkValidationPattern(patternString,fieldValue)!=0){
						errorCodeReturned=7;
					}
					else{
						if (checkLength(fieldValue)>0){
							errorCodeReturned=8;
						}
						else{
							if (checkIfLettersOfTheSameType(fieldValue)>0) errorCodeReturned=9;
						}
					}
				}
				break
			case "email":
				patternString=/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*\@[0-9a-zA-Z\_-]+(\.[a-zA-Z]+)*(\.([a-zA-Z]{2,6})){1}$/;
				if (checkIfEmpty(fieldValue)>0){
					if (checkValidationPattern(patternString,fieldValue)!=0){
						errorCodeReturned=10;
					}
					else{
						if (checkLength(fieldValue)>0){
							errorCodeReturned=11;
						}
						else{
							if (checkIfLettersOfTheSameType(fieldValue)>0) errorCodeReturned=12;
						}
					}
				}
				break
			case "mobileTelephone":
				patternString=/^[0-9]{9}$/;
				if (checkIfEmpty(fieldValue)>0){
					if (checkValidationPattern(patternString,fieldValue)!=0){
						errorCodeReturned=13;
					}
					else{
						if (checkLength(fieldValue)>0){
							errorCodeReturned=14;
						}
						else{
							if (checkIfLettersOfTheSameType(fieldValue)>0) errorCodeReturned=15;
						}
					}
				}
				break
			case "company":
				patternString=/^[0-9a-zA-ZąĄżŻźŹńŃłŁśŚęĘóÓćĆ]+((([-][0-9a-zA-ZąĄżŻźŹńŃłŁśŚęĘóÓćĆ]+)+)|(([ ][0-9a-zA-ZąĄżŻźŹńŃłŁśŚęĘóÓćĆ]+)+))?$/;
				if (checkIfEmpty(fieldValue)>0){
					if (checkValidationPattern(patternString,fieldValue)!=0){
						errorCodeReturned=27;
					}
					else{
						if (checkLength(fieldValue)>0){
							errorCodeReturned=28;
						}
						else{
							if (checkIfLettersOfTheSameType(fieldValue)>0) errorCodeReturned=29;
						}
					}
				}
				break
			case "homeTelephoneSmall":
				patternString=/^[0-9]{2}$/;
				if (checkIfEmpty(fieldValue)>0){
					if (checkValidationPattern(patternString,fieldValue)!=0){
						errorCodeReturned=16;
					}
				}
				break
			case "zipCode11":
				patternString=/^[0-9]{2}$/;
				if (checkIfEmpty(fieldValue)>0){
					if (checkValidationPattern(patternString,fieldValue)!=0){
						errorCodeReturned=25;
					}
					
				}
				break
			case "zipCode12":
				patternString=/^[0-9]{3}$/;
				if (checkIfEmpty(fieldValue)>0){
					if (checkValidationPattern(patternString,fieldValue)!=0){
						errorCodeReturned=26;
					}
					
				}
				break
			case "homeTelephone":
				patternString=/^[0-9]{7}$/;
				if (checkIfEmpty(fieldValue)>0){
					if (checkValidationPattern(patternString,fieldValue)!=0){
						errorCodeReturned=17;
					}
					else{
							if (checkIfLettersOfTheSameType(fieldValue)>0) errorCodeReturned=18;
					}
				}
				break
			case "officeTelephoneSmall":
				patternString=/^[0-9]{2}$/;
				if (checkIfEmpty(fieldValue)>0){
					if (checkValidationPattern(patternString,fieldValue)!=0){
						errorCodeReturned=19;
					}
				}
				break
			case "officeTelephone":
				patternString=/^[0-9]{7}$/;
				if (checkIfEmpty(fieldValue)>0){
					if (checkValidationPattern(patternString,fieldValue)!=0){
						errorCodeReturned=20;
					}
					else{
							if (checkIfLettersOfTheSameType(fieldValue)>0) errorCodeReturned=21;
					}
				}
				break
			case "function":
				patternString=/^[0-9a-zA-ZąĄżŻźŹńŃłŁśŚęĘóÓćĆ]+((([-][0-9a-zA-ZąĄżŻźŹńŃłŁśŚęĘóÓćĆ]+)+)|(([ ][0-9a-zA-ZąĄżŻźŹńŃłŁśŚęĘóÓćĆ]+)+))?$/;
				if (checkIfEmpty(fieldValue)>0){
					if (checkValidationPattern(patternString,fieldValue)!=0){
						errorCodeReturned=35;
					}
					else{
						if (checkLength(fieldValue)>0){
							errorCodeReturned=34;
						}
						else{
							if (checkIfLettersOfTheSameType(fieldValue)>0) errorCodeReturned=31;
						}
					}
				}
				break
		}
		return errorCodeReturned
	}
	
	// do all necessary things when status is OK
	function setStatusOK (fieldName){
		if (document.getElementById (fieldName+'Exclamation').style.display=='inline') { // check if previously there was an error shown
				document.getElementById (fieldName+'Exclamation').style.visibility='hidden'; // hide exclamation
				document.getElementById (fieldName+'Exclamation').style.display='none';
				document.getElementById (fieldName+'Error').style.visibility='hidden'; // hide error message
				document.getElementById (fieldName+'Error').style.display='none';
		}
		document.getElementById(fieldName).style.backgroundColor='#ffffff'; // reset field color to standard
		errorInPreviouslyFilledField = "False";
	}
	
	//do all necessary things when status is NOK
	function setStatusNOK(fieldName,fieldNumber){
		if(lang=='PL'){
			if(!fieldErrorMessages[fieldNumber]) fieldErrorMessages[fieldNumber]=fieldErrorMessages[0];
		}else{
			if(!fieldErrorMessagesEN[fieldNumber]) fieldErrorMessagesEN[fieldNumber]=fieldErrorMessagesEN[0];
		}
		document.getElementById (fieldName+'Exclamation').style.visibility='visible'; // show exclamation
		document.getElementById (fieldName+'Exclamation').style.display='inline';
		if(lang=='PL'){
			document.getElementById (fieldName+'Error').innerHTML="<p>"+fieldErrorMessages[fieldNumber]+"</p>";
		}else{
			document.getElementById (fieldName+'Error').innerHTML="<p>"+fieldErrorMessagesEN[fieldNumber]+"</p>";
		}
		document.getElementById (fieldName+'Error').style.visibility='visible'; // show  error
		document.getElementById (fieldName+'Error').style.display='block';
		if(lang=='PL'){
			document.getElementById('assistant-text').innerHTML=generalErrorMessage; // show information about error in hint box
		}else{
			document.getElementById('assistant-text').innerHTML=generalErrorMessageEN;
		}	
		document.getElementById(fieldName).style.backgroundColor='#ffe4ec'; // set proper value of background
		errorInPreviouslyFilledField = "True";// set variable that error occured
	}
	
	
	function colorizeInputs(id){
		document.getElementById(id).style.backgroundColor='#ffe4ec';
	}
	
	//make validation
	function checkValidation (fieldName){
		//trim if necessary
		var fieldValue = document.getElementById ('contact-form').elements[fieldName].value;
		var fieldValue = Trim(fieldValue);
		document.getElementById('contact-form').elements[fieldName].value=fieldValue;
		// check error status
		
		if ((fieldName.indexOf('homeTelephone')!=-1)) {
		
			// set which telephone field was passed  and set proper statuses for variables
			var whichTelephoneField="Short";
			var telephoneField1;
			var telephoneField2;
			var telephoneFieldStatus1;
			var telephoneFieldStatus2;
			
			if (fieldName.indexOf('Small')==-1) {
				whichTelephoneField="Long";
			}

			if (whichTelephoneField=="Short"){
				telephoneField1=fieldName;
				telephoneField2=fieldName.substring(0,fieldName.length-5);
			}
			else {
				telephoneField1=fieldName+"Small";
				telephoneField2=fieldName;
			}
		
			var fieldValue1 = document.getElementById ('contact-form').elements[telephoneField1].value;
			var fieldValue2 = document.getElementById ('contact-form').elements[telephoneField2].value;
			telephoneFieldEmptiness1= checkIfEmpty (fieldValue1);
			telephoneFieldEmptiness2= checkIfEmpty (fieldValue2);
			telephoneFieldStatus1= checkAllNecessaryValidations(fieldValue1, telephoneField1);
			telephoneFieldStatus2= checkAllNecessaryValidations(fieldValue2, telephoneField2);
			
			if ((telephoneFieldEmptiness1==0) && (telephoneFieldEmptiness2==0)) { //telephone fields empty
				document.getElementById(telephoneField1).style.backgroundColor='#ffffff';
				setStatusOK(telephoneField2);
			}
			else{
				if (telephoneFieldEmptiness1==0) { // prefix field empty
					setStatusOK (telephoneField2);
					if (telephoneFieldStatus2!=-1){
						setStatusNOK (telephoneField2,telephoneFieldStatus2);
					}
					document.getElementById(telephoneField1).style.backgroundColor='#ffffff';
				}
				else {
					if (telephoneFieldEmptiness2==0) {// long telephone field empty
						if (telephoneFieldStatus1!=-1){
							setStatusNOK (telephoneField2,telephoneFieldStatus1);
							document.getElementById(telephoneField1).style.backgroundColor='#ffe4ec';
						}
						else {
							setStatusOK (telephoneField2);
							document.getElementById(telephoneField1).style.backgroundColor='#ffffff';
						}
						document.getElementById(telephoneField2).style.backgroundColor='#ffffff';
					}
					else{// both fields are filled		
						if ((telephoneFieldStatus1!=-1)&&(telephoneFieldStatus2!=-1)){ //both fields not ok
							if(lang=='PL'){
								fieldErrorMessages[22]=fieldErrorMessages[telephoneFieldStatus1]+" "+fieldErrorMessages[telephoneFieldStatus2]
							}else{
								fieldErrorMessagesEN[22]=fieldErrorMessagesEN[telephoneFieldStatus1]+" "+fieldErrorMessagesEN[telephoneFieldStatus2]
							}	                                                                                       
						setStatusNOK (telephoneField2,22);
						document.getElementById(telephoneField1).style.backgroundColor='#ffe4ec';
						}
						else{
							if (telephoneFieldStatus1!=-1){// first NOK, second OK
								setStatusNOK (telephoneField2,telephoneFieldStatus1);
								document.getElementById(telephoneField1).style.backgroundColor='#ffe4ec';
								document.getElementById(telephoneField2).style.backgroundColor='#ffffff';
							}
							else{
								if (telephoneFieldStatus2!=-1){// second NOK, first OK
									setStatusNOK (telephoneField2,telephoneFieldStatus2);
									document.getElementById(telephoneField1).style.backgroundColor='#ffffff';
									document.getElementById(telephoneField2).style.backgroundColor='#ffe4ec';
								}
								else {// both OK
									setStatusOK (telephoneField2);
									document.getElementById(telephoneField1).style.backgroundColor='#ffffff';
								}
							}
						}
					}
				}
			}
		}else if (fieldName.indexOf('zipCode1')!=-1){
			var valueReturnedFromChecking=checkAllNecessaryValidations(fieldValue, fieldName);
			if (valueReturnedFromChecking==-1){
				if (document.getElementById (fieldName.substring(0,8)+'Exclamation').style.display=='inline') {
					document.getElementById (fieldName.substring(0,8)+'Exclamation').style.visibility='hidden'; 
					document.getElementById (fieldName.substring(0,8)+'Exclamation').style.display='none';
					document.getElementById (fieldName.substring(0,8)+'Error').style.visibility='hidden';
					document.getElementById (fieldName.substring(0,8)+'Error').style.display='none';
				}
				document.getElementById(fieldName).style.backgroundColor='#ffffff';
				errorInPreviouslyFilledField = "False";
			}
			else {
				document.getElementById (fieldName.substring(0,8)+'Exclamation').style.visibility='visible';
				document.getElementById (fieldName.substring(0,8)+'Exclamation').style.display='inline';
				if(lang=='PL'){	
					document.getElementById (fieldName.substring(0,8)+'Error').innerHTML="<p>"+fieldErrorMessages[valueReturnedFromChecking]+"</p>";
				}else{
					document.getElementById (fieldName.substring(0,8)+'Error').innerHTML="<p>"+fieldErrorMessagesEN[valueReturnedFromChecking]+"</p>";
				}
				document.getElementById (fieldName.substring(0,8)+'Error').style.visibility='visible';
				document.getElementById (fieldName.substring(0,8)+'Error').style.display='block';
				if(lang=='PL'){
					document.getElementById('assistant-text').innerHTML=generalErrorMessage;
				}else{
					document.getElementById('assistant-text').innerHTML=generalErrorMessageEN;	
				}
				document.getElementById(fieldName).style.backgroundColor='#ffe4ec';
				errorInPreviouslyFilledField = "True";
			}
		}else {
			var valueReturnedFromChecking=checkAllNecessaryValidations(fieldValue, fieldName);
			if (valueReturnedFromChecking==-1){
				setStatusOK(fieldName);
			}
			else {
				setStatusNOK(fieldName,valueReturnedFromChecking);
			}
		}
	}

		// check if NIP is valid
	function checkNIP(fieldValue){
		var weightsNIP= new Array ();
		weightsNIP[0]=6;
		weightsNIP[1]=5;
		weightsNIP[2]=7;
		weightsNIP[3]=2;
		weightsNIP[4]=3;
		weightsNIP[5]=4;
		weightsNIP[6]=5;
		weightsNIP[7]=6;
		weightsNIP[8]=7;
		
		var a=0;
		NIPSum=0;
		for (a=0;a<=8;a++){
			digitToSum=parseInt(fieldValue.substr(a,1),10)
			NIPSum=NIPSum+(digitToSum*weightsNIP[a]);
		}
		controlDigit = (NIPSum % 11);
		if (controlDigit==parseInt(fieldValue.substr(9,1),10)) return 0;
		else return 1;	
	}	
	
		// check if NIP is valid
	function checkRegon(fieldValue){
		var weightsRegon= new Array ();
		
		var checkSumDigit = 0;
		if (checkIfEmpty (fieldValue) == 9){
		  weightsRegon[0]=8;
		  weightsRegon[1]=9;
		  weightsRegon[2]=2;
		  weightsRegon[3]=3;
		  weightsRegon[4]=4;
		  weightsRegon[5]=5;
		  weightsRegon[6]=6;
		  weightsRegon[7]=7;
		
		  checkSumDigit = parseInt(fieldValue.substr(8,1),10);
		
		
		}else if (checkIfEmpty (fieldValue) == 14) {
		  weightsRegon[0]=2;
		  weightsRegon[1]=4;
		  weightsRegon[2]=8;
		  weightsRegon[3]=5;
		  weightsRegon[4]=0;
		  weightsRegon[5]=9;
		  weightsRegon[6]=7;
		  weightsRegon[7]=3;
		  weightsRegon[8]=6;
		  weightsRegon[9]=1;
		  weightsRegon[10]=2;
		  weightsRegon[11]=4;
		  weightsRegon[12]=8;		
		  checkSumDigit = parseInt(fieldValue.substr(13,1),10);  
		}
		else{
		  return 0;
		}
		var a=0;
		regonSum=0;
		for (a=0;a<=(checkIfEmpty (fieldValue)-2);a++){
			
			digitToSum=parseInt(fieldValue.substr(a,1),10)
			regonSum=regonSum+(digitToSum*weightsRegon[a]);
		}
		controlDigit = (regonSum % 11);

		if (controlDigit==checkSumDigit) return 0;
		else return 1;	
	}
	
	
	//show comboboxes for hours 
	function phone_contact_hours(phone){
	
		switch(phone) {
			case 'home':
				phonePrefix=document.getElementById(phone+'TelephoneSmall');
				break
			case 'mobile':
				phonePrefix=document.getElementById(phone+'Telephone');
				break
		}
		
		phoneContactHours = document.getElementById(phone+'TelephoneContactHours')
		phone = document.getElementById(phone+'Telephone');
		
		if (! phoneContactHours || ! phone ) return;
		if (phonePrefix.value.length > 0 || phone.value.length > 0) {
			phoneContactHours.style.display = 'block';
		}
		else {
			phoneContactHours.style.display = 'none';
		}
	}
	
	var hours = Array(8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19);
	
	
	//function to set hours after
	function set_hours_after (toTimeSelectId, fromTimeSelectId) {
		
		var fromTimeSelect = document.getElementById(fromTimeSelectId);
		var toTimeSelect = document.getElementById(toTimeSelectId);

		var hourFrom = fromTimeSelect.options[fromTimeSelect.options.selectedIndex].value;
		var selectedHourTo = toTimeSelect.options[toTimeSelect.options.selectedIndex].value;
		
		init_hours_after(toTimeSelectId, hourFrom, selectedHourTo);
	}
	
	//function to init proper values for hours after
	function init_hours_after (selectId, timeFrom, selectedTime) {

		if (! document) return;
		var select = document.getElementById(selectId);
		if (! select) return;

		var fromHour = parseInt(timeFrom);
		if(isNaN(fromHour)) fromHour = 8; // default

		var selectedHour = parseInt(selectedTime);
		if(isNaN(selectedHour)) selectedHour = 17; // default

		clearSelect(selectId);

		var found = 0;
		var index = 0;
		var h = 0;
		var m = 0;
		for (h = 0; h < hours.length; h++) {
			if (found == 0) {			
				if (parseInt(hours[h]) > parseInt(fromHour)) {
					found = 1;
				}
			}

			if (found == 1) {
				var selected = false;
				if (selectedHour == hours[h]) selected = true;

				select.options[index++] = new Option(
							hours[h]+':00',
							hours[h],
							selected,
							selected
				);
				continue;
			}
		}
	}
	
	// function to clear select
	function clearSelect(selectId) {
		if (! document) return;
		var select = document.getElementById(selectId);
		if (! select) return;
		
		var options = select.options;
		
		var i = 0;
		for (i = options.length - 1; i >= 0; i--) {
			options[i] = null;
		}
	}
	
	// count number of chars in commentary and show how much left	
	function textCounter(fieldText, countfieldText, maxlimit) {

		field=document.getElementById(fieldText);
		countfield=document.getElementById(countfieldText);
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
	else 
		countfield.value = maxlimit - field.value.length;
	}
	
	//hide email optional information
	function hideOptional() {
		if (document.getElementById('notice').value.length>0){
			document.getElementById('noticeOptionalInfo').style.display='none';
		}
		else {
			document.getElementById('noticeOptionalInfo').style.display='inline';
		}
	}

	//check everything on submit
	function submitCheck(){	
		
		//check for errors
		var generalErrorStatus=0;
		checkValidation('name');
		checkValidation('surname');
		checkValidation('company');
		checkValidation('city');
		checkValidation('email');
		checkValidation('regon');
		checkValidation('zipCode11');
		checkValidation('zipCode12');
		checkValidation('mobileTelephone');
		checkValidation('homeTelephoneSmall');
		checkValidation('homeTelephone');
		checkValidation('function');

		dropDown = document.getElementById('dropDown');
		
		if (dropDown.value == 7){
		  checkValidation('nip');
		  checkValidation('branchAddress');
		  
		}
		
		
		
		var chkboxes = checkIfSomethingFromCheckBoxesWasSelected(true);
		if (chkboxes == 1){
			generalErrorStatus=1;
		}
		var dropDown = checkIfSomethingFromComboboxWasSelected('dropDown'); 
		if (dropDown == 1 || (document.getElementById('nameError').style.display=='block')||(document.getElementById('surnameError').style.display=='block')||(document.getElementById('cityError').style.display=='block')||(document.getElementById('companyError').style.display=='block')|| (document.getElementById('emailError').style.display=='block')||(document.getElementById('mobileTelephoneError').style.display=='block')||(document.getElementById('mobileTelephoneError').style.display=='block')||(document.getElementById('homeTelephoneError').style.display=='block') || (document.getElementById('nipError').style.display=='block')||(document.getElementById('regonError').style.display=='block')|| (document.getElementById('branchAddressError').style.display=='block')) generalErrorStatus=1;
		
		if (document.getElementById('branchAddressError').style.display=='block'){
		  document.getElementById('branchCity').style.backgroundColor='#ffe4ec';
		  showHideBoth('branchCity','show');
		}
		
		//set error messages if fields are empty
		var i;
		for (i=0;i<=7;i++){
				k=document.getElementById(fieldNames[i]);
				r=k.id;
				returnCode=checkIfEmpty(k.value);
				if(i==5 || i == 6){
					if ((returnCode==0) && (fieldRequirement[i]==1)){
						if(lang=='PL'){
							document.getElementById('zipCode1Error').innerHTML="<p>"+fieldErrorMessages[33]+"</p>";
						}else{
							document.getElementById('zipCode1Error').innerHTML="<p>"+fieldErrorMessagesEN[33]+"</p>";
						}
						document.getElementById ('zipCode1Exclamation').style.display='inline';
						document.getElementById ('zipCode1Exclamation').style.visibility='visible';
						document.getElementById('zipCode1Error').style.display='block';
						document.getElementById('zipCode1Error').style.visibility='visible';
						document.getElementById('zipCode11').style.backgroundColor='#ffe4ec'
						document.getElementById('zipCode12').style.backgroundColor='#ffe4ec'
							generalErrorStatus=1;
					}
				}else{
					if ((returnCode==0) && (fieldRequirement[i]==1)){
						if(lang=='PL'){
							document.getElementById(r+'Error').innerHTML="<p>"+fieldErrorMessages[33]+"</p>";
						}else{
							document.getElementById(r+'Error').innerHTML="<p>"+fieldErrorMessagesEN[33]+"</p>";
						}
						document.getElementById (r+'Exclamation').style.display='inline';
						document.getElementById (r+'Exclamation').style.visibility='visible';
						document.getElementById(r+'Error').style.display='block';
						document.getElementById(r+'Error').style.visibility='visible';
						document.getElementById(r).style.backgroundColor='#ffe4ec'
							generalErrorStatus=1;
					}
				}
		}
		
		//check telephoneFields if at least one is shown
		
		mobileFieldLength=document.getElementById('mobileTelephone').value.length;
		homePrefixLength=document.getElementById('homeTelephoneSmall').value.length;
		homeFullLength=document.getElementById('homeTelephone').value.length;
		
		if (!(mobileFieldLength>0)&& !((homePrefixLength>0)&&(homeFullLength>0))) {
			if(lang=='PL'){	
				document.getElementById('generalTelephoneError').innerHTML="<p>"+fieldErrorMessages[24]+"</p>";
			}else{
				document.getElementById('generalTelephoneError').innerHTML="<p>"+fieldErrorMessagesEN[24]+"</p>";
			}
				showHideError('generalTelephone','show');
				generalErrorStatus=1;
		}
		else {
			showHideError('generalTelephone','hide');	
		}
		
		
		
		if (generalErrorStatus==0) {
		  
			if (document.getElementById('dropDown').value != 7){
			    document.getElementById('nip').value = ''; 
			    select = document.getElementById('branchAddress'); 
			    clearBranchSelect(select);
			    var opt = document.createElement("OPTION");
			    opt.text='';
			    opt.value='PC0784---';
			    select.options.add(opt);
			}		    
		    
			return true
		}
		else {
			return false
		}
	}
	
	//function to hide error on combobox
	function hideOptionError(whichField){
			document.getElementById (whichField+'Exclamation').style.display='none';
			document.getElementById (whichField+'Exclamation').style.visibility='hidden';
			document.getElementById(whichField+'Error').style.display='none';
			document.getElementById(whichField+'Error').style.visibility='hidden';
			document.getElementById(whichField).style.backgroundColor='#fff'
			setHint(whichField);
	}
	
	//reset combobox background
	function resetComboboxBackground(whichField,e){
		
		hideOptionError(whichField)
		if(!e)e=window.event;
		
		if(e.type=="blur"){
			document.getElementById(whichField).style.backgroundColor='#fff'
		}
		else{
			document.getElementById (whichField).style.backgroundColor='#E4EDFC'
		}
	}
	
	// check if something from combobox was selected
	function checkIfSomethingFromComboboxWasSelected(whichField){
		var whichCombobox=document.getElementById(whichField);
		if(whichCombobox != null){
			if(whichCombobox.selectedIndex==0){
				if(lang=='PL'){
					document.getElementById(whichField+'Error').innerHTML="<p>"+fieldErrorMessages[23]+"</p>";
				}else{
					document.getElementById(whichField+'Error').innerHTML="<p>"+fieldErrorMessagesEN[23]+"</p>";
				}
				showHideBoth(whichField,'show');
				document.getElementById(whichField).style.backgroundColor='#ffe4ec';
			}
			else {
				showHideBoth(whichField,'hide');
				document.getElementById(whichField).style.backgroundColor='#fff';
				return 0;
			}
		}
		return 1;
	}
	
	function checkIfSomethingFromCheckBoxesWasSelected(validateNotice){
		var returnCode = 0; //returnCode==0 <- gdy jest ok, 1 gdy zle
		//walidacja checkboxow
		chkbox1 = document.getElementById('chkbox1');
		chkbox2 = document.getElementById('chkbox2');
		chkbox3 = document.getElementById('chkbox3');
		chkbox4 = document.getElementById('chkbox4');
		chkboxNotice = document.getElementById('checkBoxNotice');
		if(chkbox1.checked == false && chkbox2.checked == false && chkbox3.checked == false  && chkbox4.checked == false) {
			if(lang=='PL'){
				document.getElementById('chkboxError').innerHTML="<p>"+fieldErrorMessages[30]+"</p>";
			} else {
				document.getElementById('chkboxError').innerHTML="<p>"+fieldErrorMessagesEN[30]+"</p>";
			}
			returnCode=1;
			showHideError('chkbox','show');
		}
		else {
			if (chkbox4.checked == true && chkboxNotice.value.length == 0 && validateNotice ){
				if(lang=='PL'){
					document.getElementById('chkboxError').innerHTML="<p>"+fieldErrorMessages[32]+"</p>";
				} else {
					document.getElementById('chkboxError').innerHTML="<p>"+fieldErrorMessagesEN[32]+"</p>";
				}
				returnCode=1;
				showHideError('chkbox','show');				
			}
			else{
				showHideError('chkbox','hide');
			}
		}
		return returnCode;
	}
	
	function validateCheckBoxes(){
	  checkIfSomethingFromCheckBoxesWasSelected(false);
	  
	  showHideCheckBoxArea ();
	  
	}
	
	
	// show/hide exclamation
	function showHideExclamation (whichField,what){
		if (what=='show'){
			document.getElementById (whichField+'Exclamation').style.display='inline';
			document.getElementById (whichField+'Exclamation').style.visibility='visible';	
		}	
		else {
			document.getElementById (whichField+'Exclamation').style.display='none';
			document.getElementById (whichField+'Exclamation').style.visibility='hidden';	
		}	
	}
	
	// show/hide exclamation
	function showHideError (whichField,what){
		if (what=='show'){
			document.getElementById (whichField+'Error').style.display='block';
			document.getElementById (whichField+'Error').style.visibility='visible';	
		}	
		else {
			document.getElementById (whichField+'Error').style.display='none';
			document.getElementById (whichField+'Error').style.visibility='hidden';	
		}	
	}
	
	//show/hide exclamation and error
	function showHideBoth(whichField,what){
		showHideExclamation (whichField,what);
		showHideError (whichField,what);
	}

	function showHideCheckBoxArea (){
		chkbox = document.getElementById('chkbox4');
		if(chkbox.checked == true){
			document.getElementById ('checkbox-other-text').style.display='block';
			document.getElementById ('checkbox-other-text').style.visibility='visible';				
			
		}
		else{
			document.getElementById ('checkbox-other-text').style.display='none';
			document.getElementById ('checkbox-other-text').style.visibility='hidden';
			showHideError('chkbox','hide');
		}
	}	

	function showHideRevenuesOptions (){		
		dropDown = document.getElementById('dropDown');
		nipArea = document.getElementById ('nip-row');
		branchArea = document.getElementById ('branch-area');
		if(nipArea != null && branchArea!=null && dropDown!=null){
		  
		      if (dropDown.value == 7){

			      nipArea.style.display='block';
			      nipArea.style.visibility='visible';
			      branchArea.style.display='block';
			      branchArea.style.visibility='visible';
			      checkValidation('nip');
		      }
		      else{
			      nipArea.style.display='none';
			      nipArea.style.visibility='hidden';
			      branchArea.style.display='none';
			      branchArea.style.visibility='hidden';			      
			      setStatusOK('nip');
			      setStatusOK('branchAddress');
			      setStatusOK('branchCity');
		      }		  
		  
		}

	}
	
	//check all things on form load
$(document).ready(function(){
if (document.getElementById('contact-form') != null){ 
	
		checkValidation('name');
		checkValidation('surname');
		checkValidation('company');
		checkValidation('city');
		checkValidation('email');
		checkValidation('regon');
		checkValidation('zipCode11');
		checkValidation('zipCode12');
		checkValidation('mobileTelephone');
		checkValidation('homeTelephoneSmall');
		checkValidation('homeTelephone');
		checkValidation('function');
		showHideRevenuesOptions();
		}
	});
