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

// validate posting of boat
function validatePostBoat(target,PokeYoke)
{
		if(target.name == "mfg_year" && target.value == "")
		{
				PokeYoke.renderInlineError(target,msg_mfg_year_cannot_be_blank);
				$(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((target.name == "id_eng_make") && ($("boat_type").value == "" || $("boat_type").value == 1 || $("boat_type").value == 3 || $("boat_type").value == 9 || $("boat_type").value == 10 || $("boat_type").value == 11))
		{
			if(target.value == "")
			{
				PokeYoke.renderInlineError(target,msg_eng_make_cannot_be_blank);
				$(target.name).addClassName('error_box');
				target.focus();
				return false;
			}
		}

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

		if(target.name == "id_town" && $("id_domicile").value != 22 && $("user_cat").value != 'D')
		{
			if($("id_town").value == "")
			{
				PokeYoke.renderInlineError(target, msg_town_cannot_be_blank);
				$(target.name).addClassName('error_box');
				target.focus();
				return false;
			}
		}

		if(target.name == "total_owner" && $("user_cat").value == "D")
		{
			if(target.value != "")
			{
				if(!(target.value.match(/^[0-9]{0,2}$/)))
				{
					PokeYoke.renderInlineError(target,msg_total_owner_must_be_number);
					$(target.name).addClassName('error_box');
					target.focus();
					return false;
				}
			}
		}
		$(target.name).removeClassName('error_box');
		PokeYoke.removeErrors(target);
		return true;
}

function boatTypeChange(v1,v2,curval,cond)
{
	var boatid='';
	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(cond == 'Y' || cond == 'POST')
		var id_make="'" + curval + "'";
	else if(cond == 'ADV')
		var id_make=curval;
	else
		var id_make='';

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

	if(boatid != '') 	//Boat Type is selected
	{
		v2.length=1;
		var j=1;

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

			if(cond == 'POST' || cond == 'ADV' || a[make_value] > 0) 	//Posting boat && Simple Search
			{
				/** OPTION GROUP PART STARTS HERE */
				/* Changes has been made for displaying makes in alphabetical group. */
				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 */

				//Display the selected values.
				if(id_make.search("'"+make_value+"'") != -1)
					v2.options[j].selected=true;

				if(e[boatid][i] == id_make)
					v2.options[j].selected=true;

				j++;
			}
	    }
		if(v2.selectedIndex == '' || v2.selectedIndex < 1)
			v2.selectedIndex=0;
	}
	else
	{
		//When Boat 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]]);

				/** OPTION GROUP PART STARTS HERE */
				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 */

				//Display the selected values.
				if(id_make.search("'"+u[z]+"'") != -1)
					v2.options[j].selected=true;

				if(u[z] == id_make)
					v2.options[j].selected=true;

				j++;
			}
		}
	}
}

