/* $Id: nt_common.js,v 1.39 2010/03/11 04:34:06 hetal Exp $ */

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

function createXHR()
{
   try { return new XMLHttpRequest(); } catch(e) {}
   try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch (e) {}
   try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch (e) {}
   try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
   return null; // no XHR support
}

function AjaxUpdater(updateDiv,url,extraAction)
{
    var xhr = createXHR();
    xhr.open("GET", url, true)
    xhr.setRequestHeader("Content-Type", "text/html;charset=UTF-8");

    xhr.onreadystatechange=function()
    {
        if(xhr.readyState == 4)
        {
            if(updateDiv)
                idiv(updateDiv).innerHTML=xhr.responseText;
            if(extraAction)
                eval(extraAction);
        }
    }
    xhr.send(null);
    return false;
}

function idiv(i)
{
    return document.getElementById(i);
}

/** Function for show/hide more search criteria */
function display_search()
{
    if(idiv('adv_option').style.display == 'inline')
        idiv('adv_option').style.display = 'none';
    else
        idiv('adv_option').style.display = 'inline';
}

/** To popup message while removing logo of record */
function confirmDelLogo(ref)
{
    if(confirm(msgDeleteLogoConfirm))
        window.location.replace(ref);
}
function check_search()
{
    vehidRegno=document.search.veh_id_reg_no.value;

    /* Strips blank spaces from left and right */
    var lre=/^\s*/;
    var rre=/\s*$/;

    vehidRegno=vehidRegno.replace(lre,"");
    vehidRegno=vehidRegno.replace(rre,"");

    if(isblank(vehidRegno))
    {
        /*   When input field is blank  */
        alert(msgBlankSearchVehicle);
        document.search.veh_id_reg_no.focus();
        return false;
    }
    else if(vehidRegno.match(/^[0-9]{1,}$/))
    {
        location.href=_su+"/viewVehicle.php?id_travel_truck="+vehidRegno;
    }
    else if(vehidRegno.match(/^([a-zA-ZäÄÖöÅå]{1,3})([0-9]{1,3})$/) || vehidRegno.match(/^([a-zA-ZäÄÖöÅå]{1,3})-([0-9]{1,3})$/) || vehidRegno.match(/^([0-9]{1,3})([a-zA-ZZäÄÖöÅå]{1,3})$/) || vehidRegno.match(/^([0-9]{1,3})-([a-zA-ZZäÄÖöÅå]{1,3})$/))
    {
        location.href=_su+"/viewVehicle.php?reg_no="+vehidRegno;
    }
    else
    {
        alert(msgInvalidIdRegno);
    }
    return false;
}

