/* $Id: common.js,v 1.2 2008/07/09 07:29:11 jignesh Exp $ */
/** Function which checks whether given email is valid or not */
function emailInvalid(s)
{
    if(s.match(/^\w+([\.\+]?[-]{0,2}\w+)*[\.]?[-]?@\w+([\.-]?\w+)*(\.\w{2,4})+$/i))
        return true;
    else
        return false;
}
/** Function which checks whether given url address is valid or not */
function urlInvalid(s)
{
    if(!(s.match(/^http:\/\/[a-zA-Z0-9]+([_|\.-][a-zA-Z0-9~-]{1,})*\.([a-z]{2,4})(\/[a-zA-Z0-9~-]{1,}[_|\.]{0,1}[a-zA-Z0-9~]{1,}\/?)*([_|\.][a-zA-Z0-9~-]{1,})*$/i) || s.match(/^ftp:\/\/[a-zA-Z0-9]+([_|\.][a-zA-Z0-9~-]{1,})*\.([a-z]{2,4})(\/[a-zA-Z0-9~-]{1,}[_|\.]{0,1}[a-zA-Z0-9~]{1,}\/?)*([_|\.][a-zA-Z0-9~]{1,})*$/i)))
        return false;
    else
        return true;
}
/** Function to check phone,fax,mobile for finland country */
function check(s)
{
    if(!s.match(/^[0-9\s\+-]{5,25}$/) )
        return false;
    else
        return true;
}
/** Function to check 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 check Password string, various rules are followed */
function checkPasswd(s)
{
    if(s.match(/^[a-zA-Z0-9åÅäÄöÖÁÀÉÈÒÓÙÚáàèéòóùúÝìíýÌÍ´_.-]{4,12}$/))
        return true;

    return false;
}
/** Function to check the alphanumeric characters. */
function checkAlphaNumeric(s)
{
    if(!s.match(/^[0-9a-zA-ZåÅäÄöÖÁÀÉÈÒÓÙÚáàèéòóùúÝìíýÌÍ´\s-]{1,100}$/))
        return false;
    else
        return true;
}
/** Function to check First-Last name values when it is entered as full name */
function checkFullName(s)
{
    if(!s.match(/^[a-zA-ZåÅäÄöÖÁÀÉÈÒÓÙÚáàèéòóùúÝìíýÌÍ´_\s-]{1,50}$/))
        return false;
    else
        return true;
}
/** Function to check First-Last name values */
function checkName(s)
{
    if(!s.match(/^[a-zA-ZåÅäÄöÖé´ÁÀÉÈÒÓÙÚáàèéòóùúÝìíýÌÍ-]{1,30}$/))
        return false;
    else
        return true;
}
/** Function to check hobby/reference values */
function checkHobbyRef(s)
{
    if(!s.match(/^[0-9a-zA-ZåÅäÄöÖÁÀÉÈÒÓÙÚáàèéòóùúÝìíýÌÍ_:;@´()\s\+\,'.-]{1,250}$/))
        return false;
    else
        return true;
}
/** Function to check address/contact time values */
function checkAddContTime(s)
{
    if(!s.match(/^[0-9a-zA-ZåÅäÄöÖÁÀÉÈÒÓÙÚáàèéòóùúÝìíýÌÍ_´:()\s\,'.!-]{1,250}$/))
        return false;
    else
        return true;
}
/** Function to check city values */
function checkCity(s)
{
    if(!s.match(/^[0-9a-zA-ZåÅäÄöÖÁÀÉÈÒÓÙÚáàèéòóùúÝìíýÌÍ_´:\s\,-]{1,250}$/))
        return false;
    else
        return true;
}
/** Function to check zip values */
function checkZip(s)
{
    if(!s.match(/^[0-9a-zA-Z]{1,250}$/))
        return false;
    else
        return true;
}
/** Function to check loginid string, various rules are followed. */
function checkLogin(s)
{
    var dummyWords=new Array('admin','webmaster','help','helpdesk','user','dealer','dummy','nettiauto',
                                'nettimoto','nettivene','nettivaraosa','nettimokki','nettikone',
                                'nettiasunto','nettimarkkina','nettikaravaani');
    if(!(s.match(/^[a-zA-Z0-9åÅäÄöÖÁÀÉÈÒÓÙÚáàèéòóùúÝìíýÌÍ´_]{4,12}$/)))
        return msgUserid;
    else
    {
        s=s.toLowerCase();
        for(i=0; i < dummyWords.length; i++)
        {
            if(s == dummyWords[i])
            {
                return msgResdId;
                break;
            }
        }
    }
    return 1;
}
/** Function to check characters length of word */
function isLong(eleValue,sep,len)
{
    if (eleValue == '')
        return true;
    else
    {
        if(sep == ' ')
            tempValue=eleValue.split(/\s+/);
        else
            tempValue=eleValue.split(sep);

        for(var i=0; i < tempValue.length; i++)
        {
            if(tempValue[i].length > len)
            {
                return 0;
                break;
            }
        }
    }
    return 1;
}
/** Function to check SSN number validation in Finland country */
function checkSsn(p)
{
    lChar=new Array('A','B','C','D','E','F','H','J','K','L','M','N','P','R','S','T','U','V','W','X','Y','Z');

    if(!(p.match(/^[0-9]{6}-[0-9]{3}[0-9a-zA-Z]{1}$/)))
        return false;
    else
    {
        ssn=p.replace('-','');
        first=ssn.substr(0,9);
        start1=ssn.substr(0,6);
        middle=ssn.substr(6,3);
        last=ssn.substr(9,1);
        remin=(first % 31);

        if(remin >= 0 && remin <= 9)
            rightChar=remin;
        else
            rightChar=lChar[remin-10];

        rightSSN=start1+'-'+middle+rightChar;

        if(rightSSN == p)
            return true;
        else
            return false;
    }
    return false;
}
/**
Function to give the user a message to login to the site, when he tries to access the feature
which is only for registered memeber.
*/
function loginWarning(msgWar,curTxt)
{
    if(!isblank(curTxt))
       alert(msgWar);
}
/** Function to confirm the cancel event and redirect to given file or home page */
function confirmCancel(valMsg,valFile)
{
    if(valMsg != '')
    {
        if(confirm(valMsg))
        {
            if(valFile)
                location.href=valFile;
            else
                location.href='home.php';
        }
        else
            return false;
    }
    else
    {
        if(valFile != '')
            location.href=valFile;
        else
            location.href='home.php';
    }
}
/** Function to open new pop up window with fixed size */
function openWin(varUrl,varTitle)
{
    var h=screen.height;
    h=h-80;

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

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

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

/** Function to open the new window with given width and height */
function openNewWin(varUrl,w,h,varTitle)
{
    var myfeatures='directories=no,location=no,menubar=no,status=yes,titlebar=no,toolbar=no,resizable=no,scrollbars=no,width='+w+',height='+h+',left=0,top=0';

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

    var newWin=window.open(varUrl,varTitle,myfeatures);
    newWin.focus();
}
/** Function to change the sitelanguage for given form. */
function changeLanguage(frm)
{
    if(frm.sitelang.value == 1)
        frm.sitelang.value=2;
    else
        frm.sitelang.value=1;

    frm.submit();
    return false;
}
/** Function to change the class name for given id elemente. */
function changeClass(id,cls)
{
    if(document.getElementById(id).className == 'listing_sel')
        document.getElementById(id).className=cls;
    else
        document.getElementById(id).className='listing_sel';
}
/**
Function blinkingText_1() blinkingText_2()
blink the text in given id with different two class and No. of time to blink.
idName=name othe tag id,
className1=Class name that change from one to other,
className2=Class name that display text in original,
nCount=Number of time to blink,
bCount=Take blinking counter so, do not pass from main function call.
*/
function blinkingText_1(idName,className1,className2,nCount,bCount)
{
    if(nCount == '' || isNaN(nCount))
        nCount=3;

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

    bCount++;

    document.getElementById(idName).className=className1;
    setTimeout('blinkingText_2("'+idName+'","'+className1+'","'+className2+'","'+nCount+'","'+bCount+'");',500);
}
/** Function call from 'blinkingText_1' and vice versa */
function blinkingText_2(idName,className1,className2,nCount,bCount)
{
    document.getElementById(idName).className=className2;

    if(bCount < nCount)
        setTimeout('blinkingText_1("'+idName+'","'+className1+'","'+className2+'","'+nCount+'","'+bCount+'");',500);
}

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

/** Sort displaying vehicle list page according to specified arguments. */
function sortForm(col,ord)
{
    document.sortl.sortCol.value=col;
    document.sortl.ord.value=ord;
    document.sortl.submit();
}

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

/**To popup message while removing multiple records*/
function confirmMultiDel(act,frm)
{
    if(confirm(msgDeleteConfirm))
    {
        if (act != '')
            eval("document."+frm+".action="+'act');

        eval("document."+frm+".submit()");
    }
}

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

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