function clear_textarea(id,text){
	if(document.getElementById(id).value == text){
		document.getElementById(id).value='';
	}
	else{
		document.getElementById(id).value=document.getElementById(id).value;
	}
}

function addDays2(myDate,days) {
	return new Date(myDate.getTime() + days*24*60*60*1000);
}
		
function change_per_date_to2(date_from,date_to){

	//alert(document.getElementById("checkin").value);
	//var date1=document.reservation_form2.checkin.value;
	var date1=document.getElementById(date_from).value;
	var test=0;
	var day;
	
	var myDate1=new Date();
	
	var date1SplitResult = date1.split("/");
	
	myDate1.setDate(parseInt(date1SplitResult[0].replace(/^[0]+/g,"")));

	myDate1.setMonth(date1SplitResult[1].replace(/^[0]+/g,"")-1);
	myDate1.setYear(parseInt(date1SplitResult[2]));
	
	var myd2=addDays2(myDate1,1);
	
	//alert(myd2);
	
	var myDate2=new Date();

	//alert(myDate2.getDate());
	myDate2=myd2;
	//alert(myDate2);
	if(parseInt(myDate2.getDate())<10){
			if(parseInt(myDate2.getMonth())<10){
				document.getElementById(date_to).value="0"+myDate2.getDate()+"/0"+(parseInt(myDate2.getMonth())+1)+"/"+myDate2.getFullYear();
			}
			else{
				document.getElementById(date_to).value="0"+myDate2.getDate()+"/"+(parseInt(myDate2.getMonth())+1)+"/"+myDate2.getFullYear();
			}
		}
		else if(parseInt(myDate2.getMonth())<10){
			document.getElementById(date_to).value=myDate2.getDate()+"/0"+(parseInt(myDate2.getMonth())+1)+"/"+myDate2.getFullYear();
		}
		else{
			document.getElementById(date_to).value=myDate2.getDate()+"/"+(parseInt(myDate2.getMonth())+1)+"/"+myDate2.getFullYear();
	
		}	
	
}


function get_number_of_persons(lang,persons){
	//alert(persons);
	var id=document.choose_reserve.roomt_un_id.value;
	//alert(persons);	
	new Ajax.Request('person_num_select_boxes.php?id='+id+'&lang='+lang+persons,
	  {
		method:'get',
		onSuccess: function(transport){
		  var response = transport.responseText || "";
		 
		  document.getElementById("person_num").innerHTML=response;
		},
		onFailure: function(){ alert('Something went wrong...') }
	  });
}

function get_number_of_persons2(lang,roomt_id){
	
	var new_id=document.reservation_form.roomt_un_id_2_tmp.value;
	
	document.getElementById("roomt_un_id_2").value=new_id;
	
	var id=document.getElementById("roomt_un_id_2").value;
	
	new Ajax.Request('person_num_select_boxes.php?flag=2&id='+id+'&lang='+lang,
	  {
		method:'get',
		onSuccess: function(transport){
		  var response = transport.responseText || "";
		  document.getElementById("res_persons").innerHTML=response;
		},
		onFailure: function(){ alert('Something went wrong...') }
	  });
}



function get_value_form(arrival,departure,form_id){
	
		var date1=document.getElementById(arrival).value;
		var date2=document.getElementById(departure).value;
	
		var date1SplitResult = date1.split("/");
		var date2SplitResult = date2.split("/");
		
		var curr= new Date();
		
		var currentTime = new Date();
		
		var curMonth = currentTime.getMonth();
		var curYear = currentTime.getFullYear();
		var curDate = currentTime.getDate();
	
	
		var tmpDate11=Date.UTC(date1SplitResult[2],date1SplitResult[1]-1,date1SplitResult[0]);
		var tmpDate12=Date.UTC(date2SplitResult[2],date2SplitResult[1]-1,date2SplitResult[0]);	
	
		var tmpCurr=Date.UTC(curYear,curMonth,curDate);
		
		
		if(tmpDate11<tmpCurr){
			alert("Arrival Date should not be earlier than today!");
			document.form_id.arrival.value="";
			return false;
		}
		else if(tmpDate12<tmpCurr){
			alert("Departure Date should not be earlier than today!");
			document.form_id.departure.value="";
			return false;
		}
		else{
			
			if (tmpDate11>tmpDate12)
			{
			alert("Departure Date must be after arrival Date!");
			document.form_id.departure.value="";
			return false;
			}
			else if(tmpDate11<tmpDate12)
			{
			return true;
			}
		}
		
		return false;
}

