var portNo = '';
var urlparts = (document.URL).split('/');
if(urlparts[0])
    urlHost = urlparts[0];
else
    urlHost = 'http:';

var siteUrl = urlHost+'//'+location.hostname;
var userUrl = siteUrl+'/user';
var clUrl = siteUrl+'/classified';
var crUrl = siteUrl+'/cricket';
var ypUrl = siteUrl+'/yellow';
var siteImgUrl = siteUrl+'/extra/siteimages';

if(location.port)
    portNo = ':'+location.port;

function confirmDelete(confrimmsg)
{
    if(confrimmsg)
    {
        if(confirm(confrimmsg))
            return true;
        else
            return false;
    }
    else
    {
        if(confirm("Are you sure you want to delete this record ?"))
            return true;
        else
            return false;
    }
}

function subMenu()
{
    $(document).ready(function()
    {
       $("ul.dropdown li").hover(function(){
            $(this).addClass("hover");
            $('ul:first',this).css('visibility', 'visible');
            $(this).find("a.mainMenu").addClass("active");
        }, function()
        {
            $(this).removeClass("hover");
            $('ul:first',this).css('visibility', 'hidden');
            $(this).find("a.mainMenu").removeClass("active");
        });
        $("ul.dropdown li ul li:has(ul)").find("a:first").addClass("child_menu");
    });
}

/** Admin : Add City info */
function ajaxCiSubCategory(catid, subCatlevel)
{
    $.post("ci_addAjaxSubCat.php", { id: catid, infolevel : subCatlevel },
    function(data)
    {
        if(data)
        {
            $("#subcat_val").show();
            $("select#ci_sub_cat").html(data);
        }
        else
        {
            $("#subcat_val").hide();
        }
    });

    if(catid == 9)
    {
        $("#establish").show();
    }
    else
    {
        $("#establish").hide();
    }
}

/** Admin : Yellow Page ( common entity ) */
function ajaxEntity(entityType, entityId, cCode)
{
    $.post("ad_ajaxEntity.php", { id: entityId, entity : entityType, countryCode : cCode },
    function(data)
    {
        if(data)
        {
            entityStr = data.split('#entity#');

            if(entityType == 'ST')
            {
                if(entityStr[0])
                {
                    $("select#district").attr('disabled',false);
                    $("select#district").html('<option value="">Select District</option>'+entityStr[0]);
                }
                else
                {
                    $("select#district").attr('disabled',true);
                    $("select#district").html('<option value="">Select District</option>');
                }
            }

            if(entityType == 'DT' || entityType == 'ST' || entityType == 'DTV')
            {
                if(entityStr[1])
                {
                    $("select#city").attr('disabled',false);
                    $("select#city").html('<option value="">Select City</option>'+entityStr[1]);
                }
                else
                {
                    $("select#city").attr('disabled',true);
                    $("select#city").html('<option value="">Select City</option>');
                }
            }

            if(entityStr[2])
            {
                $("select#location").attr('disabled',false);
                $("select#location").html('<option value="">Select Location</option>'+entityStr[2]);
            }
            else
            {
                $("select#location").attr('disabled',true);
                $("select#location").html('<option value="">Select Location</option>');
            }

            if(entityType == 'DTV')
            {
                if(entityStr[3])
                {
                    $("select#village").attr('disabled',false);
                    $("select#village").html('<option value="">Select Village</option>'+entityStr[3]);
                }
                else
                {
                    $("select#village").attr('disabled',true);
                    $("select#village").html('<option value="">Select Village</option>');
                }
            }
        }
    });
}

/** Admin : Yellow Page ( category ) */
function ajaxYpEntityAd(ypEntityType, ypEntityId, defaultVal)
{
    if(ypEntityId)
    {
        $.post("yp_ajaxEntity.php", { id: ypEntityId, entity : ypEntityType },
        function(data)
        {
            if(data)
            {
                entityStr = data.split('#entity#');

                if(ypEntityType == 'CAT')
                {
                    if(entityStr[0])
                    {
                        $("#yp_subCat").show();
                        $("select#subcat").html('<option value="">Select Subcategory</option>'+entityStr[0]);
                    }
                    else
                    {
                        $("#yp_subCat").hide();
                        $("select#subcat").html('<option value=""></option>');
                    }
                }

                if(entityStr[1])
                {
                    $("#yp_section").show();
                    $("select#section").html('<option value="">Select Section</option>'+entityStr[1]);
                }
                else
                {
                    $("#yp_section").hide();
                    $("select#section").html('<option value=""></option>');
                }
            }
        });
    }
    else
    {
        $("#yp_subCat").hide();
        $("select#subcat").html('<option value=""></option>');

        $("#yp_section").hide();
        $("select#section").html('<option value=""></option>');
    }
}

function submitBusinessFrom()
{
    document.searchbusiness.submit();
}

function imageGallery(imgId)
{
    $(function() {
        var galleries = $('.ad-gallery').adGallery({start_at_index: imgId});

        $('#switch-effect').change(
        function() {
            galleries[0].settings.effect = $(this).val();
            return false;
        });
        $('#toggle-slideshow').click(
        function() {
            galleries[0].slideshow.toggle();
            return false;
        });
        $('#toggle-description').click(
        function() {
            if(!galleries[0].settings.description_wrapper) {
            galleries[0].settings.description_wrapper = $('#descriptions');
            } else {
            galleries[0].settings.description_wrapper = false;
            }
            return false;
        });
    });
}

function checkFogotPassword()
{
    var lognin = $("#forgotPass").find("#loginid").val();
    var email = $("#forgotPass").find("#email").val();
    var veriCode = $("#forgotPass").find("#verification").val();

    if(lognin == '' && email == '')
    {
        alert('You must fill in the fields marked with *');
        $("#forgotPass").find("#loginid").focus();
        return false;
    }
    if(veriCode == '')
    {
        alert('Please enter the verification code');
        $("#forgotPass").find("#verification").focus();
        return false;
    }

    return true;
}

function setFlashBannerInfo(xmlpath)
{
    if(xmlpath == '')
        xmlpath = 'content';

    // JAVASCRIPT VARS
    // cache buster
    var cacheBuster = "?t=" + Date.parse(new Date());

    // stage dimensions
    var stageW = '695'; //"100%";
    var stageH = '215'; //"100%";

    // ATTRIBUTES
    var attributes = {};
    attributes.id = 'FlabellComponent';
    attributes.name = 'FlabellComponent';

    // PARAMS
    var params = {};
    params.bgcolor = '#ffffff';
    params.menu = 'false';
    params.scale = 'noScale';
    params.wmode = 'opaque';
    params.allowfullscreen = 'true';
    params.allowScriptAccess = 'always';

    /* FLASH VARS */
    var flashvars = {};

    /// if commented / delete these lines, the component will take the stage dimensions defined
    /// above in "JAVASCRIPT SECTIONS" section or those defined in the settings xml
    flashvars.componentWidth = stageW;
    flashvars.componentHeight = stageH;

    /// path to the content folder(where the xml files, images or video are nested)
    /// if you want to use absolute paths(like "http://domain.com/images/....") then leave it empty("")
    flashvars.pathToFiles = 'flashbanner/'+xmlpath+'/';

    // path to content XML
    flashvars.xmlPath = 'xml/banner.xml';

    /** EMBED THE SWF**/
    swfobject.embedSWF('../extra/siteimages/flashBanner.swf'+cacheBuster, attributes.id, stageW, stageH, '9.0.124', '../extra/siteimages/expressInstall.swf', flashvars, params, attributes);
}

function checkBasicInfo()
{
    $("#basicInfo").validate({rules: {
        first_name: { wordlength: 15},
        last_name: { wordlength: 15},
        bio: { wordlength: 100},
        honors_awards: { wordlength: 100}} });
    var bm = $("#basicInfo").find("#birth_month").val();
    var bd = $("#basicInfo").find("#birth_date").val();
    var by = $("#basicInfo").find("#birth_year").val();

    if((bm != '' && (bd == '' || by == '')) || (bd != '' && (bm == '' || by == '') ) || (by != '' && (bd == '' || bd == '') ))
    {
        $("#err_birth").show();
        return false;
    }
    else
        $("#err_birth").hide();

    return true;
}

function setAutoComplete()
{
    for( i = 0; i < document.eduInfo.institute_type.length; i++ )
    {
        if(document.eduInfo.institute_type[i].checked == true)
            var_name = document.eduInfo.institute_type[i].value;
    }

    if(var_name == 'university')
    {
        $("input#institute").autocomplete({ disabled: false });
        $(document).ready(function() {
            $("input#institute").autocomplete({
            source: siteUrl+"/user/user_universityAutoFill.php",
            select: function(event, ui) {$('#institute_id').val(ui.item.id);}});
        });
    }
    else
        $("input#institute").autocomplete({ disabled: true });
}

function disableExperienceTime(currentChk)
{
    if(currentChk.checked)
    {
        $("#endTime").hide();
        $("#present").show();
    }
    else
    {
        $("#endTime").show();
        $("#present").hide();
    }
}

function checkEducation()
{
    $(document).ready(function(){$("#eduInfo").validate({rules: {
        institute: { wordlength: 15},
        qualification: { wordlength: 15},
        additional: { wordlength: 40}
    } }); });
}

function chexkExperience()
{
    $(document).ready(function(){$("#expInfo").validate({rules: {
        company_name: { wordlength: 20},
        position: { wordlength: 20},
        location: { wordlength: 20},
        website: { wordlength: 120},
        job_desc: { wordlength: 40}
    } }); });
}

function checkContactInfo()
{
    $(document).ready(function(){$("#contactInfo").validate({rules: {
        address: { wordlength: 15},
        location: { wordlength: 15},
        contact_time: { wordlength: 15}
    } }); });
}

function checkEditPhoto()
{
    $(document).ready(function(){$("#userPhoto").validate();});
}

function checkFindContact()
{
    $(document).ready(function(){$("#findContact").validate({rules: {seach_name: { minlength: 4}} });});
}

function checkInviteUser()
{
    $(document).ready(function(){$("#inviteUser").validate();});
}

