var URL="http://www.dowhilestudio.com/";
//var URL="http://www.dowhilestudio.com/dowhile/";

function validarEmail(valor) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
		return (true)
	} else {
		return (false);
	}
}

function LimitAttach(tField,iType) {
	file=tField.value;
	if (iType==1) {
		extArray = new Array(".gif",".jpg",".png");
	}
	if (iType==2) {
		extArray = new Array(".swf");
	}
	if (iType==3) {
		extArray = new Array(".exe",".sit",".zip",".tar",".swf",".mov",".hqx",".ra",".wmf",".mp3",".qt",".med",".et");
	}
	if (iType==4) {
		extArray = new Array(".mov",".ra",".wmf",".mp3",".qt",".med",".et",".wav");
	}
	if (iType==5) {
		extArray = new Array(".html",".htm",".shtml");
	}
	if (iType==6) {
		extArray = new Array(".doc",".xls",".ppt");
	}
	if (iType==7) {
		extArray = new Array(".flv");
	}
	allowSubmit = false;
	if (!file) return;
	while (file.indexOf("\\") != -1) file = file.slice(file.indexOf("\\") + 1);
	ext = file.slice(file.indexOf(".")).toLowerCase();
	for (var i = 0; i < extArray.length; i++) {
		if (extArray[i] == ext) {
			allowSubmit = true;
			break;
		}
	}
	if (allowSubmit) {
	} else {
		tField.value="";
		if (iType==1) {
			alert("Només es poden pujar imatges amb les extensions " + (extArray.join(" ")) + ".\n\nEs possible que el nom del arxiu no tingui un format correcte. Canvia el nom per algun similar a 'foto_01.jpg'.\n\nPer favor selecciona un nou arxiu");
		}
		if (iType==7) {
			alert("Solo se pueden subir FLV.\n\nPer favor selecciona un archivo con formato " + (extArray.join(" ")));
		}
		if (iType==2) {
			alert("Solo se pueden subir SWF.\n\nPer favor selecciona un archivo con formato " + (extArray.join(" ")));
		}
	}
}

//Retorna: 1 = NIF ok, 2 = CIF ok, 3 = NIE ok, -1 = NIF error, -2 = CIF error, -3 = NIE error, 0 = ??? error
function valida_nif_cif_nie(a)
{
	
	var temp=a.toUpperCase();
	var cadenadni="TRWAGMYFPDXBNJZSQVHLCKE";
	if (temp!==''){
	
	//si no tiene un formato valido devuelve error
	if ((!/^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$/.test(temp) && !/^[T]{1}[A-Z0-9]{8}$/.test(temp)) && !/^[0-9]{8}[A-Z]{1}$/.test(temp))
	{
	return 0;
	}
	
	//comprobacion de NIFs estandar
	if (/^[0-9]{8}[A-Z]{1}$/.test(temp))
	{
	posicion = a.substring(8,0) % 23;
	letra = cadenadni.charAt(posicion);
	var letradni=temp.charAt(8);
	if (letra == letradni)
	{
	return 1;
	}
	else
	{
	return -1;
	}
	}
	
	//algoritmo para comprobacion de codigos tipo CIF
	suma = parseInt(a.charAt(2))+parseInt(a.charAt(4))+parseInt(a.charAt(6));
	
	for (i = 1; i < 8; i += 2)
	{
	temp1 = 2 * parseInt(a.charAt(i));
	temp1 += '';
	temp1 = temp1.substring(0,1);
	temp2 = 2 * parseInt(a.charAt(i));
	temp2 += '';
	temp2 = temp2.substring(1,2);
	if (temp2 == '')
	{
	temp2 = '0';
	}
	
	suma += (parseInt(temp1) + parseInt(temp2));
	}
	suma += '';
	n = 10 - parseInt(suma.substring(suma.length-1, suma.length));
	
	//comprobacion de NIFs especiales (se calculan como CIFs)
	if (/^[KLM]{1}/.test(temp))
	{
	if (a.charAt(8) == String.fromCharCode(64 + n))
	{
	return 1;
	}
	else
	{
	return -1;
	}
	}
	//comprobacion de CIFs
	if (/^[ABCDEFGHJNPQRSUVW]{1}/.test(temp))
	{
	temp = n + '';
	if (a.charAt(8) == String.fromCharCode(64 + n) || a.charAt(8) == parseInt(temp.substring(temp.length-1, temp.length)))
	{
	return 2;
	}
	else
	{
	return -2;
	}
	}
	
	//comprobacion de NIEs
	//T
	if (/^[T]{1}[A-Z0-9]{8}$/.test(temp))
	{
	if (a.charAt(8) == /^[T]{1}[A-Z0-9]{8}$/.test(temp))
	{
	return 3;
	}
	else
	{
	return -3;
	}
	}
	
	//XYZ
	if (/^[XYZ]{1}/.test(temp))
	{
	
	temp = temp.replace('X','0')
	temp = temp.replace('Y','1')
	temp = temp.replace('Z','2')
	pos = str_replace(['X', 'Y', 'Z'], 0, ['0','1','2'], temp).substring(0, 8) % 23;

	
	if (a.charAt(8) == cadenadni.substring(pos, pos + 1))
	{
	return 3;
	}
	else
	{
	return -3;
	}
	}
	}
	return 0;
}

