function isItemArray(obj) {
   if (!obj) { return false; }
   try {
     if (!(obj.propertyIsEnumerable("length"))
       && (typeof obj === "object")
       && (typeof obj.length === "number")) {
         return true;
     } else {
       return false;
     } // if (!(obj.propertyIsEnumerable("length"))...
   } catch (e) {
     return false;
   } // try
} // isArray() 

function checkChecked(obj)
{
  if (!isItemArray(obj)) return true;
  
  var checked = false;
	for( index = 0; index < obj.length; index++) { if ( obj[index].checked ) checked = true; }
  return checked;
}

function checkForm(form) {
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]$/;	
	var numExp = /^[0-9\ \.\-]+$/;
	var alphanumExp = /^[^!\?#%\*;<>=\[\]\^\{\}\|~]+$/;
	
	if (!checkChecked(form.kind_of_request)) { alert('Please enter kind of AlgOR request'); form.kind_of_request[0].focus(); return false; }
	if (form.kind_of_request[2].checked==true && form.agree_with_dev_cost.checked==false) { alert("You must agree to share development/manufacturing costs!"); form.agree_with_dev_cost.focus(); return false; }
  if (form.project_volume_estimation_totally.value=='') { alert("Please enter total estimation volume!"); form.project_volume_estimation_totally.focus(); return false;}	
	if (form.name.value=='') { alert("Please enter customer name!"); form.name.focus(); return false;}
	if (form.country.value=='') { alert("Please select country."); form.country.focus(); return false;}
	if (form.contact_f.value=='') { alert("Please enter your first name."); form.contact_f.focus(); return false;}
	if (!form.contact_f.value.match(alphanumExp)) { alert("Please enter only letters in your first name."); form.contact_f.focus(); return false;}
	if (form.contact_f.value.length > 80) { alert("Please enter your first name at least 80 characters long."); form.contact_f.focus(); return false;}
	if (form.contact_l.value=='') { alert("Please enter your last name."); form.contact_l.focus(); return false;}
	if (!form.contact_l.value.match(alphanumExp)) { alert("Please enter only letters in your last name."); form.contact_l.focus(); return false;}
	if (form.contact_l.value.length > 80) { alert("Please enter your last name at least 80 characters long."); form.contact_l.focus(); return false;}
	if (form.email.value=='') { alert("Please enter your E-mail."); form.email.focus(); return false;}
	if (form.conf_email.value=='') { alert("Please confirm your E-mail."); form.conf_email.focus(); return false;}
	if (form.email.value!=form.conf_email.value) { alert("Your E-mail addresses don't match. Please, check your E-mail."); form.email.focus(); return false;}
	if (!checkChecked(form.algor_sender))  { alert("Please select sender of AlgOR form!"); form.algor_sender[0].focus(); return false; }
 	if (!checkChecked(form.company_to_program_chip)) { alert("Please select company, that will be program the chip!"); form.company_to_program_chip[0].focus(); return false; }
  if (form.prog.value=='') { alert("Please select programmer."); form.prog.focus(); return false;}
	if (!checkChecked(form.buy_product)) { alert("Please enter where you bought the product."); form.buy_product[0].focus(); return false;}
	if (form.buy_product[0].checked==true && form.purchase.value=='') { alert("Please enter where you bought the product."); form.purchase.focus(); return false;}
	if (form.buy_product[2].checked==true && form.other_specify.value=='') { alert("Please enter where you bought the product."); form.other_specify.focus(); return false;}
	if (form.buy_product[3].checked==false && form.purchdate.value=='') { alert("Please enter date of purchasing."); form.purchdate.focus(); return false;}
	if (form.buy_product[3].checked==false && form.purchase.value!='' && !form.purchdate.value.match(alphanumExp)) { alert("Please, don't use any special characters."); form.purchdate.focus(); return false; }	
	if (form.buy_product[3].checked==false && form.rcarddate_sent[0].checked==false && form.rcarddate_sent[1].checked==false) { alert("Please enter date of sending registration card."); form.rcarddate_sent[0].focus(); form.rcarddate_sent[0].checked=false; return false;}
	if (form.buy_product[3].checked==false && form.rcarddate_sent[0].checked==true && form.rcarddate.value=='') { alert("Please enter date of sending registration card."); form.rcarddate.focus(); return false;}
	if (form.buy_product[3].checked==false && form.rcarddate.value!='' && !form.rcarddate.value.match(alphanumExp)) { alert("Please enter correct date of sendind registration card (dd-mm-yyy)"); form.rcarddate.focus(); return false; }
	if (form.buy_product[3].checked==false && form.serial.value=='') { alert("Please enter serial number."); form.serial.focus(); return false;}
	if (form.buy_product[3].checked==false && !form.serial.value.match(numExp)) { alert("Please enter serial number from bottom side of programmer (000-00000)."); form.serial.focus(); return false;}
	if (form.buy_product[3].checked==false && form.version.value=='') { alert("Please enter version of control program."); form.version.focus(); return false;}
	if (form.buy_product[3].checked==false && !form.version.value.match(alphanumExp)) { alert("Please enter correct version of control program PG4UW (0.00)."); form.version.focus(); return false;}
	if (form.device.value=='') { alert("Please enter device type."); form.device.focus(); return false; }
	if (form.device.value.length > 80) { alert("Please enter device type at least 80 characters long"); form.device.focus(); return false;}
	if (form.vendor.value=='') { alert("Please enter vendor."); form.vendor.focus(); return false;}
	if (form.vendor.value.length > 80) { alert("Please enter vendor at least 80 characters long"); form.vendor.focus(); return false;}
	if (form.packg.value=='') { alert("Please enter package."); form.packg.focus(); return false;}
	if (form.packg.value.length > 80) { alert("Please enter package at least 80 characters long"); form.packg.focus(); return false;}
	if (form.prog_type.value == '') { alert("Please select the way of chip programming."); form.prog_type.focus(); return false; }
	if (document.algor.kind_of_request[0].checked==false && form.deadline_day.value=='') { alert("Please enter requested deadline day!"); form.deadline_day.focus(); return false; }
	if (document.algor.kind_of_request[0].checked==false && form.deadline_month.value=='') { alert("Please enter requested deadline month!"); form.deadline_month.focus(); return false; }
	if (document.algor.kind_of_request[0].checked==false && form.deadline_year.value=='') { alert("Please enter requested deadline year!"); form.deadline_year.focus(); return false; }
	if (!checkChecked(form.verify)) {alert("Please enter whether you verified the latest version of control program doesn't support this device."); form.verify[0].focus(); return false;}
	if (!checkChecked(form.samples)) { alert("Please enter whether samples are available."); form.samples[0].focus(); form.samples[0].checked=false; return false;}
	if (form.samples[2].checked==true && form.samples_availability_day.value == '' && form.samples_availability_month.value  == '' && form.samples_availability_year.value == '') { alert("Please select date of samples availability"); form.samples_availability_day.focus(); return false;  }
  if (form.samples_confirm.checked==false) {alert("Confirm please the statement: I read THIS INFORMATION about sample chips!"); form.samples_confirm.focus(); return false; }
	if (form.security_code.value=='') { alert("Please enter control code from picture."); form.security_code.focus(); return false;}
	if (form.corrected_informations.checked == false) { alert("Confirm please the statement: All information provided above are correct at the time of sending of this request."); form.corrected_informations.focus(); return false;}

  return true;
}

