﻿// All code is created by Arash Motamedi

var isCoverOn = false;
var cover, phCover, phFrame;
function openDialogWindow(loc)
{
	// If a frame is open, just do nothng!
	if (document.getElementById("InFra") != null)
		return;

	// Add a new frame

	phCover = document.getElementById("phPageCover");
	cover = document.getElementById("PageCover");
	phFrame = document.getElementById("phIF");
	
	var newFrame
	try
	{
		newFrame = document.createElement('<iframe id="InFra" class="InlineFrame" frameborder="0" scrolling="no" src="' + loc + '"></iframe>');
	}
	catch (e)
	{
		newFrame = document.createElement("iframe");
		newFrame.setAttribute("id", "InFra");
		newFrame.setAttribute("class", "InlineFrame");
		newFrame.setAttribute("frameborder", "0");
		newFrame.setAttribute("scrolling", "no");
		newFrame.setAttribute("src", loc);
	}			
	
	phFrame.appendChild(newFrame);
	
	var CanvasWidth, CanvasHeight;

	if (window.innerWidth)
	{
		// Netscape
		CanvasWidth = window.innerWidth;
		CanvasHeight = window.innerHeight;
	}
	else
	{
		// IE
		CanvasWidth = document.documentElement.clientWidth;
		CanvasHeight = document.documentElement.clientHeight;
	}
				
	cover.style.width = (CanvasWidth) + "px";
	cover.style.height = (CanvasHeight) + "px";
	cover.style.visibility = "visible";
	
	phCover.style.width = cover.style.width;
	phCover.style.height = cover.style.height;
	phCover.style.visibility = "visible";
	
	isCoverOn = true;

}

function closeDialogWindow(loc)
{
	cover.style.visibility = "hidden";
	phCover.style.visibility = "hidden";
	isCoverOn = false;
	
	// Remove this iframe
	var oldCh = document.getElementById("InFra");
	phFrame.removeChild(oldCh);

	if (loc != null && loc != '')
	{				
		// Navigate to new location
		if (loc == "_refresh")
		{
			window.location.reload();
		}
		else if (loc.substring(0, 1) == "/")
		{
			// make it into a fully qualified path
			var baseUrl = window.location.href;
			if (window.location.pathname != "/")
			{
				baseUrl = baseUrl.substring(0, baseUrl.indexOf(window.location.pathname));
			}
			else
			{
				baseUrl = baseUrl.substring(0, baseUrl.length - 1);
			}
			loc = baseUrl + loc;
		}
		window.location = loc;
	}
}

function resizeCover()
{
	if (isCoverOn)
	{
		if (window.innerWidth)
		{
			CanvasWidth = window.innerWidth;
			CanvasHeight = window.innerHeight;
		}
		else
		{
			CanvasWidth = document.body.clientWidth;
			CanvasHeight = document.body.clientHeight;
		}
					
		cover.style.width = (CanvasWidth) + "px";
		cover.style.height = (CanvasHeight) + "px";
			
		phCover.style.width = cover.style.width;
		phCover.style.height = cover.style.height;
	}
}

function txtHelp(txt, msg)
{
	var textboxHelp = document.getElementById("TextboxHelp");
	var par = txt.offsetParent;

	var posLeft = parseInt(txt.offsetLeft);
	var posTop = parseInt(txt.offsetTop) + parseInt(txt.offsetHeight) + 2;

	while (par != null)
	{
		posLeft += par.offsetLeft;
		posTop += par.offsetTop;
		par = par.offsetParent;
	}
	textboxHelp.style.left = posLeft + "px";
	textboxHelp.style.top = posTop + "px";
	textboxHelp.innerHTML = msg;
	textboxHelp.style.visibility = "visible";
}

function hideTxtHelp()
{
	document.getElementById("TextboxHelp").style.visibility = "hidden";
}
function hoverHeaderLink(img, hover)
{	
	var HoverColor = "#7185A4";
	
	if (hover)
	{
		img.style.borderTop = "solid 1px " + HoverColor;
		img.style.borderBottom = "solid 1px " + HoverColor;
	}
	else
	{
		img.style.borderTopWidth = "0px";
		img.style.borderBottomWidth = "0px";
	}
}

function toggleProjects()
{
	var ProjectsDiv = document.getElementById(DivSubProjectsId);
	if(ProjectsDiv.innerHTML == "")
		return;
	
	if (ProjectsDiv.style.visibility == "hidden")
	{
		ProjectsDiv.style.visibility = "visible";

	}
	else
	{
		ProjectsDiv.style.visibility = "hidden";
	}
		
}
function menuHover(pic, newSrc)
{
	pic.src = newSrc;
}

function writemail(name, domain, displayName)
{
	// Reverse name!
	var email = name + "@" + domain;
	
	if (displayName == null)
	{
		displayName = email;
	}
	
	document.write("<a href=\"mailto:" + email + "\">" + displayName + "</a>");
	
}


