/* $Id: nf_common.js,v 1.56 2011/11/29 05:45:10 neeta Exp $ */

var _su='http://'+location.hostname;

function AjaxUpdater(updateDiv,url,extraAction)
{
    jQuery.get(url,'',function(data){
        if(updateDiv)
            jQuery('#'+updateDiv).html(data);
        if(extraAction)
            eval(extraAction);
    });
    return false;
}
function idiv(i)
{
    return document.getElementById(i);
}

function loadDefault(v1)
{
    if(!v1.value)
    {
        v1.value=textSearch;
    }
}

function check_search()
{
    var lre,rre;

    if(document.search.item_id.value == '')
    {
        /** Why both have value */
        alert(msgEnterOne);
        document.search.item_id.focus();
        return false;
    }
    else
    {
        /** If item id is there */
        if(document.search.item_id.value)
        {
            if(document.search.item_id.value.match(/^[0-9]{1,}$/))
            {
                //Strips blank spaces from left and right
                lre=/^\s*/;
                rre=/\s*$/;

                document.search.item_id.value=document.search.item_id.value.replace(lre,"");
                document.search.item_id.value=document.search.item_id.value.replace(rre,"");

                self.location.replace("listQuickSearchItem.php?q="+document.search.item_id.value+"&quick_search_id="+document.search.quick_search_id.value+"&fws="+document.search.quick_search_id.value);
            }
            else
            {
                alert(msgNumeric);
                document.search.item_id.select();
                document.search.item_id.focus();
                return false;
            }
        }
    }
    return false;
}
function ss_loginmodal()
{
    document.getElementById("que_modal").blur();
    pageURL="http://"+location.hostname+"/modalLogin.php?mainOnly=1&sd=1&ss=1&fwdUrl="+location.href.replace('#','_hash_');

    if (jQuery('#contact').length>0)
        jQuery('#contact').hide();
    jQuery.fn.colorbox({
        href:pageURL,onComplete:function(){jQuery('#loginid').focus();}
    });
}
function ad_loginmodal(opt,rPage)
{
    if(opt == 'N')
    {
        var srchHash=location.href.search("#");
        if(srchHash > 0)
            pageURL=_su+'/modalLogin.php?mainOnly=1&sd=0&fwdUrl='+location.href.replace('#','_hash_');
        else
            pageURL=_su+'/modalLogin.php?mainOnly=1&sd=0&fwdUrl='+location.href;
    }
    else if(opt == 'P')
        pageURL = _su+'/modalLogin.php?mainOnly=1&postad=1';
	else if(opt == 'RP')
	    pageURL = _su+'/modalLogin.php?mainOnly=1&redirectPage='+rPage;
	else if(opt=='LA') //login authentication
        pageURL=_su+'/modalLogin.php?mainOnly=1&redirectPage='+rPage+'&opt='+opt;
	else if(opt == 'POP')
        pageURL=_su+'/modalLogin.php?mainOnly=1&fwdUrl='+rPage+'&opt='+opt;

    if (jQuery('#contact').length>0)
        jQuery('#contact').hide();
    jQuery.fn.colorbox({
        href:pageURL,onComplete:function(){jQuery('#loginid').focus();}
    });
}
function car_quiz()
{
    window.open('carQuiz.php','ap','scrollbars=auto,resizable=yes,width=555,height=700');
    AjaxUpdater('car_quiz',_su+'/updateQuizCount.php');
}
/** Function to increase the hit counter of navigation_ad table */
function navigationHitCounter(id,urlNo)
{
    AjaxUpdater('',_su+'/navigationHitCounter.php?id='+id+'&urlNo='+urlNo);
}
//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;
}

/* newly  added function starts here */
function getCategory(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(s_icati[id_item_type])
	{
		var i=0;
		while(s_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=s_icati[id_item_type][i];
				catOpt.innerText=s_icatn[id_item_type][i];

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

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

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

				itemCatList.options.add(catOpt);
			}

			i++;
		}
	}
}

function getSection(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(s_iseci[id_item_type][id_item_cat])
		{
			var i=0;
			while(s_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=s_iseci[id_item_type][id_item_cat][i];
					opt.innerText=s_isecn[id_item_type][id_item_cat][i];

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

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

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

					itemSecList.options.add(opt);
				}

				i++;
			}
		}
	}
}

function getType(itemTypeList,currVal)
{
	var i=0;
	while(s_itypi[i])
	{
		//Create new option and add that option to the category list box
		if(navigator.userAgent.match(/IE/))
		{
			catOpt = document.createElement('Option');

			catOpt.value=s_itypi[i];
			catOpt.innerText=s_itypn[i];

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

			itemTypeList.appendChild(catOpt);
		}
		else
		{
			catOpt= new Option(s_itypn[i],s_itypi[i]);

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

			itemTypeList.options.add(catOpt);
		}

		i++;
	}
}

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

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

	removeOpt(townList);

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

        /** Puts 'All' caption in case the browser is IE */
        if(navigator.userAgent.match(/IE/) && siteBranch != 'NF')
            townList.options[0].text=capAll;

		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
			{
				if(siteBranch != 'NF')
					townList.options[0] = new Option(capAll);

				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;

			if(siteBranch != 'NF')
				townList.options[0] = new Option(capAll);

            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 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 opens window of desired size by giving proper alert window
function doLogin(msgVar,width,height)
{
	openImg(_su+"/msgWin.php?opt="+msgVar,width,height,'newuser');
}

//Function to submit favorite page by adding/removing items
function submitFav(thisV,siteCode)
{
	frmObj = document.fav;
    var i,flag='N',checked_value,img_id='';

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

	/*	AJAX code starts	*/
	if(thisV != 'remove')
	{
	    jQuery('#loadingImg').css('display', 'inline');
        jQuery('#loadingImg2').css('display', 'inline');

        var pars=jQuery(frmObj).serialize();
        var sub_url = document.fav.action;

        jQuery.post(sub_url,pars,function(str){
            arr=str.split('#');
            jQuery('#loadingImg').hide();
            if(arr[0] != '0')
            {
                jQuery('#favorite_cnt').html('(' + arr[0] + ')');
                if(siteCode == 'NF')
                    jQuery('#favorite_cnt_end').html('(' + arr[0] + ')');
            }
            if(arr[1] != '0')
            {
                jQuery('#common_messageX').html(arr[1] + ' ' + msgAddFav);
                jQuery('#Add_To_Fav_End').html(arr[1] + ' ' + msgAddFav);
            }
            else
            {
                jQuery('#common_messageX').html(msgRptAddFav);
                jQuery('#Add_To_Fav_End').html(msgRptAddFav);
            }
            jQuery('#common_messageX').css('display','block');

            jQuery('#Add_To_Fav_End').css('display','block');
            jQuery('#loadingImg2').hide();
        });

		//	Remove checked items
		for(i=1; i < document.fav.length; i++)
		{
			if(document.fav.elements[i].type == 'checkbox')
			{
				if(document.fav.elements[i].checked)
				{
					document.fav.elements[i].checked = false;
					if(thisV != 'remove')
					{
						checked_value = document.fav.elements[i].value;
                        changeClass(checked_value,'listing');
					}
					continue;
				}
			}
		}
		return false;
	}
	else
	{
		document.fav.submit();
	}
}

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

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=_su+'/index.php';
		}
		else
			return false;
	}
	else
	{
		if(valFile != '')
			location.href=valFile;
		else
			location.href=_su+'/index.php';
	}
}

