if(DATE_FORMAT =="") DATE_FORMAT = 'MMM dd,yyyy';
if(DATE_STANDAR_FORMAT =="") DATE_STANDAR_FORMAT = 'M/d/y';

var NEW_CHAR ="\"";
var TARGET_REXP = /_/gi;

var today_	= formatDate(new Date(), DATE_STANDAR_FORMAT);

function Hide(id){
	changeVisibility(false, id);
}
	
function Show(id){
	changeVisibility(true, id);
}

function f(id){
	var d = document.getElementById(id);
		
	d.style.display = (d.style.display == "none")?"":"none";
}

function f1(){
	var t1 = document.getElementById(".pkupeven");
	var t2 = document.getElementById(".pkupodd");
		
	t1.style.display = (t1.style.display == "none")?"block":"none";
	t2.style.display = (t1.style.display != "none")?"block":"none";
}

function f2(val){
	var d = val.split("|");
	
	if((d.length != null) || (d.length == 1)){
		changeVisibility((d[1] == 2), '.hm2')
	}
}

function showMyPrices(room, age, count){	
	var bindex	= document.getElementById(room + '_bindex');
	
	if(bindex != null && bindex.getAttribute('value') != ""){
		for(i=1; i <= count; i++)			
			changeVisibility(false, room + bindex.getAttribute('value') + '_' + i);		
	}
	
	bindex.setAttribute('value', age);

	for(i=1; i <= count; i++)
		changeVisibility(true, room + age + '_' + i);	
}

function srch_validate(f, result_page){	
	if((f['chk4p_'][1].checked) && (emptyField(f['.lp'].value) || emptyField(f['.up'].value) || isNaN(f['.lp'].value) || isNaN(f['.up'].value) || (eval(f['.lp'].value) >eval(f['.up'].value)))){
		alert(f['err_p'].value.replace(TARGET_REXP, NEW_CHAR));
				 
		return false;
	}
		
	if(result_page !=''){
		f.action = result_page;
		f.submit();
	}

	return true;
}

function openUrl(car, other_params){
	var txt="/formularios/car.asp?car="+car;
	
	if(other_params	!= '')
		txt	+= '&' + other_params;
		
	win=window.open(txt,'LinkWin',"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,height=415,width=460");
	win.focus();
}

function touch_dest(f, type_, id_, name_, lb_, sufix_){
	changeContent(sufix_ +'locn_', lb_, 'text'); 
	changeValue('.' +sufix_ +'ln_', name_); 
	changeValue('.' +sufix_ +'lno_','');

	if(f['..' +sufix_ +'id'] !=null){
		if(f['..' +sufix_ +'id'].value !='') changeVisibility(false, '.' +sufix_ +'_' +f['..' +sufix_ +'id'].value);
			
		f['..' +sufix_ +'id'].value =id_;
		changeVisibility(true, '.' +sufix_ +'_' +id_);			
	}
		
	f['.' +sufix_ +'t'].value =type_;	
}