function getPage(){
  url    = window.location.href;
  page   = window.location.href.toString().match(/\/([^\/]+)(#)?$/)[1];
  page   = page.replace(/\W/g,"");
  return page;
}
function maintainScrollUnload(e){
  page = getPage();
  var date = new Date()
  var date = new Date()
  var expdate = date.getTime()
  expdate += 5*60*1000; //expires in 5 minutes(milliseconds)
  date.setTime(expdate);

  if(page.match(/^(simpleSearch|listVehicle|listAdvSearchFindAgent|listCategory)/)){
    document.cookie = 'scroll=' +page+ document.documentElement.scrollTop
                    + "; expires="+ date.toGMTString();
  }
  if(page.match(/^viewVehicle/)){
    document.cookie = "prevpage="+page + "; expires="+ date.toGMTString();
  }
}
function maintainScrollLoad(){
  var page=getPage();
  if( document.cookie.match(/prevpage=viewVehiclephp/ ) ){
    var reg = new RegExp( "scroll="+page + "(\\d+)" );
    if( scroll = document.cookie.match(reg) ){
      document.documentElement.scrollTop=scroll[1]-50;
    }
  }
}
if(!window.location.href.toString().match(/\/$/) && navigator.userAgent.indexOf('Firefox') > 0){
    if (window.addEventListener) {
      window.addEventListener("load", maintainScrollLoad, false);
      window.addEventListener("beforeunload", maintainScrollUnload, false);
    }
}
function car_quiz()
{
    window.open(_su+'/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);
}
// This method is Used in Simple Search and Vehicle Post forms.
var textureName='';
var optChar='';
var optGroup='';
var textureGroup='';
var make_opt='';

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

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

    // This IF blocks are getting used in navigation From NA to other Nettix sites
    // Used in posting, simple search and Adv Search
    if(v1 && v1.options[v1.selectedIndex].value == 20)
    {
        v1.selectedIndex=0;

        if(cond != 'POST')
        {
            if(varaosaUrl.match(/login\.php/))
                varaosaUrl2=varaosaUrl.replace(/\/login(.*)/,'/listPart.php');
            else
                varaosaUrl2=varaosaUrl+'/listPart.php';

            window.open(varaosaUrl2);
        }
        else
            window.open(varaosaUrl+'&back=addEditPartImage.php');

        return;
    }
    else if(v1 && v1.options[v1.selectedIndex].value == 21)
    {
        v1.selectedIndex=0;

        if(cond != 'POST')
        {
            if(motoUrl.match(/login\.php/))
                motoUrl2=motoUrl.replace(/\/login(.*)/,'/listCategory.php?id=2');
            else
                motoUrl2=motoUrl+'/listCategory.php?id=2';

            window.open(motoUrl2);
        }
        else
            window.open(motoUrl+'&back=addEditVehicleImage.php');

        return;
    }
    else if(v1 && v1.options[v1.selectedIndex].value == 22)
    {
        v1.selectedIndex=0;

        if(cond != 'POST')
        {
            if(motoUrl.match(/login\.php/))
                motoUrl2=motoUrl.replace(/\/login(.*)/,'/listCategory.php?id=3');
            else
                motoUrl2=motoUrl+'/listCategory.php?id=3';

            window.open(motoUrl2);
        }
        else
            window.open(motoUrl+'&back=addEditVehicleImage.php');

        return;
    }
    else if(v1 && v1.options[v1.selectedIndex].value == 23)
    {
        v1.selectedIndex=0;

        if(cond != 'POST')
        {
            if(boatUrl.match(/login\.php/))
                boatUrl2=boatUrl.replace(/\/login(.*)/,'/listBoat.php');
            else
                boatUrl2=boatUrl+'/listBoat.php';

            window.open(boatUrl2);
        }
        else
            window.open(boatUrl+'&back=addEditBoatImage.php');

        return;
    }
    else if(v1 && v1.options[v1.selectedIndex].value == 27)
    {
        v1.selectedIndex=0;

        if(cond != 'POST')
        {
            if(boatUrl.match(/login\.php/))
                koneUrl2=koneUrl.replace(/\/login(.*)/,'/listMachine.php');
            else
                koneUrl2=koneUrl+'/listMachine.php';

            window.open(koneUrl2);
        }
        else
            window.open(koneUrl+'&back=addEditMachineImage.php');

        return;
    }
    else if(v1 && v1.options[v1.selectedIndex].value == 28)
    {
        v1.selectedIndex=0;

        if(cond != 'POST')
        {
            if(koneUrl.match(/login\.php/))
                koneUrl2=koneUrl.replace(/\/login(.*)/,'/simpleSearch.php?status=F&id_machineType=1&id_ssub_type=4');
            else
                koneUrl2=koneUrl+'/simpleSearch.php?status=F&id_machineType=1&id_ssub_type=4';

            window.open(koneUrl2);
        }
        else
            window.open(koneUrl+'&back=addEditMachineImage.php');

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

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

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

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

        for(i=0; i < m1.length; i++)
        {
            goFlag=0;
            arrMakeInfo=(m1[i]).split('#');
            arrMakeTypeInfo=(arrMakeInfo[3]).split(',');

            for(k=0; k < arrMakeTypeInfo.length; k++)
            {
                if(arrMakeTypeInfo[k] == vehicleid)
                    goFlag=1;
            }
            if(goFlag == 0)
                continue;

            var make_value=arrMakeInfo[0];
            var make_text=arrMakeInfo[1];

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

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

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

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

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

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

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

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

        for(i=0; i < m1.length; i++)
        {
            arrMakeInfo=(m1[i]).split('#');

            if(arrMakeInfo[2] > 0 || cond == 'ADV')
            {
                var make_value=arrMakeInfo[0];
                var make_text=arrMakeInfo[1];

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

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

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

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

                    textureGroup.appendChild(make_opt);
                }
                else
                {
                    makeOpt=new Option(make_text,make_value);
                    eval('v2.options[j]=makeOpt');
                }
                // Option group part ends here
                if(id_make == make_value)
                    v2.selectedIndex=j;

                j++;
            }
        }
    }
}

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

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

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

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

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

                    modelOpt=new Option(make_text,make_value);
                    eval('v2.options[j++]=modelOpt');
                }
            }
        }

        if(m[makeid])
        {
            arrModel=(m[makeid]).split(',');

            for(i=0; i < arrModel.length; i++)
            {
                var model_id=arrModel[i];

                arrModelInformation=(c[model_id]).split('#');
                var model_value=model_id;
                var model_text=arrModelInformation[0];
                var goFlag=0;

                // Simple Search
                if(cond == 'Y')
                {
                    if(vehicleid != '')
                    {
                        // When Vehicle Type is also selected then get models for that Vehicle Type only
                        arrVehicleTypeCounter=arrModelInformation[2].split(/[@,]/);

                        for(k=0; k < arrVehicleTypeCounter.length; k++,k++)
                        {
                            if(arrVehicleTypeCounter[k] == vehicleid && arrVehicleTypeCounter[k+1] > 0)
                            {
                                goFlag=1;
                                break;
                            }
                        }
                    }
                    else
                    {
                        if(arrModelInformation[1] > 0)
                            goFlag=1;
                    }
                }
                else
                {
                    if(cond == 'ADV')
                        goFlag=1;
                    else if(vehicleid != '')
                    {
                        // Vehicle Posting
                        arrVehicleTypeCounter=arrModelInformation[2].split(/[@,]/);

                        for(k=0; k < arrVehicleTypeCounter.length; k++,k++)
                        {
                            if(arrVehicleTypeCounter[k]==vehicleid && arrVehicleTypeCounter[k+1] >= 0)
                            {
                                goFlag=1;
                                break;
                            }
                        }
                    }
                    else    // Admin -> Normal Vehicle Search (Without Vehicle Type)
                        goFlag=1;
                }

                if(goFlag == 1)
                {
                    modelOpt=new Option(model_text,model_value);
                    eval('v2.options[j]=modelOpt');

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

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

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

/** Select DriveType using Selected Base */
function baseChange(vehicleType,vBase,driveType,selectedDType)
{
    driveType.length=0;

    if(vehicleType[vehicleType.selectedIndex].value != 13)
    {
        if(vBase.selectedIndex != 0)
        {
            strDtype=new String(bdt[vBase[vBase.selectedIndex].value])
            arrDtype=strDtype.split(',');

            for(i=0; i < arrDtype.length; i++)
            {
                var dTypeTxt=dv[arrDtype[i]];
                var dTypeVal=arrDtype[i];

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

                if(selectedDType == dTypeVal)
                    driveType.selectedIndex=i;
            }
        }
    }
}
/** Function to used in simple search to display make related posted base. */
function makeBaseChange(vehicleType,baseObj,vMake,selectedBase)
{
    if(vehicleType[vehicleType.selectedIndex].value == 14 || vehicleType[vehicleType.selectedIndex].value == '')
    {
        baseObj.length=1;
        var j=1;

        if(vMake.selectedIndex != 0)
        {
            if(mbc[vMake[vMake.selectedIndex].value])
            {
                strMkBaseCnt=new String(mbc[vMake[vMake.selectedIndex].value])
                arrMkBaseCnt=strMkBaseCnt.split(',');

                for(i=0; i<arrMkBaseCnt.length; i++)
                {
                    arrBaseInfo=arrMkBaseCnt[i].split('@');

                    if(arrBaseInfo[1] > 0)
                    {
                        var baseTxt=bs[arrBaseInfo[0]];
                        var baseVal=arrBaseInfo[0];

                        selOpt=new Option(baseTxt,baseVal);
                        eval('baseObj.options[j]=selOpt');

                        if(selectedBase == baseVal)
                            baseObj.selectedIndex=j;

                        j++;
                    }
                }
            }
        }
        else /** If there is no make selected then display all base having counter > 0 */
        {
            for(i=0; i<b1.length; i++)
            {
                arrBaseInfo=b1[i].split('#');

                if(arrBaseInfo[2] > 0)
                {
                    var baseTxt=arrBaseInfo[1];
                    var baseVal=arrBaseInfo[0];

                    selOpt=new Option(baseTxt,baseVal);
                    eval('baseObj.options[j]=selOpt');

                    if(selectedBase == baseVal)
                        baseObj.selectedIndex=j;

                    j++;
                }
            }
        }
    }
}

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

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

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

                j++;
            }
        }
    }
    else
    {
        // When Vehicle Type is not selected (Simple Search)
        for(z=0; z < vtype.length; z++)
        {
            if(sid[vtype.options[z].value])
            {
                for(i=0; i < sid[vtype.options[z].value].length; i++)
                {
                    var svalue=new String(sid[vtype.options[z].value][i]);
                    var stext=new String(stype[vtype.options[z].value][i]);

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

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

                    j++;
                }
            }
        }
    }
}

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

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

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

    v2.length=1;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// Function 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 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 add selected values from 'Model' fields
