function urldecode(str)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = str;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while

   return plaintext;
}

function contacto(str){
  document.write('<form action="index.php?page=contacto.php" name="contacto" id="frmcontacto" method="POST">');
  document.write('<input type="hidden" name="obs" value="'+str+'">');
  document.write('</form>');

  var x=document.getElementById("frmcontacto");
 
  window.onload=x.submit();
}

function comprar(str,total){
  document.write('<form action="https://www.paypal.com/cgi-bin/webscr" name="compra" method="post">');
  document.write('<input type="hidden" name="cmd" value="_xclick">');
  document.write('<input type="hidden" name="business" value="geral@graudeconsenso.com">');
  document.write('<input type="hidden" name="item_name" value="'+urldecode(str)+'">');
  document.write('<input type="hidden" name="amount" value="'+total+'">');  
  document.write('<input type="hidden" name="no_shipping" value="0">');
  document.write('<input type="hidden" name="return" value="http://www.softwarehotelaria.com/index.php?page=obrigado.php">');
  document.write('<input type="hidden" name="cancel_return" value="http://www.softwarehotelaria.com/index.php">');
  document.write('<input type="hidden" name="currency_code" value="EUR">');
  document.write('<input type="hidden" name="lc" value="PT">');
  document.write('<input type="hidden" name="bn" value="PP-BuyNowBF">');
  document.write('</form>');

  window.onload=document.forms.compra.submit();
}

function cotacao(intFlag,intTotal){
 var x=document.getElementById("cotaca");
 var y=document.getElementById("total");

 x.value=intFlag;
 y.value=intTotal;

 document.forms.precario.submit();
}
