
function heslo(cesta,x,y) {
	rozmery = 'width='+x+',height='+y+',left=10,top=10,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no';
	window.open(cesta,'heslo',rozmery)
	}

function obrazek(cesta,x,y) {
	url=cesta;
	rozmery='width='+x+',height='+y+',left=10,top=10,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no';
	window.open('okno.htm','obr',rozmery);
}


today = new Date();

function Validate(form) {


  if (!Validate_dates(form)) 
    return false;
  
	if ( isNaN(parseInt(form.adults.value)) || (parseInt(form.adults.value) <= 0) ) {
	  alert("ADULTS is required to fill in!");
		form.adults.focus();
		return false;
	}
	else
	  form.adults.value = parseInt(form.adults.value);

	if (form.children.value!='') {
		if ( isNaN(parseInt(form.children.value)) || (parseInt(form.children.value) < 0) )  {
		  alert("Wrong format of CHILDREN!");
			form.children.focus();
			return false;
		}
		else
		  form.children.value = parseInt(form.children.value);
  }
	else 
	  form.children.value = 0;
	



if (form.first_name.value.length<1)
   {
alert("Name is required to fill in");
form.first_name.focus();
return false;
}


if (form.surname.value.length<1)
   {
alert("Surname is required to fill in");
form.surname.focus();
return false;
}



if (form.address.value.length<1)
   {
alert("Address is required to fill in");
form.address.focus();
return false;
}






if (form.email.value.length<1)
   {
alert("Email is required to fill in");
form.email.focus();
return false;
}







  return true;
}

function Validate_dates(form) {
	var d = parseInt(form.chin_d.value);
	if (isNaN(d) || (d<1) || (d>31)) {
	 alert("Number format error of checkin-in day: "+form.chin_d.value);
	 form.chin_d.focus();
	 return false;
	}
	else
	 form.chin_d.value = d;
	 
	var m = parseInt(form.chin_m.options[form.chin_m.selectedIndex].value);
	var y = parseInt(form.chin_y.options[form.chin_y.selectedIndex].value);
	
	if (!Valid_date(d,m,y)) {
	 alert("Checkin "+d+"/"+m+"/"+y+" is wrong date!");
	 form.chin_d.focus();
	 return false;
	}
	
	if (isOutdated(d,m,y)) {
	 alert("Checkin "+d+"/"+m+"/"+y+" is out of date!");
	 form.chin_d.focus();
	 return false;
	}

	 var d1 = new Date(y, m-1, d, 0, 0, 0);

	 d = parseInt(form.chout_d.value);
	 if (isNaN(d) || (d<1) || (d>31)) {
		 alert("Number format error of checkout day: "+form.chout_d.value);
		 form.chout_d.focus();
		 return false;
	 }
	 else
		 form.chout_d.value = d;
		 
	 var m = parseInt(form.chout_m.options[form.chout_m.selectedIndex].value);
	 var y = parseInt(form.chout_y.options[form.chout_y.selectedIndex].value);

	 if (!Valid_date(d,m,y)) {
		 alert("Checkout "+d+"/"+m+"/"+y+" is wrong date!");
		 form.chout_d.focus();
		 return false;
	 }

	 var d2 = new Date(y, m-1, d, 0, 0, 0);
	 if (d2.getTime()<=d1.getTime()) {
		 alert("Checkout is not greater then checkin!");
		 return false;
	 }

  if (form.persons) {
    if ( isNaN(parseInt(form.persons.value)) || parseInt(form.persons.value)<1) {
      alert("Wrong value of persons!");
      form.persons.focus();
      return false;
    }
    else
      form.persons.value = parseInt(form.persons.value)
  }
  


  return true;	
}


// funkce overuje platnost data
function Valid_date(d,m,y) {
  month_length = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

  if ( ((y % 4)==0) && ((y % 100)!=0) || ((y % 400)==0) )
    month_length[1] = 29; //prestupny rok

  if (isNaN(y))
    return false;

  if ( (m<1) || (m>12) || isNaN(m) )
    return false;

  if ( (d>month_length[m-1]) || (d<1) || isNaN(d) )
    return false;

  return true;
}

function isOutdated(d, m, y) {
  dt = new Date(y, m-1, d, 23, 59, 59);
  if (dt.getTime()<today.getTime())
    return true;
  else
    return false;
}



// prevod datum z komb na objekt datum
function Combos2Date(d, m, y) {
	var day = parseInt(d);
  var month = parseInt(m);
  var year = parseInt(y);
 
  return new Date(year, month-1, day, 0, 0, 0);
}

// kontrola zadaneho data pri odesilani formulare
function Validate_datefields(form,prefix) {
	var day = parseInt(form[prefix+"_d"].value);
  var month = parseInt(form[prefix+"_m"].value);
  var year = parseInt(form[prefix+"_y"].value);
  if (Valid_date(day,month,year))
    return true;
  else
    return false;
}

