jQuery.noConflict();

jQuery(document).ready(function() {
	
	if(jQuery('.clickable').length != 0 || jQuery('.clickable_external').length != 0){
		makeClick();
	}
	var currentPanel = 1;
	var navClicks = 0;
	var panelWidth = 960;
	var panelHeight = 366;
	var panelCount = jQuery(this).find(".panel").size();
						   
	jQuery('.clean_inp').each(function() {
		if (jQuery(this).val() == jQuery(this).attr('defaultValue')) {
			jQuery(this).css('color','#AAA');
		}
	});
	jQuery('.clean_inp').focus(function(){
		if (jQuery(this).val() == jQuery(this).attr('defaultValue')) {
			jQuery(this).val("");
			jQuery(this).css('color','#555');
		}
	});
	jQuery('.clean_inp').blur(function(){
		if (jQuery(this).val() == "") {
			jQuery(this).val(jQuery(this).attr('defaultValue'));
			jQuery(this).css('color','#AAA');
		}
	});
	if (jQuery("#error").length > 0) {
		jQuery("#error").each(function() {
			jQuery(this).css({'display':'none'});
		});
	}
	jQuery('.error').each(function() {
		jQuery(this).removeClass('error');
	});
	if (panelCount > 0) {
		h = jQuery("#panel_"+currentPanel).height();
		jQuery("#banner").height(h);
		jQuery(".panel-container").height(h);
		jQuery(".panel-container").width(panelWidth*panelCount);	
	}
	var aux;
	jQuery("#slider-menu").find("#load_1").addClass('selected');
	jQuery("#slider-menu a").bind("click",function() {
		aux = jQuery(this).attr("id");
		aux = aux.split('_')[1];		
		jQuery(".panel-container").find(".panel").hide();
		jQuery(".panel-container").find("#panel_"+aux).show();
		jQuery("#slider-menu").find("a").removeClass('selected');
		jQuery("#slider-menu").find("#load_"+aux).addClass('selected');
	});
	jQuery("#show-contact").bind("click",function() {
		auxIE = jQuery(this).attr("class");
		jQuery(".contact").css({"margin-top":"0px"});
		if (auxIE.indexOf('selected')!=-1) {
			//jQuery("#selected-contact").fadeOut("slow");
			jQuery(".contact").css({"margin-top":"5px"});
			jQuery("#info-contact").fadeOut("slow");
			jQuery(this).parent().removeClass('activo');
			jQuery(this).parent().parent().css("margin-top","-5px");
			jQuery(this).removeClass('selected');
			cargarVacio();
		} else {
			jQuery("#selected-contact").fadeIn("slow");
			jQuery("#info-contact").fadeIn("slow");
			jQuery(this).addClass('selected');
			jQuery(this).parent().addClass('activo');
			jQuery(this).parent().parent().css("margin-top","-5px");
			cargarContenidoContacto();
		}		
	});
	if (jQuery("aside .menu ul").length > 0) {
		jQuery("aside .menu ul").each(function() {
			jQuery(this).css({'display':'none'});
		});
	}
	jQuery("aside .menu a").bind("click",function() {
		aux = jQuery(this).attr("id");
		aux = aux.split('_')[1];

		if (jQuery(this).parent().children('ul').css('display') == 'none')
			jQuery(this).parent().children('ul').show('slow');
		else if (jQuery(this).parent().children('ul').css('display') == 'block')
			jQuery(this).parent().children('ul').hide('slow');
	});
	if (jQuery(".logo").length > 0) {
		jQuery(".logo").bind("click",function() {
			jQuery(this).find("span").css({"color":"transparent"});
		});
		jQuery(".logo").bind("mouseover",function() {
			jQuery(this).find("span").css({"display":"","color":"#fff"});
		});
		jQuery(".logo").bind("mouseout",function() {
			jQuery(this).find("span").hide();
		});
	}	
	if(jQuery('div#formu-cloud').length != 0){
		jQuery('div#formu-cloud').hide();
		jQuery('a.boton-blanco').click(function(){
			jQuery('div#formu-cloud').slideToggle('fast')
			.siblings('div#formu-cloud:visible').slideUp('fast');
		});
		jQuery('a.boton').click(function(){
			jQuery('html, body').animate({scrollTop:1100},'slow');
			jQuery('div#formu-cloud').slideToggle('fast')
			.siblings('div#formu-cloud:visible').slideUp('fast');
		});
	}	
	/* boton servidores dedicados */
	if(jQuery('form#config-form').length != 0){
		jQuery('a.boton').click(function(){
			jQuery('html, body').animate({scrollTop:750},'slow');
		});
	}
});
function doBannerClick(_href){
	document.location = _href;
}
function doBannerClick_external(_href){
	window.open(_href);
}
function makeClick(){
  	if (document.getElementsByClassName) {
		var elems = document.getElementsByClassName("clickable");
		for (var i=0; i<elems.length; i++) {
			var hrefs = elems[i].getElementsByTagName("a");
			if (hrefs.length) {
				elems[i].href = hrefs[0].href;
				elems[i].onclick = function() { doBannerClick(this.href); };
			}
		}
		var elems_external = document.getElementsByClassName("clickable_external");
		for (var i=0; i<elems_external.length; i++) {
			var hrefs_external = elems_external[i].getElementsByTagName("a");
			if (hrefs_external.length) {
				elems_external[i].href = hrefs_external[0].href;
				elems_external[i].onclick = function() { hrefs_external[0].href="javascript:void()";hrefs_external[0].target="_self";doBannerClick_external(this.href); };
			}
		}
	} else {
	  div = document.getElementsByTagName("div");
	  li = document.getElementsByTagName("li");
	  ul = document.getElementsByTagName("ul");
	  span = document.getElementsByTagName("span");
	  parraf = document.getElementsByTagName("p");
	  td = document.getElementsByTagName("td");
	  pulsable(div);pulsable(li);pulsable(ul);pulsable(span);pulsable(parraf);pulsable(td);
	}
}
function pulsable(etiqueta){
	i = 0;
	while (element = etiqueta[i++]) { 
		if (element.className.indexOf('clickable')!=-1){
			var hrefs = etiqueta[i-1].getElementsByTagName("a");
			if (hrefs.length) {
				etiqueta[i-1].href = hrefs[0].href;
				if (element.className.indexOf('external')!=-1){
					hrefs[0].href="javascript:void()";hrefs[0].target="_self";
					etiqueta[i-1].onclick = function() { doBannerClick_external(this.href); };
				}else{
					etiqueta[i-1].onclick = function() { doBannerClick(this.href); };
				}
			}
		}
	}
}
function abrirVentana(_href,_w,_h) {
	ventana = window.open (_href, 'mywindow','location=NO,status=NO,scrollbars=NO,menubar=NO,resizable=NO, width='+_w+',height='+_h);
	ventana.focus();
}
function trim (str) {
	return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}