//Function to change the subtype corresponding to boat type
function subTypeChange(v1,v2,curval,cond,caption)
{
	//If the selected value is not passed in curval, then check
	//whether any subtype is selected and if yes, store it as curval.

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

    //'s' -> simple search, 'p'-> boat post/edit, 'ADV'->advamce Search
	if(cond == 's' || cond == 'p' || cond == 'ADV')
		curval="'"+curval+"'";

	//holds the seleted boat type.
	var typeId='';

	if(v1.selectedIndex >= 0)
		typeId=v1.options[v1.selectedIndex].value;

	var opt;
	v2.length=0;
	var j=0;

	if(cond == 's')	//For simplate search display the 'Boat subtype' as default option.
	{
		opt=new Option(subtype,'');
		eval("v2.options[j]=opt");
		j++;
	}
	else if(cond == 'p')	//For boat post/edit, display the blank value as default option.
	{
		opt=new Option(caption,'');
		eval("v2.options[j]=opt");
		j++;
	}
  else if(cond == 'ADV') //For advance search display the 'Boat subtype' as default option.
  {
      opt=new Option(modelDefVal,'');
      eval("v2.options[j]=opt");
      j++;
  }

	if(typeId != '') //If the boat type is selected(boat post/edit, simple search and advanced search)
	{

		for(var i=0; i < r[typeId].length; i++)
		{
			opt=new Option(s[typeId][i],r[typeId][i]);
			eval("v2.options[j]=opt");

			if(curval.search("'"+r[typeId][i]+"'") != -1)
				v2.options[j].selected=true;

			j++;
		}
	}
	else	//If the boat type is not selectd(simple search and advacned search)
	{
		var idBoatType;
		var strIdSubType=new String('');

		//Loop through all of the boat types.
		for(var m=0; m < v1.length; m++)
		{
			var idBoatType=v1.options[m].value;

			if(idBoatType > 0)
			{
				for(var i=0;i < r[idBoatType].length; i++)
				{
					//Check whether the subtype has been already added in the listbox as one subtype
					// can belong to more than one boat type.
					if(strIdSubType.search("'"+r[idBoatType][i]+"'") == -1)
					{
						opt=new Option(s[idBoatType][i],r[idBoatType][i]);
						eval("v2.options[j]=opt");

						if(curval.search("'"+r[idBoatType][i]+"'") != -1)
							v2.options[j].selected=true;

						strIdSubType=strIdSubType+"'"+r[idBoatType][i]+"',";
						j++;
					}
				}
			}
		}
	}
}
/**
	Function for changes the make value as per change the boat sub type
	v1=contain the id_boat_type
	v2=contain the id_sub_type
	v3=contain the id_make
	curval=contain the selected/current value of id_make
	cond=wether call from post/editing(p) OR search(s) page.
*/
function makeChange(v1,v2,v3,curval,cond)
{
	if(v1.options[v1.selectedIndex].value == 14)
	{
		var boatid='';
		var id_make='';
		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(cond == 'Y' || cond == 'POST')
			var id_make="'" + curval + "'";
		else if(cond == 'ADV')
			var id_make=curval;
		else
			var id_make='';

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

		if(boatid != '')
		{
			v3.length=1;
			var j=1;

			if(v2 && v2.selectedIndex >= 0 && v2.options[v2.selectedIndex].value == 9)
			{
				for(i=0; i < e[boatid].length; i++)
				{
					var make_value=new String(e[boatid][i]);
					var make_text=new String(f[boatid][i]);

					if(cond == 'POST' || cond == 'ADV' || a[make_value] > 0) //Posting boat && Simple Search
					{
						/** OPTION GROUP PART STARTS HERE */
						/* Changes has been made for displaying makes in alphabetical group. */
						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;
								v3.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('v3.options[j]=makeOpt');
						}
						/** OPTION GROUP PART ENDS HERE */

						if(id_make.search("'"+make_value+"'") != -1)
							v3.options[j].selected=true;

						if(e[boatid][i] == id_make)
							v3.options[j].selected=true;

						j++;
					}
				}
				if(v3.selectedIndex == '' || v3.selectedIndex < 1)
					v3.selectedIndex=0;
			}
			else
			{
				for(i=0; i < e[boatid].length; i++)
				{
					/** This is only for 'other make'(make_id=1) for boat sub type */
					if(e[boatid][j] == 1)
					{
						var make_value=new String(e[boatid][j]);
						var make_text=new String(f[boatid][j]);

						/** OPTION GROUP PART STARTS HERE */
						/* Changes has been made for displaying makes in alphabetical group. */
						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;
								v3.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('v3.options[1]=makeOpt');
						}
						/** OPTION GROUP PART ENDS HERE */

						if(id_make.search("'"+make_value+"'") != -1)
							v3.options[1].selected=true;

						if(e[boatid][i] == id_make)
							v3.options[1].selected=true;
					}
					j++;
				}
                if(v3.selectedIndex == '' || v3.selectedIndex < 1)
                    v3.selectedIndex=0;
			}
		}
	}
}

