/* $Id: nm_vehicleValidation.js,v 1.1.1.1 2010/10/06 04:45:22 parishesh Exp $ */

function checkAll(theForm)
{
	regno=theForm.regno.value;
	shwReg=theForm.show_reg.value;
	notReg=theForm.no_reg.value;

	if(isblank(theForm.car_make.value))
	{
		document.getElementById('car_make').className='highlight';
		document.getElementById('car_makeimg').className='hlightimage';
		alert(msgMandet);
		theForm.car_make.focus();
		return false;
	}

	if(isblank(theForm.car_model.value))
	{
		document.getElementById('car_model').className='highlight';
		document.getElementById('car_modelimg').className='hlightimage';
		alert(msgMandet);
		theForm.car_model.focus();
		return false;
	}

	//If any word in engine model field is longer than specified width characters long
	if(isLong(theForm.engine_model.value," ",21) == 0)
	{
		document.getElementById('engine_model').className='highlight';
		document.getElementById('engine_modelimg').className='hlightimage';
		alert(msgEngModel);
		theForm.engine_model.focus();
		return false;
	}

// 	if((isblank(regno)) && (shwReg == 'Y') && (isblank(notReg)))
// 	{
// 		document.getElementById('regno').className='highlight';
// 		document.getElementById('regnoimg').className='hlightimage';
// 		alert(msgBlankRegNo);
// 		theForm.regno.select();
// 		theForm.regno.focus();
// 		return false;
// 	}
//
// 	if((isblank(regno)) && (isblank(notReg)))
// 	{
// 		document.getElementById('regno').className='highlight';
// 		document.getElementById('regnoimg').className='hlightimage';
// 		alert(msgAboutRegNo);
// 		theForm.regno.select();
// 		theForm.regno.focus();
// 		return false;
// 	}
// 	else if(!(isblank(regno)) && !(isblank(notReg)))
// 	{
// 		document.getElementById('regno').className='highlight';
// 		document.getElementById('regnoimg').className='hlightimage';
// 		alert(msgAboutRegNo);
// 		theForm.regno.select();
// 		theForm.regno.focus();
// 		return false;
//
// 	}
// 	else if(!(isblank(regno)))
// 	{
// 		if( !(regno.match(/^([a-zA-ZАаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛлМмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯя]{1,3})([0-9]{1,3})$/)) && !(regno.match(/^([a-zA-ZАаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛлМмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯя]{1,3})-([0-9]{1,3})$/)) && !regno.match(/^([0-9]{1,3})([a-zA-ZАаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛлМмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯя]{1,3})$/) && !regno.match(/^([0-9]{1,3})-([a-zA-ZАаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛлМмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯя]{1,3})$/) && theForm.adminUser.value == "dummy")
// 		{
// 			document.getElementById('regno').className='highlight';
// 			document.getElementById('regnoimg').className='hlightimage';
// 			alert(msgInvalidRegNo);
// 			theForm.regno.select();
// 			theForm.regno.focus();
// 			return false;
// 		}
// 	}

	if(!isblank(theForm.car_price.value))
	{
		if((theForm.bestsold.checked))
		{
			document.getElementById('car_price').className='highlight';
			document.getElementById('car_priceimg').className='hlightimage';
			alert(msgInvalidEntry);
			theForm.car_price.select();
			theForm.car_price.focus();
			return false;
		}
		else
		{
			if(!(theForm.car_price.value.match(/^[0-9]{1,10}$/)) || parseInt(theForm.car_price.value) < 1)
			{
				document.getElementById('car_price').className='highlight';
				document.getElementById('car_priceimg').className='hlightimage';
				alert(msgInvalidPrice);
				theForm.car_price.select();
				theForm.car_price.focus();
				return false;
			}
			if((parseInt(theForm.car_price.value) >= 1) && (parseInt(theForm.car_price.value) <= 50))
			{
				document.getElementById('car_price').className='highlight';
				document.getElementById('car_priceimg').className='hlightimage';
				alert(msgPrice);
				theForm.car_price.select();
				theForm.car_price.focus();
				return false;
			}
		}
	}
	else
	{
		if(!theForm.bestsold.checked)
		{
			document.getElementById('car_price').className='highlight';
			document.getElementById('car_priceimg').className='hlightimage';
			alert(msgInvalidEntry);
			theForm.car_price.select();
			theForm.car_price.focus();
			return false;
		}
	}

	if(isblank(theForm.bike_year.value))
	{
		document.getElementById('bike_year').className='highlight';
		document.getElementById('bike_yearimg').className='hlightimage';
		alert(msgMandet);
		theForm.bike_year.focus();
		return false;
	}

	if(isblank(theForm.car_color.value))
	{
		document.getElementById('car_color').className='highlight';
		document.getElementById('car_colorimg').className='hlightimage';
		alert(msgMandet);
		theForm.car_color.focus();
		return false;
	}

	if(isblank(theForm.car_color_type.value))
	{
		document.getElementById('car_color').className='highlight';
		document.getElementById('car_colorimg').className='hlightimage';
		alert(msgMandet);
		theForm.car_color_type.focus();
		return false;
	}

	if(isblank(theForm.car_engine.value))
	{
		document.getElementById('car_engine').className='highlight';
		document.getElementById('car_engineimg').className='hlightimage';
		alert(msgMandet);
		theForm.car_engine.focus();
		return false;
	}

	if(isblank(theForm.eng_type.value))
	{
		document.getElementById('car_engine').className='highlight';
		document.getElementById('car_engineimg').className='hlightimage';
		alert(msgMandet);
		theForm.eng_type.focus();
		return false;
	}

	if(theForm.car_mileage.value != '')
	{
		if( isNaN(theForm.car_mileage.value) || isblank(theForm.car_mileage.value) )
		{
			document.getElementById('car_mileage').className='highlight';
			document.getElementById('car_mileageimg').className='hlightimage';
			alert(msgInvalidMileage);
			theForm.car_mileage.select();
			theForm.car_mileage.focus();
			return false;
		}

		if (parseInt(theForm.car_mileage.value) < 1)
		{
			document.getElementById('car_mileage').className='highlight';
			document.getElementById('car_mileageimg').className='hlightimage';
			alert(msgInvalidMileage);
			theForm.car_mileage.select();
			theForm.car_mileage.focus();
			return false;
		}
	}

	if(isblank(theForm.car_drive_type.value))
	{
		document.getElementById('car_drive_type').className='highlight';
		document.getElementById('car_drive_typeimg').className='hlightimage';
		alert(msgMandet);
		theForm.car_drive_type.focus();
		return false;
	}

	if(theForm.car_owner.value != '')
	{
		if(isNaN(theForm.car_owner.value) || (theForm.car_owner.value < 1) )
		{
			document.getElementById('car_owner').className='highlight';
			document.getElementById('car_ownerimg').className='hlightimage';
			alert(msgInvalidOwner);
			theForm.car_owner.select();
			theForm.car_owner.focus();
			return false;
		}
	}

	//If any word in vehicle remark field is longer than specified word lenght,
	//it will give a alert message.
	if(isLong(theForm.car_remark.value," ",40) == 0)
	{
		alert(msgLngRmrkWord);
		//theForm.car_remark.focus();
		return false;
	}

	if (theForm.userCat.value != 'D')
	{
		//Check for blank domicile field
		if(isblank(theForm.car_domicile.value))
		{
			document.getElementById('domicile').className='highlight';
			document.getElementById('domicileimg').className='hlightimage';
			alert(msgMandet);//msgBlankDom
			theForm.car_domicile.focus();
			return false;
		}

		if(isblank(theForm.bike_town.value) && theForm.car_domicile.value != 86)
		{
			document.getElementById('town').className='highlight';
			document.getElementById('townimg').className='hlightimage';
			alert(msgMandet);
			theForm.bike_town.focus();
			return false;
		}
	}

	return true;
}

