function calendarPicker(strField)
{
        window.open('../Calendar.aspx?field=' + strField, 'calendarPopup', 'width=250,height=160,resizable=no,left=460,top=363');
} 

function calendarPicker1(strField)
{
        window.open('../Calendar.aspx?field=' + strField, 'calendarPopup', 'width=250,height=160,resizable=no,left=580,top=363');
}   
   
function redirect(str)
{
    window.location = str;
}

function viewclick(ckkb)
{
var xState=ckkb.checked;
        if(xState)
        {
            redirect("www.yahoo.com");
        }
        else
        {
            redirect("www.indiatimes.com");
        }
}
       
function HighlightRow(chkB)
{
    try
    {
        var xState=chkB.checked;
        if(xState)
        {
            chkB.parentElement.parentElement.style.backgroundColor='#316AC5'; 
            chkB.parentElement.parentElement.style.color = '#FFFFFF';        
        }
        else
        {
            chkB.parentElement.parentElement.style.backgroundColor = '#FFFFFF'; 
            chkB.parentElement.parentElement.style.color='#000000';
             var GridView = document.getElementById ('gridView');  //get Id of gridview control
             var headerChkboxSelect = GridView.rows[0].cells[0].children[0];             
             headerChkboxSelect.checked=false;   //deselect header check box.              
        }
    }    
    catch(ex)
    {}
}    

var labelPages;
var labelNoMatch;
var lblErrMessage;

//Function called whenever page is being loaded
function load(lblPages, lblNoMatch, lblErr)
{
    labelPages = $(lblPages);
    labelNoMatch = $(lblNoMatch);
    lblErrMessage = $(lblErr);
    
    lblErrMessage.style.visibility = 'Hidden';
}


function $(d)
{ 
    return document.getElementById(d);
} 

function onChanged(gridView, textTitle, textText, textPostedBy, inputFrom, inputTo, lblErr, textTest)
{
    //debugger;
    grdView = $(gridView);
    lblErrMsg = lblErrMessage;
    txtTitle = $(textTitle);
    txtText = $(textText);
    txtPostedBy = $(textPostedBy);
    inFrom = $(inputFrom);
    inTo = $(inputTo);
    txtTest = $(textTest);
    
    
    
    if(txtTitle.value == "" && txtText.value == "" && txtPostedBy.value == "" && inFrom.value == "" && inTo.value == "")
    {
        lblErrMsg.innerHTML = "<br><LI>Minimum one field is required</LI>";
        lblErrMsg.style.visibility = 'visible'; 
    }
   
    
    if(lblErrMsg.style.visibility == "hidden")
    {
        txtTest.innerText = "Hi";
    }
    else if(txtTitle.value != "" || txtText.value != "" || txtPostedBy.value != "" || inFrom.value != "" || inTo.value != "")
    {
        txtTest.innerText = "Hi";
    }
    else if(lblErrMsg.style.visibility == "visible" && txtTitle.value == "" && txtText.value == "" && txtPostedBy.value == "" && inFrom.value == "" && inTo.value == "")
    {
        txtTest.innerText = "";
    }
    if(inFrom.value != "" && inTo.value == "")
    {
        lblErrMsg.innerHTML = "<br><LI>To Date is required</LI>";
        lblErrMsg.style.visibility = 'visible'; 
        txtTest.innerText = "";
    }
    
    else if(inFrom.value == "" && inTo.value != "")
    {
        lblErrMsg.innerHTML = "<br><LI>From Date is required</LI>";
        lblErrMsg.style.visibility = 'visible'; 
        txtTest.innerText = "";
    }
    
    if(labelPages != null)
    {
        labelPages.style.visibility = 'Hidden';
    }    
    if(labelNoMatch != null)
    {
        labelNoMatch.style.visibility = 'Hidden';      
    }
    if(grdView != null)
    {
        grdView.innerText = "";
    }
}


function SelectAllCheckboxes(spanChk)
{

    // Added as ASPX uses SPAN for checkbox

    var oItem = spanChk.children;
    var theBox=(spanChk.type=="checkbox")?spanChk : spanChk.children.item[0];
    xState=theBox.checked;
    elm=theBox.form.elements;
    
    //debugger;
    for(i=0;i<elm.length;i++)
    {
        if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
        {
            //elm[i].click();
            if(elm[i].checked!=xState)
            {
                elm[i].click();
                //elm[i].checked=xState;
            }
        }
    }    
}

function SelectCheckboxes(chkBox, spanChkBox)
{
    HighlightRow(chkBox);
    // Added as ASPX uses SPAN for checkbox
    //SelectAllCheckboxes(spanChkBox);
}

function SelectAll(chkAll)
{
    var checkAll = $(chkAll);
    SelectAllCheckboxes(checkAll);
}
function DeleteRecord1(check)
{
    //debugger
    var checkAll = $(check);
    
    var count = 0;    
    for(i = 0; i < document.forms[0].elements.length; i++) 
        {
             elm = document.forms[0].elements[i]
             if (elm.type == 'checkbox')
              {
                if (elm.checked == true)
                { 
                    delete(elm)
                     count++;
                }
              }
         }
         
    if(count==0)
    {
       alert('Please select atleast one blog.');
       window.event.returnValue = false;
    }
    else
    {                
        if(confirm('Do you want to delete the selected Blog(s)?'))
        {
            document.getElementById("buttonDelete").click();
            
        }
        else
        {
            window.event.returnValue = false;
        }
    }       
function DeleteRecord()
{
    debugger;
    //var checkAll = $(check);
    
    var count = 0;    
    for(i = 0; i < document.forms[0].elements.length; i++) 
        {
             elm = document.forms[0].elements[i]
             if (elm.type == 'checkbox')
              {
                if (elm.checked == true)
                { 
                     count++;
                }
              }
         }
         
    if(count==0)
    {
       alert('Please select atleast one record.');
       window.event.returnValue = false;
    }
    else
    {                
        if(confirm('Do you want to delete the selected Blog(s)?'))
        {
            document.getElementById("BtnDelete").click();
            
        }
        else
        {
            window.event.returnValue = false;
        }
    } 
    }     
}
