// This method is Used in Simple Search and Vehicle Post forms.
var textureName='';
var optChar='';
var optGroup='';
var textureGroup='';
var make_opt='';


// validate post car
function validatePostCar(target,PokeYoke)
{
		if($("first_reg_month").value != "" || $("first_reg_year").value != "")
		{
			if(target.name == "first_reg_year" && target.value == "")
			{
				PokeYoke.renderInlineError(target,msg_select_first_reg_year);
				$(target.name).addClassName('error_box');
				target.focus();
				return false;
			}

			if(target.name == "first_reg_month" && target.value == "")
			{
				PokeYoke.renderInlineError(target, msg_select_first_reg_month);
				$(target.name).addClassName('error_box');
				target.focus();
				return false;
			}
		}

	  if(target.name == "price_ask" && target.value != "")
		{
			if(!(target.value.match(/^[0-9]{1,10}$/)) || parseInt(target.value) < 1)
			{
				PokeYoke.renderInlineError(target, msg_invalid_price);
				$(target.name).addClassName('error_box');
				target.focus();
				return false;
			}

			if((parseInt(target.value) >= 1) && (parseInt(target.value) <= 50))
			{
				PokeYoke.renderInlineError(target, msg_too_low_price);
				$(target.name).addClassName('error_box');
				target.focus();
				return false;
			}
		}
		else if(target.name == "price_ask")
		{
			if(!$("bestsold").checked)
			{
				PokeYoke.renderInlineError(target, msg_select_price_or_not_priced);
				$(target.name).addClassName('error_box');
				target.focus();
				return false;
			}
		}

		if($("vehicle_type").value != 13)
		{
		  if(target.name == "power" && target.value != "")
			{
				if(target.value.match(/,/))
					var powerValue = target.value.replace(",",".");
				else
					var powerValue = target.value;

				if(!(powerValue.match(/^([0-9]{1,10})([0-9.]{0,1}|[0-9,]{0,1})([0-9]{1,4}|)$/)) || parseInt(powerValue) <= 0 || parseFloat(powerValue) > 700)
				{
					PokeYoke.renderInlineError(target, msg_invalid_power);
					$(target.name).addClassName('error_box');
					target.focus();
					return false;
				}
			}


		  if(target.name == 'co2_emission' && target.value != '')
			{

				if(target.value.match(/,/))
					var co2emission= target.value.replace(',',".");
				else
			 		var co2emission=target.value;


				if(!(co2emission.match(/^([0-9]{1,10})([0-9.]{0,1}|[0-9,]{0,1})([0-9]{1,4}|)$/)) || parseInt(co2emission) <= 0 || parseFloat(co2emission) > 500)
				{
					PokeYoke.renderInlineError(target, msg_invalid_emission);
					$(target.name).addClassName('error_box');
					target.focus();
					return false;
				}
			}


		  if(target.name == 'top_speed' && target.value != '')
			{

				if(target.value.match(/,/))
					var topSpeed= target.value.replace(',',".");
				else
			 		var topSpeed=target.value;


					if(!(topSpeed.match(/^([0-9]{1,10})([0-9.]{0,1}|[0-9,]{0,1})([0-9]{1,4}|)$/)))
					{
						PokeYoke.renderInlineError(target, msg_invalid_top_speed);
						$(target.name).addClassName('error_box');
						target.focus();
						return false;
					}
			}

		  if(target.name == 'acceleration' && target.value != '')
			{

				if(target.value.match(/,/))
					var acceleration= target.value.replace(',',".");
				else
			 		var acceleration=target.value;

				if(!(acceleration.match(/^([0-9]{1,10})([0-9.]{0,1}|[0-9,]{0,1})([0-9]{1,4}|)$/)) || parseInt(acceleration) <= 0 || parseFloat(acceleration) > 100)
					{
						PokeYoke.renderInlineError(target, msg_invalid_acceleration);
						$(target.name).addClassName('error_box');
						target.focus();
						return false;
					}
			}

		  if(target.name == 'consumption1' && target.value != '')
			{

				if(target.value.match(/,/))
					var consumption1= target.value.replace(',',".");
				else
			 		var consumption1=target.value;

					if(!(consumption1.match(/^([0-9]{1,10})([0-9.]{0,1}|[0-9,]{0,1})([0-9]{1,4}|)$/)))
					{
						PokeYoke.renderInlineError(target, msg_invalid_consumption1);
						$(target.name).addClassName('error_box');
						target.focus();
						return false;
					}
			}

		  if(target.name == 'consumption2' && target.value != '')
			{

				if(target.value.match(/,/))
					var consumption2= target.value.replace(',',".");
				else
			 		var consumption2=target.value;

					if(!(consumption2.match(/^([0-9]{1,10})([0-9.]{0,1}|[0-9,]{0,1})([0-9]{1,4}|)$/)))
					{
						PokeYoke.renderInlineError(target, msg_invalid_consumption2);
						$(target.name).addClassName('error_box');
						target.focus();
						return false;
					}
			}

		  if(target.name == 'consumption3' && target.value != '')
			{

				if(target.value.match(/,/))
					var consumption3= target.value.replace(',',".");
				else
			 		var consumption3=target.value;


					if(!(consumption3.match(/^([0-9]{1,10})([0-9.]{0,1}|[0-9,]{0,1})([0-9]{1,4}|)$/)))
					{
						PokeYoke.renderInlineError(target, msg_invalid_consumption3);
						$(target.name).addClassName('error_box');
						target.focus();
						return false;
					}
			}
		}

		if($("vehicle_type").value != 13)
		{
		  if(target.name == 'engine_size' && target.value == '')
			{
				PokeYoke.renderInlineError(target, msg_engine_size_cannot_be_blank);
				$(target.name).addClassName('error_box');
				target.focus();
				return false;
			}

			if(target.name == 'mileage' && target.value != "")
			{
				if(!(target.value.match(/^[0-9]{0,10}$/)))
				{
					PokeYoke.renderInlineError(target, msg_mileage_must_be_number);
					$(target.name).addClassName('error_box');
					target.focus();
					return false;
				}
			}

			if(target.name == 'id_drive_type' && target.value == "")
			{
					PokeYoke.renderInlineError(target, msg_drive_type_cannot_be_blank);
					$(target.name).addClassName('error_box');
					target.focus();
					return false;
			}

			if(target.name == 'fuel_type' && target.value == "")
			{
					PokeYoke.renderInlineError(target, msg_fuel_type_cannot_be_blank);
					$(target.name).addClassName('error_box');
					target.focus();
					return false;
			}
		}

		if((target.name == 'mot_new' && ($("mot_new").checked) && ($("mot_month").value != 0 || $("mot_year").value != 0)))
		{
				PokeYoke.renderInlineError(target, msg_InvalidTooNew);
				$(target.name).addClassName('error_box');
				target.focus();
				return false;
		}

		if((target.name == 'mot_new' && (!$("mot_new").checked) && (($("mot_month").value == 0 && $("mot_year").value != 0) || ($("mot_month").value != 0 && $("mot_year").value == 0))))
		{
			PokeYoke.renderInlineError(target, msg_InvalidMOT);
			$(target.name).addClassName('error_box');
			target.focus();
			return false;
		}
		if(target.name == "id_domicile" && $("user_cat").value != 'D')
		{
			if(target.value == "")
			{
				PokeYoke.renderInlineError(target,msg_domicile_cannot_be_blank);
				$(target.name).addClassName('error_box');
				target.focus();
				return false;
			}
		}

		if(target.name == "id_town" && $("user_cat").value != 'D')
		{
			town_flag=0;
			if(country_code == 'af' && $("id_domicile").value != 4)
				town_flag=1;
			else if(country_code != 'af' && $("id_domicile").value != 22)
				town_flag=1;

			if(town_flag == 1)
			{
				if(target.value == "")
				{
					PokeYoke.renderInlineError(target, msg_town_cannot_be_blank);
					$(target.name).addClassName('error_box');
					target.focus();
					return false;
				}
			}
		}

		$(target.name).removeClassName('error_box');
		PokeYoke.removeErrors( target );
		return true;
	}


