﻿
function Imprimir(capa,width,height,inicio,fin)
{

    var sHtmBody = "";
    var PrintItem0 = document.getElementById(capa); 
    
    sHtmBody += "<HTML><HEAD><title>Barcelona Segway Fun</title>"+
                "<link href=\"css/main.css\" rel=\"stylesheet\" type=\"text/css\"  lang=\"es\"/>"+
                "</HEAD>"+                
                "<BODY>"+inicio+PrintItem0.innerHTML+fin+"</BODY></HTML>";
                
    strRes=sHtmBody;
    strRes=strRes.replace("<TABLE id=ctl05_GridView1 style=\"","<TABLE id=ctl05_GridView1 style=\"font-family: Arial; font-size: 10pt;");
    strRes=strRes.replace("<INPUT id=ctl05_imgPrint","<IMG id=ctl05_imgPrint style=\"visibility:hidden;\" ");
    strRes=strRes.replace("type=image","");
    
    var posIni=strRes.indexOf("onclick=");
    var posFin=strRes.indexOf(";\"",posIni+1);
    
    strRes=strRes.replace(strRes.substring(posIni+9,posFin),"alert('hola'); print();");
    
    var winOpen = window.open('','','toolbar=yes,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=1,copyhistory=no,width='+width+',height='+height); 
    winOpen.moveTo(5,5);
    winOpen.document.write(strRes); 
 
}

function replaceAll(text,busca,reemplaza)
{
    while (text.toString().indexOf(busca) != -1)
    {
            text = text.toString().replace(busca,reemplaza);
    }
    return text;  
}

function trim(cadena)
{
	for(i=0; i<cadena.length; i++)
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(i+1, cadena.length);
		else
			break;
	}

	for(i=cadena.length-1; i>=0; i=cadena.length-1)
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(0,i);
		else
			break;
	}
	
	return cadena;
}

function inicio()
{
    location.href="http://www.todoactividades.com/";
}

function mostrar(nombreCapa)
{ 
    document.getElementById(nombreCapa).style.visibility="visible";
    document.getElementById(nombreCapa).style.display="block";
} 

function ocultar(nombreCapa)
{ 
    document.getElementById(nombreCapa).style.visibility="hidden"; 
    document.getElementById(nombreCapa).style.display="none"; 
}

function validarContactar()
{
    var ctrl=form1.TC;
    var valor="";
    for(i=0;i<ctrl.length;i++)
    {
        if(ctrl[i].checked)
        { 
            valor=ctrl[i].value;
            break;
        }
    }
    if (valor=="")
    {
        alert("Debe seleccionar un tipo de comentario.");
        return;
    }
    if (form1.nombre.value=="" || form1.email.value=="" || form1.mensaje.value=="" ||form1.telefono.value=="")
    {
        alert("Debe rellenar todos los campos solicitados.");
        return;
    }
    form1.submit();
}

function validarRegistro()
{
    if (form1.nombre.value=="" || form1.apellidos.value=="" || form1.empresa.value=="" || form1.ciudad.value=="" || form1.telefono.value=="" || form1.email.value=="")
    {
        alert("Debe rellenar todos los campos solicitados.");
        return;
    }
    form1.submit();
}

function validarReserva(regalo)
{
    
    //Validar las cajas comunes
    if (form1.ctl05$txtNombre.value=="" || form1.ctl05$txtApellidos.value=="" || form1.ctl05$txtCiudad.value=="" || form1.ctl05$txtTelefono.value=="" || form1.ctl05$txtEmail.value=="")
    {
        alert("Debe rellenar todos los campos solicitados.");
        return false;
    }
    if (regalo==1)
    {
        //Validar también el regalo
        if (form1.ctl05$txtNombreDestinatario.value=="" || form1.ctl05$txtMailDestinatario.value=="" || form1.ctl05$txtMensajeDestinatario.value=="")
        {
            alert("Debe rellenar todos los campos solicitados del destinatario del regalo.");
            return false;
        }
    }
    return true;
}

function emailCheck (emailStr) {
var emailPat=/^(.+)@(.+)$/
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
var validChars="\[^\\s" + specialChars + "\]"
var quotedUser="(\"[^\"]*\")"
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
var atom=validChars + '+'
var word="(" + atom + "|" + quotedUser + ")"
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

if (user.match(userPat)==null) {
    return false
}

var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
		return false
	    }
    }
    return true
}

var domainArray=domain.match(domainPat)
if (domainArray==null) {
    return false
}

var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   return false
}

if (len<2) {
   var errStr="This address is missing a hostname!"
   return false
}

return true;
}


function getCookieVal (offset)  
   { 
   var endstr = document.cookie.indexOf (";", offset); 
   if (endstr == -1) 
      endstr = document.cookie.length; 
   return unescape(document.cookie.substring(offset, endstr)); 
   } 

function GetCookie (name)  
   { 
   var arg = name + "="; 
   var alen = arg.length; 
   var clen = document.cookie.length; 
   var i = 0; 
   while (i < clen)  
      { 
      var j = i + alen; 
      if (document.cookie.substring(i, j) == arg) 
         return getCookieVal (j); 
      i = document.cookie.indexOf(" ", i) + 1; 
      if (i == 0) break;  
      } 
   return null; 
   } 

function SetCookie (name, value)  
   { 
   var argv = SetCookie.arguments; 
   var argc = SetCookie.arguments.length; 
   var expires = (argc > 2) ? argv[2] : null; 
   var path = (argc > 3) ? argv[3] : null; 
   var domain = (argc > 4) ? argv[4] : null; 
   var secure = (argc > 5) ? argv[5] : false; 
   document.cookie = name + "=" + escape (value) + 
        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
        ((path == null) ? "" : ("; path=" + path)) + 
        ((domain == null) ? "" : ("; domain=" + domain)) + 
        ((secure == true) ? "; secure" : "");
        
   } 

function DeleteCookie ()  
   { 
   var exp = new Date(); 
   exp.setTime (exp.getTime() - 1000000000);  // This cookie is history (changed -1 to make it previous time) 
   var cval = GetCookie ('DemoName'); 
   document.cookie ='DemoName' + "=" + cval + "; expires=" + exp.toGMTString(); 
   alert("The cookie has been deleted."); 
   } 

