function pesquisar(){
	if (document.form_pesquisa.tipo_pesquisa[1].checked==true){
		document.location.href='/cgi-bin/brightserver/index.pl?SVC=4%2F2%2F7&MOD=1&CATID=1105&SEARCH_KEY='+escape(document.form_pesquisa.q.value);
	} else {
		var l= window.open('http://www.google.pt/custom?q='+escape(document.form_pesquisa.q.value)+'&cof=T%3A%23000000%3BLW%3A800%3BALC%3A%23005D90%3BL%3Ahttp%3A%2F%2Fwww.cabovisao.pt%2Fsite2010%2Fimages%2Fcabecalho.gif%3BLC%3A%23005D90%3BLH%3A78%3BBGC%3A%23ffffff%3BAH%3Acenter%3BVLC%3A%23005D90%3BGL%3A0%3BS%3Ahttp%3A%2F%2Fportal.cabovisao.pt%3BAWFID%3Afaec4b8f115a76e5%3B','pesquisa');
	}
	return false;
}

function pesquisa_cobertura() {
	var erro_cp1 = 'CÓDIGO POSTAL INVÁLIDO!\n\nA primeira parte do Código-Postal é constituda por 4 dígitos numéricos.';
	var erro_cp2 = 'CÓDIGO POSTAL INVÁLIDO!\n\nA segunda parte do Código-Postal é constituda por 3 dígitos numéricos.';
	
	var f = document.form_pesquisa_cobertura;
	var cp1 = parseInt(f.cod_postal_1.value, 10);
	var cp2 = parseInt(f.cod_postal_2.value, 10);
	
	if(isNaN(cp1)) {
		alert(erro_cp1) ;
		f.cod_postal_1.focus(); 
		return false; 
	}
	if(isNaN(cp2)) {
		alert(erro_cp2) ;
		f.cod_postal_2.focus(); 
		return false; 
	}

	f.cod_postal_1.value = ""+cp1;
	f.cod_postal_2.value = ""+cp2;
	if(cp2 < 10) {
		f.cod_postal_2.value = '00' + cp2;
	}
	else if(cp2 < 100) {
		f.cod_postal_2.value = '0' + cp2;
	}
	if(f.cod_postal_1.value.length!=4)	{
		alert(erro_cp1) ;
		f.cod_postal_1.focus(); 
		return false; 
	}
	if(f.cod_postal_2.value.length!=3)	{
		alert(erro_cp2) ;
		f.cod_postal_2.focus(); 
		return false; 
	}
	var a = window.open('/site2010/popup_verificacao_cobertura.php?cod_postal_1='+f.cod_postal_1.value+'&cod_postal_2='+f.cod_postal_2.value+'&action=pesquisar', 'popup_cobertura', 'width=670, height=450');
	return false;
}


function Set_Cookie( name, value ) {
	document.cookie = name+'='+value+';path=/';
}
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

