// JavaScript Document
// Copyright BestTransport 2009
// Written by Ricky Kamil 07/27/09 11:00 PM.
//-----------------------------------------------
/*

How to use Div Panel: put this in your hyperlink onclick event

function openDivPanelCenter(siteTitle,siteURL,xwidth,yheight,divorder) : open divpanel by specifying the order

function openNextDivPanelCenter(siteTitle,siteURL,xwidth,yheight) : open the next divpanel without specifying the order

function closeDivPanelCenter(divorder) : close divpanel based on the order

function closeAllDivPanel() : close all div panels


To call another window from the child window:
window.parent.openDivPanelCenter(siteTitle,siteURL,xwidth,yheight,divorder);

To assign value from panel 2 to panel 1. This first part is a text field in panel 1 and the second one is text field in panel 2.
window.parent.window.frames.AlertIFrame1.menuform.textfield.value= document.menuform.textfield.value;
*/

//Settings & Global Var
var divpanelcounter = 0;
var maxdivpanel = 5;
var cx1=0;cy1=0;cx2=0;cy2=0;cx3=0; cy3=0,cx4=0,cy4=0,cx5=0,cy5=0;
var fadeeffect = "yes";
var imgpathpanel = "../../";

function menuopen(divorder)
{
	if (document.getElementById('DivPanel'+divorder).style.display != "block")
	{
		document.getElementById('DivPanel'+divorder).style.display = "block";
		divpanelcounter = divpanelcounter + 1;
	}	
	
	if (fadeeffect == "yes")
	{
		if (window.innerHeight) //FOR Firefox & CHROME note that +20 and -20 is offset for console layout
		{ 
				x_new = window.innerWidth;
				
				if (document.documentElement.scrollTop > document.body.scrollTop) //firefox & chrome compability issue
				{
					y_new = document.documentElement.clientHeight + document.documentElement.scrollTop;	

				}
				else
				{
					y_new = window.innerHeight + document.body.scrollTop;	
				}
		}
		else //FOR IE 6
		{ 
				x_new = document.body.clientWidth;
				y_new = document.documentElement.clientHeight + document.documentElement.scrollTop;
		}		
		document.getElementById('DivPanel0').style.width = x_new + 'px';
		document.getElementById('DivPanel0').style.height = y_new + 'px';
		document.getElementById('DivPanel0').style.display = "block";	
	}
}

function menuclose(divorder)
{ 

	document.getElementById('AlertIFrame'+divorder).src = 'blank.html';
	
	if (document.getElementById('DivPanel'+divorder).style.display != "none")
	{
		document.getElementById('DivPanel'+divorder).style.display = "none";
		divpanelcounter = divpanelcounter - 1;
	}	
	if (divpanelcounter < 0 )
	{
		divpanelcounter = 0;	
	}
	eval('cx'+divorder+'=0');
	eval('cy'+divorder+'=0');
	imgname = eval('document.imgfullscreen'+divorder);
	imgname.src = imgpathpanel + 'images/button_popup_plus.gif';
	
	if (fadeeffect == "yes")
	{
		if (divpanelcounter == 0) {
		document.getElementById('DivPanel0').style.display = "none"
		}
	}
}

function toggle(divorder)
{
	if (document.getElementById('DivPanel'+divorder).style.display == "block") 
	{
		document.getElementById('DivPanel'+divorder).style.display = "none";
	}
	else 
	{
		document.getElementById('DivPanel'+divorder).style.display = "block";
	}
}

