/***********************************************************************************************************

Zooming Functions


************************************************************************************************************/
//Image zoom in/out script- by javascriptkit.com
//Visit JavaScript Kit (http://www.javascriptkit.com) for script
//Credit must stay intact for use

var zoomfactor=0.1 //Enter factor (0.05=5%)
var maxwidth, maxheight;


function zoomhelper(){
var chght=0;
var i=0

if (parseInt(whatcache.style.width)< maxwidth&&parseInt(whatcache.style.height)< maxheight){

whatcache.style.width=parseInt(whatcache.style.width)+parseInt(whatcache.style.width)*zoomfactor*prefix;
whatcache.style.height=parseInt(whatcache.style.height)+parseInt(whatcache.style.height)*zoomfactor*prefix;
}

}

function zoom(originalW, originalH, what, state){
maxwidth = 2.2 * originalW;
maxheight = 2.2 * originalH;
if (!document.all&&!document.getElementById)
{
alert("browser does not support zoom");
return;
}
whatcache=eval("document.images."+what)
prefix=(state=="in")? 1 : -1
if (whatcache.style.width==""||state=="restore"){
whatcache.style.width=originalW+"px"
whatcache.style.height=originalH+"px"
if (state=="restore")
return
}
else{
zoomhelper()
}
beginzoom=setInterval("zoomhelper()",100)
}

function clearzoom(){
if (window.beginzoom)
clearInterval(beginzoom)
}



/************************************************************************************************************
	@fileoverview
	Floating window
	
	Copyright (C) 2006  Alf Magne Kalleland(post@dhtmlgoodies.com)
	


Update log:
	
	January 18th, 2006: Added feature that makes the window cover selectboxes(ref. problem with windowed and window less elements).
	January 29th, 2006: Fixed problem showing the windows in Opera
	Feb, 8th 2006:		Added support for creating new windows dynamically
	March,	11th, 2006: Added support for getting content from external files by use of Ajax
	
	
************************************************************************************************************/
		
	var readSizeFromCookie = false;	// Determines if size and position of windows should be set/retreved by use of cookie
	var windowMinSize = [80,30];	// Mininum width and height of windows.
	
	var moveCounter = -1;	
	var startEventPos = new Array();
	var startPosWindow = new Array();
	var startWindowSize = new Array();
	var initResizeCounter = -1;	
	var activeWindow = false;
	var activeWindowContent = false;	
	var windowSizeArray = new Array();
	var windowPositionArray = new Array();
	var currentZIndex = 10000;
	var windowStateArray = new Array();	// Minimized or maximized
	var activeWindowIframe = false;
	var divCounter = 0;
	var zIndexSet = false;

	var MSIEWIN = (navigator.userAgent.indexOf('MSIE')>=0 && navigator.userAgent.indexOf('Win')>=0 && navigator.userAgent.toLowerCase().indexOf('opera')<0)?true:false;
	var opera = navigator.userAgent.toLowerCase().indexOf('opera')>=0?true:false;
	
	var ajaxObjects = new Array();
	