//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 the Length,Power and Price list box options
function listboxChange(v1,v2,curval,sign,sep)
{
	var csep = typeof sep != 'undefined' ? sep : ' ';

	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+csep+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 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 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 to open new pop up window with variable width and height
function openImg(img_nm,w,h,nm)
{
	var myfeatures="directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no,resizable=yes,scrollbars=yes,width="+w+",height="+h+",left=0,top=0";

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

	var newImg=open(img_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=yes,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');
}

//Function to submit navigation
function submitNav(pno,sort,ono)
{
	document.nav.page.value=pno;
	document.nav.sortCol.value=sort;
	document.nav.ord.value=ono;
	document.nav.submit();
}

//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');

	self.location.reload();
}

// Function to suhmit favorite page by adding/removing boats
function submitFav(thisV)
{
	var i,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 submit favorite page to compare boats.
function compareBoat()
{
    var cnt=flag=0;

    for(var i=1; i < document.fav.length; i++)
    {
        if(document.fav.elements[i].type == 'checkbox' && document.fav.elements[i].checked)
        {
            cnt++;
            continue;
        }
    }

    if(cnt < 2 || cnt > 4)
    {
        alert(msgSelMinTwoMaxFourBoat);
        return false;
    }
    else
    {
        document.fav.action='compareBoats.php';
        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);
}

//Argument 'label' can be the entity name you want to delete,
//for exa., user,dealer,boat etc. and 'nm' can be the user name,
//dealer name or boat id etc.
function newConfirmDel(ref,label,nm)
{
	if(confirm(msgNewDeleteConfirm+" "+label+", '" + nm + "'?"))
		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()");
	}
}

// Script area for dynamic banner display
var zg_h=0;
var banid_h=new Array();
var links_h=new Array();
var alt_h=new Array();
var duration_h=new Array();
var target_h=new Array();
var bcode_h=new Array();
var btype_h=new Array();

// Part of rotating huge banner module. This is main function
// which rotates huge banners by certain intevral as specified
// in duration array.
function showHugeBanner(whatToDo,whereFrom,baseurl)
{
	if(whatToDo == 'show')
	{
		var whenToCall=5000;

		// Run this script only when there exists local image
		if(document.getElementById('huge_banner'))
		{
			// Get random banner ID, but when there is default banner, use only that
			if(banid_h.length > 1)
			{
				do
				{
					zg_h=Math.floor(Math.random() * banid_h.length)
				}
				while(zg_h < 1)

				if(btype_h[zg_h] == "F")
				{
					document.getElementById('bimage_h').style.display="none";
					document.getElementById('bflash_h').style.display="inline";
					document.getElementById('bflash_h').innerHTML=bcode_h[zg_h];
					whenToCall=duration_h[zg_h];
					
					if(banid_h.length > 2)
					{
						window.setTimeout('showHugeBanner(\'show\',\''+whereFrom+'\');',whenToCall);
					}
				}
				else
				{
					document.getElementById('bflash_h').style.display="none";
					document.getElementById('bimage_h').style.display="inline";
					whenToCall=duration_h[zg_h];


					// When CIF is viewed from ODS / TDS do not show commercial banners
					// Hence when url link matches 'netti' only then show that banner.
					if(whereFrom == 'odstds')
					{
						if(links_h[zg_h].match(/http:\/\/(www.)?(netti[a-zA-Z]{1,15})\.([a-z]{2,4})/i))
							document.hugebanner.src=eval('h_banner'+zg_h+'.src');
						else
							whenToCall=1;
					}
					else
						document.hugebanner.src=eval('h_banner'+zg_h+'.src');

						if(banid_h.length > 2)
						{
							window.setTimeout('showHugeBanner(\'show\',\''+whereFrom+'\');',whenToCall);
						}
				}
			}
			else
				zg_h=0;
		}
	}
	if(whatToDo == 'golink')
	{
		if(links_h[zg_h])
		{
			str= baseurl+'/user/bannerCounter?id='+banid_h[zg_h]+'&url='+links_h[zg_h];

			if(target_h[zg_h] == 'B')
				window.open(str);
			else
				window.location.replace(str);
		}
	}
	if(whatToDo == 'showinfo')
	{
		if(alt_h[zg_h])
		{
			window.status=links_h[zg_h];
			document.hugebanner.title=alt_h[zg_h];
		}
	}
	if(whatToDo == 'removeinfo')
		window.status='';
}


// Script area for dynamic top right banner display
var zg_t=0;
var banid_t=new Array();
var links_t=new Array();
var alt_t=new Array();
var duration_t=new Array();
var target_t=new Array();
var bcode_t=new Array();
var btype_t=new Array();

// Part of rotating banner module. This is main function
// which rotates huge banners by certain intevral as specified
// in duration array.
function showTopLeftBanner(whatToDo,whereFrom,baseurl)
{

	if(whatToDo == 'show')
	{
		var whenToCall=5000;

		// Run this script only when there exists local image
		if(document.getElementById("topleft_banner"))
		{
			// Get random banner ID, but when there is default banner, use only that
			if(banid_t.length > 1)
			{
				do
				{
					zg_t=Math.floor(Math.random() * banid_t.length)
				}
				while(zg_t < 1)

				if(btype_t[zg_t] == "F")
				{
					document.getElementById('bimage_t').style.display="none";
					document.getElementById('bflash_t').style.display="inline";
					document.getElementById('bflash_t').innerHTML=bcode_t[zg_t];
					whenToCall=duration_t[zg_t];
					
					if(banid_t.length > 2)
					{
						window.setTimeout('showTopLeftBanner(\'show\',\''+whereFrom+'\');',whenToCall);
					}
				}
				else
				{
					document.getElementById('bflash_t').style.display="none";
					document.getElementById('bimage_t').style.display="inline";

					whenToCall=duration_t[zg_t];


					// When CIF is viewed from ODS / TDS do not show commercial banners
					// Hence when url link matches 'netti' only then show that banner.
					if(whereFrom == 'odstds')
					{
						if(links_t[zg_t].match(/http:\/\/(www.)?(netti[a-zA-Z]{1,15})\.([a-z]{2,4})/i))
							document.topleftbanner.src=eval('t_banner'+zg_t+'.src');
						else
							whenToCall=1;
					}
					else
						document.topleftbanner.src=eval('t_banner'+zg_t+'.src');
						
					if(banid_t.length > 2)
					{
						window.setTimeout('showTopLeftBanner(\'show\',\''+whereFrom+'\');',whenToCall);
					}
				}
			}
			else
				zg_t=0;
		}
	}
	if(whatToDo == 'golink')
	{
		if(links_t[zg_t])
		{
			str= baseurl+'/user/bannerCounter?id='+banid_t[zg_t]+'&url='+links_t[zg_t];

			if(target_t[zg_t] == 'B')
				window.open(str);
			else
				window.location.replace(str);
		}
	}
	if(whatToDo == 'showinfo')
	{
		if(alt_t[zg_t])
		{
			window.status=links_t[zg_t];
			document.topleftbanner.title=alt_t[zg_t];
		}
	}
	if(whatToDo == 'removeinfo')
		window.status='';
}


// Script area for dynamic top right banner display
var zg_b=0;
var banid_b=new Array();
var links_b=new Array();
var alt_b=new Array();
var duration_b=new Array();
var target_b=new Array();
var bcode_b=new Array();
var btype_b=new Array();

// Part of rotating banner module. This is main function
// which rotates huge banners by certain intevral as specified
// in duration array.
function showBottomLeftBanner(whatToDo,whereFrom,baseurl)
{

	if(whatToDo == 'show')
	{
		var whenToCall=5000;

		// Run this script only when there exists local image
		if(document.getElementById("bottomleft_banner"))
		{
			// Get random banner ID, but when there is default banner, use only that
			if(banid_b.length > 1)
			{
				do
				{
					zg_b=Math.floor(Math.random() * banid_b.length)
				}
				while(zg_b < 1)

				if(btype_b[zg_b] == "F")
				{
					document.getElementById('bimage_b').style.display="none";
					document.getElementById('bflash_b').style.display="inline";
					document.getElementById('bflash_b').innerHTML=bcode_b[zg_b];
					whenToCall=duration_b[zg_b];
					
					if(banid_b.length > 2)
					{
						window.setTimeout('showBottomLeftBanner(\'show\',\''+whereFrom+'\');',whenToCall);
					}
				}
				else
				{
					document.getElementById('bflash_b').style.display="none";
					document.getElementById('bimage_b').style.display="inline";
					whenToCall=duration_b[zg_b];


					// When CIF is viewed from ODS / TDS do not show commercial banners
					// Hence when url link matches 'netti' only then show that banner.
					if(whereFrom == 'odstds')
					{
						if(links_t[zg_b].match(/http:\/\/(www.)?(netti[a-zA-Z]{1,15})\.([a-z]{2,4})/i))
							document.bottomleftbanner.src=eval('b_banner'+zg_b+'.src');
						else
							whenToCall=1;
					}
					else
						document.bottomleftbanner.src=eval('b_banner'+zg_b+'.src');

						if(banid_b.length > 2)
						{
							window.setTimeout('showBottomLeftBanner(\'show\',\''+whereFrom+'\');',whenToCall);
						}
				}
			}
			else
				zg_b=0;
		}
	}
	if(whatToDo == 'golink')
	{
		if(links_b[zg_b])
		{
			str= baseurl+'/user/bannerCounter?id='+banid_b[zg_b]+'&url='+links_b[zg_b];

			if(target_b[zg_b] == 'B')
				window.open(str);
			else
				window.location.replace(str);
		}
	}
	if(whatToDo == 'showinfo')
	{
		if(alt_b[zg_b])
		{
			window.status=links_b[zg_b];
			document.bottomleftbanner.title=alt_b[zg_b];
		}
	}
	if(whatToDo == 'removeinfo')
		window.status='';
}


// Script area for dynamic top right banner display
var zg_m=0;
var banid_m=new Array();
var links_m=new Array();
var alt_m=new Array();
var duration_m=new Array();
var target_m=new Array();
var bcode_m=new Array();
var btype_m=new Array();

// Part of rotating banner module. This is main function
// which rotates huge banners by certain intevral as specified
// in duration array.
function showMiddleRightBanner(whatToDo,whereFrom,baseurl)
{

	if(whatToDo == 'show')
	{
		var whenToCall=5000;

		// Run this script only when there exists local image
		if(document.getElementById("middleright_banner"))
		{
			// Get random banner ID, but when there is default banner, use only that
			if(banid_m.length > 1)
			{
				do
				{
					zg_m=Math.floor(Math.random() * banid_m.length)
				}
				while(zg_m < 1)

				if(btype_m[zg_m] == "F")
				{
					document.getElementById('bimage_m').style.display="none";
					document.getElementById('bflash_m').style.display="inline";
					document.getElementById('bflash_m').innerHTML=bcode_m[zg_m];
					whenToCall=duration_m[zg_m];
										
					if(banid_m.length > 2)
					{
						window.setTimeout('showMiddleRightBanner(\'show\',\''+whereFrom+'\');',whenToCall);
					}
				}
				else
				{
					document.getElementById('bflash_m').style.display="none";
					document.getElementById('bimage_m').style.display="inline";

					whenToCall=duration_m[zg_m];


					// When CIF is viewed from ODS / TDS do not show commercial banners
					// Hence when url link matches 'netti' only then show that banner.
					if(whereFrom == 'odstds')
					{
						if(links_m[zg_m].match(/http:\/\/(www.)?(netti[a-zA-Z]{1,15})\.([a-z]{2,4})/i))
							document.middlerightbanner.src=eval('m_banner'+zg_m+'.src');
						else
							whenToCall=1;
					}
					else
						document.middlerightbanner.src=eval('m_banner'+zg_m+'.src');
						
						if(banid_m.length > 2)
						{
							window.setTimeout('showMiddleRightBanner(\'show\',\''+whereFrom+'\');',whenToCall);
						}
				}
			}
			else
				zg_m=0;
		}
	}
	if(whatToDo == 'golink')
	{
		if(links_m[zg_m])
		{
			str= baseurl+'/user/bannerCounter?id='+banid_m[zg_m]+'&url='+links_m[zg_m];

			if(target_m[zg_m] == 'B')
				window.open(str);
			else
				window.location.replace(str);
		}
	}
	if(whatToDo == 'showinfo')
	{
		if(alt_m[zg_m])
		{
			window.status=links_m[zg_m];
			document.middlerightbanner.title=alt_m[zg_m];
		}
	}
	if(whatToDo == 'removeinfo')
		window.status='';
}



var zg_c=0;
var banid_c=new Array();
var links_c=new Array();
var alt_c=new Array();
var duration_c=new Array();
var target_c=new Array();
var bcode_c=new Array();
var btype_c=new Array();

function showCenterBanner(whatToDo,whereFrom,baseurl)
{
	
	if(whatToDo == 'show')
	{
		var whenToCall=5000;

		// Run this script only when there exists local image
		if(document.getElementById("center_banner"))
		{
			// Get random banner ID, but when there is default banner, use only that
			if(banid_c.length > 1)
			{
				do
				{
					zg_c=Math.floor(Math.random() * banid_c.length)
				}
				while(zg_c < 1)

				if(btype_c[zg_c] == "F")
				{
					document.getElementById('bimage_c').style.display="none";
					document.getElementById('bflash_c').style.display="inline";
					document.getElementById('bflash_c').innerHTML=bcode_c[zg_c];
					whenToCall=duration_c[zg_c];
					
					if(banid_c.length > 2)
					{
						window.setTimeout('showCenterBanner(\'show\',\''+whereFrom+'\');',whenToCall);
					}
				}
				else
				{
					document.getElementById('bflash_c').style.display="none";
					document.getElementById('bimage_c').style.display="inline";

					whenToCall=duration_c[zg_c];


					// When CIF is viewed from ODS / TDS do not show commercial banners
					// Hence when url link matches 'netti' only then show that banner.
					if(whereFrom == 'odstds')
					{
						if(links_c[zg_c].match(/http:\/\/(www.)?(netti[a-zA-Z]{1,15})\.([a-z]{2,4})/i))
							document.centerbanner.src=eval('c_banner'+zg_c+'.src');
						else
							whenToCall=1;
					}
					else
						document.centerbanner.src=eval('c_banner'+zg_c+'.src');
						
					if(banid_c.length > 2)
					{
						window.setTimeout('showCenterBanner(\'show\',\''+whereFrom+'\');',whenToCall);
					}
				}
			}
			else
				zg_c=0;
		}
	}
	if(whatToDo == 'golink')
	{
		if(links_c[zg_c])
		{
			str= baseurl+'/user/bannerCounter?id='+banid_c[zg_c]+'&url='+links_c[zg_c];

			if(target_c[zg_c] == 'B')
				window.open(str);
			else
				window.location.replace(str);
		}
	}
	if(whatToDo == 'showinfo')
	{
		if(alt_c[zg_c])
		{
			window.status=links_c[zg_c];
			document.centerbanner.title=alt_c[zg_c];
		}
	}
	if(whatToDo == 'removeinfo')
		window.status='';
}




// Script area for dynamic banner display
var zg=0;
var banid=new Array();
var links=new Array();
var alt=new Array();
var duration=new Array();
var target=new Array();
var bcode=new Array();
var btype=new Array();

// Part of rotating banner module. This is main function
// which rotates banners by certain intevral as specified
// in duration array.
function showBanner(whatToDo,whereFrom)
{
	if(whatToDo == 'show')
	{
		var whenToCall=5000;

		// Run this script only when there exists local image
		if(document.getElementById('banner'))
		{
			// Get random banner ID, but when there is default banner, use only that
			if(banid.length > 1)
			{
				do
				{
					zg=Math.floor(Math.random() * banid.length)
				}
				while(zg < 1)

				if(btype[zg] == "F")
				{
					document.getElementById('bimage').style.display="none";
					document.getElementById('bflash').style.display="inline";
					document.getElementById('bflash').innerHTML=bcode[zg];
					whenToCall=duration[zg];
					
					if(banid.length > 2)
					{
						window.setTimeout('showBanner(\'show\',\''+whereFrom+'\');',whenToCall);
					}
				}
				else
				{
					document.getElementById('bflash').style.display="none";
					document.getElementById('bimage').style.display="inline";

					whenToCall=duration[zg];

					// When CIF is viewed from ODS / TDS do not show commercial banners
					// Hence when url link matches 'netti' only then show that banner.
					if(whereFrom == 'odstds')
					{
						if(links[zg].match(/http:\/\/(www.)?(netti[a-zA-Z]{1,15})\.([a-z]{2,4})/i))
						document.banner.src=eval('banner'+zg+'.src');
						else
						whenToCall=1;
					}
					else
					document.banner.src=eval('banner'+zg+'.src');

					if(banid.length > 2)
					{
							window.setTimeout('showBanner(\'show\',\''+whereFrom+'\');',whenToCall);
					}
				}
			}
			else
			zg=0;
		}
	}
	if(whatToDo == 'golink')
	{
		if(links[zg])
		{
			str='user/bannerCounter?id='+banid[zg]+'&url='+links[zg];

			if(target[zg] == 'B')
			window.open(str);
			else
			window.location.replace(str);
		}
	}
	if(whatToDo == 'showinfo')
	{
		if(alt[zg])
		{
			window.status=links[zg];
			document.banner.title=alt[zg];
		}
	}
	if(whatToDo == 'removeinfo')
	window.status='';
}

// Script area for dynamic banner display
var zg2=0;
var b_banId=new Array();
var b_Links=new Array();
var b_alt=new Array();
var b_Duration=new Array();
var b_target=new Array();

// Part of rotating banner module. This is main function
// which rotates banners by certain intevral as specified
// in duration array.
function showBannerBody(whatToDo,whereFrom)
{
	if(whatToDo == 'show')
	{
		var whenToCall=1000;

		// Run this script only when there exists local image
		if(document.getElementById('bannerBody'))
		{
			// Get random banner ID, but when there is default banner, use only that
			if(b_banId.length > 1)
			{
				do
				{
					zg2=Math.floor(Math.random() * b_banId.length)
				}
				while(zg2 < 1)

				whenToCall=b_Duration[zg2];

				// When CIF is viewed from ODS / TDS do not show commercial banners
				// Hence when url link matches 'netti' only then show that banner.
				if(whereFrom == 'odstds')
				{
					if(b_Links[zg2].match(/http:\/\/(www.)?(netti[a-zA-Z]{1,15})\.([a-z]{2,4})/i))
					document.bannerBody.src=eval('bannerBody'+zg2+'.src');
					else
					whenToCall=1;
				}
				else
				document.bannerBody.src=eval('bannerBody'+zg2+'.src');

				window.setTimeout('showBannerBody(\'show\',\''+whereFrom+'\');',whenToCall);
			}
			else
			zg2=0;
		}
	}
	if(whatToDo == 'golink')
	{
		if(b_Links[zg2])
		{
			str='bannerCounter.php?id='+b_banId[zg2]+'&url='+b_Links[zg2];

			if(b_target[zg2] == 'B')
			window.open(str);
			else
			window.location.replace(str);
		}
	}
	if(whatToDo == 'showinfo')
	{
		if(b_alt[zg2])
		{
			window.status=b_Links[zg2];
			document.bannerBody.title=b_alt[zg2];
		}
	}
	if(whatToDo == 'removeinfo')
	window.status='';
}

// 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');
		}
	}
}

