// Custom utility functions

function toTitleCase(str) {

    return str.substr(0,1).toUpperCase() + str.substr(1).toLowerCase();

}      



function formatTitle(title) {

    return '' + (title != '/' ? ' / ' + toTitleCase(title.substr(1, title.length - 2).replace(/\//g, ' / ')) : '');

}



// Custom SWFAddress and Ajax handling

/*

function getTransport() {

    if (window.XMLHttpRequest) {

        return new XMLHttpRequest();

    } else if (window.ActiveXObject) {

        try {

            return new ActiveXObject('Msxml2.XMLHTTP');

        } catch(e) {

            return new ActiveXObject('Microsoft.XMLHTTP');

        }

    }

}

*/

/*function appear(content, value) {

    if (typeof value == 'undefined') value = 0;

    if (value > 1) return;

    var property = content.filters ? 'filter' : 'opacity';

    content.style[property] = content.filters ? 'alpha(opacity=' + value*100 + ')' : value;

    setTimeout(function () {appear(content, value + .1)} , 50);

}*/

/*

function updateChange(xhr) {

	document.getElementById('principal').innerHTML = '<br><br><br><p align="center"><img src="/images/loa.gif" /></p>'; 

    if (xhr.readyState == 4) {

        if (xhr.status == 200) {

            var content = document.getElementById('principal');

            if (com.asual.util.Browser.isIE()) {

                var _content = document.getElementById('principal');

                if (_content == null) {

                    var _content = content.cloneNode(false);

                    _content.id = 'principal';

                    _content.style.position = 'absolute';

                    _content.style.top = content.offsetTop;

                    _content.style.left = '50%';

                    _content.style.width = content.offsetWidth;

					_content.style.height = content.offsetHeight;

                    _content.style.marginLeft = -content.offsetWidth/2;

                    document.body.appendChild(_content);

                }

                _content.innerHTML = xhr.responseText;

               content.style.height = _content.offsetHeight;

                //appear(_content);                

            } else {

                content.innerHTML = xhr.responseText;

                //appear(content);            

            }

        } else {

            alert('Error: ' + xhr.status + '!');

        }

    }

}

*/

function IsNumeric(sText)



{

   var ValidChars = "0123456789.";

   var IsNumber=true;

   var Char;



 

   for (i = 0; i < sText.length && IsNumber == true; i++) 

      { 

      Char = sText.charAt(i); 

      if (ValidChars.indexOf(Char) == -1) 

         {

         IsNumber = false;

         }

      }

   return IsNumber;

   

   }

function handleChange(event) {
	SWFAddress.setTitle(seotitle);

    var parameters = '';

    for (var p in event.parameters) {

        parameters += '&' + p + '=' + event.parameters[p];

    }

    //var xhr = getTransport();

    //xhr.onreadystatechange = function() {

        //updateChange(xhr);

		if (event.path!="/"){//VALIDA QUE EXISTA UNA PETICION
			pageTracker._trackPageview(event.path);
			var seccionact_el = event.path.split('/', 4);

			seccionact = seccionact_el[2];

			pseccionact = seccionact_el[3];

			if (IsNumeric(seccionact)){//VALIDA QUE LA PETICION SEA CORRECTA CON SECCION NUMERICA

				if (seccionact!=0 || pseccionact!=0){//SI ES DIFERENTE DE LA PRIMERA VEZ
					if (seccionact_el[1]!="" && seccionact_el[2]!="" && seccionact_el[3]!=""){
						cargar_contenido('datasource.php?swfaddress=' + event.path + parameters,'principal','GET');
					}
				}

				if (seccionact==12){

					abriralum('test');


				}

			}

		}

    //}

    //xhr.open('get', 'datasource.php?swfaddress=' + event.path + parameters, true);

   // xhr.send('');

    //SWFAddress.setTitle(formatTitle(event.path));    

}

function XHConn()

{

    var xmlhttp, bComplete = false;

    try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }

    catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }

    catch (e) { try { xmlhttp = new XMLHttpRequest(); }

    catch (e) { xmlhttp = false; }}}

    if (!xmlhttp) return null;

    this.connect = function(sURL, sMethod, sVars, fnDone)

    {

        if (!xmlhttp) return false;

        bComplete = false;

        sMethod = sMethod.toUpperCase();



        try {

            if (sMethod == "GET")

            {

                xmlhttp.open(sMethod, sURL+"?"+sVars, true);

                sVars = "";

            }

            else

            {

                xmlhttp.open(sMethod, sURL, true);

                xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");

                xmlhttp.setRequestHeader("Content-Type",

                    "application/x-www-form-urlencoded");

            }

            xmlhttp.onreadystatechange = function(){

                if (xmlhttp.readyState == 4 && !bComplete)

                {

                    bComplete = true;

                    fnDone(xmlhttp);

                }};

            xmlhttp.send(sVars);

        }

        catch(z) { return false; }

        return true;

    };

    return this;

}