function DateSplit(d) {
  if ( (d == -1) || (d == "") )
      return false;
  
  var d_arr = d.split("/");
  // IE bug, 09->0, musi se kontrolovat
  if (d_arr[0].substr(0,1) == '0')
    d_arr[0] = d_arr[0].substr(1,1);
  if (d_arr[1].substr(0,1) == '0')
    d_arr[1] = d_arr[1].substr(1,1);
  if (d_arr[2].substr(0,1) == '0')
    d_arr[2] = d_arr[2].substr(1,1); 
    
  d_arr[2] = parseInt(d_arr[2])<2000?2000+parseInt(d_arr[2]):parseInt(d_arr[2]);	
  d_arr[0] = parseInt(d_arr[0]);
  d_arr[1] = parseInt(d_arr[1]);
    
  return d_arr;
}

function Check_DateGtDate(d1, m1, y1, d2, m2, y2) {

  var d1 = new Date(y1, m1-1, d1, 0, 0, 0);
  var d2 = new Date(y2, m2-1, d2, 0, 0, 0);
  //alert(d1.getDate()+"."+d1.getMonth()+"."+d1.getFullYear()+" = "+d1.getTime());
  //alert(d2.getDate()+"."+d2.getMonth()+"."+d2.getFullYear()+" = "+d2.getTime());
  
  if (d1.getTime()<=d2.getTime())
    return false;
  else
    return true;
}

function ValidateSummary(form) {
  var summaxpax = 0;
  
  if (!idarr)
    return true;

  for (i = 0; i < idarr.length; i++) {
    suffix = idarr[i]+"_"+i;
    
    // quantity
    if (isNaN(parseInt(form["quantity"+suffix].value)) || parseInt(form["quantity"+suffix].value)<=0) {
      alert("Wrong quantity: "+form["quantity"+suffix].value);
      form["quantity"+suffix].focus();
      return false;   
    }
    else
      form["quantity"+suffix].value = parseInt(form["quantity"+suffix].value);

    if ( (qntarr) && (parseInt(form["quantity"+suffix].value) > qntarr[i]) ) {
      alert ("Maximum quantity is: "+qntarr[i]);
      form["quantity"+suffix].focus();
      return false;
    }

    if ( paxarr )
      summaxpax += parseInt(form["quantity"+suffix].value)*paxarr[i];

    var dt = DateSplit(form["checkin_d"+suffix].value+"/"+form["checkin_my"+suffix].value);

    // CHECKIN
    if (!dt || isNaN(dt[0]) || isNaN(dt[1]) || isNaN(dt[2])) {
      alert("Wrong date!");
      return false;
    }


    if (!Valid_date(dt[0], dt[1], dt[2])) {
      alert("Wrong checkin date:: "+dt[1]+"/"+dt[0]+"/"+dt[2]);
      return false; 
    }
    
    if (isOutdated(dt[0], dt[1], dt[2])) {
      alert("checkin: "+dt[1]+"/"+dt[0]+"/"+dt[2]+" is out of date"); 	    
      return false; 
    }

    // CHECKOUT
    dto = DateSplit(form["checkout_d"+suffix].value+"/"+form["checkout_my"+suffix].value);

    if (!dto || isNaN(dto[0]) || isNaN(dto[1]) || isNaN(dto[2])) {
      alert("Wrong date!");
      return false;
    }

 
    if (!Valid_date(dto[0], dto[1], dto[2])) {
      alert("Wrong checkin date:: "+dto[0]+"/"+dto[1]+"/"+dto[2]);
      return false; 
    }
  
    if (isOutdated(dto[0], dto[1], dto[2])) {
      alert("checkout: "+dto[0]+"/"+dto[1]+"/"+dto[2]+" is out of date"); 	    
      return false; 
    }

    if (!Check_DateGtDate(dto[0], dto[1], dto[2], dt[0], dt[1], dt[2])) {
      alert("checkout: "+dto[0]+"/"+dto[1]+"/"+dto[2]+" is not greater than checkin: "+dt[0]+"/"+dt[1]+"/"+dt[2]); 	    
      return false; 
    }
  } //end-for

  if (form.res_pax.value=="" || isNaN(parseInt(form.res_pax.value)) || parseInt(form.res_pax.value)<0) {
     alert("Wrong format of: PERSONS");	
     form.res_pax.focus();
     return false;
  }
  else
     form.res_pax.value = parseInt( form.res_pax.value);

  if (form.res_kids.value=="" || isNaN(parseInt(form.res_kids.value)) || parseInt(form.res_kids.value)<0) {
     alert("Wrong format of: KIDS");	
     form.res_kids.focus();
     return false;
  }
  else
     form.res_kids.value = parseInt( form.res_kids.value);

  var reqcap = parseInt(form.res_pax.value) + parseInt(form.res_kids.value);
  if (  reqcap > summaxpax && !confirm("Capacity of selected services is: "+summaxpax+", you required: "+reqcap+"\nContinue reservation?")) 
    return false;

  

  return true;
}









