var isIE		= document.all;
var isIE6	= isIE && document.implementation;
var isIE5	= isIE && window.print && !isIE6;
var isIEDOM2= isIE5 || isIE6;
var isIE4	= isIE && !isIEDOM2 && navigator.cookieEnabled;
var isIE3	= isIE && !isIE4 && !isIEDOM2;
var isNS		= navigator.mimeTypes && !isIE;
var isNS3	= isNS && !navigator.language;
var isNS4	= document.layers;
var isNS6	= document.getElementById && !isIE;
var isNS7	= isNS6;
var isNS71	= document.designMode;
var isNSDOM2= isNS6;
var isDOM2	= isIEDOM2 || isNSDOM2;

function ClientDimensions_Class()
{
  this.Left = 0 
  this.Right   = 0
  this.Top     = 0
  this.Bottom  = 0
  this.Width = 0
  this.Height = 0
  this.xMiddle = 0
  this.yMiddle = 0
}

function getClientDimensions()
{
  var CWidth, CHeight, CScrollX, CScrollY;

  if (isNS)
  {
	CWidth = self.innerWidth;
	CHeight = self.innerHeight;
	CScrollX = window.pageXOffset;
	CScrollY = window.pageYOffset;
  }
  else if (isIE6)
  {
	CWidth = document.documentElement.clientWidth;
	CHeight = document.documentElement.clientHeight;
	if (CWidth==0)
	{
	  CWidth = document.body.clientWidth;
	  CHeight = document.body.clientHeight;
	}

	CScrollX = document.body.scrollLeft +
			   document.documentElement.scrollLeft;
	CScrollY = document.body.scrollTop +
			   document.documentElement.scrollTop;
  } 
  else if (isIE)
  {
	CWidth = document.body.clientWidth;
	CHeight = document.body.clientHeight;
	CScrollX = document.body.scrollLeft;
	CScrollY = document.body.scrollTop;
  }

  var ClientDimensions = new ClientDimensions_Class();
  ClientDimensions.Left    = CScrollX;
  ClientDimensions.Right   = CWidth + CScrollX;
  ClientDimensions.Top     = CScrollY;
  ClientDimensions.Bottom  = CHeight + CScrollY;
  ClientDimensions.Width = ClientDimensions.Right - ClientDimensions.Left;
  ClientDimensions.Height = ClientDimensions.Bottom - ClientDimensions.Top;
  ClientDimensions.xMiddle = Math.round(CWidth/2) + CScrollX;
  ClientDimensions.yMiddle = Math.round(CHeight/2) + CScrollY;

  return ClientDimensions;
}

function FindElementById(SourceElement, Id)
{
	if(!SourceElement)
		return false;
	
	var Element = SourceElement.getElementById(Id);
	var ChildElement
	if(!Element)
	{
		for(ChildElement in SourceElement.childNodes)
		{
			if(ChildElement.nodeType==1)
			{
				Element = FindElementById(ChildElement, Id)
				if(Element)
					return Element;
			}
		}
	}
	
	if(Element)
		return Element;
	else
		return false;
}



function FindElementsByName(SourceElement, Name)
{
	var Elements = SourceElement.getElementsByName(Name);
	var ChildElement
	if(!Elements)
	{
		for(ChildElement in SourceElement.childNodes)
		{
			Elements = FindElementsByName(ChildElement, Name)
			if(Elements)
				return Elements;
		}
	}
	
	return Elements;
}

function setElementClassName(objElement, sClassName, bRecurse)
{
	objElement.className = sClassName;
	if(bRecurse)
		setChildNodeClassName(objElement, sClassName, bRecurse)
}

function setChildNodeClassName(objParent, sClassName, bRecurse)
{
	for(i = 0 ; i < objParent.childNodes.length ; i++)
	{
		objChildNode = objParent.childNodes[i];
		objChildNode.className = sClassName;
		if(bRecurse)
			setChildNodeClassName(objChildNode, sClassName, bRecurse);

	}
}

function createXmlHttpRequest()
{
	var objRequest = null;
	if (window.XMLHttpRequest)
		objRequest = new XMLHttpRequest();
	else if(window.ActiveXObject)
		objRequest = new ActiveXObject("Microsoft.XMLHTTP");

	return objRequest;
}