//Function to give alert to those users who do not use standard browsers
function diffBrowser()
{
	alert(msgDifferentBrowser);
}

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

/* 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;file:///home/akhtar/webroot205/nettikirpputori.com/script.nettikirpputori.com/www/extra/template/nf_common.js

	//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])
		{
            if(document.getElementById('star'))
                document.getElementById('star').style.display='inline';

			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++;
			}
		}
        else
        {
            if(document.getElementById('star'))
                document.getElementById('star').style.display='none';
        }
	}
}
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;
	}
}

//	Functions for changing background color of updated row(s) when posting question or answers for Boats.

function whiteBG()
{
	var elements = document.getElementsByTagName("tr");
	for(var i = 0;i < elements.length;i++)
	{
		if(elements[i].id == "TR_BG" && elements[i].className == "bgyellow" )
		{
			elements[i].className = "bgwhite";
		}
	}
	setTimeout("yellowBG();",500);
}
function yellowBG()
{
	var elements = document.getElementsByTagName("tr");
	for(var i = 0;i < elements.length;i++)
	{
		if(elements[i].id == "TR_BG" && elements[i].className == "bgwhite")
		{
			elements[i].className = "bgyellow";
		}
	}
	setTimeout("oddevenBG();",500);
}
//		Function for doing normal background.
function oddevenBG()
{
	var elements = document.getElementsByTagName("tr");
	for(var i = 0;i < elements.length;i++)
	{
		if(elements[i].id == "TR_BG")
		{
			if(i % 2 == 0)
				elements[i].className = "even";
			else
				elements[i].className = "odd";
		}
	}
}

function modalForm(frmObj,st)
{
	var flag='N';
	var page_from = frmObj.page_from.value;
	var login_page;

	if(page_from.search('simple_dealer') == -1)
		login_page = _su+'/login.php?ajxLogin=1'
	else
		login_page = _su+'/login.php?ajxLogin=1'

	for(i=0; i < frmObj.elements.length;i++)
	{
		if(frmObj.elements[i].type == 'text')
		{
			if(!isblank(frmObj.elements[i].value))
				flag='Y';
		}
	}
	if(frmObj.passwd.value.split(' ').join('').length == 0)
		flag='N';

	if(flag == 'N')
	{
		alert(msgMandet);
		return false;
	}
	if(flag == 'Y')
	{
	    jQuery("input[name=login]").attr('disabled',true);
        jQuery("input[name=btnClose]").attr('disabled',true);
        jQuery("#loadingImgModalLogin").show();
        var pars=jQuery(frmObj).serialize();
        jQuery.post(login_page + ((login_page.indexOf('?') > 0) ? '&' : '?'),pars,function(data){
            if(data == "success")
            {
                if(frmObj.postad.value == 1)
                {
                    if(st == 'KP')
                        window.location.href = _su + '/addEditItemImage.php';
                    else
                        window.location.href = _su + '/postAd.php';
                }
                else if(frmObj.back.value.match(/verifyEmail.php/))
                	window.location.href = frmObj.back.value;
                else if(frmObj.back.value != '' && frmObj.opt.value == 'POP')
                    window.location.href = frmObj.back.value+'#qa';
                else if(frmObj.back.value != '' && frmObj.opt.value == 'LA')
                    window.location.href = frmObj.redirectPage.value;
                else if(frmObj.redirectPage && frmObj.redirectPage.value != '')
                    window.location.href=frmObj.redirectPage.value;
                else
                    window.location.reload();
            }
            else if(data == 'toHomePage')
                location.href = '/';
            else
                jQuery('#msgLoginError').html('<table width="100%" border="0" cellspacing="3" cellpadding="0"><tr><td height="27" class="message">' + data + '</td></tr></table>');
            jQuery("input[name=login]").attr('disabled',false);
            jQuery("input[name=btnClose]").attr('disabled',false);
            jQuery("#loadingImgModalLogin").hide();
        });
	}
	return false;
}
function sd_loginmodal()
{
	pageURL = _su+"/modalLogin.php?mainOnly=1&sd=1";
	if (jQuery('#contact').length>0)
        jQuery('#contact').hide();
    jQuery.fn.colorbox({
        href:pageURL,onComplete:function(){jQuery('#loginid').focus();}
    });
}

function sd_ajaxQue(formObj,var_O)
{
    if(checkQue(formObj,var_O) != false )
    {
        jQuery('#loaderimg').css('display','inline');
        var pars=jQuery(formObj).serialize();
        var answer = formObj.replyToQue.value;
        if(formObj.replyToQue.value == 0)
        {
            formObj.que.disabled=true;
            formObj.exchangeid.disabled=true;
            formObj.save.disabled=true;
            jQuery('#loaderimg').css('display','inline');
        }
        /* replacing € with &euro; */
        pars = 'ajxQueAns=1&ajx=1&'+pars.replace(/%E2%82%AC/g,'%26euro%3B');
        jQuery.post(_su+'/simple_dealer/sd_questionAnswer.php',pars,function(str){

            ary = str.split("$1#2*3#903");
            jQuery('#submitXQA').html(ary[0]);
            var errorMsgId=1;
            if(document.getElementById('errorMsg') && document.getElementById('errorMsg').innerHTML)
                errorMsgId=0;

            if(errorMsgId)
            {
                if(answer == '1')
                    setTimeout("BlinkAnswer(ary[1]);",1000);
                else
                    blinkingText_1('blink_que','blinking_qa','q_odd',3,0);
            }
            else
            {
                jQuery('#askToSeller').css('display','block');
                jQuery('#sendQueLink').attr('class','arrow_hide_small');
            }
            jQuery('#loaderimg').hide();
            initResizeQues('que');

        });
        return false;
    }
    else
        return false;
}
function sd_ajaxLoadImage(id)
{
	var qa_id = id;
	if(document.getElementById('nf_id_user').value == "")
		return false;

	if(checkQue(document.frmqueans) != false )
    {
        var answer = document.frmqueans.replyToQue.value;
        var pars=jQuery(document.frmqueans).serialize();

        if(answer == 1)
        {
            var loader_img_id='loaderimg'+qa_id;
            var ans_id='ans'+qa_id;
            var anssave_id='anssave'+qa_id;

            jQuery('#'+ans_id).attr('disabled',true);
            jQuery('#'+anssave_id).attr('disabled',true);
            jQuery('#'+loader_img_id).css('display','inline');
        }

        /* replacing € with &euro; */
        pars = 'ajxQueAns=1&ajx=1&'+pars.replace(/%E2%82%AC/g,'%26euro%3B');
        jQuery.post(_su+'/simple_dealer/sd_questionAnswer.php',pars,function(data){
            jQuery('#submitXQA').html(data);
            setTimeout("whiteBG();",1000);
        });
        return false;
    }
    else
        return false;
}
//		For Question-Answer part
function ss_ajaxQue(formObj,var_O)
{
	if(checkQue(formObj,var_O) != false )
	{
	    jQuery('#loaderimg').css('display','inline');

	    var pars=jQuery(formObj).serialize();
		if(formObj.replyToQue.value == 0)
		{
			formObj.que.disabled=true;
			formObj.exchangeid.disabled=true;
			formObj.save.disabled=true;
			jQuery('#loaderimg').css('display','inline');
		}
		/* replacing € with &euro; */
		pars = 'ajxQueAns=1&ajx=1&'+pars.replace(/%E2%82%AC/g,'%26euro%3B');

		jQuery.post(_su+'/simple_seller/ss_questionAnswer.php',pars,function(str){
            jQuery('#submitXQA').html(str);
            setTimeout("whiteBG();",1000);
            jQuery('#loaderimg').hide();
            initResizeQues('que_modal');
		});
        return false;
	}
	else
		return false;
}
function ss_ajaxLoadImage(id)
{
	var qa_id = id;
	if(document.getElementById('nf_id_user').value == "")
		return false;

	if(checkQue(document.frmqueans) != false )
	{
	    var answer = document.frmqueans.replyToQue.value;
        var pars=jQuery(document.frmqueans).serialize();

        if(answer == 1)
        {
            var loader_img_id='loaderimg'+qa_id;
            var ans_id='ans'+qa_id;
            var anssave_id='anssave'+qa_id;

            jQuery('#'+ans_id).attr('disabled',true);
            jQuery('#'+anssave_id).attr('disabled',true);
            jQuery('#'+loader_img_id).css('display','inline');
        }
		/* replacing € with &euro; */
        pars = 'ajxQueAns=1&ajx=1&'+pars.replace(/%E2%82%AC/g,'%26euro%3B');

        jQuery.post(_su+'/simple_seller/ss_questionAnswer.php',pars,function(data){
            jQuery('#submitXQA').html(data);
            setTimeout("whiteBG();",1000);
        });
        return false;
	}
	else
		return false;
}

