/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function createXMLHTTP(url){
    if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }else{// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.open("GET",url,true);
    return xmlhttp;
}


function callUserLogin() {
    $.ajax({
        url: "/publisher/ajax/user_login",
        cache: false,
        type: "GET",
        success: function(response){
            $("#greeting").html('Welcome <a href="/publisher/registration">'+response+'</a>');
        }
    });
/*var xmlHttp = createXMLHTTP("/publisher/ajax/user_login");
    xmlHttp.send();
    alert(xmlhttp.responseText);
    xmlHttp.onreadystatechange=function(){
        if (xmlHttp.readyState==4 && xmlHttp.status==200){
            document.getElementById('greeting').innerHTML = 'Welcome <strong>'+xmlHttp.responseText+'</strong>';
        }
    }*/

}

function callIsLogin() {
    /*var xmlHttp = createXMLHTTP("/publisher/ajax/is_login");
    xmlHttp.send();
    xmlHttp.onreadystatechange=function(){
        if (xmlHttp.readyState==4 && xmlHttp.status==200){            
            if(xmlHttp.responseText=='true'){
                document.getElementById('sign').innerHTML='<a href="/publisher/logout">Sign Out</a>';
                document.getElementById('be_part').innerHTML='';
            }else{
                document.getElementById('sign').innerHTML='<a href="/publisher/login">Sign In</a>';
                document.getElementById('be_part').innerHTML='Be part of the Global Halal Community.<a href="/registration">Join Now</a>';
            }
        }
    }*/
    $.ajax({
        url: "/publisher/ajax/is_login",
        cache: false,
        type: "GET",
        success: function(response){
            if(response=='true'){
                $("#sign").html('<a href="/publisher/logout">Sign Out</a>');
                $("#be_part").html('');
            }else{
                $("#sign").html('<a href="/publisher/login">Sign In</a>');
                $("#be_part").html('Be part of the Global Halal Community.<a href="/registration">Join Now</a>');
            } 
        }
    });
}




function usefulLinks(pageId){
    /*document.write('<ul>');
    document.write('Useful Links');
    document.write('<li><a href="#">Local Fatwa</a></li>');
    document.write('<li><a href="#">Global Fatwa</a></li>');
    document.write('</ul>');*/
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.open("GET","/publisher/ajax/useful_link/"+pageId,true);
    xmlhttp.send();
    /*alert(xmlhttp.responseText);*/
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            //alert(xmlhttp.responseText);
            var data = eval('('+xmlhttp.responseText+')');
            if(data.page_related.length > 0){
                var result = '';
                result += '<div><ul>';
                result += 'Useful Links';
                for (i = 0; i < data.page_related.length; i++) {
                    result += '<li><a href="'+data.page_related[i].prlLink+'" target="_blank">'+data.page_related[i].prlTitle+'</a></li>';
                }                
                result += '</ul>';
                document.getElementById('usefulllinks').innerHTML = result;
            }
            else
            {
                document.getElementById('usefulllinks').parentNode.parentNode.parentNode.style.display='none';
            }
        }
    }
}




