window.onload = function() {
	addTB();
	initNav();
}

// CSS (if JavaScript is enabled)
function writeJSstyle(){
	document.write('<link rel="stylesheet" type="text/css" media="screen" href="96/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,"Company name");
	if(trim(f.f_contact_person.value)=="")emptys[emptys.length]=new Array(f.f_contact_person,"Contact person");
	if(trim(f.f_phone.value)=="")emptys[emptys.length]=new Array(f.f_phone,"Telephone");
	if(trim(f.f_email.value)=="") {
		emptys[emptys.length]=new Array(f.f_email,"E-mail");
	} else {
		if(!isMail(trim(f.f_email.value)))invalids[invalids.length]=new Array(f.f_email,"E-mail");	
	}
	
	// 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,"Specification of the goods");
		if(trim(f.f_source_place.value)==""){
			emptys[emptys.length]=new Array(f.f_source_place,"Place of dispatch (post code)");
		} else {
			if(!incNumber(trim(f.f_source_place.value)))invalids[invalids.length]=new Array(f.f_source_place,"Place of dispatch (post code)");
		}
		if(trim(f.f_destination_place.value)==""){
			emptys[emptys.length]=new Array(f.f_destination_place,"Destination (post code)");
		} else {
			if(!incNumber(trim(f.f_destination_place.value)))invalids[invalids.length]=new Array(f.f_destination_place,"Destination (post code)");
		}
		
		if(trim(f.f_quantity.value)=="")emptys[emptys.length]=new Array(f.f_quantity,"Number of pieces");
		if(trim(f.f_weight.value)=="")emptys[emptys.length]=new Array(f.f_weight,"Total weight (kg)");
	}	
	
	// Form2
	if(f.id=="form2") {
		if(trim(f.f_goods_name.value)=="")emptys[emptys.length]=new Array(f.f_goods_name,"Name of the goods");
		if(trim(f.f_source_country.value)=="")emptys[emptys.length]=new Array(f.f_source_country,"Station/country of dispatch");
		if(trim(f.f_destination_country.value)=="")emptys[emptys.length]=new Array(f.f_destination_country,"Station/country of dispatch");
		if(trim(f.f_quantity.value)=="")emptys[emptys.length]=new Array(f.f_quantity,"Number of pieces");
	}

	// Form3
	if(f.id=="form3") {
		if(trim(f.f_goods_specification.value)=="")emptys[emptys.length]=new Array(f.f_goods_specification,"Specification of the goods");
		if(trim(f.f_source_place.value)=="")emptys[emptys.length]=new Array(f.f_source_place,"Place of dispatch/loading port");
		if(trim(f.f_destination_place.value)=="")emptys[emptys.length]=new Array(f.f_destination_place,"Destination/delivery port");
		if(trim(f.f_weight.value)=="")emptys[emptys.length]=new Array(f.f_weight,"Weight of the consignment");
	}

	// Form4
	if(f.id=="form4") {
		if(trim(f.f_goods_specification.value)=="")emptys[emptys.length]=new Array(f.f_goods_specification,"Specification of the goods");
		if(trim(f.f_source_place.value)=="")emptys[emptys.length]=new Array(f.f_source_place,"Place of dispatch");
		if(trim(f.f_destination_place.value)=="")emptys[emptys.length]=new Array(f.f_destination_place,"Destination");
		if(trim(f.f_quantity.value)=="")emptys[emptys.length]=new Array(f.f_quantity,"Number of pieces");
		if(trim(f.f_weight.value)=="")emptys[emptys.length]=new Array(f.f_weight,"Total weight (kg)");
	}

	if(f.id=="form5") {
		if(trim(f.f_goods_specification.value)=="")emptys[emptys.length]=new Array(f.f_goods_specification,"Specification of the goods");
		if(trim(f.f_quantity.value)=="")emptys[emptys.length]=new Array(f.f_quantity,"Number of pieces");
		if(trim(f.f_weight.value)=="")emptys[emptys.length]=new Array(f.f_weight,"Weight (kg)");
	}

	if(f.id=="form6") {
		if(trim(f.f_goods_specification.value)=="")emptys[emptys.length]=new Array(f.f_goods_specification,"Specification of the goods");
		if(trim(f.f_send_address.value)=="")emptys[emptys.length]=new Array(f.f_send_address,"Address of dispatch");
		if(trim(f.f_quantity.value)=="")emptys[emptys.length]=new Array(f.f_quantity,"Number of pieces");
		if(trim(f.f_weight.value)=="")emptys[emptys.length]=new Array(f.f_weight,"Weight (kg)");
	}
	
	if(emptys.length>0 || invalids.length>0){
		var alrt="";
		if(emptys.length>0){
			alrt+="Following items wasn't filled in:\n\n";
			for(var i=0;i<emptys.length;i++){
				alrt+=emptys[i][1]+"\n";
				emptys[i][0].style.backgroundImage="url('96/images/layout/crumbs/exclamation-mark.gif')";
			}
		}
	
		if(invalids.length>0){
			alrt+=(emptys.length>0?"\n\n":"")+"Following items wasn't correctly filled in:\n\n";
			for(var i=0;i<invalids.length;i++){
				alrt+=invalids[i][1]+"\n";
				invalids[i][0].style.backgroundImage="url('96/images/layout/crumbs/exclamation-mark.gif')";
			}
		}
	
		alert(alrt);
		return false;
	} else {
		return true;
	}
}