function ConfirmDelete(url)
{
    doIt=confirm('Delete This Record?');
    if(doIt)
        {
        window.location=url;
    }
    else
        {
        return false;
    }
}

function GetXmlHttpObject()
{
    if (window.XMLHttpRequest)
        {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        return new XMLHttpRequest();
    }
    if (window.ActiveXObject)
        {
        // code for IE6, IE5
        return new ActiveXObject("Microsoft.XMLHTTP");
    }
    return null;
}


function AjaxCall(url,target)
{
    var xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
        {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var pollElement=document.getElementsByName("poll");   
    var url=url;       
    url=url+"&sid="+Math.random();
    //alert(url);
    xmlhttp.onreadystatechange=function () 
    {
        if (xmlhttp.readyState==4)
            {
            document.getElementById(target).innerHTML=xmlhttp.responseText;        
        }
    }

    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);

}  

//functions for tooltip
function ShowToolTip(id)
{
    var control=document.getElementById(id);
    control.className="ToolTipVisible";
    Animate(id,true);

}

function HideToolTip(id)
{
    var control=document.getElementById(id);
    control.className="ToolTipHidden";                
    //Animate(id,false);
    opacity=0;   
}

var opacity=0;
var increment=12; 
var timeOutId;
var OpacityLimit=94;        

function Animate(id,isShowing)
{
    control=document.getElementById(id);
    SetTransperancy(control,opacity);
    if(isShowing)
        {
        if(opacity<OpacityLimit)
            {
            opacity=opacity+increment;
            timeOutId=setTimeout('Animate(\''+id+'\',true)',15);   
        }
        else
            {
            clearTimeout(timeOutId);
            opacity=OpacityLimit; 
            SetTransperancy(control,opacity);                
        }
    }
    else
        {
        if(opacity>0)
            {
            opacity=opacity-increment;
            timeOutId=setTimeout('Animate(\''+id+'\',false)',45);   
        }
        else
            {
            clearTimeout(timeOutId);  
            control.className="ToolTipHidden";
            opacity=0; 
        }
    }        
}

function SetTransperancy(elem, opacityAsInt)
{
    //alert('Element: '+elem)
    var opacityAsDecimal = opacityAsInt;

    if (opacityAsInt > 100)
        opacityAsInt = opacityAsDecimal = 100; 
    else if (opacityAsInt < 0)
        opacityAsInt = opacityAsDecimal = 0; 

    opacityAsDecimal /= 100;
    if (opacityAsInt < 1)
        opacityAsInt = 1; // IE7 bug, text smoothing cuts out if 0

    elem.style.opacity = (opacityAsDecimal);
    elem.style.filter  = "alpha(opacity=" + opacityAsInt + ")";
}


function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer')
        {
        var ua = navigator.userAgent;
        var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat( RegExp.$1 );
    }
    return rv;
}

function checkVersion()
{        
    var ver = getInternetExplorerVersion();
    if ( ver > -1 )
        {
        if ( ver >= 7.0 ) 
            {
            //ok...
        }
        else
            {
            alert("This site works good with IE7+ browsers, You should upgrade your browser!");
        }
    }     
}


//Extra functions

function CheckSecurity()
{        
    if(document.getElementById('security_code').value.length !=5)
        {
        alert('कृपया सही कोड भरें!');
        return false;
    }
    return true;;
}    

function ReplaceAll(txt, replace, with_this) {
    return txt.replace(new RegExp(" "+replace+" ", 'g')," "+with_this+" ");
}

function AddTags()
{
    var tags=document.getElementById('DivTags').innerHTML;
    //alert(tags);
    var contents=document.getElementById('DivContents').innerHTML;
    var tagsArray=tags.split(",");
    for(var i=0;i<tagsArray.length;i=i+2)
        {
        if(tagsArray[i]!=" ")
            {               
            var str=tagsArray[i];             
            contents=ReplaceAll( contents,str,"<a target='_blank' class='ShowpageTagLinks' href='"+tagsArray[i+1]+"'>"+str+"</a>");
        }
    }
    //alert(contents);
    document.getElementById('DivContents').innerHTML=contents;
}

//functions of home page
function SavePoll()
{
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
        {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var pollElement=document.getElementsByName("poll");   
    var url="poll.php";       
    url=url+"?action=add&poll="+getCheckedValue(pollElement);
    url=url+"&sid="+Math.random();
    //alert(url);
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);

}

function stateChanged()
{
    if (xmlhttp.readyState==4)
        {
        document.getElementById('polldiv').innerHTML=xmlhttp.responseText;        
    }
}

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 "";
}

  




