/*
=============================================================================================
KOOLPHP javascript interface
============================================================================================

KOOLPHP_cwindow  	-> the function to create teh overlay and insert box
KOOLPHP_redirect	-> Redirect to different page
KOOLPHP_cerror		-> error message
KOOLPHP_cloading	-> Loading Message
KOOLPHP_hideloading	-> Hiding Loading message


*/


var KOOLPHP_window;			// display main window
var KOOLPHP_iframe;			// display the iframe window
var KOOLPHP_error;			// display the error window




//page scroll
function KOOLPHPPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

//Page size
function KOOLPHPPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


/*
======================================================================================================
Reload fnction
======================================================================================================
*/

function KOOLPHP_reload()
{
	location.reload();
}



/*
=========================================================================================================
Overlay System
=========================================================================================================
*/



function KOOLPHP_overlay()
{
	var objects = document.getElementsByTagName('object');
	for (i = 0; i != objects.length; i++) 
	{
		objects[i].style.visibility = 'hidden';
	}
	
	$_x = document.getElementById("koolphp_overlay");
	$_l = KOOLPHPPageSize();
	
	if($_l[1] > $_l[3])
	{
		$_x.style.height= $_l[1] + "px";
	}
	else
	{
		$_x.style.height= $_l[2] + "px";
	}
	
	$_x.style.display = 'block';
	

}


function KOOLPHP_endoverlay()
{
	var objects = document.getElementsByTagName('object');
	for (i = 0; i != objects.length; i++) 
	{
		objects[i].style.visibility = 'visible';
	}
	
	$_x = document.getElementById("koolphp_overlay");
	$_l = KOOLPHPPageSize();
		
	$_x.style.display = 'none';
	
	if((typeof KOOLPHP_window) != "undefined")
	{
		KOOLPHP_iframe.src = "about:blank";	
		KOOLPHP_window.style.display = 'none';

	}
	

}




/*
====================================================================================================
Create the window
====================================================================================================
*/

function KOOLPHP_cwindow($url,$width,$height)
{

	KOOLPHP_overlay();
	KOOLPHP_cloading()
	
	if($width == 0 ) 	{ $width   =600; }
	if($height == 0 ) 	{ $height  =550; }
	
	var arrayPageScroll = KOOLPHPPageScroll();
	var arrayPageSize = KOOLPHPPageSize();

	$totalheight = parseInt($height) - 39;
	KOOLPHP_iframe.onload = function ()
	{
		KOOLPHP_hideloading();
	}

	KOOLPHP_iframe.style.height = $totalheight + "px";
	KOOLPHP_iframe.style.width = "100%";
	KOOLPHP_iframe.setAttribute('frameborder','0');
	KOOLPHP_iframe.frameborder = "0px";
	KOOLPHP_iframe.src = $url;
	

	
	var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 15);

	$left = parseInt(parseInt(arrayPageSize[2] - (parseInt($width) - 30))/2);
	KOOLPHP_window.style.top = lightboxTop + "px";
	KOOLPHP_window.style.left = $left + "px";
	
	KOOLPHP_window.style.width = $width + "px";
	KOOLPHP_window.style.height = $height + "px";
	
	KOOLPHP_window.style.display = 'block';
	
	
	
}


/*	
=================================================================================
Create Error message
=================================================================================
*/

function KOOLPHP_cerror($message)
{
	var arrayPageScroll = KOOLPHPPageScroll();
	var arrayPageSize = KOOLPHPPageSize();
	
	var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 15);

	$left = parseInt(parseInt(arrayPageSize[2] - (parseInt(400) - 30))/2);

	KOOLPHP_error.style.top = lightboxTop + "px";
	KOOLPHP_error.style.left = $left + "px";
		
	KOOLPHP_error.style.display = 'block';	
	KOOLPHP_error.innerHTML = $message;

}






/*	
=================================================================================
Create Loading 
=================================================================================
*/

function KOOLPHP_cloading()
{
	var arrayPageScroll = KOOLPHPPageScroll();
	var arrayPageSize = KOOLPHPPageSize();
	
	var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 2) - 10;

	$left = parseInt(parseInt(arrayPageSize[2] - (parseInt(400) - 30))/2);

	KOOLPHP_loading.style.top = lightboxTop + "px";
	KOOLPHP_loading.style.left = $left + "px";
		
	KOOLPHP_loading.style.display = 'block';	
	KOOLPHP_loading.innerHTML = "Loading please wait...";

}