// into 'Selected models' field, used in Advanced search page
function addModel(v1,v2)
{
    if(!(v1.id_model.selectedIndex >= 0))
        return;

    if(v1.id_model[v1.id_model.selectedIndex].value != '')
    {
        if(v2.options[0].value == '')
            document.adv.id_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.id_model[v1.id_model.selectedIndex].value;

            if(tmpValue == tmpValue2)
            {
                dup=1;
                alert(msgDupSelected);
                break;
            }
            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);

                arrModel=(m[makeid]).split(',');

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

                arrModel=(m[makeid]).split(',');

                for(i=0; i < arrModel.length; i++)
                {
                    var model_value=new String(arrModel[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.id_model[v1.id_model.selectedIndex].value).match(/^([0-9]{1,})#/i) )
                selOpt=new Option(v1.id_model[v1.id_model.selectedIndex].text,v1.id_model[v1.id_model.selectedIndex].value);
            else
            {
                str1=v1.id_model[0].text;
                selOpt=new Option(str1.slice(0,str1.indexOf(':'))+'-'+v1.id_model[v1.id_model.selectedIndex].text,v1.id_model[v1.id_model.selectedIndex].value);
            }
            eval('v2.options[tot]=selOpt');
        }
    }
}

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

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

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

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

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

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


// 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(_su+'/popUpLogin.php?M=OnlyForRegisteredUser',350,320,'nt_login');
        else
            openImg(_su+'/popUpLogin.php?M=OnlyForRegisteredUser',350,320,'nt_login');

        return false;
    }
    var flag='N';

    for(i=0; i < file.elements.length;i++)
    {
        if(file.elements[i].type == 'text')
        {
            if(!isblank(file.elements[i].value))
                flag='Y';
        }
    }
    if(flag == 'N')
    {
        alert(msgBlankForm);
        return false;
    }
}
// Function to check SSN number validation in Finland country
// Function to return nothing, this is used sometimes
// to display tool tip on plain text by making trick
function returnVoid() {}