function tiene_numeros(texto){
	var numeros="0123456789";
   for(i=0; i<texto.length; i++){
      if (numeros.indexOf(texto.charAt(i),0)!=-1){
         return true;
      }
   }
   return false;
}

function obtenerDigito(valor){
  valores = new Array(1, 2, 4, 8, 5, 10, 9, 7, 3, 6);
  control = 0;
  for (i=0; i<=9; i++)
    control += parseInt(valor.charAt(i)) * valores[i];
  control = 11 - (control % 11);
  if (control == 11) control = 0;
  else if (control == 10) control = 1;
  return control;
}

function numerico(valor){
  cad = valor.toString();
  for (var i=0; i<cad.length; i++) {
    var caracter = cad.charAt(i);
	if (caracter<"0" || caracter>"9")
	  return false;
  }
  return true;
}

function validar_CC(banco,sucursal,dc,cuenta) {
  if (banco=="" || sucursal=="" || dc=="" || cuenta=="")
    	return false;
  else {
    if (banco.length!=4 || sucursal.length!=4 || dc.length!=2 || cuenta.length!=10)
     	return false;
    else {
      if (!numerico(banco) || !numerico(sucursal) || !numerico(dc) || !numerico(cuenta))
        	return false;
      else {
        if (!(obtenerDigito("00"+banco+sucursal)==parseInt(dc.charAt(0))) || !(obtenerDigito(cuenta)==parseInt(dc.charAt(1))))
          	return false;
	    else
          return true;
      }
    }
  }
}


$(document).ready(function(){
						   
	$(".bandera").click(function () {
		//alert($(this).attr("valor"));
		$.ajax({
			type: "POST",
			url: URL+"includes/set_idioma.php",
			data: "ban="+$(this).attr("valor"),
			success: function(msg){
				window.location.reload(); 
			}
		});
	});
	
	/*$('.px_sombra_banner').cycle({
		fx: 'fade',
		//speed: 4000
		speed: 1000
	});*/
	//$('.px_sombra_banner').nivoSlider();
	$('.px_sombra_banner').nivoSlider({
        effect: 'fade', // Specify sets like: 'fold,fade,sliceDown'
		startSlide: 0, // Set starting Slide (0 index)
		animSpeed: 1000, // Slide transition speed
		pauseTime: 4000, // How long each slide will show
		directionNav: false, // Next & Prev navigation
        directionNavHide: false, // Only show on hover
		controlNav: false, // 1,2,3... navigation
		pauseOnHover: false, // Stop animation while hovering
		controlNavThumbs: false, // Use thumbnails for Control Nav
		captionOpacity: 0, // Universal caption opacity
		keyboardNav: false // Use left & right arrows
		/*
		slices: 15, // For slice animations
        boxCols: 8, // For box animations
        boxRows: 4, // For box animations
        animSpeed: 500, // Slide transition speed
        pauseTime: 3000, // How long each slide will show
        startSlide: 0, // Set starting Slide (0 index)
        directionNav: true, // Next & Prev navigation
        directionNavHide: true, // Only show on hover
        controlNav: true, // 1,2,3... navigation
        controlNavThumbs: false, // Use thumbnails for Control Nav
        controlNavThumbsFromRel: false, // Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', // Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
        keyboardNav: true, // Use left & right arrows
        pauseOnHover: true, // Stop animation while hovering
        manualAdvance: false, // Force manual transitions
        captionOpacity: 0.8, // Universal caption opacity
        prevText: 'Prev', // Prev directionNav text
        nextText: 'Next', // Next directionNav text
        beforeChange: function(){}, // Triggers before a slide transition
        afterChange: function(){}, // Triggers after a slide transition
        slideshowEnd: function(){}, // Triggers after all slides have been shown
        lastSlide: function(){}, // Triggers when last slide is shown
        afterLoad: function(){} // Triggers when slider has loaded
		*/
    });
	
	$(".opc_menu").mouseover(function() {
		var valor=$(this).attr("valor");
		if ($("#opc_"+valor).attr("valor")=="no") {
			var n = $("#opc_"+valor).queue("fx");
			if (n.length==0) {
				$("#opc_"+valor).fadeIn("slow");
				//$("#opc_"+valor).clearQueue();
				//$(this).clearQueue();
				//$("#opc_"+valor).stop();
				//$(this).stop();
			}
		}
		return false;
	});
	$(".opc_menu").mouseout(function() {
		var valor=$(this).attr("valor");
		if ($("#opc_"+valor).attr("valor")=="no") {
			//var n = $("#opc_"+valor).queue("fx");
			//if (n.length==0) {
				$("#opc_"+valor).fadeOut("normal");
				//$("#opc_"+valor).clearQueue();
				//$(this).clearQueue();
				//$("#opc_"+valor).stop();
				//$(this).stop();
			//}
		}
		return false;
	});
	
});