function openDivPanelCenter(siteTitle,siteURL,xwidth,yheight,divorder)
{	
	//Header
	document.getElementById('DivPanelheadertext'+divorder).innerHTML = siteTitle;
	imgname = eval('document.imgfullscreen'+divorder);
	imgname.src = imgpathpanel + 'images/button_popup_plus.gif';
	//Container
	var x
	x = document.getElementById('DivPanel'+divorder);
	x.style.width = xwidth + 'px';
	x.style.height = yheight + 'px'; 
	
	//Content
	var y
	y = document.getElementById('AlertIFrame'+divorder);
	y.style.width = xwidth + 'px';
	y.style.height = (yheight - 39) + 'px';  


	//Construct the url and pass query string for divpanel
	if (checkquerystring(siteURL))
	{
	    y.src = siteURL+'&divpanel='+divorder;
	}
	else
	{
	    y.src = siteURL+'?divpanel='+divorder;
	}
	
	//Cover to fix Drag problem
	var z
	z = document.getElementById('DivPanelContentCover'+divorder);
	z.style.width = xwidth + 'px';
	z.style.height = (yheight - 39) + 'px';  
	

	//offset to center panel
	if (window.innerHeight) //FOR Firefox & CHROME note that +20 and -20 is offset for console layout
	{ 
    		x_center = (window.innerWidth/2) - (xwidth/2)-20;
			
			if (document.documentElement.scrollTop > document.body.scrollTop) //firefox & chrome compability issue
			{
				y_center = (document.documentElement.clientHeight/2) - (yheight/2) + document.documentElement.scrollTop-20;	
			}
			else
			{
				y_center = (window.innerHeight/2) - (yheight/2) + document.body.scrollTop-20;	
			}
		
			if (y_center < 0) 
			{
				y_center = 0
			}
	}
	else //FOR IE 6
	{ 
    		x_center = (document.body.clientWidth/2) - (xwidth/2)-20;
    		y_center = (document.documentElement.clientHeight/2) - (yheight/2) + document.documentElement.scrollTop-20;
			if (y_center < 0) 
			{
				y_center = 0
			}
	}
	document.getElementById('DivPanel'+divorder).style.left = x_center + 'px';
    document.getElementById('DivPanel'+divorder).style.top = y_center + 'px';
	
	menuopen(divorder);
}

function openNextDivPanelCenter(siteTitle,siteURL,xwidth,yheight) //Open the next divpanel without specifying the order
{
	if (divpanelcounter < maxdivpanel)
	{
	openDivPanelCenter(siteTitle,siteURL,xwidth,yheight,parseInt(divpanelcounter + 1));
	}
}

function closeDivPanelCenter(divorder)
{
	menuclose(divorder);
}

function closeAllDivPanel()
{
	for (i=1; i< maxdivpanel+1; i++)
	{
		menuclose(i);
	}
}

