/* $Id: nc_advSearch.js,v 1.2 2010/08/18 06:46:04 kiran Exp $ */

/** Define global variable for those field they generated using javascript, used for manipulation */
var domTown=new Array();
var selTown=new Array();
var avlTo='';

/** when page is loaded store default value of those field they generated using javaScript,
this field value is not reset using reset function of javascript so, reset manually.
*/
function setDefReset(advForm)
{
    if(advForm.id_sel_town.length > 0)
    {
        for(var st=0; st<advForm.id_sel_town.length; st++)
        {
            /** Assign in domTown array 'selected domicile and town' as value and text seperated with , */
            if(advForm.id_sel_town[st].value != "")
                domTown[st]=advForm.id_sel_town[st].value+","+advForm.id_sel_town[st].text;
        }
    }

    if(advForm.availableTo.selectedIndex > 0)
        avlTo=advForm.availableTo.value;
    if(advForm.id_sel_town.length > 0)
        selTown=domTown;
}

function blankFa()
{
    if(isblank(document.adv.findAgent.value) || !checkCity(document.adv.findAgent.value))
    {
        alert(msgInvalidFa);
        document.adv.findAgent.focus();
        return false;
    }
}
function checkFa(advForm)
{
    var aT="";

    if(document.adv.id_sel_town.length > 0)
    {
        for(a=0; a<document.adv.id_sel_town.length-1; a++)
        {
            if(document.adv.id_sel_town[a].value != "")
                aT += document.adv.id_sel_town[a].value+",";
        }
        if(document.adv.id_sel_town[a].value != "")
            aT += document.adv.id_sel_town[a].value;

        document.adv.selTown.value=aT;
    }
    return true;
}
function loginWarning(msgWar,curTxt)
{
    if(!isblank(curTxt))
    {
        alert(msgWar);
    }
}
function updateNumField(o)
{
    if (frmFixUIntField(o))
    o.focus();
}
var frmD=new Object(), frmO, frmE;

function frmCheckUInt(o)
{
    for (var i=0;i < o.length;i++)
    {
        var c=o.charAt(i);
        if (c < '0' || c >'9')
        return false;
    }
    return true;
}

function frmFixUIntField(o)
{
    var t=frmCheckUInt(o.value);
    if (t)
    {
        frmD[o.name]=o.value;
    }
    else
    {
        o.value=(frmD[o.name]!=null?frmD[o.name]:'');
    }
    return t;
}
function loadDef(v1)
{
    if(!v1.value)
    {
        if(v1.name == 'priceFrom')
            v1.value=lvalue;
        else
            v1.value=uvalue;
    }
}
function loadDefArea(v1)
{
    if(!v1.value)
    {

        if(v1.name == 'areaFrom')
            v1.value=lvalue;
        else
            v1.value=uvalue;
    }
}

function loadDefGArea(v1)
{
    if(!v1.value)
    {

        if(v1.name == 'areaFrom')
            v1.value=lvalue;
        else
            v1.value=uvalue;
    }
}

function loadDefBerths(v1)
{
    if(!v1.value)
    {

        if(v1.name == 'berthsFrom')
            v1.value=lvalue;
        else
            v1.value=uvalue;
    }
}

function loadDefRoom(v1)
{
    if(!v1.value)
    {

        if(v1.name == 'roomFrom')
            v1.value=lvalue;
        else
            v1.value=uvalue;
    }
}

function chkMandOutOfTwo(chk,chkOther)
{
    /** if another checkbox is not selected/checked, keep the first one as selected regardless of
       whether user has checked or unchecked.
    */
    if(!chkOther.checked)
        chk.checked=true;

    return;
}