function showHideMailPart()
{
    $('#hideMailButton').toggle();
    $('#showMailPart').toggle();
}

function showHideEmailProvider(providerType)
{
    if(providerType == 'others')
        $('#pList').show();
    else
        $('#pList').hide();

    if(providerType != 'others')
        document.getElementById("providerType").innerHTML= "<input type='hidden' name='provider_box' value='"+providerType+"'/>";
}
function toggleAll(element, formDetail)
{
    var form = formDetail, z = 0;
    for(z=0; z<form.length;z++)
    {
        if(form[z].type == 'checkbox')
            form[z].checked = element.checked;
    }
}
function checkComposeMsg()
{
    $(document).ready(function(){$("#composeMsg").validate({rules: {subject: { wordlength: 40}} }); });
}

function ajaxComposeMsg(stremail)
{
    if(stremail)
    {
        $.post(userUrl+"/user_ajaxComposeMsg.php", { stremail: stremail },
        function(data){$('#to').attr("value", data);});
    }
}
function checkLogin()
{
    $(document).ready(function(){$("#LoginFrm").validate();});
}
function checkValidateMobile()
{
    $(document).ready(function(){$("#validateMobile").validate();});
}
function checkRegistration()
{
    $("#register").validate({rules: {
    password: { minlength: 6,maxlength: 20 },
    confirm_password: {equalTo: "#password"}} });

    if((document.register.mobile_chk.checked == true && document.register.mobile.value == '') || (document.register.mobile_code.value == 'other' && document.register.mobile.value == ''))
        $("#errMobile").show();
    else
        $("#errMobile").hide();

    if(document.register.birth_date.value == '' || document.register.birth_year.value == '' || document.register.birth_month.value == '')
        $("#err_birth").show();
    else
        $("#err_birth").hide();
    if(document.register.tearm_cond)
    {
        if(document.register.tearm_cond.checked == false)
            $("#err_tc").show();
        else
            $("#err_tc").hide();
    }
}
function checkConversation()
{
    $(document).ready(function(){$("#conversation").validate({rules: {message: { wordlength: 80}} }); });
}

function blah(txtmsg)
{
    $('#message').removeClass("gray");

    if(txtmsg == "What's on your mind? What you have achieved recently?")
        $('#message').attr("value", '');
}

function blankString()
{
    if(document.conversation.message.value == '')
    {
        $('#message').addClass("gray");
        $('#message').attr("value", "What's on your mind? What you have achieved recently?");
    }
    else
        $('#message').removeClass("gray");
}
function showHideConvComment(showbox)
{
    var totbx = document.getElementById('totConv').value;

    for(var i=0;i<totbx;i++)
    {
        $('#com_'+i).hide();
    }

    $('#com_'+showbox).show();
}

function showHideMoreConvCommet(convId, totalCom)
{
    if(document.getElementById('moreConvCom_'+convId).className == 'none')
    {
        $('#moreConvCom_'+convId).removeClass("none");
        hideCom = "<a onclick=\"showHideMoreConvCommet('"+convId+"', "+totalCom+")\">Hide all comment<a/>";
        $('#viewall_'+convId).html(hideCom);
    }
    else
    {
        $('#moreConvCom_'+convId).addClass("none");
        showCom = "<a onclick=\"showHideMoreConvCommet('"+convId+"',"+totalCom+")\">View "+totalCom+" all comments<a/>";
        $('#viewall_'+convId).html(showCom);
    }
}

function showHideMoreConv(convId, ishide)
{
    if(ishide == 'Y')
    {
        $('#fullConv_'+convId).hide();
        $('#lessConv_'+convId).show();
    }
    else
    {
        $('#fullConv_'+convId).show();
        $('#lessConv_'+convId).hide();
    }
}

function showHideMoreConvComm(convId, ishide)
{
    if(ishide == 'Y')
    {
        $('#fullConvComm_'+convId).hide();
        $('#lessConvComm_'+convId).show();
    }
    else
    {
        $('#fullConvComm_'+convId).show();
        $('#lessConvComm_'+convId).hide();
    }
}

function addConvComment(idConv, divId)
{
    if(document.getElementById('conv_comment_'+idConv).value)
    {
        $('#err_conv_'+idConv).hide();
        $.post(userUrl+"/user_ajaxAddDeleteConvComment.php", { convCom: document.getElementById('conv_comment_'+idConv).value, convId : idConv },
        function(data){
            document.getElementById('conv_comment_'+idConv).value = '';
            $('#com_'+divId).hide();
            $('#convComm_'+idConv).html(data);
        });
    }
    else
        $('#err_conv_'+idConv).show();
}

function deleteConvComment(idConvComm, idConv)
{
    var confirmDel = confirmDelete();
    if(confirmDel)
    {
        $.post(userUrl+"/user_ajaxAddDeleteConvComment.php", { commId: idConvComm, convId: idConv, comDelete: 'Y'},
        function(data){$('#convComm_'+idConv).html(data);});
    }
}

function switchTab(showTab, hideTab)
{
    document.getElementById(showTab).style.display = '';
    document.getElementById(hideTab).style.display = 'none';
}

function previewProfile(chkboxId, divId)
{
    var chkBox = "document.profileSetting."+chkboxId+".checked";
    if(eval(chkBox))
        eval("document.getElementById('"+divId+"').style.display = 'block';");
    else
        eval("document.getElementById('"+divId+"').style.display = 'none';");

}

function expPreviewProfile(chkboxId, divId)
{
    var chkBox = "document.profileSetting."+chkboxId+".checked";
    var chkCpdBox = "document.profileSetting.current_position_detail.checked";
    var chkPpdBox = "document.profileSetting.past_position_detail.checked";

    if(eval(chkBox))
        eval("document.getElementById('"+divId+"').style.display = 'block';");
    else
        eval("document.getElementById('"+divId+"').style.display = 'none';");

    if(eval(chkCpdBox) || eval(chkPpdBox))
        eval("document.getElementById('preview_exp').style.display = 'block';");
    else
        eval("document.getElementById('preview_exp').style.display = 'none';");

}

function personalPreviewProfile(chkboxId, divId)
{
    var chkBox = "document.profileSetting."+chkboxId+".checked";
    var chkBirthBox = "document.profileSetting.birthday.checked";
    var chkBioBox = "document.profileSetting.bio.checked";
    var chkHaBox = "document.profileSetting.honors_awards.checked";

    if(eval(chkBox))
        eval("document.getElementById('"+divId+"').style.display = 'block';");
    else
        eval("document.getElementById('"+divId+"').style.display = 'none';");

    if(eval(chkBirthBox) || eval(chkBioBox) || eval(chkHaBox))
        eval("document.getElementById('personal_info').style.display = 'block';");
    else
        eval("document.getElementById('personal_info').style.display = 'none';");
}

function contactPreviewProfile(chkboxId, divId)
{
    var chkBox = "document.profileSetting."+chkboxId+".checked";
    var chkCnBox = "document.profileSetting.contact_number.checked";
    var chkAddBox = "document.profileSetting.address.checked";
    var chkCtBox = "document.profileSetting.contact_time.checked";
    var chkWebBox = "document.profileSetting.website.checked";

    if(eval(chkBox))
        eval("document.getElementById('"+divId+"').style.display = 'block';");
    else
        eval("document.getElementById('"+divId+"').style.display = 'none';");

    if(eval(chkCnBox) || eval(chkAddBox) || eval(chkCtBox) || eval(chkWebBox))
        eval("document.getElementById('contact_info').style.display = 'block';");
    else
        eval("document.getElementById('contact_info').style.display = 'none';");
}

function checkQuickSMS()
{
    $(document).ready(function(){$("#newSms").validate();});
}

function checkGroupSMS()
{
    var MsgErrFlag = ContactErrFlag = 0;

    if(document.newSms.message.value == '')
    {
        $("#groupMsgErr").html('Please Enter Message');
        var MsgErrFlag = 1;
    }
    else
    {
        $("#groupMsgErr").html('');
        var MsgErrFlag = 0;
    }

    var form = document.forms.newSms, z = 0, totalChk = 0;
    for(z=0; z<form.length;z++)
    {
        if(form[z].type == 'checkbox' && form[z].name != 'selectall' && form[z].checked == true)
        {
            totalChk = totalChk + 1
        }
    }
    if(totalChk == 0)
    {
        $("#groupContactErr").html('Please Select contact');
        var ContactErrFlag = 1;
    }
    else if(totalChk > 20)
    {
        $("#groupContactErr").html('You can send maximum 20 messages at a time.');
        var ContactErrFlag = 1;
    }
    else
    {
        $("#groupContactErr").html('');
        var ContactErrFlag = 0;
    }

    if(ContactErrFlag == 1 || MsgErrFlag == 1)
        return false;
    else
        return true;
}
function checkAddContact()
{
    $(document).ready(function(){$("#addContact").validate();});
}
function checkAddGroup()
{
    $(document).ready(function(){$("#addGroup").validate();});
}
function checkChangeMobile()
{
    $(document).ready(function(){$("#changeMobile").validate();});
}
function countChars(charLimit)
{
    var len=document.newSms.message.value.length;
    var str=document.newSms.message.value;
    if(len<=charLimit)
        $('#msgChar').html(charLimit-len)
    else
        document.newSms.message.value=str.substr(0,str.length-1);
}
function smsAjaxContact(userId, groupId)
{
    $.post(siteUrl+"/sms/sms_ajaxContactList.php", { user_id: userId, group_id : groupId},
    function(data)
    {
        $('#groupContactList').html(data);
    });
}
function smsDatePicker(img)
{
    $(document).ready(function() {$( "#onDate" ).datepicker(
    {showOn: 'button', buttonImageOnly: true, buttonImage:img, dateFormat: 'yy-mm-dd', maxDate: new Date()});});
}
function checkSentSms()
{
    if(document.msgDate.onDate.value == '')
    {
        alert('Please Select date');
        return false;
    }
    return true;
}
function showHideBulkSmsCheckBox(countryId)
{
    if(countryId == 'other')
        $('#msgBulkSms').hide();
    else
        $('#msgBulkSms').show();
}
function showHideBulkSms(oldMobileNo)
{
    if(document.contactInfo.mobile_code.value != 'other')
    {
        var newMobileNo = document.contactInfo.mobile_code.value+document.contactInfo.mobile.value;

        if(oldMobileNo == newMobileNo)
            $('#msgBulkSms').hide();
        else
            $('#msgBulkSms').show();
    }
}
function checkSearchSms()
{
    $(document).ready(function(){$("#searchsms").validate();});
}