function OpenCal(form, suffix) {
  var y = document.forms[form][suffix+"_y"].options[document.forms[form][suffix+"_y"].selectedIndex].value;
  var m = document.forms[form][suffix+"_m"].options[document.forms[form][suffix+"_m"].selectedIndex].value;
   var d = document.forms[form][suffix+"_d"].options[document.forms[form][suffix+"_d"].selectedIndex].value;
  var date = m+'/'+d;

  window.open ('calendar.php?date='+date+'&form='+form+'&suffix='+suffix, '_blank','resizable=0,top=0,left=0,menubar=0,scrollbars=0,width=260,height=250');
  }


function OpenCal2(form, suffix) {
  var y = document.forms[form][suffix+"_y"].options[document.forms[form][suffix+"_y"].selectedIndex].value;
  var m = document.forms[form][suffix+"_m"].options[document.forms[form][suffix+"_m"].selectedIndex].value;
   var d = document.forms[form][suffix+"_d"].options[document.forms[form][suffix+"_d"].selectedIndex].value;
  var date = m+'/'+d;

  window.open ('calendar2.php?date='+date+'&form='+form+'&suffix='+suffix, '_blank','resizable=0,top=0,left=0,menubar=0,scrollbars=0,width=260,height=250');
  }





function ChangeCheckin(form) {
  var m,d,y;

  y = parseInt(form.chin_y.options[form.chin_y.options.selectedIndex].value);
  m = parseInt(form.chin_m.options[form.chin_m.options.selectedIndex].value);
  d = parseInt(form.chin_d.options[form.chin_d.options.selectedIndex].value);

  checkout = new Date(y, m -1, d+5);
  now  = new Date();


  form.chout_d.options.selectedIndex = checkout.getDate() - 1;
  form.chout_m.options.selectedIndex = checkout.getMonth();  
  form.chout_y.options.selectedIndex = checkout.getYear() - now.getYear();
}





function check_login(form) {

if (form.user_name.value=='') {
alert ("Insert your name please");
form.user_name.focus();
return false;
}


if (form.user_surname.value=='') {
alert ("Insert your surname please");
form.user_surname.focus();
return false;
}



if (form.user_address.value=='') {
alert ("Insert your address please");
form.user_address.focus();
return false;
}



if (form.user_email.value=='@' || form.user_email.value=='') {
alert ("Insert your email address please");
form.user_email.focus();
return false;
}


if (form.phone.value=='') {
alert ("Insert your phone please");
form.phone.focus();
return false;
}




return true;
}



PositionX = 100;
PositionY = 100;

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)

defaultWidth  = 500;
defaultHeight = 500;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows

var AutoClose = true;

// Do not edit below this line...
// ================================
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;

}

var optNN='scrollbars=0,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=0,width=150,height=100,left='+PositionX+',top='+PositionY;


function popImage(imageURL,imageTitle){

if (isNN){imgWin=window.open('about:blank','',optNN);}
if (isIE){imgWin=window.open('about:blank','',optIE);}



with (imgWin.document){
writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');


writeln('isNN=(navigator.appName=="Netscape")?1:0;');
writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');



writeln('function reSizeToImage(){');

writeln('if (isIE){');
writeln('window.resizeTo(100,100);');
writeln('width=100-(document.body.clientWidth-document.images[0].width);');
writeln('height=100-(document.body.clientHeight-document.images[0].height);');
writeln('window.resizeTo(width,height);}');





writeln('if (isNN){');       
writeln('window.innerWidth=document.images["George"].width;');
writeln('window.innerHeight=document.images["George"].height;}}');






writeln('function doTitle(){document.title="'+imageTitle+'";}');
writeln('</sc'+'ript>');
if (!AutoClose) writeln('</head><body bgcolor=#FFFFFF scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
writeln('<a href="http://www.czech-republic-accommodation.eu" onclick="javascript:self.close();" target=hp><img name="George" src='+imageURL+' style="display:block"></body></html>');
close();		
}}PositionX = 100;
PositionY = 100;

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)

defaultWidth  = 500;
defaultHeight = 500;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows

var AutoClose = true;

// Do not edit below this line...
// ================================
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;

}

var optNN='scrollbars=0,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=0,width=150,height=100,left='+PositionX+',top='+PositionY;


function popImage(imageURL,imageTitle){

if (isNN){imgWin=window.open('about:blank','',optNN);}
if (isIE){imgWin=window.open('about:blank','',optIE);}



with (imgWin.document){
writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');


writeln('isNN=(navigator.appName=="Netscape")?1:0;');
writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');



writeln('function reSizeToImage(){');

writeln('if (isIE){');
writeln('window.resizeTo(100,100);');
writeln('width=100-(document.body.clientWidth-document.images[0].width);');
writeln('height=100-(document.body.clientHeight-document.images[0].height);');
writeln('window.resizeTo(width,height);}');





writeln('if (isNN){');       
writeln('window.innerWidth=document.images["George"].width;');
writeln('window.innerHeight=document.images["George"].height;}}');






writeln('function doTitle(){document.title="'+imageTitle+'";}');
writeln('</sc'+'ript>');
if (!AutoClose) writeln('</head><body bgcolor=#FFFFFF scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
writeln('<a href="http://www.czech-republic-accommodation.eu" onclick="javascript:self.close();" target=hp><img name="George" src='+imageURL+' style="display:block"></body></html>');
close();		
}}

