function TrimString(sInString) {
	  sInString = sInString.replace( /^\s+/g, "" );// strip leading
	  return sInString.replace( /\s+$/g, "" );// strip trailing
	}

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 AddArt(idArt,cantidad)
	{
       /*POR AHORA NO HACE FALTA VALIDAR CANTIDA DPORQUE NO SE USAN CANTIDADES EN PLANETA ( CANTIDAD.VALUE CAMBIADO ABAJO POR 1 )
       *if ((cantidad.value=='') || (!(IsNumeric(cantidad.value)))) {
       *	  alert("Recuerde colocar una cantidad y que esta sea un valor numerico");
	   *  } else {
       *
       */

			  var hd3 =
				{
					success: function(o)
					{
                        if (TrimString(o.responseText)=="Ok"){
                               document.getElementById('interesBoton').innerHTML = "<img src=img/opts_24.png> Articulo Agregado al carrito de consulta.<br> <a href='shopCart.php'>Ver Carrito de consulta</a>";
                        }else{
                               document.getElementById('interesBoton').innerHTML = "El Articulo ya existe en el carrito.<br> <a href='shopCart.php'>Ver Solicitud</a> | <a style='cursor:pointer' onclick='history.go(-1);'>Seguir mirando</a>";
                        }
                         //alert(TrimString(o.responseText));
                         //alert(TrimString(o.responseText));
						 //ActualizarPanel();
					} ,
					failure: function(o)
					{
						//ActualizarPanel();
					}
				}
//				var cObj = YAHOO.util.Connect.asyncRequest('POST', 'AjaxArt.php?T=1&Art='+ idArt + '&Cantidad=' + cantidad.value, hd3);
   				var cObj = YAHOO.util.Connect.asyncRequest('POST', 'AjaxArt.php?T=1&Art='+ idArt + '&Cantidad=1', hd3);
	 // }

	}
	function ActualizarPanel()
	{
	var hd =
		{
			success: function(o) 	{

	                //alert(o.responseText);
	                 document.getElementById('Arts').innerHTML= "<a class='ch4' href='ShopCart.php'>"+ o.responseText + " Articulos en el Carrito </a>";

			} ,
	    	failure: function(o)	   {
				alert("Error. Recargue la pagina.");
			}
		}

		 var cObj = YAHOO.util.Connect.asyncRequest('POST', 'AjaxArt.php?T=2', hd);

	   }

	function ActualizoTabla()
	{
	var hd2 =
		{
			success: function(o) 	{

	                //alert(o.responseText);
	                 document.getElementById('Tabla').innerHTML=TrimString(o.responseText);

			} ,
	    	failure: function(o)	   {
				alert("Error. Recargue la pagina.");
			}
		}

		 var cObj = YAHOO.util.Connect.asyncRequest('POST', 'AjaxArt.php?T=3', hd2);

	   }

	function DeleteArt(Num)
	{
	var hd4 =
		{
			success: function(o) 	{
	                //alert(o.responseText);
	                ActualizoTabla();
	                //ActualizarPanel();
	                //alert("Articulo Eliminado del Pedido");

			} ,
	    	failure: function(o)	   {
				alert("Error. Recargue la pagina.");
			}
		}

		 var cObj = YAHOO.util.Connect.asyncRequest('POST', 'AjaxArt.php?T=4&pos=' + Num, hd4);

	   }

       	function SubirCantidad(pos)
		{
		  var handlerSubirCantidad =
				{
					success: function(o)
					{
						document.getElementById(pos).innerHTML = o.responseText;
						history.go();
					} ,
					failure: function(o)
					{
						alert("Error al aumentar cantidad,intente nuevamente");
					}
				}

				 var cObj = YAHOO.util.Connect.asyncRequest('GET', 'AjaxArt.php?T=5&pos='+ pos , handlerSubirCantidad);

		}
		function BajarCantidad(pos)
		{
		  var handlerBajarCantidad =
				{
					success: function(o)
					{
						document.getElementById(pos).innerHTML = o.responseText;
						history.go();
					} ,
					failure: function(o)
					{
						alert("Error al aumentar cantidad,intente nuevamente");
					}
				}

				 var cObj = YAHOO.util.Connect.asyncRequest('GET', 'AjaxArt.php?T=6&pos='+ pos , handlerBajarCantidad);

		}