function winPos()
	{
	var winY = 0;
	browser=navigator.appName;

if (browser != "Netscape")
    {	
	if (document.documentElement && !document.documentElement.scrollTop)
	   {
	    winY = document.documentElement.scrollTop;
		// IE6 +4.01 but no scrolling going on
		}
	else if (document.documentElement && document.documentElement.scrollTop)
		{
		winY = document.documentElement.scrollTop;  
		// IE6 +4.01 and user has scrolled
		}
	else if (document.body && document.body.scrollTop)
	    {
		winY = document.body.scrollTop;  		
		// IE5 or DTD 3.2
		}
	}	
 else
		{
		winY = window.pageYOffset;
		// Navigator
		}
	
	return(winY);
	}					
	/*
	These cookie functions are downloaded from 
	http://www.mach5.com/support/analyzer/manual/html/General/CookiesJavaScript.htm
	*/	
	function Get_Cookie(name) { 
	   var start = document.cookie.indexOf(name+"="); 
	   var len = start+name.length+1; 
	   if ((!start) && (name != document.cookie.substring(0,name.length))) return null; 
	   if (start == -1) return null; 
	   var end = document.cookie.indexOf(";",len); 
	   if (end == -1) end = document.cookie.length; 
	   return unescape(document.cookie.substring(len,end)); 
	} 
	// This function has been slightly modified
	function Set_Cookie(name,value,expires,path,domain,secure) { 
		expires = expires * 60*60*24*1000;
		var today = new Date();
		var expires_date = new Date( today.getTime() + (expires) );
	    var cookieString = name + "=" +escape(value) + 
	       ( (expires) ? ";expires=" + expires_date.toGMTString() : "") + 
	       ( (path) ? ";path=" + path : "") + 
	       ( (domain) ? ";domain=" + domain : "") + 
	       ( (secure) ? ";secure" : ""); 
	    document.cookie = cookieString; 
	} 
			
	function cancelEvent()
	{
		return (moveCounter==-1 && initResizeCounter==-1)?true:false;
	}
	function initMove(e)
	{		
		if(document.all)e = event;
		moveCounter = 0;
		switchElement(false,this);
		
		startEventPos = [e.clientX,e.clientY];
		startPosWindow = [activeWindow.offsetLeft,activeWindow.offsetTop];
		startMove();
		if(!MSIEWIN)return false;
	
	}
	
	function startMove()
	{
		if(moveCounter>=0 && moveCounter<=10){
			moveCounter++;
			setTimeout('startMove()',5);
		}
	}
	
	function stopMove(e)
	{
		if(document.all)e = event;
		moveCounter=-1;
		initResizeCounter=-1;
		if(!activeWindow || !activeWindowContent)return;
		var state = '0';
		if(windowStateArray[activeWindow.id.replace(/[^0-9]/g,'')])state = '1';
		
		Set_Cookie(activeWindow.id + '_attr',activeWindow.style.left.replace('px','2px') + ',' + activeWindow.style.top.replace('px','') + ',' + activeWindow.style.width.replace('px','') + ',' + activeWindowContent.style.height.replace('px','') + ',' + activeWindow.style.zIndex + ',' + state,50);
	}
	
	function moveWindow(e)
	{
		
		if(document.all)e = event;
		if(moveCounter>=10){
			activeWindow.style.left = startPosWindow[0] + e.clientX - startEventPos[0]  + 'px';
			activeWindow.style.top = startPosWindow[1] + e.clientY - startEventPos[1]  + 'px';
			
		}	
		
		if(initResizeCounter>=10){
			var newWidth = Math.max(windowMinSize[0],startWindowSize[0] + e.clientX - startEventPos[0]);
			var newHeight = Math.max(windowMinSize[1],startWindowSize[1] + e.clientY - startEventPos[1]);
			activeWindow.style.width =  newWidth + 'px';
			activeWindowContent.style.height = newHeight  + 'px';		
			
			if(MSIEWIN && activeWindowIframe){
				activeWindowIframe.style.width = (newWidth) + 'px';	
				activeWindowIframe.style.height = (newHeight+20) + 'px';	
			}
				
			
		}
		if(!document.all)return false;
	}
	
	
	function initResizeWindow(e)
	{
		if(document.all)e = event;
		initResizeCounter = 0;
		switchElement(false,document.getElementById('dhtml_goodies_id' + this.id.replace(/[^\d]/g,'')));
		startWindowSize = [activeWindowContent.offsetWidth,activeWindowContent.offsetHeight];
		startEventPos = [e.clientX,e.clientY];
		
		if(MSIEWIN)activeWindowIframe = activeWindow.getElementsByTagName('IFRAME')[0];
		startResizeWindow();
		return false;
			
	}
	
	function startResizeWindow()
	{
		if(initResizeCounter>=0 && initResizeCounter<=10){
			initResizeCounter++;
			setTimeout('startResizeWindow()',5);
		}
	}
	
	function switchElement(e,inputElement)
	{
		if(!inputElement)inputElement = this;
		var numericId = inputElement.id.replace(/[^0-9]/g,'');
		var state = '0';
		if(windowStateArray[numericId])state = '1';
			
		if(activeWindow && activeWindowContent){
			Set_Cookie(activeWindow.id + '_attr',activeWindow.style.left.replace('px','') + ',' + activeWindow.style.top.replace('px','') + ',' + activeWindow.style.width.replace('px','') + ',' + activeWindowContent.style.height.replace('px','') + ',' + activeWindow.style.zIndex + ',' + state,50);
	
		}
		currentZIndex = currentZIndex/1 + 1;
		activeWindow = document.getElementById('dhtml_goodies_id' + numericId);	
		activeWindow.style.zIndex = currentZIndex;
		activeWindowContent = document.getElementById('windowContent' + numericId);

		Set_Cookie(activeWindow.id + '_attr',activeWindow.style.left.replace('px','') + ',' + activeWindow.style.top.replace('px','') + ',' + activeWindow.style.width.replace('px','') + ',' + activeWindowContent.style.height.replace('px','') + ',' + activeWindow.style.zIndex + ',' + state,50);
	}
	
	function hideWindow()
	{
		switchElement(false,document.getElementById('dhtml_goodies_id' + this.id.replace(/[^\d]/g,'')));	
		activeWindow.style.display='none';
	}
	
	function minimizeWindow(e,inputObj)
	{
		if(!inputObj)inputObj = this;
		var numericID = inputObj.id.replace(/[^0-9]/g,'');
		switchElement(false,document.getElementById('dhtml_goodies_id' + numericID));
		var state;	
		if(inputObj.src.indexOf('minimize')>=0){
			activeWindowContent.style.display='none';
			document.getElementById('resizeImage'+numericID).style.display='none';
			inputObj.src = inputObj.src.replace('minimize','maximize');	
			windowStateArray[numericID] = false;
			state = '0';		
		}else{			
			activeWindowContent.style.display='block';
			document.getElementById('resizeImage'+numericID).style.display='';
			inputObj.src = inputObj.src.replace('maximize','minimize');
			windowStateArray[numericID] = true;
			state = '1';
		}
		
		Set_Cookie(activeWindow.id + '_attr',activeWindow.style.left.replace('px','') + ',' + activeWindow.style.top.replace('px','') + ',' + activeWindow.style.width.replace('px','') + ',' + activeWindowContent.style.height.replace('px','') + ',' + activeWindow.style.zIndex + ',' + state,50);

	}
	
	function initWindows(e,divObj)
	{
		
		
		var divs = document.getElementsByTagName('DIV');
		
		if(divObj){
			var tmpDivs = divObj.getElementsByTagName('DIV');
			var divs = new Array();
			divs[divs.length] = divObj;
			
			for(var no=0;no<tmpDivs.length;no++){
				divs[divs.length] = tmpDivs[no];
			}
		}
		
		for(var no=0;no<divs.length;no++){
			var curWinY = 0;
				
			curWinY = winPos();
			
			if(divs[no].className=='dhtmlgoodies_window'){	
		
				if(MSIEWIN){
					var iframe = document.createElement('IFRAME');
					iframe.style.border='1px';
					iframe.frameborder=0;
					iframe.style.position = 'absolute';
					iframe.style.backgroundColor = '#FFFFFF';
					iframe.style.top = '0px';
					iframe.style.left = '0px';
					iframe.style.zIndex = 100;
					iframe.title = "Frame";
					iframe.scrolling="yes";
					
					var subDiv = divs[no].getElementsByTagName('DIV')[0];
					divs[no].insertBefore(iframe,subDiv);
					
				}					
				if(divObj){
					divs[no].style.zIndex = currentZIndex;
					currentZIndex = currentZIndex /1 + 1;
				}
				
				divCounter = divCounter + 1;	
				if(divCounter==1)activeWindow = divs[no];		
				divs[no].id = 'dhtml_goodies_id' + divCounter;	
				divs[no].onmousedown = switchElement;
				if(readSizeFromCookie)var cookiePos = Get_Cookie(divs[no].id + '_attr') + '';	else cookiePos = '';
				if(divObj)cookiePos='';
				var cookieValues = new Array();
				
					
				if(cookiePos.indexOf(',')>0){
					cookieValues = cookiePos.split(',');
					if(!windowPositionArray[divCounter])windowPositionArray[divCounter] = new Array();
					windowPositionArray[divCounter][0] = Math.max(0,cookieValues[0]);
					windowPositionArray[divCounter][1] = Math.max(0,cookieValues[1]);
				}

				if(cookieValues.length==5 && !zIndexSet){
					divs[no].style.zIndex = cookieValues[4];
					if(cookieValues[4]/1 > currentZIndex)currentZIndex = cookieValues[4]/1;					
				}
				if(windowPositionArray[divCounter]){
				    divs[no].style.left = windowPositionArray[divCounter][0] + 'px';
					
					//alert("start winY is" +curWinY);
					curWinY = curWinY + windowPositionArray[divCounter][1];
					//alert("winY is" +curWinY);
					divs[no].style.top = curWinY + 'px';
					//alert(divs[no].style.top);	
				}
				
				var subImages = divs[no].getElementsByTagName('IMG');
				for(var no2=0;no2<subImages.length;no2++){
					if(subImages[no2].className=='resizeImage'){
						subImages[no2].style.cursor = 'nw-resize';
						subImages[no2].onmousedown = initResizeWindow;
						subImages[no2].id = 'resizeImage' + divCounter;
						break;
					}	
					if(subImages[no2].className=='closeButton'){
						subImages[no2].id = 'closeImage' + divCounter;
						subImages[no2].onclick = hideWindow;	
					}	
					if(subImages[no2].className=='minimizeButton'){
						subImages[no2].id = 'minimizeImage' + divCounter;
						subImages[no2].onclick = minimizeWindow;	
						if(cookieValues.length==6 && cookieValues[5]=='0'){							
							setTimeout('minimizeWindow(false,document.getElementById("minimizeImage' + divCounter + '"))',10);
						}
						if(cookieValues.length==6 && cookieValues[5]=='1'){							
							windowStateArray[divCounter] = 1;
						}
						
						
					}
				}			
			}	
			if(divs[no].className=='dhtmlgoodies_windowMiddle' || divs[no].className=='dhtmlgoodies_window_bottom'){
				divs[no].style.zIndex = 1000;
				
			}
			if(divs[no].className=='dhtmlgoodies_window_top'){
				divs[no].onmousedown = initMove;
				divs[no].id = 'top_bar'+divCounter;
				divs[no].style.zIndex = 1000;
	
			}

			if(divs[no].className=='dhtmlgoodies_windowContent'){
				divs[no].id = 'windowContent'+divCounter;
				divs[no].style.zIndex = 1000;
				if(cookieValues && cookieValues.length>3){
					if(!windowSizeArray[divCounter])windowSizeArray[divCounter] = new Array();
					windowSizeArray[divCounter][0] = cookieValues[2];
					windowSizeArray[divCounter][1] = cookieValues[3];
				}	
				if(cookieValues && cookieValues.length==5){
					activeWindowContent = document.getElementById('windowContent' + divCounter);	
				}		
				if(windowSizeArray[divCounter]){
					divs[no].style.height = windowSizeArray[divCounter][1] + 'px';
					divs[no].parentNode.parentNode.style.width = windowSizeArray[divCounter][0] + 'px';
					
					if(MSIEWIN){
						iframe.style.width = (windowSizeArray[divCounter][0]) + 'px';
						iframe.style.height = (windowSizeArray[divCounter][1]+20) + 'px';
					}
				}
			}

			
		}	
		
		if(!divObj){
			document.documentElement.onmouseup = stopMove;	
			document.documentElement.onmousemove = moveWindow;
			document.documentElement.ondragstart = cancelEvent;
			document.documentElement.onselectstart = cancelEvent;
		}
		
		return divCounter;
	}

	function createNewWindow(width,height,left,top)
	{
	 	
		var winY = 0;
		
		winY = winPos();
				
		top += winY;
		
		var div = document.createElement('DIV');
		div.className='dhtmlgoodies_window';
		
		document.body.appendChild(div);
		
	
			
		var sTitle;			
		var topDiv = document.createElement('DIV');
		topDiv.className='dhtmlgoodies_window_top';
		div.appendChild(topDiv);
		
		
		var img = document.createElement('IMG');
		img.src = '../images/top_left.gif';
		img.align='left';
		img.title='Stuff Here';
		topDiv.appendChild(img);
		
		
		var sTitle=document.getElementById("title");
						
		var img = document.createElement('IMG');
		img.src = '../images/top_center.gif';
		img.className='topCenterImage';
		topDiv.appendChild(img);
		
		var buttonDiv = document.createElement('DIV');
		buttonDiv.className='top_buttons';
		topDiv.appendChild(buttonDiv);
		
		var img = document.createElement('IMG');
		img.src = '../images/minimize.gif';
		img.className='minimizeButton';
		buttonDiv.appendChild(img);	
		
		var img = document.createElement('IMG');
		img.src = '../images/close.gif';
		img.className='closeButton';
		buttonDiv.appendChild(img);	
		
		var img = document.createElement('IMG');
		img.src = '../images/top_right.gif';
		buttonDiv.appendChild(img);		
		
		var middleDiv = document.createElement('DIV');
		middleDiv.className='dhtmlgoodies_windowMiddle';
		div.appendChild(middleDiv);
		
		var contentDiv = document.createElement('DIV');
		contentDiv.className='dhtmlgoodies_windowContent';
		middleDiv.appendChild(contentDiv);
		
		var bottomDiv = document.createElement('DIV');
		bottomDiv.className='dhtmlgoodies_window_bottom';
		div.appendChild(bottomDiv);
		
		var img = document.createElement('IMG');
		img.src = '../images/bottom_right.gif';
		img.className='resizeImage';
		bottomDiv.appendChild(img);		

		windowSizeArray[windowSizeArray.length] = [width,height];
		windowPositionArray[windowPositionArray.length] = [left,top+winY];

		div.style.width =  width + 'px';
		contentDiv.style.height = height  + 'px';		
		div.style.left =  left + 'px';
		div.style.top = top  + 'px';	
		
		//alert("new height"+div.style.top);
		
		self.moveTo(div.style.top,div.style.left);
	
		return initWindows(false,div);
		
		
		 	
	}
	
	function showAjaxContent(ajaxIndex,windowId)
	{
		document.getElementById('windowContent' + windowId).innerHTML = ajaxObjects[ajaxIndex].response;			
		//alert("Here ShowAjaxContent");
		
	}

