/* $Id: nf_common.js,v 1.17 2009/06/20 04:43:41 vaishali Exp $ */

//changeCategory(reference_type,reference_category)
function changeCategory(itemTypeList,itemCatList,currVal,capAny)//,curval_more,cond,extra)
{
	var catOpt,selAny=true;

	removeOpt(itemCatList);

	//Getting selected item type
	id_item_type=itemTypeList.value;

	//Fill the list box with categories of the selected item type
	if(icati[id_item_type])
	{
		var i=0;
		while(icati[id_item_type][i])
		{
			//Create new option and add that option to the category list box
			if(navigator.userAgent.match(/IE/))
			{
				catOpt = document.createElement('Option');

				catOpt.value=icati[id_item_type][i];
				catOpt.innerText=icatn[id_item_type][i];

				if(currVal == icati[id_item_type][i])
				{
					catOpt.selected = true;
					selAny = false;
				}

				itemCatList.appendChild(catOpt);
			}
			else
			{
				catOpt= new Option(icatn[id_item_type][i],icati[id_item_type][i]);

				if(currVal == icati[id_item_type][i])
				{
					catOpt.selected = true;
					selAny = false;
				}

				itemCatList.options.add(catOpt);
			}

			i++;
		}
	}

	if(selAny)
	itemCatList.options[0].selected = true;
}

function changeSection(itemTypeList,itemCatList,itemSecList,currVal,capAny)
{
	var catOpt,selAny=true;

	removeOpt(itemSecList);

	id_item_type=itemTypeList.value;
	id_item_cat=itemCatList.value;

	//Fill the list box with categories of the selected item type
	if(id_item_type > 0)
	{
		if(iseci[id_item_type][id_item_cat])
		{
			var i=0;
			while(iseci[id_item_type][id_item_cat][i])
			{
				//Create new option and add that option to the category list box
				if(navigator.userAgent.match(/IE/))
				{
					opt = document.createElement('Option');

					opt.value=iseci[id_item_type][id_item_cat][i];
					opt.innerText=isecn[id_item_type][id_item_cat][i];

					if(currVal.match(iseci[id_item_type][id_item_cat][i]))
					{
						opt.selected = true;
						selAny = false;
					}

					itemSecList.appendChild(opt);
				}
				else
				{
					opt= new Option(isecn[id_item_type][id_item_cat][i],iseci[id_item_type][id_item_cat][i]);

					if(currVal.match(iseci[id_item_type][id_item_cat][i]))
					{
						opt.selected = true;
						selAny = false;
					}

					itemSecList.options.add(opt);
				}

				i++;
			}
		}
	}

	if(selAny)
	itemSecList.options[0].selected = true;
}

function removeOpt(listbox)
{
	if(listbox.options.length > 0)
	{
		listbox.options.length=1;
		//listbox.options[0].selected=true;
	}
}

function changeTown(domicileList,townList,currVal,capAny)
{
	var i,id_domicile = domicileList.value,selAny=true;

	removeOpt(townList);

	if(t[id_domicile])
	{
		i=0;

		while(t[id_domicile][i])
		{

			if(navigator.userAgent.match(/IE/))
			{
				opt = document.createElement('Option');

				opt.value=t[id_domicile][i];
				opt.innerText=n[id_domicile][i];

				if(currVal.match(t[id_domicile][i]))
				{
					opt.selected = true;
					selAny = false;
				}

				townList.appendChild(opt);
			}
			else
			{
				opt= new Option(n[id_domicile][i],t[id_domicile][i]);

				if(currVal.match(t[id_domicile][i]))
				{
					opt.selected = true;
					selAny = false;
				}

				townList.options.add(opt);
			}
			i++;
		}
		if(selAny)
		townList.options[0].selected = true;
	}
	else
	{
		/** if id_domicile not selected in simple search. */
		if(capAny == 'Y')
		{
			townList.length=1;
			var j=1;
			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;

			for(dm=0; dm < di.length; dm++)
			{
				if(!dn[di[dm]] || di[dm] == 15)
				continue;

				var domicile_text=new String(dn[di[dm]]);

				if(domicile_text != '')
				{
					if(!navigator.userAgent.match(/Opera/) && bflag == 1)
					{
						optGroup='T';
						textureGroup=document.createElement ('optgroup');
						textureGroup.label=domicile_text;
						townList.appendChild(textureGroup);
					}
					else
						optGroup='F';

					for(tw=0; tw < t[di[dm]].length; tw++)
					{
						var town_value=new String(t[di[dm]][tw]);
						var town_text=new String(n[di[dm]][tw]);

						if(optGroup != 'F' && domicile_text != '')
						{
							town_opt=document.createElement('option');
							town_opt.value=town_value;

							if(navigator.userAgent.match(/IE/))
							town_opt.innerText=town_text;
							else
								town_opt.text=town_text;

							textureGroup.appendChild(town_opt);
						}
						else
						{
							townOpt=new Option(town_text,town_value);
							townList.options.add(townOpt);
						}
						/** OPTION GROUP PART ENDS HERE */

						/** Display the selected values. */
						if(currVal.search("'"+t[di[dm]][tw]+"'") != -1)
						townList.options[j].selected=true;

						if(t[di[dm]][tw] == currVal)
						townList.options[j].selected=true;

						j++;
					}
				}
			}
		}
	}
}

