window.onload = function() {
	addTB();
	initNav();
}

// CSS (if JavaScript is enabled)
function writeJSstyle(){
	document.write('<link rel="stylesheet" type="text/css" media="screen" href="1/css/cechofracht-js.css" />');
}

var timers=new Array();
var menuFall=20;
function initNav() {
	if(browser.isIE) {
		var menuElements=getEl('mnu').getElementsByTagName("ul");
		for(var i=0;i<menuElements.length;i++) {
			menuElements[i].parentNode.parentNode.onmouseover=function() {
				if(timers[this.lastChild.id]) clearTimeout(timers[this.lastChild.id]);							
				setVVObj(this.lastChild);
				this.firstChild.lastChild.style.backgroundPosition="0px -36px";
			}

			menuElements[i].parentNode.parentNode.onmouseout=function() {
				timers[this.lastChild.id]=setTimeout('setVH("'+this.lastChild.id+'");var liEl=getEl("'+this.id+'");liEl.firstChild.lastChild.style.backgroundPosition="0px 0px"',menuFall);
			}
		}
	}
}

function setBranch(branchId,status) {
	if(status=="show")setVV(branchId);
	if(status=="hide")setVH(branchId);
}

function isMail(mail){
  var mailre=/^[_a-zA-Z0-9\.\-]+@[_a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,4}$/;
  return mailre.test(mail);
}

function incNumber(num){
  var numre=/^.*[0-9].*$/;
  return numre.test(num);
}

function reVal(el){
  if(trim(el.value)!="")el.style.backgroundImage="none";
}