function vehicleTypeChange(v1,v2,curval,cond,v3)
{
	var vehicleid='';
	var bflag=1;

	// If browser is IE but version is not 6.0 then flag will be false
	if(navigator.appVersion.indexOf('MSIE') != -1 && navigator.appVersion.indexOf('MSIE 6.0') == -1)
		bflag=0;
	if(navigator.appName == 'Netscape' && !(parseFloat(navigator.appVersion) >= 4.8))
		bflag=0;

	if(isNaN(curval))
		var id_make='';
	else
		var id_make=curval;

	// While posting, if vehicle type is changed change Make and Model as well
	if(cond == 'POST' && v3.length > 0)
		v3.length=1;
	else if(cond == 'Y') // Simple Search
		v3.length=1;

	if(v1)
	{
		if(v1.length)
		{
			if(v1.selectedIndex > -1)
				var vehicleid=new String(v1.options[v1.selectedIndex].value);
			else
				var vehicleid='';
		}
		else
			var vehicleid=v1;
	}
	textureName='';

	if(vehicleid != '') 	// Vehicle Type is selected
	{
		if(cond == 'Y' || (v2.length > 0 && v2.options[0].value == ''))
		{
			v2.length=1;
			var j=1;
		}
		else 				// Posting Vehicle
		{
			v2.length=1;
			var j=1;
		}
		if(v2.length != 0)
        	v2.selectedIndex=0;

		for(i=0; i < e[vehicleid].length; i++)
	    {
			var make_value=new String(e[vehicleid][i]);
			var make_text=new String(f[vehicleid][i]);

			if(cond == 'POST' || a[make_value] > 0) 	// Posting Vehicle && Simple Search
			{
				// Changes has been made for displaying makes in option group wise.
				// i.e. Starting with char A will listed below A Group, same as for B to Z.
				if(make_text.match(/^[A-Za-z]{1}/) && (!(navigator.userAgent.match(/Opera/))) && bflag == 1)
				{
					optChar='';
					optChar=make_text.substr(0,1);
					optGroup='T';

					if(textureName != optChar)
					{
						textureName=optChar;
						textureGroup=document.createElement('optgroup');
						textureGroup.label=textureName;
						v2.appendChild(textureGroup);
					}
				}
				else
					optGroup='F';

				if(optGroup != 'F' && textureName != '')
				{
					make_opt=document.createElement('option');
					make_opt.value=make_value;

					if(navigator.userAgent.match(/IE/))
						make_opt.innerText=make_text;
					else
						make_opt.text=make_text;

					textureGroup.appendChild(make_opt);
				}
				else
				{
					makeOpt=new Option(make_text,make_value);
					eval('v2.options[j]=makeOpt');
				}

				// Option group part ends here
				if(id_make == make_value)
					v2.selectedIndex=j;

				j++;
			}
	    }
		if(v2.selectedIndex == ''  || v2.selectedIndex < 1)
			v2.selectedIndex=0;

		if(cond == 'POST' && v2.length > 0) // Posting Vehicle
			makeChange(v2,v3,'','',v1);
	}
	else
	{
		// When Vehicle Type is not selected (Simple Search)
		v2.length=1;
		var j=1;

		for(z=0; z < u.length; z++)
		{
			if(a[u[z]] > 0 || cond == 'ADV')
			{
				var make_value=new String(u[z]);
				var make_text=new String(b[u[z]]);

				// Changes has been made for displaying makes in option group wise.
				// i.e. Starting with char A will listed below A Group, same as for B to Z.
				if(make_text.match(/^[A-Za-z]{1}/) && (!(navigator.userAgent.match(/Opera/))) && bflag == 1)
				{
					optChar='';
					optChar=make_text.substr(0,1);
					optGroup='T';

					if(textureName != optChar)
					{
						textureName=optChar;
						textureGroup=document.createElement('optgroup');
						textureGroup.label=textureName;
						v2.appendChild(textureGroup);
					}
				}
				else
					optGroup='F';

				if(optGroup != 'F' && textureName != '')
				{
					make_opt=document.createElement('option');
					make_opt.value=make_value;

					if(navigator.userAgent.match(/IE/))
						make_opt.innerText=make_text;
					else
						make_opt.text=make_text;

					textureGroup.appendChild(make_opt);
				}
				else
				{
					makeOpt=new Option(make_text,make_value);
					eval('v2.options[j]=makeOpt');
				}

				// Option group part ends here
				if(id_make == u[z])
					v2.selectedIndex=j;

				j++;
			}
		}
	}
}

