// function to get only two decimals for any number
function check(name){

	if(name=="onlinepayment") {
	
		document.getElementById('onlineo').disabled=false;
		document.getElementById('method3').checked=false;
		document.getElementById('method4').checked=false;		
		document.getElementById('bank_check').disabled=true;
	}
	else {
		
		document.getElementById('onlineo').disabled=true;	
		document.getElementById('method2').checked=false;
		document.getElementById('bank_check').disabled=false;		
		
	}
}




function displaynum(numnum)
{
var num = new Number(numnum);
return num.toFixed(2);
}

function calcs(name1, target, target2, personsno) {

		if (document.getElementById(name1).checked == true) {

			var a, b;
			a = parseFloat(displaynum(document.getElementById(name1).value * document.getElementById(personsno).value));
			b = parseFloat(displaynum(document.getElementById(target2).value));
			if (isNaN(b)) b = 0;

			document.getElementById(target).value = displaynum(a + b);
			document.getElementById(target2).value = displaynum(a + b);
			
		}
		if (document.getElementById(name1).checked != true && document.getElementById(target2).value != 0) {
			
			document.getElementById(target).value -= displaynum(parseFloat(document.getElementById(name1).value * document.getElementById(personsno).value));		
			document.getElementById(target2).value -= displaynum(parseFloat(document.getElementById(name1).value * document.getElementById(personsno).value));
		}

		grand();
}

function calcs2(name1, target, target2, personsno) {

		if (document.getElementById(name1).checked == true) {
			document.getElementById(target).value = displaynum(parseFloat(document.getElementById(name1).value * document.getElementById(personsno).value));					
			document.getElementById(target2).value = displaynum(parseFloat(document.getElementById(name1).value * document.getElementById(personsno).value));
		}
		if (document.getElementById(name1).checked != true && document.getElementById(target2).value != 0) {
			
			document.getElementById(target).value -= displaynum(parseFloat(document.getElementById(name1).value * document.getElementById(personsno).value));		
			document.getElementById(target2).value -= displaynum(parseFloat(document.getElementById(name1).value * document.getElementById(personsno).value));
		}

		grand();
}


function calcs3(name1, personsno1, name2, personsno2, name3, personsno3, target, target2) {

		var a, b, c;

		if (document.getElementById(name1).checked == true) {
			
			a = parseFloat(displaynum(document.getElementById(name1).value * document.getElementById(personsno1).value));
		} else { a = 0; }

		if (document.getElementById(name2).checked == true) {
			
			b = parseFloat(displaynum(document.getElementById(name2).value * document.getElementById(personsno2).value));
		} else { b = 0; }
		
		if (document.getElementById(name3).checked == true) {
			
			c = parseFloat(displaynum(document.getElementById(name3).value * document.getElementById(personsno3).value));
			
		} else { c = 0; }

			if (isNaN(a)) a = 0;
			if (isNaN(b)) b = 0;
			if (isNaN(c)) c = 0;

			document.getElementById(target).value = displaynum(a + b + c);
			document.getElementById(target2).value = displaynum(a + b + c);

		grand();
}



function disabl(name1, name2, name3, name4, name5) {
	
	if (document.getElementById(name1).checked == true) {
		
		document.getElementById(name2).disabled = true;
		document.getElementById(name3).disabled = true;
		document.getElementById(name4).disabled = true;		
		document.getElementById(name5).disabled = true;						
	}
	else {
		
		document.getElementById(name2).disabled = false;
		document.getElementById(name3).disabled = false;
		document.getElementById(name4).disabled = false;				
		document.getElementById(name5).disabled = false;				
	}
	
}