function checkFrm(f){

	 var emptys=new Array();
	 var invalids=new Array();
	
	// Global
	if(trim(f.f_company_name.value)=="")emptys[emptys.length]=new Array(f.f_company_name,"Název firmy");
	if(trim(f.f_contact_person.value)=="")emptys[emptys.length]=new Array(f.f_contact_person,"Kontaktní osoba");
	if(trim(f.f_phone.value)=="")emptys[emptys.length]=new Array(f.f_phone,"Telefon");
	/*if(trim(f.f_fax.value)=="")emptys[emptys.length]=new Array(f.f_fax,"Fax");*/
	if(trim(f.f_email.value)=="") {
		emptys[emptys.length]=new Array(f.f_email,"Email");
	} else {
		if(!isMail(trim(f.f_email.value)))invalids[invalids.length]=new Array(f.f_email,"Email");	
	}
	
	// Form0	
	if(f.id=="form0") {
		if(trim(f.f_text.value)=="")emptys[emptys.length]=new Array(f.f_text,"Text");
	}

	// Form1
	if(f.id=="form1") {
		if(trim(f.f_goods_specification.value)=="")emptys[emptys.length]=new Array(f.f_goods_specification,"Specifikace zboží");
/*		if(f.f_goods_warning.value=="Ano") {
			if(trim(f.f_classification_code.value)=="")emptys[emptys.length]=new Array(f.f_classification_code,"Klasifikační kód dle ADR");
		}*/
		if(trim(f.f_source_place.value)==""){
			emptys[emptys.length]=new Array(f.f_source_place,"Místo odeslání (post code)");
		} else {
			if(!incNumber(trim(f.f_source_place.value)))invalids[invalids.length]=new Array(f.f_source_place,"Místo odeslání (post code)");
		}
		if(trim(f.f_destination_place.value)==""){
			emptys[emptys.length]=new Array(f.f_destination_place,"Místo určení (post code)");
		} else {
			if(!incNumber(trim(f.f_destination_place.value)))invalids[invalids.length]=new Array(f.f_destination_place,"Místo určení (post code)");
		}
		
		if(trim(f.f_quantity.value)=="")emptys[emptys.length]=new Array(f.f_quantity,"Počet kusů");
		if(trim(f.f_weight.value)=="")emptys[emptys.length]=new Array(f.f_weight,"Celková hmotnost (kg)");
/*		if(trim(f.f_size.value)=="")emptys[emptys.length]=new Array(f.f_size,"Rozměry (d x š x v)");
		if(trim(f.f_stackable.value)=="")emptys[emptys.length]=new Array(f.f_stackable,"Stohovatelné");
		if(trim(f.f_date.value)=="")emptys[emptys.length]=new Array(f.f_date,"Datum/období");
		if(trim(f.f_requirements.value)=="")emptys[emptys.length]=new Array(f.f_requirements,"Speciální požadavky");
		if(trim(f.f_delivery_condition.value)=="")emptys[emptys.length]=new Array(f.f_delivery_condition,"Dodací podmínka INCOTERMS");
		if(trim(f.f_payer.value)=="")emptys[emptys.length]=new Array(f.f_payer,"Plátce přepravy");
		if(trim(f.f_additional_insurance.value)=="Ano") {
			if(trim(f.f_goods_value.value)=="")emptys[emptys.length]=new Array(f.f_goods_value,"Hodnota zboží");
		}
		if(trim(f.f_package_requirement.value)=="")emptys[emptys.length]=new Array(f.f_package_requirement,"Požadavek na balení");*/
	}	
	
	// Form2
	if(f.id=="form2") {
		if(trim(f.f_goods_name.value)=="")emptys[emptys.length]=new Array(f.f_goods_name,"Název zboží");
/*		if(trim(f.f_nmh.value)=="")emptys[emptys.length]=new Array(f.f_nmh,"NHM");
		if(trim(f.f_payload.value)=="")emptys[emptys.length]=new Array(f.f_payload,"Předpokládané vytížení vozu");
		if(trim(f.f_goods_warning.value)=="Ano") {
			if(trim(f.f_warning_number.value)=="")emptys[emptys.length]=new Array(f.f_warning_number,"Číslo k označení nebezpečí");		
			if(trim(f.f_un_number.value)=="")emptys[emptys.length]=new Array(f.f_un_number,"UN-číslo");
			if(trim(f.f_rid.value)=="")emptys[emptys.length]=new Array(f.f_rid,"Obalová skupina dle RID");
		}*/
		if(trim(f.f_source_country.value)=="")emptys[emptys.length]=new Array(f.f_source_country,"Stanice/země odeslání");
		if(trim(f.f_destination_country.value)=="")emptys[emptys.length]=new Array(f.f_destination_country,"Stanice/země určení");
		if(trim(f.f_quantity.value)=="")emptys[emptys.length]=new Array(f.f_quantity,"Počet kusů");
/*		if(trim(f.f_date.value)=="")emptys[emptys.length]=new Array(f.f_date,"Datum/období");
		if(trim(f.f_requirements.value)=="")emptys[emptys.length]=new Array(f.f_requirements,"Speciální požadavky");*/
	}

	// Form3
	if(f.id=="form3") {
		if(trim(f.f_goods_specification.value)=="")emptys[emptys.length]=new Array(f.f_goods_specification,"Specifikace zboží");
/*		if(trim(f.f_goods_warning.value)=="Ano") {
			if(trim(f.f_imdg.value)=="")emptys[emptys.length]=new Array(f.f_imdg,"třída IMDG");
			if(trim(f.f_un.value)=="")emptys[emptys.length]=new Array(f.f_un,"UN-číslo");
		}*/
		if(trim(f.f_source_place.value)=="")emptys[emptys.length]=new Array(f.f_source_place,"Místo odeslání / přístav nakládky");
		if(trim(f.f_destination_place.value)=="")emptys[emptys.length]=new Array(f.f_destination_place,"Místo určení / přístav doručení");
/*		if(trim(f.f_size.value)=="")emptys[emptys.length]=new Array(f.f_size,"Rozměry (d x š x v)");*/
		if(trim(f.f_weight.value)=="")emptys[emptys.length]=new Array(f.f_weight,"Hmotnost zásilky");
/*		if(trim(f.f_count_covers.value)=="")emptys[emptys.length]=new Array(f.f_count_covers,"Počet/druh obalů");
		if(trim(f.f_date.value)=="")emptys[emptys.length]=new Array(f.f_date,"Datum/období");
		if(trim(f.f_requirements.value)=="")emptys[emptys.length]=new Array(f.f_requirements,"Speciální požadavky");
		if(trim(f.f_delivery_condition.value)=="")emptys[emptys.length]=new Array(f.f_delivery_condition,"Dodací podmínka INCOTERMS");
		if(trim(f.f_clearance_place.value)=="")emptys[emptys.length]=new Array(f.f_clearance_place,"Místo proclení v ČR");*/
	}

	// Form4
	if(f.id=="form4") {
		if(trim(f.f_goods_specification.value)=="")emptys[emptys.length]=new Array(f.f_goods_specification,"Specifikace zboží");
/*		if(trim(f.f_goods_warning.value)=="Ano") {
			if(trim(f.f_un.value)=="")emptys[emptys.length]=new Array(f.f_un,"UN-číslo");
		}*/
		if(trim(f.f_source_place.value)=="")emptys[emptys.length]=new Array(f.f_source_place,"Místo odeslání");
		if(trim(f.f_destination_place.value)=="")emptys[emptys.length]=new Array(f.f_destination_place,"Místo určení");
		if(trim(f.f_quantity.value)=="")emptys[emptys.length]=new Array(f.f_quantity,"Počet kusů");
		if(trim(f.f_weight.value)=="")emptys[emptys.length]=new Array(f.f_weight,"Celková hmotnost");
/*		if(trim(f.f_size.value)=="")emptys[emptys.length]=new Array(f.f_size,"Rozměry (d x š x v)");
		if(trim(f.f_date.value)=="")emptys[emptys.length]=new Array(f.f_date,"Datum/období");
		if(trim(f.f_requirements.value)=="")emptys[emptys.length]=new Array(f.f_requirements,"Speciální požadavky");*/
	}

	if(f.id=="form5") {
		if(trim(f.f_goods_specification.value)=="")emptys[emptys.length]=new Array(f.f_goods_specification,"Specifikace zboží");
		if(trim(f.f_quantity.value)=="")emptys[emptys.length]=new Array(f.f_quantity,"Počet kusů");
		if(trim(f.f_weight.value)=="")emptys[emptys.length]=new Array(f.f_weight,"Hmotnost");
/*		if(trim(f.f_size.value)=="")emptys[emptys.length]=new Array(f.f_size,"Rozměry (d x š x v)");
		if(trim(f.f_pallete_places.value)=="")emptys[emptys.length]=new Array(f.f_pallete_places,"Předpokládané m2 nebo paletová místa");
		if(trim(f.f_pallete_height.value)=="")emptys[emptys.length]=new Array(f.f_pallete_height,"Výška palet");
		if(trim(f.f_income_frequency.value)=="")emptys[emptys.length]=new Array(f.f_income_frequency,"Četnost příjmů / výdejů");		
		if(trim(f.f_season_fluctation.value)=="")emptys[emptys.length]=new Array(f.f_season_fluctation,"Sezónní výkyvy");
		if(trim(f.f_requirements.value)=="")emptys[emptys.length]=new Array(f.f_requirements,"Speciální požadavky");*/
	}

	if(f.id=="form6") {
		if(trim(f.f_goods_specification.value)=="")emptys[emptys.length]=new Array(f.f_goods_specification,"Specifikace zásilky");
		if(trim(f.f_send_address.value)=="")emptys[emptys.length]=new Array(f.f_send_address,"Adresa odeslání");
/*		if(trim(f.f_action_name.value)=="")emptys[emptys.length]=new Array(f.f_action_name,"Název akce / veletrhu");
		if(trim(f.f_action_term.value)=="")emptys[emptys.length]=new Array(f.f_action_term,"Termín konání");		
		if(trim(f.f_action_place.value)=="")emptys[emptys.length]=new Array(f.f_action_place,"Místo konání");*/
		if(trim(f.f_quantity.value)=="")emptys[emptys.length]=new Array(f.f_quantity,"Počet kusů");
		if(trim(f.f_weight.value)=="")emptys[emptys.length]=new Array(f.f_weight,"Hmotnost");
/*		if(trim(f.f_size.value)=="")emptys[emptys.length]=new Array(f.f_size,"Rozměry (d x š x v)");
		if(trim(f.f_goods_value.value)=="")emptys[emptys.length]=new Array(f.f_goods_value,"Hodnota zboží");
		if(trim(f.f_required_services.value)=="")emptys[emptys.length]=new Array(f.f_required_services,"Speciální požadavky");*/
	}
	
	if(emptys.length>0 || invalids.length>0){
		var alrt="";
		if(emptys.length>0){
			alrt+="Následující položky nebyly vyplněny:\n\n";
			for(var i=0;i<emptys.length;i++){
				alrt+=emptys[i][1]+"\n";
				emptys[i][0].style.backgroundImage="url('1/images/layout/crumbs/exclamation-mark.gif')";
			}
		}
	
		if(invalids.length>0){
			alrt+=(emptys.length>0?"\n\n":"")+"Nasledujici položky nebyly správně vyplněny:\n\n";
			for(var i=0;i<invalids.length;i++){
				alrt+=invalids[i][1]+"\n";
				invalids[i][0].style.backgroundImage="url('1/images/layout/crumbs/exclamation-mark.gif')";
			}
		}
	
		alert(alrt);
		return false;
	} else {
		return true;
	}
}

