var mozilla=document.getElementById && !document.all;
var ie=document.all;
function set_cookie (name, value)
{
		document.cookie = name + '=' + escape(value) + '; path=/';
}
var loading_pic = new Image(50, 50);
loading_pic.src = "http://digitalcatalog.iseekcorp.com:80/common/icon/loading.gif";
function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}
function delete_cookie ( cookie_name )
{
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}
function inputIsEmpty(id, msg)
{
	var obj = document.getElementById(id);
	if(obj.value == "")
	{
		alert(msg);
		return(false);
	}
	else
	{
		return(true);
	}
}
function CStringBuilder(initialValue)
{
	this.append			= CStringBuilder_Append;
	this.clear			= CStringBuilder_Clear;
	this.length			= CStringBuilder_Length;
	this.toString		= CStringBuilder_ToString;
	this.buffer			= new Array();
	this.bufferLength	= 0;
	if(initialValue != null) { this.append(initialValue); }
}
function CStringBuilder_Append(appendValue)
{
	if(appendValue == null) { return; }
	this.bufferLength += appendValue.length;
	this.buffer.push(appendValue);
}
function CStringBuilder_Clear()
{
	this.buffer = new Array();
	this.bufferLength = 0;
}
function CStringBuilder_Length()
{
	return this.bufferLength;
}
function CStringBuilder_ToString()
{
	return(this.buffer.join(""));
}
			function checkUncheckAll(theElement)
			{
				var theForm = theElement.form, z = 0;
				for(z=0; z<theForm.length;z++)
				{
					if(theForm[z].type == 'checkbox')
					{
						theForm[z].checked = theElement.checked;
					}
				}
			}
var dragtarget;
function cancelEvent() {
	window.event.returnValue = false;
}
function drop() {
	window.location.href = 'http://digitalcatalog.iseekcorp.com:80/compare_models?m1=' + dragtarget + '&m2=' + window.event.srcElement.id;
}