function calc4(name1, name2, name3, name4, name5, name6, name7, name8, name9) {

	do {
		a32 = document.form1.item(name1).value;				
		a33 = document.form1.item(name2).value;				

		vv1 = parseInt(document.form1.item(name1).value);
	  	if (isNaN(vv1)) vv1 = 0;
		vv2 = parseInt(document.form1.item(name2).value);
	  	if (isNaN(vv2)) vv2 = 0;
		vv5 = parseInt(document.form1.item(name5).value);
	  	if (isNaN(vv5)) vv5 = 0;

		vv3 = parseInt(document.form1.item(name3).value);
		vv4 = parseInt(document.form1.item(name4).value);
		vv6 = parseInt(document.form1.item(name6).value);


		vv7 = document.form1.item(name8).value;
		vv8 = document.form1.item(name9).value;
		
/*		alert('vv7');
		alert(vv7);
		
		alert('vv8');
		alert(vv8);
*/		
		
		vv9 = parseInt(vv7.substring(8,10));
		vv10 = parseInt(vv8.substring(8,10));
/*		
		alert('vv9');
		alert(vv9);
			
		alert('vv10');
		alert(vv10);
*/
		
		
		vv11 = vv10 - vv9;			// minimum stay should be 2 nights	
/*		
		alert('vv11');
		alert(vv11);
*/


		sn_sum = vv1 * vv3 * vv11;
		db_sum = vv2 * vv4 * vv11;
		flt_sum = vv5 * vv6;

		
		document.form1.item(name7).value = (sn_sum + db_sum + flt_sum);


		if(((a32.length!=0) || (a33.length!=0)) && ((document.form1.item(name8).value.length==0 || document.form1.item(name9).value.length==0))) {
			alert(errorMsg10);
			document.form1.item(name8).focus();
			
			document.form1.item(name1).value = '';
			document.form1.item(name2).value = '';
			document.form1.item(name5).value = '';
			document.form1.item(name7).value = '';
			
			return false;
			break;			
		}

//		alert(vv11);

		if (vv11 < 2) {
			alert ("(*) Minimum stay at any hotel is 02 nights");
			document.form1.item(name1).value = '';
			document.form1.item(name2).value = '';
			document.form1.item(name5).value = '';
			document.form1.item(name7).value = '';			

			return false;
			break;			
		}		

		prepost();
		
	} while(0) 
}

function calc44(name1, name2, name3, name4, name5, name6, name7) {
	
		vv1 = parseInt(document.form1.item(name1).value);
	  	if (isNaN(vv1)) vv1 = 0;
		vv2 = parseInt(document.form1.item(name2).value);
	  	if (isNaN(vv2)) vv2 = 0;
		vv5 = parseInt(document.form1.item(name5).value);
	  	if (isNaN(vv5)) vv5 = 0;

		vv3 = parseInt(document.form1.item(name3).value);
		vv4 = parseInt(document.form1.item(name4).value);
		vv6 = parseInt(document.form1.item(name6).value);


		sn_sum = vv1 * vv3;
		db_sum = vv2 * vv4;
		flt_sum = vv5 * vv6;

		
		document.form1.item(name7).value = (sn_sum + db_sum + flt_sum);
		
		prepost();
}

function calend_pres(name1, name2, name3, name4) {

			document.form1.item(name1).value = '';
			document.form1.item(name2).value = '';
			document.form1.item(name3).value = '';
			document.form1.item(name4).value = '';
	
}

function extra() {
	
	ss1 = parseInt(document.form1.ex_meet_sum.value);
  	if (isNaN(ss1)) ss1 = 0;
	ss2 = parseInt(document.form1.ex_visa_sum.value);
  	if (isNaN(ss2)) ss2 = 0;
/*	ss3 = parseInt(document.form1.ex_depa_sum.value);
  	if (isNaN(ss3)) ss3 = 0;
	ss4 = parseInt(document.form1.ex_vip_sum.value);
  	if (isNaN(ss4)) ss4 = 0;
*/
	document.form1.extra_sum.value = ss1 + ss2;
	document.form1.extra_sum_up.value = ss1 + ss2;

	grand();
}

function tours() {
	
	d1 = parseInt(document.form1.tour_c1_sum.value);
  	if (isNaN(d1)) d1 = 0;
	d2 = parseInt(document.form1.tour_c2_sum.value);
  	if (isNaN(d2)) d2 = 0;
	d3 = parseInt(document.form1.tour_c3_sum.value);
  	if (isNaN(d3)) d3 = 0;
	d4 = parseInt(document.form1.tour_c4_sum.value);
  	if (isNaN(d4)) d4 = 0;
	d5 = parseInt(document.form1.tour_c5_sum.value);
  	if (isNaN(d5)) d5 = 0;
	d6 = parseInt(document.form1.tour_c6_sum.value);
  	if (isNaN(d6)) d6 = 0;

	document.form1.tours_sum.value = d1 + d2 + d3 + d4 + d5 + d6;
	document.form1.tours_sum_up.value = d1 + d2 + d3 + d4 + d5 + d6;

	grand();

}