function needed_preliminary_info() {
    if(document.algor.kind_of_request[0].checked) {
        document.algor.deadline_day.disabled = true;
        document.algor.deadline_month.disabled = true;
        document.algor.deadline_year.disabled = true;
    } else {
        document.algor.deadline_day.disabled = false;
        document.algor.deadline_month.disabled = false;
        document.algor.deadline_year.disabled = false;
    }
}

function checkFormSk(form) {
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;	
	var numExp = /^[0-9\ \.\-]+$/;
	var alphanumExp = /^[^!\?#%\*;<>=\[\]\^\{\}\|~]+$/;

	if (!checkChecked(form.kind_of_request)) { alert('Prosím vyberte typ požiadavku'); form.kind_of_request[0].focus(); return false; }
	if (form.kind_of_request[2].checked==true && form.agree_with_dev_cost.checked==false) { alert("Musíte súhlasiť s podieľaním sa na vývojových/výrobných nákladoch!"); form.kind_of_request.focus(); return false; }
  if (form.project_volume_estimation_totally.value=='') { alert("Prosím vložte celkovú odhadovanú kvantitu!"); form.project_volume_estimation_totally.focus(); return false;}	
	if (form.name.value=='') { alert("Prosím vložte meno zákazníka!"); form.name.focus(); return false;}
	if (form.country.value=='') { alert("Prosím vyberte štát."); form.country.focus(); return false;}
	if (form.contact_f.value=='') { alert("Prosím zadajte Vaše meno."); form.contact_f.focus(); return false;}
	if (!form.contact_f.value.match(alphanumExp)) { alert("Prosím nepoužívajte špeciálne znaky vo Vašom mene."); form.contact_f.focus(); return false;}
	if (form.contact_f.value.length > 80) { alert("Prosím zadajte Vaše meno na max.80 znakov."); form.contact_f.focus(); return false;}
	if (form.contact_l.value=='') { alert("Prosím zadajte Vaše priezvisko."); form.contact_l.focus(); return false;}
	if (!form.contact_l.value.match(alphanumExp)) { alert("Prosím nepoužívajte špeciálne znaky vo Vašom priezvisku."); form.contact_l.focus(); return false;}
	if (form.contact_l.value.length > 80) { alert("Prosím zadajte Vaše priezvisko na max.80 znakov."); form.contact_l.focus(); return false;}
	if (form.email.value=='') { alert("Prosím zadajte Vašu E-mailovú adresu."); form.email.focus(); return false;}
	if (form.email.value!=form.conf_email.value) { alert("Zadané E-mailové adresy nie sú rovnaké. Prosím skontrolujte Váš E-mail."); form.email.focus(); return false;}
	if (form.conf_email.value=='') { alert("Prosím potvrdte Váš e-mail."); form.conf_email.focus(); return false;}
	if (!checkChecked(form.algor_sender)) { alert("Prosím vyberte odosielateľa AlgOR formuláru!"); form.algor_sender[0].focus(); return false; }
 	if (!checkChecked(form.company_to_program_chip)) { alert("Prosím vyberte spoločnosť, ktorá bude obvod programovať!"); form.company_to_program_chip[0].focus(); return false; }
	if (form.prog.value=='') { alert("Prosím vyberte programátor."); form.prog.focus(); return false;}
	if (!checkChecked(form.buy_product)) { alert("Prosím zadajte kde ste zakúpili výrobok."); form.buy_product[0].focus(); form.buy_product[0].checked=false; return false;}
	if (form.buy_product[0].checked==true && form.purchase.value=='') { alert("Prosím zadajte kde ste zakúpili výrobok."); form.purchase.focus(); return false;}
	if (form.buy_product[2].checked==true && form.other_specify.value=='') { alert("Prosím zadajte kde ste zakúpili výrobok."); form.other_specify.focus(); return false;}
	if (form.buy_product[3].checked==false && form.purchdate.value=='') { alert("Prosím zadajte dátum zakúpenia."); form.purchdate.focus(); return false;}
	if (form.buy_product[3].checked==false && form.purchase.value!='' && !form.purchase.value.match(alphanumExp)) { alert("Prosím nepoužívajte špecálne znaky kde ste zakúpili výrobok."); form.purchase.focus(); return false;}
	if (form.buy_product[3].checked==false && form.rcarddate_sent[0].checked==false && form.rcarddate_sent[1].checked==false) { alert("Prosím zadajte dátum zaslania registračnej karty."); form.rcarddate_sent[0].focus(); form.rcarddate_sent[0].checked=false; return false;}
	if (form.buy_product[3].checked==false && form.rcarddate_sent[0].checked==true && form.rcarddate.value=='') { alert("Prosím zadajte dátum zaslania registračnej karty."); form.rcarddate.focus(); return false;}
	if (form.buy_product[3].checked==false && form.rcarddate.value!='' && !form.rcarddate.value.match(alphanumExp)) { alert("Prosím zadajte korektný dátum zaslania registračnej karty (dd-mm-yyy)"); form.rcarddate.focus(); return false; }
	if (form.buy_product[3].checked==false && form.serial.value=='') { alert("Prosím zadajte sériové číslo."); form.serial.focus(); return false;}
	if (form.buy_product[3].checked==false && !form.serial.value.match(numExp)) { alert("Prosím zadajte sériové číslo zo spodnej strany programátora (000-00000)."); form.serial.focus(); return false;}
	if (form.buy_product[3].checked==false && form.version.value=='') { alert("Prosím zadajte verziu ovládacieho programu."); form.version.focus(); return false;}
	if (form.buy_product[3].checked==false && !form.version.value.match(alphanumExp)) { alert("Prosím zadajte správnu verziu ovládacieho programu PG4UW (0.00)."); form.version.focus(); return false;}
	if (form.device.value=='') { alert("Prosím zadajte typ obvodu."); form.device.focus(); return false;}
	if (form.device.value.length > 80) { alert("Prosím zadajte typ obvodu na max.80 znakov"); form.device.focus(); return false;}
	if (form.vendor.value=='') { alert("Prosím zadajte výrobcu."); form.vendor.focus(); return false;}
	if (form.vendor.value.length > 80) { alert("Prosím zadajte výrobcu na max.80 znakov"); form.vendor.focus(); return false;}
	if (form.packg.value=='') { alert("Prosím zadajte púzdrenie."); form.packg.focus(); return false;}
	if (form.packg.value.length > 80) { alert("Prosím zadajte púzdrenie na max.80 znakov"); form.packg.focus(); return false;}
	if (form.prog_type.value == '') { alert("Prosím vyberte spôsob, akým sa obvod bude programovať."); form.prog_type.focus(); return false; }
	if (document.algor.kind_of_request[0].checked==false && form.deadline_day.value=='') { alert("Prosím vložte požadovaný deň realizácie AlgOR požiadavky!"); form.deadline_day.focus(); return false; }
	if (document.algor.kind_of_request[0].checked==false && form.deadline_month.value=='') { alert("Prosím vložte požadovaný mesiac realizácie AlgOR požiadavky!"); form.deadline_month.focus(); return false; }
	if (document.algor.kind_of_request[0].checked==false && form.deadline_year.value=='') { alert("Prosím vložte požadovaný rok realizácie AlgOR požiadavky!"); form.deadline_year.focus(); return false; }
	if (!checkChecked(form.verify)) {alert("Prosím zadajte či ste overili, či aktuálna verzia ovládacieho programu nepodporuje požadovaný obvod."); form.verify[0].focus(); form.verify[0].checked=false; return false;}
	if (!checkChecked(form.samples)) { alert("Prosím zadajte či máte vzorku."); form.samples[0].focus(); form.samples[0].checked=false; return false;}
	if (form.samples[2].checked==true && form.samples_availability_day.value == '' && form.samples_availability_month.value  == '' && form.samples_availability_year.value == '') { alert("Prosím zadajte dátum dostupnosti vzorky obvodu."); form.samples_availability_day.focus(); return false;  }
  if (form.samples_confirm.checked==false) {alert("Potvrďte prosím nasledovné: čítal som TÚTO INFORMÁCIU o vzorke obvodov!"); form.samples_confirm.focus(); return false; }
	if (form.security_code.value=='') { alert("Prosím vložte kontrolný kód z obrázka."); form.security_code.focus(); return false;}
	if (form.corrected_informations.checked == false) { alert("Potvrďte prosím nasledovné: Všetky informácie uvedené vyššie sú správne v čase odoslania tejto požiadavky."); form.corrected_informations.focus(); return false;}
	
	return true;
}