function window_open(sURL, sName, iWidth, iHeight, sFeatures)
{
	if(!sFeatures)
		sFeatures = '';

	sFeatures += 'width=' + iWidth + ',';
	sFeatures += 'height=' + iHeight + ',';

	if(sFeatures.indexOf('location')==-1)
		sFeatures += 'location=no,'

	if(sFeatures.indexOf('menubar')==-1)
		sFeatures += 'menubar=no,';

	if(sFeatures.indexOf('resizeable')==-1)
		sFeatures += 'resizeable=no,';

	if(sFeatures.indexOf('scrollbars')==-1)
		sFeatures += 'scrollbars=no,';

	if(sFeatures.indexOf('status')==-1)
		sFeatures += 'status=no,';

	if(sFeatures.indexOf('titlebar')==-1)
		sFeatures += 'titlebar=no,';
	
	if(sFeatures.indexOf('toolbar')==-1)
		sFeatures += 'toolbar=no';
	
	return window.open(sURL, sName, sFeatures);
}

function replaceEmailWithAnchor(sString, sAnchor)
{
	if(!(sAnchor && sAnchor.length > 0)) 
		sAnchor = '<a href="mailto:%email">%email</a>'

//		var sPattern ='[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-\w]*[0-9a-zA-Z])*\.)+[a-zA-Z]{2,9}';
	var sPattern = '([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}';

	var objRE = new RegExp(sPattern, 'im');

	var sOutput = '';
	var sMatch;
	var iLastIndex;

	result = objRE.exec(sString);
	while(result != null)
	{
		sMatch = result[0]
		iLastIndex = objRE.lastIndex;

		sOutput += sString.substring(0,iLastIndex);
		sOutput = sOutput.replace(sMatch, sAnchor.replace(/%email/g, sMatch));
		sString = sString.substr(iLastIndex);
		result = objRE.exec(sString);
	}

	return sOutput
}

function replaceURLWithAnchor(sString, sAnchor)
{
	if(!(sAnchor && sAnchor.length > 0)) 
		sAnchor = '<a href="mailto:%email">%email</a>'

//		var sPattern = '((((ht|f)tp(s?))\://)?(www.|[a-zA-Z0-9].)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,6}(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\;\?\'\\\+&%\$#\=~_\-]+))*)';
//		var sPattern = '((ht| f)tp(s?)\:\/\/[a-zA-Z0-9\-\._]+(\.[a-zA-Z0-9\-\._]+){2,}(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&%\$#_]*)?($|\s))'
//		var sPattern = '((((ht|f)tp(s?))\://)?(www.|[a-zA-Z0-9].)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,6}(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\;\?\'\\\+&%\$#\=~_\-]+))*)'
//		var sPattern = '(http|ftp|https):\/\/[\w-_]+(\.[\w-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?'
	var sPattern = '(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*[^\.\,\)\(\s]'


	var objRE = new RegExp(sPattern, 'im');


	var sOutput = '';
	var sMatch;
	var iLastIndex;

	result = objRE.exec(sString);
	while(result != null)
	{
		sMatch = result[0]
		iLastIndex = objRE.lastIndex;

		sOutput += sString.substring(0,iLastIndex);
		sOutput = sOutput.replace(sMatch, sAnchor.replace(/%email/g, sMatch));
		sString = sString.substr(iLastIndex);
		result = objRE.exec(sString);
	}

	sOutput += sString.substr(0);

	return sOutput
}

function preloadImages(Images)
{
	var MyImage = null;
	var i;
	for(i=0;i<Images.length;i++)
	{
		MyImage = new Image();
		MyImage.src = Images[i];
	}
}


function startUp(){
msie = (document.all)? true:false
	showMe.style.visibility = "hidden";
}

function change(){
	if (showMe.style.visibility == "visible")
		{showMe.style.visibility = "hidden";}
	   else
		{showMe.style.visibility = "visible";}
	  
}

function popup(source,wide,hite,scroll) {
	specs = new String();
	specs = "width=" + wide + ",height=" + hite +",location=no,status=no,toolbar=no,menubar=no,scrollbars=" + scroll + ",resizable=yes"
	newWindow = window.open (source,"",specs);
	}

function printView(item1, sub1, page1) {
	window.open("print.asp?item=" + item1 + "&sub=" + sub1 + "&page=" + page1 + "&readOnly=True", "Printpreview","width=640,height=600,location=yes,status=yes,toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes")
   // window.open("print.asp?item=" + item1 + "&sub=" + sub1 + "&page=" + page1 ,"Printpreview","scrollbars=yes, titlebar=yes,location=yes, toolbar=yes, menubar=yes, resizable=yes, width=500,height=600, alwaysRaised=yes, status=yes")
}

function goBack() {
	history.back();
}