//Function to change the town corresponding to domicile
function townChange(v1,v2,curval)
{
	//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;

	//holds the selected domicile.
	var i,j=0,opt,typeId='';

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

	v2.length=0;

	opt=new Option(selectOpt,'');
	eval("v2.options[j++]=opt");

	if(typeId != '') //If the domicile is selected(item post/edit, simple search and advanced search)
	{
		for(i=0; i < t[typeId].length; i++)
		{
			opt=new Option(n[typeId][i],t[typeId][i]);
			eval("v2.options[j]=opt");

			if(curval.search(t[typeId][i]) != -1)
			v2.options[j].selected=true;
			j++;
		}
	}
}
/** Function to remove the domicile wise optGroups in simple search. */
function RemoveGroups(selectId)
{
	for(var chr=0; chr < di.length; chr++)
	{
		if(!dn[di[chr]] || di[chr] == 15)
		continue;

		RemoveGroup(dn[di[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 change year list box options
function yearChange(v1,v2,curval)
{
	var i,j,temp,tot=v1.selectedIndex+1;

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

	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
function priceChange(v1,v2,curval,sign)
{
	var st,i,j,temp,len,disp,disp1,disp2;

	if(v1.selectedIndex < 1)
	st=1;
	else
		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)
		{
			len=v1.options[i].value.length;
			disp=v1.options[i].value;
			disp1=disp.substr(0,len-3);
			disp2=disp.substr(len-3,len);
			disp=disp1+" "+disp2+" "+sign;
		}
		else
			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 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))
	if(s.match(/^[a-z0-9åÅäÄöÖ_-]+(\.[a-z0-9åÅäÄöÖ_-]+)*[.]?@([a-z0-9åÅäÄöÖ-])+(\.[a-z0-9_-]+)*(\.[a-z]{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|ftp|https):\/\/)?[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 checkString(str)
{
	if(str.match(/[^a-zA-Z0-9åäöÅÄÖ&\+\-,:;\*€£$\.!\s]/))
		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 fixed size
function openVIF(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=660,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=yes,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,scroll)
{
	document.nav.page.value=pno;
	document.nav.sortCol.value=sort;
	document.nav.ord.value=ono;
	if(scroll ==1)
	{
		SaveScrollXY(document.nav);
	}
	document.nav.submit();
}


//This function is used to switch between image 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-Jan-2010 00:00:01 GMT');

	self.location.reload();
}

//Function to submit favorite page by adding/removing items
function submitFav(thisV)
{
	var i,flag='N';

	//for(i=1; i < document.fav.length; i++)
	for(i=0; 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;
	}submitNav
	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 item list page according to specified arguments.
function sortForm(col,ord)
{
	document.sortl.sortCol.value=col;
	document.sortl.ord.value=ord;
	document.sortl.submit();
}

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

// For removing single item from favorite list
function confirmFavDel(ref)
{
	if(confirm(msgDelFav))
		window.location.replace(ref);
}

//For removing single item from Find Agent
function confirmFindAgentDel(ref)
{
	if(confirm(msgToDelAgent))
		window.location.replace(ref);
}

/* Argument 'label' can be the entity name you want to delete,
for exa., user,deasubmitNavler,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 + "'?"))
	//if(confirm(msgNewDeleteConfirm+" "+label+"/" + nm + "?"))
	if(label=='tyyppi')
	{
		label='';
	}
	else
		label=label+'/ ';

	if(confirm(msgNewDeleteConfirm+" "+label+ nm + "?"))
		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 ConfirmDel_store(ref,label,nm)
{
	if(confirm(msgNewDeleteConfirm+" "+label+ nm + "?"))
		window.location.replace(ref);
}
function confirmDelSubCat(ref,cat,subcat)
{
	if(confirm(msgNewDeleteConfirm+' '+cat+ ' / ' +subcat+ '?'))
		window.location.replace(ref);
}

function confirmDelBanner(ref)
{
	if(confirm(msgDeleteBanner))
	window.location.replace(ref);
}
//To pop up message while removing multiple records
function confirmMultiDel(act,frm)
{
	if(confirm(msgDeleteConfirm))
	{
		if (act != '')
		eval("document."+frm+".action="+'act');

		eval("document."+frm+".submit()");
	}
}
function confirmfeedbackDel(act,frm)
{
	if(confirm(msgNewDeleteConfirm))
	{
		if (act != '')
		eval("document."+frm+".action="+'act');

		eval("document."+frm+".submit()");
	}
	else
	return false;
}
function confirmReset()
{
	if(confirm(msgConfirmReset))
	return true;

	return false;
}
function newConfirmCancel(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 confirmCancel()
{
	if(confirm(msgConfirmCancel))
	location.href="home.php";
}

//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 banKey=new Array();
var arrBanKey=new Array();
var strBannerKey='';

//Part of rotating banner module. This is main function
//which rotates banners by certain interval as specified
//in duration array.
function Timer()
{
	//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)
		{
			/** Make a string of all banner key's values. */
			strBannerKey=banKey.join(',');
			strBannerKey=strBannerKey.replace(/,+/g,','); // Remove blank banner key's values.
			arrBanKey=strBannerKey.split(','); // Generate array of banner key's values.

			/** Generate the random key grom banner key. */
			do
			{
				zg=Math.floor(Math.random() * arrBanKey.length)
			}
			while(zg < 1)

			zg=arrBanKey[zg]; // Get the value of banner number.

			//Protection when there are no banners
			document.banner.src=eval("banner"+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.banner.title=alt[zg];
	}
}

//Part of rotating banner module, to remove alter text from windows's status bar
function remove1()
{
	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 give alert to those users who do not use standard browsers
function diffBrowser()
{
	alert(msgDifferentBrowser);
}

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

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

//To check login session of user in VIF while sumbitting
//question or giving answer, if user is not logged in
//a pop up 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,'nf_login');
		else
			openImg('popUpLogin.php?M=OnlyForRegisteredUser',350,320,'nf_login');

		return false;
	}
	var flag='N';

	for(var 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(msgMandet);
		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 login id 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 == 'nettikirpputori' || 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
	{
		var tempValue= new Array();

		tempValue=value.split(sep);

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

//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 address/contact time values
function checkAddContTime(s)
{
	if(!s.match(/^[0-9a-zA-ZåÅäÄöÖé´ÁÀÉÈÒÓÙÚáàèéòóùúÝìíýÌÍ´:()\s\,'.!-]{1,255}$/))
	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 check zip values
function checkZip(s)
{
	if(!s.match(/^[0-9a-zA-Z]{1,250}$/))
	return false;
	else
		return true;
}

//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 changeClass(id,cls)
{
	if(document.getElementById(id).className=='highlight')
	document.getElementById(id).className=cls;
	else
		document.getElementById(id).className='highlight';
}

/* newly  added function starts here */
function changeItemCategory(itemTypeList,itemCatList,currVal)
{
	var catOpt;

	//Remove all categories from the list except the first entry
	if(itemCatList.options.length > 0)
	{
		itemCatList.options.length=1;
		itemCatList.options[0].selected=true;
	}

	//Getting selected item type
	id_item_type=itemTypeList.value;

	//Fill the list box with categories of the selected item type
	if(icati[id_item_type])
	{
		var i=0;
		while(icati[id_item_type][i])
		{
			//Create new option and add that option to the category list box
			if(navigator.userAgent.match(/IE/))
			{
				catOpt = document.createElement('Option');

				catOpt.value=icati[id_item_type][i];
				catOpt.innerText=icatn[id_item_type][i];

				if(currVal == icati[id_item_type][i])
				catOpt.selected = true;

				itemCatList.appendChild(catOpt);
			}
			else
			{
				catOpt= new Option(icatn[id_item_type][i],icati[id_item_type][i]);

				if(currVal == icati[id_item_type][i])
				catOpt.selected = true;

				itemCatList.options.add(catOpt);
			}

			i++;
		}
	}
}

function changeItemSection(itemTypeList,itemCatList,itemSecList,currVal)
{
	var opt;

	//Remove all categories from the list except the first entry
	if(itemSecList.options.length > 0)
	{
		itemSecList.options.length=1;
		itemSecList.options[0].selected=true;
	}

	//Getting selected item type
	id_item_type=itemTypeList.value

	//Getting selected item category
			id_item_cat=itemCatList.value;

	//Fill the list box with categories of the selected item type
	if(id_item_type > 0)
	{
		if(iseci[id_item_type][id_item_cat])
		{
			var i=0;
			while(iseci[id_item_type][id_item_cat][i])
			{
				//Create new option and add that option to the category list box
				if(navigator.userAgent.match(/IE/))
				{
					opt = document.createElement('Option');

					opt.value=iseci[id_item_type][id_item_cat][i];
					opt.innerText=isecn[id_item_type][id_item_cat][i];

					if(currVal == iseci[id_item_type][id_item_cat][i])
					opt.selected = true;

					itemSecList.appendChild(opt);
				}
				else
				{
					opt= new Option(isecn[id_item_type][id_item_cat][i],iseci[id_item_type][id_item_cat][i]);

					if(currVal == iseci[id_item_type][id_item_cat][i])
					opt.selected = true;

					itemSecList.options.add(opt);
				}

				i++;
			}
		}
	}
}
function checkPage(theForm,pageVal)
{
	if(theForm.gotopage.value.match(/^[0-9]{1,3}$/))
	{
		if(theForm.gotopage.value != 0)
		{
			if(theForm.gotopage.value > pageVal)
			{
				alert(msgPageNotAvailable);
				return false;
			}
			else
				return true;
		}
		else
		{
			alert(notValidPageNumber);
			return false;
		}
	}
	else
	{
		alert(notPageVal);
		return false;
	}
}
/**
Function blinkingText_1() blinkingText_2()
blink the text in given id with different two class and No. of time to blink.
idName=name othe tag id,
className1=Class name that change from one to other,
className2=Class name that display text in original,
nCount=Number of time to blink,
bCount=Take blinking counter so, do not pass from main function call.
*/
function blinkingText_1(idName,className1,className2,nCount,bCount)
{
	if(nCount == '' || isNaN(nCount))
	nCount=3;

	if(bCount == '' || isNaN(bCount))
	bCount=0;

	bCount++;

	document.getElementById(idName).className=className1;
	setTimeout('blinkingText_2("'+idName+'","'+className1+'","'+className2+'","'+nCount+'","'+bCount+'");',500);
}

function blinkingText_2(idName,className1,className2,nCount,bCount)
{
	document.getElementById(idName).className=className2;

	if(bCount < nCount)
	setTimeout('blinkingText_1("'+idName+'","'+className1+'","'+className2+'","'+nCount+'","'+bCount+'");',500);
}
function ShowOrHide(d1, d2)
{
	if (d1 != '')
	{
		var d1_val = d1.split(',');
		for(i=0; i<d1_val.length; i++)
		{
			DoDiv(d1_val[i]);
		}
	}
	if(d2 != '')
	{
		var d2_val = d2.split(',');
		for(i=0; i<d2_val.length; i++)
		{
			DoDiv(d2_val[i]);
		}
	}
}
function DoDiv(id)
{

	var item = null;

	if (document.getElementById)
	{
		item = document.getElementById(id);

	}
	else if (document.all)
	{
		item = document.all[id];
	}
	else if (document.layers)
	{
		item = document.layers[id];
	}

	if (!item) {}
	else if (item.style)
	{
		if (item.style.display == "none")
		{
			item.style.display = "inline";

		}
		else
		{
			item.style.display = "none";
		}
	}
	else
	{
		item.visibility = "show";
	}
}

function loadPageHelp(id,DivId,Fid)
{
	if(nf_fieldHelp[id])
	{
		if(DivId == '')
			DivId = 'HELP2';
		document.getElementById('help_title'+Fid).innerHTML=nf_fieldHelp[id]['title'];
		document.getElementById('help_desc'+Fid).innerHTML=nf_fieldHelp[id]['desc'];
	}
	else
	{
		document.getElementById('help_title'+Fid).innerHTML='';
		document.getElementById('help_desc'+Fid).innerHTML='';
	}

	openDiv(DivId);
}

function openDiv(x)
{
	document.getElementById(x).style.visibility='visible';
}
function closeDiv(x)
{
	document.getElementById(x).style.visibility='hidden';
}

//Function used for  putting limit on Enter  character in textArea.
function ok(maxchars)
{
 	if(document.getElementById('content').value.length  > maxchars)
	{
		document.getElementById('longlen').innerHTML=msgLongReport;
	   return false;
	}
}

function createNIDForm(idUser)
{
    var strIdUser='strIdUser='+idUser;
    new Ajax.Request(site_url+'/createNIDForm.php',{asynchronous:true, parameters:strIdUser,
                            method: 'get',
                            contentType: 'text/xml',
                            onSuccess: function(responseReq)
                            {
                                $('nidReqUser').innerHTML='';
                                $('nidReqUser').innerHTML=responseReq.responseText;
                                document.listNorthId.submit();
                            }
                        }
                    );
    return false;
}
function createNIDFormNewUser()
{
   // var strIdUser='strIdUser='+idUser;
    new Ajax.Request(site_url+'/nidCreateForm.php',{asynchronous:true, method: 'get',
                            contentType: 'text/xml',
                            onSuccess: function(responseReq)
                            {
                                $('nidReqUser').innerHTML='';
                                $('nidReqUser').innerHTML=responseReq.responseText;
                                document.northId.submit();
                            }
                        }
                    );
    return false;
}

//Function to check valid char in string
function checkAllow(str)
{
	if(str.match(/^[a-zA-Z0-9åäöÅÄÖ&\+\-,:;\*€£$\.!\s]{1,40}$/))
		return true;
	else
	{
		alert(msgInvalidText);
		return false;
	}
}

// Function for validating admin entities.
function validateEntity(str)
{
	var re=new RegExp(/\\|\/|@|=|\^|\?|;|:|\[|\]/g);
	if(str != '' && (str.match(/[^0-9a-zA-ZåÅäÄöÖÁÀÉÈÒÓÙÚáàèéòóùúÝìíýÌÍ',-_\.\)\(\>\<\s–]/) || str.match(re)))
	{
		alert(msgInvalidAdminText);
		return false;
	}
	else
		return true;
}

//Save scroll position section start...........................
// Function to save scroll Position on form submit.
function SaveScrollXY(frm)
{
	//var document.fav.ScrollX.value = 0,  document.fav.ScrollY.value =0;
		if( typeof( window.pageYOffset ) == 'number' &&  window.pageYOffset !=0  )
		{
			//Netscape compliant
			frm.ScrollY.value = window.pageYOffset;
			frm.ScrollX.value = window.pageXOffset;
		}
		else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )
		{
			//DOM compliant
			frm.ScrollY.value = document.body.scrollTop;
			frm.ScrollX.value = document.body.scrollLeft;
		}
		else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )
		{
			//IE6 standards compliant mode
			frm.ScrollY.value = document.documentElement.scrollTop;
			frm.ScrollX.value = document.documentElement.scrollLeft;
		}
	}

// Reset form on scrolling Position
function ResetScrollPosition(frm)
{
	var hidx=0, hidy=0;
	hidx=frm.ScrollX.value;
	hidy=frm.ScrollY.value;
	if (typeof hidx != 'undefined' && typeof hidy != 'undefined')
	{
	window.scrollTo(hidx, hidy);
	}
}
//Save scroll position section end...........................

	//sorting+scrolling the form.
function sortScroll(col,ord,frm)
{
	frm.sortCol.value=col;
	frm.ord.value=ord;
	SaveScrollXY(frm);
	frm.submit();
}

