$.fn.clearForm = function() {
  return this.each(function() {
 var type = this.type, tag = this.tagName.toLowerCase();
 if (tag == 'form')
   return $(':input',this).clearForm();
 if (type == 'text' || type == 'password' || tag == 'textarea')
   this.value = '';
 else if (type == 'checkbox' || type == 'radio')
   this.checked = false;
 else if (tag == 'select')
   this.selectedIndex = -1;
  });
};

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

templatePrevio = '<div>'+
  		   '<img src="${path}"  height="72" width="96"/>'+
  		   '<span>${fecha}</span>'+
           '<h3>${titulo}</h3>'+
           '<p>${resumen}</p>'+
           '<a href="${cat}-detalle.html?id=${id}" class="link">ver mas</a>'+   
           '</div>';

templateMuestra='<div class="top"><p><a href="${cat}.html" class="link">Volver</a>${link2}</p></div>'+
'<img src="${path}" id="img_masc" width="400px" height="240px"  /><div><h2>${titulo}</h2>${cuerpo}</div>';

callServiceJSON = function (p_name,p_data,fx,async,c){
	var v_async = false;
	if(async)v_async = async;
	if(! c)c=10;
	if (c>0)
		$.ajax({						
			type: "POST",
			dataType:"json",
			data:p_data,
			url: p_name,
			async:v_async,
			success: function (json){
				fx(json);
				//ocultas el div
			},
			cache:false,
			error: function (request, status, error) {
					//reintentando...
					callServiceJSON (p_name,p_data,fx,async,c--);
				}
		});
	else{
		// ocultar div plubicar error hoy con alert	
		alert("Error en "+ p_name);
	}
};

cargar_var = function(txt){
	v = txt.split("|");
	eval(v[0] +"=v[1]");
};

callServiceText = function (p_name,p_data,fx,async){
	var v_async = false;
	if(async)v_async = async;
	$.ajax({						
		type: "POST",
		dataType:"text",
		async:v_async,
		data:p_data,
		url: p_name,
		success: fx,
		cache:false
	});
};

ReplaceAll =function (Source,stringToFind,stringToReplace){

	  var temp = Source;

	    var index = temp.indexOf(stringToFind);

	        while(index != -1){

	            temp = temp.replace(stringToFind,stringToReplace);

	            index = temp.indexOf(stringToFind);

	        }

	        return temp;

};