function smsReceivers($sId, $totalRes)
{
    for(i = 1; i <= $totalRes; i++)
    {
        if('r_'+i != $sId)
            $('#r_'+i).hide();
        else
            $('#r_'+i).show(480);
    }
}

function closeContactInfo($sId)
{
    $('#'+$sId).hide(1050);
}

function ajaxGetReceivers(smsId, sc, totalRes)
{
    $.post("sms_adListReceivers.php", {idSms: smsId, smsDivId: sc},
    function(data)
    {
        if(data)
        {
            $('#'+sc).html(data);
            $('#'+sc).show(480);

            for(i = 1; i <= totalRes; i++)
            {
                if('r_'+i != sc)
                    $('#r_'+i).hide();
                else
                    $('#r_'+i).show(480);
            }
        }
    });
}
function breakingNewsScroll()
{
    (function($) { $(function() { $("#scroller").simplyScroll({ autoMode: 'loop', speed: 2 }); }); })(jQuery);
}
function countCommentChars(charLimit)
{
    var len=document.newsComment.comment.value.length;
    var str=document.newsComment.comment.value;
    $('#msgChar').html(charLimit-len)
}
function checkRequiredFiled(formId)
{
    $(document).ready(function(){$("#"+formId).validate();});
}

function submitFrom(redirectUrl)
{
    document.seachNewsList.action = redirectUrl;
    document.seachNewsList.submit();
}
function showHideNewsImage(catId)
{
    if(catId == 8)
        $('#newsImg').hide();
    else
        $('#newsImg').show();
}
function confirmDeleteNews(redirectUrl)
{
    if(confirm("Are you sure you want to delete this record ?"))
        window.open(redirectUrl,'Delete News','scrollbars=1,resizable=1,width=400,height=120');
    else
        return false;
}
function openReportModalBox(popID,commentId)
{
    $(document).ready(function(){
        $('#your_name').attr("value", '');
        $('#email').attr("value", '');
        $('#subject').attr("value", '');
        $('#additional_info').attr("value", '');
        $('#errReport').html('');
        $('#comment_id').attr("value", commentId);

        $( "#"+popID ).dialog({
            maxHeight: 370,
            minHeight: 70,
            width: 625,
            resizable: false,
            modal: true
        });
        return false;
    });
}
function ajaxReportCall(ajaxUrl)
{
    $.post(ajaxUrl, {news_id: $('#news_id').attr('value'), comment_id : $('#comment_id').attr('value'), your_name : $('#your_name').attr('value'), email : $('#email').attr('value'), subject : $('#subject').attr('value'), additional_info : $('#additional_info').attr('value') },
    function(data)
    {
        msgStr = data.split('#!#');
        if(msgStr[1] == 'err')
            $('#errReport').html(msgStr[0]);
        else
        {
            $("#reportlink_"+$('#comment_id').attr('value')).html("<span class='gray'>Report abuse</span>");
            $("#popup1").dialog("destroy");
            $("#reportmsg_"+$('#comment_id').attr('value')).html(data);
        }
    });

    return false;
}

function newsCommentAjaxPagging(pageNo, idNews, ajaxUrl)
{
    $.post(ajaxUrl, {page:pageNo, id_news:idNews},
    function(data){
        $('#commentList').html(data);
    });
}

function ajaxNewsSearch(pageNo, searchName, ajaxUrl)
{
    $('#searchResAll').hide();
    $('#searchRes').html('<div class="news_loadimg">&nbsp;</div>');
    $("ul.tab_menu li").removeClass("active");
    $("ul.tab_menu li."+searchName).addClass("active");
    var searchVal = $("#searchVal").html();
    $.post(ajaxUrl, {search_val:searchVal, search_name:searchName, page:pageNo},
    function(data){
        $('#searchRes').html(data);
    });
}

function allNewsSearch()
{
    $("ul.tab_menu li").removeClass("active");
    $("ul.tab_menu li.all").addClass("active");
    $('#searchResAll').show();
    $('#searchRes').html('');
}

function checkNewsSearch()
{
    var str = $('#q').val();
    str = jQuery.trim(str);

    if($('#q').val() == '')
    {
        $('#errSearch').show();
        return false;
    }
    else if(str.length <= 1)
    {
        $('#errSearch').show();
        return false;
    }
    else
        $('#errSearch').hide();

    return true;
}
function submitReportSearch(redirectUrl)
{
    document.newsReport.action = redirectUrl;
    document.newsReport.submit();
}
function deleteReport()
{
    var form = document.forms.reportList, z = 0, totalChk = 0;
    for(z=0; z<form.length;z++)
    {
        if(form[z].type == 'checkbox' && form[z].checked == true)
        {
            totalChk = totalChk + 1
        }
    }
    if(totalChk > 0)
    {
        if(confirm("Are you sure you want to delete report(s) / comment(s)?"))
            document.reportList.submit();
    }
    else
        alert('Pelease select comment / report');
}

function fillClSubCat(catInfo, isSelect)
{
    $('#catMsg').html('');
    $('#adCatAttr').html('');
    $('#sub_category').show();
    $('select#sub_category').attr('disabled',false);
    var Category = catInfo.value;
    var subCatValues = $('#subCatVal').val();
    var rows = subCatValues.split('::');
    document.postAd.sub_category.length = 1;

    if(isSelect == 'Y')
    {
        var j = 1;
        document.postAd.sub_category.options[j] = new Option('select sub category', '');
    }
    else
        var j = 0;

    for(i = 0; i < rows.length; i ++ )
    {
        var row = rows[i].split(':');
        if(Category == row[0])
            document.postAd.sub_category.options[j ++ ] = new Option(row[2], row[1]);
    }
}

function openClModalBox(linkInfo, linkId)
{
    if(linkInfo)
        popuId = linkInfo.rel;
    else
        popuId = linkId;

    $("#"+popuId).dialog({
        maxHeight: 370,
        minHeight: 70,
        width: 625,
        resizable: false,
        modal: true
    });
}
function makeTabMenuActive(linkdata)
{
    $("ul.tab_menu li").each(function(i) {
        var linkName = $(this).find('a').attr("name");
        if(linkdata.name == linkName)
        {
            $(this).addClass('active');
            $('#'+linkName).show();
        }
        else
        {
            $(this).removeClass('active');
            $('#'+linkName).hide();
        }
    });
}

function aiAjaxEntity(entityId, entityType, entityReturn, isZipCode)
{
    if(entityReturn == 'DT')
        var dataId = 'district';
    if(entityReturn == 'CT')
        var dataId = 'city';
    if(entityReturn == 'LT')
        var dataId = 'locality';

    $.post(siteUrl+"/ai_ajaxEntity.php", { id: entityId, entity : entityType, returnVal : entityReturn, zipcode: isZipCode },
    function(data)
    {
        if(data.entity)
        {
            $("select#"+dataId).attr('disabled',false);
            $("select#"+dataId).html(data.entity);
        }
        else
        {
            $("select#"+dataId).attr('disabled',true);
            $("select#"+dataId).html('<option value="">- - Select '+dataId+' - -</option>');
        }

        if(isZipCode == 'y')
        {
            $("#zpCodeTxt").show();
            $("#zpCodeSel").hide();
            if(data.zipcode)
            {
                $("#zpCodeSel").show();
                $("#zpCodeSel").html(data.zipcode);
                $("#zpCodeTxt").hide();
            }
        }

    }, 'json');
}

function setEntityName(entity)
{
    var optiontext = entity.options[entity.selectedIndex].text;
    var entiyVal = entity.id+'_name';
    $('#'+entiyVal).attr("value", optiontext);
}

function checkClAdPost(isEdit, isUs)
{
    var totalErr = 0;
    if(isEdit == 'Y')
    {
        var arrAdPost = [ "category", "sub_category", "state", "city", "address", "title","description", "zip_code", "contact_name", "email"];
    }
    else
    {
        var arrAdPost = [ "category", "sub_category", "state", "city", "address", "title","description", "zip_code"];
    }

    $.each(arrAdPost, function(key, inputId) {
        if(jQuery.trim($('#'+inputId).val()) == '')
        {
            if(inputId != 'sub_category' && inputId != 'city' && inputId != 'zip_code')
                totalErr = AddErr(inputId, totalErr);
            else if(inputId == 'sub_category' && $('#category').val() > 0)
                totalErr = AddErr(inputId, totalErr);
            else if(inputId == 'city' && $('#state').val() > 0)
                totalErr = AddErr(inputId, totalErr);
        }
        else
        {
            if(inputId == 'zip_code')
            {
                chkZip = validateZipCode($('#'+inputId).val(), isUs);
                if(chkZip == false)
                    totalErr = AddErr(inputId, totalErr, 'Please enter valid zip code');
                else
                    AddSuc(inputId);
            }
            else
                AddSuc(inputId);
        }
    });

    if(document.getElementById('property_s'))
    {
        if($('#property_s').attr('checked') == false && $('#property_r').attr('checked') == false)
            totalErr = AddErr('chkPropertyType', totalErr, 'Please select Property type');
        else
            RemoveErr('chkPropertyType');
    }

    if(document.getElementById('room_1'))
    {
        if($('#room_1').attr('checked') == false && $('#room_2').attr('checked') == false && $('#room_3').attr('checked') == false && $('#room_4').attr('checked') == false && $('#room_5').attr('checked') == false)
            totalErr = AddErr('chkNoRoom', totalErr, 'No. of Rooms required');
        else
            RemoveErr('chkNoRoom');
    }

    if(document.getElementById('job_type_f'))
    {
        if($('#job_type_f').attr('checked') == false && $('#job_type_p').attr('checked') == false && $('#job_type_h').attr('checked') == false)
            totalErr = AddErr('chkJobtype', totalErr, 'Please selec job type');
        else
            RemoveErr('chkJobtype');
    }

    if(document.getElementById('ad_type'))
    {
        if($('#ad_type').attr('checked') == false && $('#ad_type_w').attr('checked') == false)
            totalErr = AddErr('chkAdType', totalErr, 'Please select ad type');
        else
            RemoveErr('chkAdType');
    }

    if(document.getElementById('post_by'))
    {
        if($('#post_by').attr('checked') == false && $('#post_by_o').attr('checked') == false)
            totalErr = AddErr('chkPostBy', totalErr, 'Please make a selection');
        else
            RemoveErr('chkPostBy');
    }

    if(document.getElementById('condition'))
    {
        if($('#condition').attr('checked') == false && $('#condition_n').attr('checked') == false)
            totalErr = AddErr('chkCondition', totalErr, 'Please make a selection');
        else
            RemoveErr('chkCondition');
    }

    if(document.getElementById('price'))
    {
        if(jQuery.trim($('#price').val()) == '' || jQuery.trim($('#price').val()) <= 0)
            totalErr = AddErr('price', totalErr);
        else
        {
            chkPrice = validatePrice($('#price').val());
            if(chkPrice == false)
                totalErr = AddErr('price', totalErr, 'Please enter valid price');
            else
                AddSuc('price');
        }
    }

    if(totalErr == 0)
        return true;
    else
        return false;
}