//		Fn. for Login modal
function loginmodal(opt,rPage)
{
	//  D => Simple Dealer , N => From View Page , P => Post Ad, RP => any given redirect page rPage
    if(opt == 'D')
        pageURL=_su+'/modalLogin.php?mainOnly=1&sd=1&fwdUrl='+location.href.replace('#','_hash_');

    else if(opt == 'N')
    {
        var srchHash=location.href.search("#");
        if(srchHash > 0)
            pageURL=_su+'/modalLogin.php?mainOnly=1&sd=0&fwdUrl='+location.href.replace('#','_hash_');
        else
            pageURL=_su+'/modalLogin.php?mainOnly=1&sd=0&fwdUrl='+location.href;
    }
    else if(opt == 'P')
        pageURL=_su+'/modalLogin.php?mainOnly=1&postad=1';
	else if(opt == 'RP')
	    pageURL=_su+'/modalLogin.php?mainOnly=1&redirectPage='+rPage;
    else if(opt != 'P' && location.href.search('advSearch') == -1)
        document.getElementById('que_modal').blur();

    if(jQuery('#que').length>0)
        document.getElementById("que").blur();

    if (jQuery('#contact').length>0)
        jQuery('#contact').hide();
    jQuery.fn.colorbox({
        href:pageURL,onComplete:function(){jQuery('#loginid').focus();}
    });

}
//		Check send link form
function checkFL()
{
	if(isblank(document.sendlink.name.value))
	{
		alert(msgNameBlank);
		document.sendlink.name.focus();
		return false;
	}
	if(!document.sendlink.name.value.match(/^[a-zA-ZåÅäÄöÖÁÀÉÈÒÓÙÚáàèéòóùúÝìíýÌÍ´_\s-]{1,50}$/))
	{
		alert(msgNameBlank);
		document.sendlink.name.focus();
		document.sendlink.name.select();
		return false;
	}
    if(isblank(document.sendlink.userEmail.value))
    {
        alert(msgMandet);
        document.sendlink.userEmail.focus();
        return false;
    }
    else if(!emailInvalid(document.sendlink.userEmail.value))
    {
        alert(msgInvalidEmail);
        document.sendlink.userEmail.focus();
        return false;
    }
    if(isblank(document.sendlink.email.value))
    {
        alert(msgMandet);
        document.sendlink.email.focus();
        return false;
    }
    s=document.sendlink.email.value;
	removeSpace = s.replace(/ /g,"");
    str1=removeSpace.split(',');

    if(str1.length > 10)
    {
        alert(msgMoreThan10Mail);
        document.sendlink.email.focus();
        return false;
    }
    else
    {
        for(var m=0; m<str1.length; m++)
        {
            if(!emailInvalid(str1[m]))
            {
                alert(msgInvalidEmail);
                document.sendlink.email.focus();
                return false;
            }
        }
    }
    return true;
}

