function verificar_input(obj,ifnot){ //Función para verificar que un campo 'input' tiene contenido válido
  if(obj.value.length<1){
    obj.value = ifnot;
  }
}

function money(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + num + '.' + cents);
}
function numero_formateo(obj,decimal){
	var decimal = parseInt(decimal);
	var num = parseFloat(obj.value);
	if(isNaN(num) || num<0){
		num = 0.00;
	}
	if(decimal == 0){
		num = parseInt(num);
	} else {
		num = num.toFixed(decimal);
	}
	obj.value = num;
}

function submitenter(myfield,e){
	var keycode;
	if(window.event){
		keycode = window.event.keyCode;
	}else if(e){
		keycode = e.which;
	}else{
		return true;
	}
	if(keycode == 13){
		myfield.form.submit();
		return false;
	}else{
		 return true;
	 }
}

function loggin_enter(myfield,e,form){
	var keycode;
	if(window.event){
		keycode = window.event.keyCode;
	}else if(e){
		keycode = e.which;
	}else{
		return true;
	}
	if(keycode == 13){
	 loggin("acceso");
	 return false;
	}else{
		 return true;
	 }
}

function dominio_focus(obj){
	if(obj.value=="Escriba su dominio"){
		obj.value="";
	} else {
		obj.select();
	}
}

function dominio_blur(obj){
	if(obj.value.length==0){
		obj.value="Escriba su dominio";
	}
}

function procesar(url){
	var result = $.ajax({
		url: url,
		async: false
	}).responseText;
	
	return result;
}

function loggin(form){
	var email = $("#"+form+"_email").val();
	var pass = $("#"+form+"_pass").val();
	url = "?loggin&email="+email+"&pass="+pass;
	r = procesar(url);
	if(r == "no"){
		alert("Su correo electrónico o contraseña no son correctos.\nIntente nuevamente.");
		return false;
	}
	if(r == "si"){
		window.location = window.location;
	}
}

function sumar_modulos()
{
	var total = 0;
	$(".modulo_checkbox:checked").each(function(){
		total += parseFloat($(this).val());
	});
	$("#armador_total > span").html("$ "+money(total));
}

$(document).ready(function(){
	$(".modulo").click(function(){
		var id = $(this).attr("id").replace("modulo_cuadrado","");
		if($("#checkbox"+id).attr("checked"))
		{
			$("#checkbox"+id).attr("checked",false)
			$(this).find(".modulo_detalle").removeClass("modulo_selected");
		}
		else
		{
			$("#checkbox"+id).attr("checked",true);
			$(this).find(".modulo_detalle").addClass("modulo_selected");
		}
		sumar_modulos();
	});
	
	hs.graphicsDir = 'scripts/highslide/graphics/';
	hs.align = 'center';
	hs.transitions = ['expand', 'crossfade'];
	hs.showCredits = 0;
	hs.dimmingOpacity = .8;
	hs.outlineType = 'glossy-dark';
	hs.fadeInOut = true;
	hs.dimmingGeckoFix = true;
	hs.Expander.prototype.onAfterExpand = function(){document.body.style.overflow='hidden';}
	hs.Expander.prototype.onBeforeClose = function(){document.body.style.overflow='auto'; window.scrollBy(0,1); window.scrollBy(0,-1);}
	
	//$("#banner_principal").flash({swf: "banercarg.swf",width:1020, height: 186});
	
	var flashvars = {};
	flashvars.xml = "banner/config.php";
	flashvars.font = "banner/font.swf";
	var params = {};
	params.wmode = "transparent";
	params.id = "slider";
	
	$("#banner_principal").flash({swf: "banner/cu3er.swf",width:1000, height: 186, flashvars: flashvars, params: params});
	//$("#promo1").flash({swf: "swf/baner1.swf",width:328, height: 100});
	//$("#promo2").flash({swf: "swf/baner2.swf",width:328, height: 100});
	//$("#promo3").flash({swf: "swf/baner3.swf",width:328, height: 100});
	$("#flash_intro").flash({swf: "contenido/bienvenida.swf",width:550, height: 400});
	
	var margin = parseFloat($("#promo_limite").css("margin-top").replace("px",""));
	$("#promo_jala, #log_inicie_sesion").click(function(){
		if(parseFloat($("#promo_limite").css("margin-top").replace("px","")) < 0)
		{
			$("#promo_limite").animate({
				marginTop: 0
			}, 1000, function() {
			// Animation complete.
			});
		}
		else
		{
			$("#promo_limite").animate({
				marginTop: margin
			}, 1000, function() {
			// Animation complete.
			});
		}
	});	
	//swfobject.embedSWF("banercarg.swf", "banner_principal", "1020", "183", "9", "scripts/expressInstall.swf", flashvars, attributes);	
});