function submit_form(arrival,departure,first_name,last_name,address,phone,city,pc,country,email,form_id,person_num){
	var check=false;
	
	if(form_id=="choose_reserve"){
		check=check_person_num();
	}
	else if(form_id=="reservation_form"){
		check=check_person_num2(person_num);
	}
	else{
		check=true;	
	}
	
	
	if(check){
		
		var count=0;
		
		var txtBoxes = document.getElementById(form_id.toString()).getElementsByTagName("input");
		  for(var i = 0; i < txtBoxes.length; i++){
			if(txtBoxes[i].name == "first_name" || txtBoxes[i].name == "last_name" || txtBoxes[i].name == "address" || txtBoxes[i].name == "phone" || txtBoxes[i].name == "city" || txtBoxes[i].name == "pc" || txtBoxes[i].name == "country" || txtBoxes[i].name == "email"){
				count++;
			}
			  
		  };
	
		if(form_id!="proceed_reservation"){
			if(count>0){
				MM_validateForm(arrival,'','R',departure,'','R',first_name,'','R',last_name,'','R',address,'','R',phone,'','R',city,'','R',pc,'','R',country,'','R',email,'','RisEmail');
			}
			else{
				MM_validateForm(arrival,'','R',departure.toString(),'','R');	
			}
		}
		else{
			document.getElementById(form_id).submit();
			return true;
		}
	
		if(document.MM_returnValue==true){
				if(get_value_form(arrival,departure,form_id)){	
					document.getElementById(form_id).submit();
					return true;
				}
				else{
					return false;
				}
			}
		else{
			return false;
		}
	}
	
}

function submit_payment_form(lang,hotel_id){
	
	
	for (var i=0; i < document.payment_details.payment_method.length; i++){
	   if (document.payment_details.payment_method[i].checked){
		  var rad_val = document.payment_details.payment_method[i].value;
		}
	}

	
	if(rad_val=="PayPal"){
		document.payment_details.action="index.php?file=14&lang="+lang+"&hotel_id="+hotel_id;
	}
	else if(rad_val=="Bank Deposit"){
		document.payment_details.action="index.php?file=17&lang="+lang+"&hotel_id="+hotel_id;
	}
	else if(rad_val=="Credit Card"){
		document.payment_details.action="https://www.voulahotel.gr/index.php?file=18&lang="+lang+"&hotel_id="+hotel_id;
	}
	
	MM_validateForm('res_first_name','','R','res_last_name','','R','res_phone','','RisNum','res_email','','RisEmail','res_address','','R','res_city','','R','res_country','','R','res_pc','','R','res_mobile','','isNum','res_pc','','isNum');
	
	if(document.MM_returnValue==true){
		document.payment_details.submit();
		return true;
	}
	else{
		return false;	
	}
	
}

function submit_reservation_form_right(){
	document.choose_reserve.submit();	
}

function get_images(page,lang,hotel_id){
	//alert("aaa");
	new Ajax.Request('get_images.php?page='+page+'&lang='+lang+'&hotel_id='+hotel_id,
	  {
		method:'get',
		onSuccess: function(transport){
		  var response = transport.responseText || "";
		 
		  document.getElementById("images_table").innerHTML=response;
		},
		onFailure: function(){ alert('Something went wrong...') }
	  });
}

function get_large_img(id){
	
	new Ajax.Request('get_large_img.php?img='+id,
	  {
		method:'get',
		onSuccess: function(transport){
		  var response = transport.responseText || "";
		 
		  document.getElementById("image_large").innerHTML=response;
		  initImage();
		},
		onFailure: function(){ alert('Something went wrong...') }
	  });	
	
}

function check_person_num(){
		
		
		var tmp='person_'+jQuery('[name=roomt_un_id]').val()+'_adult';
		var tmp2='person_'+jQuery('[name=roomt_un_id]').val()+'_child';
		
		var adult=Number(jQuery('[name='+tmp+']').val());
		var child=Number(jQuery('[name='+tmp2+']').val());
		var per_num=Number(jQuery('[name=hidden_per_num]').val());
		
		
		if(adult==0 && child==0){
			//alert("Ο αριθμός δεν αντιστοιχεί στον σωστό αριθμό ατόμων");
			alert("The persons you have chosen do not agree with the room type");
			return false;
		}
		else{
			if(per_num>0){
				per_num=per_num;	
			}
			else{
				per_num=0;	
			}
			//alert(adult+child<per_num);
			if((adult+child)==per_num){
				return true;
			}
			else{
				//alert("Ο αριθμός δεν αντιστοιχεί στον σωστό αριθμό ατόμων");
				alert("The persons you have chosen do not agree with the room type");
				return false;
			}
			
		}
}	