// Used in Simple Search, Advance Search and Vehicle Post forms.
function makeChange(v1,v2,curval,cond,v3)
{
	var vehicleid='';

	if(isNaN(curval))
		var id_model='';
	else
		var id_model=curval;

	if(v1.selectedIndex > -1)
		var makeid=new String(v1.options[v1.selectedIndex].value)
	else
		var makeid='';

	if(v3)
	{
		if(v3.length)
		{
			if(v3.selectedIndex > -1)
				var vehicleid=new String(v3.options[v3.selectedIndex].value)
			else
				var vehicleid='';
		}
		else
			var vehicleid=v3;
	}
	if(makeid != '')
	{
		if(cond == 'Y' || (v2.length > 0 && v2.options[0].value == ''))
		{
			v2.length=1;
			var j=1;
		}
		else	// Posting Vehicle
		{
			v2.length=0;
			var j=0;
		}
		if(cond == 'ADV')
 		{
 			// Remove first element which is just blank
 			v2.length=0;
 			var j=0;
 		}
		if(v2.length != 0)
        	v2.selectedIndex=0;

		if(cond == 'ADV')
		{
			if(m[makeid].length > 0)
			{
				var make_value=v1.options[v1.selectedIndex].value+'#'+v1.options[v1.selectedIndex].text;
				var make_text=v1.options[v1.selectedIndex].text+': '+anyModel;

				modelOpt=new Option(make_text,make_value);
				eval('v2.options[j++]=modelOpt');
			}
		}
	    for(i=0; i < m[makeid].length; i++)
	    {
			var model_value=new String(m[makeid][i]);
	    var model_text=d[model_value];
			var goFlag=0;

			// Simple Search
			if(cond == 'Y')
			{
				if(vehicleid != '')
				{
					// When Vehicle Type is also selected then get models for that Vehicle Type only
					if(l[model_value][vehicleid] > 0)
						goFlag=1;
				}
				else
				{
					if(l[model_value][0] > 0)
						goFlag=1;
				}
			}
			else
			{
				if(cond == 'ADV')
					goFlag=1;
				else if(vehicleid != '')
				{
					// Vehicle Posting
					if (l[model_value][vehicleid] >= 0)
						goFlag=1;
				}
				else	// Admin -> Normal Vehicle Search (Without Vehicle Type)
					goFlag=1;
			}
			if(goFlag == 1)
			{
				modelOpt=new Option(model_text,model_value);
				eval('v2.options[j]=modelOpt');

				if(id_model == model_value)
					v2.selectedIndex=j;

				j++;
			}

	    }
		if(cond != 'ADV')
		{
			if(v2.selectedIndex == ''  || v2.selectedIndex < 1)
				v2.selectedIndex=0;
		}
	}
	else
	{
		v2.length=1;
		var j=1;

		if(cond == 'ADV')
		{
			selOpt=new Option('                                          ','');
			eval('v2.options[0]=selOpt');
		}
	}
}

