//call ajax script
function call_ajax(method, element_id, script_link, parameters)
        {
                var xmlHttp;
        
                try
                        {
                                // Firefox, Opera 8.0+, Safari
                                xmlHttp = new XMLHttpRequest();
                        }
                catch (e)
                        {
                                // Internet Explorer
                                try
                                        {
                                                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
                                        }
                                catch (e)
                                        {
                                                try
                                                        {
                                                                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                                                        }
                                                catch (e)
                                                        {
                                                                alert("Your browser does not support AJAX!");
                                                                return false;
                                                        }
                                        }
                        }
                
                xmlHttp.onreadystatechange = function()
                        {
                                if(xmlHttp.readyState == 4)
                                        {
                                                var result = xmlHttp.responseText;
                                                
                                                if (!element_id)
                                                        {
                                                                alert (result);
                                                        }
                                                else
                                                        {
                                                                document.getElementById(element_id).innerHTML = result;
                                                        }
                                        }
                        }
                        
                if (method == 'post')
                        {                        
                                xmlHttp.open('POST', script_link, true);
                                xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                                xmlHttp.setRequestHeader("Content-length", parameters.length);
                                xmlHttp.setRequestHeader("Connection", "close");                
                                xmlHttp.send(parameters);
                        }
                else
                        {                        
                                xmlHttp.open('GET', script_link, true);
                                xmlHttp.send(null);                        
                        }
        }         

//used to auto-start function on page load         
function addLoadEvent(func) 
        {
                var oldonload = window.onload;
                if (typeof window.onload != 'function') 
                        {
                                window.onload = func;
                        }
                else
                        {
                                window.onload = function()
                                        {
                                                if (oldonload)
                                                        {
                                                                oldonload();
                                                        }
                                                func();
                                        }
                        }
        }
        
/********************* custom functions ********************/

//show rating
function show_rating()
        {
                //show 'loading'
                document.getElementById('rating').innerHTML = '<div style="padding: 0px 0px 0px 15px;"><img src="loading.gif" class="loading" /> Please wait ...</div>';
        
                //call php script
                call_ajax('get', 'rating', 'rating.php');
        }

//update rating
function update_rating(rating)
        {
                //show 'loading'
                document.getElementById('rating').innerHTML = '<div style="padding: 0px 0px 0px 15px;"><img src="loading.gif" class="loading" /> Please wait ...</div>';
        
                //call php script
                call_ajax('get', 'rating', 'rating.php?rating=' + rating);
        }

/********************* initiat functions ********************/
        
addLoadEvent(show_rating);

