/////////////////////////////////////////////////////////////////////////////
function echeck(str) { //valida el email.
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1)
		{return false}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false}

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false}

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false}
		
		 if (str.indexOf(" ")!=-1){
		    return false}
 		 return true					
	}

/////////////////////////////////////////////////////////////////////////////
function checkPhone(str) /* Validate a telephone/fax number... */
{
	var num = "0123456789()- +.";
	for (var intLoop = 0; intLoop < str.value.length; intLoop++) 
		if ( num.indexOf(str.value.charAt(intLoop)) == -1 ) 
			{return false;}
}
/////////////////////////////////////////////////////////////////////////////
function checkNumber(str) /* Validate a NUMBER */
{
	var num = "0123456789";
	for (var intLoop = 0; intLoop < str.value.length; intLoop++) 
		if (-1 == num.indexOf(str.value.charAt(intLoop)) ) 
			{return false;}
}
////////////////////////////////////////////////////////////////////////
function validar_cotizacion()
{
	var Error = "";
	
	document.form_cotizacion.nombre.value = trim(document.form_cotizacion.nombre.value);
		if(document.form_cotizacion.nombre.value=="")
			{Error += "Intoduzca su nombre por favor.\n";}
			
	document.form_cotizacion.ciudad.value = trim(document.form_cotizacion.ciudad.value);
		if(document.form_cotizacion.ciudad.value=="")
			{Error += "Intoduzca su ciudad.\n";}
			
	document.form_cotizacion.direccion.value = trim(document.form_cotizacion.direccion.value);
		if(document.form_cotizacion.direccion.value=="")
			{Error += "Intoduzca su direccion.\n";}
			
	document.form_cotizacion.estado.value = trim(document.form_cotizacion.estado.value);
		if(document.form_cotizacion.estado.value=="")
			{Error += "Escriba su estado.\n";}
			
	document.form_cotizacion.telefono.value = trim(document.form_cotizacion.telefono.value);
		if( (document.form_cotizacion.telefono.value=="") || checkPhone(document.form_cotizacion.telefono)==false)
			{Error +=  "Escriba teléfono o escribalo correctamente.\n";}

	document.form_cotizacion.email.value = trim(document.form_cotizacion.email.value);
		if( (document.form_cotizacion.email.value=="") || echeck(document.form_cotizacion.email.value)==false)
			{Error +=  "Escriba su e-mail o escríbalo correctamente.\n";}
	
	document.form_cotizacion.producto.value = trim(document.form_cotizacion.producto.value);
		if(document.form_cotizacion.producto.value=="")
			{Error += "Escriba el nombre o descripcion del producto.\n";}
			
	document.form_cotizacion.cantidad.value = trim(document.form_cotizacion.cantidad.value);
		if( (document.form_cotizacion.cantidad.value=="") || checkNumber(document.form_cotizacion.cantidad)==false)
			{Error +=  "Escriba la cantidad del producto o escríbala correctamente.\n";}
	
    if (Error != "" ) 
		{
		alert(Error);
		return false;
		}
	else 
		{return true;}


}

//////////////////////////////////////////////////////////////////////////

function trim(s) { 	
	var temp = ""; 	
	var left; 	
	var right;  	
	
	// trim a la izquierda	 	
	for(left = 0; left < s.length; left++) { 		
		var c = s.charAt(left); 
		if( (c != ' ') && (c != '\t') ) break; 	
	} 	
	
	// trim a la derecha	 	
	for(right = s.length-1; right >= 0; right--) { 		
		var c = s.charAt(right); 		
		if( (c != ' ') && (c != '\t') ) break; 	
	} 	 	
		
	temp = s.slice(left, right+1); 	return temp; 
}
////////////////////////////////////////////////////////////////////////