var win=null;
function dump(arr,level) {
 // Simply pass the object, and error level
 var dumped_text = "";
 if(!level) level = 0;
 var level_padding = "";
 for(var j=0;j<level+1;j++) level_padding += "    ";
 if(typeof(arr) == 'object') {
 for(var item in arr) {
 var value = arr[item];
 if(typeof(value) == 'object') {
 dumped_text += level_padding + "'" + item + "' ...\n";
 dumped_text += dump(value,level+1);
 } else {
 dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
 }
 }
 } else {
 dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
 }
 return dumped_text;
}
function readCookie(name){
 var ca = document.cookie.split(';');
 var nameEQ = name + "=";
 for(var i=0; i <ca.length; i++) {
 var c = ca[i];
 while (c.charAt(0)==' ') c = c.substring(1, c.length);
 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
 }
 return null;
}
function createCookie(name,value,domain,minutes){
 if (minutes) {
 var date = new Date();
 date.setTime( date.getTime() + ((minutes*60)*1000) );
 var expires = "; expires="+date.toGMTString();
 }
 else var expires = "";
 document.cookie = name+"="+value+expires+"; domain=" + domain + "; path=/";
}
function NewWindowUser(mypage,myname,w,h,pos,infocus){
 if (readCookie('Community_Name')) {
 if(pos=="random"){myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
 if(pos=="center"){myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h)/2:100;}
 else if((pos!='center' && pos!="random") || pos==null){myleft=0;mytop=20;}
 settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";win=window.open(mypage,myname,settings);
 win.focus();
 }
 else if (myname=="newcomment") {
 alert('Debes hacer login para hacer comentarios');
 }
 else {
 alert('Debes hacer login para efectuar esta operación');
 }
}
function closepopup(){
 if (win) {
 win.close();
 }
}
function NewWindowGuest(mypage,myname,w,h,pos,infocus){
var winguest=null;
if(pos=="random"){myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h)/2:100;}
else if((pos!='center' && pos!="random") || pos==null){myleft=0;mytop=20}
settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";win=window.open(mypage,myname,settings);
win.focus();
}
function NewWindowGuestFixed(mypage,myname,w,h,pos,infocus){
var winguest=null;
if(pos=="random"){myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h)/2:100;}
else if((pos!='center' && pos!="random") || pos==null){myleft=0;mytop=20}
settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";win=window.open(mypage,myname,settings);
win.focus();
}
function ModifyUploadProgress(mypage,myname,w,h,pos,infocus){
if ( !(document.modify.Image_Big.value) && (document.modify.Image_Big) ) {
 return false;
}
var winguest=null;
if(pos=="random"){myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h)/2:100;}
else if((pos!='center' && pos!="random") || pos==null){myleft=0;mytop=20}
settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";win=window.open(mypage,myname,settings);
win.focus();
}
function UploadProgress(mypage,myname,w,h,pos,infocus){
if ( !(document.add.Image_Big.value) && (document.add.Image_Big) ) {
 return false;
}
var winguest=null;
if(pos=="random"){myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h)/2:100;}
else if((pos!='center' && pos!="random") || pos==null){myleft=0;mytop=20}
settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";win=window.open(mypage,myname,settings);
win.focus();
}
function TransferProgress(mypage,myname,w,h,pos,infocus){
if ( !(document.upload.url.value) && (document.upload.url) ) {
 return false;
}
var winguest=null;
if(pos=="random"){myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h)/2:100;}
else if((pos!='center' && pos!="random") || pos==null){myleft=0;mytop=20}
settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";win=window.open(mypage,myname,settings);
win.focus();
}
function CheckAttachment(){
 if ( !(document.add.Image_Big.value) && (document.add.Image_Big) ) {
 var ReturnValue = window.confirm('No seleccionastes un archivo, deseas continuar y agregarlo luego? Presiona CANCELAR para agregarlo ahora, OK para continuar.');
 return (ReturnValue);
 }
}
function CheckEmailAlert(){
 var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
 var OK = re.exec(document.add.Contact_Email.value);
 if ( !(document.add.Contact_Email.value) && (document.add.Contact_Email)  ) {
 alert('Debes ingresar una dirección de correo');
 return;
 }
 else if (!OK) {
 alert('Direccion de correo es incorrecta');
 return;
 }
 else {
 return 1;
 }
}
function CheckAttachmentAlert(){
 var re = /^([\w\s\(\)\[\]\/\\\-\.\:%]+(\\|\/)+)?[\w\s\-\.\[\]]+$/;
 // var re = /[\/\\][\w\s\-\.]+$/;
 // var re = /[\\\/]+[\w\s\-\.]+$/;
 var OK = re.exec(document.add.Image_Big.value);
 if ( !(document.add.Image_Big.value) && (document.add.Image_Big)  ) {
 alert('No seleccionastes un archivo');
 return;
 }
 else if (!OK) {
 alert('El archivo ' + document.add.Image_Big.value + ' contiene caracteres invalidos. Renombra el archivo antes de cargarlo.');
 return;
 }
 else {
 document.getElementById('mysubmit').disabled=true;
 return 1;
 }
}
function goToURL(url){window.location = url;}
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 CheckField_msg_body(){
 if ( !(document.message.msg_body.value) && (document.message.msg_body) ) {
 alert('Debes completar todos los datos para continuar');
 return false;
 }
}
function AlertNoAttPost(){
 var myvalue = document.post.post_attachment.value;
 var myfield = document.post.post_attachment;
 if ( ! myfield ) {
 return 1;
 }
 else if ( myfield && myvalue ) {
 var returnValue = window.confirm('ALERTA: Si presionas OK se publicara tu mensaje sin el archivo anexo ' + document.post.post_attachment.value + '. Si deseas anexar el archivo correctamente Cancela y asegurate de presionar el boton \'Cargar anexo\' antes de publicar tu mensaje');
 return(returnValue);
 }
 else {
 return 1;
 }
}
function AlertDelete(){
 var returnValue = window.confirm('Estas seguro que deseas eliminar este registro?');
 return(returnValue);
}
function initFileUploads(f){
	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = f;
	fakeFileUpload.appendChild(document.createElement('input'));
	var image = document.createElement('img');
	image.src='http://static.venetubo.com/images/button_select.gif';
	fakeFileUpload.appendChild(image);
	var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++) {
 if (x[i].type != 'file') continue;
 if (x[i].parentNode.className != 'fileinputs') continue;
 x[i].className = 'file hidden';
 var clone = fakeFileUpload.cloneNode(true);
 x[i].parentNode.appendChild(clone);
 x[i].relatedElement = clone.getElementsByTagName('input')[0];
 x[i].onchange = x[i].onmouseout = function () {
 this.relatedElement.value = this.value;
 }
	}
}
function loadinParent(u){
 window.opener.location.href = u;
 if (window.opener.progressWindow)
 {
 window.opener.progressWindow.close()
 }
 window.close();
}
function ajax_request(uri,container){
 var nocache = ";anticache=" + new Date().getTime();
 var furl = uri + nocache;
 $.ajax({
 url: furl,
 dataType:"html",
 success:function (data) { $(container).html( data ); },
 error:function (xhr,err,e) { $(container).html( '<span class=error>\n  <small>Solicitud no procesada, intenta de nuevo.<\/small>\n<\/span>' ); }
 });
}
function please_wait(txt){
 $(document).ready(function() {
 $.blockUI({ fadeOut: 300, overlayCSS: { backgroundColor: '#FFFFFF' }, message: '<img alt=\"Favor espera...\" src=\"http://static.venetubo.com/images/pleasewait.gif\"><p class=header><b>Favor espera...</b><br><br><div id=upload_status></div><br> <p class=account>( '+txt+' )</p>', css: { padding: '20px', border: '1px solid #EEEEEE', backgroundColor: '#FFFFFF' } });
 });
 return true;
}
function add_playlist(id,res) {
 var endpoint = "http://www.venetubo.com/cgi-bin/myfaves.cgi";
 var payload = "action=add;t=wap;is_ajax=1;SaveType=c";
 payload += ";ID=" + id;
 var uri = endpoint + '?' + payload;
 var container = 'div#'+res;
 ajax_request(uri,container);
}