function RemoveGroups(selectId,v2,make_txt)
{
    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 confirmReset(thisForm)
{
    if(confirm(msgConfirmReset))
        return true;

    return false;
}
// function to change town list according the selected domicile.
function partTownChange(domicile,town,curval,page)
{
    if(domicile)
    {
        if(domicile.length)
        {
            if(domicile.selectedIndex > -1)
            {
                idDomicile=new String(domicile.options[domicile.selectedIndex].value);
            }
            else
                idDomicile='';
        }
        else
            idDomicile=domicile;
    }
    if(page == 'simp')
    {
        townlist=curval.split(',');
    }
    if (page == 'listService')
    {
        town.length=0;
        j=0;
    }
    else
    {
        town.length=1;
        j=1;
    }
    if(idDomicile != '')
    {
        if(tId[idDomicile])
        {
            for(i=0; i < tId[idDomicile].length; i++)
            {
                cvalue=new String(tId[idDomicile][i]);
                ctext=new String(tName[idDomicile][i]);

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

                if(page == 'simp')
                {
                    for(k=0; k < townlist.length; k++)
                    {
                        if(cvalue == townlist[k])
                            town.options[j].selected=true;
                    }
                }
                else
                {
                    if(tId[idDomicile][i] == curval)
                        town.selectedIndex=j;
                }
                j++;
            }
        }
    }
    else
    {
        if (page == 'listService')
        {
            town.length=0;
            j=0;
        }
        else
        {
            town.length=1;
            j=1;
        }
    }
}

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

    subcategory.length=0;
    j=0;

    if(idCat != '')
    {
        if(sId[idCat])
        {
            for(i=0; i < c.length; i++)
            {
                if(sCnt[idCat][i] > 0)
                {
                    if(sAvail[idCat][i].match(/NT/))
                    {
                        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 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()
{
    idiv('que_modal').value = '';
    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 sd_ajaxQue(formObj,var_O)
{
    if(checkQue(formObj,var_O) != false )
    {
        var pars = Form.serialize($(formObj));
        if(formObj.replyToQue.value == 0)
        {
            formObj.que.disabled=true;
            formObj.exchangeid.disabled=true;
            formObj.save.disabled=true;
            document.getElementById('loaderimg').style.display='inline';
        }
        /* replacing € with &euro; */
        pars = pars.replace(/%E2%82%AC/g,'%26euro%3B');
        var id_template = formObj.id_template.value;
        var id_travel_truck=formObj.id_travel_truck.value;
        var answer = formObj.replyToQue.value;

        var xmlHttpReq=createXHR();
        xmlHttpReq.open('GET',_su+'/simple_dealer/sd_questionAnswer.php?ajxQueAns=1&ajx=1&id_travel_truck='+id_travel_truck+'&'+pars,true);
        xmlHttpReq.setRequestHeader("Content-Type", "text/html;charset=UTF-8");
        xmlHttpReq.onreadystatechange=function() {
            if(xmlHttpReq.readyState == 4) {
                var str = xmlHttpReq.responseText;
                ary = str.split("$1#2*3#903");
                idiv('submitXQA').innerHTML = ary[0];
                var queToSeller=document.getElementById('askToSeller');
                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
                {
                    queToSeller.style.display='block';
                    idiv('sendQueLink').className='arrow_hide_small';
                }
            }
        }
        xmlHttpReq.send(null);
        return false;
    }
    else
        return false;
}
function sd_ajaxLoadImage(id)
{
    var qa_id = id;

    if(document.getElementById('nt_id_user').value == "")
        return false;

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

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

            document.getElementById(ans_id).disabled=true;
            document.getElementById(anssave_id).disabled=true;
            document.getElementById(loader_img_id).style.display='inline';
        }

        /* replacing € with &euro; */
        pars = pars.replace(/%E2%82%AC/g,'%26euro%3B');

        var xmlHttpReq=createXHR();
        xmlHttpReq.open('GET',_su+'/simple_dealer/sd_questionAnswer.php?ajx=1&ajxQueAns=1&'+pars,true);
        xmlHttpReq.setRequestHeader("Content-Type", "text/html;charset=UTF-8");
        xmlHttpReq.onreadystatechange=function() {
            if(xmlHttpReq.readyState == 4) {
                var str = xmlHttpReq.responseText;
                idiv('submitXQA').innerHTML = str;
                setTimeout("whiteBG();",1000);
            }
        }
        xmlHttpReq.send(null);
    }
    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';
        idiv('lightbox').style.left = '65%';
    }
    else if(opt == 'N')
    {
        pageURL = _su+'/modalLogin.php?mainOnly=1&sd=0';
        idiv('lightbox').style.left = '40%';
//      idiv('lightbox').style.left = '50%';
    }
    else if(opt == 'P')
    {
        pageURL = _su+'/modalLogin.php?mainOnly=1&postad=1';
        idiv('lightbox').style.left = '40%';
    }
    else if(opt == 'RP')
    {
        pageURL = _su+'/modalLogin.php?mainOnly=1&redirectPage='+rPage;
        idiv('lightbox').style.left = '40%';
    }
    else if(opt != 'P' && location.href.search('advSearch') == -1)
    {
        document.queAsk.que.value = '';
        idiv('que').blur();
    }

    lightbox.prototype.content = pageURL;
    lightbox.prototype.activate();
    idiv('lightbox').style.top = '65%';
    idiv('lightbox').style.width = '430px';
}

function modalForm(frmObj)
{
    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')
    {
        var pars = Form.serialize($(frmObj));

        var xmlHttpReq=createXHR();

        xmlHttpReq.open('',login_page + ((login_page.indexOf('?') > 0) ? '&' : '?') + pars,true);
        xmlHttpReq.setRequestHeader("Content-Type", "text/html;charset=UTF-8");
        xmlHttpReq.onreadystatechange=function() {
            if(xmlHttpReq.readyState == 4) {
                if(xmlHttpReq.responseText == 'success')
                {
                    if(frmObj.postad.value == 1)
                        window.location.href = _su+"/postAd.php";
                    else if(frmObj.redirectPage && frmObj.redirectPage.value != '')
                        window.location.href=frmObj.redirectPage.value;
                    else
                        window.location.reload();
                }
                else if(xmlHttpReq.responseText == 'toHomePage')
                    location.href = '/';
                else
                    idiv('msgLoginError').innerHTML = '<table width="100%" border="0" cellspacing="3" cellpadding="0"><tr><td height="27" class="message">' + xmlHttpReq.responseText + '</td></tr></table>';
            }
        }
        xmlHttpReq.send(null);
    }
    return false;
}

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

/**     Modal for SendLink   */
function sendlinkmodal(event,anchor_obj)
{
    Event.stop(event);
    var urlLink = anchor_obj.href + '&mainOnly=1';
    lightbox.prototype.content = urlLink;
    lightbox.prototype.activate();
    idiv('lightbox').style.top = "50%";
    idiv('lightbox').style.width = "255px";
}

//      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;
}
/** 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_travel_truck='+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 to change part type and part category and vehicle type and related make model using Ajax. */
function ajaxPartCatChange(id_partTypeMake,id_partCatModel,id_partVehicle_type,chgFor,curVal)
{
    var divName;

    idiv('loadingImg_part').style.display='inline';

    /** Parse the required variables those are used in ajaxPartSearch.php file. */
    var ajaxPars='id_partTypeMake='+id_partTypeMake.value;
        ajaxPars +='&idVehicleType='+id_partVehicle_type.value+'&chgFor='+chgFor+'&curSelVal='+curVal;

    if(chgFor == 'PT')
        divName='partCategory';
    else if(chgFor == 'VT')
        divName='make_model';
    else if(chgFor == 'MK')
        divName='model_change';
    else
        divName='partCategory';

    AjaxUpdater(divName,_su+'/ajaxPartSearch.php?ajxifrm=A&'+ajaxPars,'idiv("loadingImg_part").style.display="none";callAjaxPart(document.srch_part);')

    return false;

}

/**
Function to change the model as per make and engine_model as per model using ajax.
1.  id_make         =form object of make.
2.  id_model        =form object of model.
3.  curval_make     =Current value of make
4.  curval_model    =Current value of model
5.  chgFrom         =change make and/or model from posing/simple search/adv search(POST/SIMP/ADV/N/OM)
6.  chgFor          =change for type/make/model.('TP'/'MK'/'MD')
7.  id_vehicle_type =form object of vehicle class.
8.  admin           =Function calling from admin or client side if admin pass '1'.
9.  exOpt           =Pass the extra option.
                    1. 'nxSrc'=> Calling from Nettix search.
                    2. 'carawall'=>Calling from carawall search
10. id_sub_type     =vehicle subtype
11. vehicleStatus   = Vehicle Status
*/
function ajaxMakeModelChange(id_make, id_model, curval_make, curval_model,curval_base, chgFrom, chgFor, id_vehicle_type, admin, exOpt, id_sub_type, vehicleStatus)
{

    var idSubType=idModel=idVehicleType='';

    if(!vehicleStatus)
        var vehicleStatus='';

    if(id_sub_type)
        idSubType=id_sub_type.value;

    if(id_model)
        idModel=id_model.value;

    if(id_vehicle_type)
        idVehicleType=id_vehicle_type.value

    /** Parse the required variables those are used in ajaxMakeModelChange.php file. */
    var ajaxPars='idMake='+id_make.value+'&idModel='+idModel;
        ajaxPars +='&curvalMake='+curval_make+'&curvalModel='+curval_model+'&curvalBase='+curval_base;
        ajaxPars +='&chgFrom='+chgFrom+'&chgFor='+chgFor+'&idVehicleType='+idVehicleType;
        ajaxPars +='&admin='+admin+'&exOpt='+exOpt+'&idSubType='+idSubType+'&vehicleStatus='+vehicleStatus;

    var ajaxFname=_su+'/ajaxMakeModelChange.php?ajxifrm=A';

    /** Display image loader. */
    if(chgFrom == 'SIMP')
    {
        if(chgFor == 'TP' && idiv('loadingImg_src_make'))
            idiv('loadingImg_src_make').style.display='inline';

        if(chgFor == 'MK' && idiv('loadingImg_src_model') && idVehicleType != '14')
            idiv('loadingImg_src_model').style.display='inline';
    }

    var xmlHttpReq=createXHR();

    xmlHttpReq.open('GET',ajaxFname+'&'+ajaxPars);
    xmlHttpReq.setRequestHeader("Content-Type", "text/html;charset=UTF-8");
    xmlHttpReq.onreadystatechange=function()
    {
        if(xmlHttpReq.readyState == 4)
        {
            showTextResponse(xmlHttpReq.responseText);

            /** Hide image loader. */
            if(chgFrom == 'SIMP')
            {
                if(!exOpt)
                    callAjax(document.srch);

                if(chgFor == 'TP' && idiv('loadingImg_src_make'))
                    idiv('loadingImg_src_make').style.display='none';

                if(chgFor == 'MK' && idiv('loadingImg_src_model'))
                    idiv('loadingImg_src_model').style.display='none';
            }
        }
    }
    xmlHttpReq.send(null);
    return false;
}
function cleanUrl(qs)
{
    var mk=qs.elements.id_make.options[qs.elements.id_make.selectedIndex];
    var md=qs.elements.id_model.options[qs.elements.id_model.selectedIndex];
    var bs=qs.elements.id_base.options[qs.elements.id_base.selectedIndex];
    var mi=qs.elements.model_info.value;
    var vt=qs.elements.id_vehicle_type.options[qs.elements.id_vehicle_type.selectedIndex];
    var u=_su;
    var l =qs.elements.length;

    if(mk.text.toLowerCase()=='bürstner')
        mk.text='burstner';
    if(mk.text.toLowerCase()=='Fjällvagen')
        mk.text='Fjallvagen';
    else if(mk.text.toLowerCase()=='münsterland')
        mk.text='munsterland';
    else if(mk.text.toLowerCase()=='smålandia')
        mk.text='smalandia';
    else if(mk.text.toLowerCase()=='pössl')
        mk.text='possl';
    else if(mk.text.toLowerCase()=='sävsjö')
        mk.text='savsjo';
    else if(mk.text.toLowerCase()=='fjällvagen')
        mk.text='fjallvagen';

    if(vt.text.toLowerCase()=='travel box')
        vt.text='matkailuvaunu';
    else if(vt.text.toLowerCase()=='travel truck')
        vt.text='matkailuauto';

    if(md.text.toLowerCase()=='südwind')
        md.text='sudwind';

    if(!mk.value && !bs.value && !vt.value)
        u=u+'/haku?';
    else
    {
        if(mk.value)
            u=u+'/'+mk.text;
        else
            u=u+'/'+'kaikki';

        if(md.value)
            u=u+'/'+md.text;
        else if(bs.value)
            u=u+'/'+bs.text;
        else if(mi && mi!=capModelInfo)
            u=u+'/'+mi;
        else
            u=u+'/'+'kaikki';

        if(vt.value)
            u=u+'/'+vt.text;
        else
            u=u+'/'+'kaikki';

        u=u+'/?';
    }

    u=u.toLowerCase();

    mk.value=md.value=vt.value=mi='';
    for(var i = 0; i < l; i++)
    {
        var e=qs.elements[i];

        if(e.name!='search')
        {
            if(e.value && e.type == 'hidden' && qs.lm.checked)
                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;
                }
            }
        }
    }

    u=u.replace(/\s/g,'-');
    window.location.replace(u.substr(0,u.length-1));
    return false;
}
/**Function to set default value for more search criteria of simple search. */
 function blankCri()
 {
     document.srch.id_fuel_type.value='';
     document.srch.id_gear_type.value='';
     document.srch.id_domicile.value='';
     document.srch.id_town.length=1;
 }
 /** call Ajax function for search result counter on change elements value. */
 function callAjax(frmObj)
 {
    /** for write hidden parameter selected model & selected acc and validate inspected motmonth & motyear */
     var ajaxFName;
     if(frmObj.name == 'srch_car')
        ajaxFName=_su + '/ajaxSearchCounter.php?ajxifrm=A&site=NA';
    else
        ajaxFName=_su + '/ajaxSearchCounter.php?ajxifrm=A&site=NT';

     if(frmObj.name == 'adv')
     {
         checkFa();
         return ajaxCounterChng(ajaxFName+'&frm=ADV&'+ cleanFrmUrl(frmObj),frmObj.name);
     }
     else if(frmObj.name == 'srch' || frmObj.name == 'srch_car')
     {
        return ajaxCounterChng(ajaxFName+'&frm=SIMP&'+ cleanFrmUrl(frmObj),frmObj.name);
     }
 }
 /** Ajax Function for display total counter of vehicle which are belong to search criteria */
 function ajaxCounterChng(searchUrl,frmName)
 {

    var loadingImg='';
    var ajaxFname=searchUrl.replace('/#/ig','@');

    if(frmName == 'adv')
        loadingImg='loadingImg_src_chngCntAdv';
    else if(frmName == 'srch')
        loadingImg='loadingImg_src_chngCnt';
    else if (frmName == 'srch_car')
        loadingImg='loadingImg_car';

    idiv(loadingImg).style.display='inline';

    var xmlHttpReq=createXHR();

    xmlHttpReq.open('GET',ajaxFname);
    xmlHttpReq.setRequestHeader("Content-Type", "text/xml;charset=UTF-8");
    xmlHttpReq.onreadystatechange=function()
    {
        if(xmlHttpReq.readyState == 4)
        {
            showResponse(xmlHttpReq.responseXML);
            idiv(loadingImg).style.display='none';
        }
    }
    xmlHttpReq.send(null);
    return false;
 }
 function callAjaxPart(frmElement)
 {
 	var ajaxFname=_su + '/ajaxSearchCounter.php?ajxifrm=A&site=NP&'+cleanFrmUrl(frmElement);

    idiv('loadingImg_part').style.display='inline';

    var xmlHttpReq=createXHR();

    xmlHttpReq.open('GET',ajaxFname);
    xmlHttpReq.setRequestHeader("Content-Type", "text/xml;charset=UTF-8");
    xmlHttpReq.onreadystatechange=function()
    {
        if(xmlHttpReq.readyState == 4)
        {
            showResponse(xmlHttpReq.responseXML);
            idiv('loadingImg_part').style.display='none';
        }
    }
    xmlHttpReq.send(null);
    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')
        {
           // alert('not chkbox and not radio name:'+e.name+'value:'+e.value);
            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 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 to change part type and part category and vehicle type and related make model using Ajax.
*/
function ajaxCarMkMdlChange(id_carMake,id_carModel,chgFor,curVal)
{
    var divName;
    idiv('loadingImg_car').style.display='inline';
    /** Parse the required variables those are used in ajaxPartSearch.php file. */
    var ajaxPars='id_carMake='+id_carMake.value+'&id_carModel='+id_carModel.value;
        ajaxPars +='&chgFor='+chgFor+'&curSelVal='+curVal+'&form=srch_car';

    if(chgFor == 'MK')
        divName='carModel';

    AjaxUpdater(divName,_su+'/ajaxCarSearch.php?ajxifrm=A&'+ajaxPars,'idiv("loadingImg_car").style.display="none";callAjax(document.srch_car);');
}