function checkEmpty(entity, entityType, justMsg, isUs)
{
    if(entityType == 'zipcode')
    {
        if(entity.value != '')
        {
            chkZip = validateZipCode(entity.value, isUs);
            if(chkZip == false || entity.value == '000000')
                AddErr(entity.id, '', 'Please enter valid zip code', justMsg);
            else
                AddSuc(entity.id);
        }
        else
            RemoveErr(entity.id);
    }
    else if(entityType == 'email')
    {
        if(entity.value != '')
        {
            chkEmail = validateEmail(entity.value);
            if(chkEmail == false)
                AddErr(entity.id, '', 'Please enter valid email', justMsg);
            else
                AddSuc(entity.id);
        }
        else
            AddErr(entity.id);
    }
    else if(entityType == 'mobile')
    {
        if(entity.value != '')
        {
            chkEmail = validateMobile(entity.value);
            if(chkEmail == false)
                AddErr(entity.id, '', 'Please enter valid mobile', justMsg);
            else
                AddSuc(entity.id);
        }
        else
            RemoveErr(entity.id);
    }
    else if(entityType == 'website')
    {
        if(entity.value != '')
        {
            chkWebsite = isUrl(entity.value);
            if(chkWebsite == false)
                AddErr(entity.id, '', 'Please enter valid web site', justMsg);
            else
                AddSuc(entity.id);
        }
        else
            RemoveErr(entity.id);
    }
    else
    {
        if(jQuery.trim(entity.value) == '')
            AddErr(entity.id, '', '', justMsg);
        else
            AddSuc(entity.id);
    }
}

function AddErr(errId, totErr, errMsg, justMsg)
{
    $("#"+errId).addClass('failed');
    RemoveSuc(errId);
    var spanErrId = 'err_'+errId;

    if(errMsg == '' || errMsg == null)
        errMsg = "<span style='text-transform:capitalize;'>"+errId.replace('_', ' ')+"</span> is required";

    if(document.getElementById(spanErrId))
    {
        var em=document.getElementById(spanErrId);
        em.parentNode.removeChild(em);
    }

    var errDispId = document.getElementById(errId);
    var em = document.createElement('span');
    em.id = spanErrId;
    if(justMsg == 'Y')
        em.innerHTML = "<span class='red lh18 pl5'>"+errMsg+"</span>";
    else
        em.innerHTML = "<span class='red lh18'> <img src='"+siteImgUrl+"/val-failure.gif' class='alignBottom'> <br/>"+errMsg+"</span>";
    errDispId.parentNode.insertBefore(em,errDispId.nextSibling);

    return totErr+1;
}

function AddSuc(errId)
{
    RemoveErr(errId);
    var spanSucId = 'suc_'+errId;

    if(document.getElementById(spanSucId))
    {
        var em=document.getElementById(spanSucId);
        em.parentNode.removeChild(em);
    }

    var errDispId = document.getElementById(errId);
    var em = document.createElement('span');
    em.id = spanSucId;
    em.innerHTML = "<span class='lh18'> <img src='"+siteImgUrl+"/val-success.gif' class='alignBottom'> </span>";
    errDispId.parentNode.insertBefore(em,errDispId.nextSibling);
}

function RemoveErr(errId)
{
    $("#"+errId).removeClass('failed');
    $('#err_'+errId).remove();
}

function RemoveSuc(errId)
{
    $('#suc_'+errId).remove();
}

function validateZipCode(elementValue, isUs)
{
    if(isUs == 'Y')
        var zipCodePattern = /(^\d{5}$)/;
    else
        var zipCodePattern = /^\d{6}$|^\d{3}-\d{3}|^\d{3} \d{3}$/;

    return zipCodePattern.test(elementValue);
}

function validatePrice(price)
{
    var pricePattern = /^([0-9\.]+)$/;
    return pricePattern.test(price);
}

function validateEmail(email)
{
    var emailPattern = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    return emailPattern.test(email);
}

function validateMobile(mobile)
{
    var mobilePattern = /[0-9]$/;
    mobile = mobile.replace(/[\(\)\+\-\s]/g, "");
    if(mobilePattern.test(mobile) == false)
        return false;
    else if(mobile.length < 10 || mobile.length > 15)
        return false;
    else
        return true;
}

function validateIndianMobile(mobile)
{
    var startOfMobile = mobile.charAt(0);

    if((startOfMobile == '9' || startOfMobile == '8' || startOfMobile == '7') && mobile.length == 10)
        return true;
    else
        return false;
}

function isUrl(s)
{
    var regexpPattern = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
    return regexpPattern.test(s);
}

function addTempImage(formSession, fieldName, msgid, dataId)
{
    $("#loading")
    .ajaxStart(function(){$(this).show();})
    .ajaxComplete(function(){$(this).hide();});

    $.ajaxFileUpload({
        url:siteUrl+'/ai_ajaxAddTempImg.php?formSession='+formSession+'&fieldName='+fieldName,
        secureuri:false,
        fileElementId:fieldName,
        dataType: 'json',
        success: function (data, status)
        {
            if(typeof(data.error) != 'undefined')
            {
                if(data.error != '')
                    $('#'+msgid).html(data.error);
                if(data.msg)
                    $('#'+msgid).html(data.msg);
                if(data.imgdata)
                    $('#'+dataId).html(data.imgdata);
                if(data.allUploaded == 'Y')
                    $('#'+fieldName).hide();
                else
                    $('#'+fieldName).show();
            }
            $('#'+fieldName).val('');
        }
    });

    return false;
}

function removeClTempImage(imgId)
{
    $.post(siteUrl+"/ai_ajaxAddTempImg.php", { removeImg: 'Y', img_id : imgId, formSession: 'FORM_CL_POST_AD' },
    function(data){$('#addedClImg').html(data);$('#clImgMsg').html('');$('#ad_image').show();});
}

function getAdAttributes(subCatId)
{
    $.post("cl_ajaxAdPostCatAttributes.php", { sId: subCatId },
    function(data){
        $('#catMsg').html(data.msg);
        $('#adCatAttr').html(data.attrTxt);
    }, "json");
}

function checkEmailAdvretiser()
{
    var totalErr = 0;
    var arrPostVar = [ "name", "email", "reply_message", "verification"];

    $.each(arrPostVar, function(key, inputId) {
        entityVal = jQuery.trim($('#'+inputId).val());
        if(jQuery.trim(entityVal) == '')
            totalErr = AddErr(inputId, totalErr);
        else if(inputId == 'email')
        {
            chkEmail = validateEmail(entityVal);
            if(chkEmail == false)
                totalErr = AddErr(inputId, '', 'Please enter valid email');
            else
                AddSuc(inputId);
        }
        else
            AddSuc(inputId);
    });

    if(totalErr == 0)
    {
        $.post(clUrl+"/addetail", { name: $('#name').val(), email : $('#email').val(), msg: $('#reply_message').val(), code : $('#verification').val(), adId : $('#adId').val(), mobile : $('#mobile').val(), module : 'advertiser' },
        function(data){
            $('#errMsg').html(data.err);
            if(data.captchaImg)
                $('#captachImg').html(data.captchaImg);
            if(data.mailSend)
            {
                $.each(arrPostVar, function(key, inputId) {
                    $('#'+inputId).val('');
                    RemoveSuc(inputId);
                });
                $('#emailAdvertiser').dialog('close');
                $('#detailSuc').html('Mail Sucessfully sent');
            }
        }, "json");
    }

    return false;
}

function checkFwdToFrd()
{
    var totalErr = 0;
    var arrPostVar = [ "your_name", "your_email", "recepient_email"];

    $.each(arrPostVar, function(key, inputId) {
        entityVal = jQuery.trim($('#'+inputId).val());
        if(jQuery.trim(entityVal) == '')
            totalErr = AddErr(inputId, totalErr);
        else if(inputId == 'your_email' || inputId == 'recepient_email')
        {
            chkEmail = validateEmail(entityVal);
            if(chkEmail == false)
                totalErr = AddErr(inputId, '', 'Please enter valid email');
            else
                AddSuc(inputId);
        }
        else
            AddSuc(inputId);
    });

    if(totalErr == 0)
    {
        $.post(clUrl+"/addetail", { adTitle: $('#adTitle').val(), adId : $('#adId').val(), fromName: $('#your_name').val(), fromEmail : $('#your_email').val(), toEmail : $('#recepient_email').val(), module : 'fwdfrd' },
        function(data){
            $('#errMsg').html(data.err);
            if(data.mailSend)
            {
                $.each(arrPostVar, function(key, inputId) {
                    $('#'+inputId).val('');
                    RemoveSuc(inputId);
                });
                $('#forwardFrd').dialog('close');
                $('#detailSuc').html('Mail Sucessfully sent');
            }
        }, "json");
    }

    return false;
}