//Script area for dynamic banner display
var zg=0;
var banid=new Array();
var links=new Array();
var alt=new Array();
var duration=new Array();
var target=new Array();

//Part of rotating banner module. This is main function
//which rotates banners by certain intevral as specified
//in duration array.
function Timer()
{
	//Run this script only when there exists local image
	if(document.getElementById('netBanner'))
	{
		//Get random banner ID, but when there is default banner, use only that
		if(banid.length > 1)
		{
			do
			{
				zg=Math.floor(Math.random() * banid.length)
			}
			while(zg < 1)

			//Protection when there are no banners
			document.netBanner.src=eval("netBanner"+zg+".src");
			window.setTimeout('Timer();',duration[zg]);
		}
		else
			zg=0;
	}
}

//Part of rotating banner module, to open url in new or same
//window as specified in links array.
function clickLink()
{
	if(links[zg])
	{
		str="bannerCounter.php?id="+banid[zg]+"&url="+links[zg];

		if (target[zg] == 'B')
			window.open(str);
		else
			self.location.replace(str);
	}
}

//Part of rotating banner module, to show alter text on windows's status bar
function descript()
{
	if(alt[zg])
	{
		window.status=alt[zg];

		if ((navigator.appName == 'Netscape') && (parseFloat(navigator.appVersion.substr(0,3)) < 5.0))
		{
			document.netBan.visibility='show';
			text='';
			text=alt[zg];

			document.netBan.document.write('<layer id="id1" top="20" left="450" bgcolor="#f7f7d3" style="border:0px solid white; font-family: verdana; font-size:11px; color:black;">'+text+'</layer>');
		}
		else
			document.netBanner.title=alt[zg];
	}
}