function prepost(){
	
	e1 = parseInt(document.form1.pre_luxor_sum.value);
  	if (isNaN(e1)) e1 = 0;
	e2 = parseInt(document.form1.pre_hurg_sum.value);
  	if (isNaN(e2)) e2 = 0;
	e3 = parseInt(document.form1.pre_sharm_sum.value);
  	if (isNaN(e3)) e3 = 0;
	e4 = parseInt(document.form1.pre_d3_sum.value);
  	if (isNaN(e4)) e4 = 0;
	e5 = parseInt(document.form1.pre_d4_sum.value);
  	if (isNaN(e5)) e5 = 0;
	e6 = parseInt(document.form1.pre_d5_sum.value);
  	if (isNaN(e6)) e6 = 0;
	
	document.form1.prepost_sum.value = e1 + e2 + e3 + e4 + e5 + e6 ;
	document.form1.prepost_sum_up.value = e1 + e2 + e3 + e4 + e5 + e6 ;

	grand();
	
	
}

function acom() {
	
	s1 = parseInt(document.form1.inter_1_sum.value);
  	if (isNaN(s1)) s1 = 0;
	s2 = parseInt(document.form1.inter_2_sum.value);
  	if (isNaN(s2)) s2 = 0;
	s5 = parseInt(document.form1.sher_sum.value);
  	if (isNaN(s5)) s5 = 0;

	document.form1.accom_sum.value = s1 + s2 + s5;
	document.form1.accom_sum_up.value = s1 + s2 + s5;

	grand();
}


function grand() {

	t1 = parseFloat(document.getElementById('accom_sum').value);
  	if (isNaN(t1)) t1 = 0;
	t2 = parseFloat(document.getElementById('prepost_sum').value);
  	if (isNaN(t2)) t2 = 0;
	t3 = parseFloat(document.getElementById('extra_sum').value);
  	if (isNaN(t3)) t3 = 0;
	t4 = parseFloat(document.getElementById('tours_sum').value);
  	if (isNaN(t4)) t4 = 0;

	document.getElementById("grand_sum").value = displaynum(t1 + t2 + t3 + t4);
}

//////////////////////// END OF CALCULATIONS ///////////////////