function fullscreenDivPanel(divorder)
{
	if (eval('cx'+divorder) == 0)
	{			
			//store current panel dimension into global var	
			eval('cx'+divorder+' = document.getElementById(\'DivPanel\'+ divorder).style.width;');
			eval('cy'+divorder+' = document.getElementById(\'DivPanel\'+ divorder).style.height;');
			
			
			
			//Measure the max width & height and place at the right location including scroll down distance
				if (window.innerHeight) //FOR Firefox & CHROME note that +20 and -20 is offset for console layout
				{ 
						x_new = (window.innerWidth)-30;
						
						if (document.documentElement.scrollTop > document.body.scrollTop) //firefox & chrome compability issue
						{
							y_new = (document.documentElement.clientHeight)-30;	
							document.getElementById('DivPanel'+divorder).style.left = '4px';
							document.getElementById('DivPanel'+divorder).style.top = document.documentElement.scrollTop + 4 + 'px';
						}
						else
						{
							y_new = (window.innerHeight) -30;	
							document.getElementById('DivPanel'+divorder).style.left = '4px';
							document.getElementById('DivPanel'+divorder).style.top = document.body.scrollTop + 4 + 'px';
						}
				}
				else //FOR IE 6
				{ 
						x_new = (document.body.clientWidth)-20;
						y_new = (document.documentElement.clientHeight)-20;
						document.getElementById('DivPanel'+divorder).style.left = '4px';
						document.getElementById('DivPanel'+divorder).style.top = document.documentElement.scrollTop + 4 + 'px';
				}
				

			//Container
			var x
			x = document.getElementById('DivPanel'+divorder);
			x.style.width = x_new + 'px';
			x.style.height = y_new + 'px'; 
			
			//Content
			var y
			y = document.getElementById('AlertIFrame'+divorder);
			y.style.width = x_new + 'px';
			y.style.height = (y_new - 39) + 'px';  
			
			imgname = eval('document.imgfullscreen'+divorder);
			imgname.src = imgpathpanel + 'images/button_popup_minus.gif';
			
				//Cover to fix Drag problem
	        var z
	        z = document.getElementById('DivPanelContentCover'+divorder);
	        z.style.width = xwidth + 'px';
	        z.style.height = (yheight - 39) + 'px';  
	}
	else
	{
		
			xwidth = eval('cx'+divorder);
			strip=/[px]/gi; 
			xwidth = xwidth.replace(strip,''); 
			xwidth = parseInt(xwidth);
			
			yheight = eval('cy'+divorder);
			strip=/[px]/gi; 
			yheight = yheight.replace(strip,''); 
			yheight = parseInt(yheight);
			
			//Container
			var x
			x = document.getElementById('DivPanel'+divorder);
			x.style.width = xwidth + 'px';
			x.style.height = yheight + 'px'; 
			
			//Content
			var y
			y = document.getElementById('AlertIFrame'+divorder);
			y.style.width = xwidth + 'px';
			y.style.height = (yheight - 39) + 'px';
			
		    z = document.getElementById('DivPanelContentCover'+divorder);
	        z.style.width = xwidth + 'px';
	        z.style.height = (yheight - 39) + 'px';  
			

			

			
				//offset to center panel
				if (window.innerHeight) //FOR Firefox & CHROME note that +20 and -20 is offset for console layout
				{ 
						x_center = (window.innerWidth/2) - (xwidth/2)-20;
						
						if (document.documentElement.scrollTop > document.body.scrollTop) //firefox & chrome compability issue
						{
							y_center = (document.documentElement.clientHeight/2) - (yheight/2) + document.documentElement.scrollTop-20;	
						}
						else
						{
							y_center = (window.innerHeight/2) - (yheight/2) + document.body.scrollTop-20;	
						}
					
						if (y_center < 0) 
						{
							y_center = 0
						}
				}
				else //FOR IE 6
				{ 
						x_center = (document.body.clientWidth/2) - (xwidth/2)-20;
						y_center = (document.documentElement.clientHeight/2) - (yheight/2) + document.documentElement.scrollTop-20;
						if (y_center < 0) 
						{
							y_center = 0
						}
				}
				document.getElementById('DivPanel'+divorder).style.left = x_center + 'px';
				document.getElementById('DivPanel'+divorder).style.top = y_center + 'px';
			
			eval('cx'+divorder+'=0');
			eval('cy'+divorder+'=0');
			imgname = eval('document.imgfullscreen'+divorder);
			imgname.src = imgpathpanel + 'images/button_popup_plus.gif';
	}
}


function checkquerystring (strUrl) 
{
    if (strUrl.indexOf("?") > -1) {
        return true;
    }
    else {
        return false;
    }
}


document.write("<div id='DivPanel0'></div>");

document.write("<DIV id='DivPanel1' class='drag'>");
document.write("<div id='DivPanelheader1'>");
document.write("<div id='DivPanelheadertext1'></div>");
document.write("<div id='DivPanelheaderclosebutton1'><a href='javascript:closeDivPanelCenter(1)'><img src='" + imgpathpanel + "images/button_popup_close.gif' border='0'/></a></div>");
document.write("<div id='DivPanelheaderplusbutton1'><a href='javascript:fullscreenDivPanel(1)'><img src='" + imgpathpanel + "images/button_popup_plus.gif' name='imgfullscreen1' border='0'/></a></div>");
document.write("</div>");
document.write("<div id='DivPanelContent1'>");
document.write("<div id='DivPanelContentCover1'>");
document.write("</div>");
document.write("<div id='DivPanelContentIframe1'>");
document.write("<iframe id='AlertIFrame1' name='AlertIFrame1' SRC='' frameborder='0' scrolling=auto></iframe>");
document.write("</div>");
document.write("</div>");
document.write("<div id='DivPanelBottom1'></div>");
document.write("</DIV>");