function clBookmarkAd(adId, linkInfo)
{
    $.post(clUrl+"/addetail", { adId : $('#adId').val(), module : 'bookmark' },
    function(data){
        $('#detailSuc').html('Added to favorite.');
        linkInfo.setAttribute("onclick", 'openClModalBox("", \''+linkInfo.rel+'\')');
        $('#showFavAdMsg').html('Already added to your favourite list');
    }, "json");
}

function clBookmarkAdFromList(adId)
{
    $.post(clUrl+"/addetail", { adId : adId, module : 'bookmark' },
    function(data){
        document.getElementById("adbm_"+adId).setAttribute("onclick", 'clRemoveBookmarkAdFromList('+adId+')');
        $("#adbm_"+adId).html("<img src='"+siteImgUrl+"/icon_star_full.gif' alt='' />");
        $("#adbm_"+adId).attr("title", 'click here to remove this ad from bookmark');
    });
}

function clRemoveBookmarkAdFromList(adId)
{
    $.post(clUrl+"/addetail", { adId : adId, module : 'bookmark_del' },
    function(data){
        document.getElementById("adbm_"+adId).setAttribute("onclick", 'clBookmarkAdFromList('+adId+')');
        $("#adbm_"+adId).html("<img src='"+siteImgUrl+"/icon_star_empty.gif' alt='' />");
        $("#adbm_"+adId).attr("title", 'click here for add this ad to bookmark');
    });
}

function clReportAd()
{
    var totalErr = 0;
    var arrPostVar = [ "reason", "report_name", "report_email", "comment", "verification_code"];

    $.each(arrPostVar, function(key, inputId) {
        entityVal = jQuery.trim($('#'+inputId).val());
        if(jQuery.trim(entityVal) == '')
        {
            if(inputId == 'report_name')
                totalErr = AddErr(inputId, totalErr, 'Please enter your name');
            else if(inputId == 'report_email')
                totalErr = AddErr(inputId, totalErr, 'Please enter your email');
            else
                totalErr = AddErr(inputId, totalErr);
        }
        else if(inputId == 'report_email')
        {
            chkEmail = validateEmail(entityVal);
            if(chkEmail == false)
                totalErr = AddErr(inputId, '', 'Please enter valid email');
            else
                AddSuc(inputId);
        }
        else
            AddSuc(inputId);
    });

    if(totalErr == 0)
    {
        $.post(clUrl+"/addetail", { adId : $('#adId').val(), idReport: $('#reason').val(), name : $('#report_name').val(), email : $('#report_email').val(), comment : $('#comment').val(), code : $('#verification_code').val(), module : 'report' },
        function(data){
            $('#errReportMsg').html(data.err);
            if(data.captchaImg)
                $('#captachReportImg').html(data.captchaImg);
            if(!data.err)
            {
                $.each(arrPostVar, function(key, inputId) {
                    $('#'+inputId).val('');
                    RemoveSuc(inputId);
                });
                $('#reportSpam').dialog('close');
                $('#detailSuc').html('Your report has successfully sent to admin.');
            }
        }, "json");
    }

    return false;
}

function showHideTabMenu(tabInfo)
{
    $("ul#tabmenu li a").each(function(i) {
        if($(this).attr("name") != tabInfo.name)
        {
            $('#'+$(this).attr("name")).hide();
            $(this).removeClass("active");
        }
        else
        {
            $('#'+$(this).attr("name")).show();
            $(this).addClass("active");
        }
    });
}

function showHideRanking(tabInfo, idVal)
{
    $("ul#"+idVal+" li").each(function(i) {
        var linkName = $(this).find('a').attr("name");
        if(linkName != tabInfo.name)
        {
            $('#'+linkName).hide();
            $(this).removeClass("active");
        }
        else
        {
            $('#'+linkName).show();
            $(this).addClass("active");
        }
    });
}

function reloadScore()
{
    setTimeout('location.reload(true);', 30000);
}

function numberCheck(objF)
{
    var val = objF.value;

    if(!/^[0-9]+$/.test(val))
    {
        objF.value='';
        objF.focus();
        return false;
    }
}

function showHideBlock(objChk, idBlock)
{
    if(objChk && objChk.checked)
        document.getElementById(idBlock).style.display = 'inline-block';
    else
        document.getElementById(idBlock).style.display = 'none';
}

function getCheckedValue(radioObj)
{
    if(!radioObj)
        return '';

    var radioLength = radioObj.length;

    if(radioLength == undefined)
        if(radioObj.checked)
            return radioObj.value;
        else
            return '';

        for(var i = 0; i < radioLength; i++)
        {
            if(radioObj[i].checked)
            {
                return radioObj[i].value;
            }
        }
        return '';
}

function setExtraRun(objChk)
{
    if(objChk.value != 0)
        document.getElementById('id_extra').innerHTML = 1;
    else
        document.getElementById('id_extra').innerHTML = 0;
}

function setTotalRun()
{
    var totalRun = extra = boundry = runs = 0;
    var empty_ball = '';

    boundry = getCheckedValue(document.updateMatch.boundry);
    boundry = (isNaN(boundry)) ? 0 : boundry;
    empty_ball = getCheckedValue(document.updateMatch.empty_ball);

    if(empty_ball != 0)
        extra = 1;

    if(empty_ball == 'WB')
        document.getElementById('id_leg_bye').style.display = 'none';
    else
        document.getElementById('id_leg_bye').style.display = 'inline-block';

    if(boundry != 0)
    {
        document.updateMatch.runs.value = '';
        document.getElementById('id_run').style.display = 'none';
    }
    else
        document.getElementById('id_run').style.display = 'inline-block';

    runs = document.updateMatch.runs.value;
    runs = (isNaN(runs)) ? 0 : runs;

    //totalRun = eval(boundry)+eval(runs);
    totalRun = Number(boundry)+Number(runs)+Number(extra);

    document.getElementById('id_total').innerHTML = totalRun;
}

function setBatsManId()
{
    var objFrm = document.updateMatch.striker
    var fLength = objFrm.length;

    for(var i = 0; i < fLength; i++)
    {
        if(!objFrm[i].checked)
        {
            document.getElementById('id_non_striker').value = objFrm[i].value;
            break;
        }
    }

}

function ajaxGetPlayer(idTour, idMatch, idTeam, idCur, idBlock)
{
    var reqPars = 'id_tour='+idTour+'&id_match='+idMatch+'&id_team='+idTeam+'&id_curVal='+idCur+'&id_block='+idBlock;

    requestURL = location.protocol+'//'+location.hostname+portNo+'/cr_adGetPlayerList.php?'+reqPars;

    jQuery.fn.colorbox({
            href:requestURL
     });
}

function updatePlayer(objForm)
{
    var selPlayer = playerId = playerName = id_block = curVal = '';

    selPlayer = getCheckedValue(objForm.id_player);

    if(selPlayer)
    {
        arrpInfo = selPlayer.split('#');
        playerId = arrpInfo[0];
        playerName = arrpInfo[1];
    }

    if(!playerId)
    {
        alert('Please select player');
        return false;
    }
    else
    {
        id_block = objForm.id_block.value;
        curVal = objForm.id_curVal.value;

        jQuery.fn.colorbox.close();

        document.getElementById(id_block).innerHTML = playerName;

        if(id_block == 'id_striker_info')
            document.getElementById('id_striker').value = playerId;

        if(id_block == 'id_striker_info_opp')
            document.getElementById('id_striker_opp').value = playerId;

        setBatsManId();

        if(id_block == 'id_bowler_info')
            document.getElementById('id_bowler').value = playerId;

        if(curVal == 'id_wicket_by') //Assing cur valu as id
            document.getElementById('id_wicket_by').value = playerId;
    }

    return true;
}

function setWicketInfo()
{
    capSetPlayer = 'Set Player';

    document.getElementById('id_wicket_by').value = 0;
    document.getElementById('id_wicket_by_c').innerHTML = capSetPlayer;
    document.getElementById('id_wicket_by_ro').innerHTML = capSetPlayer;
    document.getElementById('id_wicket_by_sto').innerHTML = capSetPlayer;
}

function confirmSetToss()
{
    if(confirm('Are you sure you want to set this Toss Details ?'))
        return true;
    else
        return false;
}

function confirmChangeInning()
{
    if(confirm('Are you sure you want to Change Innings ?'))
        return true;
    else
        return false;
}

function checkCricketSmsUpdate()
{
    totalErr = 0;

    entity = document.sendScore.mobile;
    if(entity.value != '')
    {
        chkEmail = validateMobile(entity.value);
        if(chkEmail == false)
            totalErr = AddErr(entity.id, '', 'Please enter valid mobile');
        else
            RemoveErr(entity.id);
    }
    else
        totalErr = AddErr(entity.id);

    if(totalErr == 0)
    {
        mobile = document.sendScore.mobile.value;
        $.post(siteUrl+"/ai_ajaxSmsScoreUpdate.php", { mobile: mobile},
        function(data)
        {
            if(data)
                window.location = data;
        });
    }
}

function addSmsUpdate()
{
    var form = document.forms.smsUpdate, z = 0, totalChk = 0;
    for(z=0; z<form.length;z++)
    {
        if(form[z].type == 'checkbox' && form[z].checked == true)
        {
            totalChk = totalChk + 1
        }
    }
    if(totalChk == 0)
    {
        if(confirm("Are you sure you don't want to get Live Score SMS Update?"))
            return true;
        else
            return false;
    }

    return true;
}

function cricketPoll(chkPoll)
{
    var optId = $('input[name=pollOpt]:checked').val();
    ajaxFlag = 1;

    if(chkPoll != 'N')
    {
        if(optId)
            ajaxFlag = 1;
        else
        {
            alert('Please select an option');
            ajaxFlag = 0;
        }
    }

    if(ajaxFlag)
    {
        var pollId = $('#pollId').val();
        $.post(siteUrl+"/ai_ajaxCricketPoll.php", { pollId: pollId, optId:optId },
        function(data)
        {
            if(data)
                $('#pollRes').html(data);
        });
    }
}
function checkInstantMsg()
{
    if(document.newSms.message.value == '')
    {
        alert('Please enter message');
        document.newSms.message.focus();
        return false;
    }
    return true;
}