function getMouseX(e)
{
	if(ie)
	{
		return(window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft);
	}
	else if(mozilla)
	{
		return(e.clientX + document.documentElement.scrollLeft + document.body.scrollLeft);
	}
}
function getMouseY(e)
{
	if(ie)
	{
		return(window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop);
	}
	else if(mozilla)
	{
		return(e.clientY + document.documentElement.scrollTop + document.body.scrollTop);
	}
}
var xmlhttp;
function showContext(uri, e)
{
	xmlhttp = null;
	if(window.XMLHttpRequest)
	{
		xmlhttp = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if(window.event) { e = window.event; };
	var cmx = getMouseX(e);
	var cmy = getMouseY(e);
	if(cmx + parseInt(getStyleId("contextMenu").style.width) > document.documentElement.clientWidth)
	{
		cmx = cmx - parseInt(getStyleId("contextMenu").style.width);
	}
	if(cmy + document.getElementById('contextMenu').offsetHeight > document.documentElement.clientHeight)
	{
		cmy = cmy - document.getElementById('contextMenu').offsetHeight;
	}
	getStyleId('contextMenu').style.top = cmy + 'px';
	getStyleId('contextMenu').style.left = cmx + 'px';
	getStyleId('contextMenu').style.visibility = 'visible';
	getStyleId('contextMenu_shadow').style.top = (cmy + 5) + "px";
	getStyleId('contextMenu_shadow').style.left = (cmx + 5) + "px";
	getStyleId('contextMenu_shadow').style.visibility = 'visible';
	document.getElementById('contextMenu').innerHTML = "<center><img src='http://digitalcatalog.iseekcorp.com:80/common/icon/loading.gif' /></center>";
	getStyleId('contextMenu_shadow').style.height = (document.getElementById('contextMenu').offsetHeight - 10) + "px";
	document.onclick = function() { hideContext(); }
	if(xmlhttp != null)
	{
		xmlhttp.onreadystatechange = contextStateChange;
		xmlhttp.open("POST", uri, true);
		xmlhttp.send(null);
	}
	else
	{
		alert("Your browser does not support AJAX.");
	}
}
function contextStateChange()
{
	if(xmlhttp.readyState == 4)
	{
		if(xmlhttp.status == 200)
		{
			document.getElementById('contextMenu').innerHTML = xmlhttp.responseText;
			getStyleId('contextMenu_shadow').style.height = (document.getElementById('contextMenu').offsetHeight - 10) + "px";
			if(atlCADseekViewer)
			{
				if(atlCADseekViewer.ControlActive == true)
				{
					atlCADseekViewer.SetBackgroundColors(0.9764, 0.9921, 1.0, 0.8157, 0.8627, 0.9216, 50);
				}
			}
		}
		else
		{
			alert("Problem retrieving AJAX data.");
		}
	}
}
function checkModelState(mid, uri, e)
{
	var ajax = null;
	if(window.XMLHttpRequest)
	{
		ajax = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if(window.event) { e = window.event; };
	if(ajax != null)
	{
		ajax.onreadystatechange = function()
		{
	if(ajax.readyState == 4)
	{
		if(ajax.status == 200)
		{
			var statusColor = ajax.responseText;
			var count = document.all[mid].length;
			if(!count)
			{
				document.getElementById(mid).style.background = statusColor;
			}
			else
			{
				for(var i = 0; i < count; i++)
				{
					if(document.all[mid][i].id == mid)
					{
						document.all[mid][i].style.background = statusColor;
					}
				}
			}
			ajax = null;
		}
		else
		{
		}
	}
		};
		ajax.open("POST", "http://digitalcatalog.iseekcorp.com:80/global/model/" + mid + "/check_status", true);
		ajax.send(null);
	}
	else
	{
	}
}
var xmlhttp;
function deleteModel(uri, e)
{
	xmlhttp = null;
	if(window.XMLHttpRequest)
	{
		xmlhttp = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if(window.event) { e = window.event; };
	if(xmlhttp != null)
	{
		xmlhttp.onreadystatechange = deleteModelStateChange;
		xmlhttp.open("POST", uri, true);
		xmlhttp.send(null);
	}
	else
	{
		alert("Your browser does not support AJAX.");
	}
}
function deleteModelStateChange()
{
	if(xmlhttp.readyState == 4)
	{
		if(xmlhttp.status == 200)
		{
			var mid = xmlhttp.responseText;
			var count = document.all[mid].length;
			if(!count)
			{
				if((document.getElementById(mid).style.background == '#f9fdff')||(document.getElementById(mid).style.background == ''))
					document.getElementById(mid).style.background = '#f9cfcc';
				else
					document.getElementById(mid).style.background = '#f9fdff';
			}
			else
			{
				for(var i = 0; i < count; i++)
				{
					if(document.all[mid][i].id == mid)
					{
						if((document.all[mid][i].style.background == '#f9fdff')||(document.all[mid][i].style.background == ''))
							document.all[mid][i].style.background = '#f9cfcc';
						else
							document.all[mid][i].style.background = '#f9fdff';
					}
				}
			}
		}
		else
		{
			alert("Problem retrieving AJAX data.");
		}
	}
}
function hideContext()
{
	getStyleId('contextMenu').style.visibility = 'hidden';
	getStyleId('contextMenu_shadow').style.visibility = 'hidden';
	if(ie)
	{
		document.detachEvent("onclick", hideContext);
	}
	else if(mozilla)
	{
		document.removeEventListener("click", hideContext, true);
	}
}
function getStyleClass (className) {
	for (var s = 0; s < document.styleSheets.length; s++)
	{
		if(document.styleSheets[s].rules)
		{
			for (var r = 0; r < document.styleSheets[s].rules.length; r++)
			{
				if (document.styleSheets[s].rules[r].selectorText == '.' + className)
				{
					return document.styleSheets[s].rules[r];
				}
			}
		}
		else if(document.styleSheets[s].cssRules)
		{
			for (var r = 0; r < document.styleSheets[s].cssRules.length; r++)
			{
				if (document.styleSheets[s].cssRules[r].selectorText == '.' + className)
					return document.styleSheets[s].cssRules[r];
			}
		}
	}
	return null;
}
function getStyleId (idName) {
	for (var s = 0; s < document.styleSheets.length; s++)
	{
		if(document.styleSheets[s].rules)
		{
			for (var r = 0; r < document.styleSheets[s].rules.length; r++)
			{
				if (document.styleSheets[s].rules[r].selectorText == '#' + idName)
				{
					return document.styleSheets[s].rules[r];
				}
			}
		}
		else if(document.styleSheets[s].cssRules)
		{
			for (var r = 0; r < document.styleSheets[s].cssRules.length; r++)
			{
				if (document.styleSheets[s].cssRules[r].selectorText == '#' + idName)
					return document.styleSheets[s].cssRules[r];
			}
		}
	}
	return null;
}
