/*AJAX*/
// JavaScript Document

//Add alert message when error occur 

//window.onerror = function(msg, err_url, line) {alert('Error: '+msg+'\non line '+ line +'\n at page '+err_url);}

//Detects browser type 

function makeObject(){
var x; 
var browser = navigator.appName; 
if(browser == "Microsoft Internet Explorer"){
x = new ActiveXObject("Microsoft.XMLHTTP");
}else{
x = new XMLHttpRequest();
}
return x;
}

//Call function 
var request = makeObject();

//The POST method AJAX 
function post_method(){

var data = document.getElementById('DATA').value;

request.open('post', 'dbase/qryajax.php');
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
request.onreadystatechange = output; 
request.send('data='+data);
}


function output()
{
  if(request.readyState == 1){
  //You can add animated gif while loading // 
  document.getElementById('output').innerHTML = 'adding to you favorites...';
  }
  if(request.readyState ==4){
  var data = request.responseText;
  document.getElementById('output').innerHTML = data;
  }
}

function addToFavorite(pid)
{
  request.open('post', 'page_favs.php');
  request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  request.onreadystatechange = output; 
  request.send('pid='+pid);
}

function textCounter(field, id, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
document.getElementById(id).innerHTML = maxlimit - field.value.length;
}

function toggle( targetId )
{   
    if (document.getElementById){         
		       
					 target = document.getElementById( targetId );
					             
					 if (target.style.display == "none"){               
					 target.style.display = "";            
		       } else{               
		       target.style.display = "none";            
					}      
	  } 
} 

function postPageComment(pgid)
{
  var name = document.getElementById('com_name').value;
	var text = document.getElementById('com_text').value;
	var image = document.getElementById('com_image').value;
	
  toggle('loading');
	
  request.open('post', 'include/comment.func.php');
  request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  request.onreadystatechange = output_postPageComment; 
  request.send('action=comment&name='+name+'&text='+text+'&image='+image+'&page_id='+pgid);
}

function output_postPageComment()
{
  if(request.readyState == 1){
  //You can add animated gif while loading // 
  toggle('comment_main');
	document.getElementById('loading').innerHTML = '<div align="center" style="padding:120px;" ><img alt="loading (2K)" src="images/wait.gif" /> Please wait while we verify your comment.</div>';
	}
  if(request.readyState ==4){
  var data = request.responseText;
  document.getElementById('loading').innerHTML = data;
  }
}

function showHideComment()
{
   toggle('comment_main');
	 toggle('loading');
}

function show_page(pgnum)
{
  request.open('post', 'include/comment_paging.php');
  request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  request.onreadystatechange = output_show_page; 
  request.send('pg='+pgnum);
}

function output_show_page()
{
  if(request.readyState == 1){
  //You can add animated gif while loading // 
	document.getElementById('loading_icon').innerHTML = ' <img alt="loading (2K)" src="images/wait.gif" style="vertical-align:middle;" /> loading page ...';
	}
  if(request.readyState ==4){
  var data = request.responseText;
  document.getElementById('comment_data').innerHTML = data;
  }
}

function AddClicks(id)
{
   request.open('post', '../include/ads.func.php');
   request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   request.onreadystatechange = output_AddClicks;
   request.send('action=clickads&id='+id);
}

function output_AddClicks()
{
//don't remove
}