function addClImage(fieldName, msgid, dataId)
{
    $("#loading")
    .ajaxStart(function(){$(this).show();})
    .ajaxComplete(function(){$(this).hide();});

    adId = document.getElementById('id_ad').value;

    $.ajaxFileUpload({
        url:clUrl+'/addimage?fieldName='+fieldName+'&adId='+adId,
        secureuri:false,
        fileElementId:fieldName,
        dataType: 'json',
        success: function (data, status)
        {
            if(typeof(data.error) != 'undefined')
            {
                if(data.error != '')
                    $('#'+msgid).html(data.error);
                if(data.msg)
                    $('#'+msgid).html(data.msg);
                if(data.imgdata)
                    $('#'+dataId).html(data.imgdata);
                if(data.allUploaded == 'Y')
                    $('#'+fieldName).hide();
                else
                    $('#'+fieldName).show();
            }
            $('#'+fieldName).val('');
        }
    });

    return false;
}

function removeClImage(imgId)
{
    var confirmDel = confirmDelete();

    if(confirmDel)
    {
        adId = document.getElementById('id_ad').value;

        $.post(clUrl+"/addimage", { removeImg: 'Y', img_id : imgId, adId : adId},
        function(data){$('#addedClImg').html(data);$('#clImgMsg').html('');$('#ad_image').show();});
    }
}

function setSmsUpdateResult(teamInfo)
{
    if(teamInfo)
    {
        teamId = teamInfo.value;

        if(teamId == 'd')
            document.getElementById('matchTeam').value = '';
        else
            document.getElementById('matchTeam').value = document.getElementById('sn_'+teamId).value;
    }

    msg = document.getElementById('matchRes').value;
    msgRes = document.getElementById('result').value;
    teamName = document.getElementById('matchTeam').value;

    if(teamName)
        teamName = teamName+' won by ';

    document.getElementById('message').value = msg+'Result : '+teamName+msgRes;
    document.getElementById('msgChar').innerHTML = 140 - (document.getElementById('message').value.length);
}

function showHideMatchMessage(msgType)
{
    if(msgType.value == 'N')
        $('#dlmethodMsg').hide();
    else
        $('#dlmethodMsg').show();
}

function validateOver(over)
{
    var overPattern = /^[0-9]{1,2}$|^[0-9]{1,2}\.[0-9]$/;
    return overPattern.test(over);
}

function validateRun(run)
{
    var runPattern = /^[0-9]{1,3}$/;
    return runPattern.test(run);
}

function validateWicket(wicket)
{
    var wicketPattern = /^[0-9]{1,2}$/;
    return wicketPattern.test(wicket);
}

function checkMatchMessage()
{
    var totErr = 0;

    if($('#normal').attr('checked') == true && $('#message').val() == '')
    {
        $('#errMatchMsg').html('Please Enter Message');
        return false;
    }

    if($('#dlmethod').attr('checked') == true && $('#over').val() == '' && $('#target').val() == '' && $('#wicket').val() == '')
    {
        $('#errMatchMsg').html('Please Enter target');
        return false;
    }

    if($('#over').val() != '')
    {
        chkOver = validateOver($('#over').val());
        if(chkOver == false)
        {
            totErr = totErr + 1;
            $('#over').focus();
        }
    }
    if($('#target').val() != '')
    {
        chkRun = validateRun($('#target').val());
        if(chkRun == false)
        {
            totErr = totErr + 1;
            $('#target').focus();
        }
    }
    if($('#wicket').val() != '')
    {
        chkWicket = validateWicket($('#wicket').val());
        if(chkWicket == false)
        {
            totErr = totErr + 1;
            $('#wicket').focus();
        }
    }

    if(totErr > 0)
    {
        $('#errMatchMsg').html('Please Enter valid target');
        return false;
    }
    else
    {
        $('#errMatchMsg').html('');
        return true;
    }
}

function removeClFavAd(adinfo)
{
    if(confirm("If you wish to remove this ad from your favourites, click the ok button"))
    {
        adId = ((adinfo.id).replace('rem_', ''));
        $.post(clUrl+"/addetail", { adId : adId, module : 'bookmark_del' },
        function(data){
            window.location = clUrl+'/favoritead.html';
        });
    }
}

function chkingsearch()
{
    if(document.clSearch.q.value == '' && document.clSearch.l.value == '')
    {
        alert("please enter keyword or location");
        document.clSearch.q.focus();
        return false;
    }
    return true;
}

function clSelectCity(cityStart, ajaxUrl)
{
    $("#cityList").text("Loading...");
    $.post(ajaxUrl+'/searchcity', {cityStart:cityStart},
    function(data)
    {
        if(data)
        {
            $("#cityList").html(data.city);
            $("#alphaStrcityList").html(data.alphaStr);
            if(data.pCity)
                $("#popularCity").html(data.pCity);

        }
    }, "json");
}

function clShowState(isToggle, ajaxUrl)
{
    if(isToggle == 'Y')
    {
        $('#changeCity').toggle();
        if(document.getElementById("cityList").innerHTML == '')
            clSelectCity('', ajaxUrl);
    }
    else
        $('#changeCity').hide();
}

function selectCityPagging(formNm, fieldNm)
{
    function pageselectCallback(page_index, jq){
        var new_content = jQuery('#hiddenresult div.ctList:eq('+page_index+')').clone();
        $('#Searchresult').empty().append(new_content);
        setCityInfoForSearch(formNm, fieldNm);
        return false;
    }

    function initPagination() {
        var num_entries = jQuery('#hiddenresult div.ctList').length;
        $('#Pagination').pagination(num_entries, {
            callback: pageselectCallback,
            items_per_page:1,
            num_display_entries:0
        });
        }

    $(document).ready(function(){
        initPagination();
    });
}

function setCityInfoForSearch(formNm, fieldNm)
{
    $('#Searchresult div.ctList ul li a').mouseover(function() {
        $('#cityInfo').html($(this).attr('title'));
    }).mouseout(function(){
        $('#cityInfo').html('');
    }).click(function() {
        if($(this).attr('class') == 'double')
            eval("document."+formNm+"."+fieldNm+".value = '"+$(this).attr('title')+"';");
        else
            eval("document."+formNm+"."+fieldNm+".value = '"+$(this).attr('name')+"';");

        $('#changeCity').hide();
    });
}

function setCityForSearch(cityInfo, formNm, fieldNm)
{
    eval("document."+formNm+"."+fieldNm+".value = '"+cityInfo.title+"';");
    $('#changeCity').hide();
}

function checkYpInquiry(isUser)
{
    var totalErr = 0;
    if(isUser == 'Y')
        var arrPostVar = [ "product_name", "detail"];
    else
        var arrPostVar = [ "product_name", "detail", "login_id", "password"];

    $.each(arrPostVar, function(key, inputId) {
        if($('#'+inputId).length > 0)
        {
            entityVal = jQuery.trim($('#'+inputId).val());
            if(jQuery.trim(entityVal) == '')
                totalErr = AddErr(inputId, totalErr);
            else
                AddSuc(inputId);
        }
    });

    if(totalErr == 0)
        return true;
    else
        return false;
}

function addPlayerForIpl(btninfo)
{
    var isPlayerChk = teamId = 0;
    var capIs = wcIs = 'N';
    var playerType = '';

    playerId = jQuery.trim((btninfo.name).replace('save_', ' '));

    var tourId = document.addPlayer.tourId.value;
    var matchId = document.addPlayer.idMatch.value;
    var countryId = document.addPlayer.countryId.value;

    if($('#cap_'+playerId).length > 0)
        var capBox = "document.addPlayer.cap_"+playerId+".checked;";
    if($('#wc_'+playerId).length > 0)
        var wcBox = "document.addPlayer.wc_"+playerId+".checked;";
    if($('#playerType').length > 0)
        var playerType = $('#playerType').attr('value');

    if(eval("document.addPlayer.match_"+playerId+".checked;") == true)
        isPlayerChk = playerId
    if(capBox)
    {
        if(eval(capBox) == true)
            capIs = 'Y';
    }
    if(wcBox)
    {
        if(eval(wcBox) == true)
            wcIs = 'Y';
    }

    tourMatchPlayerId = eval("document.addPlayer.tour_match_player_id_"+playerId+".value;");
    teamId = eval("document.addPlayer.team_"+playerId+".value;");

    if(tourMatchPlayerId > 0)
        var playerMsg = 'Updated';
    else
        var playerMsg = 'Added';

    if(isPlayerChk == 0 || teamId == 0)
        alert('Please Check Player and Select Team');
    else
        $.post("cr_adAjaxPlayerForTournament.php", { idTour : tourId, idMatch : matchId, idPlayer : playerId, idTeam : teamId, isCap : capIs, isWc : wcIs, tourMatchPlayerId : tourMatchPlayerId, playerType : playerType},function(data){
            if(data.errMsg)
            {
                eval("document.addPlayer.match_"+playerId+".checked = false;");
                eval("document.addPlayer.cap_"+playerId+".checked = false;");
                eval("document.addPlayer.wc_"+playerId+".checked = false;");
                alert(data.errMsg);
            }
            else
            {
                if(capIs == 'Y' || wcIs == 'Y')
                {
                    window.location = $('#teamSetUrl').attr('value')+'idCountry='+countryId;
                }
                else if(data.playerId)
                {
                    eval("document.getElementById('tour_match_player_id_'+playerId).value = "+data.playerId+";");
                    $(btninfo).attr('value', 'Edit');
                    jQuery('#id_delete_'+playerId).html('<a href="#" onclick="removeIplPlayer('+data.playerId+')" title="Delete Player from Tournament">X</a>');
                    jQuery('#id_msg_'+playerId).html(playerMsg);
                    textBlinking_1('id_msg_'+playerId, 'green_text', 'redtext');
                }
            }
        }, "json");
}