document.write("<DIV id='DivPanel2' class='drag'>");
document.write("<div id='DivPanelheader2'>");
document.write("<div id='DivPanelheadertext2'></div>");
document.write("<div id='DivPanelheaderclosebutton2'><a href='javascript:closeDivPanelCenter(2)'><img src='" + imgpathpanel + "images/button_popup_close.gif' border='0'/></a></div>");
document.write("<div id='DivPanelheaderplusbutton2'><a href='javascript:fullscreenDivPanel(2)'><img src='" + imgpathpanel + "images/button_popup_plus.gif' name='imgfullscreen2' border='0'/></a></div>");
document.write("</div>");
document.write("<div id='DivPanelContent2'>");
document.write("<div id='DivPanelContentCover2'>");
document.write("</div>");
document.write("<div id='DivPanelContentIframe2'>");
document.write("<iframe id='AlertIFrame2' name='AlertIFrame2' SRC='' frameborder='0' scrolling=auto></iframe>");
document.write("</div>");
document.write("</div>");
document.write("<div id='DivPanelBottom2'></div>");
document.write("</DIV>");


document.write("<DIV id='DivPanel3' class='drag'>");
document.write("<div id='DivPanelheader3'>");
document.write("<div id='DivPanelheadertext3'></div>");
document.write("<div id='DivPanelheaderclosebutton3'><a href='javascript:closeDivPanelCenter(3)'><img src='" + imgpathpanel + "images/button_popup_close.gif' border='0'/></a></div>");
document.write("<div id='DivPanelheaderplusbutton3'><a href='javascript:fullscreenDivPanel(3)'><img src='" + imgpathpanel + "images/button_popup_plus.gif' name='imgfullscreen3' border='0'/></a></div>");
document.write("</div>");
document.write("<div id='DivPanelContent3'>");
document.write("<div id='DivPanelContentCover3'>");
document.write("</div>");
document.write("<div id='DivPanelContentIframe3'>");
document.write("<iframe id='AlertIFrame3' name='AlertIFrame3' SRC='' frameborder='0' scrolling=auto></iframe>");
document.write("</div>");
document.write("</div>");
document.write("<div id='DivPanelBottom3'></div>");
document.write("</DIV>");


document.write("<DIV id='DivPanel4' class='drag'>");
document.write("<div id='DivPanelheader4'>");
document.write("<div id='DivPanelheadertext4'></div>");
document.write("<div id='DivPanelheaderclosebutton4'><a href='javascript:closeDivPanelCenter(4)'><img src='" + imgpathpanel + "images/button_popup_close.gif' border='0'/></a></div>");
document.write("<div id='DivPanelheaderplusbutton4'><a href='javascript:fullscreenDivPanel(4)'><img src='" + imgpathpanel + "images/button_popup_plus.gif' name='imgfullscreen4' border='0'/></a></div>");
document.write("</div>");
document.write("<div id='DivPanelContent4'>");
document.write("<div id='DivPanelContentCover4'>");
document.write("</div>");
document.write("<div id='DivPanelContentIframe4'>");
document.write("<iframe id='AlertIFrame4' name='AlertIFrame4' SRC='' frameborder='0' scrolling=auto></iframe>");
document.write("</div>");
document.write("</div>");
document.write("<div id='DivPanelBottom4'></div>");
document.write("</DIV>");


document.write("<DIV id='DivPanel5' class='drag'>");
document.write("<div id='DivPanelheader5'>");
document.write("<div id='DivPanelheadertext5'></div>");
document.write("<div id='DivPanelheaderclosebutton5'><a href='javascript:closeDivPanelCenter(5)'><img src='" + imgpathpanel + "images/button_popup_close.gif' border='0'/></a></div>");
document.write("<div id='DivPanelheaderplusbutton5'><a href='javascript:fullscreenDivPanel(5)'><img src='" + imgpathpanel + "images/button_popup_plus.gif' name='imgfullscreen5' border='0'/></a></div>");
document.write("</div>");
document.write("<div id='DivPanelContent5'>");
document.write("<div id='DivPanelContentCover5'>");
document.write("</div>");
document.write("<div id='DivPanelContentIframe5'>");
document.write("<iframe id='AlertIFrame5' name='AlertIFrame5' SRC='' frameborder='0' scrolling=auto></iframe>");
document.write("</div>");
document.write("</div>");
document.write("<div id='DivPanelBottom5'></div>");
document.write("</DIV>");



var draggers=document.getElementsByTagName('div')
for (var i_tem = 0; i_tem < draggers.length; i_tem++)
if ( draggers[i_tem].className=='drag' )
Drag.init(draggers[i_tem])