/**	To blink question and answers submitted by user */
function BlinkAnswer(str)
{
	var replyId = '';
	ansAry = str.split("#");
	for(var i = 0;i < ansAry.length-1;i++)
	{
		replyId = 'reply' + ansAry[i];
		blinkingText_1(replyId,'blinking_qa','r_odd',3,0);
	}
}

/** Function to change the video status. */
function changeVideoStatus(idAd,videoStatus,idReporter)
{
    var reporterSuffix;

    if(confirm(msgChangeStatus))
    {
        if(idReporter == '')
        {
            reporterSuffix='';
            idReporter='';
        }
        else
            reporterSuffix='_'+idReporter;

        var pars='id_item='+idAd+'&video_status='+videoStatus+'&id_reporter='+idReporter+'&ajxifrm=A';
        AjaxUpdater('vStatus'+idAd+reporterSuffix,_su+'/extra/admin/changeVideoStatus.php?'+pars);
    }
    else
        return;
}

/** Function for confirmation when video ad is delete. */
function confirmVideoDelete(ref)
{
    if(confirm(msgDeleteVideoConfirm))
        window.location.replace(ref);
}

/**
Function to play the video at given id of element.
id_element=>id of element where to display the video.
videoUrl=>viewVideo.php file.
*/
function playVideo(id_element,videoUrl)
{
    AjaxUpdater(id_element,videoUrl+((videoUrl.indexOf('?') > 0) ? '&' : '?')+'ajxifrm=A');
}

function toggleElementDisplay(targetID)
{
    jQuery('#'+targetID).toggle();
}

function chkTxtVal(theForm,strQry,fromWhere)
{
	if(fromWhere == 'NF')
	{
		if(theForm.auctionAds.checked != true)
		{
			if(theForm.q.value.match(/^[0-9]{1,50}$/) && theForm.fws.value == 'A')
			{
				alert(msgIdSearch);
				theForm.fws.focus();
				return false;
			}

			if(theForm.fws.value == 'NF' || !theForm.q.value.match(/^[0-9]{1,50}$/))
				document.solr_search.target='';
			else
				document.solr_search.target='formResults';
		}
	}
    return true;
}

// Change CSS when tab is selected
function menuSwap(onMenu)
{
	var setElementNm='';

	if(document.getElementsByName('searchTabMenu'))
	{
		setElementNm='searchTabMenu';
		setClassNm='menuButton';
	}

	//turn off all buttons
	var menu = document.getElementsByName(setElementNm);

	for (var i = 0; i < menu.length; i++)
	{
		classChange(menu[i].id, setClassNm);
	}

	//turn on current button/layer
	classChange(onMenu, 'onmenuButton');
}

// change class function
function classChange(mytarget, myclass)
{
	if (document.getElementById(mytarget))
		document.getElementById(mytarget).className=myclass;
}
function callAjax(frmObj)
{
   /** for write hidden parameter selected model & selected acc and validate inspected motmonth & motyear */
   var ajaxFName=_su + '/ajaxSearchCounter.php?ajxifrm=A&site=NF';
   var value='';
   if(frmObj.name == 'adv')
   {
       value = ajaxFName+'&frm=ADV&'+ cleanFrmUrl(frmObj);
       jQuery('#loadingImg_src_chngCntAdv').css('display','inline');
   }
   else if(frmObj.name == 'srch')
   {
       value = ajaxFName+'&frm=SIMP&'+ cleanFrmUrl(frmObj);
       jQuery('#loadingImg_src_chngCnt').css('display','inline');
   }
   var ajaxFname=value.replace('/#/ig','@');

   jQuery.get(ajaxFname,'',function(data){
       showResponse(data);
       if(frmObj.name == 'adv')
           jQuery('#loadingImg_src_chngCntAdv').hide();
       else if(frmObj.name == 'srch')
           jQuery('#loadingImg_src_chngCnt').hide();
   });
   return false;
}
/** This function is return whole url with append of selected search criteria*/
function cleanFrmUrl(qs)
{
    var len =qs.elements.length;
    var u='';

    u=u.replace(/\s/g,'-').toLowerCase();

    for(var i = 0; i < len; i++)
    {
        var e=qs.elements[i];

        if(e.name == 'search')
            continue;

        if(e.type == 'select-multiple')
        {
            var si=new Array();
            var count=0;
            var k;
            while (e.selectedIndex != -1)
            {
                if (e.selectedIndex != 0)
                {
                    u=u+e.name+'='+e.options[e.selectedIndex].value+'&';
                    si[count++]=e.selectedIndex;
                }
                e.options[e.selectedIndex].selected=false;
            }
            for(k=0; k<si.length; k++)
                e.options[si[k]].selected=true;
        }
        else if(((e.type == 'checkbox' || e.type == 'radio') && e.checked && e.value))
        {
            u=u+e.name+'='+e.value+'&';
        }
        else if(e.value && !isblank(e.value) && e.type != 'checkbox' && e.type != 'radio')
        {
            if(e.value.indexOf('#') != -1)
                u=u+e.name+'='+escape(e.value)+'&';
            else
                u=u+e.name+'='+e.value+'&';
        }
    }
    return u.substr(0,u.length-1);
}
/** Function to Clean URL */
function cleanRewriteUrl(str)
{
    var rExps=[{re:/[\xC0-\xC6]/gi, ch:'A'},{re:/[\xE0-\xE6]/gi, ch:'a'},{re:/[\xC8-\xCB]/gi, ch:'E'},{re:/[\xE8-\xEB]/gi, ch:'e'},{re:/[\xCC-\xCF]/gi, ch:'I'},{re:/[\xEC-\xEF]/gi, ch:'i'},{re:/[\xD2-\xD6]/gi, ch:'O'},{re:/[\xF2-\xF6]/gi, ch:'o'},{re:/[\xD9-\xDC]/gi, ch:'U'},{re:/[\xF9-\xFC]/gi, ch:'u'},{re:/[\xD1]/gi, ch:'N'},{re:/[\xF1]/gi, ch:'n'},{re:/[^a-zA-Z0-9\/_|+ -]/gi, ch:''},{re:/[\/_| -]+/gi, ch:'-'},{re:/^[-]/gi, ch:''},{re:/[-]$/gi, ch:''}];

    for(var i=0, len=rExps.length; i<len; i++)
        str=str.replace(rExps[i].re, rExps[i].ch);

    return str.toLowerCase();
}
/** This function is return whole url with append of selected search criteria*/
function cleanUrl(qs)
{
    var mk=qs.elements.id_item_type.options[qs.elements.id_item_type.selectedIndex];
    var md=qs.elements.id_item_category.options[qs.elements.id_item_category.selectedIndex];

    if(qs.elements.id_item_section.selectedIndex > 0)
        var sc=qs.elements.id_item_section.options[qs.elements.id_item_section.selectedIndex];

    var atype=qs.elements.ad_type.options[qs.elements.ad_type.selectedIndex];
    var u=_su+'/markkinapaikka';
    var l =qs.elements.length;

    if(mk.value)
        u=u+'/'+cleanRewriteUrl(s_itypn_fi[qs.elements.id_item_type.selectedIndex-1]);
    if(md.value)
        u=u+'/'+cleanRewriteUrl(s_icatn_fi[mk.value][qs.elements.id_item_category.selectedIndex-1]);
    if(qs.elements.id_item_section.selectedIndex > 0)
    {
        if(sc.value)
            u=u+'/'+cleanRewriteUrl(s_isecn_fi[mk.value][md.value][qs.elements.id_item_section.selectedIndex-1]);
    }
    if(atype.value)
    {
        var arrAdtype=new Array();
        arrAdtype['A']='huutokaupataan';
        arrAdtype['F']='myydaan';
        arrAdtype['P']='ostetaan';
        arrAdtype['E']='vaihdetaan';
        arrAdtype['G']='annetaan';
        arrAdtype['C']='vastaanotetaan';
        u=u+'/'+arrAdtype[atype.value];
    }

    u=u+'?';
    u=u.replace(/\s/g,'-').toLowerCase();

    mk.value=md.value=atype.value='';
    if(qs.elements.id_item_section.selectedIndex > 0)
        sc.value='';

    for(var i = 0; i < l; i++)
    {
        var e=qs.elements[i];

        if(e.name!='search')
        {
            if(e.value && e.type == 'hidden')
                u=u+e.name+'='+e.value+'&';
            if((e.value && e.type == 'select-one') ||(e.type == 'checkbox' && e.checked))
                u=u+e.name+'='+e.value+'&';
            if(e.type == 'select-multiple')
            {
                while (e.selectedIndex != -1)
                {
                    if (e.selectedIndex != 0)
                        u=u+e.name+'='+e.options[e.selectedIndex].value+'&';
                    e.options[e.selectedIndex].selected = false;
                }
            }
        }
    }
    return u.substr(0,u.length-1);

}

