
function MyAjaxRequery(myurl,mytarget)
{
	$("#"+mytarget).load(myurl+'&ajax=1');
}

function MyAjaxLoad(myurl,mytarget)
{
	$("#"+mytarget).html('');
	$("#"+mytarget).load(myurl+'&ajax=1');
}

function prepareForm(formName,target,nextSchema,type)
{
var v = jQuery("#"+formName).validate
				({
					submitHandler: function(formName) 
					{
						jQuery(formName).ajaxSubmit
						({
							target: "#"+target,
							success: function(responseText, statusText, xhr, $form)
							{
								if (nextSchema!=null)
								{
									if(type == 'ajax')
									{
										action = '/templates/public/lib/process.php?action='+nextSchema;
										MyAjaxLoad(action,target);
									}
									if(type == 'redirect')
									{
										window.location.href=nextSchema;
									}
								}
								else
									alert('ok');
							}		 			
						});
					}
				});
}

function openConfirmation(href,id)
{
 if(confirm("¿Seguro que desea eliminar la Imagen seleccionada?")) 
 { 
				document.getElementById(id).style.display="none";
				$.ajax({
				  url: href,
				  cache: false,
				  success: function(data) {
				  $("#confirmDialog").html(data);
				  $("#confirmDialog").dialog('option','title',title);
				  $("#confirmDialog").dialog('open');
				  }
				});
}
}

function RequeryField(field,schema)
{
	values = $("#"+schema+"Form").serialize();
	action = '/centros/templates/public/lib/process.php?schema='+schema+'&action=requery&field='+field+'&'+values;
	$("#"+field+'formField').load(action);
}

function RequeryFieldAndSetValue(field,values,schema)
{
	action = '/centros/templates/public/lib/process.php?schema='+schema+'&action=requery&field='+field+'&'+values;
	$("#"+field+'formField').load(action);
	$("#"+field).val(values);
}

function SetEditable(field)
{
	$("#"+field).removeAttr("disabled");
	$("#"+field).removeAttr("readonly");
}

function generatePermalink(origen, destino)
{  
  var text = document.getElementById(origen).value.toLowerCase();
  text = text.replace(/[áàäâå]/, 'a');
  text = text.replace(/[éèëê]/g, 'e');
  text = text.replace(/[íìïî]/g, 'i');
  text = text.replace(/[óòöô]/g, 'o');
  text = text.replace(/[úùüû]/g, 'u');
  text = text.replace(/[ýÿ]/g, 'y');
  text = text.replace(/[ñ]/g, 'n');
  text = text.replace(/[ç]/g, 'c');
  text = text.replace(/['"]/g, '');
  text = text.replace(/[^a-zA-Z0-9-]/g, ' '); 
  text = text.replace(/\s+/g, '_');
  text = text.replace(/(_)$/g, '');
  text = text.replace(/^(_)/g, '');  
  document.getElementById(destino).value = text; 
  return false;
}

