// JavaScript Document

if (!document.all)
document.captureEvents(Event.MOUSEMOVE);

// On the move of the mouse, it will call the function getPosition
document.onmousemove = getPosition;

// These varibles will be used to store the position of the mouse
var X = 0;
var Y = 0;

// This is the function that will set the position in the above varibles 
function getPosition(args) 
{
  // Gets IE browser position
  if (document.all) 
  {
    X = event.clientX + document.body.scrollLeft;
    Y = event.clientY + document.body.scrollTop;
  }
  
  // Gets position for other browsers
  else 
  {  
    X = args.pageX;
    Y = args.pageY;
  }  
}

function viewHTMLTemplate()
{
	var oDiv = document.getElementById("otablecontainer");
	var oDivContent = oDiv.innerHTML;
	removeAllChildren(oDiv);
	
	var oTBox = document.createElement("textarea");
	oTBox.setAttribute('id', 'otableta');
	oTBox.setAttribute('name', 'otableta');
	oTBox.setAttribute('rows', 100);
	oTBox.setAttribute('cols', 75);

	oTBox.style.margin = '0 10px 10px 10px';
	oTBox.innerText = oDivContent;
	oDiv.appendChild(oTBox);
	
	var oViewBtn = document.getElementById("btnview");
	oViewBtn.value = "Exit HTML";
	oViewBtn.onclick = Function("viewPreviewTemplate()");
	
} // function viewHTMLTemplate()

function viewPreviewTemplate()
{
	var oDiv = document.getElementById("otablecontainer");
	var oTA = document.getElementById("otableta");
	
	var oTAContent = oTA.innerText;
	removeAllChildren(oDiv);
	
	oDiv.innerHTML = oTAContent;
	
	var oViewBtn = document.getElementById("btnview");
	oViewBtn.value = "View HTML";
	oViewBtn.onclick = Function("viewHTMLTemplate()");
	
} // function viewPreviewTemplate

function toggleCheckText(percheckid, pertextid)
{
	var oPercheck = document.getElementById(percheckid);
	var oPertext = document.getElementById(pertextid);
	
	if (oPercheck.checked) {
		oPertext.disabled = false;
	}
	else {
		oPertext.disabled = true;
	}
	
} //togglePermissionReminder

function backgroundFilter() 

{ 
	
    var div; 
	var divBtm = document.getElementById('btmsection');
	var divBtmY = divBtm.offsetTop + divBtm.offsetHeight;
	
	
    if(document.getElementById) 
    // Standard way to get element 
    div = document.getElementById('backgroundFilter'); 
    else if(document.all) 
    // Get the element in old IE's 
	
    div = document.all['backgroundFilter'];    
	
    // if the style.display value is blank we try to check it out here 
	
    if(div.style.display== '' && div.offsetWidth != undefined&&div.offsetHeight != undefined) 
    { 
        div.style.display = (div.offsetWidth!=0 && div.offsetHeight!=0)?'block':'none'; 
		div.style.height = (div.offsetWidth!=0 && div.offsetHeight!=0)?divBtmY:'100%';
    } 
    // If the background is hidden ('none') then it will display it ('block'). 
    // If the background is displayed ('block') then it will hide it ('none'). 
    div.style.display = (div.style.display==''||div.style.display=='block')?'none':'block';
	div.style.height = (div.style.display==''||div.style.display=='block')?divBtmY:'100%';
	
}

function showeEditWindow(divid)
{

    var div;
    
    if(document.getElementById)
    // Standard way to get element
    div = document.getElementById('eEditWindow'); 
    else if(document.all) 
    // Get the element in old IE's 
    div = document.all['eEditWindow']; 
    
    // if the style.display value is blank we try to check it out here 
    if(div.style.display==''&&div.offsetWidth!=undefined&&div.offsetHeight!=undefined)
    {
        div.style.display = (div.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none'; 
    }
    
    // If the PopUp is hidden ('none') then it will display it ('block').
    // If the PopUp is displayed ('block') then it will hide it ('none').
    div.style.display = (div.style.display==''||div.style.display=='block')?'none':'block';
    
    // Off-sets the X position by 15px
    X = X + 15;
    
    // Sets the position of the DIV
	var div1 = document.getElementById(divid);
	var div2 = document.getElementById('eEditWindowBody');
	
    div.style.left = div1.offsetLeft;
    div.style.top = div1.style.top;
	div.style.width = div1.style.width;
	
	div2.innerHTML = div1.innerHTML;
}

function hideeEditWindow(divid, saveflag)
{
	
    var div;
    
    if(document.getElementById)
    // Standard way to get element
    div = document.getElementById('eEditWindow'); 
    else if(document.all) 
    // Get the element in old IE's 
    div = document.all['eEditWindow']; 
	
	if (saveflag == "save") {
		var div1 = document.getElementById('eEditWindowBody');
		var div2 = document.getElementById(divid);
		
		div2.innerHTML = div1.innerHTML;
	}
    
    // if the style.display value is blank we try to check it out here 
    if(div.style.display==''&&div.offsetWidth!=undefined&&div.offsetHeight!=undefined)
    {
        div.style.display = (div.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none'; 
    }
    
    // If the PopUp is hidden ('none') then it will display it ('block').
    // If the PopUp is displayed ('block') then it will hide it ('none').
    div.style.display = (div.style.display==''||div.style.display=='block')?'none':'block';
   
}

function showPreviewEmailScreen(dirid,tempid,e)
{
	var posx = 0;
    var posy = 0;
	var sWidth = document.body.clientWidth;
	var sHeight = document.body.clientHeight;
	
	var oDivHTML = document.getElementById("otablecontainer").innerHTML;
	
    //posx= getX(e) + getScrollX();
    //posy= getY(e) + getScrollY();
	document.getElementById("pemailbody").innerHTML = oDivHTML;
	document.getElementById("usebtn1").onclick = Function("emailindex.php?action=test-email; backgroundFilter()");
	var divname = document.getElementById("pemailscreen");
	divname.style.top = 20 + getScrollY();
	divname.style.left = (sWidth - 700)/2;
}  // view template

function hidePreviewEmailScreen()
{
	document.getElementById("pemailbody").innerHTML = "";
	var divname = document.getElementById("pemailscreen");
	divname.style.top = -1000;
	divname.style.left = -1000;
	
}  // view template