/** This function is return whole url with append of selected search criteria*/
function cleanUrlFunc(qs)
{
    var mk=qs.elements.id_item_type.options[qs.elements.id_item_type.selectedIndex];
    var md=qs.elements.id_item_category.options[qs.elements.id_item_category.selectedIndex];
    var sc=qs.elements.id_item_section.options[qs.elements.id_item_section.selectedIndex];

    if(qs.elements.id_item_section.selectedIndex > 0)
        var sc=qs.elements.id_item_section.options[qs.elements.id_item_section.selectedIndex];

    var atype=qs.elements.ad_type.options[qs.elements.ad_type.selectedIndex];
    var u=_su+'/markkinapaikka';
    var l =qs.elements.length;

    if(mk.value)
        u=u+'/'+mk.title;
    if(md.value)
        u=u+'/'+md.title;
    if(sc.value)
        u=u+'/'+sc.title;

    if(atype.value)
    {
        var arrAdtype=new Array();
        arrAdtype['A']='huutokaupataan';
        arrAdtype['F']='myydaan';
        arrAdtype['P']='ostetaan';
        arrAdtype['E']='vaihdetaan';
        arrAdtype['G']='annetaan';
        arrAdtype['C']='vastaanotetaan';
        u=u+'/'+arrAdtype[atype.value];
    }

    u=u+'?';
    u=u.replace(/\s/g,'-').toLowerCase();

    mk.value=md.value=atype.value='';
    if(qs.elements.id_item_section.selectedIndex > 0)
        sc.value='';

    for(var i = 0; i < l; i++)
    {
        var e=qs.elements[i];

        if(e.name!='search')
        {
            if(e.value && e.type == 'hidden')
                u=u+e.name+'='+e.value+'&';
            if((e.value && e.type == 'select-one') ||(e.type == 'checkbox' && e.checked))
                u=u+e.name+'='+e.value+'&';
            if(e.type == 'select-multiple')
            {
                while (e.selectedIndex != -1)
                {
                    if (e.selectedIndex != 0)
                        u=u+e.name+'='+e.options[e.selectedIndex].value+'&';
                    e.options[e.selectedIndex].selected = false;
                }
            }
        }
    }
    return u.substr(0,u.length-1);
}

/** 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;
}

function getDomTown(domVal,curval,page,sCode)
{
	var townStr='';
	var site='';
	var townUrl='http://'+location.hostname+'/ajaxGetDomicileTown.php?ajxifrm=A&frm='+page+'&';

   	if(curval) townStr='&sel_id_town='+curval;
	if(sCode) site='&site='+sCode;

	if(page == 'ADV')
		AjaxUpdater('adv_id_town',townUrl+'id_domicile='+domVal+townStr+site,"callAjax(document.adv);");
	else if(page == 'SIMP')
		AjaxUpdater('srch_id_town',townUrl+'id_domicile='+domVal+townStr);
	else if(page == 'POST')
		AjaxUpdater('post_id_town',townUrl+'id_domicile='+domVal+townStr+site);
	else if(page == 'listService')
		AjaxUpdater('service_id_town',townUrl+'id_domicile='+domVal+townStr);
	else if(page=='EDIT_DEALER')
		AjaxUpdater('dealer_id_town',townUrl+'id_domicile='+domVal+townStr);
}

/** Function to open the new window with given width and height */
function openNewWin(varUrl,w,h,varTitle,varLeft,varTop)
{
    var varLeft,varTop;
    if(varLeft == '')
        varLeft='0';

    if(varTop == '')
        varTop='0';

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

    if(varTitle == '')
        varTitle='new';

    var newWin=window.open(varUrl,varTitle,myfeatures);
    newWin.focus();
}