function cargar_contenido(destino,div,metodo,parametros){

	destino="/"+destino;

	document.getElementById(div).innerHTML = '<br><p><img src="/images/loading2.gif"/ style="margin:40px 0 40px 0;"></p>'; 

    var myConn = new XHConn();

    if (!myConn) alert("XMLHTTP not available, Try with a recent browser.");

    var peticion = function (oXML) { document.getElementById(div).innerHTML = oXML.responseText; };

    myConn.connect(destino, metodo, parametros, peticion);

}



function encuestas_ajax(idencu,obj){

	e=eval('document.encuesta'+idencu+'.elements');

	n=e.length;

	str='';

	err='';

	for(i=0;i<n;i++){

		if(e[i].type=="checkbox" && e[i].checked){

			str+=e[i].name + '=' + e[i].value + '&';

		}else if(e[i].type=="radio" && e[i].checked){

			str+=e[i].name + '=' + e[i].value + '&';

		}else if(e[i].value && e[i].type != "checkbox" && e[i].type != "radio"){

			str+=e[i].name + '=' + e[i].value + '&';

		}

	}

	cargar_contenido('datasource_encu_20.php','dato_box'+idencu,'POST',str);

	return false;

}



function preguntas_ajax(idencu,obj){

	e=eval('document.encuesta'+idencu+'.elements');

	n=e.length;

	str='';

	err='';

	for(i=0;i<n;i++){

		if(e[i].type=="checkbox" && e[i].checked){

			str+=e[i].name + '=' + e[i].value + '&';

		}else if(e[i].type=="radio" && e[i].checked){

			str+=e[i].name + '=' + e[i].value + '&';

		}else if(e[i].value && e[i].type != "checkbox" && e[i].type != "radio"){

			str+=e[i].name + '=' + e[i].value + '&';

		}

	}

	cargar_contenido('datasource_preg_23.php','dato_box'+idencu,'POST',str);

	return false;

}



function regalo(){

	e=eval('document.fregalos.elements');

	n=e.length;

	str='';

	err='';

	

	var valido=0;

	for (i=0;i<n;i++){ 

	  if(document.fregalos.elements[i].type == "checkbox"){

		if(document.fregalos.elements[i].checked==1){

			valido=1;

		} 

	  }

	}

	if (valido==1){

		if(document.fregalos.nombre.value.length==0){

			alert('Please complete the field: "Name"');

			document.fregalos.nombre.focus()

			return 0;

		}else{

			for(i=0;i<n;i++){

				if(e[i].type=="checkbox" && e[i].checked){

					str+=e[i].name + '=' + e[i].value + '&';

				}else if(e[i].type=="radio" && e[i].checked){

					str+=e[i].name + '=' + e[i].value + '&';

				}else if(e[i].value && e[i].type != "checkbox" && e[i].type != "radio"){

					str+=e[i].name + '=' + e[i].value + '&';

				}

			}

			cargar_contenido('datasource_regalo_10.php','regalo','POST',str);

		}

	}else{

		alert ('Error: To reserve a gift, you must select at least one gift from the list!');	

	}

	return false;

}



function librodevisitas(){

	e=eval('document.librovisitas');

	n=e.length;

	str='';

	err='';

	if(document.librovisitas.nombre.value.length==0){

		alert('Please complete the field: "Your Name"');

		document.librovisitas.nombre.focus()

		return 0;

	}else{

		for(i=0;i<n;i++){

			if(e[i].type=="checkbox" && e[i].checked){

				str+=e[i].name + '=' + e[i].value + '&';

			}else if(e[i].type=="radio" && e[i].checked){

				str+=e[i].name + '=' + e[i].value + '&';

			}else if(e[i].value && e[i].type != "checkbox" && e[i].type != "radio"){

				str+=e[i].name + '=' + e[i].value + '&';

			}

		}

		cargar_contenido('datasource_guestbook_5.php','guestbook','POST',str);

	}

	return false;

}