function removeIplPlayer(idTourPlayer)
{
    var tourId = document.addPlayer.tourId.value;
    var matchId = document.addPlayer.idMatch.value;
    var countryId = document.addPlayer.countryId.value;

    if(confirm("Are you sure you want to remove this player in this tournament ?"))
    {
        $.post("cr_adAjaxPlayerForTournament.php", { idTourPlayer : idTourPlayer, idMatch : matchId, idTour : tourId, playerAction : 'del'},
        function(data){
            window.location = $('#teamSetUrl').attr('value')+'idCountry='+countryId;
        }, "json");
    }
}

function setUrl(countryId)
{
    if(countryId)
    {
        window.location = $('#teamSetUrl').attr('value')+'idCountry='+countryId;
    }
}

function textBlinking_1(idName, clsName1, clsName2, cntN, cntB)
{
    if(cntN == '' || isNaN(cntN)) cntN = 3;
    if(cntB == '' || isNaN(cntB)) cntB = 0;
    cntB++;

    $('#'+idName).removeClass(clsName2);
    $('#'+idName).addClass(clsName1);
    setTimeout('textBlinking_2("'+idName+'","'+clsName1+'","'+clsName2+'","'+cntN+'","'+cntB+'");',500);
}

function textBlinking_2(idName, clsName1, clsName2, cntN, cntB)
{
    $('#'+idName).removeClass(clsName1);
    $('#'+idName).addClass(clsName2);

    if(cntB < cntN)
        setTimeout('textBlinking_1("'+idName+'","'+clsName1+'","'+clsName2+'","'+cntN+'","'+cntB+'");',500);
}

function ajaxYpEntity(idCat, idSubCat)
{
    if(idCat)
        resId = 'subcategory';
    else
        resId = 'yp_section';

    $.post(ypUrl+'/entity', { id_cat: idCat, id_subcat : idSubCat},
    function(data){
        if(data)
        {
            document.getElementById(resId).style.display = '';
            $('#'+resId).html(data);
        }
        else
            $('#'+resId).html('<td></td>');
    });
}
function checkYpBusinessPost()
{
    var totalErr = 0;
    var arrAdPost = [ 'business_name', 'category', 'state', 'district', 'city', 'address', 'zip_code', 'contact_person', 'email', 'website'];

    $.each(arrAdPost, function(key, inputId) {
        if(jQuery.trim($('#'+inputId).val()) == '' && inputId != 'zip_code' && inputId != 'website')
            totalErr = AddErr(inputId, totalErr, '', 'Y');
        else if(inputId == 'zip_code' || inputId == 'website')
        {
            if(jQuery.trim($('#'+inputId).val()) != '')
            {
                if(inputId == 'zip_code')
                {
                    chkZip = validateZipCode($('#'+inputId).val());
                    if(chkZip == false)
                        totalErr = AddErr(inputId, totalErr, 'Please enter valid zip code', 'Y');
                    else
                        AddSuc(inputId);
                }
                if(inputId == 'website')
                {
                    chkWeb = isUrl($('#'+inputId).val());
                    if(chkWeb == false)
                        totalErr = AddErr(inputId, totalErr, 'Please enter valid website', 'Y');
                    else
                        AddSuc(inputId);
                }
            }
            else
                RemoveErr(inputId);
        }
    });

    if(document.addBusiness.tearm_cond)
    {
        if(document.addBusiness.tearm_cond.checked == false)
        {
            $("#err_tc").show();
            totalErr = totalErr +1;
        }
        else
        {
            $("#err_tc").hide();
            if(totalErr > 0)
                totalErr = totalErr - 1;
        }
    }

    if(jQuery.trim($('#mobile').val()) == '' && ($('#area_code').val() == 'Area Code' || $('#phone').val() == 'Phone'))
    {
        totalErr = AddErr('mobile', totalErr, 'Please enter either mobile or phone number', 'Y');
        $('#area_code').addClass('failed');
        $('#phone').addClass('failed');
    }
    else
    {
        RemoveErr('mobile');
        $('#area_code').removeClass('failed');
        $('#phone').removeClass('failed');
    }

//     var arrContHead = ['comp_info', 'products', 'photo_video', 'contacts', 'inquiry', 'offers'];
//
//     $.each(arrContHead, function() {
//         if($('#'+this).val().length > 25)
//         {
//             totalErr = AddErr(this, totalErr, 'Content Heading length should be maximum 35 characters', 'Y');
//             $('#'+this).addClass('failed');
//         }
//         else
//         {
//             RemoveErr(this);
//             $('#'+this).removeClass('failed');
//         }
//     });

    if(totalErr == 0)
        return true;
    else
        return false;
}

function setMsgToTextBox(txtInfo, txtMsg, callType)
{
    if(callType == 'F')
    {
        if($('#'+txtInfo.id).val() == txtMsg)
        {
            $('#'+txtInfo.id).removeClass("gray");
            $('#'+txtInfo.id).val('');
        }
    }
    else
    {
        if($('#'+txtInfo.id).val() == '')
        {
            $('#'+txtInfo.id).addClass("gray");
            $('#'+txtInfo.id).val(txtMsg);
        }
    }
}

function checkAddRemoveYpProduct(isEdit)
{
    var err = suc = 0;
    var totProduct = document.addBusinessProduct.theValue.value;

    for( i = 1; i <= totProduct; i++ )
    {
        var pName = eval("document.addBusinessProduct.product_name_"+i+".value;")
        var pImg = eval("document.addBusinessProduct.product_img_"+i+".value;")
        var pDesc = eval("document.addBusinessProduct.description_"+i+".value;")

        if(isEdit == 'Y')
        {
            if(pName == '')
                err = 1;
            else
            {
                err = 0;
                suc = 1;
            }
        }
        else
        {
            if(((pName == '' || pImg == '') && suc == 0)|| (pName != '' && pImg == '') || (pName == '' && pImg != '') || (pDesc != '' && (pName == '' || pImg == '')))
                err = 1;
            else
            {
                err = 0;
                suc = 1;
            }
        }
    }

    if(err == 1)
    {
        alert('Please Enter Proper Product / Service Information.');
        return false;
    }
    if(pImg)
    {
        imgErr = checkPhoto(pImg);
        if(imgErr == false)
            return false;
    }

    return true;
}

function addAnotherProduct(maximg, isEdit)
{
    var imgTot = $('table.product_txt').size() + 1;

    if(maximg == imgTot)
        $('#addProductLink').html('');

    var numi = document.getElementById('theValue');
    var num = (document.getElementById('theValue').value -1)+ 2;
    numi.value = num;

    var content = ($('#product1 div.fl').html()).replace(/_1/g, "_"+num);
    var newdiv = document.createElement('div');
    var divIdName = 'product'+num;
    newdiv.setAttribute('id',divIdName);
    newdiv.innerHTML = '<div class=\'fl width_60\'>'+content+'</div><div class=\'fl font_11 underline\' style=\'padding-top:21%;\'><a href=\'javascript:void(0);\' onclick=\'removeProduct("'+divIdName+'", '+maximg+', "'+isEdit+'")\' title=\'Click here to remove product / service\'>Remove product / service</a></div><div class=\'clear\'></div>';
    $(newdiv).addClass('border_top1 mt10 pt10').appendTo('#productTxt');
    $('#imgErr_'+num).html('');
    $('#'+divIdName+' div.fl input').each(function(i) {
        $(this).attr('value', '');
    });
    $('#'+divIdName+' div.fl textarea').html('');
}

function removeProduct(divNum, maximg, isEdit)
{
    var htmlAppend = '';

    if(isEdit == 'Y')
        htmlAppend = '&nbsp; | &nbsp;';

    $('#addProductLink').html('<a href=\'javascript:void(0)\' onclick=\'addAnotherProduct('+maximg+');\' title=\'Click here to add another product / service\'>Add another Product / service</a>'+htmlAppend);
    $('#'+divNum).remove();
}

function ypFavoriteBusiFromList(busiId)
{
    $.post(ypUrl+'/favorite', { idBusi : busiId},
    function(data){
        $('#busi_hide_'+busiId).hide();
        $('#busi_show_'+busiId).show();
    });
}

function checkYpSearch(isProduct)
{
    if(document.ypSearchBusi.business.value == '' || document.ypSearchBusi.business.value == 'Enter search keyword ....')
    {
        alert('Please enter Search keyword.');
        document.ypSearchBusi.business.focus();
        return false;
    }

    return true;
}

function checkPhoto(imagePath)
{
    var pathLength = imagePath.length;
    var lastDot = imagePath.lastIndexOf(".");
    var fileType = (imagePath.substring(lastDot,pathLength)).toLowerCase();

    if((fileType == ".gif") || (fileType == ".jpg") || (fileType == ".png") || (fileType == ".jpeg"))
        return true;
    else
    {
        alert('Please upload proper image');
        return false;
    }
}

function clRedirectStatePage(state)
{
    window.location = clUrl+'/'+state;
}

function checkClChangeStatus(idad)
{
    if(document.changeSts.adstatus.checked == false)
    {
        alert('Please Select status');
        return false;
    }
    else
    {
        if(document.changeSts.adstatus.value == 'T')
            var newSts = '<b>Terminate</b>';
        else if(document.changeSts.adstatus.value == 'A')
            var newSts = '<b>Active</b>';

        window.opener.$('#status_'+idad).html(newSts);
    }

    return true;
}

function submitFromForPagging(redirectUrl)
{
    document.seachList.action = redirectUrl;
    document.seachList.submit();
}

function enCheckSearch()
{
    if(document.enSearch.q.value == '' || document.enSearch.section.value == '')
    {
        alert("please enter search and select section");
        document.enSearch.q.focus();
        return false;
    }
    return true;
}

function setCookie(c_name, value, exdays)
{
    if(exdays)
    {
        var exdate = new Date();
        exdate.setDate(exdate.getDate() + exdays);
        var c_value = escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
    }
    else
        var c_value = escape(value);

    document.cookie = c_name + "=" + c_value;
}

