

///
/// Return a XMLHTTPRequest in a browser independent fashion.
///
function GetXMLHttp()
{
    var xmlhttp=false;
    
    try 
    { 
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } 
    catch (e) 
    {
        try 
        {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (E)
        {
            xmlhttp = false;
        }
    }

    // Mozilla then?
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
       xmlhttp = new XMLHttpRequest();
    }
    
    return xmlhttp;
}

function addNews()
{
    var strURL = window.location.toString();
    strURL = strURL.toLowerCase();
    strURL = strURL.replace("newsview.aspx", "newsadd.aspx");
    window.location = strURL;
}

function editNews( passNewsID )
{
    //window.open("newsadd.aspx?ID=" + passNewsID);
    var strURL = window.location.toString();
    strURL = strURL.toLowerCase();
    strURL = strURL.replace("newsview.aspx", "newsadd.aspx?ID="+passNewsID);
  
    strURL = strURL.replace("newsdetail.aspx", "newsadd.aspx?ID="+passNewsID);
      alert("got it");
    window.location = strURL;
}

function deleteNews(passNewsID)
{

    var varYesNo;
    var strURL;
    strURL = window.location;
    
    varYesNo = confirm("Are you sure, want to DELETE ?")
    if(varYesNo==1)
    {
        var xmlhttp = GetXMLHttp();
        xmlhttp.open("GET", "NewsDelete.aspx?NewsID="+passNewsID + "&sid=" + Math.random(), true);
        xmlhttp.onreadystatechange=function() 
        {
            if (xmlhttp.readyState==4)
            {  
		        if(xmlhttp.status == 200)
		        {
			        ClientNode = xmlhttp.responseXML.documentElement;
			        if(ClientNode!=null)
			        {
        			    var varMsg = ClientNode.getElementsByTagName('Message');
			            alert(GetInnerText(varMsg[0]));
			            //window.location = strURL;
			            window.location = "newsview.aspx";
			            
			            
                        //alert(xmlhttp.responseText);
                    }
                    else
                    {
                        alert( "else client node null");
                    }
                }
            }
            else
            {
                //alert( xmlhttp.readyState );
            }
        }
        xmlhttp.send(null)   
    }
}


function GetInnerText (node)
{
	 return (node.textContent || node.innerText || node.text) ;
}