function ajaxListChange(frmObj,chgFor,efs)
{
    var efs,pars;
    var pars=jQuery(frmObj).serialize();
    if(typeof efs == 'undefined') efs='';

    pars +='&chgFor=' + chgFor + '&ajxr=A' + efs + '&frm=' + frmObj.name;

    jQuery.post(_su+'/ajaxChangeEntity.php',pars,function(data){
        showTextResponse(data);
        if(frmObj.name == 'srch' || frmObj.name == 'adv')
            callAjax(frmObj);
    });
    return false;
}
function moveToSite(siteNm)
{
    var dropdownIndex = document.getElementById('site_list').selectedIndex;
    var dropdownValue = document.getElementById('site_list')[dropdownIndex].value;

    jQuery('#site_list option:selected').dblclick();
}
function showHideCat()
{
    if(document.getElementById('search_catbox').style.display == 'none')
    {
        jQuery('#search_catbox').css('display','block');
        jQuery('#search_area_box').css('display','none');
    }
    else
        jQuery('#search_catbox').css('display','none');

    if(document.getElementById('search_cat_id').className == 'catsearch_none')
        document.getElementById('search_cat_id').className='catsearch';
    else
        document.getElementById('search_cat_id').className='catsearch_none';
}
function submitQSForm(statVal,selfLink,facet_home)
{
       jQuery('#loadingImg_search').css('display','inline');
       var pars = 'categroy='+ statVal +'&facetHome='+ facet_home +'&ajxReq=1';
       jQuery.get('http://' + document.domain + '/simpleSearchIframe.php',pars,function(data){
           jQuery('#adv_box_option').html(data);
           jQuery('#loadingImg_search').hide();
       });
}

//function ajaxcall(formObj,containerName)
//{
//    formObj.ajxifrm.value = 'A';
//    var pars=jQuery(formObj).serialize();
//    jQuery.fn.colorbox.close();
//    jQuery.post('http://'+location.hostname+'/viewItem.php',pars,function(data){
//        jQuery('#'+containerName).html(data);
//    });
//    return false;
//}
function create_captchaImg()
{
    jQuery.get(_su+'/createCaptchaImg.php','',function(data){
        jQuery('#captcha_image').html(data);
    });
}
function callUpdater(container,itemType)
{
    if(container == 'show_sell')
    {
        var item_type = document.getElementById(itemType).value;
        jQuery('#scheduled_list,#active_list,#sold_list,#unsold_list').hide();
        if(item_type == 'scheduled')
            jQuery('#scheduled_list').css('display','block');
        else if(item_type == 'selling')
            jQuery('#active_list').css('display','block');
        else if(item_type == 'sold')
            jQuery('#sold_list').css('display','block');
        else if(item_type == 'unsold')
            jQuery('#unsold_list').css('display','block');
        else
        {
            jQuery('#scheduled_list').css('display','block');
            jQuery('#active_list').css('display','block');
            jQuery('#sold_list').css('display','block');
            jQuery('#unsold_list').css('display','block');
        }
    }
    else
    {
        var buy_type = document.getElementById(itemType).value;
        jQuery('#id_bid_item,#id_won_item,#id_notwon_item').hide();
        if(buy_type == 'bidding')
            jQuery('#id_bid_item').css('display','block');
        else if(buy_type == 'won')
            jQuery('#id_won_item').css('display','block');
        else if(buy_type == 'notwon')
            jQuery('#id_notwon_item').css('display','block');
        else
        {
            jQuery('#id_bid_item').css('display','block');
            jQuery('#id_won_item').css('display','block');
            jQuery('#id_notwon_item').css('display','block');
        }
    }
}
if (typeof jQuery != 'undefined')
{
    jQuery(document).ready(function(){
        if(jQuery('#searchAreaHeader').length>0)
            jQuery('#searchAreaHeader').bind('click',function(){toggleElementDisplay('search_area_box');});

        jQuery('#q.search_box').mouseover(function(){jQuery('#search_bubble').show();});
        jQuery('#q.search_box').mouseout(function(){jQuery('#search_bubble').hide();});
    });
}

function cacheMapDealer(imgpath)
{
    mapDealer[0]=new Image(167,312); mapDealer[0].src=imgpath+'/map/map.gif';
    mapDealer[1]=new Image(167,312); mapDealer[1].src=imgpath+'/map/map1.gif';
    mapDealer[2]=new Image(167,312); mapDealer[2].src=imgpath+'/map/map2.gif';
    mapDealer[3]=new Image(167,312); mapDealer[3].src=imgpath+'/map/map3.gif';
    mapDealer[4]=new Image(167,312); mapDealer[4].src=imgpath+'/map/map4.gif';
    mapDealer[5]=new Image(167,312); mapDealer[5].src=imgpath+'/map/map5.gif';
    mapDealer[6]=new Image(167,312); mapDealer[6].src=imgpath+'/map/map6.gif';
    mapDealer[7]=new Image(167,312); mapDealer[7].src=imgpath+'/map/map7.gif';
    mapDealer[8]=new Image(167,312); mapDealer[8].src=imgpath+'/map/map8.gif';
    mapDealer[9]=new Image(167,312); mapDealer[9].src=imgpath+'/map/map9.gif';
    mapDealer[10]=new Image(167,312); mapDealer[10].src=imgpath+'/map/map10.gif';
    mapDealer[11]=new Image(167,312); mapDealer[11].src=imgpath+'/map/map11.gif';
    mapDealer[12]=new Image(167,312); mapDealer[12].src=imgpath+'/map/map12.gif';
    mapDealer[13]=new Image(167,312); mapDealer[13].src=imgpath+'/map/map13.gif';
    mapDealer[14]=new Image(167,312); mapDealer[14].src=imgpath+'/map/map14.gif';
    mapDealer[15]=new Image(167,312); mapDealer[15].src=imgpath+'/map/map15.gif';
    mapDealer[16]=new Image(167,312); mapDealer[16].src=imgpath+'/map/map16.gif';
    mapDealer[17]=new Image(167,312); mapDealer[17].src=imgpath+'/map/map17.gif';
    mapDealer[20]=new Image(167,312); mapDealer[20].src=imgpath+'/map/map20.gif';
    mapDealer[21]=new Image(167,312); mapDealer[21].src=imgpath+'/map/map21.gif';
    mapDealer[23]=new Image(167,312); mapDealer[23].src=imgpath+'/map/map23.gif';
    mapDealer[24]=new Image(167,312); mapDealer[24].src=imgpath+'/map/map24.gif';
}
function changeMapDealer(thisChoice)
{
    if (document.getElementById)
    {
        if(thisChoice == "" || thisChoice > 24)
            thisChoice=0;

        var dealerMap=document.getElementById("dealerMap");
        dealerMap.src=mapDealer[Number(thisChoice)].src;
    }
}
function check_dealer()
{
    if(isblank(document.searchDealer.search_dealer.value))
    {
        alert(msgBlankDealer);
        document.searchDealer.search_dealer.focus();
        return false;
    }
}
/** Function to display the list dealer of particular domicile. */