function KOOLPHP_hideloading()
{
	var arrayPageScroll = KOOLPHPPageScroll();
	var arrayPageSize = KOOLPHPPageSize();
	
	var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 2) - 10;

	$left = parseInt(parseInt(arrayPageSize[2] - (parseInt(400) - 30))/2);
		
	KOOLPHP_loading.style.display = 'none';	
	KOOLPHP_loading.innerHTML = "";

}





/*
====================================================================================================
redirect 
====================================================================================================
*/

function KOOLPHP_redirect($url)
{
	location.href=$url;
}

/*
====================================================================================================
confirm delete
====================================================================================================
*/


function KOOLPHP_confirmDelete($message,$url)
{

	if(confirm($message))
	{
		location.href=$url;
	}
}




/*
====================================================================================================
creating the overlay 
====================================================================================================
*/


function koolphp() 
{

		
	var objBody = document.getElementsByTagName("body").item(0);

	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','koolphp_overlay');
	objOverlay.className = 'coverentire';
	objOverlay.style.display = 'none';
	objOverlay.onclick = function() 
	{
		KOOLPHP_endoverlay()
	}
	objBody.appendChild(objOverlay);
	
	
	// creating the main windows
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','koolphp_windows');
	objOverlay.className = 'koolphp_windows';
	objOverlay.style.display = 'none';
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0px';
	
	KOOLPHP_window = objOverlay;
	objBody.appendChild(objOverlay);



	var error = document.createElement("div");
	error.setAttribute("id","error_message");
	error.style.display = 'none';
	error.style.position = 'absolute';
	error.style.top = '0px';
	error.onclick =  function ()
	{
		KOOLPHP_error.style.display= "none";
	}
	objBody.appendChild(error);
	KOOLPHP_error = error;

	
	// loading system

	var error = document.createElement("div");
	error.setAttribute("id","loading_message");
	error.style.display = 'none';
	error.style.position = 'absolute';
	error.style.top = '0px';
	objBody.appendChild(error);
	KOOLPHP_loading = error;






	// creating the main windows
	var innerDiv = document.createElement("div");
	innerDiv.setAttribute('id','inner');
	innerDiv.setAttribute('align','right');
	innerDiv.width = "100%";
	objOverlay.appendChild(innerDiv);
	

	// creating the main windows
	var innerImg = document.createElement("img");
	innerImg.src = baselocation + "/include/images/closelabel.gif";
	innerImg.onclick = KOOLPHP_endoverlay;
	innerDiv.appendChild(innerImg);


	// creating the main windows
	KOOLPHP_iframe = document.createElement("iframe");
	KOOLPHP_iframe.setAttribute('frameborder','0');
	KOOLPHP_iframe.frameBorder = "0px";
	objOverlay.appendChild(KOOLPHP_iframe);

	if(backoffice_login == 1 && backoffice == 0)
	{
		var innerDiv = document.createElement("div");
		innerDiv.setAttribute('id','KOOL_setting');
		innerDiv.style.position = 'absolute';		
		innerDiv.style.top = "0px";
		innerDiv.style.width = "100%";
		innerDiv.align = "right";
		objBody.appendChild(innerDiv);	

		var imageData = document.createElement("img");
		imageData.src = baselocation + "include/images/setting.gif";
		imageData.style.cursor = "pointer";
		imageData.style.cursor = "hand";		
		
		imageData.onclick = function()
		{
			KOOLPHP_cwindow(baselocation + "backoffice/ajax_admin_pagessetting.html?currentfile=" + currentfile,700,550);
		}
		
		innerDiv.appendChild(imageData);

	}
		

	/*KOOLPHP_cwindow("backoffice/index.html",500,500);*/
	/*KOOLPHP_overlay();*/
	/*KOOLPHP_cerror("kumar is ok");*/
	/*KOOLPHP_cloading();*/
	
	


}

if (window.addEventListener) 
{
	window.addEventListener("load", koolphp, false);
} 
else if (window.attachEvent) 
{
	window.attachEvent("onload", koolphp);
}