function readURLFile(InURL){
var requestObj = readyAJAX();
var url = InURL;
var i = 0;

requestObj.open("GET",url,true);

//alert("return from requestOpen = " +requestObj.open("GET",url,true));
requestObj.send();


requestObj.onreadystatechange = function() {
    if (requestObj.readyState == 4) {
        if (requestObj.status == 200) {
            alert(requestObj.responseText);
        } else {
            alert(requestObj.statusText);
        }
    }
	
}	
}

function addContentFromUrl(url,windowId)
	{
	 	var ajaxIndex = ajaxObjects.length;
		
		//alert("addContentFromUrl = "+url);
		sack(url);	
		ajaxObjects[ajaxIndex] = new sack();
		ajaxObjects[ajaxIndex].requestFile = url;	// Specifying which file to get
		ajaxObjects[ajaxIndex].onCompletion = function(){ showAjaxContent(ajaxIndex,windowId); };	// Specify function that will be executed after file has been found
		alert("ajaxIndex = "+ajaxIndex);
		//alert("windowID = "+windowId); 
		
		ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function			
		//alert("Show URL addContent"+ajaxObjects[ajaxIndex].onCompletion);
		
	}
	
/* This function illustrates how you can create a new custom window dynamically */
function CorrectURL(InfName)
	     {		 
		 
		 a = 0;
		 i=0;
		 var RootDir = String(window.location);
		 
		 a = RootDir.indexOf('tech');
		 
		 b = RootDir.indexOf('/',a);
		 b++;
		 
		 c = RootDir.indexOf('.', a);
		 
		 var NewDir = String(RootDir.substr(0, b)); 
		 // now we have the target directory //
		 
		 // so put http: in the front //
		 
		 var ShortDir = String(NewDir.substr(a-7, NewDir.length));
		 //alert("ShortDir" + ShortDir+"Root Dir"+RootDir)
		 NewDir = "http://www."+ShortDir;
		 NewDir = String(NewDir.substr(0, NewDir.length - 1));
		 // finally put on the extension //
		 var check = 0;
		 
	     NewDir += "/";
		 c=InfName.indexOf('/');
		 c++;
		 
		 var outFile = String(InfName.substr(c));
		 // now we have the out file name //
		 c--;
		 
		 var OutDir = String(InfName.substr(0, c));
		 
		 
		 // now the input directory //
		 //now put the path back together //
		    
		 if(OutDir.length > 0)
		   {
		    NewDir += OutDir;
			NewDir += "/";
		    NewDir += outFile;  
		 	}
		  else
		  {
		  NewDir += outFile;
		  }		 
		 //alert("New Dir is after adding outFile is:::"+NewDir);
		 
		 if (NewDir.indexOf("?")!=-1) { 
		 newDir=NewDir.substring(0,NewDir.indexOf("?")); 
		 } 

		 //window.location=String(NewDir);
		 return(NewDir);
		 }
	
	/* This function illustrates how you can create a new custom window dynamically */