function touch_total(f, val, sufix, sindex, rpiindex){
	var ss =eval(f['seasons' +sufix].value);
	var rpis =eval(f['rpis' +sufix].value);
	
	var ctrp =document.getElementById(sufix +'x' +sindex);
	ctrp.setAttribute('value', val);
	
	var total_		=0;	
	var exp_		=(f['price_exp']!=null)?f['price_exp'].value:PRICE_EXP;
	
	for(j=0; j<= ss; j++){
		var rp =document.getElementById(sufix +'x' +j);

		if(rp !=null)
			total_ += eval(rp.getAttribute('value'));
	}
	total_ =(Math.round(100*total_))/100;
		
	var numb_str =new String(total_).split('.');

	var total_str_	=total_;
	
	if(numb_str.length ==1)
		total_str_ =total_str_ +'.00'
	else if((numb_str.length ==2)&&(numb_str[1].length ==1))
		total_str_ =total_str_ +'0';
	
	total_str_ =exp_.replace("[x]", total_str_);
	
	var r_dates =eval(f['.rent_days_r_' +sufix].value);
	
	if(r_dates >1){
		var jour_p = (Math.round(100*(total_/r_dates)))/100;
	
		numb_str =new String(jour_p).split('.');	

		if(numb_str.length ==1)
			jour_p =jour_p +'.00'
		else if((numb_str.length ==2)&&(numb_str[1].length ==1))
			jour_p =jour_p +'0';	
	
		if(f['.jbookings_r_' +sufix] !=null) f['.jbookings_r_' +sufix].value = jour_p;

		total_str_ =total_str_ +'(' +f['.jbookings_str_r_' +sufix].value.replace("[x]", exp_.replace("[x]", jour_p)) +')';
	}
	
	if(f['t_' +sufix] !=null) f['t_' +sufix].value = total_;
	
	changeContent(sufix +'_total', total_str_, 'text');	
 }
 
 function touch_cc(f, items_n, val_, pick_){
	var cur_cc	= (val_ >0)?val_:getFval(f, '.cc', 's');

	f['.cc'].options.length = 1;
		
	if(f[items_n] !=null){
		if(f[items_n].length == null){
			var parts = f[items_n].value.split(";");			

			f['.cc'].options[f['.cc'].length] = new Option(parts[1], parts[0]);
		}else
			for(j=0; j<f[items_n].length; j++){
				var parts = f[items_n][j].value.split(';');
				var picks_= f['.cc_picks' +parts[0]].value;
				
				if((pick_ =='[]') || (picks_.indexOf(pick_) != -1))
					f['.cc'].options[f['.cc'].length] = new Option(parts[1], parts[0]);
			}
		
		sel_select(f['.cc'], cur_cc);
		touch_cc_peoples(f, cur_cc);
	}
 }
  
 function touch_cc_peoples(f, id_){
	var cap_	= (f['.cc'].selectedIndex >0)?eval(f['.mxc_' +id_].value):10;
	var hm_		= (f['.hm'].selectedIndex >0)?f['.hm'].options[f['.hm'].selectedIndex].value:0;
	
	f['.hm'].options.length =1;
	for(i=1; i<= cap_; i++){
		j = 2 *i;

		f['.hm'].options[j -1]	= new Option(i, i);	
		f['.hm'].options[j]		= new Option(i +'+', i +'_');	
	}

	sel_select(f['.hm'], hm_)
 }
 
 function touch_price_pos(f, sufix, ppos){
	if(f['pcoords_' +sufix] !=null){
		ccoords =f['pcoords_' +sufix].value;
		cparts  = ppos.split('.');	
	
		parts = ccoords.split(';');
		if((ccoords.lastIndexOf(cparts[0] +'.') !=-1) && (parts.length !=null)){	
			ccoords ='';
			
			for(j=0; j<parts.length; j++)
				if(parts[j].lastIndexOf(cparts[0] +'.') ==-1){
					if(ccoords !='') ccoords +=';';
	
					ccoords +=parts[j];
				}
		}	
		
		if(ccoords !='') ccoords +=';';	
		ccoords +=ppos;
	
		f['pcoords_' +sufix].value =ccoords;

		/*
		alert('ccoords=' +ccoords);
		alert('ppos=' +ppos);
		*/
	}
 }
 
 function canRESERVE(f){
	var onehour		= 1000 * 60 * 60;
	var oneday		= onehour * 24;

	if(emptyField(f['name'].value)){
        alert(f['err_name'].value.replace(TARGET_REXP, NEW_CHAR));
         
        return false;
	}	
	
	if((f['email'] !=null) && emptyField(f['email'].value)){
        alert(f['err_email'].value.replace(TARGET_REXP, NEW_CHAR));
         
        return false;
	}
		
	if(emptyField(f['.pcku'].value)){
        alert(f['err_.pcku'].value.replace(TARGET_REXP, NEW_CHAR));
         
        return false;
	}

	if(isNaN(Date.parse(f['.pcku_standar'].value)) || (Math.floor(Date.parse(f['.pcku_standar'].value)/oneday) <Math.floor(Date.parse(today_)/oneday))){
		alert(f['err_.pckuv'].value.replace(TARGET_REXP, NEW_CHAR));
					
		return false;
	}

	if(emptyField(f['.doff'].value)){
        alert(f['err_.doff'].value.replace(TARGET_REXP, NEW_CHAR));
         
        return false;
	};
	
	if(isNaN(Date.parse(f['.doff_standar'].value)) || ((Math.floor(Date.parse(f['.doff_standar'].value)/oneday) <Math.floor(Date.parse(today_)/oneday)) || (Math.floor(Date.parse(f['.doff_standar'].value)/oneday) <Math.floor(Date.parse(f['.pcku_standar'].value)/oneday)))){
		alert(f['err_.doffv'].value.replace(TARGET_REXP, NEW_CHAR));
					
		return false;
	}

	if((getFval(f, 'pickupLst', 's') == '-1.0') || (getFval(f, 'dropoffLst', 's') == '-1.0')){
        alert(f['err_.locs'].value.replace(TARGET_REXP, NEW_CHAR));
    		 
        return false;
	}
			
	return true;
 }

 function get_rates_validate(f, url){
	if(canRESERVE(f)){
		if(f['.a'] != null)
			f['.a'].value = "/s";
			
	    goTo(f, url);
	}
			 
	return false;
 }
		
 function mustGetRATEs(f){
	var grn_ = false;
	
	var pcku_ =formatDate(new Date(f['.pcku_standar'].value), DATE_FORMAT);
	var doff_ =formatDate(new Date(f['.doff_standar'].value), DATE_FORMAT);
	
	var grn_pcku_ =formatDate(new Date(f['.grn.pcku'].value), DATE_FORMAT);
	var grn_doff_ =formatDate(new Date(f['.grn.doff'].value), DATE_FORMAT);
	
	var pckul_ = getFval(f, 'pickupLst', 's');
	var doffl_ = getFval(f, 'dropoffLst', 's');	

	var grn_pckul_ = f['.grn.pckul'].value;
	var grn_doffl_ = f['.grn.doffl'].value;	

	var tt_ = getFval(f, '.ctt', 'r');
	var grn_tt_ = (f['.grn.ctt'] !=null) ? f['.grn.ctt'].value: null;
	
	var wthdrv_ = getFval(f, '.wthdrv', 'r');
	var grn_wthdrv_ = (f['.grn.wthdrv'] !=null) ? f['.grn.wthdrv'].value: null;

	grn_ = ((pcku_!=grn_pcku_) || (doff_!=grn_doff_) || (f['.grn.rp'].value!=getFval(f, '.crp', 'r')) || (tt_!=grn_tt_) || (wthdrv_!=grn_wthdrv_) || (pckul_ != grn_pckul_) || (doffl_ != grn_doffl_));

	return grn_;
 }

 function shopping_validate(f, url){
	f.target	= '_self';
	
	if(canRESERVE(f))
		if(!mustGetRATEs(f))
			goTo(f, url)
		else
			alert(f['err_.grn'].value.replace(TARGET_REXP, NEW_CHAR));
	
	return false;
 }

 function fast_reservation_validate(f, url){
	f.target	= '_self';
	
	if(canRESERVE(f))
		if(!mustGetRATEs(f))
			goTo(f, url)
		else
			alert(f['err_.grn'].value.replace(TARGET_REXP, NEW_CHAR));
			
	return false;
 }

 function bookNOW_validate(f, url){
	if(canRESERVE(f))
		if(!mustGetRATEs(f)){
			f.target	= '_blank';
			f.action	= url;
			
			f.submit();
			
			return true;		
		}else
			alert(f['err_.book.grn'].value.replace(TARGET_REXP, NEW_CHAR));
	
	return false;		
 } 

