﻿// JScript File

/* This function is used to toggle image of image button according to write text in textbox 
   and disable or enable button. Means if textbox is blank then DisabledImage will display on the button 
   & if textbox is not blank then EnableImage will display on the button and disable or enable 
   button accordingly */
   
    function ToggleEnableButton(obj,buttonId,EnabledImage,DisabledImage)
    {        
        var ImageSrc = document.getElementById("ctl00_ContentPlaceHolder1_" + buttonId).src;
        
        ImageSrc = ImageSrc.substring(0,ImageSrc.lastIndexOf('/')+1)
        
        if (trim(obj.value) != "")
        {        
            document.getElementById("ctl00_ContentPlaceHolder1_" + buttonId).disabled=""
            document.getElementById("ctl00_ContentPlaceHolder1_" + buttonId).src=ImageSrc + EnabledImage
        }
        else
        {
            document.getElementById("ctl00_ContentPlaceHolder1_" + buttonId).disabled="disabled"                    
            document.getElementById("ctl00_ContentPlaceHolder1_" + buttonId).src=ImageSrc + DisabledImage
        }
    }
    
    /* This function remove trailing spaces around a given string */
    function trim(str) { 
	    return( ("" + str).replace(/^\s+/,'').replace(/[\s]+/g,' ').replace(/\s+$/,'') ); 
    }

    /* This function is used to visible false of particular object. But u need to pass 
    client Id of that object like:- 'ctl00_ContentPlaceHolder1_lblUsrNm' */
    function VisibleFalse(objId)
    {   
        if (document.getElementById(objId))
        {
            document.getElementById(objId).style.display = 'none';             
        }
    }
        /* This function is used to visible true of particular object. But u need to pass 
    client Id of that object like:- 'ctl00_ContentPlaceHolder1_lblUsrNm' */
    function VisibleTrue(objId)
    {   
        if (document.getElementById(objId))
        {
            document.getElementById(objId).style.display = 'block';             
        }
    }
    
    //the purpose of this function is to allow the enter key to 
    //point to the correct button to click.
    function doClick(buttonName,e)
    {

        var key;

         if(window.event)
              key = window.event.keyCode;     //IE
         else
              key = e.which;     //firefox
    
        if (key == 13)
        {
            //Get the button the user wants to have clicked
            var btn = document.getElementById(buttonName);
            if (btn != null)
            { //If we find the button click it
                btn.click();
                event.keyCode = 0
            }
        }
   }
   
    /* This function is used to set the text of labels to blank
    client Id of that object like:- 'ctl00_ContentPlaceHolder1_lblUsrNm' */
    function BlankLabel(objId)
    {   
        if (document.getElementById(objId))
        {
            document.getElementById(objId).innerHTML = '';             
        }
    }
    
    /* This function is used to toggle the disabled status of td and elements in td 
    client Id of that object like:- 'ctl00_ContentPlaceHolder1_lblUsrNm' */
     function toggleDisabled(el) {
        try {
            el.disabled = el.disabled ? false : true;
        }
        catch(E){}
        
        if (el.childNodes && el.childNodes.length > 0) {
            for (var x = 0; x < el.childNodes.length; x++) {
                toggleDisabled(el.childNodes[x]);
            }
        }
    }
    
     /* This function is used disable the container and elements in td 
    client Id of that object like:- 'ctl00_ContentPlaceHolder1_lblUsrNm' */
     function makeDisabled(el) {
        try {
            el.disabled = true;
        }
        catch(E){}
        
        if (el.childNodes && el.childNodes.length > 0) {
            for (var x = 0; x < el.childNodes.length; x++) {
                makeDisabled(el.childNodes[x]);
            }
        }
    }
    /* This function is used disable the container and elements in td 
    client Id of that object like:- 'ctl00_ContentPlaceHolder1_lblUsrNm' */
    function makeEnabled(el) {
        try {
            el.disabled = false;
        }
        catch(E){}
        
        if (el.childNodes && el.childNodes.length > 0) {
            for (var x = 0; x < el.childNodes.length; x++) {
                makeEnabled(el.childNodes[x]);
            }
        }
    }
    
    // enables all validators in page
    function enableAllValidators()
    {
        for(i=0;i< Page_Validators.length;i++)
        {
            ValidatorEnable(Page_Validators[i], true)
        }        
    }
    // disables all valditors in page
    function disableAllValidators()
    {
        for(i=0;i< Page_Validators.length;i++)
        {
            ValidatorEnable(Page_Validators[i], false)
        }        
    }
    // all validators in page displays error mesages
    function validateAllValidators()
    {
        for(i=0;i< Page_Validators.length;i++)
        {
            ValidatorValidate(Page_Validators[i])
        }        
    }
    
    //returns the minimum date for datepicker 
    function getmindate()
    {
        var date=document.getElementById("ctl00_ContentPlaceHolder1_hdnDate");			    
        var month=document.getElementById("ctl00_ContentPlaceHolder1_hdnMonth");
        var year=document.getElementById("ctl00_ContentPlaceHolder1_hdnYear");			    
	    
        var dt=new Date(year.value,month.value,date.value);
        return new Date(dt.getFullYear(),dt.getMonth()-1, dt.getDate());
    }
    //returns the maximum date for datepicker 
    function getmaxdate()
    {
        var date=document.getElementById("ctl00_ContentPlaceHolder1_hdnDate");			    
        var month=document.getElementById("ctl00_ContentPlaceHolder1_hdnMonth");
        var year=document.getElementById("ctl00_ContentPlaceHolder1_hdnYear");			    
        
        var dt=new Date(year.value,month.value,date.value);
        
        return new Date(dt.getFullYear(),dt.getMonth()+1, dt.getDate());
    }
  
    function Expand()
    {
         if(document.getElementById('hidExpand').value=='')
         {
             document.getElementById('hidExpand').value=0;
             document.getElementById('ctl00_ContentPlaceHolder1_ucLeftPanel_spncontent').style.display ='none';
         }
         else
         {
             if(document.getElementById('hidExpand').value=='0')
             {
                 document.getElementById('hidExpand').value='1';
                document.getElementById('ctl00_ContentPlaceHolder1_ucLeftPanel_spncontent').style.display ='block';
             }
             else
             {
                if(document.getElementById('hidExpand').value=='1')
                {
                    document.getElementById('hidExpand').value='0';
                    document.getElementById('ctl00_ContentPlaceHolder1_ucLeftPanel_spncontent').style.display ='none';
                }
             }
         }
    }





 //this is to select or unselect the datagrid check boxes 

        function DGSelectOrUnselectAll(grdid,obj,objlist){ 
        //this function decides whether to check or uncheck all
            if(obj.checked) 
                DGSelectAll(grdid,objlist) 
            else 
                DGUnselectAll(grdid,objlist) 
        } 
        //---------- 
         
        function DGSelectAll(grdid,objid){ 
        //.this function is to check all the items
            var chkbox; 
            var i=2; 
        //ctl00_ContentPlaceHolder1_GridView1_ctl04_chkDel      
            chkbox=document.getElementById('ctl00_ContentPlaceHolder1_'+ grdid + 
                       '_ctl' +'0'+ i + '_' + objid); 
           
            while(chkbox!=null){ 
                chkbox.checked=true; 
                i=i+1; 
                if(i<10)
                {
                chkbox=document.getElementById('ctl00_ContentPlaceHolder1_'+ grdid + 
                       '_ctl' +'0'+ i + '_' + objid); 
                }
                else
                {
                 chkbox=document.getElementById('ctl00_ContentPlaceHolder1_'+ grdid + 
                       '_ctl' + i + '_' + objid); 
                }
            } 

        }//-------------- 

        function DGUnselectAll(grdid,objid){ 
        //.this function is to uncheckcheck all the items
            var chkbox; 
            var i=2; 

           chkbox=document.getElementById('ctl00_ContentPlaceHolder1_'+ grdid + 
                       '_ctl' +'0'+ i + '_' + objid); 

            while(chkbox!=null){ 
                chkbox.checked=false; 
                i=i+1; 
                if(i<10)
                {
                chkbox=document.getElementById('ctl00_ContentPlaceHolder1_'+ grdid + 
                       '_ctl' +'0'+ i + '_' + objid); 
                }
                else
                {
                 chkbox=document.getElementById('ctl00_ContentPlaceHolder1_'+ grdid + 
                       '_ctl' + i + '_' + objid); 
                }
            } 
            }
            
            
        //To prevent Form Submission on pressing enter key (Binding event:onkeypress) --Mudit    
        function nosubmit()
        {
            return !(window.event && window.event.keyCode == 13); 
        }
        
        //used on "public profile" and post message page
      //used to limit number of characters entered in comments textbox 
        function limitChars(textid, limit, infodiv)
        {
           var text = $('#'+textid).val(); 
           var textlength = text.length;
           if(textlength > limit)
           {
             $('#' + infodiv).html('You cannot write more then ' + limit + ' characters!');
             $('#'+textid).val(text.substr(0,limit));
             return false;             
           }
           else
           {
             $('#' + infodiv).html("<span class='blue12'>"+(limit - textlength) +"</span> char(s) left, Max <span class='blue12'>1000</span> characters are allowed.");
             return true;
           }
         }
         
     //For pop in same window    
     function popwindow(itemName, theURL, width, height,left,top) {
		var winProps = "width=" + width + ",height=" + height + ",top=" +top + ",left="+left;
		winProps += ",titlebar=0,toolbar=0,location=0,menubar=0,status=1,scrollbars=1'";
		var popupWin = window.open(theURL,itemName,winProps,true);
		popupWin.focus();
	}
	function fnOnLoad()
	{
	    document.getElementById(dynamicid+'AnchorPrev').disabled=true;
	    document.getElementById(dynamicid+'AnchorPrev').className="pagging-a";// new class
        document.getElementById(dynamicid+'AnchorNext').disabled=true;
        document.getElementById(dynamicid+'AnchorNext').className="pagging-a";// new class
        if((parseInt(pagnum)==1) && (parseInt(totalpages)==1))
        { 
//            document.getElementById(dynamicid+'AnchorPrev').disabled=true;
             document.getElementById(dynamicid+'AnchorPrev').style.display='none';
            document.getElementById(dynamicid+'AnchorPrev').className="pagging-a";// new class
//            document.getElementById(dynamicid+'AnchorNext').disabled=true;
            document.getElementById(dynamicid+'AnchorNext').style.display='none';
            document.getElementById(dynamicid+'AnchorNext').className="pagging-a";// new class
        }
        else if(parseInt(pagnum)==1 && parseInt(totalpagerecord)<20)
        {     document.getElementById(dynamicid+'AnchorPrev').style.display='none';
            //  document.getElementById(dynamicid+'AnchorNext').style.display='none';
//            document.getElementById(dynamicid+'AnchorPrev').disabled=true;
            //document.getElementById(dynamicid+'AnchorNext').disabled=true;
            document.getElementById(dynamicid+'AnchorNext').disabled=false;
            document.getElementById(dynamicid+'AnchorPrev').className="pagging-a";// new class
            document.getElementById(dynamicid+'AnchorNext').className="pagging-a";// new class
        }
        else if(parseInt(pagnum)==1)
        { 
            //document.getElementById(dynamicid+'AnchorPrev').disabled=true;
            document.getElementById(dynamicid+'AnchorPrev').style.display='none';
            document.getElementById(dynamicid+'AnchorNext').disabled=false;
            document.getElementById(dynamicid+'AnchorPrev').className="pagging-a";// new class
        }
        else if(parseInt(totalpages)==0 || parseInt(totalpages)==1)
        {
            //document.getElementById(dynamicid+'AnchorPrev').disabled=true;
            //document.getElementById(dynamicid+'AnchorNext').disabled=true;
             document.getElementById(dynamicid+'AnchorPrev').style.display='none';
              document.getElementById(dynamicid+'AnchorNext').style.display='none';
            document.getElementById(dynamicid+'AnchorPrev').className="pagging-a";// new class
            document.getElementById(dynamicid+'AnchorNext').className="pagging-a";// new class
        }
        else if(parseInt(pagnum)==parseInt(totalpages))
        {
            document.getElementById(dynamicid+'AnchorPrev').disabled=false;
//            document.getElementById(dynamicid+'AnchorNext').disabled=true;
            document.getElementById(dynamicid+'AnchorNext').style.display='none';
            document.getElementById(dynamicid+'AnchorNext').className="pagging-a";// new class
        }
        else if(parseInt(pagnum)!=1 && parseInt(totalpages)>parseInt(pagnum))
        {
            document.getElementById(dynamicid+'AnchorPrev').disabled=false;
            document.getElementById(dynamicid+'AnchorPrev').className="pagging-a";// new class
            document.getElementById(dynamicid+'AnchorNext').disabled=false;
            document.getElementById(dynamicid+'AnchorNext').className="pagging-a";// new class
        }
             //following code new added  for disabling next link while having <20 records on page
	    else if(parseInt(totalpagerecord)<20)
	    {
            //document.getElementById(dynamicid+'AnchorNext').disabled=true;
              document.getElementById(dynamicid+'AnchorNext').style.display='none';
            document.getElementById(dynamicid+'AnchorNext').className="pagging-a";// new class
	    }
      
}
       function GetPaging(obj) 
       {
           if (obj.id != null) {
               if (obj.id.indexOf("AnchorPrev") > -1) 
               {
                   if (parseInt(pagnum) > 1) {
                       pagnum = parseInt(pagnum) - parseInt(1);
                       //location.href=url+"/SearchFor/"+keyword+"/"+catid+"/"+lprice+"/"+hprice+"/"+pagnum+"/"+sort+"/"+order+"/"+psize+"/"+contenttype+"/"+showattr+".aspx";//pawan comment

                       //pawan code start
                       //alert(webform + "1 function");
                       if (webform == 'result' || webform == 'result3')
//                           location.href = url + "/SearchFor/" + keyword + "/" + catid + "/" + lprice + "/" + hprice + "/" + pagnum + "/" + sort + "/" + order + "/" + psize + "/" + contenttype + "/" + showattr + ".aspx";
location.href = url + "/search/" + keyword + "/" + catid + "/" + lprice + "/" + hprice + "/" + pagnum + "/" + sort + "/" + order + "/" + psize + "/" + contenttype + "/" + showattr;
                       else if (webform == 'guidelisting') {
                           if (catid == '' || catid == 'catid')
                               location.href = url + "/guides/all-guides/0/" + pagnum + "/" + psize;
                           else
                               location.href = url + "/guides/" + catnm + "-guides/" + catid + "/" + pagnum + "/" + psize;
                       }
                       else if (webform == 'reviewlisting') {
                           if (catid == '' || catid == 'catid')
                               location.href = url + "/reviews/all-reviews/0/" + pagnum + "/" + psize;
                           else
                               location.href = url + "/reviews/" + catnm + "-reviews/" + catid + "/" + pagnum + "/" + psize;
                       }
                       //pawan code end


                   }
                   else {
                       pagnum = 1;
                       // document.getElementById(dynamicid+'AnchorPrev').disabled=true;
                       document.getElementById(dynamicid + 'AnchorPrev').style.display = 'none';
                       document.getElementById(dynamicid + 'AnchorPrev').className = "pagging-a"; //new
                       document.getElementById(dynamicid + 'AnchorNext').disabled = false;
                       document.getElementById(dynamicid + 'AnchorNext').className = "pagging-a"; //new
                   }
               }
               else if (obj.id.indexOf("AnchorNext") > -1) {
                   if ((parseInt(pagnum) < parseInt(totalpages)))// && (parseInt(totalpagerecord)>20))
                   {
                       pagnum = parseInt(pagnum) + parseInt(1);
                       //location.href=url+"/SearchFor/"+keyword+"/"+catid+"/"+lprice+"/"+hprice+"/"+pagnum+"/"+sort+"/"+order+"/"+psize+"/"+contenttype+"/"+showattr+".aspx";//pawan comment

                       //pawan code start
                       //alert(webform +"2function");
                       if (webform == 'result' || webform == 'result3')
//                           location.href = url + "/SearchFor/" + keyword + "/" + catid + "/" + lprice + "/" + hprice + "/" + pagnum + "/" + sort + "/" + order + "/" + psize + "/" + contenttype + "/" + showattr + ".aspx";
                            location.href = url + "/search/" + keyword + "/" + catid + "/" + lprice + "/" + hprice + "/" + pagnum + "/" + sort + "/" + order + "/" + psize + "/" + contenttype + "/" + showattr;
                       else if (webform == 'guidelisting') {
                           //alert(catid);alert(pagnum);
                           if (catid == '' || catid == 'catid')
                               location.href = url + "/guides/all-guides/0/" + pagnum + "/" + psize;
                           else
                               location.href = url + "/guides/" + catnm + "-guides/" + catid + "/" + pagnum + "/" + psize;
                       }
                       else if (webform == 'reviewlisting') {
                           if (catid == '' || catid == 'catid')
                               location.href = url + "/reviews/all-reviews/0/" + pagnum + "/" + psize;
                           else
                               location.href = url + "/reviews/" + catnm + "-reviews/" + catid + "/" + pagnum + "/" + psize;
                       }
                       //pawan code end
                   }
                   else {
                       pagnum = totalpages;
                       document.getElementById(dynamicid + 'AnchorPrev').disabled = false;
                       //                    document.getElementById(dynamicid+'AnchorNext').disabled=true;
                       document.getElementById(dynamicid + 'AnchorNext').style.display = 'none';
                       document.getElementById(dynamicid + 'AnchorPrev').className = "pagging-a"; //new
                       document.getElementById(dynamicid + 'AnchorNext').className = "pagging-a"; //new
                   }

               }
           }
       }    
       
       function pagerefresh()
       {
           if(window.parent.location.href=="http://braintech/cnr/default.aspx?Login=SignOut")
           {
                location.href = "http://braintech/cnr/default.aspx";
            }
            else
            {
                window.parent.location.href = window.parent.location.href;
            }
       }
   