//Funcion de Envio de Formularios...
function enviar (formu){
	document.getElementById(formu).submit();		
}

//Ubica campo al cargar la pagina..
function ubicar(campo){
	document.getElementById(campo).focus();						
}

//regresa el id del campo a asignar..
function GEBI(id){
		return document.getElementById(id);
	}

//AJAX para carga de procesos
var http_request = false;
var global_load_div = '';
function makePOSTRequest(url, parametros){
	http_request = false;  
	try { // Firefox, Opera 8.0+, Safari
	http_request =new XMLHttpRequest();
		if (http_request.overrideMimeType) {
		http_request.overrideMimeType('text/html');
		}
  	}
	catch (e){
		try {	// IE
		http_request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
		http_request = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
   
	if (!http_request) {
	alert('Your browser does not support AJAX!');
	return false;
	}
	
	http_request.onreadystatechange = alertContents;
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", parametros.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(parametros);
}
//<------ END AJAX BASIC FUNCTION ------>
	  
function alertContents() {
	if (http_request.readyState == 1) {
	GEBI(global_load_div).innerHTML = '<div align="center"><img src="'+urlimg+'images/loading.gif" align="absmiddle" width="16" height="16"/></div>';
	}

	if (http_request.readyState == 4) {
    	if (http_request.status == 200) {
        result = http_request.responseText;
		GEBI(global_load_div).innerHTML = result;		
		}
		else {
		alert('Your Internet connection is null or an abuse made in the system. \n Please try again');
		}
	}
}

//Validador de campos numericos
function numberValidate(e) {
	tecla = (document.all) ? e.keyCode : e.which;
	if (tecla==8 || tecla==0) return true; //Tecla de retroceso (para poder borrar)
		patron =/[0-9]/;
		te = String.fromCharCode(tecla);
		return patron.test(te);
};

function inf_ver(id,ty){
	alert(ty);
	if(ty == 'YES'){ 
		GEBI(id).style.display='';
	}else{
		GEBI(id).style.display='none';		
	}
}

//FUNCION EVALUDORA DE PRECIOS HOTELES
function evalua_price(idrefente){	
	if(GEBI('price_trans_'+idrefente).checked == true){
		var transfer = parseFloat(GEBI('price_trans_'+idrefente).value);
	}else{
		var transfer = 0;		
	}
	if(GEBI('price_other_'+idrefente).checked == true){
		var otherinf = parseFloat(GEBI('price_other_'+idrefente).value)*parseFloat(GEBI('dias_diferencia').value);
		otherinf = otherinf * parseFloat(GEBI('price_unit_'+idrefente).value);
	}else{
		var otherinf = 0;		
	}	
	var roominf = parseFloat(GEBI('price_room_'+idrefente).value);
	var extrainf = parseFloat(GEBI('price_extra_'+idrefente).value)*parseFloat(GEBI('dias_diferencia').value);
	extrainf = extrainf * parseFloat(GEBI('price_unit_'+idrefente).value); 
	if(GEBI('price_unit_'+idrefente).value == 0){ 
		if(transfer != 0 || otherinf != 0 || extrainf != 0){
			GEBI('price_unit_'+idrefente).value = 1;
		}
	}
	GEBI('price_adicio_'+idrefente).value = extrainf + otherinf + transfer;
	GEBI('price_total').value = parseFloat(GEBI('price_total').value)-parseFloat(GEBI('price_roomto_'+idrefente).value);
  GEBI('price_re_grr').value = parseFloat(GEBI('price_re_grr').value)-parseFloat(GEBI('price_roomre_'+idrefente).value);
  GEBI('price_re_user').value = parseFloat(GEBI('price_re_user').value)-parseFloat(GEBI('price_roomto_'+idrefente).value);  	
	var total_price = roominf;
	total_price = total_price * parseFloat(GEBI('price_unit_'+idrefente).value);	
	total_price = total_price * parseFloat(GEBI('dias_diferencia').value);
  GEBI('price_roomre_'+idrefente).value = total_price;
  GEBI('price_roomto_'+idrefente).value = total_price + parseFloat(GEBI('price_adicio_'+idrefente).value);	
	GEBI('price_line_'+idrefente).innerHTML = GEBI('price_roomto_'+idrefente).value+'&nbsp;&euro;';	
	GEBI('price_total').value = parseFloat(GEBI('price_total').value)+parseFloat(GEBI('price_roomto_'+idrefente).value);
 	GEBI('price_re_grr').value = parseFloat(GEBI('price_re_grr').value) + parseFloat(GEBI('price_roomre_'+idrefente).value);
  GEBI('price_re_user').value = parseFloat(GEBI('price_re_user').value) + parseFloat(GEBI('price_roomto_'+idrefente).value); 	
 	GEBI('price_roomto_'+idrefente).value = total_price + extrainf + otherinf + transfer;
  GEBI('price_deposit').value = ((GEBI('price_re_grr').value*parseFloat(GEBI('porcentajedes').value))/100);  
  GEBI('price_arrival').value = (GEBI('price_total').value - GEBI('price_deposit').value);  	
	GEBI('total_price_arrival').innerHTML = GEBI('price_arrival').value+'&nbsp;&euro;';	  
  GEBI('total_price_deposit').innerHTML = GEBI('price_deposit').value+'&nbsp;&euro;';  	
	GEBI('total_price').innerHTML = GEBI('price_total').value+'&nbsp;&euro;';	
	if(parseFloat(GEBI('price_deposit').value) >= 1){
		GEBI('reserinf').style.display='';
	}else{
		GEBI('reserinf').style.display='none';		
	}
}