function fd()
{
do {

		var y;
		y=document.form1.nam.value;
		if((y.length==0) || (y.charAt(0)==' '))
		{
			alert(errorMsg1);
			document.form1.nam.value="";			
			document.form1.nam.focus();
			return false;
			break;
		}

		var x;
		x=document.form1.fnam.value;
		if((x.length==0) || (x.charAt(0)==' '))
		{
			alert(errorMsg0);
			document.form1.fnam.value="";			
			document.form1.fnam.focus();
			return false;
			break;
		}


		var zi;
		zi=document.form1.comp.value;
		if((zi.length==0) || (zi.charAt(0)==' '))
		{
			alert(errorMsg223);
			document.form1.comp.value="";			
			document.form1.comp.focus();
			return false;
			break;
		}


		var yni;
		yni=document.form1.inst.value;
		if((yni.length==0) || (yni.charAt(0)==' '))
		{
			alert(errorMsg911);
			document.form1.inst.value="";			
			document.form1.inst.focus();
			return false;
			break;
		}


		var zy22;
		zy22=document.form1.adr.value;
		if((zy22.length==0) || (zy22.charAt(0)==' '))
		{
			alert(errorMsg33);
			document.form1.adr.value="";			
			document.form1.adr.focus();
			return false;
			break;
		}	


		var z;
		z=document.form1.cit.value;
		if((z.length==0) || (z.charAt(0)==' '))
		{
			alert(errorMsg2);
			document.form1.cit.value="";			
			document.form1.cit.focus();
			return false;
			break;
		}

/*
		var zni;
		zni=document.form1.func.value;
		if((zni.length==0) || (zni.charAt(0)==' '))
		{
			alert(errorMsg233);
			document.form1.func.value="";			
			document.form1.func.focus();
			return false;
			break;
		}

		var zmi;
		zmi=document.form1.zipc.value;
		if((zmi.length==0) || (zmi.charAt(0)==' '))
		{
			alert(errorMsg234);
			document.form1.zipc.value="";			
			document.form1.zipc.focus();
			return false;
			break;
		}
*/


		var xy;
		xy=document.form1.cntry.value;
		if((xy.length==0) || (xy.charAt(0)==' '))
		{
			alert(errorMsg3);
			document.form1.cntry.value="";			
			document.form1.cntry.focus();
			return false;
			break;
		}

		var b;
		b=document.form1.pho.value;
		if((b.length==0) || (b.charAt(0)==' '))
		{
			alert(errorMsg17);
			document.form1.pho.value="";
			document.form1.pho.focus(); 
			return false;
			break;
		}		
			b=parseInt(document.form1.pho.value);
			if(isNaN(b))
		{
			alert(errorMsg18);
			document.form1.pho.value="";
			document.form1.pho.focus();
			return false;
			break;
		}

		var c;
		c=document.form1.fax.value;
		if((c.length==0) || (c.charAt(0)==' '))
		{
			alert(errorMsg19);
			document.form1.fax.value="";
			document.form1.fax.focus(); 
			return false;
			break;
		}		
			c=parseInt(document.form1.fax.value);
			if(isNaN(c))
		{
			alert(errorMsg20);
			document.form1.fax.value="";
			document.form1.fax.focus();
			return false;
			break;
		}

		var r;
		r=document.form1.emal.value;
		if((r.length==0) || (r.charAt(0)==' '))
		{
			alert(errorMsg4);
			document.form1.emal.value=''; 
			document.form1.emal.focus(); 
			return false;
			break;
		}

		   if (document.form1.emal.value.indexOf('@',0)==-1 ||
	       document.form1.emal.value.indexOf('@',0)== 0 ||
	       document.form1.emal.value.indexOf('.',0)==-1 ||
   	       document.form1.emal.value.indexOf('.',0)== 0) 
		   {
				alert(errorMsg5);
//			    document.form1.emal.value="";
			    document.form1.emal.focus();
				return false;
				break;
    		}


		var r2;
		r2=document.form1.emal2.value;
		if(r2.length!=0)
		{

		   if (document.form1.emal2.value.indexOf('@',0)==-1 ||
	       document.form1.emal2.value.indexOf('@',0)== 0 ||
	       document.form1.emal2.value.indexOf('.',0)==-1 ||
   	       document.form1.emal2.value.indexOf('.',0)== 0)
		   {
				alert(errorMsg5);
//			    document.form1.emal.value="";
			    document.form1.emal2.focus();
				return false;
				break;
    		}
		}

		
		var grandt;		
		grandt = document.form1.grand_sum.value;
		if((grandt.length==0) || (grandt.charAt(0)==' ') || (grandt==0))
		{
			alert(errorMsg8);
			document.form1.inter_1_sn.value="";			
//			document.form1.inter_1_sn.focus();
			return false;
			break;
		}
		
		if(document.form1.terms.checked == false) {
		
				alert('You forgot to check the payment and cancellation conditions box'); 
				document.form1.terms.focus();
				return false;
		}

	} while(0)
}



// register.php page to send password by e-mail to user.