// Select DriveType using Selected Model
function modelChange(vehicleType, vmodel, driveType, selectedDType)
{
	driveType.length=0;

	if(vehicleType[vehicleType.selectedIndex].value != 13)
	{
		if(vmodel.selectedIndex != 0)
		{
			str=new String(t[vmodel[vmodel.selectedIndex].value])
			arrd=str.split(",");

			for(i=0; i < arrd.length; i++)
			{
				var disp=dv[arrd[i]-1];
				var val=dk[arrd[i]-1];

				selOpt=new Option(disp,val);
				eval('driveType.options[i]=selOpt');

				if(selectedDType == val)
					driveType.selectedIndex=i;
			}
		}
	}
}

// Change subType according to Vehicle Type
function subTypeChange(vtype,subtype,curval,page)
{
	if(vtype)
	{
		if(vtype.length)
		{
			if(vtype.selectedIndex > -1)
				var vehicleid=new String(vtype.options[vtype.selectedIndex].value);
			else
				var vehicleid='';
		}
		else
			var vehicleid=vtype;
	}
	if(page == 'POST')
	{
		subtype.length=1;
		j=1;
	}
	else
	{
		subtype.length=1;
		j=1;
	}
	if(vehicleid != '')
	{
		if(sid[vehicleid])
		{
			for(i=0; i < sid[vehicleid].length; i++)
		    {
				var svalue=new String(sid[vehicleid][i]);
				var stext=new String(stype[vehicleid][i]);

				sOpt=new Option(stext,svalue);
				eval('subtype.options[j]=sOpt');

				if(sid[vehicleid][i] == curval)
					subtype.selectedIndex=j;

				j++;
			}
		}
	}
	else
	{
		// When Vehicle Type is not selected (Simple Search)
		var lstSubType='';

	  for(z=0; z < vtype.length; z++)
		{
			if(sid[vtype.options[z].value])
			{
				for(i=0; i < sid[vtype.options[z].value].length; i++)
				{
					var svalue=new String(sid[vtype.options[z].value][i]);
					if((lstSubType.search('#'+svalue+'#')) == -1)
          {
						var stext=new String(stype[vtype.options[z].value][i]);

						sOpt=new Option(stext,svalue);
						eval('subtype.options[j]=sOpt');

						if(curval == svalue)
							subtype.selectedIndex=j;

						j++;
						lstSubType = lstSubType+'#'+svalue+'#,';
          }
				}
			}
		}
	}
}

// Function to change year list box options
function yearChange(v1,v2,curval)
{
	var tot=v1.selectedIndex+1;

	if(tot == 1)
		tot=v1.options.length-1;

	if(curval == '' && v2.selectedIndex > 0)
		curval=v2.options[v2.selectedIndex].value;

	v2.length=1;

	for(i=1,j=1; i<tot; j++,i++)
	{
		temp=new Option(v1.options[i].value,v1.options[i].value);
		eval('v2.options[j]=temp');

		if(curval == v1.options[i].value)
			v2.selectedIndex=j;
	}
}

// Function to change price list box options
// sign argument is to display sign after the text
function priceChange(v1,v2,curval,sign,sep)
{
	if(v1.selectedIndex < 1)
		var st=1;
	else
		var st=v1.selectedIndex;

	var tot=v1.length;
	v2.length=1;

	for(i=st,j=1; i < tot; j++,i++)
	{
		if(parseInt(v1.options[i].value) >= 1000)
		{
			var len=v1.options[i].value.length;
			var disp=v1.options[i].value;
			var disp1=disp.substr(0,len-3);
			var disp2=disp.substr(len-3,len);

			disp=disp1+sep+disp2+' '+sign;
		}
		else
			var disp=v1.options[i].value+' '+sign;

		temp=new Option(disp,v1.options[i].value);
		eval('v2.options[j]=temp');

		if(curval == v1.options[i].value)
			v2.selectedIndex=j;
	}
}

// Function to change mileage list box options
function mileageChange(v1,v2,curval)
{
	if(v1.selectedIndex < 1)
		var st=1;
	else
		var st=v1.selectedIndex;

	var tot=v1.length;
	v2.length=1;

	for(i=st,j=1; i < tot; j++,i++)
	{
		temp=new Option(v1.options[i].value,v1.options[i].value);
		eval('v2.options[j]=temp');

		if(curval == v1.options[i].value)
			v2.selectedIndex=j;
	}
}

// Function to change engine size list box options
function engineChange(v1,v2,curval)
{
	if(v1.selectedIndex < 1)
		var st=1;
	else
		var st=v1.selectedIndex;

	var tot=v1.length;
	v2.length=1;

	for(i=st,j=1; i < tot; j++,i++)
	{
		temp=new Option(v1.options[i].value,v1.options[i].value);
		eval('v2.options[j]=temp');

		if(curval == v1.options[i].value)
			v2.selectedIndex=j;
	}
}