function getCookie(c_name)
{
    var i,x,y,ARRcookies = document.cookie.split(";");
    for(i = 0; i<ARRcookies.length; i++)
    {
        x = ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
        y = ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
        x = x.replace(/^\s+|\s+$/g,"");
        if (x == c_name)
            return unescape(y);
    }
}

function setSlideShow(c_name, urlRed, lastPage)
{
    cookieChk = getCookie(c_name);

    if(!cookieChk)
        setCookie(c_name, 'pause');
    else if(cookieChk == 'play' && urlRed)
        myTimeout = setTimeout("location.href='"+urlRed+"'", 4000);

    if(lastPage == 'y')
        setCookie(c_name, 'pause');

    $(function() {$('#playSlideShow li a').click(
        function() {
            setCookie(c_name, 'play');
        });
    });
    $(function() {$('#pauseSlideShow li a').click(
        function() {
            setCookie(c_name, 'pause');
            $("#pauseSlideShow").hide();
            $("#slideShowNavStr").hide();
            $("#playSlideShow").show();
            $("#slideShowPage").show();
            clearTimeout(myTimeout);
        });
    });
}


function addYpPicture(fieldName, msgid, idBusi, isVideo, maxLoad)
{
    $("#load_"+msgid)
    .ajaxStart(function(){$(this).show();})
    .ajaxComplete(function(){$(this).hide();});

    $.ajaxFileUpload({
        url:siteUrl+'/yellowpages/yp_ajaxAddBusinessPicture.php?fieldName='+fieldName+'&idBusiness='+idBusi+'&isVideo='+isVideo+'&maxLoad='+maxLoad,
        secureuri:false,
        fileElementId:fieldName,
        dataType: 'json',
        success: function (data, status)
        {
            if(data.msg)
                $('#'+msgid).html(data.msg);

            if(data.errMsg)
                $('#err_'+msgid).html(data.errMsg);
            else
                $('#err_'+msgid).html('');

            if(data.allUploaded == 'Y')
                $('#'+fieldName).hide();
            else
                $('#'+fieldName).show();

            $('#'+fieldName).val('');
        }
    });

    return false;
}

function removeYpPictureVideoImage(imgId, isVideo)
{
    if(isVideo)
    {
        var imgid = 'ypVideoMsg';
        var inputid = 'video';
        var isVideo = 'Y';
    }
    else
    {
        var imgid = 'ypImgMsg';
        var inputid = 'picture';
        var isVideo = 'N';
    }

    var confirmDel = confirmDelete();
    if(confirmDel)
    {
        $.post(siteUrl+"/yellowpages/yp_ajaxAddBusinessPicture.php", { removeImgVideo: 'Y', img_id : imgId, isVideo: isVideo },
        function(data){
            $('#'+imgid).html(data);
            $('#'+inputid).show();
        });
    }
}

function showSlide(iId, idName)
{
    var imgId = idName+'_'+iId;

    $("ul#"+idName+"SlideShow li").each(function(k, val)
    {
        if(val.id == imgId)
            $(this).removeClass('none');
        else
            $(this).addClass('none');
    });

    $("div#"+idName+"SlideShowLink a").each(function(k, val)
    {
        if($(this).text() == iId)
            $(this).html('<b>'+$(this).text()+'</b>');
        else
            $(this).html($(this).text());
    });
}

function checkYpSendToMobile()
{
    var totalErr = 0;

    if(jQuery.trim($('#name').val()) == '')
        totalErr = AddErr('name', totalErr);
    else
        RemoveErr('name');

    if(jQuery.trim($('#mobile').val()) == '')
        totalErr = AddErr('mobile', totalErr);
    else
    {
        chkMobile = validateIndianMobile(jQuery.trim($('#mobile').val()));
        if(chkMobile == false)
            totalErr = AddErr('mobile', totalErr, 'Please enter valid mobile');
        else
            RemoveErr('mobile');
    }

    if(totalErr == 0)
    {
        $('#load_msgMobile').show();
        $.post(ypUrl+"/yp_ajaxSendToMobile.php", { name: $('#name').val(), mobile : $('#mobile').val(), bId : $('#bId').val()},
        function(data){
            $('#load_msgMobile').hide();
            $('#smsForm').hide();
            $('#smsResponse').show();
            $('#smsResponse').html(data);
        });
    }

    return false;
}

function openYpSendToMobile(linkInfo)
{
    $('#name').attr('value', '');
    $('#mobile').attr('value', '');
    $('#smsResponse').html('');
    document.getElementById('smsForm').style.display = '';
    openClModalBox(linkInfo);
}

function setRating(item)
{
    rating = item.id.replace('str', '');
    document.newsComment.rating.value = rating;

    for(i=1;i<=rating;i++)
    {
        $('#str'+i).attr('src',siteImgUrl+'/icon_star_full.gif');
    }
    for(i=rating+1;i>rating;i--)
    {
        $('#str'+i).attr('src',siteImgUrl+'/icon_star_empty.gif');
    }
}

function setYpDomainVal(cityVal, domainObj)
{
    if(cityVal)
    {
        cityVal = $("#city option[value='"+cityVal+"']").text();
        $('#domainCity').html(cityVal.toLowerCase().replace(' ', '-'));
        $('#cityName').attr("value", cityVal);
    }
    if(domainObj)
    {
        domainVal = allowSpecialChar(domainObj).toLowerCase();
        domainObj.value = domainVal;
        if(domainVal)
            $('#domainName').html(domainVal);
        else
            $('#domainName').html('DOMAIN');
    }
}

function allowSpecialChar(textname)
{
    var t = textname;
    var v = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    var w = "";
    for (i=0; i < t.value.length; i++)
    {
        x = t.value.charAt(i);
        if (v.indexOf(x,0) != -1)
            w += x;
    }

    return w;
}

function ajaxCheckDomainAvailable(idBusi)
{
    var msg = '';

    ctNm = document.getElementById('cityName').value;
    domainNm = document.getElementById('business_url').value;

    if(ctNm == '')
        msg = '<span class="red">Please Select City</span>';
    else if(domainNm == '')
        msg = '<span class="red">Please Enter Domain Name</span>';
    else if(msg == '' && domainNm != '' && ( domainNm.length < 3 || domainNm.length > 15))
        msg = '<span class="red">Domain Name allow minimum 3 Char and maximum 15 char</span>';

    if(msg == '')
    {
        $('#chkAvailable').html('');
        $.post(ypUrl+"/yp_ajaxDomainAvailable.php", { cityName: ctNm, domainName : domainNm, busiId:idBusi},
        function(data)
        {
            $('#chkAvailable').html(data);
        });
    }
    else
        $('#chkAvailable').html(msg);
}

function YpCatAjaxPagging(pageNo, ajaxUrl, totalCat)
{
    $.post(ajaxUrl, {page:pageNo, pageUrl:ajaxUrl, totalCat:totalCat, state :$('#state_name').attr('value'), districtName:$('#district_name').attr('value'), did :$('#district_id').attr('value'), cityName : $('#city_name').attr('value'), cityId : $('#city_id').attr('value') },
    function(data){
        $('#catList').html(data);
    });
}

function redirectPage(pageUrl)
{
    window.location = pageUrl;
}

function makeActiveTpl(tplId)
{
    if(tplId == 1 || tplId == 2)
        $('#tplMainBanner').show();
    else
        $('#tplMainBanner').hide();

    $("ul#allTplli li").each(function(i) {
        $(this).removeClass('select_tpl_active mb25 pb10');
        $(this).addClass('minh_280');
    });

    $('#tplli_'+tplId).removeClass('minh_280');
    $('#tplli_'+tplId).addClass('select_tpl_active');
    if(tplId == 2)
    {
        $('#tplli_'+tplId).removeClass('pb10');
        $('#tplli_'+tplId).addClass('mb25');
    }
}

function addYpBanner(fieldName, idBusi, msgid)
{
    $("#load_"+msgid)
    .ajaxStart(function(){$(this).show();})
    .ajaxComplete(function(){$(this).hide();});

    $.ajaxFileUpload({
        url:siteUrl+'/yellowpages/yp_ajaxAddBanner.php?fieldName='+fieldName+'&idBusiness='+idBusi,
        secureuri:false,
        fileElementId:fieldName,
        dataType: 'json',
        success: function (data, status)
        {
            if(data.msg)
                $('#'+msgid).html(data.msg);
        }
    });

    $('#'+fieldName).val('');
    return false;
}

function removeYpBanner(idBusi, isHeadBanner)
{
    var confirmDel = confirmDelete("Are you sure you want to delete this banner ?");

    if(confirmDel)
    {
        if(isHeadBanner)
        {
            isHeaderBanner = 'Y';
            idMsg = 'ypHeaderBanner';
        }
        else
        {
            isHeaderBanner = 'N';
            idMsg = 'ypBanner';
        }

        $.post(siteUrl+'/yellowpages/yp_ajaxAddBanner.php', { idBusiness: idBusi, isHeaderBanner: isHeaderBanner, isDel:'Y' },
        function(data){$('#'+idMsg).html('');});
    }
}

function showHideProduct(msxImg, removeID)
{
    if(!removeID)
    {
        imgShow = 0;
        for(z=2; z<=msxImg; z++)
        {
            if(document.getElementById('product'+z).style.display == 'none' && imgShow == 0)
            {
                document.getElementById('product'+z).style.display = '';
                imgShow = 1;
                if(z == msxImg)
                    document.getElementById('addProductLink').style.display = 'none';
            }
        }
    }
    else
    {
        $("#product_name_"+removeID).attr('value', '');
        $("#product_img_"+removeID).attr('value', '');
        document.getElementById('product'+removeID).style.display = 'none';
        document.getElementById('addProductLink').style.display = '';
    }
}

function checkYpChangeStatus(idad)
{
    var stsVal = jQuery('input[name=ypsts]:checked').val();

    if(stsVal != undefined)
    {
        window.opener.jQuery('#status_'+idad).html('<b class="stsText sts_'+stsVal+'">'+stsVal+'</b>');        
        window.opener.textBlinking_1('status_'+idad, 'blickStsText');
    }
    else
    {
        alert('Please Select status');
        return false;
    }

    return true;
}