//Part of rotating banner module, to remove alter text from windows's status bar
function remove()
{
	window.status='';

	if ((navigator.appName == 'Netscape') && (parseFloat(navigator.appVersion.substr(0, 3)) < 5.0))
		document.netBan.visibility='hide';
}

//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)
{
	document.getElementById('fullimg').src=newimg;
}

//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(file,from)
{
	if(file.id_user.value == '')
	{
		if(from == 'O')
			openImg('../../popUpLogin.php?M=OnlyForRegisteredUser',350,320,'na_login');
		else
			openImg('popUpLogin.php?M=OnlyForRegisteredUser',350,320,'na_login');

		return false;
	}
	var flag='N';

	for(var q=0; q < file.elements.length; q++)
	{
		if(file.elements[q].type == 'text')
		{
			if(!isblank(file.elements[q].value))
			{
				if(!isLong(file.elements[q].value,' ',40))
				{
					alert(msgTooLongWord);
					file.elements[q].select();
					file.elements[q].focus();
					return false;
				}
				flag='Y';
			}
		}
	}
	if(flag == 'N')
	{
		alert(msgBlankForm);
		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 == 'nettiauto' || s == 'netipaat' || 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(txtVal,sep,len)
{
	if (txtVal == '')
		return true;
	else
	{
		if(sep == ' ')
			tempValue=txtVal.split(/\s+/);
		else
			tempValue=txtVal.split(sep);

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

//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(name)
{
    var start=document.cookie.indexOf(name+"=");
    var len=start+name.length+1;

    if ((!start) && (name != document.cookie.substring(0,name.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(name,value,expires,path,domain,secure)
{
    document.cookie=name+"="+escape(value)+((expires)?";expires="+expires:'')+((path)?";path="+path:'')+((domain)?";domain="+domain:'')+((secure)?";secure":'');
}

//Function to delete cookie
function Delete_Cookie(name,path,domain)
{
    if(Get_Cookie(name))
    	document.cookie=name+"="+((path)?";path="+path:'')+((domain)?";domain="+domain:'')+";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 hobby/reference values
function checkHobbyRef(s)
{
	if(!s.match(/^[0-9a-zA-ZÄäÕõÅåÖöŠšÜüŽžÁÀÉÈÒÓÙÚáàèéòóùúÝìíýÌÍ_:;@´()\s\+\,'.-]{1,250}$/))
		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 to give warning messaeg to the user when he tries
//to access the feature available only to the logged in user.
function loginWarning(msgWar,curTxt)
{
	if(!isblank(curTxt))
	{
		alert(msgWar);
	}
}
function confirmReset(msg)
{
	if(confirm(msg))
		return true;

	return false;
}
function confirmCancel(valMsg,valFile)
{
	if(valMsg != '')
	{
		if(confirm(valMsg))
		{
			if(valFile)
				location.href=valFile;
			else
				location.href='home.php';
		}
		else
			return false;
	}
	else
	{
		if(valFile != '')
			location.href=valFile;
		else
			location.href='home.php';
	}
}

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 to change town list according the selected domicile.
function partTownChange(ptype,town,curval,page)
{
	if(ptype)
	{
		if(ptype.length)
		{
			if (page == 'SELECTPART')
			{
				if(ptype.selectedIndex > -1 && ptype.selectedIndex > 0)
						idPart=new String(ptype.options[ptype.selectedIndex].value);
				else
						idPart='';
			}
			else
			{
				if(ptype.selectedIndex > -1)
						idPart=new String(ptype.options[ptype.selectedIndex].value);
				else
						idPart='';
			}
		}
		else
			partid=ptype;
	}
	if(page == 'POST')
	{
		town.length=1;
		j=1;
	}
	else if(page == 'ADV')
	{
		town.length=0;
		j=0;
	}
	else if (page == 'listService')
	{
		town.length=0;
		j=0;
	}
	else
	{
		town.length=1;
		j=1;
	}
	if(idPart != '')
	{
		if(tId[idPart])
		{
			for(i=0; i < tId[idPart].length; i++)
			{
				cvalue=new String(tId[idPart][i]);
				ctext=new String(tName[idPart][i]);

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

				if(tId[idPart][i] == curval)
						town.selectedIndex=j;
				j++;
			}
		}
	}
	else
	{
		j=1;
		town.length=1;
	}
}

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 < sId[idCat].length; i++)
			{
				if(sCnt[idCat][i] > 0)
				{
					if(sAvail[idCat][i].match(/NV/))
					{
						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;
	}
}

// Function to add the sail information in listbox
function addSailDetails(type,make,material,mfg_year,sail_options,sail_options_val)
{
	var val=type.options[type.selectedIndex].value+","+
			make.options[make.selectedIndex].value+","+
			material.options[material.selectedIndex].value+","+
			mfg_year.options[mfg_year.selectedIndex].value;

	var txt='';

	if(type.selectedIndex > 0)
		txt +=type.options[type.selectedIndex].text+", ";

	if(make.selectedIndex > 0)
		txt +=make.options[make.selectedIndex].text+", ";

	if(material.selectedIndex > 0)
		txt +=material.options[material.selectedIndex].text+", ";

	if(mfg_year.selectedIndex > 0)
		txt +=mfg_year.options[mfg_year.selectedIndex].text+', ';

	var txt=txt.slice(0,-2);
	var tot=sail_options.length;
	var selOpt = new Option(txt,val);
	eval("sail_options.options[tot]=selOpt");

	sail_options_val.value += sail_options.options[tot].value+"#";
	//sail_options_txt.value += txt+"#";
}

// Function to remove the sail information from listbox
function removeSailDetails(sail_options,sail_options_val)
{
	if(sail_options.length == 0 || sail_options.selectedIndex < 0)
		return;

	var selIndex=sail_options.selectedIndex;
	var tot=sail_options.length;
	var txt,val;

	if(selIndex >= tot)
		return;

	for(var i=selIndex + 1; i < sail_options.length; i++)
	{
		sail_options.options[i - 1].value=sail_options.options[i].value;
		sail_options.options[i - 1].text=sail_options.options[i].text;
	}
	sail_options.length=tot - 1;

	//sail_options_txt.value='';
	sail_options_val.value='';

	for(var i=0; i < sail_options.length; i++)
	{
		//sail_options_txt.value += sail_options.options[i].text+"#";
		sail_options_val.value += sail_options.options[i].value+"#";
	}
	if(sail_options.length > 0)
		sail_options.selectedIndex=-1;
}