//Function to change the Length,Power and Price list box options
function listboxChange(v1,v2,curval,sign)
{
	if(v1.selectedIndex < 1)
		var st=1;
	else
		var st=v1.selectedIndex;

	if(curval == '' && v2.selectedIndex > 0)
		curval=v2.options[v2.selectedIndex].value;

	var tot=v1.length;
	v2.length=1;

	for(i=st,j=1; i < tot; j++,i++)
	{
		if (parseInt(v1.options[i].value) >= 1000)
		{
			var len=v1.options[i].value.length;
			var disp=v1.options[i].value;
			var disp1=disp.substr(0,len-3);
			var disp2=disp.substr(len-3,len);
			disp=disp1+' '+disp2;
		}
		else
			var disp=v1.options[i].value;

		if(sign != '')
			disp=disp+' '+sign;

		temp=new Option(disp,v1.options[i].value);
		eval("v2.options[j]=temp");

		if(curval == v1.options[i].value)
			v2.selectedIndex=j;
	}
}

// Function which checks whether given email is valid or not
function emailInvalid(s)
{
	if(s.match(/^\w+([\.\+]?[-]{0,2}\w+)*[\.]?@\w+([\.-]?\w+)*(\.\w{2,4})+$/i))
		return true;
	else
		return false;
}

// Function which checks whether given url address is valid or not
function urlInvalid(s)
{
	if(!(s.match(/^http:\/\/[a-zA-Z0-9]+([_|\.-][a-zA-Z0-9~-]{1,})*\.([a-z]{2,4})(\/[a-zA-Z0-9~-]{1,}[_|\.]{0,1}[a-zA-Z0-9~]{1,}\/?)*([_|\.][a-zA-Z0-9~-]{1,})*$/i) || s.match(/^ftp:\/\/[a-zA-Z0-9]+([_|\.][a-zA-Z0-9~-]{1,})*\.([a-z]{2,4})(\/[a-zA-Z0-9~-]{1,}[_|\.]{0,1}[a-zA-Z0-9~]{1,}\/?)*([_|\.][a-zA-Z0-9~]{1,})*$/i)))
		return false;
	else
		return true;
}

// Function to open new pop up window with fixed size
function openWin(win_nm,nm)
{
	var h=screen.height;
	h=h-80;

	var myfeatures='directories=no,location=no,menubar=no,status=yes,titlebar=no,toolbar=no,resizable=yes,scrollbars=yes,width=730,height='+h+',left=0,top=0';

	if(nm == '')
		nm='new';

	var newImg=window.open(win_nm,nm,myfeatures);
	newImg.focus();
}

function openNewWin(win_nm,w,h,nm)
{
	var myfeatures='directories=no,location=no,menubar=no,status=yes,titlebar=no,toolbar=no,resizable=no,scrollbars=no,width='+w+',height='+h+',left=0,top=0';

	if(nm == '')
		nm='new';

	var newImg=window.open(win_nm,nm,myfeatures);
	newImg.focus();
}

// Function opens window of desired size by giving proper alert window
function doLogin(msgVar,width,height)
{
	openImg('msgWin.php?opt='+msgVar,width,height,'newuser');
}


// This function is used to switch between imaeg and text version
// It used toggling method, hence if Image is set then set Text and vice versa
function switchVersion()
{
	if(Get_Cookie('imgCook') == 'T')
		Set_Cookie('imgCook','');
	else
		Set_Cookie('imgCook','T','Fri, 01-Dec-2050 00:00:01 GMT');

	window.location.reload();
}

// Function to suhmit favorite page by adding/removing vehicles
function submitFav(thisV)
{
	var flag='N';

	for(i=1; i < document.fav.length; i++)
	{
		if(document.fav.elements[i].type == 'checkbox')
		{
			if(document.fav.elements[i].checked)
			{
				flag='Y';
				continue;
			}
		}
	}
	if(flag != 'Y')
	{
		alert(msgSelectAtLeastOne);
		return false;
	}
	if(thisV == 'remove')
		document.fav.opt.value='Rem';
	else
		document.fav.opt.value='Fav';

	document.fav.submit();
}

// Function to check whether given string is really empty or not
function isblank(s)
{
	for(var i=0; i < s.length; i++)
	{
		var c=s.charAt(i);

		if((c != ' ') && (c != "\n") && (c != "\t"))
			return false;
	}
	return true;
}

// Sort displaying vehicle list page according to specified arguments.
function sortForm(col,ord)
{
	document.sortl.sortCol.value=col;
	document.sortl.ord.value=ord;
	document.sortl.submit();
}

// To popup message while removing single records
function confirmDel(ref)
{
	if(confirm(msgDeleteConfirm))
		window.location.replace(ref);
}

// To popup message while removing multiple records
function confirmMultiDel(act,frm)
{
	if(confirm(msgDeleteConfirm))
	{
		if(act != '')
			eval('document.'+frm+'.action=\''+act+'\'');

		eval('document.'+frm+'.submit()');
	}
}