function openHideDomicile(domeName,domeId,fromWhichSt)
{
    var checkAjaxId='checkAjax_'+domeId;
    var imgLinkId=domeName+'_'+domeId;
    var AjaxLoaderId='loadingImg_'+domeId;
    /** Check weather list display using ajax request OR normal show/hide id. */
    if(jQuery('#'+checkAjaxId).attr("class") == checkAjaxId)
    {
        if(document.getElementById(domeName).style.display == 'none')
        {
            document.getElementById(domeName).style.display='block';           ;
            jQuery('#'+imgLinkId).attr({title:C_HIDE,'class':'arrow_hide'});
        }
        else
        {
            document.getElementById(domeName).style.display='none';
            jQuery('#'+imgLinkId).attr({title:C_OPEN,'class':'arrow_open'});
        }
    }
    else
    {
        jQuery('#'+AjaxLoaderId).css('display','inline');
        var pars='ajxifrm=A&id_domicile='+domeId+'&domeName='+domeName+'&fromWhichSt='+fromWhichSt;
        jQuery.get('http://'+location.hostname+'/ajaxListDealer.php',pars,function(data){

            jQuery('#'+domeName).html(data);
            jQuery('#'+domeName).show();

            jQuery('#'+checkAjaxId).attr('class',checkAjaxId);
            jQuery('#'+imgLinkId).attr({title:C_HIDE,'class':'arrow_hide'});

            jQuery('#'+AjaxLoaderId).hide();
        });
        return false;
    }
     return false;
}
/**
Function to open/hide whole domicile list dealer.
var openAll='Y' set global variable for check hide/openall domicile.
*/
function openHideAllDomicile(fromWhichSt)
{
    if(idDomJs)
    {
        /** Check weather list display using ajax request OR normal show/hide id. */
        if(jQuery('#checkAjax_open_hide').attr("class") == 'ajax_done')
        {
            for(var i=0; i<idDomJs.length; i++)
            {
                arrDomInfo=(idDomJs[i]).split('@');
                var domeId=arrDomInfo[0];
                var domeName=arrDomInfo[1];
                var checkAjaxId='checkAjax_'+domeId;
                var imgLinkId=domeName+'_'+domeId;
                var AjaxLoaderId='loadingImg_'+domeId;

                if(openAll == 'Y')
                {
                    jQuery('#'+domeName).show();
                    jQuery('#'+imgLinkId).attr({title:C_HIDE,'class':'arrow_hide'});
                }
                else
                {
                    jQuery('#'+domeName).hide();
                    jQuery('#'+imgLinkId).attr({title:C_OPEN,'class':'arrow_open'});
                }
            }
            if(openAll == 'Y')
            {
                openAll='N';
                jQuery('#open_hide').attr({href:'http://'+location.hostname+'/listDealer.php',title:C_HIDE_ALL,'class':'arrow_hide'});
                jQuery('#open_hide').html(C_HIDE_ALL);
            }
            else
            {
                openAll='Y';
                jQuery('#open_hide').html(C_OPEN_ALL);
                jQuery('#open_hide').attr({href:'http://'+location.hostname+'/listDealer.php?opt=open_all',title:C_OPEN_ALL,'class':'arrow_open'});
            }
        }
        else
        {
            jQuery('#loadingImg_open_hide').show();
            var strIdDomJs='';

            for(var i=0; i<idDomJs.length; i++)
            {
                arrDomInfo=(idDomJs[i]).split('@');
                strIdDomJs +=arrDomInfo[0]+',';
            }
            strIdDomJs=strIdDomJs.slice(0,-1);

            var pars='ajxifrm=A&open_hide=all&strIdDom='+strIdDomJs+'&fromWhichSt='+fromWhichSt;
            jQuery.get('http://'+location.hostname+'/ajaxListDealer.php',pars,function(data){

                jQuery('#open_hide_all').html(data);
                jQuery('#checkAjax_open_hide').attr('class','ajax_done');

                openAll='N';
                jQuery('#open_hide').attr({href:'http://'+location.hostname+'/listDealer.php',title:C_HIDE_ALL,'class':'arrow_hide'});
                jQuery('#open_hide').html(C_HIDE_ALL);

                jQuery('#loadingImg_open_hide').hide();
            });
            return false;
        }
         return false;
    }
}
function checkVal(theForm)
{
    if(isblank(theForm.fmt_name.value))
    {
        document.getElementById('fmt_name').className='highlight';
        document.getElementById('fmt_nameimg').className='hlightimage';

        alert(msgMandet);
        theForm.fmt_name.focus();

        return false;
    }
    else if(theForm.fmt_name.value.match(/^([0-9]+)$/))
    {
        document.getElementById('fmt_name').className='highlight';
        document.getElementById('fmt_nameimg').className='hlightimage';

        alert(msgNotNumericName);
        theForm.fmt_name.focus();

        return false;
    }
    else if(theForm.fmt_name && !(theForm.fmt_name.value.match(/^([a-zA-Z0-9-_\s]+)$/)))
    {
        document.getElementById('fmt_name').className='highlight';
        document.getElementById('fmt_nameimg').className='hlightimage';

        alert(msgInvlidName);
        theForm.fmt_name.focus();

        return false;
    }

    if(isblank(theForm.fmt_url.value))
    {
        document.getElementById('fmt_url').className='highlight';
        document.getElementById('fmt_urlimg').className='hlightimage';

        alert(msgMandet);
        theForm.fmt_url.focus();

        return false;
    }
    else if(theForm.fmt_url.value.match(/^([0-9]+)$/))
    {
        document.getElementById('fmt_url').className='highlight';
        document.getElementById('fmt_urlimg').className='hlightimage';

        alert(msgNotNumeric);
        theForm.fmt_url.focus();

        return false;
    }
    else if(theForm.fmt_url && !(theForm.fmt_url.value.match(/^([a-zA-Z0-9-_]+)$/)))
    {
        document.getElementById('fmt_url').className='highlight';
        document.getElementById('fmt_urlimg').className='hlightimage';

        alert(msgInvlidURL);
        theForm.fmt_url.focus();

        return false;
    }
    return true;
}
function submitSelectionFormPostAd(theForm)
{
    document.attachimg.submit();
}

