var jslib = 
{
	is_duplicate:function(v,ar)
	{
		var duplicate = false;
		for(var i=0;i <= ar.length-1;i++)
		{
			if (ar[i] == v){duplicate = true;}
		}
		return duplicate;
	}	
}
if (top.location!=window.location){top.location=window.location;}

/***AJAX**/
var req=null;
var ajconsole=null;
var READY_STATE_UNINITIALIZED=0;
var READY_STATE_LOADING=1;
var READY_STATE_LOADED=2;
var READY_STATE_INTERACTIVE=3;
var READY_STATE_COMPLETE=4;
var store = new Array(); // data store of previously requested page
var storeid = '';
function sendRequest(url,params,HttpMethod){
if (!HttpMethod){
HttpMethod="GET";
}
req=initXMLHTTPRequest();
if (req){
req.onreadystatechange=onReadyState;
req.open(HttpMethod,url,true);
req.setRequestHeader
("Content-Type", "application/x-www-form-urlencoded");
req.send(params);
}
}
function initXMLHTTPRequest(){
var xRequest=null;
if (window.XMLHttpRequest){
xRequest=new XMLHttpRequest();
} else if (window.ActiveXObject){
xRequest=new ActiveXObject
("Microsoft.XMLHTTP");
}
return xRequest;
}
function onReadyState(){
var ready=req.readyState;
var data=null;
if (ready==READY_STATE_COMPLETE)
{
data=req.responseText;
}else
{
    data ="";
	//document.getElementById('maincontent').style.display = 'none';
	document.getElementById('loadimg').style.display = 'block';	
}
toajconsole(data);
}
var qry_load_msg = false;
function toajconsole(data)
{
if (ajconsole!=null)
{
if (data =="")
{
   ajconsole.innerHTML = data;   
}
else
{
    if(data.indexOf("For assistance, contact your network support team.") > -1)
	{
	         data = 'Your Interent Connection is currently making a trouble to display the page. Refresh again later.';
	}
    ajconsole.innerHTML = data ;
	document.getElementById(storeid).value = data;	
	document.getElementById('maincontent').style.display = '';	
	document.getElementById('loadimg').style.display = 'none';		
	window.focus();
}
}
}
function sr(url,data,method)
{	
	ajconsole=document.getElementById('maincontent');		
	if (jslib.is_duplicate(url,store) == false)
	{			
		sendRequest('1nc/req_handler.php?pg='+url,data,method);		
		store[store.length] = url;
		storeid = url;		
		var pgHead = document.getElementsByTagName("head").item(0);
		var objTextarea = document.createElement("textarea");
		objTextarea.setAttribute('style','display:none;');
		objTextarea.setAttribute('id',url);
		pgHead.appendChild(objTextarea);
		window.location.hash = '#' + url;		
		
	}
	else 
	{
		ajconsole.innerHTML = document.getElementById(url).value;
		window.location.hash = '#' + url;		
	}	
}

/**[/AJAX]***/
window.onload=function()
{
   try{get_hash(window.top.location.hash);}catch(e){document.getElementById('maincontent').innerHTML='Frame not Accepted!';}
  
}
window.onkeyup = function(e){
	
    if (typeof(e) == 'undefined') {	
        if (window.event.keyCode == 8 || window.event.keyCode == 37 || window.event.keyCode == 39) {
			checkHistory();
        }	
    }
    else {
        if (e.keyCode == 8 || e.keyCode == 37 || e.keyCode == 39) {
			checkHistory();
        }
    }
}

function checkHistory()
{
		var url = document.location+"";	
		if(url.indexOf("#") < 0)return;		
		url = url.substring(url.indexOf("#")+1,url.length);
		
		if (jslib.is_duplicate(url,store))
		{			
			ajconsole.innerHTML = document.getElementById(url).value;							
		}
}
function get_hash(loc)
{
	loc = loc.replace(/#/,'');
	if (loc!=null&&loc!=""&&loc.length!=0)
	{
		// prevent DOM-Based XSS
		sr(escape(loc));	
	}
	else {sr('home');}
}
function $(id){return document.getElementById(id);}
function go_url(keyword)
{
	//redirect
}
function show_more_txt(e)
{
	e.innerHTML = document.getElementById('more').innerHTML;
	e.style.cursor = 'default';
	e.style.color = 'black'; e.style.textDecoration='none';
}
function view_movie(u)
{
	window.open(u,u,"fullscreen=Yes,toolbar=No,menubar=No,location=No,scrollbars=Yes,resizable=Yes,status=No");
	return false;
}
