/*--------------------------------*/
/*	SECURITY					  */
/*--------------------------------*/	
function set_int(valor){
	valor = '' + valor;
	valor = trim(valor);
	if(valor.length>0){
	  valor = parseInt(valor);
	  if (isNaN(valor)) {
			return 0;
	  }
	}else{
		return 0;
	}
	return valor;
}
function set_float(valor){
	valor = '' + valor;
	valor = trim(valor);
	if(valor!=0){
	  valor = parseFloat(valor);
	  if (isNaN(valor)) {
			return 0;
	  }
	}
	return valor;
}
function validarEntero(valor){
	if(valor!=0){
		valor = parseInt(valor);
		if (isNaN(valor)) {
			return "";
		}
	}
	return valor;
}
function validarFloat(valor){
	if(valor!=0){
		valor = parseFloat(valor);
		if (isNaN(valor)) {
			return "";
		}
	}
	return valor;
}
function CheckEmailAddress(value){
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(value)){
		return true;
	}else{
		return false;
	}
}
function VerificarMail(strMail) {
//La siguiente funcion da error si se introduce algo.usuario@dominio.es
	var patMail = /^(.+)@(.+)$/;
	var patUser = /^[a-zņA-Z\d_-]+(\.[a-zņA-Z\d_-]+)*$/;
	var patDomainIP = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
	var patDomain = /^[a-zņA-Z\d_-]+(\.[a-zņA-Z\d_-]+)+$/;
	var matchArray = strMail.match(patMail);
	if(matchArray == null){return false;}
	var user = new String(matchArray[1]);
	var domain = new String(matchArray[2]); 
	if(user.match(patUser) == null){return false;}
	var IPArray = domain.match(patDomainIP);
	if(IPArray != null){ 
		 for (var i=1;i<=4;i++) {
		  if(IPArray[i]>255){return false;}
		 }
		 return true; 
	}
	var domainArray = domain.match(patDomain);
	if(domainArray == null) {return false;}
	if(domainArray[domainArray.length - 1].length < 3 || domainArray[ domainArray.length - 1].length > 5) { return false;}
	return true;
}
/*--------------------------------*/
/*	UTILS						  */
/*--------------------------------*/	
function ltrim(valor) {
	valor = '' + valor;
	if(valor.length>0){
		return valor.replace(/^\s+/, "");
	}else{
		return valor;
	}
}
function rtrim(valor) {
	valor = '' + valor;
	if(valor.length>0){
		return valor.replace(/\s+$/, "");
	}else{
		return valor;
	}
}
function trim(valor) {
	valor = '' + valor;
	if(valor.length>0){
		return rtrim(ltrim(valor));
	}else{
		return valor;
	}
}
function str_replace(haystack, needle, replacement) {
	if(haystack.indexOf(needle) != -1) {
		var temp = haystack.split(needle);
		return temp.join(replacement);
	}
	return haystack;
}
function getElById(name) {
	return document.getElementById(name);
}
function isset(variable_name) {
	try {
		if (typeof(eval(variable_name)) != 'undefined')
		if (eval(variable_name) != null)
		return true;
	} catch(e) { }
	return false;
}
/*--------------------------------*/
/*	PNG							  */
/*--------------------------------*/	
// Corrector de Bug PNG para Explorer. Opera y Mozilla funcionan correctamente sin este JS
function correctPNG() {
   for(var i=0; i<document.images.length; i++)
      {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	     {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText 
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\');\"></span>" 
		 img.outerHTML = strNewHTML
		 i = i-1
	     }
      }
}

/*--------------------------------*/
/*	NAVIGATOR					  */
/*--------------------------------*/	
var ua = navigator.userAgent.toLowerCase();

function detect(text) {
   	stringposition = ua.indexOf(text) + 1;
   	data = text;
   	return stringposition;
}
if (detect('opera')) { 
} else if (detect('firefox')){ 
} else if (detect('msie')){
	 window.attachEvent("onload", correctPNG);	
}

/*--------------------------------*/
/*	VARIOS TIENDA				  */
/*--------------------------------*/	
function OpenWin2(page,name,w,h,scrol) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	window.open(page,name,'scrollbars='+scrol+',resizable=1,left='+winl+',top='+wint+',width='+w+',height='+h);
}

function mostrar_recurso(recurso_id,w,h,scrol) {
	var url='recurso.asp?recurso_id=' + recurso_id;
    OpenWin2(url,'recurso',w,h,scrol);return false;	
}

// ***** redondeo de divs ***** //

window.onload=function(){
	$(".TitCaja").corner('6px top');
	$("#ColumnaIzquierda .Caja").corner('6px bottom');
	$(".Cintillo").corner('6px');
	$(".Mensaje").corner('12px');
	$(".Aviso").corner('12px');
	$(".FichaProducto").corner('12px');
	$(".FichaProducto table table").corner('12px');
	$(".FotoEnListado").corner('6px');
	$("#CarrusellTienda").corner('24px');
	$("#Carrito").corner('12px bottom');
	$(".overview").corner('6px');
	$(".Fondo").corner('10px');
	$(".overview strong").corner('5px');
	$(".overview img").corner('14px');
	$(".Caja2").corner('6px');
	$(".DatosEnvio").corner('12px');
	$(".DatosFacturacion").corner('12px');
	$(".PasoAPaso").corner('4px');
	$(function() {
		$('.Galeria a').lightBox({fixedNavigation:true});
	});	
}