function fn()
{
do {

		var x;
		x=formato.nam.value;
		if((x.length==0) || (x.charAt(0)==' '))
		{
			alert("Enter your name please.");
			formato.nam.value="";			
			formato.nam.focus();
			return false;
			break;
		}


		var r;
		r=formato.emal.value;
		if((r.length==0) || (r.charAt(0)==' '))
		{
			alert("Your e-mail address please.");
			formato.emal.value=''; 
			formato.emal.focus(); 
			return false;
			break;
		}

		   if (formato.emal.value.indexOf('@',0)==-1 ||
	       formato.emal.value.indexOf('@',0)== 0 ||
	       formato.emal.value.indexOf('.',0)==-1 ||
   	       formato.emal.value.indexOf('.',0)== 0) 
		   {
			    alert("Invalid e-mail address.");
//			    formato.emal.value="";
			    formato.emal.focus();
				return false;
				break;
    		}
			
/*													in case of select validation
			if(formato.country.value==0)
		{
			alert("Please select your Country");
			formato.country.focus(); 
			return false;
			break;
		}
*/
		var b;
		b=formato.pho.value;
		if((b.length==0) || (b.charAt(0)==' '))
		{
			alert("Please put your phone number.");
			formato.pho.value="";
			formato.pho.focus(); 
			return false;
			break;
		}		
			b=parseInt(formato.pho.value);
			if(isNaN(b))
		{
			alert("numbers only, please.");
			formato.pho.value="";
			formato.pho.focus();
			return false;
			break;
		}

/*															fax number validation
			cc4=parseInt(formato.fax.value);
				if(formato.fax.value!=0 && isNaN(cc4))
				{
					alert("numbers only, please.");
					formato.fax.value="";
					formato.fax.focus();
					return false;
					break;
				}
*/

		var usn;
		ps=formato.usnam.value;
		if((ps.length==0) || (ps.charAt(0)==' '))
		{
			alert("Enter a username for you please.");
			formato.usnam.value=""; 
			formato.usnam.focus(); 
			return false;
			break;
		}

		var psw;
		psw=formato.pasw.value;
		if((psw.length==0) || (psw.charAt(0)==' '))
		{
			alert("Enter a password please.");
			formato.pasw.value=""; 
			formato.pasw.focus(); 
			return false;
			break;
		}


		var psw2;
		psw2=formato.pasw2.value;
		if((psw2.length==0) || (psw2.charAt(0)==' '))
		{
			alert("Verify your password please.");
			formato.pasw2.value=""; 
			formato.pasw2.focus(); 
			return false;
			break;
		}


		if(formato.pasw.value != formato.pasw2.value)
		{
			alert("Password is not the same.");
			formato.pasw2.value=""; 
			formato.pasw2.focus();
			return false;
			break;			
		}

	} while(0)
}

// feedback.php page


// login.php page to log User In.
function loginn()
{
do {

		var x;
		x=forma.usernam.value;
		if((x.length==0) || (x.charAt(0)==' '))
		{
			alert(errorMsg0);
			forma.usernam.value="";			
			forma.usernam.focus();
			return false;
			break;
		}

		var z;
		z=forma.passwrd.value;
		if((z.length==0) || (z.charAt(0)==' '))
		{
			alert(errorMsg1);
			forma.passwrd.value="";
			forma.passwrd.focus(); 	
			return false;
			break;
		}

	} while(0)
}

// login.php page to send password by e-mail to user.
function sndpsw() {
		
	do
	{
		f=paswordo.emailo.value;
		if((f.length==0) || (f.charAt(0)==' '))
		{
			alert("Enter your username or e-mail please");
			paswordo.emailo.value="";			
			paswordo.emailo.focus();
			return false;
			break;
		}

	} while(0)
}


// booking.php page validation
function bkng() 
{
	do
	{
		if(document.frmato.speci.value==0)
		{
			alert(errorMsg2);
			document.frmato.speci.focus(); 
			return false;
			break;
		}

		var x;
		x=frmato.date1.value;
		if((x.length==0) || (x.charAt(0)==' '))
		{
			alert(errorMsg3);
			return false;
			break;
		}

//		else {
//			location.href="booking.php?spec="+x;
//		}
	
	} while(0)
}


// admin.php

function fns() 
{
	do
	{

		var x;
		x=formatos.special.value;
		if((x.length==0) || (x.charAt(0)==' '))
		{
			alert(errorMsg3);
			formatos.special.value="";			
			formatos.special.focus();
			return false;
			break;
		}

		var s;
		s=formatos.specialar.value;
		if((s.length==0) || (s.charAt(0)==' '))
		{
			alert(errorMsg4);
			formatos.specialar.value="";			
			formatos.specialar.focus();
			return false;
			break;
		}
	
	} while(0)
}



function chang(x){

	location.href="booking.php?speci="+x;
}


//////////  CALCULATIONS IN ADMIN PAGE ///////////////////

function calc5(name1, name2, name3) {
	
		v1 = parseInt(document.all.item(name1).value);
	  	if (isNaN(v1)) v1 = 0;
		v2 = parseInt(document.all.item(name2).value);
	  	if (isNaN(v2)) v2 = 0;
				
		document.all.item(name3).value = v2 - v1;		
}


