
function validate(form)
{

	if(Trim(form.Manufacturer.value).length < 1)
	{
		alert("Select Manufacturer")

		form.Manufacturer.focus() 		
		 
		return false	
	}	
	if(Trim(form.CarCategory.value).length < 1)
	{
		alert("Select Type of car")
		
		form.CarCategory.focus()		
		 
		return false	
	}
	if(Trim(form.CarName.value).length < 1)
	{
		alert("Enter Car Name")
		form.CarName.select()
		form.CarName.focus() 
		 
		return false	
	}	
	if(Trim(form.CarName.value).length > 50)
	{		
		alert("Maximum allowed length of Car Name is 50 !!!")
		form.CarName.select()
		form.CarName.focus() 
		 
		return false	
	}			
	if(Trim(form.Colour.value).length < 1)
	{
		alert("Enter Colour")
		form.Colour.select()
		form.Colour.focus() 
		 
		return false	
	}	
	if(Trim(form.Colour.value).length > 50)
	{		
		alert("Maximum allowed length of Colour is 50 !!!")
		form.Colour.select()
		form.Colour.focus() 
		 
		return false	
	}	
	if(Trim(form.regstate.value)=="Select State")
	{		
		alert("Select State")
		 
		return false	
	}
	if(Trim(form.Location.value).length < 1)
	{
		alert("Enter Location")
		form.Location.select()
		form.Location.focus() 
		 
		return false	
	}	
	if(Trim(form.Location.value).length > 50)
	{		
		alert("Maximum allowed length of Location is 50 !!!")
		form.Location.select()
		form.Location.focus() 
		 
		return false	
	}	
	if(Trim(form.Mileage.value).length < 1)
	{
		alert("Enter Mileage")
		form.Mileage.select()
		form.Mileage.focus() 
		 
		return false	
	}	
	if(Trim(form.Mileage.value).length > 5)
	{		
		alert("Enter Valid Data !!!")
		form.Mileage.select()
		form.Mileage.focus() 
		 
		return false	
	}	
	if(!checkNumeric(form.Mileage))
	{
		alert("Enter Valid Data")
		form.Mileage.select()
		form.Mileage.focus() 		 
		return false	
	}	
	if(Trim(form.Km.value).length < 1)
	{
		alert("Enter Kilometers traveled")
		form.Km.select()
		form.Km.focus() 
		 
		return false	
	}	
	if(Trim(form.Km.value).length > 7)
	{		
		alert("Enter Valid Data!!!")
		form.Km.select()
		form.Km.focus() 
		 
		return false	
	}				
	if(!checkNumeric(form.Km))
	{
		alert("Enter Valid Data")
		form.Km.select()
		form.Km.focus() 		 
		return false	
	}
	if(Trim(form.Price.value).length < 1)
	{
		alert("Enter Expecting Price ")
		form.Price.select()
		form.Price.focus() 
		 
		return false	
	}	
	if(Trim(form.Price.value).length > 9)
	{		
		alert("Enter Valid Data!!!")
		form.Price.select()
		form.Price.focus() 
		 
		return false	
	}				
	if(!checkNumeric(form.Price))
	{
		alert("Enter Valid Data")
		form.Price.select()
		form.Price.focus() 		 
		return false	
	}
	if(Trim(form.Description.value).length > 1000)
	{		
		alert("Maximum allowed length of Description is 50 !!!")
		form.Description.select()
		form.Description.focus() 
		 
		return false	
	}	
	if(Trim(form.Priority.value).length < 1)
	{
		alert("Enter Priority")
		form.Priority.select()
		form.Priority.focus() 
		 
		return false	
	}	
	if(Trim(form.Priority.value).length > 3)
	{		
		alert("Maximum allowed length of Priority is 3 !!!")
		form.Priority.select()
		form.Priority.focus() 
		 
		return false	
	}	

	if(!checkNumeric(form.Priority))
	{
		alert("Enter only numbers of priority")
		form.Priority.select()
		form.Priority.focus() 		 
		return false	
	}
	if(Trim(form.ContactName.value).length < 1)
	{
		alert("Enter Contact Name")
		form.ContactName.select()
		form.ContactName.focus() 
		 
		return false	
	}	
	if(Trim(form.ContactName.value).length > 50)
	{		
		alert("Maximum allowed length of Contact Name is 50 !!!")
		form.ContactName.select()
		form.ContactName.focus() 
		 
		return false	
	}	
	if(Trim(form.Address.value).length < 1)
	{
		alert("Enter Address")
		form.Address.select()
		form.Address.focus() 
		 
		return false	
	}	
	if(Trim(form.Address.value).length > 200)
	{		
		alert("Maximum allowed length of Address is 200 !!!")
		form.Address.select()
		form.Address.focus() 
		 
		return false	
	}	
	if(Trim(form.City.value).length < 1)
	{
		alert("Enter City")
		form.City.select()
		form.City.focus() 
		 
		return false	
	}	
	if(Trim(form.City.value).length > 50)
	{		
		alert("Maximum allowed length of City is 50 !!!")
		form.City.select()
		form.City.focus() 
		 
		return false	
	}	
	if(Trim(form.State.value).length < 1)
	{
		alert("Enter State")
		form.State.select()
		form.State.focus() 
		 
		return false	
	}	
	if(Trim(form.State.value).length > 50)
	{		
		alert("Maximum allowed length of State is 50 !!!")
		form.State.select()
		form.State.focus() 
		 
		return false	
	}	
	if(Trim(form.Pin.value).length < 1)
	{
		alert("Enter Pin")
		form.Pin.select()
		form.Pin.focus() 
		 
		return false	
	}	
	if(Trim(form.Pin.value).length > 50)
	{		
		alert("Maximum allowed length of Pin is 50 !!!")
		form.Pin.select()
		form.Pin.focus() 
		 
		return false	
	}	
	if(Trim(form.Phone.value).length < 1)
	{
		alert("Enter Phone")
		form.Phone.select()
		form.Phone.focus() 
		 
		return false	
	}	
	if(Trim(form.Phone.value).length > 50)
	{		
		alert("Maximum allowed length of Phone is 50 !!!")
		form.Phone.select()
		form.Phone.focus() 
		 
		return false	
	}	
	if(Trim(form.Email.value).length > 50)
	{		
		alert("Maximum allowed length of Email is 50 !!!")
		form.Email.select()
		form.Email.focus() 
		 
		return false	
	}	
	if(Trim(form.Fax.value).length > 50)
	{		
		alert("Maximum allowed length of Fax is 50 !!!")
		form.Fax.select()
		form.Fax.focus() 
		 
		return false	
	}	
	if(Trim(form.BigPicture.value).length > 0)
	{
			
		if(!validateFileExtension("registration","BigPicture"))
		{
			alert("Only jpg , gif  formats are allowed")
			form.BigPicture.select()
			form.BigPicture.focus() 			
			return false
		}
	}
	
	form.submitbutton.disabled = true;
	return true;
}
function checkNumeric(objValue)
{
	 
              var charpos = objValue.value.search("[^0-9]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              {                            
                //alert("\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }
	      else
	      {
		return true;
              }
                         
           
}
function searchSpace(name)
{
	var str = name.value
	
	if( str.indexOf(" ",0) >= 0 )
	{
		alert ("Please do not use any space.");
		name.focus();
		name.select();
		return false;
	}
	else
	{return true;}
}
function LTrim(str)
{
        var whitespace = new String(" \t\n\r ");
        // last space character is not a space, but alt+0160,
        // another invisible char.
        var s = new String(str);
        if (whitespace.indexOf(s.charAt(0)) != -1) {
            // We have a string with leading blank(s)...
            var j=0, i = s.length;
            // Iterate from the far left of string until we
            // don't have any more whitespace...
            while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
                j++;
            // Get the substring from the first non-whitespace
            // character to the end of the string...
            s = s.substring(j, i);
        }
        return s;
}
// Trims all spaces to the right of a specific string
function RTrim(str)
{
        // We don't want to trip JUST spaces, but also tabs,
        // line feeds, etc.  Add anything else you want to
        // "trim" here in whitespace
        var whitespace = new String(" \t\n\r ");
        // last space character is not a space, but alt+0160,
        // another invisible char.
        var s = new String(str);
        if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
            // We have a string with trailing blank(s)...
            var i = s.length - 1;       // Get length of string
            // Iterate from the far right of string until we
            // don't have any more whitespace...
            while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
                i--;
            // Get the substring from the front of the string to
            // where the last non-whitespace character is...
            s = s.substring(0, i+1);
        }
        return s;
}
                                                                                                                        
// Trims all spaces to the left and right of a specific string by calling RTim
// and LTrim
function Trim(str)
{
        return RTrim(LTrim(str));
}
function loadPicture(picturename)
{
	
	document.getElementById("Preveiw"+picturename).src = document.getElementById(picturename).value 
	
}
function validateFileExtension(form,picturename)
{
	fileName = document.getElementById(picturename).value
	//fileName = form.Small_Picture.value
	fileName = fileName.toLowerCase()
	if( fileName!= "" )
	{
		index = fileName.length-1
		strTemp=""		
		for(i=0;i<3;i++)
		{
			strTemp = strTemp+fileName.charAt(index--)
		}
	
		if( (strTemp=="fig") || (strTemp== "gpj")|| (strTemp== "gepj"))
			return true
		else
			return false		
	}
	
}