function contacto(){

	e=eval('document.contactanos');

	n=e.length;

	str='';

	err='';

	if(document.contactanos.nombre.value.length==0){

		alert('Please complete the field: "Your Name"');

		document.contactanos.nombre.focus()

		return 0;

	}else if(document.contactanos.mensaje.value.length==0){

		alert('Please complete the field: "Message"');

		document.contactanos.mensaje.focus()

		return 0;

	}else{

		for(i=0;i<n;i++){

			if(e[i].type=="checkbox" && e[i].checked){

				str+=e[i].name + '=' + e[i].value + '&';

			}else if(e[i].type=="radio" && e[i].checked){

				str+=e[i].name + '=' + e[i].value + '&';

			}else if(e[i].value && e[i].type != "checkbox" && e[i].type != "radio"){

				str+=e[i].name + '=' + e[i].value + '&';

			}

		}

		cargar_contenido('datasource_contacto_2.php','contactod','POST',str);

	}

	return false;

}



function validarsvp(){

	e=eval('document.rsvp');

	n=e.length;

	str='';

	err='';

	var str= document.rsvp.email.value;

		var at="@"

		var dot="."

		var lat=str.indexOf(at)

		var lstr=str.length

		var ldot=str.indexOf(dot)

	if(document.rsvp.nombre.value.length==0){

		alert('Please complete the field: "Your Name"');

		document.rsvp.nombre.focus()

		return 0;

	}else if(document.rsvp.email.value.length==0){

		alert('Please complete the field: "Email"');

		document.rsvp.email.focus()

		return 0;

	}else if (str.indexOf(at)==-1){

	   alert('"Email address" invalid, please review and try again')

	   document.rsvp.email.focus()

	   return false

	}else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){

	   alert('"Email address" invalid, please review and try again')

	   document.rsvp.email.focus()

	   return false

	}else if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){

		alert('"Email address" invalid, please review and try again')

		document.rsvp.email.focus()

		return false

	}else if (str.indexOf(at,(lat+1))!=-1){

		alert('"Email address" invalid, please review and try again')

		document.rsvp.email.focus()

		return false

	}else if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){

		alert('"Email address" invalid, please review and try again')

		document.rsvp.email.focus()

		return false

	}else if (str.indexOf(dot,(lat+2))==-1){

		alert('"Email address" invalid, please review and try again')

		document.rsvp.email.focus()

		return false

	}else if (str.indexOf(" ")!=-1){

		alert('"Email address" invalid, please review and try again')

		document.rsvp.email.focus()

		return false			

	}else{

		for(i=0;i<n;i++){

			if(e[i].type=="checkbox" && e[i].checked){

				str+=e[i].name + '=' + e[i].value + '&';

			}else if(e[i].type=="radio" && e[i].checked){

				str+=e[i].name + '=' + e[i].value + '&';

			}else if(e[i].value && e[i].type != "checkbox" && e[i].type != "radio"){

				str+=e[i].name + '=' + e[i].value + '&';

			}

		}

		cargar_contenido('datasource_rsvp_7.php','rsvpd','POST',str);

	}

	return false;

}



function validasuscripcion(){
	e=eval('document.suscripcion');
	n=e.length;
	str='';
	err='';
	var str= document.suscripcion.email.value;
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
	if(document.suscripcion.nombre.value.length==0){
		alert('Please complete the field: "Your Name"');
		document.suscripcion.nombre.focus()
		return 0;
	}else if(document.suscripcion.email.value.length==0){
		alert('Please complete the field: "Email"');
		document.suscripcion.email.focus()
		return 0;
	}else if (str.indexOf(at)==-1){
	   alert('"Email address" invalid, please review and try again')
	   document.suscripcion.email.focus()
	   return false
	}else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert('"Email address" invalid, please review and try again')
	   document.suscripcion.email.focus()
	   return false
	}else if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert('"Email address" invalid, please review and try again')
		document.suscripcion.email.focus()
		return false
	}else if (str.indexOf(at,(lat+1))!=-1){
		alert('"Email address" invalid, please review and try again')
		document.suscripcion.email.focus()
		return false
	}else if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert('"Email address" invalid, please review and try again')
		document.suscripcion.email.focus()
		return false
	}else if (str.indexOf(dot,(lat+2))==-1){
		alert('"Email address" invalid, please review and try again')
		document.suscripcion.email.focus()
		return false
	}else if (str.indexOf(" ")!=-1){
		alert('"Email address" invalid, please review and try again')
		document.suscripcion.email.focus()
		return false			
	}else{
		for(i=0;i<n;i++){
			if(e[i].type=="checkbox" && e[i].checked){
				str+=e[i].name + '=' + e[i].value + '&';
			}else if(e[i].type=="radio" && e[i].checked){
				str+=e[i].name + '=' + e[i].value + '&';
			}else if(e[i].value && e[i].type != "checkbox" && e[i].type != "radio"){
				str+=e[i].name + '=' + e[i].value + '&';
			}
		}
		cargar_contenido('datasource_suscripcion_24.php','suscripciond','POST',str);
	}
	return false;
}