function get_rent_period_days(f){
	var onehour		= 1000 * 60 * 60;
	var oneday		= onehour * 24;
	
    return 	(Math.floor(Date.parse(f['.doff_standar'].value)/oneday) - Math.floor(Date.parse(f['.pcku_standar'].value)/oneday));
}

function touch_plans(f){
    var rent_days_ = get_rent_period_days(f);

    var plans_ =  f['.crp'];
    var selected_plan_ = null;
    for(var i=0; i <plans_.length; i++){
        var period_ = f['rpp_' +plans_[i].value].value.split('.');
        
        period_[0] = eval(period_[0]);
        period_[1] = eval(period_[1]);
        
        changeEnable(!((period_[0] >0) && (period_[0] <=rent_days_) && ((period_[1] ==-1) || (rent_days_ <=period_[1]))), '.crp_' +plans_[i].value);
        
        selected_plan_ = (!plans_[i].disabled && (plans_[i].checked || (selected_plan_ ==null)))?plans_[i]:selected_plan_;
    }
        
    if(selected_plan_ != null) selected_plan_.checked = true;
}

function validate_travelinfo(f){
	var onehour		= 1000 * 60 * 60;
	var oneday		= onehour * 24;
	
	var must_submit = (!emptyField(f['.doff'].value) && !emptyField(f['.pcku'].value));
	
	if(!emptyField(f['.pcku'].value) || !emptyField(f['.doff'].value)){
		var chi_ = today_;
		var cho_ = today_;
			
		if(!emptyField(f['.pcku'].value)){
			if((isNaN(Date.parse(f['.pcku_standar'].value))) || (Math.floor(Date.parse(f['.pcku_standar'].value)/oneday) <Math.floor(Date.parse(today_)/oneday))){
				alert(f['err_.pcku'].value.replace(TARGET_REXP, NEW_CHAR));
					
				return false;
			}

			if(emptyField(f['.doff'].value)){
				f['.doff'].value = formatDate(new Date(Date.parse(f['.pcku_standar'].value) +oneday), DATE_FORMAT);
				f['.doff_standar'].value = formatDate(new Date(Date.parse(f['.pcku_standar'].value) +oneday), DATE_STANDAR_FORMAT);
			}
		}
		
		if(!emptyField(f['.doff'].value)){
			if(emptyField(f['.pcku'].value)){
				f['.pcku'].value = formatDate(today_, DATE_FORMAT);
				f['.pcku_standar'].value = formatDate(today_, DATE_STANDAR_FORMAT);
			}
			
			if((isNaN(Date.parse(f['.doff_standar'].value))) || ((Math.floor(Date.parse(f['.doff_standar'].value)/oneday) <Math.floor(Date.parse(today_)/oneday)) || (Math.floor(Date.parse(f['.doff_standar'].value)/oneday) <Math.floor(Date.parse(f['.pcku_standar'].value)/oneday)))){
				alert(f['err_.doff'].value.replace(TARGET_REXP, NEW_CHAR));
					
				return false;
			}
		}
	}else{
		alert(f['err_.pcku'].value.replace(TARGET_REXP, NEW_CHAR));
		
		return false;
	 }
		
	return must_submit;
}

