var $CAPITAL 	= 	"CAPITAL FEDERAL";
	
function mainmenu(){
$(" #nav ul ").css({display: "none"}); // Opera Fix
$(" #nav li ").hover(function(){
		$(this).find('ul:first:hidden').css({visibility: "visible",display: "none"}).show(400);
		},function(){
		$(this).find('ul:first').css({visibility: "hidden"});
		});
}

$(document).ready(function(){
	mainmenu();
	
	$("li.filter_localidad").hide(100);
	$("li.filter_calle").hide(100);
	
	$(".list-novedades div.clearleft a").click(function(){
		$(this).parent().parent().find("div.newsText").slideToggle(100);
				
		if($(this).parent().parent("li").find("p.newsIntro").is(":hidden")){
			$(this).parent().parent("li").find("p.newsIntro").show();	
			$(this).html('Ampliar');
			$(this).removeClass('goTopSmall');
			$(this).addClass('goDownSmall');
		}else{
			$(this).parent().parent("li").find("p.newsIntro").hide();	
			$(this).html('Reducir');
			$(this).removeClass('goDownSmall');
			$(this).addClass('goTopSmall');
		}		
	});
	
	$("#provincia").change(function(){
		$("#localidad").val('');
		$("#cp_result").val('');
				
		if( jQuery.browser.msie == true && jQuery.browser.version == '6.0' ){
			$("#ocultarProvincia").hide(0);
		}
		console.log($("#provincia").val());		
		switch( $("#provincia").val() )
		{
			case $CAPITAL:
				$("li.filter_localidad").hide(100);
				$("li.filter_calle").show(100);
				break;
			case '':
			default:
				$("li.filter_calle").hide(100);
				$("li.filter_localidad").show(100);
				break;
		}
	});
		
	/* if (jQuery.browser.msie) {
        try { 
            document.execCommand("BackgroundImageCache", false, true); 
        } catch(err) {}
    }
*/
	
	$(".cotizador input:checkbox").click(function(){
		/*if( jQuery.browser.msie == true && jQuery.browser.version == '6.0' ){
			if( $("#"+ $(this).val()).is(":hidden") )
				$("#"+ $(this).val()).css("display","block");
			else
				$("#"+ $(this).val()).css("display","none");				
		}else{
			$("#"+ $(this).val()).slideToggle(400);
		}	*/
		$("#"+ $(this).val()).slideToggle(400);
	});
		
	$("#correspondencia_material").change(function(){
		if( $(this).val() == 'Otro' )
			$(".especificar").css("display","");
		else
			$(".especificar").css("display","none");
	});
		
	$("li.filter_localidad").hide(0);
	//$("#nameCalle").hide(0);
	//$("#alturaCalle").hide(0);

});

function searchLocalidad(suggestBoxId,url){
	$("#localidad").val($("#show_localidad").val());
	if($("#show_localidad").val().length == 0 ){
		$("#"+suggestBoxId).fadeOut();
	}else{
		$.post(
			url,
			{
				localidad: $("#show_localidad").val(),
				provincia: $("#provincia").val()
			}, 
			function(data){
				
				if(data !=''){
					$("#"+suggestBoxId).fadeIn();
				}else{
					$("#"+suggestBoxId).fadeOut();
				}
				$("#"+suggestBoxId).html(data);
			}
		);
	}
}

function searchCalle(suggestBoxId,url){
	$("#calle").val($("#show_calle").val());
	if(	$("#show_calle").val().length == 0 ){
		$("#"+suggestBoxId).fadeOut();
	}else{
		$.post(
			url,
			{
				calle: $("#show_calle").val() + ' ',
				provincia: $("#provincia").val()
			}, 
			function(data){
				
				if(data !=''){
					$("#"+suggestBoxId).fadeIn();
				}else{
					$("#"+suggestBoxId).fadeOut();
				}
				$("#"+suggestBoxId).html(data);
			}
		);
	}
}


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

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

function searchCP(){
	var $fields 	=   $("#frmCP").serializeArray();
	var $err		= 	"";
	
	if( $("#provincia").val() ){		
		if( $("#provincia").val() != $CAPITAL ){
			// 	SI ESTA SELECCIONADO CAPITAL, OBLIGATORIO LOCALIDAD
			if($("#localidad").val()=='' ){
				$err	+= 	"<br>- Localidad";

			}
		}else{
			// 	SI ESTA SELECCIONADO OTRO MENOS CAPITAL, OBLIGATORIO CALLE Y ALTURA
			if( !$("#calle").val() )
				$err	+= 	"<br>- Calle";
			if( !$("#altura").val() )
				$err	+= 	"<br>- Altura";				
		}
	}else{
		$err	+= 	"<br>- Provincia";	
	}	
	
	if( $err != "" ){
		$("#cp_result").fadeIn();
		$("#cp_result").html('<div class="darkRed" style="text-align:center">Los siguientes campos son obligatorios:' + $err + '</div>');
	}else{	
		$("#cp_result").fadeIn();
		$("#cp_result").html('<img src="/images/various/ajax-loader.gif" alt="Loading..." title="Loading..." align="center" border="1"/>');

		$.post(
			'getCP.asp',
			$fields, 
			function(data){
				$("#cp_result").fadeIn();
				$("#cp_result").html(data);
			}
		);
	}	
}

function checkIe(){
	if( jQuery.browser.msie == true && jQuery.browser.version == '6.0' ){
		document.location 	= 	'/codigosPostales.asp';
	}else{
		document.frmCP.reset();
		$('#cp_result').val('');
		$('#cp_result').fadeOut();
		$('#suggestLocalidad').fadeOut();
	}		
	$("li.filter_localidad").hide(100);
	$("li.filter_calle").hide(100);
}
function cleanLocalidad(){
	$('#show_localidad').val('');
	$('#calle').val('');
	$('#show_calle').val('');
	$('#altura').val('');
	$('#cp_altura').val('');
	$('#suggestLocalidad').fadeOut();
	$("#cp_result").fadeOut();
	$("#cp_result").html('');
}
function loadTextBox(Value,iChange){
	if(iChange==1){
		$('#show_localidad').val(Value);
		$('#localidad').val(Value);
		$('#suggestLocalidad').fadeOut();
	}else{
		$('#show_calle').val(Value);
		$('#calle').val(Value);
		$('#suggestCalle').fadeOut();
	}
}