function check_person_num2(person_num){
		
		
		var tmp='person_'+jQuery('[name=roomt_un_id_2_tmp]').val()+'_adult_2';
		var tmp2='person_'+jQuery('[name=roomt_un_id_2_tmp]').val()+'_child_2';
		
		var adult=Number(jQuery('[name='+tmp+']').val());
		var child=Number(jQuery('[name='+tmp2+']').val());
	
		if(isNaN(jQuery('[name=hidden_per_num2]').val())){
			var per_num=Number(jQuery('[name=hidden_per_num_with_refresh]').val());
		}
		else{
			var per_num=Number(jQuery('[name=hidden_per_num2]').val());
		}
		
	
		//alert("aaa="+adult+"&bbb="+child+"&ccc="+per_num);
	
		if(adult==0 && child==0){
			//alert("Ο αριθμός δεν αντιστοιχεί στον σωστό αριθμό ατόμων");
			alert("The persons you have chosen do not agree with the room type");
			return false;
		}
		else{
			if(per_num>0){
				per_num=per_num;	
			}
			else{
				per_num=0;	
			}
			
			if((adult+child)==per_num){
				return true;
			}
			else{
				//alert("Ο αριθμός δεν αντιστοιχεί στον σωστό αριθμό ατόμων");
				alert("The persons you have chosen do not agree with the room type");
				return false;
			}
			
		}
		
}

function search_form_submit(){
	if($('search_text').value==""){
		alert($('searc_text_required').value);
	}
	else{
		document.search_form.submit();	
	}
}

/*function num_per_update(room_type_id,lang){
	var tmp='person_'+room_type_id+'_adult';
	var tmp2='person_'+room_type_id+'_child';
	alert(jQuery('[name='+tmp+']').val());
	//alert(jQuery('[name=person_2_adult]').val());
	//var id=document.choose_reserve.roomt_un_id.value;
	//alert(persons);	
	new Ajax.Request('person_num_select_boxes.php?id='+room_type_id+'&lang='+lang+'&adult='+jQuery('[name='+tmp+']').val()+'&child='+jQuery('[name='+tmp2+']').val(),
	  {
		method:'get',
		onSuccess: function(transport){
		  var response = transport.responseText || "";
		 
		  document.getElementById("person_num").innerHTML=response;
		},
		onFailure: function(){ alert('Something went wrong...') }
	  });
	
}*/

function initImage() {
  
  imageId = 'thephoto';
  image = document.getElementById(imageId);
  setOpacity(image, 33);
  image.style.visibility = 'visible';
  fadeIn(imageId,0);
}

function setOpacity(obj, opacity) {
  
  opacity = (opacity == 100)?99.999999999999999999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/33.3333333333333333333;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/33.3333333333333333333;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/33.3333333333333333333;
}

function fadeIn(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity <= 100) {
      setOpacity(obj, opacity);
      opacity += 12;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
    }
  }
}

function submit_payment_form_credit(){
	MM_validateForm('cardType','','R','expiryMonth','','R','expiryYear','','R','ccn','','RisNum','ccd','','RisNum','cardOwner','','R','phone','','R','address1','','R','city','','R','country','','R');
	
	if(document.MM_returnValue==true){
		document.myform.submit();
	}
	else{
		return false;
	}
}

function add_aircondition_breakfast(check){
		var roomt_un_id=Number(jQuery('[name=roomt_un_id]').val());
		var tmp='person_'+roomt_un_id+'_child';
		var tmp1='person_'+roomt_un_id+'_adult';
		var adult=Number(jQuery('[name='+tmp+']').val());
		var child=Number(jQuery('[name='+tmp1+']').val());
		var persons=adult+child;
		var res_days=Number(jQuery('[name=res_days]').val());
		var price =Number(jQuery('[name=price]').val());
	
		if(check==1){
			if(jQuery('[name=aircondition]').attr('checked')){
				var tmp_price=price+(6*res_days);
				jQuery('[name=price]').val(tmp_price);
				jQuery('#price_field').html("&euro;&nbsp;"+tmp_price);
			}
			else{
				var tmp_price=price-(6*res_days);
				jQuery('[name=price]').val(tmp_price);
				jQuery('#price_field').html("&euro;&nbsp;"+tmp_price);
			}
		}
		else if(check==2){
			if(jQuery('[name=breakfast]').attr('checked')){
				var tmp_price=price+(5*res_days*persons);
				jQuery('[name=price]').val(tmp_price);
				jQuery('#price_field').html("&euro;&nbsp;"+tmp_price);
			}
			else{
				var tmp_price=price-(5*res_days*persons);
				jQuery('[name=price]').val(tmp_price);
				jQuery('#price_field').html("&euro;&nbsp;"+tmp_price);
			}
		}
}