function checkPurchaseDetail(theForm)
{
	if(isblank(theForm.car_make.value))
	{
		changeClass('idBikeMake','highlight');
		alert(msgMandet);
		theForm.car_make.focus();
		return false;
	}

	if(isblank(theForm.car_model.value))
	{
		changeClass('idBikeModel','highlight');
		alert(msgMandet);
		theForm.car_model.focus();
		return false;
	}

	//If any word in engine model field is longer than specified width characters long
	if(isLong(theForm.engine_model.value," ",21) == 0)
	{
		changeClass('idEngineModel','highlight');
		alert(msgEngModel);
		theForm.engine_model.focus();
		return false;
	}

	if(!(theForm.car_price.value.match(/^[0-9]{1,10}$/)) || parseInt(theForm.car_price.value) < 1)
	{
		changeClass('idBikePrice','highlight');
		alert(msgInvalidPrice);
		theForm.car_price.focus();
		return false;
	}

	if((isblank(theForm.bike_year_from.value)) || (isblank(theForm.bike_year_to.value)))
	{
		changeClass('idBikeYear','highlight');
		alert(msgMandet);
		theForm.bike_year_from.focus();
		return false;
	}

	//If any word in vehicle remark field is longer than specified word lenght,
	//it will give a alert message.
	if(isLong(theForm.car_remark.value," ",40) == 0)
	{
		changeClass('idBikeRemark','highlight');
		alert(msgLngRmrkWord);
		theForm.car_remark.focus();
		return false;
	}

	return true;
}

//Function used to change the classname of given element
function changeClass(idEle,cls)
{
	document.getElementById(idEle).className=cls;
}

//Function used when inserting sold price at marking vehicle sold
function soldCar(theForm)
{
	s=theForm.sold_price.value;

	if(s != "")
	{
		if(!(s.match(/^[0-9]{1,10}$/)))
		{
			alert(msgInvalidPrice);
			theForm.sold_price.focus();
			return false;
		}
		if (parseInt(s) < 1 )
		{
			alert(msgLessThan1Price);
			theForm.sold_price.focus();
			return false;
		}
		false;
	}
}

//This function check for word length in the string entered in the given textbox(input field)
function txtValid(theTxtbox,maxWordLen)
{
	//If any word in engine model field is longer than specified width characters long
	if(isLong(theTxtbox.value," ",maxWordLen) == 0)
	{
		alert(msgLngWordFPart + maxWordLen + msgLngWordSPart);
		theTxtbox.focus();
		return false;
	}
	else
		return true;
}

//This function works like the function 'txtValid', but used
//when there is a array of textBox(input field) elements
function txtErrayValid(theFrm,txtName,txtId,maxWordLen)
{
	for(i=0; i<theFrm.elements.length; i++)
	{
		var eleName=theFrm.elements[i].name;

		if(eleName.match(txtName) != null)
		{
			if(eleName.match(txtId) != null)
			{
				if(isLong(theFrm.elements[i].value," ",maxWordLen) == 0)
				{
					alert(msgLngWordFPart + maxWordLen + msgLngWordSPart);
					theFrm.elements[i].focus();
					return false;
					break;
				}
				else
				{
					return true;
					break;
				}
			}
		}
	}
	return false;
}