function displayImageUploadPostAd(val)
{
    if(val == 'YES')
    {
        document.getElementById("image").style.display = 'block';

        if(document.getElementById("attached_img"))
            document.getElementById("attached_img").style.display = 'block';

        document.getElementById("continue").style.display = 'none';
        document.getElementById("dispBubbleForSaleAd").style.display = 'block';

        idiv('old_link').childNodes[0].href=idiv('old_link').childNodes[0].href.replace('without_img_post=Y','without_img_post=N');
    }
    if(val == 'NO')
    {
        document.getElementById("image").style.display = 'none';

        if(document.getElementById("attached_img"))
            document.getElementById("attached_img").style.display = 'none';

        document.getElementById("continue").style.display = 'block';
        document.getElementById("contButInst").style.display = 'block';
        document.getElementById("dispBubbleForSaleAd").style.display = 'none';

        idiv('old_link').childNodes[0].href=idiv('old_link').childNodes[0].href.replace('without_img_post=N','without_img_post=Y');
    }
}
function submitSelectionForm(statVal)
{
    window.location="http://" + document.domain + "/listFavoriteItem.php?fav_listSite=" + statVal;
}
function ShowReasonDiv()
{
    document.getElementById('id_reason').style.display='table';
    document.getElementById('high_bid').style.display ='none';
}

function HideReasonDiv()
{
    document.getElementById('id_reason').style.display ='none';
    document.getElementById('high_bid').style.display ='inline';
}

function endAuction(askReasonFlg)
{
    if(askReasonFlg == 'Y')
    {
        for (var i=0; i < document.end_auction.auc_end_reason.length; i++)
        {
            if (document.end_auction.auc_end_reason[i].checked)
            {
                var rad_val = document.end_auction.auc_end_reason[i].value;
            }
        }

        if(rad_val == 'C')
        {
            if(!confirm(msgCancelBid))
                return false;
        }
        else
        {
            if(!confirm(msgEndAuction))
                return false;
        }
    }
    else
    {
        if(askReasonFlg == 'NB')
        {
            if(!confirm(msgEndAuctionWithouBid))
                return false;
        }
        else
        {
            if(!confirm(msgEndAuction))
                return false;
        }
    }
}
function checkBid(theForm,idSeller,fromWhere)
{
    if(fromWhere == 'V')
    {
        if(!confirm(buyNowConfirmation))
            return false;
    }
    else if(fromWhere == 'B')
    {
        if(!confirm(bidNowConfirmation))
            return false;
    }

    if(theForm.id_user.value == '')
    {
        if(theForm.bid_amount.value == '')
        {
            alert(msgBlnkBid);
            theForm.bid_amount.focus();
            return false;
        }
        else
        {
            if(!theForm.bid_amount.value.match(/^(\d+)(\.|)(\d*){1,10}$/))
            {
                alert(msgInvldBid);
                theForm.bid_amount.select();
                return false;
            }
            if(theForm.id_user.value == idSeller)
            {
                alert(msgNoBuyOwnItem);
                theForm.bid_amount.select();
                return false;
            }
        }

        if(Number(theForm.bid_amount.value) < Number(theForm.bid_price.value))
        {
            alert(msgInvldBid);
            theForm.bid_amount.select();
            return false;
        }
        else if(Number(theForm.max_bid_amount.value) >= Number(theForm.bid_amount.value))
        {
            alert(msgMaxBidInstr);
            theForm.bid_amount.select();
            return false;
        }
    }
    bidamt = theForm.bid_amount.value;

    if(bidamt.indexOf('.') > 0)
            seperation = bidamt.length - bidamt.indexOf('.') -1;
    if(seperation > 2)
    {
        alert(msgInvalidDecimalPrice);
        theForm.bid_amount.select();
        return false;
    }
}
function ShowHideAllCat(stCode)
{
    if(jQuery('#cat_short_txt_'+stCode).is(':visible')==false)
    {
        jQuery('#cat_short_txt_'+stCode).css('display','block');
        jQuery('#cat_full_txt_'+stCode).css('display','none');
    }
    else if(jQuery('#cat_short_txt_'+stCode).is(':visible')==true)
    {
        jQuery('#cat_short_txt_'+stCode).css('display','none');
        jQuery('#cat_full_txt_'+stCode).css('display','block');
    }
    return false;
}
function callAddVehicle(mlink)
{
   var eleValue='';

   if(document.getElementById('sel_ad_type'))
       eleValue=document.getElementById('sel_ad_type');
   else
       eleValue=document.attachimg.ad_type;

   if(eleValue.value == 'S')
   {
       alert(msgSelectAdType);
       return false;
   }
   document.attachimg.action=mlink;
   document.attachimg.submit();
   return false;
}
function callPage(url)
{
    window.location.href = url;
}
function callCatPage(siteLink,catLink)
{
    if(catLink != '')
        window.location.href = _su+'/'+siteLink+'/'+catLink;
    else
        window.location.href = _su+'/'+siteLink;
}