function contrata_tienda() {
	var i, pos, acuerdo = "";
	var a = document.cookie.split(";");
	for (i=0; i<a.length; i++) {
		pos = a[i].indexOf("=");
		n = a[i].substring(0, pos);
		if (trim(n)=="cookieacuerdo") {
			acuerdo = "&acuerdo=" + (a[i].substring(1 + pos, a[i].length));
		}		
	}
	sinDNS = document.getElementById("sinDNS");
	conDNS = document.getElementById("conDNS");
	if (sinDNS.checked) {
		document.location = "https://panel.acens.net/catalogo/index.jsp?id_producto=" + sinDNS.value + acuerdo;
	}else{

		document.location = "https://panel.acens.net/catalogo/index.jsp?id_producto=" + conDNS.value + acuerdo;
	}
}
function contrata_exchange() {
	var i, pos, acuerdo = "";
	var a = document.cookie.split(";");
	for (i=0; i<a.length; i++) {
		pos = a[i].indexOf("=");
		n = a[i].substring(0, pos);
		if (trim(n)=="cookieacuerdo") {
			acuerdo = "&acuerdo=" + (a[i].substring(1 + pos, a[i].length));
		}		
	}
	sinDNS = document.getElementById("sinDNS");
	conDNS = document.getElementById("conDNS");
	if (sinDNS.checked) {
		document.location = "https://panel.acens.net/catalogo/index.jsp?id_producto=" + sinDNS.value + acuerdo;
	}else{
		document.location = "https://panel.acens.net/catalogo/index.jsp?id_producto=" + conDNS.value + acuerdo;
	}
}
