
// set object dimensions
function set_h(val, id){
	var obj = document.getElementById(id);
	obj.style.height = val+"px";
}

// get object height
function get_h(id){
	var obj_h = document.getElementById(id);
	var new_h = obj_h.style.height;
		new_h = parseFloat(new_h);
	return new_h;
}

/*
function get_win(pictures, win_name, width, height){
	window.open("./img/pics.php?pic="+pictures, win_name, "left=100, top=100, width="+width+", height="+height);
}
*/

function stat(message){
		window.status = message;
}

// preloading menu images
imgsrc = new Array();
	imgsrc[0] = './img/left_menu/active/menu_left_active_1x1.gif';
	imgsrc[1] = './img/left_menu/active/menu_left_active_2x1.gif';
	imgsrc[2] = './img/left_menu/active/menu_left_active_3x1.gif';
	imgsrc[3] = './img/left_menu/active/menu_left_active_4x1.gif';
	imgsrc[4] = './img/left_menu/active/menu_left_active_5x1.gif';
	imgsrc[5] = './img/left_menu/active/menu_left_active_6x1.gif';
	imgsrc[6] = './img/left_menu/active/menu_left_active_7x1.gif';

img = new Array();
for (i=0; i<imgsrc.length; i++){
	img[i] = new Image();
	img[i].src = imgsrc[i];
}

// changing menu images onmouseover		
function chng(i,imgname){
	if(document.images){
			document[imgname].src=img[i].src;
	}
}

function chng2(i, img_id){
	image=document.getElementById(img_id);
	image.setAttribute("src", imgsrc[i]);
}

function leave(tgt){
	location.href = tgt;
}

function getPositionByID(ob){
		obj = document.getElementById(ob);
		objLeft = obj.offsetLeft;
		objTop = obj.offsetTop;
}

function moveobj(id, x, y, ob){
	getPositionByID(ob);
	document.getElementById(id).style.top = objTop + y + "px";
	document.getElementById(id).style.left = objLeft + x + "px";
}

function popUp(menuName,on){
	if(on){
		document.getElementById(menuName).style.visibility = "visible";
	}else{
		document.getElementById(menuName).style.visibility = "hidden";
	}
}

function getLocation(){
	var loc = window.location;
	return loc;
}

function draw_credits(){
	document.write("<a href='http://validator.w3.org/check?uri="+getLocation()+"'>W3C XHTML Validate</a>&nbsp;&nbsp;&nbsp;&nbsp;");
	document.write("<a href='http://jigsaw.w3.org/css-validator/validator?uri="+getLocation()+"'>W3C CSS Validate</a>");
}

function get_win(pictures, win_name, width, height){
	window.open("./img/pics.php?pic="+pictures, win_name, "left=100, top=100, width="+width+", height="+height);
}

function check_email(e) {
		ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
		for(i=0; i < e.length ;i++){
				if(ok.indexOf(e.charAt(i))<0){ 
					return (false);
				}	
		} 

		if (document.images) {
				re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
				re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
				if (!e.match(re) && e.match(re_two)) {
					return (-1);		
				} 
		}

}

function validate(){
var chyba = "Nesprávné nebo chybějící údaje:\n\n";
var fall = 0;
var emptypass = 0;
var el = document.getElementById("regform");

	if(el.day_begin.value==0){
			chyba = chyba + "Den počátku pobytu\n";
			fall=1;
	}if(el.month_begin.value==0){
			chyba = chyba + "Měsíc počátku pobytu\n";
			fall=1;
	}if(el.year_begin.value==0){
			chyba = chyba + "Rok počátku pobytu\n";
			fall=1;
	}if(el.day_end.value==0){
			chyba = chyba + "Den konce pobytu\n";
			fall=1;
	}if(el.month_end.value==0){
			chyba = chyba + "Měsíc konce pobytu\n";
			fall=1;
	}if(el.year_end.value==0){
			chyba = chyba + "Rok konce pobytu\n";
			fall=1;
	}if(el.dosp_osoby.value==""){
			chyba = chyba + "Počet dospělých osob\n";
			fall=1;
	}if(el.deti.value==""){
			chyba = chyba + "Počet dětí do 10 let\n";
			fall=1;
	}if(el.fname.value==""){
			chyba = chyba + "Jméno\n";
			fall=1;
	}if(el.lname.value==""){
			chyba = chyba + "Příjmení\n";
			fall=1;
	}
	
	if(el.company.value!=""){
			if(el.ico.value==""){
					chyba = chyba + "Pokud jste společnost, uveďte Vaše IČO\n";
					fall=1;
			}
	}

	if(el.street.value==""){
			chyba = chyba + "Ulice\n";	
			fall=1;
	}if(el.city.value==""){
			chyba= chyba + "Město\n";
			fall=1;
			emptypass = 1;
	}if(el.psc.value==""){
			chyba = chyba + "PSČ\n";
			fall=1;
			emptypass = 1;
	}if(el.phone.value==""){
			chyba = chyba + "Telefon\n";
			fall=1;
	}if(el.email.value==""){
			chyba = chyba + "E-mail\n";
			fall=1;
	}else{
			if (!check_email(el.email.value)){
					chyba = chyba + "Vaše E-mailová adresa není ve správném formátu.\n";
					fall=1;
			}
	}if(el.potvrzeni.value==0){
			chyba = chyba + "Způsob potvrzení objednávky\n";
			fall=1;
	}

	if (fall==1){
			window.alert(chyba);
			return false;
	}else{
			return true;
	}

}

function conf_remove(action){
	var cnf = window.confirm("Skutečně chcete odstranit záznam? \n"+action);
	if(cnf == true){
		return true;
	}else{
		return false;
	}
}