function test_cmb() {

		cont=0;
		for (var j = 0; j < document.form1.pre_luxor_frm.length; j++){
			if (document.form1.pre_luxor_frm[j].checked){
				cont++;
			}		
		}			

		cont2=0;
		for (var x = 0; x < document.form1.sn_dbl.length; x++){
			if (document.form1.sn_dbl[x].checked){
				cont2++;
			}		
		}			

			if(cont2==1 && cont==0){ 
				alert(errorMsg11); 
				document.form1.pre_luxor_frm.focus();
				return false;
			}
}


function noofnights() {
	
		v1 = parseInt(document.form1.checkin_dt.value);
	  	if (isNaN(v1)) v1 = 0;
		v2 = parseInt(document.form1.checkout_dt.value);
	  	if (isNaN(v2)) v2 = 0;
		v5 = parseInt(document.form1.nonights2.value);
	  	if (isNaN(v5)) v5 = 0;

		
		v3 = (v2 - v1);
		
		if (v3 != v5) {

			document.form1.inter_1_sn.disabled=true;
			document.form1.inter_1_db.disabled=true;
			document.form1.inter_1_sn.value=0;
			document.form1.inter_1_db.value=0;
			document.form1.inter_1_sum.value=0;

			document.form1.inter_2_sn.disabled=true;
			document.form1.inter_2_db.disabled=true;
			document.form1.inter_2_sn.value=0;
			document.form1.inter_2_db.value=0;
			document.form1.inter_2_sum.value=0;

			document.form1.sher_sn.disabled=true;
			document.form1.sher_db.disabled=true;
			document.form1.sher_sn.value=0;
			document.form1.sher_db.value=0;
			document.form1.sher_sum.value=0;
			
			acom();
		
		}
		if (v3 > 2 && v3 < 20) {

			document.form1.inter_1_sn.disabled=false;
			document.form1.inter_1_db.disabled=false;
			document.form1.inter_1_bk.disabled=false;
			document.form1.inter_2_sn.disabled=false;
			document.form1.inter_2_db.disabled=false;
			document.form1.inter_2_bk.disabled=false;
			document.form1.sher_sn.disabled=false;
			document.form1.sher_db.disabled=false;
			document.form1.sher_bk.disabled=false;
	
		}
		else {
			
			alert ('Minimum reservation is 3 nights\nPlease modify dates to enable reservation');

			document.form1.inter_1_sn.disabled=true;
			document.form1.inter_1_db.disabled=true;
			document.form1.inter_1_sn.value=0;
			document.form1.inter_1_db.value=0;
			document.form1.inter_1_bk.disabled=true;
			document.form1.inter_1_bk.value=0;			
			document.form1.inter_1_sum.value=0;

			document.form1.inter_2_sn.disabled=true;
			document.form1.inter_2_db.disabled=true;
			document.form1.inter_2_bk.disabled=true;
			document.form1.inter_2_sn.value=0;
			document.form1.inter_2_db.value=0;
			document.form1.inter_2_bk.value=0;			
			document.form1.inter_2_sum.value=0;

			document.form1.sher_sn.disabled=true;
			document.form1.sher_db.disabled=true;
			document.form1.sher_bk.disabled=true;
			document.form1.sher_sn.value=0;
			document.form1.sher_db.value=0;
			document.form1.sher_bk.value=0;
			document.form1.sher_sum.value=0;
			
			acom();
	
		}

		if (v3 > 0 && v3 < 20) {

			document.form1.nonights.value = v3;
			document.form1.nonights2.value = v3;
			document.form1.nonights3.value = v3;
		}
		else {
			document.form1.nonights.value = v3;
			document.form1.nonights2.value = v3;			
			document.form1.nonights3.value = 0;
		}
		
}

 function DisplayEditMenu2(name1, name2)
{
	if (document.getElementById(name1).style.display == "block"){
  	  	document.getElementById(name1).style.display = "none"; 
	}
	else {
		document.getElementById(name1).style.display = "block"; 
		document.getElementById(name2).style.display = "none";
	}
}

function fcheck() {
	do {
		if(document.form2.terms.checked == false) {
		
				alert('You forgot to check the payment and cancellation conditions box'); 
				return false;
		}

	} while(0)
}


function detailso(x,y){

		moni=window.open('details.php?id='+x+'','geo','width=550, height='+y+', status=0, scrollbars=1, left=120, top=30');
		moni.focus();

}
