function setCookie(name, value, expires, path, domain, secure)
{
  document.cookie =
    name+"="+escape(value)+
    (expires ? "; expires="+expires.toGMTString() : "")+
    (path    ? "; path="   +path   : "")+
    (domain  ? "; domain=" +domain : "")+
    (secure  ? "; secure" : "");
}
function setCookieLT(name, value, lifetime, path, domain, secure)
{
  if (lifetime) lifetime = new Date(Date.parse(new Date())+lifetime*1000);
  setCookie(name, value, lifetime, path, domain, secure);
}

// ***** getCookie *****

function getCookie(name)
{
  var cookie, offset, end;
  cookie  = " "+document.cookie;
  offset  = cookie.indexOf(" "+name+"=");
  if (offset == -1) return undefined;
  offset += name.length+2;
  end     = cookie.indexOf(";", offset)
  if (end    == -1) end = cookie.length;
  return unescape(cookie.substring(offset, end));
}

// ***** delCookie *****

// PARAMETERS:
//
// name         - cookie name
// path, domain - cookie path & domain (the same as those used to create cookie)

function delCookie(name, path, domain)
{
  if (getCookie(name))
    setCookie(name, "", new Date("January 01, 2000 00:00:01"), path, domain);
}




//Funcion de Envio de Formularios...
function enviar (formu){
	document.getElementById(formu).submit();		
}

function enviar_link (formu){
        var f = document.getElementById(formu);
        window.pageTracker._linkByPost(f);
        f.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
// JavaScript Document
var global_load_div = '';
var http_request = new Array;
var contador_j = 0;
   function makePOSTRequest(url, parameters) {
	  var etiquetadiv = global_load_div
	  contador_j = contador_j + 1
	  var valor_http = http_request[contador_j]
      valor_http = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         valor_http = new XMLHttpRequest();
         if (valor_http.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //valor_http.overrideMimeType('text/xml');
            valor_http.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            valor_http = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               valor_http = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!valor_http) {
         alert('Your browser does not support AJAX!');
         return false;
      }else{
	  }
      valor_http.onreadystatechange = function(){
		if (valor_http.readyState == 1) {
			document.getElementById(etiquetadiv).innerHTML= '<span align="center"><img src="http://www.getreadyrentals.com/images/loading.gif" align="absmiddle" width="16" height="16"/></span>';
		}		  
	  if (valor_http.readyState == 4) {
         if (valor_http.status == 200) {
            //alert(valor_http.responseText);
            result = valor_http.responseText;
			//document.getElementById('loading_coment').style.visibility="hidden";
			document.getElementById(etiquetadiv).innerHTML = result;
         } else {
            alert('No s\'ha carregat correctament el fitxer.');
         }
      }
	  };
      valor_http.open('POST', url, true);
      valor_http.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=ISO-8859-1");
      valor_http.setRequestHeader("Content-length", parameters.length);
      valor_http.setRequestHeader("Connection", "close");
      valor_http.send(parameters);
	  return valor_http.readyState
   }

//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){
	GEBI('price_total').value = parseFloat(GEBI('price_total').value)-GEBI('price_roomto_'+idrefente).value;		
	GEBI('price_total_net').value = parseFloat(GEBI('price_total_net').value)-GEBI('price_roomre_'+idrefente).value;
	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);
	}else{
		var otherinf = 0;		
	}	
	var roominf = parseFloat(GEBI('price_room_'+idrefente).value);
	var roominfdesc = parseFloat(GEBI('price_asign_'+idrefente).value);
	roominfdesc = roominfdesc * parseFloat(GEBI('price_unit_'+idrefente).value);
	var extrainf = parseFloat(GEBI('price_extra_'+idrefente).value);
	if(GEBI('price_unit_'+idrefente).value == 0){ 
		if(transfer != 0 || otherinf != 0 || extrainf != 0){
			GEBI('price_unit_'+idrefente).value = 1;
		}
	}

	
	var total_price_net = roominf * parseFloat(GEBI('price_unit_'+idrefente).value);
	total_price_net = total_price_net * parseFloat(GEBI('dias_diferencia').value);	
	var disc_long= parseFloat(GEBI('discount_long').value);
	if(disc_long>0){
		var tot_dis_long = (total_price_net * disc_long)/100;
		
	}else{
		var tot_dis_long =0;
	}

	total_price_net = total_price_net - tot_dis_long  + roominfdesc;
	GEBI('price_roomre_'+idrefente).value= total_price_net;

	var total_price = roominf+extrainf + otherinf ;
	
	var extras = extrainf * parseFloat(GEBI('price_unit_'+idrefente).value);
	extras = extras * parseFloat(GEBI('dias_diferencia').value);	
	
	var otros = otherinf * parseFloat(GEBI('price_unit_'+idrefente).value);
	otros = otros * parseFloat(GEBI('dias_diferencia').value);	
	total_price_net= total_price_net + otros;
	GEBI('price_adicio_'+idrefente).value = extras + transfer + otros; 	

	total_price = total_price * parseFloat(GEBI('price_unit_'+idrefente).value);
	total_price = total_price * parseFloat(GEBI('dias_diferencia').value);		
	total_price = total_price + transfer - tot_dis_long  + roominfdesc;
	GEBI('price_roomto_'+idrefente).value = total_price; 	

	GEBI('price_line_'+idrefente).innerHTML = total_price+'&nbsp;';

	GEBI('price_total').value = parseFloat(GEBI('price_total').value)+total_price;	
	GEBI('price_total_net').value = parseFloat(GEBI('price_total_net').value)+total_price_net;	
	GEBI('total_price').innerHTML = GEBI('price_total').value+'&nbsp;';
	GEBI('price_deposit').value = ((GEBI('price_total_net').value*parseFloat(GEBI('porcentajedes').value))/100);
	GEBI('price_arrival').value = GEBI('price_total').value - GEBI('price_deposit').value;	
	GEBI('total_price_deposit').innerHTML = GEBI('price_deposit').value+'&nbsp;';
	GEBI('total_price_arrival').innerHTML = GEBI('price_arrival').value+'&nbsp;';		
	if(parseFloat(GEBI('price_total').value) >= 1){
		GEBI('reserinf').style.display='';
	}else{
		GEBI('reserinf').style.display='none';		
	}
}