function view_imagen(imagennor,rnd,heightg,widthg){
	imagennor = imagennor.replace(/flash_/gi, "");
	imagennor = imagennor.replace(/tmb_/gi, "");
	imagennor = imagennor.replace(/.jpg/gi, "_org.jpg");
	imagennor = imagennor.replace(/.jpeg/gi, "_org.jpeg");
	imagennor = imagennor.replace(/.gif/gi, "_org.gif");
	imagennor = imagennor.replace(/.png/gi, "_org.png");
	if (heightg=="0" || heightg=="" || widthg=="0" || widthg==""){
		var newImg = new Image();
		newImg.src = imagennor;
		var heightg = newImg.height;
		var widthg = newImg.width;
		//alert (newImg.src+" - "+heightg+" - "+widthg);
	}
	heightgp = (heightg*1);
	widthgp = (widthg*1);
	myLightWindow.activateWindow({
		href: 'http://'+window.location.hostname+'/image.php?src='+imagennor+'&src_down='+imagennor+'&rnd='+rnd,     
		type: 'external',
		height: heightgp,
		width: widthgp,
		title: 'View or Download Full Screen Image '
	});
}

function preview_youtube(video){

	myLightWindow.activateWindow({

		href: 'http://'+window.location.hostname+'/youtube/video.php?video='+video,     

		type: 'external',

		height: 368,

		width: 440,

		title: 'YouTube Preview'

	});

}

function external_url(url){

	myLightWindow.activateWindow({

		href: url,     

		type: 'external',

		title: ''

	});

}
function muestra_esconde_div(div_id){
	var existediv=document.getElementById(div_id);
	if (existediv){
		if (document.getElementById(div_id).style.display=='none'){
			muestra_div(div_id);
		}else{
			esconde_div(div_id);
		}
	}
}
function muestra_div(div_id){
	var existediv=document.getElementById(div_id);
	if (existediv){
		document.getElementById(div_id).style.display = '';
	}
}
function esconde_div(div_id){
	var existediv=document.getElementById(div_id);
	if (existediv){
		document.getElementById(div_id).style.display = 'none';
	}
}

function esconde_all(id, idactuals){
	if (document.getElementById('conteprincipal')){
		muestra_div('conteprincipal');
	}
	var ids = id.split('-');
	for(i=0;i<ids.length;i++){
		if (document.getElementById('usermenu'+ids[i])){
			if (ids[i]==idactuals){
				muestra_div("usermenu"+ids[i]);
			}else{
				esconde_div("usermenu"+ids[i]);
			}
		}
	}
}
function esconde_all_datos(id, idactuals){
	if (document.getElementById('conteprincipal')){
		esconde_div('conteprincipal');
	}
	var ids = id.split('-');
	for(i=0;i<ids.length;i++){
		if (document.getElementById('subconte_'+ids[i])){
			if (ids[i]==idactuals){
				muestra_div("subconte_"+ids[i]);
			}else{
				esconde_div("subconte_"+ids[i]);
			}
		}
	}
}
function url_inwindow(url,heightg,widthg,seccionname){
	myLightWindow.activateWindow({
		href: url,     
		type: 'external',
		height: heightg,
		width: widthg,
		title: seccionname
	});
}
if (SWFAddress){
	SWFAddress.addEventListener(SWFAddressEvent.CHANGE, handleChange);
}