// Function to add selected values from 'Model' fields
// into 'Selected models' field, used in Advanced search page
function addModel(v1,v2)
{
	if(!(v1.all_model.selectedIndex >= 0))
		return;

	if(v1.all_model[v1.all_model.selectedIndex].value != '')
	{
		if(v2.options[0].value == '')
			document.adv.sel_model.length--;

		if(v2.selectedIndex == 1)
			v2.selectedIndex=0;

		var tot=v2.length;
		var dup=0;

		for(o=0; o < tot; o++)
		{
			var tmpValue2=v2.options[o].value;
			var tmpValue=v1.all_model[v1.all_model.selectedIndex].value;

			if(tmpValue == tmpValue2)
			{
				dup=1;
				alert(msgDupSelected);
			}
			else if(tmpValue.match(/^([0-9]{1,})$/i) && tmpValue2.match(/^([0-9]{1,})#/i))
			{
				var makeid=tmpValue2.substr(0,tmpValue2.indexOf('#'));
				var make=tmpValue2.substr(tmpValue2.indexOf('#')+1,tmpValue2.length);

	    		for(i=0; i < m[makeid].length; i++)
	    		{
					var model_value=new String(m[makeid][i]);

					if(tmpValue == model_value)
					{
						dup=1;
						alert(makeAllSelected);
					}
				}
			}
			else if(tmpValue.match(/^([0-9]{1,})#/i))
			{
				var makeid=tmpValue.substr(0,tmpValue.indexOf('#'));
				var make=tmpValue.substr(tmpValue.indexOf('#')+1,tmpValue.length);

	    		for(i=0; i < m[makeid].length; i++)
	    		{
					var model_value=new String(m[makeid][i]);

					for(h=0; h < tot; h++)
					{
						var v2Value=v2.options[h].value;

						if(v2Value == model_value)
						{
							var j=0;

							for(var r=h; r<tot;r++)
							{
								j=r+1;

								if(j > (tot-1))
									j=tot-1;

								var disp=v2.options[j].text;
								var val=v2.options[j].value;

								selOpt=new Option(disp,val);
								eval('v2.options[r]=selOpt');
							}
							v2.length=tot-1;
							tot=v2.length;
						}
					}
				}
			}
		}
		if(dup != 1)
		{
			if((v1.all_model[v1.all_model.selectedIndex].value).match(/^([0-9]{1,})#/i) )
				selOpt=new Option(v1.all_model[v1.all_model.selectedIndex].text,v1.all_model[v1.all_model.selectedIndex].value);
			else
			{
				str1=v1.all_model[0].text;
				selOpt=new Option(str1.slice(0,str1.indexOf(":"))+'-'+v1.all_model[v1.all_model.selectedIndex].text,v1.all_model[v1.all_model.selectedIndex].value);
			}

			eval('v2.options[tot]=selOpt');
		}
	}
}

function removeModel(v1)
{
	var p=v1.sel_model.selectedIndex;
	var j=0;
	var tot=v1.sel_model.options.length;

	if(tot > p)
	{
		for(i=p; i <= tot; i++)
		{
			j=i+1;

			if(j > (tot-1))
				j=tot-1;

			var disp=v1.sel_model[j].text;
			var val=v1.sel_model[j].value;

			selOpt=new Option(disp,val);
			eval('v1.sel_model.options[i]=selOpt');
		}
	}
	v1.sel_model.length=tot-1;

	// If no option is there then add "any" as default
	if(v1.sel_model.options.length == 0)
	{
		selOpt=new Option('                                                      ','');
		eval('v1.sel_model.options[0]=selOpt');
	}
}

// This function check only alfa numeric value not allowed special characters
function checkAlfaNumeric(s)
{
	if(!isblank(s))
	{
		if(!s.match(/^[a-zA-Z0-9Ã„Ã¤Ã•ÃµÃ…Ã¥Ã–Ã¶Å Å¡ÃœÃ¼Å½Å¾ÐÐ°Ð‘Ð±Ð’Ð²Ð“Ð³Ð”Ð´Ð•ÐµÐÑ‘Ð–Ð¶Ð—Ð·Ð˜Ð¸Ð™Ð¹ÐšÐºÐ›Ð»ÐœÐ¼ÐÐ½ÐžÐ¾ÐŸÐ¿Ð Ñ€Ð¡ÑÐ¢Ñ‚Ð£ÑƒÐ¤Ñ„Ð¥Ñ…Ð¦Ñ†Ð§Ñ‡Ð¨ÑˆÐ©Ñ‰ÐªÑŠÐ«Ñ‹Ð¬ÑŒÐ­ÑÐ®ÑŽÐ¯Ñ]*$/))
			return false;
		else
			return true;
	}
}

// Function to swap image (used in Map etc.)
function swapImage(imgname,path,carid,imageid)
{
	carid.value=imageid;
	imgname.src=path;
}

// Function to change full image of VIF etc.
function loadImage(newimg,currentImgValue,id_ad,seo_str)
{
	document.getElementById('fullimg').alt=seo_str;
	document.getElementById('fullimg').title=seo_str;
	document.getElementById('fullimg').src=newimg;
}

function loadZoomImage(newimg,img_width,lImg_idNo,tot_image,commonImageUrl,seo_str)
{
    //document.getElementById('fullimg').src=newimg;

    if(tot_image > 0)
    {
        for(j=1; j<=tot_image; j++)
        {
            if(document.getElementById('zoom_'+j))
            {
           		  document.getElementById('zoom_'+j).innerHTML='';
                document.getElementById('zoom_image_icon').style.display='block';

            }

            if(document.getElementById('fullimg_'+j))
            {
                document.getElementById('fullimg_'+j).innerHTML='';
             	  document.getElementById('zoom_large_img').style.display ='block';
            }
        }

        if(document.getElementById('fullimg_'+lImg_idNo))
      		document.getElementById('fullimg_'+lImg_idNo).innerHTML= '<img src="'+newimg+'" alt="'+seo_str+'" title="'+seo_str+'" border="0">';

        if(document.getElementById('zoom_'+lImg_idNo))
            document.getElementById('zoom_'+lImg_idNo).innerHTML='<img style="cursor:pointer;" class="img png" src="'+commonImageUrl+'/zoom_modal_icon.png" width="24" height="24" alt="" title="" border="0"/>';
    }
    if(img_width)
    {
        document.getElementById('zoom_image_icon').style.width=img_width+'px';
    }
}




// To check login sesion of user in VIF while sumbitting question or giving answer,
// if user is not logged in a popup window opens where he can log in
function checkQue(url,file,msg)
{
	if(file.id_user.value == '')
	{
		openImg(url,350,320,'na_login');

		return false;
	}
	var flag='N';

	for(i=0; i < file.elements.length;i++)
	{
		if(file.elements[i].type == 'text')
		{
			if(!isblank(file.elements[i].value))
				flag='Y';
		}
	}
	if(flag == 'N')
	{
		alert(msg);
		return false;
	}

	return true;
}

// Function to check phone,fax,mobile for finland country
function check(s)
{
	if(!s.match(/^[0-9\s\+-]{5,25}$/) )
		return false;
	else
		return true;
}

// Function to check loginid string, various rules are followed
function checkLogin(s)
{
	if(!(s.match(/^[a-zA-Z0-9ÄäÕõÅåÖöŠšÜüŽžАаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛлМмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯяÁÀÉÈÒÓÙÚáàèéòóùúÝìíýÌÍ´_]{4,12}$/)))
		return msgUserid;
	else
	{
		s=s.toLowerCase();

		if(s == 'admin' || s == 'webmaster' || s == 'help' || s == 'helpdesk' || s == 'netiauto' || s == 'user' || s == 'dealer' || s == 'dummy')
			return msgResdId;
	}
	return 1;
}


// Function to check Password string, various rules are followed
function checkPasswd(s)
{
	if(s.match(/^[a-zA-Z0-9ÄäÕõÅåÖöŠšÜüŽžАаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛлМмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯяÁÀÉÈÒÓÙÚáàèéòóùúÝìíýÌÍ´_.-]{4,12}$/))
		return true;

	return false;
}


// Function to check characters length of word
function isLong(value,sep,len)
{
	if(value == '')
		return true;
	else
	{
		tempValue=value.split(sep);

		for(var i=0; i < tempValue.length; i++)
		{
			if(tempValue[i].length > len)
			{
				return 0;
				break;
			}
		}
	}
}

// Function to check SSN number validation in Finland country
function checkSsn(p)
{
    lChar=new Array('A','B','C','D','E','F','H','J','K','L','M','N','P','R','S','T','U','V','W','X','Y','Z');

	if(!(p.match(/^[0-9]{6}-[0-9]{3}[0-9a-zA-Z]{1}$/)))
		return false;
	else
    {
		ssn=p.replace('-','');
		first=ssn.substr(0,9);
		start1=ssn.substr(0,6);
		middle=ssn.substr(6,3);
		last=ssn.substr(9,1);
		remin=(first % 31);

		if(remin >= 0 && remin <= 9)
			rightChar=remin;
		else
			rightChar=lChar[remin-10];

		rightSSN=start1+'-'+middle+rightChar;

		if(rightSSN == p)
			return true;
		else
			return false;
	}
	return false;
}

// Function to get stored cookie
function Get_Cookie(cookname)
{
    var start=document.cookie.indexOf(cookname+'=');
    var len=start+cookname.length+1;

    if((!start) && (cookname != document.cookie.substring(0,cookname.length)))
    	return null;

    if(start == -1)
    	return null;

    var end=document.cookie.indexOf(';',len);

    if(end == -1)
    	end=document.cookie.length;

    return unescape(document.cookie.substring(len,end));
}

// Function to set new cookie
function Set_Cookie(cookname,cookvalue,expires,path,cookdomain,secure)
{
    document.cookie=cookname+'='+escape(cookvalue)+((expires)?';expires='+expires:'')+((path)?';path='+path:'')+((cookdomain)?';domain='+cookdomain:'')+((secure)?';secure':'');
}

// Function to delete cookie
function Delete_Cookie(cookname,path,cookdomain)
{
    if(Get_Cookie(cookname))
    	document.cookie=cookname+'='+((path)?';path='+path:'')+((cookdomain)?';domain='+cookdomain:'')+';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}

// Function to return nothing, this is used sometimes
// to display tool tip on plain text by making trick
function returnVoid() {}

// Function to check the alphanumeric characters.
function checkAlphaNumeric(s)
{
	if(!s.match(/^[0-9a-zA-ZÄäÕõÅåÖöŠšÜüŽžАаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛлМмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯяÁÀÉÈÒÓÙÚáàèéòóùúÝìíýÌÍ´\s-]{1,100}$/))
		return false;
	else
		return true;
}

// Function to check First-Last name values when it is entered as full name
function checkFullName(s)
{
	if(!s.match(/^[a-zA-ZÄäÕõÅåÖöŠšÜüŽžАаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛлМмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯяÁÀÉÈÒÓÙÚáàèéòóùúÝìíýÌÍ´_\s-]{1,50}$/))
		return false;
	else
		return true;
}


// Function to check First-Last name values
function checkName(s)
{
	if(!s.match(/^[a-zA-ZÄäÕõÅåÖöŠšÜüŽžАаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛлМмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯяé´ÁÀÉÈÒÓÙÚáàèéòóùúÝìíýÌÍ-]{1,30}$/))
		return false;
	else
		return true;
}

// Function to check address/contact time values
function checkAddContTime(s)
{
	if(!s.match(/^[0-9a-zA-ZÄäÕõÅåÖöŠšÜüŽžАаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛлМмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯяÁÀÉÈÒÓÙÚáàèéòóùúÝìíýÌÍ_´:()\s\,'.!-]{1,250}$/))
		return false;
	else
		return true;
}

// Function to check city values
function checkCity(s)
{
	if(!s.match(/^[0-9a-zA-ZÄäÕõÅåÖöŠšÜüŽžАаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛлМмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯяÁÀÉÈÒÓÙÚáàèéòóùúÝìíýÌÍ_´:\s\,-]{1,250}$/))
		return false;
	else
		return true;
}

function RemoveGroups(selectId)
{
	var lChars=new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');

	for(var chr=0; chr < lChars.length; chr++)
	{
		RemoveGroup(lChars[chr],selectId);
	}
}
function RemoveGroup(groupLabel,selectId)
{
	try
	{
		var selectList=document.getElementById(selectId);
		var eachGroup=selectList.firstChild;

		while(groupLabel != eachGroup.label)
		{
			eachGroup=eachGroup.nextSibling;
		}
		selectList.removeChild(eachGroup);
	}
	catch(er){}
}

//Function to give the user a message to login to the site, when he tries
//to access the feature which is only for registered memeber.
function loginWarning(msgWar,curTxt)
{
	if(!isblank(curTxt))
	{
		alert(msgWar);
	}
}
function confirmReset(msg)
{
	if(confirm(msg))
		return true;

	return false;
}
// function to change town list according the selected domicile.
function partTownChange(domicile,town,curval,page)
{
	if(domicile)
	{
		if(domicile.length)
		{
			if(domicile.selectedIndex > -1)
			{
				idDomicile=new String(domicile.options[domicile.selectedIndex].value);
			}
			else
				idDomicile='';
		}
		else
			idDomicile=domicile;
	}

	if (page == 'listService')
	{
		town.length=0;
		j=0;
	}
	else
	{
		town.length=1;
		j=1;
	}
	if(idDomicile != '')
	{
		if(tId[idDomicile])
		{
			for(i=0; i < tId[idDomicile].length; i++)
		    {
				cvalue=new String(tId[idDomicile][i]);
				ctext=new String(tName[idDomicile][i]);

				cOpt=new Option(ctext,cvalue);
				eval("town.options[j]=cOpt");

				if(tId[idDomicile][i] == curval)
					town.selectedIndex=j;
				j++;
			}
		}
	}
	else
	{
		if (page == 'listService')
		{
			town.length=0;
			j=0;
		}
		else
		{
			town.length=1;
			j=1;
		}
	}
}

function changeLanguage(frm)
{
	if(frm.sitelang.value == 1)
		frm.sitelang.value=2;
	else
		frm.sitelang.value=1;

	frm.submit();
	return false;
}

function changeClass(id,cls)
{
	if(document.getElementById(id).className=='listing listing_sel')
		document.getElementById(id).className=cls;
	else
		document.getElementById(id).className='listing listing_sel';
}

function categoryChange(category,subcategory,curval)
{
	if(category)
	{
		if(category.length)
		{
			if(category.selectedIndex > -1)
			{
				idCat=new String(category.options[category.selectedIndex].value);
			}
			else
				idCat='';
		}
		else
			idCat=category;
	}

	subcategory.length=0;
	j=0;

	if(idCat != '')
	{
		if(sId[idCat])
		{
			for(i=0; i < c.length; i++)
		    {
				if(sCnt[idCat][i] > 0)
				{
					if(sAvail[idCat][i].match(/NA/))
					{
						cvalue=new String(sId[idCat][i]);
						ctext=new String(sName[idCat][i]);

						cOpt=new Option(ctext,cvalue);
						eval("subcategory.options[j]=cOpt");

						if(sId[idCat][i] == curval)
							subcategory.selectedIndex=j;
						j++;
					}
				}
			}
		}
	}
	else
	{
		j=0;
		subcategory.length=0;
	}
}

//Define indicator for all ajax requests
Ajax.Responders.register({
  onCreate: function() { Element.show('indicator'); },
  onComplete: function() { Element.hide('indicator'); }
});