function customFunctionCreateWindow(urlToExternalFile, width,height,left,top)
{		
var winY = document.documentElement.scrollTop;
    top += winY;
	
var divId = createNewWindow(width,height,left,top);
var txtOut = "";
var hOut = 0;
	

	
	if(urlToExternalFile){
	    var div = document.createElement('DIV');
		var page_request = false;
		var bustcacheparameter="";
		var imglocat="";

		
		var CompDir = CorrectURL(urlToExternalFile);
		//alert("This is the file to open"+CompDir);
		var txtFile = new XMLHttpRequest();
		txtFile.open("GET", String(CompDir), true);
		page_request = new XMLHttpRequest();
		  bustcacheparameter=(CompDir.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime();
		
		page_request.open('GET', String(CompDir)+bustcacheparameter, true);
		page_request.send(null);
		
		txtFile.onreadystatechange = function() {
  		   if (txtFile.readyState === 4) {  // Makes sure the document is ready to parse.
    	      if (txtFile.status === 200) {  // Makes sure it's found the file.
      		  allText = txtFile.responseText;
			  //alert(allText); 
      		  lines = txtFile.responseText.split("\n"); // Will separate each line into an array
			  	  var i=0;
			  	  while(i < lines.length)
			  	      {
					  if (lines[i].indexOf('src')> 1)
					     {
						 imglocat = lines[i];				 				    
						  }
					  // leave this here because you may need an element from the xlm file someday	  		  
			  		  i++;
			  		  }
			  
			  	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
				   document.getElementById('windowContent' + divId).innerHTML=page_request.responseText}
			  
			   
			  document.getElementById('windowContent' + divId).innerHTML = allText;
			  
		
    		  }
  		    }
		   }
		 txtFile.send(null);
  		 }		 
		 else
		 {
		  document.getElementById('windowContent' + divId).innerHTML = 'This REALLY REALLY should have changed';
		  //activeWindow = document.getElementById('title' + divId).innerHTML;
		  //alert(activeWindow(""));
		  		  
		  }
		  		  
		
		
		//if(urlToExternalFile)addContentFromUrl(urlToExternalFile,divId);	// Add content from external file
}
		
	window.onload = initWindows;