
function errorLog() {
	jQuery("#pcv_statusLoading").hide();
	jQuery("#pcv_pcMsg").html("Vaya!! Parece que ha ocurrido un error. Int&eacute;ntalo de nuevo en unos minutos.");
	jQuery("#pcv_pcMsg").show();
}

function vCloudCall(f, v, url_directory) {
	url_images=url_directory+"/images/";
	jQuery.blockUI({ message: '<div style="padding:10px;"><img src="'+url_images+'ajax_loading_peq.gif"/>&nbsp;&nbsp;<h2>Espera por favor...</h2><p style="font-size:0.9em;color:#666666;">Este proceso puede tardar. No refresques esta p&aacute;gina.</p></div>' });
	jQuery.post( url_directory + "vcloud_api.php", { V11: f, V12: v, V13: Math.random() }, function(data){
			try {
				var data = eval('(' + data + ')');
				if (data[0]==-2) { // Ya existe la caja
					function mycallbackfunc(value,m){
						if (value==true) {
							jQuery.blockUI({ message: '<div style="padding:10px;"><img src="'+url_images+'ajax_loading_peq.gif"/>&nbsp;&nbsp;<h2>Espera por favor...</h2><p style="font-size:0.9em;color:#666666;">Este proceso puede tardar. No refresques esta p&aacute;gina.</p></div>' });
							jQuery.post( url_directory + "vcloud_api.php", { V11: f, V12: v+"&ow=1", V13: Math.random() }, function(data){
								var data = eval('(' + data + ')');
								jQuery("#pcv_pcMsg").html("<p>" + data[1] + "</p>");
								jQuery("#pcv_pcMsg").fadeIn(1000).fadeTo(5000, 1).fadeOut(1000);
							});
						}
					}
					jQuery.prompt('Alguno de los proyectos que usa esta aplicación ya existen en tu Velneo vServer.<br>&#191;Deseas sobreescribirlos?',{ opacity: 0.6, buttons: { Si: true, No: false }, callback: mycallbackfunc });
				} else { // No existia la caja en el vServer
					jQuery("#pcv_pcMsg").html("<p>" + data[1] + "</p>");
					jQuery("#pcv_pcMsg").fadeIn(1000).fadeTo(5000, 1).fadeOut(1000);
				}
			} catch(e) {
				errorLog();
			}
		}
	);
}

function vUpdateControls(result) {
	if (result==-9) { // No tiene vServer
		jQuery('#pcv_install').click(function () {location='/inicio-sesion';});
	}
	jQuery("#pcv_instalar").show();
}

function vCloudGetStatus(v, url_directory) {
	jQuery("#pcv_statusLoading").show();  
	jQuery.post( url_directory + "vcloud_api.php", { V11: "getStatus", V12: v, V13: Math.random()}, function(data){
			try {
				var myObject = eval('(' + data + ')');
				szHost=myObject[0];
				result=myObject[1];
				jQuery("#pcv_statusLoading").hide();
				vUpdateControls(result);
			} catch (e) {
				errorLog();
			}
		}
	);
}