//================================//

function ifr_touch_caption(f, sufix_, val){
	var parts_ = val.replace('ta_', '').replace('pu_','').split('.');
	var lb_ = (val.lastIndexOf('ta_') ==-1)?f[sufix_ +'_pu_caption'].value.replace('[x]', '<B>' +parts_[2] +'</B>'):f[sufix_ +'_ta_caption'].value.replace('[x]', '<B>' +parts_[1] +'</B>');

	changeContent(sufix_ +'_caption', lb_, 'html'); 
}

function ifr_srch_validate(f){	
	if(f['.lpcku'].selectedIndex ==0){
	 alert(f['err_pku_pattern'].value.replace(TARGET_REXP, NEW_CHAR));
			 
	 return false;
	}else if(f['.ldoff'].selectedIndex ==0){
	 alert(f['err_doff_pattern'].value.replace(TARGET_REXP, NEW_CHAR));
			 
	 return false;
	}
	
	var must_submit = true;
	
	if(!emptyField(f['.pcku'].value) || !emptyField(f['.doff'].value)){
		var onehour		= 1000 * 60 * 60;
		var oneday		= onehour * 24;
			
		var chi_ = today_;
		var cho_ = today_;

		if(!emptyField(f['.pcku'].value)){
			if((isNaN(Date.parse(f['.pcku_standar'].value))) || (Math.floor(Date.parse(f['.pcku_standar'].value)/oneday) <Math.floor(Date.parse(today_)/oneday))){
				alert(f['err_.pcku'].value.replace(TARGET_REXP, NEW_CHAR));
						
				return false;
			}

			if(emptyField(f['.doff'].value)){
				f['.doff'].value = formatDate(new Date(Date.parse(f['.pcku_standar'].value) +oneday), DATE_FORMAT);
				f['.doff_standar'].value = formatDate(new Date(Date.parse(f['.pcku_standar'].value) +oneday), DATE_STANDAR_FORMAT);
				
				must_submit = false;
			}
		}
			
		if(!emptyField(f['.doff'].value)){
			if(emptyField(f['.pcku'].value)){
				f['.pcku'].value = formatDate(today_, DATE_FORMAT);
				f['.pcku_standar'].value = formatDate(today_, DATE_STANDAR_FORMAT);
				
				must_submit = false;
			}
				
			if((isNaN(Date.parse(f['.doff_standar'].value))) || ((Math.floor(Date.parse(f['.doff_standar'].value)/oneday) <Math.floor(Date.parse(today_)/oneday)) || (Math.floor(Date.parse(f['.doff_standar'].value)/oneday) <Math.floor(Date.parse(f['.pcku_standar'].value)/oneday)))){
				alert(f['err_.doff'].value.replace(TARGET_REXP, NEW_CHAR));
						
				return false;
			}
		}
	}
	
	f.submit();
			
	return must_submit;
}
function allInONE(f, grdf_arg0, grdf_arg1, grdf_arg2, grdf_arg3, tdst_arg0, tdst_arg1, tdst_arg2, tdst_arg3, tdst_arg4, tcc_arg0, tcc_arg1, tcc_arg2){
    touch_dest(f, tdst_arg0, tdst_arg1, tdst_arg2, tdst_arg3, tdst_arg4); 
    getRdFocus(f, grdf_arg0, grdf_arg1); 
    getRdFocus(f, grdf_arg2, grdf_arg3);     
    touch_cc  (f, tcc_arg0, tcc_arg1, tcc_arg2);
}
function allInONE2(f, grdf_arg0, grdf_arg1, tdst_arg0, tdst_arg1, tdst_arg2, tdst_arg3, tdst_arg4, tcc_arg0, tcc_arg1, tcc_arg2){
    getRdFocus(f, grdf_arg0, grdf_arg1); 
    touch_dest(f, tdst_arg0, tdst_arg1, tdst_arg2, tdst_arg3, tdst_arg4); 
    touch_cc  (f, tcc_arg0, tcc_arg1, tcc_arg2);
}
