$j = jQuery.noConflict();

if(location.pathname.indexOf("/tienda/") != -1){
	if($j.browser.msie && parseInt($j.browser.version) <= 6){
		window.location = "/tienda-ie6.php";	
	}
}
	
$j(function(){
	$j("#navmenu > ul > li > a").each(function(){
		var sURL = new String(this.pathname);
		if($j.browser.msie){
			sURL = "/" + sURL;
		}
		if(sURL == "/") return;
		if(window.location.pathname.indexOf(sURL) != -1){
			$j(this).parent("li").addClass("active");
		}
	});
	
	$j("#sidebar-navigation td a").each(function(){
		if(this.pathname == "/") return;
		if(window.location.pathname == this.pathname){
			$j(this).attr("id", "active_menu-sidenav");
		}
	});
	
	if($j("#sidebar-categories").get(0)){
		$j("#sidebar-categories").accordion({
			autoHeight: false,
			collapsible: true,
			active: "h3.active"
		});
	}
});

function Trim(sText){
	return sText.replace(/^\s*|\s*$/g, "");
}

function IsEmail(sAddress){
	if(sAddress == "") return false;
	var objRegExp = new RegExp("^[a-z0-9_.\-]{3,}@[a-z0-9.\-]{3,}\.[a-z]{2,3}$", "i");
	return objRegExp.test(sAddress);
}

function CapitalizeName(sName){
	if(sName == "") return sName;
	sName = sName.toLowerCase();
	sFirstLetter = sName.charAt(0);
	sName = sFirstLetter.toUpperCase() + sName.substring(1, sName.length);
	return sName;
}

function ChecarSuscripcion(Form){
	if(Form.first_name.value == 'tu nombre') Form.first_name.value = "";
	if(Form.email.value == 'tu e-mail') Form.email.value = "";
	if(Trim(Form.first_name.value) == ""){
		alert("Por favor ingresa tu primer nombre");
		Form.first_name.focus();
		return false;
	}
	sName = Form.first_name.value;
	if(sName.indexOf(" ") != -1) sName = sName.split(" ")[0];
	Form.first_name.value = CapitalizeName(sName);
	if(Trim(Form.email.value) == ""){
		alert("Por favor ingresa tu direccion de correo electronico");
		Form.email.focus();
		return false;
	}
	if(!IsEmail(Trim(Form.email.value))){
		alert("Por favor ingresa una direccion de correo electronico valida");
		Form.email.focus();
		Form.email.select();
		return false;
	}
	return true;
}
